blob: 297f1a8f0416573077e0414e329446604b8e8890 [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.
Andreas Gampe7104cbf2014-03-21 11:44:43 -070033 // Uint required, so that sign extension does not make this wrong on 64b systems
34 uint32_t src_value = shadow_frame.GetVReg(src_reg);
Mathieu Chartier4e305412014-02-19 10:54:44 -080035 mirror::Object* o = shadow_frame.GetVRegReference<kVerifyNone>(src_reg);
Andreas Gampe7104cbf2014-03-21 11:44:43 -070036 if (src_value == reinterpret_cast<uintptr_t>(o)) {
Ian Rogersef7d42f2014-01-06 12:55:46 -080037 new_shadow_frame->SetVRegReference(dest_reg, o);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020038 } else {
Ian Rogersef7d42f2014-01-06 12:55:46 -080039 new_shadow_frame->SetVReg(dest_reg, src_value);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020040 }
41}
42
Sebastien Hertzc61124b2013-09-10 11:44:19 +020043template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +010044bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc61124b2013-09-10 11:44:19 +020045 const Instruction* inst, uint16_t inst_data, JValue* result) {
46 // Compute method information.
Sebastien Hertz8ece0502013-08-07 11:26:41 +020047 MethodHelper mh(method);
48 const DexFile::CodeItem* code_item = mh.GetCodeItem();
Sebastien Hertzc61124b2013-09-10 11:44:19 +020049 const uint16_t num_ins = (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020050 uint16_t num_regs;
Sebastien Hertz8ece0502013-08-07 11:26:41 +020051 if (LIKELY(code_item != NULL)) {
52 num_regs = code_item->registers_size_;
Sebastien Hertzc61124b2013-09-10 11:44:19 +020053 DCHECK_EQ(num_ins, code_item->ins_size_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020054 } else {
55 DCHECK(method->IsNative() || method->IsProxyMethod());
Sebastien Hertzc61124b2013-09-10 11:44:19 +020056 num_regs = num_ins;
Sebastien Hertz8ece0502013-08-07 11:26:41 +020057 }
58
Sebastien Hertzc61124b2013-09-10 11:44:19 +020059 // Allocate shadow frame on the stack.
Mathieu Chartiere861ebd2013-10-09 15:01:21 -070060 const char* old_cause = self->StartAssertNoThreadSuspension("DoCall");
Sebastien Hertz8ece0502013-08-07 11:26:41 +020061 void* memory = alloca(ShadowFrame::ComputeSize(num_regs));
62 ShadowFrame* new_shadow_frame(ShadowFrame::Create(num_regs, &shadow_frame, method, 0, memory));
Sebastien Hertzc61124b2013-09-10 11:44:19 +020063
64 // Initialize new shadow frame.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020065 const size_t first_dest_reg = num_regs - num_ins;
Jeff Haoa3faaf42013-09-03 19:07:00 -070066 if (do_assignability_check) {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020067 // Slow path: we need to do runtime check on reference assignment. We need to load the shorty
68 // to get the exact type of each reference argument.
69 const DexFile::TypeList* params = mh.GetParameterTypeList();
70 const char* shorty = mh.GetShorty();
71
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020072 // TODO: find a cleaner way to separate non-range and range information without duplicating code.
73 uint32_t arg[5]; // only used in invoke-XXX.
74 uint32_t vregC; // only used in invoke-XXX-range.
75 if (is_range) {
76 vregC = inst->VRegC_3rc();
77 } else {
78 inst->GetArgs(arg, inst_data);
79 }
Sebastien Hertz9119c5f2013-12-16 11:31:45 +010080
81 // Handle receiver apart since it's not part of the shorty.
82 size_t dest_reg = first_dest_reg;
83 size_t arg_offset = 0;
84 if (!method->IsStatic()) {
85 size_t receiver_reg = (is_range) ? vregC : arg[0];
86 new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg));
87 ++dest_reg;
88 ++arg_offset;
89 }
Ian Rogersef7d42f2014-01-06 12:55:46 -080090 for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +020091 DCHECK_LT(shorty_pos + 1, mh.GetShortyLength());
92 const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset];
93 switch (shorty[shorty_pos + 1]) {
94 case 'L': {
95 Object* o = shadow_frame.GetVRegReference(src_reg);
96 if (do_assignability_check && o != NULL) {
97 Class* arg_type = mh.GetClassFromTypeIdx(params->GetTypeItem(shorty_pos).type_idx_);
98 if (arg_type == NULL) {
99 CHECK(self->IsExceptionPending());
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700100 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200101 return false;
102 }
103 if (!o->VerifierInstanceOf(arg_type)) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700104 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200105 // This should never happen.
106 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(),
107 "Ljava/lang/VirtualMachineError;",
108 "Invoking %s with bad arg %d, type '%s' not instance of '%s'",
109 mh.GetName(), shorty_pos,
110 ClassHelper(o->GetClass()).GetDescriptor(),
111 ClassHelper(arg_type).GetDescriptor());
112 return false;
113 }
Jeff Haoa3faaf42013-09-03 19:07:00 -0700114 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200115 new_shadow_frame->SetVRegReference(dest_reg, o);
116 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700117 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200118 case 'J': case 'D': {
119 uint64_t wide_value = (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << 32) |
120 static_cast<uint32_t>(shadow_frame.GetVReg(src_reg));
121 new_shadow_frame->SetVRegLong(dest_reg, wide_value);
122 ++dest_reg;
123 ++arg_offset;
124 break;
125 }
126 default:
127 new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg));
128 break;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200129 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200130 }
131 } else {
132 // Fast path: no extra checks.
133 if (is_range) {
134 const uint16_t first_src_reg = inst->VRegC_3rc();
135 for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < num_regs;
136 ++dest_reg, ++src_reg) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800137 AssignRegister(new_shadow_frame, shadow_frame, dest_reg, src_reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200138 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200139 } else {
140 DCHECK_LE(num_ins, 5U);
141 uint16_t regList = inst->Fetch16(2);
142 uint16_t count = num_ins;
143 if (count == 5) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800144 AssignRegister(new_shadow_frame, shadow_frame, first_dest_reg + 4U, (inst_data >> 8) & 0x0f);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200145 --count;
146 }
147 for (size_t arg_index = 0; arg_index < count; ++arg_index, regList >>= 4) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800148 AssignRegister(new_shadow_frame, shadow_frame, first_dest_reg + arg_index, regList & 0x0f);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200149 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200150 }
151 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700152 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200153
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200154 // Do the call now.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200155 if (LIKELY(Runtime::Current()->IsStarted())) {
Ian Rogers1d99e452014-01-02 17:36:41 -0800156 if (kIsDebugBuild && method->GetEntryPointFromInterpreter() == nullptr) {
157 LOG(FATAL) << "Attempt to invoke non-executable method: " << PrettyMethod(method);
158 }
Hiroshi Yamauchi563b47c2014-02-28 17:18:37 -0800159 if (kIsDebugBuild && Runtime::Current()->GetInstrumentation()->IsForcedInterpretOnly() &&
160 !method->IsNative() && !method->IsProxyMethod() &&
161 method->GetEntryPointFromInterpreter() == artInterpreterToCompiledCodeBridge) {
162 LOG(FATAL) << "Attempt to call compiled code when -Xint: " << PrettyMethod(method);
163 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200164 (method->GetEntryPointFromInterpreter())(self, mh, code_item, new_shadow_frame, result);
165 } else {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200166 UnstartedRuntimeInvoke(self, mh, code_item, new_shadow_frame, result, first_dest_reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200167 }
168 return !self->IsExceptionPending();
169}
170
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100171template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200172bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
173 Thread* self, JValue* result) {
174 DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY ||
175 inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE);
176 const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c();
177 if (!is_range) {
178 // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments.
179 CHECK_LE(length, 5);
180 }
181 if (UNLIKELY(length < 0)) {
182 ThrowNegativeArraySizeException(length);
183 return false;
184 }
185 uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
186 Class* arrayClass = ResolveVerifyAndClinit(type_idx, shadow_frame.GetMethod(),
187 self, false, do_access_check);
188 if (UNLIKELY(arrayClass == NULL)) {
189 DCHECK(self->IsExceptionPending());
190 return false;
191 }
192 CHECK(arrayClass->IsArrayClass());
193 Class* componentClass = arrayClass->GetComponentType();
194 if (UNLIKELY(componentClass->IsPrimitive() && !componentClass->IsPrimitiveInt())) {
195 if (componentClass->IsPrimitiveLong() || componentClass->IsPrimitiveDouble()) {
196 ThrowRuntimeException("Bad filled array request for type %s",
197 PrettyDescriptor(componentClass).c_str());
198 } else {
199 self->ThrowNewExceptionF(shadow_frame.GetCurrentLocationForThrow(),
200 "Ljava/lang/InternalError;",
Brian Carlstrom4fa0bcd2013-12-10 11:24:21 -0800201 "Found type %s; filled-new-array not implemented for anything but 'int'",
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200202 PrettyDescriptor(componentClass).c_str());
203 }
204 return false;
205 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800206 Object* newArray = Array::Alloc<true>(self, arrayClass, length, arrayClass->GetComponentSize(),
207 Runtime::Current()->GetHeap()->GetCurrentAllocator());
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200208 if (UNLIKELY(newArray == NULL)) {
209 DCHECK(self->IsExceptionPending());
210 return false;
211 }
Sebastien Hertzabff6432014-01-27 18:01:39 +0100212 uint32_t arg[5]; // only used in filled-new-array.
213 uint32_t vregC; // only used in filled-new-array-range.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200214 if (is_range) {
Sebastien Hertzabff6432014-01-27 18:01:39 +0100215 vregC = inst->VRegC_3rc();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200216 } else {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200217 inst->GetArgs(arg);
Sebastien Hertzabff6432014-01-27 18:01:39 +0100218 }
219 const bool is_primitive_int_component = componentClass->IsPrimitiveInt();
220 for (int32_t i = 0; i < length; ++i) {
221 size_t src_reg = is_range ? vregC + i : arg[i];
222 if (is_primitive_int_component) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100223 newArray->AsIntArray()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVReg(src_reg));
Sebastien Hertzabff6432014-01-27 18:01:39 +0100224 } else {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100225 newArray->AsObjectArray<Object>()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVRegReference(src_reg));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200226 }
227 }
228
229 result->SetL(newArray);
230 return true;
231}
232
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100233// TODO fix thread analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
234template<typename T>
235static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array, int32_t count)
236 NO_THREAD_SAFETY_ANALYSIS {
237 Runtime* runtime = Runtime::Current();
238 for (int32_t i = 0; i < count; ++i) {
239 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i));
240 }
241}
242
243void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
244 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
245 DCHECK(Runtime::Current()->IsActiveTransaction());
246 DCHECK(array != nullptr);
247 DCHECK_LE(count, array->GetLength());
248 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType();
249 switch (primitive_component_type) {
250 case Primitive::kPrimBoolean:
251 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count);
252 break;
253 case Primitive::kPrimByte:
254 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count);
255 break;
256 case Primitive::kPrimChar:
257 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count);
258 break;
259 case Primitive::kPrimShort:
260 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count);
261 break;
262 case Primitive::kPrimInt:
263 case Primitive::kPrimFloat:
264 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count);
265 break;
266 case Primitive::kPrimLong:
267 case Primitive::kPrimDouble:
268 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count);
269 break;
270 default:
271 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type
272 << " in fill-array-data";
273 break;
274 }
275}
276
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200277static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh,
278 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame,
279 JValue* result, size_t arg_offset) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200280 // In a runtime that's not started we intercept certain methods to avoid complicated dependency
281 // problems in core libraries.
282 std::string name(PrettyMethod(shadow_frame->GetMethod()));
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800283 if (name == "java.lang.Class java.lang.Class.forName(java.lang.String)"
284 || name == "java.lang.Class java.lang.VMClassLoader.loadClass(java.lang.String, boolean)") {
285 // TODO Class#forName should actually call Class::EnsureInitialized always. Support for the
286 // other variants that take more arguments should also be added.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200287 std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset)->AsString()->ToModifiedUtf8().c_str()));
Mathieu Chartier590fee92013-09-13 13:46:47 -0700288
289 SirtRef<ClassLoader> class_loader(self, nullptr); // shadow_frame.GetMethod()->GetDeclaringClass()->GetClassLoader();
Ian Rogers98379392014-02-24 16:53:16 -0800290 Class* found = Runtime::Current()->GetClassLinker()->FindClass(self, descriptor.c_str(),
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200291 class_loader);
292 CHECK(found != NULL) << "Class.forName failed in un-started runtime for class: "
293 << PrettyDescriptor(descriptor);
294 result->SetL(found);
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800295 } else if (name == "java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String)") {
296 SirtRef<ClassLoader> class_loader(self, down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset)));
297 std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset + 1)->AsString()->ToModifiedUtf8().c_str()));
298
Ian Rogers98379392014-02-24 16:53:16 -0800299 Class* found = Runtime::Current()->GetClassLinker()->FindClass(self, descriptor.c_str(),
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800300 class_loader);
301 result->SetL(found);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200302 } else if (name == "java.lang.Object java.lang.Class.newInstance()") {
303 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
304 ArtMethod* c = klass->FindDeclaredDirectMethod("<init>", "()V");
305 CHECK(c != NULL);
306 SirtRef<Object> obj(self, klass->AllocObject(self));
307 CHECK(obj.get() != NULL);
308 EnterInterpreterFromInvoke(self, c, obj.get(), NULL, NULL);
309 result->SetL(obj.get());
310 } else if (name == "java.lang.reflect.Field java.lang.Class.getDeclaredField(java.lang.String)") {
311 // Special managed code cut-out to allow field lookup in a un-started runtime that'd fail
312 // going the reflective Dex way.
313 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
314 String* name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString();
315 ArtField* found = NULL;
316 FieldHelper fh;
317 ObjectArray<ArtField>* fields = klass->GetIFields();
318 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) {
319 ArtField* f = fields->Get(i);
320 fh.ChangeField(f);
321 if (name->Equals(fh.GetName())) {
322 found = f;
323 }
324 }
325 if (found == NULL) {
326 fields = klass->GetSFields();
327 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) {
328 ArtField* f = fields->Get(i);
329 fh.ChangeField(f);
330 if (name->Equals(fh.GetName())) {
331 found = f;
332 }
333 }
334 }
335 CHECK(found != NULL)
336 << "Failed to find field in Class.getDeclaredField in un-started runtime. name="
337 << name->ToModifiedUtf8() << " class=" << PrettyDescriptor(klass);
338 // TODO: getDeclaredField calls GetType once the field is found to ensure a
339 // NoClassDefFoundError is thrown if the field's type cannot be resolved.
340 Class* jlr_Field = self->DecodeJObject(WellKnownClasses::java_lang_reflect_Field)->AsClass();
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800341 SirtRef<Object> field(self, jlr_Field->AllocNonMovableObject(self));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200342 CHECK(field.get() != NULL);
343 ArtMethod* c = jlr_Field->FindDeclaredDirectMethod("<init>", "(Ljava/lang/reflect/ArtField;)V");
344 uint32_t args[1];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800345 args[0] = StackReference<mirror::Object>::FromMirrorPtr(found).AsVRegValue();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200346 EnterInterpreterFromInvoke(self, c, field.get(), args, NULL);
347 result->SetL(field.get());
348 } else if (name == "void java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)" ||
349 name == "void java.lang.System.arraycopy(char[], int, char[], int, int)") {
350 // Special case array copying without initializing System.
351 Class* ctype = shadow_frame->GetVRegReference(arg_offset)->GetClass()->GetComponentType();
352 jint srcPos = shadow_frame->GetVReg(arg_offset + 1);
353 jint dstPos = shadow_frame->GetVReg(arg_offset + 3);
354 jint length = shadow_frame->GetVReg(arg_offset + 4);
355 if (!ctype->IsPrimitive()) {
356 ObjectArray<Object>* src = shadow_frame->GetVRegReference(arg_offset)->AsObjectArray<Object>();
357 ObjectArray<Object>* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsObjectArray<Object>();
358 for (jint i = 0; i < length; ++i) {
359 dst->Set(dstPos + i, src->Get(srcPos + i));
360 }
361 } else if (ctype->IsPrimitiveChar()) {
362 CharArray* src = shadow_frame->GetVRegReference(arg_offset)->AsCharArray();
363 CharArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsCharArray();
364 for (jint i = 0; i < length; ++i) {
365 dst->Set(dstPos + i, src->Get(srcPos + i));
366 }
367 } else if (ctype->IsPrimitiveInt()) {
368 IntArray* src = shadow_frame->GetVRegReference(arg_offset)->AsIntArray();
369 IntArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsIntArray();
370 for (jint i = 0; i < length; ++i) {
371 dst->Set(dstPos + i, src->Get(srcPos + i));
372 }
373 } else {
374 UNIMPLEMENTED(FATAL) << "System.arraycopy of unexpected type: " << PrettyDescriptor(ctype);
375 }
376 } else {
377 // Not special, continue with regular interpreter execution.
378 artInterpreterToInterpreterBridge(self, mh, code_item, shadow_frame, result);
379 }
380}
381
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200382// Explicit DoCall template function declarations.
Sebastien Hertzc6714852013-09-30 16:42:32 +0200383#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \
384 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100385 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \
386 ShadowFrame& shadow_frame, \
Sebastien Hertzc6714852013-09-30 16:42:32 +0200387 const Instruction* inst, uint16_t inst_data, \
388 JValue* result)
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200389EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false);
390EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true);
391EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false);
392EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true);
393#undef EXPLICIT_DO_CALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200394
395// Explicit DoFilledNewArray template function declarations.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100396#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \
397 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
398 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \
399 const ShadowFrame& shadow_frame, \
400 Thread* self, JValue* result)
401#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \
402 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \
403 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \
404 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \
405 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active)
406EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false);
407EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true);
408#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200409#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL
410
411} // namespace interpreter
412} // namespace art