blob: ca0c92e6d58d75b0d9f24e1b7f8d1d4210fca216 [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"
Ian Rogers62d6c772013-02-27 08:32:07 -080018#include "common_throws.h"
Elliott Hughesaf778e62012-05-01 18:45:31 -070019#include "dex_instruction.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080020#include "mirror/array.h"
21#include "mirror/object-inl.h"
Ian Rogers57b86d42012-03-27 16:05:41 -070022
23namespace art {
24
25/*
26 * Fill the array with predefined constant values, throwing exceptions if the array is null or
27 * not of sufficient length.
28 *
29 * NOTE: When dealing with a raw dex file, the data to be copied uses
30 * little-endian ordering. Require that oat2dex do any required swapping
31 * so this routine can get by with a memcpy().
32 *
33 * Format of the data:
34 * ushort ident = 0x0300 magic value
35 * ushort width width of each element in the table
36 * uint size number of elements in the table
37 * ubyte data[size*width] table of data values (may contain a single-byte
38 * padding at the end)
39 */
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080040extern "C" int artHandleFillArrayDataFromCode(mirror::Array* array,
Logan Chien19c350a2012-05-01 19:21:32 +080041 const Instruction::ArrayDataPayload* payload,
Brian Carlstromea46f952013-07-30 01:26:50 -070042 Thread* self, mirror::ArtMethod** sp)
Ian Rogersb726dcb2012-09-05 08:57:23 -070043 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers57b86d42012-03-27 16:05:41 -070044 FinishCalleeSaveFrameSetup(self, sp, Runtime::kRefsOnly);
Elliott Hughesaf778e62012-05-01 18:45:31 -070045 DCHECK_EQ(payload->ident, static_cast<uint16_t>(Instruction::kArrayDataSignature));
Ian Rogers57b86d42012-03-27 16:05:41 -070046 if (UNLIKELY(array == NULL)) {
Ian Rogers62d6c772013-02-27 08:32:07 -080047 ThrowNullPointerException(NULL, "null array in FILL_ARRAY_DATA");
Ian Rogers57b86d42012-03-27 16:05:41 -070048 return -1; // Error
49 }
50 DCHECK(array->IsArrayInstance() && !array->IsObjectArray());
Elliott Hughesaf778e62012-05-01 18:45:31 -070051 if (UNLIKELY(static_cast<int32_t>(payload->element_count) > array->GetLength())) {
Ian Rogers62d6c772013-02-27 08:32:07 -080052 ThrowLocation throw_location = self->GetCurrentLocationForThrow();
53 self->ThrowNewExceptionF(throw_location, "Ljava/lang/ArrayIndexOutOfBoundsException;",
54 "failed FILL_ARRAY_DATA; length=%d, index=%d",
Ian Rogers7655f292013-07-29 11:07:13 -070055 array->GetLength(), payload->element_count - 1);
Ian Rogers57b86d42012-03-27 16:05:41 -070056 return -1; // Error
57 }
Elliott Hughesaf778e62012-05-01 18:45:31 -070058 uint32_t size_in_bytes = payload->element_count * payload->element_width;
59 memcpy(array->GetRawData(payload->element_width), payload->data, size_in_bytes);
Ian Rogers57b86d42012-03-27 16:05:41 -070060 return 0; // Success
61}
62
63} // namespace art