blob: 62b9cf96cf50b4203226c09d26a97f13deffa2ec [file] [log] [blame]
Ian Rogers57b86d42012-03-27 16:05:41 -07001/*
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 Hughesaf778e62012-05-01 18:45:31 -070018#include "dex_instruction.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070019#include "object.h"
20
21namespace art {
22
23/*
24 * Fill the array with predefined constant values, throwing exceptions if the array is null or
25 * not of sufficient length.
26 *
27 * NOTE: When dealing with a raw dex file, the data to be copied uses
28 * little-endian ordering. Require that oat2dex do any required swapping
29 * so this routine can get by with a memcpy().
30 *
31 * Format of the data:
32 * ushort ident = 0x0300 magic value
33 * ushort width width of each element in the table
34 * uint size number of elements in the table
35 * ubyte data[size*width] table of data values (may contain a single-byte
36 * padding at the end)
37 */
Logan Chien19c350a2012-05-01 19:21:32 +080038extern "C" int artHandleFillArrayDataFromCode(Array* array,
39 const Instruction::ArrayDataPayload* payload,
Ian Rogers00f7d0e2012-07-19 15:28:27 -070040 Thread* self, Method** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070041 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070042 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly);
Elliott Hughesaf778e62012-05-01 18:45:31 -070043 DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature));
Ian Rogers57b86d42012-03-27 16:05:41 -070044 if (UNLIKELY(array == NULL)) {
45 Thread::Current()->ThrowNewExceptionF("Ljava/lang/NullPointerException;",
Elliott Hughesaf778e62012-05-01 18:45:31 -070046 "null array in FILL_ARRAY_DATA");
Ian Rogers57b86d42012-03-27 16:05:41 -070047 return -1; // Error
48 }
49 DCHECK(array->IsArrayInstance() && !array->IsObjectArray());
Elliott Hughesaf778e62012-05-01 18:45:31 -070050 if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) {
Ian Rogers57b86d42012-03-27 16:05:41 -070051 Thread::Current()->ThrowNewExceptionF("Ljava/lang/ArrayIndexOutOfBoundsException;",
Elliott Hughesaf778e62012-05-01 18:45:31 -070052 "failed FILL_ARRAY_DATA; length=%d, index=%d",
53 array->GetLength(), payload->element_count);
Ian Rogers57b86d42012-03-27 16:05:41 -070054 return -1; // Error
55 }
Elliott Hughesaf778e62012-05-01 18:45:31 -070056 uint32_t size_in_bytes = payload->element_count * payload->element_width;
57 memcpy(array->GetRawData(payload->element_width), payload->data, size_in_bytes);
Ian Rogers57b86d42012-03-27 16:05:41 -070058 return 0; // Success
59}
60
61} // namespace art