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" 1862d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers#include "common_throws.h" 19af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes#include "dex_instruction.h" 202dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/array.h" 212dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogers#include "mirror/object-inl.h" 2257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers 2357b86d47b66322693a070185fadfb43cb9c12eabIan Rogersnamespace art { 2457b86d47b66322693a070185fadfb43cb9c12eabIan Rogers 2557b86d47b66322693a070185fadfb43cb9c12eabIan Rogers/* 2657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * Fill the array with predefined constant values, throwing exceptions if the array is null or 2757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * not of sufficient length. 2857b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * 2957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * NOTE: When dealing with a raw dex file, the data to be copied uses 3057b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * little-endian ordering. Require that oat2dex do any required swapping 3157b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * so this routine can get by with a memcpy(). 3257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * 3357b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * Format of the data: 3457b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * ushort ident = 0x0300 magic value 3557b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * ushort width width of each element in the table 3657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * uint size number of elements in the table 3757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * ubyte data[size*width] table of data values (may contain a single-byte 3857b86d47b66322693a070185fadfb43cb9c12eabIan Rogers * padding at the end) 3957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers */ 402dd0e2cea360bc9206eb88ecc40d259e796c239dIan Rogersextern "C" int artHandleFillArrayDataFromCode(mirror::Array* array, 4119c350a9197411d427b71b7ab15b18417701de10Logan Chien const Instruction::ArrayDataPayload* payload, 42cf4035a4c41ccfcc3e89a0cee25f5218a11b0705Andreas Gampe Thread* self, StackReference<mirror::ArtMethod>* sp) 43b726dcb581bf72da46527378ccb6889020f0e6e9Ian Rogers SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 4457b86d47b66322693a070185fadfb43cb9c12eabIan Rogers FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); 45af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature)); 4657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers if (UNLIKELY(array == NULL)) { 4762d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers ThrowNullPointerException(NULL, "null array in FILL_ARRAY_DATA"); 4857b86d47b66322693a070185fadfb43cb9c12eabIan Rogers return -1; // Error 4957b86d47b66322693a070185fadfb43cb9c12eabIan Rogers } 5057b86d47b66322693a070185fadfb43cb9c12eabIan Rogers DCHECK(array->IsArrayInstance() && !array->IsObjectArray()); 51af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) { 5262d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers ThrowLocation throw_location = self->GetCurrentLocationForThrow(); 5362d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers self->ThrowNewExceptionF(throw_location, "Ljava/lang/ArrayIndexOutOfBoundsException;", 5462d6c772205b8859f0ebf7ad105402ec4c3e2e01Ian Rogers "failed FILL_ARRAY_DATA; length=%d, index=%d", 557655f29fabc0a12765de828914a18314382e5a35Ian Rogers array->GetLength(), payload->element_count - 1); 5657b86d47b66322693a070185fadfb43cb9c12eabIan Rogers return -1; // Error 5757b86d47b66322693a070185fadfb43cb9c12eabIan Rogers } 58af778e627aa41ec6c176cba537062b95d4d960b6Elliott Hughes uint32_t size_in_bytes = payload->element_count * payload->element_width; 59ef7d42fca18c16fbaf103822ad16f23246e2905dIan Rogers memcpy(array->GetRawData(payload->element_width, 0), payload->data, size_in_bytes); 6057b86d47b66322693a070185fadfb43cb9c12eabIan Rogers return 0; // Success 6157b86d47b66322693a070185fadfb43cb9c12eabIan Rogers} 6257b86d47b66322693a070185fadfb43cb9c12eabIan Rogers 6357b86d47b66322693a070185fadfb43cb9c12eabIan Rogers} // namespace art 64