quick_fillarray_entrypoints.cc revision af778e627aa41ec6c176cba537062b95d4d960b6
157b86d47b66322693a070185fadfb43cb9c12eabIan Rogers/* 257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * Copyright (C) 2012 The Android Open Source Project 357b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * 457b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * Licensed under the Apache License, Version 2.0 (the "License"); 557b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * you may not use this file except in compliance with the License. 657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * You may obtain a copy of the License at 757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * 857b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * http://www.apache.org/licenses/LICENSE-2.0 957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * 1057b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * Unless required by applicable law or agreed to in writing, software 1157b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * distributed under the License is distributed on an "AS IS" BASIS, 1257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1357b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * See the License for the specific language governing permissions and 1457b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * limitations under the License. 1557b86d47b66322693a070185fadfb43cb9c12eabIan Rogers */ 1657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers 1757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers#include "callee_save_frame.h" 18af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes#include "dex_instruction.h" 1957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers#include "object.h" 2057b86d47b66322693a070185fadfb43cb9c12eabIan Rogers 2157b86d47b66322693a070185fadfb43cb9c12eabIan Rogersnamespace art { 2257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers 2357b86d47b66322693a070185fadfb43cb9c12eabIan Rogers/* 2457b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * Fill the array with predefined constant values, throwing exceptions if the array is null or 2557b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * not of sufficient length. 2657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * 2757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * NOTE: When dealing with a raw dex file, the data to be copied uses 2857b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * little-endian ordering. Require that oat2dex do any required swapping 2957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * so this routine can get by with a memcpy(). 3057b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * 3157b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * Format of the data: 3257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * ushort ident = 0x0300 magic value 3357b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * ushort width width of each element in the table 3457b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * uint size number of elements in the table 3557b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * ubyte data[size*width] table of data values (may contain a single-byte 3657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * padding at the end) 3757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers */ 38af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughesextern "C" int artHandleFillArrayDataFromCode(Array* array, const DexFile::Payload* payload, 3957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers Thread* self, Method** sp) { 4057b86d47b66322693a070185fadfb43cb9c12eabIan Rogers FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); 41af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature)); 4257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers if (UNLIKELY(array == NULL)) { 4357b86d47b66322693a070185fadfb43cb9c12eabIan Rogers Thread::Current()->ThrowNewExceptionF("Ljava/lang/NullPointerException;", 44af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes "null array in FILL_ARRAY_DATA"); 4557b86d47b66322693a070185fadfb43cb9c12eabIan Rogers return -1; // Error 4657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers } 4757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers DCHECK(array->IsArrayInstance() && !array->IsObjectArray()); 48af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) { 4957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers Thread::Current()->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;", 50af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes "failed FILL_ARRAY_DATA; length=%d, index=%d", 51af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes array->GetLength(), payload->element_count); 5257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers return -1; // Error 5357b86d47b66322693a070185fadfb43cb9c12eabIan Rogers } 54af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes uint32_t size_in_bytes = payload->element_count * payload->element_width; 55af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes memcpy(array->GetRawData(payload->element_width), payload->data, size_in_bytes); 5657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers return 0; // Success 5757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers} 5857b86d47b66322693a070185fadfb43cb9c12eabIan Rogers 5957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers} // namespace art 60