blob: f76d50c87338a82fdd70225c295a50b78cb11f57 [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 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800200 Object* newArray = Array::Alloc<true>(self, arrayClass, length, arrayClass->GetComponentSize(),
201 Runtime::Current()->GetHeap()->GetCurrentAllocator());
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200202 if (UNLIKELY(newArray == NULL)) {
203 DCHECK(self->IsExceptionPending());
204 return false;
205 }
Sebastien Hertzabff6432014-01-27 18:01:39 +0100206 uint32_t arg[5]; // only used in filled-new-array.
207 uint32_t vregC; // only used in filled-new-array-range.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200208 if (is_range) {
Sebastien Hertzabff6432014-01-27 18:01:39 +0100209 vregC = inst->VRegC_3rc();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200210 } else {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200211 inst->GetArgs(arg);
Sebastien Hertzabff6432014-01-27 18:01:39 +0100212 }
213 const bool is_primitive_int_component = componentClass->IsPrimitiveInt();
214 for (int32_t i = 0; i < length; ++i) {
215 size_t src_reg = is_range ? vregC + i : arg[i];
216 if (is_primitive_int_component) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100217 newArray->AsIntArray()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVReg(src_reg));
Sebastien Hertzabff6432014-01-27 18:01:39 +0100218 } else {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100219 newArray->AsObjectArray<Object>()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVRegReference(src_reg));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200220 }
221 }
222
223 result->SetL(newArray);
224 return true;
225}
226
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100227// TODO fix thread analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
228template<typename T>
229static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array, int32_t count)
230 NO_THREAD_SAFETY_ANALYSIS {
231 Runtime* runtime = Runtime::Current();
232 for (int32_t i = 0; i < count; ++i) {
233 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i));
234 }
235}
236
237void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
238 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
239 DCHECK(Runtime::Current()->IsActiveTransaction());
240 DCHECK(array != nullptr);
241 DCHECK_LE(count, array->GetLength());
242 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType();
243 switch (primitive_component_type) {
244 case Primitive::kPrimBoolean:
245 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count);
246 break;
247 case Primitive::kPrimByte:
248 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count);
249 break;
250 case Primitive::kPrimChar:
251 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count);
252 break;
253 case Primitive::kPrimShort:
254 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count);
255 break;
256 case Primitive::kPrimInt:
257 case Primitive::kPrimFloat:
258 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count);
259 break;
260 case Primitive::kPrimLong:
261 case Primitive::kPrimDouble:
262 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count);
263 break;
264 default:
265 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type
266 << " in fill-array-data";
267 break;
268 }
269}
270
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200271static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh,
272 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame,
273 JValue* result, size_t arg_offset) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200274 // In a runtime that's not started we intercept certain methods to avoid complicated dependency
275 // problems in core libraries.
276 std::string name(PrettyMethod(shadow_frame->GetMethod()));
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800277 if (name == "java.lang.Class java.lang.Class.forName(java.lang.String)"
278 || name == "java.lang.Class java.lang.VMClassLoader.loadClass(java.lang.String, boolean)") {
279 // TODO Class#forName should actually call Class::EnsureInitialized always. Support for the
280 // other variants that take more arguments should also be added.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200281 std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset)->AsString()->ToModifiedUtf8().c_str()));
Mathieu Chartier590fee92013-09-13 13:46:47 -0700282
283 SirtRef<ClassLoader> class_loader(self, nullptr); // shadow_frame.GetMethod()->GetDeclaringClass()->GetClassLoader();
Ian Rogers98379392014-02-24 16:53:16 -0800284 Class* found = Runtime::Current()->GetClassLinker()->FindClass(self, descriptor.c_str(),
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200285 class_loader);
286 CHECK(found != NULL) << "Class.forName failed in un-started runtime for class: "
287 << PrettyDescriptor(descriptor);
288 result->SetL(found);
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800289 } else if (name == "java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String)") {
290 SirtRef<ClassLoader> class_loader(self, down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset)));
291 std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset + 1)->AsString()->ToModifiedUtf8().c_str()));
292
Ian Rogers98379392014-02-24 16:53:16 -0800293 Class* found = Runtime::Current()->GetClassLinker()->FindClass(self, descriptor.c_str(),
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800294 class_loader);
295 result->SetL(found);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200296 } else if (name == "java.lang.Object java.lang.Class.newInstance()") {
297 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
298 ArtMethod* c = klass->FindDeclaredDirectMethod("<init>", "()V");
299 CHECK(c != NULL);
300 SirtRef<Object> obj(self, klass->AllocObject(self));
301 CHECK(obj.get() != NULL);
302 EnterInterpreterFromInvoke(self, c, obj.get(), NULL, NULL);
303 result->SetL(obj.get());
304 } else if (name == "java.lang.reflect.Field java.lang.Class.getDeclaredField(java.lang.String)") {
305 // Special managed code cut-out to allow field lookup in a un-started runtime that'd fail
306 // going the reflective Dex way.
307 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
308 String* name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString();
309 ArtField* found = NULL;
310 FieldHelper fh;
311 ObjectArray<ArtField>* fields = klass->GetIFields();
312 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) {
313 ArtField* f = fields->Get(i);
314 fh.ChangeField(f);
315 if (name->Equals(fh.GetName())) {
316 found = f;
317 }
318 }
319 if (found == NULL) {
320 fields = klass->GetSFields();
321 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) {
322 ArtField* f = fields->Get(i);
323 fh.ChangeField(f);
324 if (name->Equals(fh.GetName())) {
325 found = f;
326 }
327 }
328 }
329 CHECK(found != NULL)
330 << "Failed to find field in Class.getDeclaredField in un-started runtime. name="
331 << name->ToModifiedUtf8() << " class=" << PrettyDescriptor(klass);
332 // TODO: getDeclaredField calls GetType once the field is found to ensure a
333 // NoClassDefFoundError is thrown if the field's type cannot be resolved.
334 Class* jlr_Field = self->DecodeJObject(WellKnownClasses::java_lang_reflect_Field)->AsClass();
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800335 SirtRef<Object> field(self, jlr_Field->AllocNonMovableObject(self));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200336 CHECK(field.get() != NULL);
337 ArtMethod* c = jlr_Field->FindDeclaredDirectMethod("<init>", "(Ljava/lang/reflect/ArtField;)V");
338 uint32_t args[1];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800339 args[0] = StackReference<mirror::Object>::FromMirrorPtr(found).AsVRegValue();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200340 EnterInterpreterFromInvoke(self, c, field.get(), args, NULL);
341 result->SetL(field.get());
342 } else if (name == "void java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)" ||
343 name == "void java.lang.System.arraycopy(char[], int, char[], int, int)") {
344 // Special case array copying without initializing System.
345 Class* ctype = shadow_frame->GetVRegReference(arg_offset)->GetClass()->GetComponentType();
346 jint srcPos = shadow_frame->GetVReg(arg_offset + 1);
347 jint dstPos = shadow_frame->GetVReg(arg_offset + 3);
348 jint length = shadow_frame->GetVReg(arg_offset + 4);
349 if (!ctype->IsPrimitive()) {
350 ObjectArray<Object>* src = shadow_frame->GetVRegReference(arg_offset)->AsObjectArray<Object>();
351 ObjectArray<Object>* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsObjectArray<Object>();
352 for (jint i = 0; i < length; ++i) {
353 dst->Set(dstPos + i, src->Get(srcPos + i));
354 }
355 } else if (ctype->IsPrimitiveChar()) {
356 CharArray* src = shadow_frame->GetVRegReference(arg_offset)->AsCharArray();
357 CharArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsCharArray();
358 for (jint i = 0; i < length; ++i) {
359 dst->Set(dstPos + i, src->Get(srcPos + i));
360 }
361 } else if (ctype->IsPrimitiveInt()) {
362 IntArray* src = shadow_frame->GetVRegReference(arg_offset)->AsIntArray();
363 IntArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsIntArray();
364 for (jint i = 0; i < length; ++i) {
365 dst->Set(dstPos + i, src->Get(srcPos + i));
366 }
367 } else {
368 UNIMPLEMENTED(FATAL) << "System.arraycopy of unexpected type: " << PrettyDescriptor(ctype);
369 }
370 } else {
371 // Not special, continue with regular interpreter execution.
372 artInterpreterToInterpreterBridge(self, mh, code_item, shadow_frame, result);
373 }
374}
375
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200376// Explicit DoCall template function declarations.
Sebastien Hertzc6714852013-09-30 16:42:32 +0200377#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \
378 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100379 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \
380 ShadowFrame& shadow_frame, \
Sebastien Hertzc6714852013-09-30 16:42:32 +0200381 const Instruction* inst, uint16_t inst_data, \
382 JValue* result)
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200383EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false);
384EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true);
385EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false);
386EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true);
387#undef EXPLICIT_DO_CALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200388
389// Explicit DoFilledNewArray template function declarations.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100390#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \
391 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
392 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \
393 const ShadowFrame& shadow_frame, \
394 Thread* self, JValue* result)
395#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \
396 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \
397 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \
398 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \
399 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active)
400EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false);
401EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true);
402#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200403#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL
404
405} // namespace interpreter
406} // namespace art