Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 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 "callee_save_frame.h" |
Elliott Hughes | af778e6 | 2012-05-01 18:45:31 -0700 | [diff] [blame] | 18 | #include "dex_instruction.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame^] | 19 | #include "mirror/array.h" |
| 20 | #include "mirror/object-inl.h" |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 21 | |
| 22 | namespace art { |
| 23 | |
| 24 | /* |
| 25 | * Fill the array with predefined constant values, throwing exceptions if the array is null or |
| 26 | * not of sufficient length. |
| 27 | * |
| 28 | * NOTE: When dealing with a raw dex file, the data to be copied uses |
| 29 | * little-endian ordering. Require that oat2dex do any required swapping |
| 30 | * so this routine can get by with a memcpy(). |
| 31 | * |
| 32 | * Format of the data: |
| 33 | * ushort ident = 0x0300 magic value |
| 34 | * ushort width width of each element in the table |
| 35 | * uint size number of elements in the table |
| 36 | * ubyte data[size*width] table of data values (may contain a single-byte |
| 37 | * padding at the end) |
| 38 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame^] | 39 | extern "C" int artHandleFillArrayDataFromCode(mirror::Array* array, |
Logan Chien | 19c350a | 2012-05-01 19:21:32 +0800 | [diff] [blame] | 40 | const Instruction::ArrayDataPayload* payload, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame^] | 41 | Thread* self, mirror::AbstractMethod** sp) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 42 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 43 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); |
Elliott Hughes | af778e6 | 2012-05-01 18:45:31 -0700 | [diff] [blame] | 44 | DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature)); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 45 | if (UNLIKELY(array == NULL)) { |
| 46 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/NullPointerException;", |
Elliott Hughes | af778e6 | 2012-05-01 18:45:31 -0700 | [diff] [blame] | 47 | "null array in FILL_ARRAY_DATA"); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 48 | return -1; // Error |
| 49 | } |
| 50 | DCHECK(array->IsArrayInstance() && !array->IsObjectArray()); |
Elliott Hughes | af778e6 | 2012-05-01 18:45:31 -0700 | [diff] [blame] | 51 | if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) { |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 52 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;", |
Elliott Hughes | af778e6 | 2012-05-01 18:45:31 -0700 | [diff] [blame] | 53 | "failed FILL_ARRAY_DATA; length=%d, index=%d", |
| 54 | array->GetLength(), payload->element_count); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 55 | return -1; // Error |
| 56 | } |
Elliott Hughes | af778e6 | 2012-05-01 18:45:31 -0700 | [diff] [blame] | 57 | uint32_t size_in_bytes = payload->element_count * payload->element_width; |
| 58 | memcpy(array->GetRawData(payload->element_width), payload->data, size_in_bytes); |
Ian Rogers | 57b86d4 | 2012-03-27 16:05:41 -0700 | [diff] [blame] | 59 | return 0; // Success |
| 60 | } |
| 61 | |
| 62 | } // namespace art |