blob: 9e1d915a0ff762251f713a4cbdd666ac21830676 [file] [log] [blame]
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001/*
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 "interpreter_common.h"
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010018#include "mirror/array-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020019
20namespace art {
21namespace interpreter {
22
Sebastien Hertzc61124b2013-09-10 11:44:19 +020023static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh,
24 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame,
25 JValue* result, size_t arg_offset)
26 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020027
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020028// Assign register 'src_reg' from shadow_frame to register 'dest_reg' into new_shadow_frame.
Ian Rogersef7d42f2014-01-06 12:55:46 -080029static inline void AssignRegister(ShadowFrame* new_shadow_frame, const ShadowFrame& shadow_frame,
30 size_t dest_reg, size_t src_reg)
31 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020032 // If both register locations contains the same value, the register probably holds a reference.
33 int32_t src_value = shadow_frame.GetVReg(src_reg);
Mathieu Chartier4e305412014-02-19 10:54:44 -080034 mirror::Object* o = shadow_frame.GetVRegReference<kVerifyNone>(src_reg);
Ian Rogersef7d42f2014-01-06 12:55:46 -080035 if (src_value == reinterpret_cast<intptr_t>(o)) {
36 new_shadow_frame->SetVRegReference(dest_reg, o);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020037 } else {
Ian Rogersef7d42f2014-01-06 12:55:46 -080038 new_shadow_frame->SetVReg(dest_reg, src_value);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020039 }
40}
41
Sebastien Hertzc61124b2013-09-10 11:44:19 +020042template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +010043bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc61124b2013-09-10 11:44:19 +020044 const Instruction* inst, uint16_t inst_data, JValue* result) {
45 // Compute method information.
Sebastien Hertz8ece0502013-08-07 11:26:41 +020046 MethodHelper mh(method);
47 const DexFile::CodeItem* code_item = mh.GetCodeItem();
Sebastien Hertzc61124b2013-09-10 11:44:19 +020048 const uint16_t num_ins = (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020049 uint16_t num_regs;
Sebastien Hertz8ece0502013-08-07 11:26:41 +020050 if (LIKELY(code_item != NULL)) {
51 num_regs = code_item->registers_size_;
Sebastien Hertzc61124b2013-09-10 11:44:19 +020052 DCHECK_EQ(num_ins, code_item->ins_size_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020053 } else {
54 DCHECK(method->IsNative() || method->IsProxyMethod());
Sebastien Hertzc61124b2013-09-10 11:44:19 +020055 num_regs = num_ins;
Sebastien Hertz8ece0502013-08-07 11:26:41 +020056 }
57
Sebastien Hertzc61124b2013-09-10 11:44:19 +020058 // Allocate shadow frame on the stack.
Mathieu Chartiere861ebd2013-10-09 15:01:21 -070059 const char* old_cause = self->StartAssertNoThreadSuspension("DoCall");
Sebastien Hertz8ece0502013-08-07 11:26:41 +020060 void* memory = alloca(ShadowFrame::ComputeSize(num_regs));
61 ShadowFrame* new_shadow_frame(ShadowFrame::Create(num_regs, &shadow_frame, method, 0, memory));
Sebastien Hertzc61124b2013-09-10 11:44:19 +020062
63 // Initialize new shadow frame.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020064 const size_t first_dest_reg = num_regs - num_ins;
Jeff Haoa3faaf42013-09-03 19:07:00 -070065 if (do_assignability_check) {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020066 // Slow path: we need to do runtime check on reference assignment. We need to load the shorty
67 // to get the exact type of each reference argument.
68 const DexFile::TypeList* params = mh.GetParameterTypeList();
69 const char* shorty = mh.GetShorty();
70
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020071 // TODO: find a cleaner way to separate non-range and range information without duplicating code.
72 uint32_t arg[5]; // only used in invoke-XXX.
73 uint32_t vregC; // only used in invoke-XXX-range.
74 if (is_range) {
75 vregC = inst->VRegC_3rc();
76 } else {
77 inst->GetArgs(arg, inst_data);
78 }
Sebastien Hertz9119c5f2013-12-16 11:31:45 +010079
80 // Handle receiver apart since it's not part of the shorty.
81 size_t dest_reg = first_dest_reg;
82 size_t arg_offset = 0;
83 if (!method->IsStatic()) {
84 size_t receiver_reg = (is_range) ? vregC : arg[0];
85 new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg));
86 ++dest_reg;
87 ++arg_offset;
88 }
Ian Rogersef7d42f2014-01-06 12:55:46 -080089 for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020090 DCHECK_LT(shorty_pos + 1, mh.GetShortyLength());
91 const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset];
92 switch (shorty[shorty_pos + 1]) {
93 case 'L': {
94 Object* o = shadow_frame.GetVRegReference(src_reg);
95 if (do_assignability_check && o != NULL) {
96 Class* arg_type = mh.GetClassFromTypeIdx(params->GetTypeItem(shorty_pos).type_idx_);
97 if (arg_type == NULL) {
98 CHECK(self->IsExceptionPending());
Mathieu Chartiere861ebd2013-10-09 15:01:21 -070099 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200100 return false;
101 }
102 if (!o->VerifierInstanceOf(arg_type)) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700103 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200104 // This should never happen.
105 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(),
106 "Ljava/lang/VirtualMachineError;",
107 "Invoking %s with bad arg %d, type '%s' not instance of '%s'",
108 mh.GetName(), shorty_pos,
109 ClassHelper(o->GetClass()).GetDescriptor(),
110 ClassHelper(arg_type).GetDescriptor());
111 return false;
112 }
Jeff Haoa3faaf42013-09-03 19:07:00 -0700113 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200114 new_shadow_frame->SetVRegReference(dest_reg, o);
115 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700116 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200117 case 'J': case 'D': {
118 uint64_t wide_value = (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << 32) |
119 static_cast<uint32_t>(shadow_frame.GetVReg(src_reg));
120 new_shadow_frame->SetVRegLong(dest_reg, wide_value);
121 ++dest_reg;
122 ++arg_offset;
123 break;
124 }
125 default:
126 new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg));
127 break;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200128 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200129 }
130 } else {
131 // Fast path: no extra checks.
132 if (is_range) {
133 const uint16_t first_src_reg = inst->VRegC_3rc();
134 for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < num_regs;
135 ++dest_reg, ++src_reg) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800136 AssignRegister(new_shadow_frame, shadow_frame, dest_reg, src_reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200137 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200138 } else {
139 DCHECK_LE(num_ins, 5U);
140 uint16_t regList = inst->Fetch16(2);
141 uint16_t count = num_ins;
142 if (count == 5) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800143 AssignRegister(new_shadow_frame, shadow_frame, first_dest_reg + 4U, (inst_data >> 8) & 0x0f);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200144 --count;
145 }
146 for (size_t arg_index = 0; arg_index < count; ++arg_index, regList >>= 4) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800147 AssignRegister(new_shadow_frame, shadow_frame, first_dest_reg + arg_index, regList & 0x0f);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200148 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200149 }
150 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700151 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200152
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200153 // Do the call now.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200154 if (LIKELY(Runtime::Current()->IsStarted())) {
Ian Rogers1d99e452014-01-02 17:36:41 -0800155 if (kIsDebugBuild && method->GetEntryPointFromInterpreter() == nullptr) {
156 LOG(FATAL) << "Attempt to invoke non-executable method: " << PrettyMethod(method);
157 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200158 (method->GetEntryPointFromInterpreter())(self, mh, code_item, new_shadow_frame, result);
159 } else {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200160 UnstartedRuntimeInvoke(self, mh, code_item, new_shadow_frame, result, first_dest_reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200161 }
162 return !self->IsExceptionPending();
163}
164
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100165template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200166bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
167 Thread* self, JValue* result) {
168 DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY ||
169 inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE);
170 const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c();
171 if (!is_range) {
172 // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments.
173 CHECK_LE(length, 5);
174 }
175 if (UNLIKELY(length < 0)) {
176 ThrowNegativeArraySizeException(length);
177 return false;
178 }
179 uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
180 Class* arrayClass = ResolveVerifyAndClinit(type_idx, shadow_frame.GetMethod(),
181 self, false, do_access_check);
182 if (UNLIKELY(arrayClass == NULL)) {
183 DCHECK(self->IsExceptionPending());
184 return false;
185 }
186 CHECK(arrayClass->IsArrayClass());
187 Class* componentClass = arrayClass->GetComponentType();
188 if (UNLIKELY(componentClass->IsPrimitive() && !componentClass->IsPrimitiveInt())) {
189 if (componentClass->IsPrimitiveLong() || componentClass->IsPrimitiveDouble()) {
190 ThrowRuntimeException("Bad filled array request for type %s",
191 PrettyDescriptor(componentClass).c_str());
192 } else {
193 self->ThrowNewExceptionF(shadow_frame.GetCurrentLocationForThrow(),
194 "Ljava/lang/InternalError;",
Brian Carlstrom4fa0bcd2013-12-10 11:24:21 -0800195 "Found type %s; filled-new-array not implemented for anything but 'int'",
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200196 PrettyDescriptor(componentClass).c_str());
197 }
198 return false;
199 }
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800200 Object* newArray = Array::Alloc<true>(self, arrayClass, length);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200201 if (UNLIKELY(newArray == NULL)) {
202 DCHECK(self->IsExceptionPending());
203 return false;
204 }
Sebastien Hertzabff6432014-01-27 18:01:39 +0100205 uint32_t arg[5]; // only used in filled-new-array.
206 uint32_t vregC; // only used in filled-new-array-range.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200207 if (is_range) {
Sebastien Hertzabff6432014-01-27 18:01:39 +0100208 vregC = inst->VRegC_3rc();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200209 } else {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200210 inst->GetArgs(arg);
Sebastien Hertzabff6432014-01-27 18:01:39 +0100211 }
212 const bool is_primitive_int_component = componentClass->IsPrimitiveInt();
213 for (int32_t i = 0; i < length; ++i) {
214 size_t src_reg = is_range ? vregC + i : arg[i];
215 if (is_primitive_int_component) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100216 newArray->AsIntArray()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVReg(src_reg));
Sebastien Hertzabff6432014-01-27 18:01:39 +0100217 } else {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100218 newArray->AsObjectArray<Object>()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVRegReference(src_reg));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200219 }
220 }
221
222 result->SetL(newArray);
223 return true;
224}
225
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100226// TODO fix thread analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
227template<typename T>
228static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array, int32_t count)
229 NO_THREAD_SAFETY_ANALYSIS {
230 Runtime* runtime = Runtime::Current();
231 for (int32_t i = 0; i < count; ++i) {
232 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i));
233 }
234}
235
236void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
237 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
238 DCHECK(Runtime::Current()->IsActiveTransaction());
239 DCHECK(array != nullptr);
240 DCHECK_LE(count, array->GetLength());
241 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType();
242 switch (primitive_component_type) {
243 case Primitive::kPrimBoolean:
244 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count);
245 break;
246 case Primitive::kPrimByte:
247 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count);
248 break;
249 case Primitive::kPrimChar:
250 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count);
251 break;
252 case Primitive::kPrimShort:
253 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count);
254 break;
255 case Primitive::kPrimInt:
256 case Primitive::kPrimFloat:
257 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count);
258 break;
259 case Primitive::kPrimLong:
260 case Primitive::kPrimDouble:
261 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count);
262 break;
263 default:
264 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type
265 << " in fill-array-data";
266 break;
267 }
268}
269
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200270static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh,
271 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame,
272 JValue* result, size_t arg_offset) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200273 // In a runtime that's not started we intercept certain methods to avoid complicated dependency
274 // problems in core libraries.
275 std::string name(PrettyMethod(shadow_frame->GetMethod()));
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800276 if (name == "java.lang.Class java.lang.Class.forName(java.lang.String)"
277 || name == "java.lang.Class java.lang.VMClassLoader.loadClass(java.lang.String, boolean)") {
278 // TODO Class#forName should actually call Class::EnsureInitialized always. Support for the
279 // other variants that take more arguments should also be added.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200280 std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset)->AsString()->ToModifiedUtf8().c_str()));
Mathieu Chartier590fee92013-09-13 13:46:47 -0700281
282 SirtRef<ClassLoader> class_loader(self, nullptr); // shadow_frame.GetMethod()->GetDeclaringClass()->GetClassLoader();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200283 Class* found = Runtime::Current()->GetClassLinker()->FindClass(descriptor.c_str(),
284 class_loader);
285 CHECK(found != NULL) << "Class.forName failed in un-started runtime for class: "
286 << PrettyDescriptor(descriptor);
287 result->SetL(found);
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800288 } else if (name == "java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String)") {
289 SirtRef<ClassLoader> class_loader(self, down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset)));
290 std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset + 1)->AsString()->ToModifiedUtf8().c_str()));
291
292 Class* found = Runtime::Current()->GetClassLinker()->FindClass(descriptor.c_str(),
293 class_loader);
294 result->SetL(found);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200295 } else if (name == "java.lang.Object java.lang.Class.newInstance()") {
296 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
297 ArtMethod* c = klass->FindDeclaredDirectMethod("<init>", "()V");
298 CHECK(c != NULL);
299 SirtRef<Object> obj(self, klass->AllocObject(self));
300 CHECK(obj.get() != NULL);
301 EnterInterpreterFromInvoke(self, c, obj.get(), NULL, NULL);
302 result->SetL(obj.get());
303 } else if (name == "java.lang.reflect.Field java.lang.Class.getDeclaredField(java.lang.String)") {
304 // Special managed code cut-out to allow field lookup in a un-started runtime that'd fail
305 // going the reflective Dex way.
306 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
307 String* name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString();
308 ArtField* found = NULL;
309 FieldHelper fh;
310 ObjectArray<ArtField>* fields = klass->GetIFields();
311 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) {
312 ArtField* f = fields->Get(i);
313 fh.ChangeField(f);
314 if (name->Equals(fh.GetName())) {
315 found = f;
316 }
317 }
318 if (found == NULL) {
319 fields = klass->GetSFields();
320 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) {
321 ArtField* f = fields->Get(i);
322 fh.ChangeField(f);
323 if (name->Equals(fh.GetName())) {
324 found = f;
325 }
326 }
327 }
328 CHECK(found != NULL)
329 << "Failed to find field in Class.getDeclaredField in un-started runtime. name="
330 << name->ToModifiedUtf8() << " class=" << PrettyDescriptor(klass);
331 // TODO: getDeclaredField calls GetType once the field is found to ensure a
332 // NoClassDefFoundError is thrown if the field's type cannot be resolved.
333 Class* jlr_Field = self->DecodeJObject(WellKnownClasses::java_lang_reflect_Field)->AsClass();
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800334 SirtRef<Object> field(self, jlr_Field->AllocNonMovableObject(self));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200335 CHECK(field.get() != NULL);
336 ArtMethod* c = jlr_Field->FindDeclaredDirectMethod("<init>", "(Ljava/lang/reflect/ArtField;)V");
337 uint32_t args[1];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800338 args[0] = StackReference<mirror::Object>::FromMirrorPtr(found).AsVRegValue();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200339 EnterInterpreterFromInvoke(self, c, field.get(), args, NULL);
340 result->SetL(field.get());
341 } else if (name == "void java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)" ||
342 name == "void java.lang.System.arraycopy(char[], int, char[], int, int)") {
343 // Special case array copying without initializing System.
344 Class* ctype = shadow_frame->GetVRegReference(arg_offset)->GetClass()->GetComponentType();
345 jint srcPos = shadow_frame->GetVReg(arg_offset + 1);
346 jint dstPos = shadow_frame->GetVReg(arg_offset + 3);
347 jint length = shadow_frame->GetVReg(arg_offset + 4);
348 if (!ctype->IsPrimitive()) {
349 ObjectArray<Object>* src = shadow_frame->GetVRegReference(arg_offset)->AsObjectArray<Object>();
350 ObjectArray<Object>* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsObjectArray<Object>();
351 for (jint i = 0; i < length; ++i) {
352 dst->Set(dstPos + i, src->Get(srcPos + i));
353 }
354 } else if (ctype->IsPrimitiveChar()) {
355 CharArray* src = shadow_frame->GetVRegReference(arg_offset)->AsCharArray();
356 CharArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsCharArray();
357 for (jint i = 0; i < length; ++i) {
358 dst->Set(dstPos + i, src->Get(srcPos + i));
359 }
360 } else if (ctype->IsPrimitiveInt()) {
361 IntArray* src = shadow_frame->GetVRegReference(arg_offset)->AsIntArray();
362 IntArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsIntArray();
363 for (jint i = 0; i < length; ++i) {
364 dst->Set(dstPos + i, src->Get(srcPos + i));
365 }
366 } else {
367 UNIMPLEMENTED(FATAL) << "System.arraycopy of unexpected type: " << PrettyDescriptor(ctype);
368 }
369 } else {
370 // Not special, continue with regular interpreter execution.
371 artInterpreterToInterpreterBridge(self, mh, code_item, shadow_frame, result);
372 }
373}
374
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200375// Explicit DoCall template function declarations.
Sebastien Hertzc6714852013-09-30 16:42:32 +0200376#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \
377 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100378 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \
379 ShadowFrame& shadow_frame, \
Sebastien Hertzc6714852013-09-30 16:42:32 +0200380 const Instruction* inst, uint16_t inst_data, \
381 JValue* result)
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200382EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false);
383EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true);
384EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false);
385EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true);
386#undef EXPLICIT_DO_CALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200387
388// Explicit DoFilledNewArray template function declarations.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100389#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \
390 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
391 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \
392 const ShadowFrame& shadow_frame, \
393 Thread* self, JValue* result)
394#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \
395 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \
396 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \
397 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \
398 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active)
399EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false);
400EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true);
401#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200402#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL
403
404} // namespace interpreter
405} // namespace art