1 /* 2 * Copyright (C) 2012 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #include "dex_instruction.h" 18 #include "entrypoints/entrypoint_utils.h" 19 #include "mirror/art_method-inl.h" 20 #include "mirror/object-inl.h" 21 22 namespace art { 23 24 extern "C" void art_portable_fill_array_data_from_code(mirror::ArtMethod* method, 25 uint32_t dex_pc, 26 mirror::Array* array, 27 uint32_t payload_offset) 28 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { 29 const DexFile::CodeItem* code_item = MethodHelper(method).GetCodeItem(); 30 const Instruction::ArrayDataPayload* payload = 31 reinterpret_cast<const Instruction::ArrayDataPayload*>(code_item->insns_ + payload_offset); 32 DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature)); 33 if (UNLIKELY(array == NULL)) { 34 ThrowNullPointerException(NULL, "null array in FILL_ARRAY_DATA"); 35 return; // Error 36 } 37 DCHECK(array->IsArrayInstance() && !array->IsObjectArray()); 38 if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) { 39 Thread* self = Thread::Current(); 40 ThrowLocation throw_location = self->GetCurrentLocationForThrow(); 41 self->ThrowNewExceptionF(throw_location, "Ljava/lang/ArrayIndexOutOfBoundsException;", 42 "failed FILL_ARRAY_DATA; length=%d, index=%d", 43 array->GetLength(), payload->element_count - 1); 44 return; // Error 45 } 46 uint32_t size_in_bytes = payload->element_count * payload->element_width; 47 memcpy(array->GetRawData(payload->element_width), payload->data, size_in_bytes); 48 } 49 50 } // namespace art 51