blob: 2d90734be1b4a09ad28cb9036751ed58973dbdc7 [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"
Ian Rogers22d5e732014-07-15 22:23:51 -070018
Andreas Gampef0e128a2015-02-27 20:08:34 -080019#include <cmath>
20
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Daniel Mihalyieb076692014-08-22 17:33:31 +020022#include "debugger.h"
Nicolas Geoffray7bf2b4f2015-07-08 10:11:59 +000023#include "entrypoints/runtime_asm_entrypoints.h"
Tamas Berghammerdd5e5e92016-02-12 16:29:00 +000024#include "jit/jit.h"
Narayan Kamath9823e782016-08-03 12:46:58 +010025#include "jvalue.h"
26#include "method_handles.h"
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010027#include "mirror/array-inl.h"
Narayan Kamath9823e782016-08-03 12:46:58 +010028#include "mirror/class.h"
29#include "mirror/method_handle_impl.h"
30#include "reflection.h"
31#include "reflection-inl.h"
Andreas Gampeb3025922015-09-01 14:45:00 -070032#include "stack.h"
Andreas Gampe2969bcd2015-03-09 12:57:41 -070033#include "unstarted_runtime.h"
Jeff Hao848f70a2014-01-15 13:49:50 -080034#include "verifier/method_verifier.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020035
36namespace art {
37namespace interpreter {
38
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000039void ThrowNullPointerExceptionFromInterpreter() {
40 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -070041}
42
43template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
44bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
45 uint16_t inst_data) {
46 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
47 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Roland Levillain4b8f1ec2015-08-26 18:34:03 +010048 ArtField* f =
49 FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
50 Primitive::ComponentSize(field_type));
Ian Rogers54874942014-06-10 16:31:03 -070051 if (UNLIKELY(f == nullptr)) {
52 CHECK(self->IsExceptionPending());
53 return false;
54 }
Mathieu Chartier3398c782016-09-30 10:27:43 -070055 ObjPtr<Object> obj;
Ian Rogers54874942014-06-10 16:31:03 -070056 if (is_static) {
57 obj = f->GetDeclaringClass();
58 } else {
59 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
60 if (UNLIKELY(obj == nullptr)) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000061 ThrowNullPointerExceptionForFieldAccess(f, true);
Ian Rogers54874942014-06-10 16:31:03 -070062 return false;
63 }
64 }
Sebastien Hertz1edbd8e2014-07-16 20:00:11 +020065 f->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self);
Ian Rogers54874942014-06-10 16:31:03 -070066 // Report this field access to instrumentation if needed.
67 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
68 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
Mathieu Chartier0715c0b2016-10-03 22:49:46 -070069 StackHandleScope<1> hs(self);
70 // Wrap in handle wrapper in case the listener does thread suspension.
71 HandleWrapperObjPtr<mirror::Object> h(hs.NewHandleWrapper(&obj));
Mathieu Chartier3398c782016-09-30 10:27:43 -070072 ObjPtr<Object> this_object;
73 if (!f->IsStatic()) {
74 this_object = obj;
75 }
76 instrumentation->FieldReadEvent(self,
77 this_object.Decode(),
78 shadow_frame.GetMethod(),
79 shadow_frame.GetDexPC(),
80 f);
Ian Rogers54874942014-06-10 16:31:03 -070081 }
82 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
83 switch (field_type) {
84 case Primitive::kPrimBoolean:
85 shadow_frame.SetVReg(vregA, f->GetBoolean(obj));
86 break;
87 case Primitive::kPrimByte:
88 shadow_frame.SetVReg(vregA, f->GetByte(obj));
89 break;
90 case Primitive::kPrimChar:
91 shadow_frame.SetVReg(vregA, f->GetChar(obj));
92 break;
93 case Primitive::kPrimShort:
94 shadow_frame.SetVReg(vregA, f->GetShort(obj));
95 break;
96 case Primitive::kPrimInt:
97 shadow_frame.SetVReg(vregA, f->GetInt(obj));
98 break;
99 case Primitive::kPrimLong:
100 shadow_frame.SetVRegLong(vregA, f->GetLong(obj));
101 break;
102 case Primitive::kPrimNot:
Mathieu Chartier3398c782016-09-30 10:27:43 -0700103 shadow_frame.SetVRegReference(vregA, f->GetObject(obj).Decode());
Ian Rogers54874942014-06-10 16:31:03 -0700104 break;
105 default:
106 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700107 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700108 }
109 return true;
110}
111
112// Explicitly instantiate all DoFieldGet functions.
113#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
114 template bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, \
115 ShadowFrame& shadow_frame, \
116 const Instruction* inst, \
117 uint16_t inst_data)
118
119#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
120 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
121 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
122
123// iget-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700124EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean)
125EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte)
126EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar)
127EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort)
128EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt)
129EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong)
130EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700131
132// sget-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700133EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean)
134EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte)
135EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar)
136EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort)
137EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt)
138EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong)
139EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700140
141#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
142#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
143
144// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
145// Returns true on success, otherwise throws an exception and returns false.
146template<Primitive::Type field_type>
147bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
148 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
149 if (UNLIKELY(obj == nullptr)) {
150 // We lost the reference to the field index so we cannot get a more
151 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000152 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -0700153 return false;
154 }
155 MemberOffset field_offset(inst->VRegC_22c());
156 // Report this field access to instrumentation if needed. Since we only have the offset of
157 // the field from the base of the object, we need to look for it first.
158 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
159 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
160 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
161 field_offset.Uint32Value());
162 DCHECK(f != nullptr);
163 DCHECK(!f->IsStatic());
164 instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
165 shadow_frame.GetDexPC(), f);
166 }
167 // Note: iget-x-quick instructions are only for non-volatile fields.
168 const uint32_t vregA = inst->VRegA_22c(inst_data);
169 switch (field_type) {
170 case Primitive::kPrimInt:
171 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
172 break;
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800173 case Primitive::kPrimBoolean:
174 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldBoolean(field_offset)));
175 break;
176 case Primitive::kPrimByte:
177 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldByte(field_offset)));
178 break;
179 case Primitive::kPrimChar:
180 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldChar(field_offset)));
181 break;
182 case Primitive::kPrimShort:
183 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldShort(field_offset)));
184 break;
Ian Rogers54874942014-06-10 16:31:03 -0700185 case Primitive::kPrimLong:
186 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
187 break;
188 case Primitive::kPrimNot:
189 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
190 break;
191 default:
192 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700193 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700194 }
195 return true;
196}
197
198// Explicitly instantiate all DoIGetQuick functions.
199#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
200 template bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
201 uint16_t inst_data)
202
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800203EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
204EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimBoolean); // iget-boolean-quick.
205EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimByte); // iget-byte-quick.
206EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimChar); // iget-char-quick.
207EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimShort); // iget-short-quick.
208EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
209EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
Ian Rogers54874942014-06-10 16:31:03 -0700210#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
211
212template<Primitive::Type field_type>
213static JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700214 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers54874942014-06-10 16:31:03 -0700215 JValue field_value;
216 switch (field_type) {
217 case Primitive::kPrimBoolean:
218 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
219 break;
220 case Primitive::kPrimByte:
221 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
222 break;
223 case Primitive::kPrimChar:
224 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
225 break;
226 case Primitive::kPrimShort:
227 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
228 break;
229 case Primitive::kPrimInt:
230 field_value.SetI(shadow_frame.GetVReg(vreg));
231 break;
232 case Primitive::kPrimLong:
233 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
234 break;
235 case Primitive::kPrimNot:
236 field_value.SetL(shadow_frame.GetVRegReference(vreg));
237 break;
238 default:
239 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700240 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700241 }
242 return field_value;
243}
244
245template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
246 bool transaction_active>
247bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
248 uint16_t inst_data) {
249 bool do_assignability_check = do_access_check;
250 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
251 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100252 ArtField* f =
253 FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
254 Primitive::ComponentSize(field_type));
Ian Rogers54874942014-06-10 16:31:03 -0700255 if (UNLIKELY(f == nullptr)) {
256 CHECK(self->IsExceptionPending());
257 return false;
258 }
Mathieu Chartier3398c782016-09-30 10:27:43 -0700259 ObjPtr<Object> obj;
Ian Rogers54874942014-06-10 16:31:03 -0700260 if (is_static) {
261 obj = f->GetDeclaringClass();
262 } else {
263 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
264 if (UNLIKELY(obj == nullptr)) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000265 ThrowNullPointerExceptionForFieldAccess(f, false);
Ian Rogers54874942014-06-10 16:31:03 -0700266 return false;
267 }
268 }
Sebastien Hertz1edbd8e2014-07-16 20:00:11 +0200269 f->GetDeclaringClass()->AssertInitializedOrInitializingInThread(self);
Ian Rogers54874942014-06-10 16:31:03 -0700270 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
271 // Report this field access to instrumentation if needed. Since we only have the offset of
272 // the field from the base of the object, we need to look for it first.
273 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
274 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
Mathieu Chartier0715c0b2016-10-03 22:49:46 -0700275 StackHandleScope<1> hs(self);
276 // Wrap in handle wrapper in case the listener does thread suspension.
277 HandleWrapperObjPtr<mirror::Object> h(hs.NewHandleWrapper(&obj));
Ian Rogers54874942014-06-10 16:31:03 -0700278 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
Mathieu Chartier3398c782016-09-30 10:27:43 -0700279 ObjPtr<Object> this_object = f->IsStatic() ? nullptr : obj;
280 instrumentation->FieldWriteEvent(self, this_object.Decode(),
281 shadow_frame.GetMethod(),
282 shadow_frame.GetDexPC(),
283 f,
284 field_value);
Ian Rogers54874942014-06-10 16:31:03 -0700285 }
286 switch (field_type) {
287 case Primitive::kPrimBoolean:
288 f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA));
289 break;
290 case Primitive::kPrimByte:
291 f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA));
292 break;
293 case Primitive::kPrimChar:
294 f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA));
295 break;
296 case Primitive::kPrimShort:
297 f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA));
298 break;
299 case Primitive::kPrimInt:
300 f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA));
301 break;
302 case Primitive::kPrimLong:
303 f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA));
304 break;
305 case Primitive::kPrimNot: {
306 Object* reg = shadow_frame.GetVRegReference(vregA);
307 if (do_assignability_check && reg != nullptr) {
308 // FieldHelper::GetType can resolve classes, use a handle wrapper which will restore the
309 // object in the destructor.
Mathieu Chartier3398c782016-09-30 10:27:43 -0700310 ObjPtr<Class> field_class;
Ian Rogers54874942014-06-10 16:31:03 -0700311 {
Mathieu Chartierc7853442015-03-27 14:35:38 -0700312 StackHandleScope<2> hs(self);
Ian Rogers54874942014-06-10 16:31:03 -0700313 HandleWrapper<mirror::Object> h_reg(hs.NewHandleWrapper(&reg));
Mathieu Chartier3398c782016-09-30 10:27:43 -0700314 HandleWrapperObjPtr<mirror::Object> h_obj(hs.NewHandleWrapper(&obj));
Mathieu Chartierc7853442015-03-27 14:35:38 -0700315 field_class = f->GetType<true>();
Ian Rogers54874942014-06-10 16:31:03 -0700316 }
Mathieu Chartier3398c782016-09-30 10:27:43 -0700317 if (!reg->VerifierInstanceOf(field_class.Decode())) {
Ian Rogers54874942014-06-10 16:31:03 -0700318 // This should never happen.
Ian Rogers1ff3c982014-08-12 02:30:58 -0700319 std::string temp1, temp2, temp3;
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000320 self->ThrowNewExceptionF("Ljava/lang/VirtualMachineError;",
Ian Rogers54874942014-06-10 16:31:03 -0700321 "Put '%s' that is not instance of field '%s' in '%s'",
Ian Rogers1ff3c982014-08-12 02:30:58 -0700322 reg->GetClass()->GetDescriptor(&temp1),
323 field_class->GetDescriptor(&temp2),
324 f->GetDeclaringClass()->GetDescriptor(&temp3));
Ian Rogers54874942014-06-10 16:31:03 -0700325 return false;
326 }
327 }
328 f->SetObj<transaction_active>(obj, reg);
329 break;
330 }
331 default:
332 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700333 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700334 }
335 return true;
336}
337
338// Explicitly instantiate all DoFieldPut functions.
339#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
340 template bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \
341 const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
342
343#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
344 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
345 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
346 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
347 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
348
349// iput-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700350EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean)
351EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte)
352EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar)
353EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort)
354EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt)
355EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong)
356EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700357
358// sput-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700359EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean)
360EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte)
361EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar)
362EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort)
363EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt)
364EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong)
365EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700366
367#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
368#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
369
370template<Primitive::Type field_type, bool transaction_active>
371bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
372 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
373 if (UNLIKELY(obj == nullptr)) {
374 // We lost the reference to the field index so we cannot get a more
375 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000376 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -0700377 return false;
378 }
379 MemberOffset field_offset(inst->VRegC_22c());
380 const uint32_t vregA = inst->VRegA_22c(inst_data);
381 // Report this field modification to instrumentation if needed. Since we only have the offset of
382 // the field from the base of the object, we need to look for it first.
383 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
384 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
385 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
386 field_offset.Uint32Value());
387 DCHECK(f != nullptr);
388 DCHECK(!f->IsStatic());
389 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
390 instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
391 shadow_frame.GetDexPC(), f, field_value);
392 }
393 // Note: iput-x-quick instructions are only for non-volatile fields.
394 switch (field_type) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700395 case Primitive::kPrimBoolean:
396 obj->SetFieldBoolean<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
397 break;
398 case Primitive::kPrimByte:
399 obj->SetFieldByte<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
400 break;
401 case Primitive::kPrimChar:
402 obj->SetFieldChar<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
403 break;
404 case Primitive::kPrimShort:
405 obj->SetFieldShort<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
406 break;
Ian Rogers54874942014-06-10 16:31:03 -0700407 case Primitive::kPrimInt:
408 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
409 break;
410 case Primitive::kPrimLong:
411 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
412 break;
413 case Primitive::kPrimNot:
414 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
415 break;
416 default:
417 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700418 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700419 }
420 return true;
421}
422
423// Explicitly instantiate all DoIPutQuick functions.
424#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
425 template bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
426 const Instruction* inst, \
427 uint16_t inst_data)
428
429#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
430 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
431 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
432
Andreas Gampec8ccf682014-09-29 20:07:43 -0700433EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt) // iput-quick.
434EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimBoolean) // iput-boolean-quick.
435EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimByte) // iput-byte-quick.
436EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimChar) // iput-char-quick.
437EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimShort) // iput-short-quick.
438EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong) // iput-wide-quick.
439EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot) // iput-object-quick.
Ian Rogers54874942014-06-10 16:31:03 -0700440#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
441#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
442
Sebastien Hertz520633b2015-09-08 17:03:36 +0200443// We accept a null Instrumentation* meaning we must not report anything to the instrumentation.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700444uint32_t FindNextInstructionFollowingException(
445 Thread* self, ShadowFrame& shadow_frame, uint32_t dex_pc,
446 const instrumentation::Instrumentation* instrumentation) {
Ian Rogers54874942014-06-10 16:31:03 -0700447 self->VerifyStack();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700448 StackHandleScope<2> hs(self);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000449 Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException()));
Sebastien Hertz520633b2015-09-08 17:03:36 +0200450 if (instrumentation != nullptr && instrumentation->HasExceptionCaughtListeners()
Nicolas Geoffray7642cfc2015-02-26 10:56:09 +0000451 && self->IsExceptionThrownByCurrentMethod(exception.Get())) {
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000452 instrumentation->ExceptionCaughtEvent(self, exception.Get());
Sebastien Hertz9f102032014-05-23 08:59:42 +0200453 }
Ian Rogers54874942014-06-10 16:31:03 -0700454 bool clear_exception = false;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700455 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(
456 hs.NewHandle(exception->GetClass()), dex_pc, &clear_exception);
Sebastien Hertz520633b2015-09-08 17:03:36 +0200457 if (found_dex_pc == DexFile::kDexNoIndex && instrumentation != nullptr) {
Nicolas Geoffray7642cfc2015-02-26 10:56:09 +0000458 // Exception is not caught by the current method. We will unwind to the
459 // caller. Notify any instrumentation listener.
Sebastien Hertz9f102032014-05-23 08:59:42 +0200460 instrumentation->MethodUnwindEvent(self, shadow_frame.GetThisObject(),
Ian Rogers54874942014-06-10 16:31:03 -0700461 shadow_frame.GetMethod(), dex_pc);
462 } else {
Nicolas Geoffray7642cfc2015-02-26 10:56:09 +0000463 // Exception is caught in the current method. We will jump to the found_dex_pc.
Ian Rogers54874942014-06-10 16:31:03 -0700464 if (clear_exception) {
465 self->ClearException();
466 }
467 }
468 return found_dex_pc;
469}
470
Ian Rogerse94652f2014-12-02 11:13:19 -0800471void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) {
472 LOG(FATAL) << "Unexpected instruction: "
473 << inst->DumpString(shadow_frame.GetMethod()->GetDexFile());
474 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700475}
476
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200477// Assign register 'src_reg' from shadow_frame to register 'dest_reg' into new_shadow_frame.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800478static inline void AssignRegister(ShadowFrame* new_shadow_frame, const ShadowFrame& shadow_frame,
479 size_t dest_reg, size_t src_reg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700480 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe7104cbf2014-03-21 11:44:43 -0700481 // Uint required, so that sign extension does not make this wrong on 64b systems
482 uint32_t src_value = shadow_frame.GetVReg(src_reg);
Mathieu Chartier4e305412014-02-19 10:54:44 -0800483 mirror::Object* o = shadow_frame.GetVRegReference<kVerifyNone>(src_reg);
Igor Murashkinc449e8b2015-06-10 15:56:42 -0700484
485 // If both register locations contains the same value, the register probably holds a reference.
486 // Note: As an optimization, non-moving collectors leave a stale reference value
487 // in the references array even after the original vreg was overwritten to a non-reference.
Andreas Gampe7104cbf2014-03-21 11:44:43 -0700488 if (src_value == reinterpret_cast<uintptr_t>(o)) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800489 new_shadow_frame->SetVRegReference(dest_reg, o);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200490 } else {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800491 new_shadow_frame->SetVReg(dest_reg, src_value);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200492 }
493}
494
Sebastien Hertz45b15972015-04-03 16:07:05 +0200495void AbortTransactionF(Thread* self, const char* fmt, ...) {
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700496 va_list args;
497 va_start(args, fmt);
Sebastien Hertz45b15972015-04-03 16:07:05 +0200498 AbortTransactionV(self, fmt, args);
499 va_end(args);
500}
501
502void AbortTransactionV(Thread* self, const char* fmt, va_list args) {
503 CHECK(Runtime::Current()->IsActiveTransaction());
504 // Constructs abort message.
Sebastien Hertz1c80bec2015-02-03 11:58:06 +0100505 std::string abort_msg;
506 StringAppendV(&abort_msg, fmt, args);
507 // Throws an exception so we can abort the transaction and rollback every change.
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200508 Runtime::Current()->AbortTransactionAndThrowAbortError(self, abort_msg);
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700509}
510
Igor Murashkin158f35c2015-06-10 15:55:30 -0700511// Separate declaration is required solely for the attributes.
Narayan Kamath9823e782016-08-03 12:46:58 +0100512template <bool is_range, bool do_assignability_check>
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700513 REQUIRES_SHARED(Locks::mutator_lock_)
Igor Murashkin158f35c2015-06-10 15:55:30 -0700514static inline bool DoCallCommon(ArtMethod* called_method,
515 Thread* self,
516 ShadowFrame& shadow_frame,
517 JValue* result,
518 uint16_t number_of_inputs,
Narayan Kamath370423d2016-10-03 16:51:22 +0100519 uint32_t (&arg)[Instruction::kMaxVarArgRegs],
Igor Murashkin158f35c2015-06-10 15:55:30 -0700520 uint32_t vregC) ALWAYS_INLINE;
521
Siva Chandra05d24152016-01-05 17:43:17 -0800522void ArtInterpreterToCompiledCodeBridge(Thread* self,
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100523 ArtMethod* caller,
Siva Chandra05d24152016-01-05 17:43:17 -0800524 const DexFile::CodeItem* code_item,
525 ShadowFrame* shadow_frame,
526 JValue* result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700527 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700528 ArtMethod* method = shadow_frame->GetMethod();
529 // Ensure static methods are initialized.
530 if (method->IsStatic()) {
531 mirror::Class* declaringClass = method->GetDeclaringClass();
532 if (UNLIKELY(!declaringClass->IsInitialized())) {
533 self->PushShadowFrame(shadow_frame);
534 StackHandleScope<1> hs(self);
535 Handle<mirror::Class> h_class(hs.NewHandle(declaringClass));
536 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true,
537 true))) {
538 self->PopShadowFrame();
539 DCHECK(self->IsExceptionPending());
540 return;
541 }
542 self->PopShadowFrame();
543 CHECK(h_class->IsInitializing());
544 // Reload from shadow frame in case the method moved, this is faster than adding a handle.
545 method = shadow_frame->GetMethod();
546 }
547 }
548 uint16_t arg_offset = (code_item == nullptr)
549 ? 0
550 : code_item->registers_size_ - code_item->ins_size_;
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100551 jit::Jit* jit = Runtime::Current()->GetJit();
552 if (jit != nullptr && caller != nullptr) {
553 jit->NotifyInterpreterToCompiledCodeTransition(self, caller);
554 }
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700555 method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset),
556 (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t),
Andreas Gampe542451c2016-07-26 09:02:02 -0700557 result, method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty());
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700558}
559
Mingyao Yangffedec52016-05-19 10:48:40 -0700560void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame,
561 uint16_t this_obj_vreg,
562 JValue result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700563 REQUIRES_SHARED(Locks::mutator_lock_) {
Mingyao Yangffedec52016-05-19 10:48:40 -0700564 Object* existing = shadow_frame->GetVRegReference(this_obj_vreg);
565 if (existing == nullptr) {
566 // If it's null, we come from compiled code that was deoptimized. Nothing to do,
567 // as the compiler verified there was no alias.
568 // Set the new string result of the StringFactory.
569 shadow_frame->SetVRegReference(this_obj_vreg, result.GetL());
570 return;
571 }
572 // Set the string init result into all aliases.
573 for (uint32_t i = 0, e = shadow_frame->NumberOfVRegs(); i < e; ++i) {
574 if (shadow_frame->GetVRegReference(i) == existing) {
575 DCHECK_EQ(shadow_frame->GetVRegReference(i),
576 reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i)));
577 shadow_frame->SetVRegReference(i, result.GetL());
578 DCHECK_EQ(shadow_frame->GetVRegReference(i),
579 reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i)));
580 }
581 }
582}
583
Narayan Kamath9823e782016-08-03 12:46:58 +0100584template<bool is_range, bool do_access_check>
585 REQUIRES_SHARED(Locks::mutator_lock_)
586inline bool DoInvokePolymorphic(Thread* self, ShadowFrame& shadow_frame,
587 const Instruction* inst, uint16_t inst_data,
588 JValue* result) {
589 // Invoke-polymorphic instructions always take a receiver. i.e, they are never static.
590 const uint32_t vRegC = (is_range) ? inst->VRegC_4rcc() : inst->VRegC_45cc();
591
592 // The method_idx here is the name of the signature polymorphic method that
593 // was symbolically invoked in bytecode (say MethodHandle.invoke or MethodHandle.invokeExact)
594 // and not the method that we'll dispatch to in the end.
595 //
596 // TODO(narayan) We'll have to check in the verifier that this is in fact a
597 // signature polymorphic method so that we disallow calls via invoke-polymorphic
598 // to non sig-poly methods. This would also have the side effect of verifying
599 // that vRegC really is a reference type.
600 mirror::MethodHandleImpl* const method_handle =
601 reinterpret_cast<mirror::MethodHandleImpl*>(shadow_frame.GetVRegReference(vRegC));
602 if (UNLIKELY(method_handle == nullptr)) {
603 const int method_idx = (is_range) ? inst->VRegB_4rcc() : inst->VRegB_45cc();
604 // Note that the invoke type is kVirtual here because a call to a signature
605 // polymorphic method is shaped like a virtual call at the bytecode level.
606 ThrowNullPointerExceptionForMethodAccess(method_idx, InvokeType::kVirtual);
607
608 result->SetJ(0);
609 return false;
610 }
611
612 // The vRegH value gives the index of the proto_id associated with this
613 // signature polymorphic callsite.
614 const uint32_t callsite_proto_id = (is_range) ? inst->VRegH_4rcc() : inst->VRegH_45cc();
615
616 // Call through to the classlinker and ask it to resolve the static type associated
617 // with the callsite. This information is stored in the dex cache so it's
618 // guaranteed to be fast after the first resolution.
619 StackHandleScope<2> hs(self);
620 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
621 mirror::Class* caller_class = shadow_frame.GetMethod()->GetDeclaringClass();
622 mirror::MethodType* callsite_type = class_linker->ResolveMethodType(
623 caller_class->GetDexFile(), callsite_proto_id,
624 hs.NewHandle<mirror::DexCache>(caller_class->GetDexCache()),
625 hs.NewHandle<mirror::ClassLoader>(caller_class->GetClassLoader()));
626
627 // This implies we couldn't resolve one or more types in this method handle.
628 if (UNLIKELY(callsite_type == nullptr)) {
629 CHECK(self->IsExceptionPending());
630 result->SetJ(0);
631 return false;
632 }
633
634 const char* old_cause = self->StartAssertNoThreadSuspension("DoInvokePolymorphic");
635
636 // Get the method we're actually invoking along with the kind of
637 // invoke that is desired. We don't need to perform access checks at this
638 // point because they would have been performed on our behalf at the point
639 // of creation of the method handle.
640 ArtMethod* called_method = method_handle->GetTargetMethod();
641 const MethodHandleKind handle_kind = method_handle->GetHandleKind();
642 mirror::MethodType* const handle_type = method_handle->GetMethodType();
643 CHECK(called_method != nullptr);
644 CHECK(handle_type != nullptr);
645
646 // We now have to massage the number of inputs to the target function.
647 // It's always one less than the number of inputs to the signature polymorphic
648 // invoke, the first input being a reference to the MethodHandle itself.
649 const uint16_t number_of_inputs =
650 ((is_range) ? inst->VRegA_4rcc(inst_data) : inst->VRegA_45cc(inst_data)) - 1;
651
652 uint32_t arg[Instruction::kMaxVarArgRegs] = {};
653 uint32_t receiver_vregC = 0;
654 if (is_range) {
655 receiver_vregC = (inst->VRegC_4rcc() + 1);
656 } else {
657 inst->GetVarArgs(arg, inst_data);
658 arg[0] = arg[1];
659 arg[1] = arg[2];
660 arg[2] = arg[3];
661 arg[3] = arg[4];
662 arg[4] = 0;
663 receiver_vregC = arg[0];
664 }
665
666 if (IsInvoke(handle_kind)) {
667 if (handle_kind == kInvokeVirtual || handle_kind == kInvokeInterface) {
668 mirror::Object* receiver = shadow_frame.GetVRegReference(receiver_vregC);
669 mirror::Class* declaring_class = called_method->GetDeclaringClass();
670 // Verify that _vRegC is an object reference and of the type expected by
671 // the receiver.
672 called_method = receiver->GetClass()->FindVirtualMethodForVirtualOrInterface(
673 called_method, kRuntimePointerSize);
674 if (!VerifyObjectIsClass(receiver, declaring_class)) {
675 self->EndAssertNoThreadSuspension(old_cause);
676 return false;
677 }
678 } else if (handle_kind == kInvokeDirect) {
679 // TODO(narayan) : We need to handle the case where the target method is a
680 // constructor here. Also the case where we don't want to dynamically
681 // dispatch based on the type of the receiver.
682 self->EndAssertNoThreadSuspension(old_cause);
683 UNIMPLEMENTED(FATAL) << "Direct invokes are not implemented yet.";
684 return false;
685 }
686
687 // NOTE: handle_kind == kInvokeStatic needs no special treatment here. We
688 // can directly make the call. handle_kind == kInvokeSuper doesn't have any
689 // particular use and can probably be dropped.
690 if (callsite_type->IsExactMatch(handle_type)) {
691 self->EndAssertNoThreadSuspension(old_cause);
692 return DoCallCommon<is_range, do_access_check>(
693 called_method, self, shadow_frame, result, number_of_inputs,
694 arg, receiver_vregC);
695 }
696
697 self->EndAssertNoThreadSuspension(old_cause);
698 UNIMPLEMENTED(FATAL) << "Non exact invokes are not implemented yet.";
699 return false;
700 } else {
701 // TODO(narayan): Implement field getters and setters.
702 self->EndAssertNoThreadSuspension(old_cause);
703 UNIMPLEMENTED(FATAL) << "Field references in method handles are not implemented yet.";
704 return false;
705 }
706}
707
Igor Murashkin6918bf12015-09-27 19:19:06 -0700708template <bool is_range,
Narayan Kamath370423d2016-10-03 16:51:22 +0100709 bool do_assignability_check>
Igor Murashkin158f35c2015-06-10 15:55:30 -0700710static inline bool DoCallCommon(ArtMethod* called_method,
711 Thread* self,
712 ShadowFrame& shadow_frame,
713 JValue* result,
714 uint16_t number_of_inputs,
Narayan Kamath370423d2016-10-03 16:51:22 +0100715 uint32_t (&arg)[Instruction::kMaxVarArgRegs],
Igor Murashkin158f35c2015-06-10 15:55:30 -0700716 uint32_t vregC) {
Jeff Hao848f70a2014-01-15 13:49:50 -0800717 bool string_init = false;
718 // Replace calls to String.<init> with equivalent StringFactory call.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700719 if (UNLIKELY(called_method->GetDeclaringClass()->IsStringClass()
720 && called_method->IsConstructor())) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +0100721 called_method = WellKnownClasses::StringInitToStringFactory(called_method);
Jeff Hao848f70a2014-01-15 13:49:50 -0800722 string_init = true;
723 }
724
Alex Lightdaf58c82016-03-16 23:00:49 +0000725 // Compute method information.
726 const DexFile::CodeItem* code_item = called_method->GetCodeItem();
Igor Murashkin158f35c2015-06-10 15:55:30 -0700727
728 // Number of registers for the callee's call frame.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200729 uint16_t num_regs;
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700730 if (LIKELY(code_item != nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200731 num_regs = code_item->registers_size_;
Igor Murashkin158f35c2015-06-10 15:55:30 -0700732 DCHECK_EQ(string_init ? number_of_inputs - 1 : number_of_inputs, code_item->ins_size_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200733 } else {
Ian Rogerse94652f2014-12-02 11:13:19 -0800734 DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
Igor Murashkin158f35c2015-06-10 15:55:30 -0700735 num_regs = number_of_inputs;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200736 }
737
Igor Murashkin158f35c2015-06-10 15:55:30 -0700738 // Hack for String init:
739 //
740 // Rewrite invoke-x java.lang.String.<init>(this, a, b, c, ...) into:
741 // invoke-x StringFactory(a, b, c, ...)
742 // by effectively dropping the first virtual register from the invoke.
743 //
744 // (at this point the ArtMethod has already been replaced,
745 // so we just need to fix-up the arguments)
David Brazdil65902e82016-01-15 09:35:13 +0000746 //
747 // Note that FindMethodFromCode in entrypoint_utils-inl.h was also special-cased
748 // to handle the compiler optimization of replacing `this` with null without
749 // throwing NullPointerException.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700750 uint32_t string_init_vreg_this = is_range ? vregC : arg[0];
Igor Murashkina06b49b2015-06-25 15:18:12 -0700751 if (UNLIKELY(string_init)) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700752 DCHECK_GT(num_regs, 0u); // As the method is an instance method, there should be at least 1.
Igor Murashkina06b49b2015-06-25 15:18:12 -0700753
Igor Murashkin158f35c2015-06-10 15:55:30 -0700754 // The new StringFactory call is static and has one fewer argument.
Igor Murashkina06b49b2015-06-25 15:18:12 -0700755 if (code_item == nullptr) {
756 DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
757 num_regs--;
758 } // else ... don't need to change num_regs since it comes up from the string_init's code item
Igor Murashkin158f35c2015-06-10 15:55:30 -0700759 number_of_inputs--;
760
761 // Rewrite the var-args, dropping the 0th argument ("this")
Igor Murashkin6918bf12015-09-27 19:19:06 -0700762 for (uint32_t i = 1; i < arraysize(arg); ++i) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700763 arg[i - 1] = arg[i];
764 }
Igor Murashkin6918bf12015-09-27 19:19:06 -0700765 arg[arraysize(arg) - 1] = 0;
Igor Murashkin158f35c2015-06-10 15:55:30 -0700766
767 // Rewrite the non-var-arg case
768 vregC++; // Skips the 0th vreg in the range ("this").
769 }
770
771 // Parameter registers go at the end of the shadow frame.
772 DCHECK_GE(num_regs, number_of_inputs);
773 size_t first_dest_reg = num_regs - number_of_inputs;
774 DCHECK_NE(first_dest_reg, (size_t)-1);
775
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200776 // Allocate shadow frame on the stack.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700777 const char* old_cause = self->StartAssertNoThreadSuspension("DoCallCommon");
Andreas Gampeb3025922015-09-01 14:45:00 -0700778 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe03ec9302015-08-27 17:41:47 -0700779 CREATE_SHADOW_FRAME(num_regs, &shadow_frame, called_method, /* dex pc */ 0);
Andreas Gampeb3025922015-09-01 14:45:00 -0700780 ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200781
Igor Murashkin158f35c2015-06-10 15:55:30 -0700782 // Initialize new shadow frame by copying the registers from the callee shadow frame.
Jeff Haoa3faaf42013-09-03 19:07:00 -0700783 if (do_assignability_check) {
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -0700784 // Slow path.
785 // We might need to do class loading, which incurs a thread state change to kNative. So
786 // register the shadow frame as under construction and allow suspension again.
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -0700787 ScopedStackedShadowFramePusher pusher(
Sebastien Hertzf7958692015-06-09 14:09:14 +0200788 self, new_shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction);
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -0700789 self->EndAssertNoThreadSuspension(old_cause);
790
Igor Murashkin9f95ba72016-02-01 14:21:25 -0800791 // ArtMethod here is needed to check type information of the call site against the callee.
792 // Type information is retrieved from a DexFile/DexCache for that respective declared method.
793 //
794 // As a special case for proxy methods, which are not dex-backed,
795 // we have to retrieve type information from the proxy's method
796 // interface method instead (which is dex backed since proxies are never interfaces).
Andreas Gampe542451c2016-07-26 09:02:02 -0700797 ArtMethod* method =
798 new_shadow_frame->GetMethod()->GetInterfaceMethodIfProxy(kRuntimePointerSize);
Igor Murashkin9f95ba72016-02-01 14:21:25 -0800799
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -0700800 // We need to do runtime check on reference assignment. We need to load the shorty
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200801 // to get the exact type of each reference argument.
Igor Murashkin9f95ba72016-02-01 14:21:25 -0800802 const DexFile::TypeList* params = method->GetParameterTypeList();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700803 uint32_t shorty_len = 0;
Igor Murashkin9f95ba72016-02-01 14:21:25 -0800804 const char* shorty = method->GetShorty(&shorty_len);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200805
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100806 // Handle receiver apart since it's not part of the shorty.
807 size_t dest_reg = first_dest_reg;
808 size_t arg_offset = 0;
Igor Murashkin158f35c2015-06-10 15:55:30 -0700809
Igor Murashkin9f95ba72016-02-01 14:21:25 -0800810 if (!method->IsStatic()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700811 size_t receiver_reg = is_range ? vregC : arg[0];
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100812 new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg));
813 ++dest_reg;
814 ++arg_offset;
Igor Murashkina06b49b2015-06-25 15:18:12 -0700815 DCHECK(!string_init); // All StringFactory methods are static.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100816 }
Igor Murashkin158f35c2015-06-10 15:55:30 -0700817
818 // Copy the caller's invoke-* arguments into the callee's parameter registers.
Ian Rogersef7d42f2014-01-06 12:55:46 -0800819 for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) {
Igor Murashkina06b49b2015-06-25 15:18:12 -0700820 // Skip the 0th 'shorty' type since it represents the return type.
821 DCHECK_LT(shorty_pos + 1, shorty_len) << "for shorty '" << shorty << "'";
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200822 const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset];
823 switch (shorty[shorty_pos + 1]) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700824 // Handle Object references. 1 virtual register slot.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200825 case 'L': {
826 Object* o = shadow_frame.GetVRegReference(src_reg);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700827 if (do_assignability_check && o != nullptr) {
Andreas Gampe542451c2016-07-26 09:02:02 -0700828 PointerSize pointer_size = Runtime::Current()->GetClassLinker()->GetImagePointerSize();
Ian Rogersa0485602014-12-02 15:48:04 -0800829 Class* arg_type =
Igor Murashkin9f95ba72016-02-01 14:21:25 -0800830 method->GetClassFromTypeIndex(
Vladimir Marko05792b92015-08-03 11:56:49 +0100831 params->GetTypeItem(shorty_pos).type_idx_, true /* resolve */, pointer_size);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700832 if (arg_type == nullptr) {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200833 CHECK(self->IsExceptionPending());
834 return false;
835 }
836 if (!o->VerifierInstanceOf(arg_type)) {
837 // This should never happen.
Ian Rogers1ff3c982014-08-12 02:30:58 -0700838 std::string temp1, temp2;
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000839 self->ThrowNewExceptionF("Ljava/lang/VirtualMachineError;",
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200840 "Invoking %s with bad arg %d, type '%s' not instance of '%s'",
Ian Rogerse94652f2014-12-02 11:13:19 -0800841 new_shadow_frame->GetMethod()->GetName(), shorty_pos,
Ian Rogers1ff3c982014-08-12 02:30:58 -0700842 o->GetClass()->GetDescriptor(&temp1),
843 arg_type->GetDescriptor(&temp2));
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200844 return false;
845 }
Jeff Haoa3faaf42013-09-03 19:07:00 -0700846 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200847 new_shadow_frame->SetVRegReference(dest_reg, o);
848 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700849 }
Igor Murashkin158f35c2015-06-10 15:55:30 -0700850 // Handle doubles and longs. 2 consecutive virtual register slots.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200851 case 'J': case 'D': {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700852 uint64_t wide_value =
853 (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << BitSizeOf<uint32_t>()) |
854 static_cast<uint32_t>(shadow_frame.GetVReg(src_reg));
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200855 new_shadow_frame->SetVRegLong(dest_reg, wide_value);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700856 // Skip the next virtual register slot since we already used it.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200857 ++dest_reg;
858 ++arg_offset;
859 break;
860 }
Igor Murashkin158f35c2015-06-10 15:55:30 -0700861 // Handle all other primitives that are always 1 virtual register slot.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200862 default:
863 new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg));
864 break;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200865 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200866 }
867 } else {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700868 size_t arg_index = 0;
869
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200870 // Fast path: no extra checks.
871 if (is_range) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700872 uint16_t first_src_reg = vregC;
873
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200874 for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < num_regs;
875 ++dest_reg, ++src_reg) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800876 AssignRegister(new_shadow_frame, shadow_frame, dest_reg, src_reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200877 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200878 } else {
Igor Murashkin6918bf12015-09-27 19:19:06 -0700879 DCHECK_LE(number_of_inputs, arraysize(arg));
Igor Murashkin158f35c2015-06-10 15:55:30 -0700880
881 for (; arg_index < number_of_inputs; ++arg_index) {
882 AssignRegister(new_shadow_frame, shadow_frame, first_dest_reg + arg_index, arg[arg_index]);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +0200883 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200884 }
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -0700885 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200886 }
887
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200888 // Do the call now.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200889 if (LIKELY(Runtime::Current()->IsStarted())) {
Tamas Berghammerdd5e5e92016-02-12 16:29:00 +0000890 ArtMethod* target = new_shadow_frame->GetMethod();
891 if (ClassLinker::ShouldUseInterpreterEntrypoint(
892 target,
893 target->GetEntryPointFromQuickCompiledCode())) {
Tamas Berghammerc94a61f2016-02-05 18:09:08 +0000894 ArtInterpreterToInterpreterBridge(self, code_item, new_shadow_frame, result);
Tamas Berghammer3a98aae2016-02-08 20:21:54 +0000895 } else {
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100896 ArtInterpreterToCompiledCodeBridge(
897 self, shadow_frame.GetMethod(), code_item, new_shadow_frame, result);
Nicolas Geoffray7070ccd2015-07-08 09:41:54 +0000898 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200899 } else {
Andreas Gampe799681b2015-05-15 19:24:12 -0700900 UnstartedRuntime::Invoke(self, code_item, new_shadow_frame, result, first_dest_reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200901 }
Jeff Hao848f70a2014-01-15 13:49:50 -0800902
903 if (string_init && !self->IsExceptionPending()) {
Mingyao Yangffedec52016-05-19 10:48:40 -0700904 SetStringInitValueToAllAliases(&shadow_frame, string_init_vreg_this, *result);
Jeff Hao848f70a2014-01-15 13:49:50 -0800905 }
906
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200907 return !self->IsExceptionPending();
908}
909
Igor Murashkin158f35c2015-06-10 15:55:30 -0700910template<bool is_range, bool do_assignability_check>
Igor Murashkin158f35c2015-06-10 15:55:30 -0700911bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
912 const Instruction* inst, uint16_t inst_data, JValue* result) {
913 // Argument word count.
Roland Levillain4b8f1ec2015-08-26 18:34:03 +0100914 const uint16_t number_of_inputs =
915 (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700916
917 // TODO: find a cleaner way to separate non-range and range information without duplicating
918 // code.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700919 uint32_t arg[Instruction::kMaxVarArgRegs] = {}; // only used in invoke-XXX.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700920 uint32_t vregC = 0;
921 if (is_range) {
922 vregC = inst->VRegC_3rc();
923 } else {
924 vregC = inst->VRegC_35c();
925 inst->GetVarArgs(arg, inst_data);
926 }
927
928 return DoCallCommon<is_range, do_assignability_check>(
929 called_method, self, shadow_frame,
930 result, number_of_inputs, arg, vregC);
931}
932
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100933template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200934bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
935 Thread* self, JValue* result) {
936 DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY ||
937 inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE);
938 const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c();
939 if (!is_range) {
940 // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments.
941 CHECK_LE(length, 5);
942 }
943 if (UNLIKELY(length < 0)) {
944 ThrowNegativeArraySizeException(length);
945 return false;
946 }
947 uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
Mathieu Chartier52ea33b2015-06-18 16:48:52 -0700948 Class* array_class = ResolveVerifyAndClinit(type_idx, shadow_frame.GetMethod(),
949 self, false, do_access_check);
950 if (UNLIKELY(array_class == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200951 DCHECK(self->IsExceptionPending());
952 return false;
953 }
Mathieu Chartier52ea33b2015-06-18 16:48:52 -0700954 CHECK(array_class->IsArrayClass());
955 Class* component_class = array_class->GetComponentType();
956 const bool is_primitive_int_component = component_class->IsPrimitiveInt();
957 if (UNLIKELY(component_class->IsPrimitive() && !is_primitive_int_component)) {
958 if (component_class->IsPrimitiveLong() || component_class->IsPrimitiveDouble()) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200959 ThrowRuntimeException("Bad filled array request for type %s",
Mathieu Chartier52ea33b2015-06-18 16:48:52 -0700960 PrettyDescriptor(component_class).c_str());
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200961 } else {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000962 self->ThrowNewExceptionF("Ljava/lang/InternalError;",
Brian Carlstrom4fa0bcd2013-12-10 11:24:21 -0800963 "Found type %s; filled-new-array not implemented for anything but 'int'",
Mathieu Chartier52ea33b2015-06-18 16:48:52 -0700964 PrettyDescriptor(component_class).c_str());
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200965 }
966 return false;
967 }
Mathieu Chartier52ea33b2015-06-18 16:48:52 -0700968 Object* new_array = Array::Alloc<true>(self, array_class, length,
969 array_class->GetComponentSizeShift(),
970 Runtime::Current()->GetHeap()->GetCurrentAllocator());
971 if (UNLIKELY(new_array == nullptr)) {
972 self->AssertPendingOOMException();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200973 return false;
974 }
Igor Murashkin158f35c2015-06-10 15:55:30 -0700975 uint32_t arg[Instruction::kMaxVarArgRegs]; // only used in filled-new-array.
976 uint32_t vregC = 0; // only used in filled-new-array-range.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200977 if (is_range) {
Sebastien Hertzabff6432014-01-27 18:01:39 +0100978 vregC = inst->VRegC_3rc();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200979 } else {
Ian Rogers29a26482014-05-02 15:27:29 -0700980 inst->GetVarArgs(arg);
Sebastien Hertzabff6432014-01-27 18:01:39 +0100981 }
Sebastien Hertzabff6432014-01-27 18:01:39 +0100982 for (int32_t i = 0; i < length; ++i) {
983 size_t src_reg = is_range ? vregC + i : arg[i];
984 if (is_primitive_int_component) {
Mathieu Chartier52ea33b2015-06-18 16:48:52 -0700985 new_array->AsIntArray()->SetWithoutChecks<transaction_active>(
986 i, shadow_frame.GetVReg(src_reg));
Sebastien Hertzabff6432014-01-27 18:01:39 +0100987 } else {
Mathieu Chartier52ea33b2015-06-18 16:48:52 -0700988 new_array->AsObjectArray<Object>()->SetWithoutChecks<transaction_active>(
989 i, shadow_frame.GetVRegReference(src_reg));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200990 }
991 }
992
Mathieu Chartier52ea33b2015-06-18 16:48:52 -0700993 result->SetL(new_array);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200994 return true;
995}
996
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700997// TODO fix thread analysis: should be REQUIRES_SHARED(Locks::mutator_lock_).
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100998template<typename T>
999static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array, int32_t count)
1000 NO_THREAD_SAFETY_ANALYSIS {
1001 Runtime* runtime = Runtime::Current();
1002 for (int32_t i = 0; i < count; ++i) {
1003 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i));
1004 }
1005}
1006
1007void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001008 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001009 DCHECK(Runtime::Current()->IsActiveTransaction());
1010 DCHECK(array != nullptr);
1011 DCHECK_LE(count, array->GetLength());
1012 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType();
1013 switch (primitive_component_type) {
1014 case Primitive::kPrimBoolean:
1015 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count);
1016 break;
1017 case Primitive::kPrimByte:
1018 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count);
1019 break;
1020 case Primitive::kPrimChar:
1021 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count);
1022 break;
1023 case Primitive::kPrimShort:
1024 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count);
1025 break;
1026 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001027 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count);
1028 break;
Mathieu Chartiere401d142015-04-22 13:56:20 -07001029 case Primitive::kPrimFloat:
1030 RecordArrayElementsInTransactionImpl(array->AsFloatArray(), count);
1031 break;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001032 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001033 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count);
1034 break;
Mathieu Chartiere401d142015-04-22 13:56:20 -07001035 case Primitive::kPrimDouble:
1036 RecordArrayElementsInTransactionImpl(array->AsDoubleArray(), count);
1037 break;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001038 default:
1039 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type
1040 << " in fill-array-data";
1041 break;
1042 }
1043}
1044
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001045// Explicit DoCall template function declarations.
Sebastien Hertzc6714852013-09-30 16:42:32 +02001046#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001047 template REQUIRES_SHARED(Locks::mutator_lock_) \
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001048 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \
1049 ShadowFrame& shadow_frame, \
Sebastien Hertzc6714852013-09-30 16:42:32 +02001050 const Instruction* inst, uint16_t inst_data, \
1051 JValue* result)
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001052EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false);
1053EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true);
1054EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false);
1055EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true);
1056#undef EXPLICIT_DO_CALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001057
Narayan Kamath9823e782016-08-03 12:46:58 +01001058// Explicit DoInvokePolymorphic template function declarations.
1059#define EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(_is_range, _do_assignability_check) \
1060 template REQUIRES_SHARED(Locks::mutator_lock_) \
1061 bool DoInvokePolymorphic<_is_range, _do_assignability_check>( \
1062 Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1063 uint16_t inst_data, JValue* result)
1064
1065EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(false, false);
1066EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(false, true);
1067EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(true, false);
1068EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(true, true);
1069#undef EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL
1070
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001071// Explicit DoFilledNewArray template function declarations.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001072#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001073 template REQUIRES_SHARED(Locks::mutator_lock_) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001074 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \
1075 const ShadowFrame& shadow_frame, \
1076 Thread* self, JValue* result)
1077#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \
1078 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \
1079 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \
1080 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \
1081 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active)
1082EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false);
1083EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true);
1084#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001085#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL
1086
1087} // namespace interpreter
1088} // namespace art