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" |
| 18 | #include "object.h" |
| 19 | |
| 20 | namespace art { |
| 21 | |
| 22 | /* |
| 23 | * Fill the array with predefined constant values, throwing exceptions if the array is null or |
| 24 | * not of sufficient length. |
| 25 | * |
| 26 | * NOTE: When dealing with a raw dex file, the data to be copied uses |
| 27 | * little-endian ordering. Require that oat2dex do any required swapping |
| 28 | * so this routine can get by with a memcpy(). |
| 29 | * |
| 30 | * Format of the data: |
| 31 | * ushort ident = 0x0300 magic value |
| 32 | * ushort width width of each element in the table |
| 33 | * uint size number of elements in the table |
| 34 | * ubyte data[size*width] table of data values (may contain a single-byte |
| 35 | * padding at the end) |
| 36 | */ |
| 37 | extern "C" int artHandleFillArrayDataFromCode(Array* array, const uint16_t* table, |
| 38 | Thread* self, Method** sp) { |
| 39 | FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly); |
| 40 | DCHECK_EQ(table[0], 0x0300); |
| 41 | if (UNLIKELY(array == NULL)) { |
| 42 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/NullPointerException;", |
| 43 | "null array in fill array"); |
| 44 | return -1; // Error |
| 45 | } |
| 46 | DCHECK(array->IsArrayInstance() && !array->IsObjectArray()); |
| 47 | uint32_t size = (uint32_t)table[2] | (((uint32_t)table[3]) << 16); |
| 48 | if (UNLIKELY(static_cast<int32_t>(size) > array->GetLength())) { |
| 49 | Thread::Current()->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;", |
| 50 | "failed array fill. length=%d; index=%d", array->GetLength(), size); |
| 51 | return -1; // Error |
| 52 | } |
| 53 | uint16_t width = table[1]; |
| 54 | uint32_t size_in_bytes = size * width; |
| 55 | memcpy((char*)array + Array::DataOffset(width).Int32Value(), (char*)&table[4], size_in_bytes); |
| 56 | return 0; // Success |
| 57 | } |
| 58 | |
| 59 | } // namespace art |