blob: e8cea9d833c3b78226fa4b6eacf85a6364965dfd [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 }
Hiroshi Yamauchi563b47c2014-02-28 17:18:37 -0800158 if (kIsDebugBuild && Runtime::Current()->GetInstrumentation()->IsForcedInterpretOnly() &&
159 !method->IsNative() && !method->IsProxyMethod() &&
160 method->GetEntryPointFromInterpreter() == artInterpreterToCompiledCodeBridge) {
161 LOG(FATAL) << "Attempt to call compiled code when -Xint: " << PrettyMethod(method);
162 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200163 (method->GetEntryPointFromInterpreter())(self, mh, code_item, new_shadow_frame, result);
164 } else {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200165 UnstartedRuntimeInvoke(self, mh, code_item, new_shadow_frame, result, first_dest_reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200166 }
167 return !self->IsExceptionPending();
168}
169
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100170template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200171bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
172 Thread* self, JValue* result) {
173 DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY ||
174 inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE);
175 const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c();
176 if (!is_range) {
177 // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments.
178 CHECK_LE(length, 5);
179 }
180 if (UNLIKELY(length < 0)) {
181 ThrowNegativeArraySizeException(length);
182 return false;
183 }
184 uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
185 Class* arrayClass = ResolveVerifyAndClinit(type_idx, shadow_frame.GetMethod(),
186 self, false, do_access_check);
187 if (UNLIKELY(arrayClass == NULL)) {
188 DCHECK(self->IsExceptionPending());
189 return false;
190 }
191 CHECK(arrayClass->IsArrayClass());
192 Class* componentClass = arrayClass->GetComponentType();
193 if (UNLIKELY(componentClass->IsPrimitive() && !componentClass->IsPrimitiveInt())) {
194 if (componentClass->IsPrimitiveLong() || componentClass->IsPrimitiveDouble()) {
195 ThrowRuntimeException("Bad filled array request for type %s",
196 PrettyDescriptor(componentClass).c_str());
197 } else {
198 self->ThrowNewExceptionF(shadow_frame.GetCurrentLocationForThrow(),
199 "Ljava/lang/InternalError;",
Brian Carlstrom4fa0bcd2013-12-10 11:24:21 -0800200 "Found type %s; filled-new-array not implemented for anything but 'int'",
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200201 PrettyDescriptor(componentClass).c_str());
202 }
203 return false;
204 }
Ian Rogers6fac4472014-02-25 17:01:10 -0800205 Object* newArray = Array::Alloc<true>(self, arrayClass, length, arrayClass->GetComponentSize(),
206 Runtime::Current()->GetHeap()->GetCurrentAllocator());
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200207 if (UNLIKELY(newArray == NULL)) {
208 DCHECK(self->IsExceptionPending());
209 return false;
210 }
Sebastien Hertzabff6432014-01-27 18:01:39 +0100211 uint32_t arg[5]; // only used in filled-new-array.
212 uint32_t vregC; // only used in filled-new-array-range.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200213 if (is_range) {
Sebastien Hertzabff6432014-01-27 18:01:39 +0100214 vregC = inst->VRegC_3rc();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200215 } else {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200216 inst->GetArgs(arg);
Sebastien Hertzabff6432014-01-27 18:01:39 +0100217 }
218 const bool is_primitive_int_component = componentClass->IsPrimitiveInt();
219 for (int32_t i = 0; i < length; ++i) {
220 size_t src_reg = is_range ? vregC + i : arg[i];
221 if (is_primitive_int_component) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100222 newArray->AsIntArray()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVReg(src_reg));
Sebastien Hertzabff6432014-01-27 18:01:39 +0100223 } else {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100224 newArray->AsObjectArray<Object>()->SetWithoutChecks<transaction_active>(i, shadow_frame.GetVRegReference(src_reg));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200225 }
226 }
227
228 result->SetL(newArray);
229 return true;
230}
231
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100232// TODO fix thread analysis: should be SHARED_LOCKS_REQUIRED(Locks::mutator_lock_).
233template<typename T>
234static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array, int32_t count)
235 NO_THREAD_SAFETY_ANALYSIS {
236 Runtime* runtime = Runtime::Current();
237 for (int32_t i = 0; i < count; ++i) {
238 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i));
239 }
240}
241
242void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
243 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
244 DCHECK(Runtime::Current()->IsActiveTransaction());
245 DCHECK(array != nullptr);
246 DCHECK_LE(count, array->GetLength());
247 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType();
248 switch (primitive_component_type) {
249 case Primitive::kPrimBoolean:
250 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count);
251 break;
252 case Primitive::kPrimByte:
253 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count);
254 break;
255 case Primitive::kPrimChar:
256 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count);
257 break;
258 case Primitive::kPrimShort:
259 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count);
260 break;
261 case Primitive::kPrimInt:
262 case Primitive::kPrimFloat:
263 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count);
264 break;
265 case Primitive::kPrimLong:
266 case Primitive::kPrimDouble:
267 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count);
268 break;
269 default:
270 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type
271 << " in fill-array-data";
272 break;
273 }
274}
275
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200276static void UnstartedRuntimeInvoke(Thread* self, MethodHelper& mh,
277 const DexFile::CodeItem* code_item, ShadowFrame* shadow_frame,
278 JValue* result, size_t arg_offset) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200279 // In a runtime that's not started we intercept certain methods to avoid complicated dependency
280 // problems in core libraries.
281 std::string name(PrettyMethod(shadow_frame->GetMethod()));
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800282 if (name == "java.lang.Class java.lang.Class.forName(java.lang.String)"
283 || name == "java.lang.Class java.lang.VMClassLoader.loadClass(java.lang.String, boolean)") {
284 // TODO Class#forName should actually call Class::EnsureInitialized always. Support for the
285 // other variants that take more arguments should also be added.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200286 std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset)->AsString()->ToModifiedUtf8().c_str()));
Mathieu Chartier590fee92013-09-13 13:46:47 -0700287
288 SirtRef<ClassLoader> class_loader(self, nullptr); // shadow_frame.GetMethod()->GetDeclaringClass()->GetClassLoader();
Ian Rogers98379392014-02-24 16:53:16 -0800289 Class* found = Runtime::Current()->GetClassLinker()->FindClass(self, descriptor.c_str(),
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200290 class_loader);
291 CHECK(found != NULL) << "Class.forName failed in un-started runtime for class: "
292 << PrettyDescriptor(descriptor);
293 result->SetL(found);
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800294 } else if (name == "java.lang.Class java.lang.VMClassLoader.findLoadedClass(java.lang.ClassLoader, java.lang.String)") {
295 SirtRef<ClassLoader> class_loader(self, down_cast<mirror::ClassLoader*>(shadow_frame->GetVRegReference(arg_offset)));
296 std::string descriptor(DotToDescriptor(shadow_frame->GetVRegReference(arg_offset + 1)->AsString()->ToModifiedUtf8().c_str()));
297
Ian Rogers98379392014-02-24 16:53:16 -0800298 Class* found = Runtime::Current()->GetClassLinker()->FindClass(self, descriptor.c_str(),
Kenny Rootfa31b3c2013-12-09 13:51:32 -0800299 class_loader);
300 result->SetL(found);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200301 } else if (name == "java.lang.Object java.lang.Class.newInstance()") {
302 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
303 ArtMethod* c = klass->FindDeclaredDirectMethod("<init>", "()V");
304 CHECK(c != NULL);
305 SirtRef<Object> obj(self, klass->AllocObject(self));
306 CHECK(obj.get() != NULL);
307 EnterInterpreterFromInvoke(self, c, obj.get(), NULL, NULL);
308 result->SetL(obj.get());
309 } else if (name == "java.lang.reflect.Field java.lang.Class.getDeclaredField(java.lang.String)") {
310 // Special managed code cut-out to allow field lookup in a un-started runtime that'd fail
311 // going the reflective Dex way.
312 Class* klass = shadow_frame->GetVRegReference(arg_offset)->AsClass();
313 String* name = shadow_frame->GetVRegReference(arg_offset + 1)->AsString();
314 ArtField* found = NULL;
315 FieldHelper fh;
316 ObjectArray<ArtField>* fields = klass->GetIFields();
317 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) {
318 ArtField* f = fields->Get(i);
319 fh.ChangeField(f);
320 if (name->Equals(fh.GetName())) {
321 found = f;
322 }
323 }
324 if (found == NULL) {
325 fields = klass->GetSFields();
326 for (int32_t i = 0; i < fields->GetLength() && found == NULL; ++i) {
327 ArtField* f = fields->Get(i);
328 fh.ChangeField(f);
329 if (name->Equals(fh.GetName())) {
330 found = f;
331 }
332 }
333 }
334 CHECK(found != NULL)
335 << "Failed to find field in Class.getDeclaredField in un-started runtime. name="
336 << name->ToModifiedUtf8() << " class=" << PrettyDescriptor(klass);
337 // TODO: getDeclaredField calls GetType once the field is found to ensure a
338 // NoClassDefFoundError is thrown if the field's type cannot be resolved.
339 Class* jlr_Field = self->DecodeJObject(WellKnownClasses::java_lang_reflect_Field)->AsClass();
Mathieu Chartiercbb2d202013-11-14 17:45:16 -0800340 SirtRef<Object> field(self, jlr_Field->AllocNonMovableObject(self));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200341 CHECK(field.get() != NULL);
342 ArtMethod* c = jlr_Field->FindDeclaredDirectMethod("<init>", "(Ljava/lang/reflect/ArtField;)V");
343 uint32_t args[1];
Ian Rogersef7d42f2014-01-06 12:55:46 -0800344 args[0] = StackReference<mirror::Object>::FromMirrorPtr(found).AsVRegValue();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200345 EnterInterpreterFromInvoke(self, c, field.get(), args, NULL);
346 result->SetL(field.get());
347 } else if (name == "void java.lang.System.arraycopy(java.lang.Object, int, java.lang.Object, int, int)" ||
348 name == "void java.lang.System.arraycopy(char[], int, char[], int, int)") {
349 // Special case array copying without initializing System.
350 Class* ctype = shadow_frame->GetVRegReference(arg_offset)->GetClass()->GetComponentType();
351 jint srcPos = shadow_frame->GetVReg(arg_offset + 1);
352 jint dstPos = shadow_frame->GetVReg(arg_offset + 3);
353 jint length = shadow_frame->GetVReg(arg_offset + 4);
354 if (!ctype->IsPrimitive()) {
355 ObjectArray<Object>* src = shadow_frame->GetVRegReference(arg_offset)->AsObjectArray<Object>();
356 ObjectArray<Object>* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsObjectArray<Object>();
357 for (jint i = 0; i < length; ++i) {
358 dst->Set(dstPos + i, src->Get(srcPos + i));
359 }
360 } else if (ctype->IsPrimitiveChar()) {
361 CharArray* src = shadow_frame->GetVRegReference(arg_offset)->AsCharArray();
362 CharArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsCharArray();
363 for (jint i = 0; i < length; ++i) {
364 dst->Set(dstPos + i, src->Get(srcPos + i));
365 }
366 } else if (ctype->IsPrimitiveInt()) {
367 IntArray* src = shadow_frame->GetVRegReference(arg_offset)->AsIntArray();
368 IntArray* dst = shadow_frame->GetVRegReference(arg_offset + 2)->AsIntArray();
369 for (jint i = 0; i < length; ++i) {
370 dst->Set(dstPos + i, src->Get(srcPos + i));
371 }
372 } else {
373 UNIMPLEMENTED(FATAL) << "System.arraycopy of unexpected type: " << PrettyDescriptor(ctype);
374 }
375 } else {
376 // Not special, continue with regular interpreter execution.
377 artInterpreterToInterpreterBridge(self, mh, code_item, shadow_frame, result);
378 }
379}
380
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200381// Explicit DoCall template function declarations.
Sebastien Hertzc6714852013-09-30 16:42:32 +0200382#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \
383 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100384 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \
385 ShadowFrame& shadow_frame, \
Sebastien Hertzc6714852013-09-30 16:42:32 +0200386 const Instruction* inst, uint16_t inst_data, \
387 JValue* result)
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200388EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false);
389EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true);
390EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false);
391EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true);
392#undef EXPLICIT_DO_CALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200393
394// Explicit DoFilledNewArray template function declarations.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100395#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \
396 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
397 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \
398 const ShadowFrame& shadow_frame, \
399 Thread* self, JValue* result)
400#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \
401 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \
402 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \
403 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \
404 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active)
405EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false);
406EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true);
407#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200408#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL
409
410} // namespace interpreter
411} // namespace art