blob: ce3346e37d2812aa983032ee6ff1efe52b75bf95 [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#ifndef ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_
18#define ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_
19
20#include "interpreter.h"
21
22#include <math.h>
23
24#include "base/logging.h"
25#include "class_linker-inl.h"
26#include "common_throws.h"
27#include "dex_file-inl.h"
28#include "dex_instruction-inl.h"
29#include "dex_instruction.h"
30#include "entrypoints/entrypoint_utils.h"
31#include "gc/accounting/card_table-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020032#include "nth_caller_visitor.h"
33#include "mirror/art_field-inl.h"
34#include "mirror/art_method.h"
35#include "mirror/art_method-inl.h"
36#include "mirror/class.h"
37#include "mirror/class-inl.h"
38#include "mirror/object-inl.h"
39#include "mirror/object_array-inl.h"
40#include "object_utils.h"
41#include "ScopedLocalRef.h"
42#include "scoped_thread_state_change.h"
43#include "thread.h"
44#include "well_known_classes.h"
45
46using ::art::mirror::ArtField;
47using ::art::mirror::ArtMethod;
48using ::art::mirror::Array;
49using ::art::mirror::BooleanArray;
50using ::art::mirror::ByteArray;
51using ::art::mirror::CharArray;
52using ::art::mirror::Class;
53using ::art::mirror::ClassLoader;
54using ::art::mirror::IntArray;
55using ::art::mirror::LongArray;
56using ::art::mirror::Object;
57using ::art::mirror::ObjectArray;
58using ::art::mirror::ShortArray;
59using ::art::mirror::String;
60using ::art::mirror::Throwable;
61
62namespace art {
63namespace interpreter {
64
65// External references to both interpreter implementations.
66
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010067template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020068extern JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh,
69 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020070 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020071
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010072template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020073extern JValue ExecuteGotoImpl(Thread* self, MethodHelper& mh,
74 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020075 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020076
77static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
78 ref->MonitorEnter(self);
79}
80
81static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
82 ref->MonitorExit(self);
83}
84
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010085void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
86 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
87
Sebastien Hertzc6714852013-09-30 16:42:32 +020088// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
89// DoInvokeVirtualQuick functions.
90// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +020091template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +010092bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +020093 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +020094
Sebastien Hertzc6714852013-09-30 16:42:32 +020095// Handles invoke-XXX/range instructions.
96// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +020097template<InvokeType type, bool is_range, bool do_access_check>
98static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
99 uint16_t inst_data, JValue* result) {
100 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
101 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700102 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200103 ArtMethod* const method = FindMethodFromCode<type, do_access_check>(method_idx, receiver,
104 shadow_frame.GetMethod(),
105 self);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200106 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200107 CHECK(self->IsExceptionPending());
108 result->SetJ(0);
109 return false;
110 } else if (UNLIKELY(method->IsAbstract())) {
111 ThrowAbstractMethodError(method);
112 result->SetJ(0);
113 return false;
114 } else {
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100115 return DoCall<is_range, do_access_check>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200116 }
117}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200118
Sebastien Hertzc6714852013-09-30 16:42:32 +0200119// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
120// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200121template<bool is_range>
122static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
123 const Instruction* inst, uint16_t inst_data,
124 JValue* result) {
125 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
126 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200127 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200128 // We lost the reference to the method index so we cannot get a more
129 // precised exception message.
130 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
131 return false;
132 }
133 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
134 ArtMethod* const method = receiver->GetClass()->GetVTable()->GetWithoutChecks(vtable_idx);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200135 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200136 CHECK(self->IsExceptionPending());
137 result->SetJ(0);
138 return false;
139 } else if (UNLIKELY(method->IsAbstract())) {
140 ThrowAbstractMethodError(method);
141 result->SetJ(0);
142 return false;
143 } else {
144 // No need to check since we've been quickened.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100145 return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200146 }
147}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200148
Sebastien Hertzc6714852013-09-30 16:42:32 +0200149// Handles iget-XXX and sget-XXX instructions.
150// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200151template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
152static inline bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200153 const Instruction* inst, uint16_t inst_data) {
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200154 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
155 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
156 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
157 Primitive::FieldSize(field_type));
158 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200159 CHECK(self->IsExceptionPending());
160 return false;
161 }
162 Object* obj;
163 if (is_static) {
164 obj = f->GetDeclaringClass();
165 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200166 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200167 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200168 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), f, true);
169 return false;
170 }
171 }
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200172 // Report this field access to instrumentation if needed.
173 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
174 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
175 Object* this_object = f->IsStatic() ? nullptr : obj;
176 instrumentation->FieldReadEvent(self, this_object, shadow_frame.GetMethod(),
177 shadow_frame.GetDexPC(), f);
178 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200179 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200180 switch (field_type) {
181 case Primitive::kPrimBoolean:
182 shadow_frame.SetVReg(vregA, f->GetBoolean(obj));
183 break;
184 case Primitive::kPrimByte:
185 shadow_frame.SetVReg(vregA, f->GetByte(obj));
186 break;
187 case Primitive::kPrimChar:
188 shadow_frame.SetVReg(vregA, f->GetChar(obj));
189 break;
190 case Primitive::kPrimShort:
191 shadow_frame.SetVReg(vregA, f->GetShort(obj));
192 break;
193 case Primitive::kPrimInt:
194 shadow_frame.SetVReg(vregA, f->GetInt(obj));
195 break;
196 case Primitive::kPrimLong:
197 shadow_frame.SetVRegLong(vregA, f->GetLong(obj));
198 break;
199 case Primitive::kPrimNot:
200 shadow_frame.SetVRegReference(vregA, f->GetObject(obj));
201 break;
202 default:
203 LOG(FATAL) << "Unreachable: " << field_type;
204 }
205 return true;
206}
207
Sebastien Hertzc6714852013-09-30 16:42:32 +0200208// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
209// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200210template<Primitive::Type field_type>
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200211static inline bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
212 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200213 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200214 // We lost the reference to the field index so we cannot get a more
215 // precised exception message.
216 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
217 return false;
218 }
219 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200220 // Report this field access to instrumentation if needed. Since we only have the offset of
221 // the field from the base of the object, we need to look for it first.
222 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
223 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
224 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
225 field_offset.Uint32Value());
226 DCHECK(f != nullptr);
227 DCHECK(!f->IsStatic());
228 instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
229 shadow_frame.GetDexPC(), f);
230 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700231 // Note: iget-x-quick instructions are only for non-volatile fields.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200232 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200233 switch (field_type) {
234 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700235 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200236 break;
237 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700238 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200239 break;
240 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700241 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200242 break;
243 default:
244 LOG(FATAL) << "Unreachable: " << field_type;
245 }
246 return true;
247}
248
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200249template<Primitive::Type field_type>
250static inline JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
251 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
252 JValue field_value;
253 switch (field_type) {
254 case Primitive::kPrimBoolean:
255 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
256 break;
257 case Primitive::kPrimByte:
258 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
259 break;
260 case Primitive::kPrimChar:
261 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
262 break;
263 case Primitive::kPrimShort:
264 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
265 break;
266 case Primitive::kPrimInt:
267 field_value.SetI(shadow_frame.GetVReg(vreg));
268 break;
269 case Primitive::kPrimLong:
270 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
271 break;
272 case Primitive::kPrimNot:
273 field_value.SetL(shadow_frame.GetVRegReference(vreg));
274 break;
275 default:
276 LOG(FATAL) << "Unreachable: " << field_type;
277 break;
278 }
279 return field_value;
280}
281
Sebastien Hertzc6714852013-09-30 16:42:32 +0200282// Handles iput-XXX and sput-XXX instructions.
283// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100284template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200285static inline bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame,
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200286 const Instruction* inst, uint16_t inst_data) {
Jeff Haoa3faaf42013-09-03 19:07:00 -0700287 bool do_assignability_check = do_access_check;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200288 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
289 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200290 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
291 Primitive::FieldSize(field_type));
292 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200293 CHECK(self->IsExceptionPending());
294 return false;
295 }
296 Object* obj;
297 if (is_static) {
298 obj = f->GetDeclaringClass();
299 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200300 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200301 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200302 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(),
303 f, false);
304 return false;
305 }
306 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200307 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200308 // Report this field access to instrumentation if needed. Since we only have the offset of
309 // the field from the base of the object, we need to look for it first.
310 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
311 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
312 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
313 Object* this_object = f->IsStatic() ? nullptr : obj;
314 instrumentation->FieldWriteEvent(self, this_object, shadow_frame.GetMethod(),
315 shadow_frame.GetDexPC(), f, field_value);
316 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200317 switch (field_type) {
318 case Primitive::kPrimBoolean:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100319 f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200320 break;
321 case Primitive::kPrimByte:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100322 f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200323 break;
324 case Primitive::kPrimChar:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100325 f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200326 break;
327 case Primitive::kPrimShort:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100328 f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200329 break;
330 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100331 f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200332 break;
333 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100334 f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200335 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700336 case Primitive::kPrimNot: {
337 Object* reg = shadow_frame.GetVRegReference(vregA);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200338 if (do_assignability_check && reg != nullptr) {
Jeff Haoa3faaf42013-09-03 19:07:00 -0700339 Class* field_class = FieldHelper(f).GetType();
340 if (!reg->VerifierInstanceOf(field_class)) {
341 // This should never happen.
342 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(),
343 "Ljava/lang/VirtualMachineError;",
344 "Put '%s' that is not instance of field '%s' in '%s'",
345 ClassHelper(reg->GetClass()).GetDescriptor(),
346 ClassHelper(field_class).GetDescriptor(),
347 ClassHelper(f->GetDeclaringClass()).GetDescriptor());
348 return false;
349 }
350 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100351 f->SetObj<transaction_active>(obj, reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200352 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700353 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200354 default:
355 LOG(FATAL) << "Unreachable: " << field_type;
356 }
357 return true;
358}
359
Sebastien Hertzc6714852013-09-30 16:42:32 +0200360// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
361// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100362template<Primitive::Type field_type, bool transaction_active>
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200363static inline bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200364 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200365 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200366 // We lost the reference to the field index so we cannot get a more
367 // precised exception message.
368 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
369 return false;
370 }
371 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200372 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200373 // Report this field modification to instrumentation if needed. Since we only have the offset of
374 // the field from the base of the object, we need to look for it first.
375 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
376 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
377 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
378 field_offset.Uint32Value());
379 DCHECK(f != nullptr);
380 DCHECK(!f->IsStatic());
381 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
382 instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
383 shadow_frame.GetDexPC(), f, field_value);
384 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700385 // Note: iput-x-quick instructions are only for non-volatile fields.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200386 switch (field_type) {
387 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700388 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200389 break;
390 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700391 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200392 break;
393 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700394 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200395 break;
396 default:
397 LOG(FATAL) << "Unreachable: " << field_type;
398 }
399 return true;
400}
401
Sebastien Hertzc6714852013-09-30 16:42:32 +0200402// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
403// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200404static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
405 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800406 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200407 Class* java_lang_string_class = String::GetJavaLangString();
408 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
409 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800410 SirtRef<mirror::Class> sirt_class(self, java_lang_string_class);
411 if (UNLIKELY(!class_linker->EnsureInitialized(sirt_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200412 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800413 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200414 }
415 }
416 return mh.ResolveString(string_idx);
417}
418
Sebastien Hertzc6714852013-09-30 16:42:32 +0200419// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
420// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200421static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
422 int32_t dividend, int32_t divisor)
423 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700424 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200425 if (UNLIKELY(divisor == 0)) {
426 ThrowArithmeticExceptionDivideByZero();
427 return false;
428 }
429 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
430 shadow_frame.SetVReg(result_reg, kMinInt);
431 } else {
432 shadow_frame.SetVReg(result_reg, dividend / divisor);
433 }
434 return true;
435}
436
Sebastien Hertzc6714852013-09-30 16:42:32 +0200437// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
438// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200439static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
440 int32_t dividend, int32_t divisor)
441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700442 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200443 if (UNLIKELY(divisor == 0)) {
444 ThrowArithmeticExceptionDivideByZero();
445 return false;
446 }
447 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
448 shadow_frame.SetVReg(result_reg, 0);
449 } else {
450 shadow_frame.SetVReg(result_reg, dividend % divisor);
451 }
452 return true;
453}
454
Sebastien Hertzc6714852013-09-30 16:42:32 +0200455// Handles div-long and div-long-2addr instructions.
456// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200457static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
458 int64_t dividend, int64_t divisor)
459 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700460 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200461 if (UNLIKELY(divisor == 0)) {
462 ThrowArithmeticExceptionDivideByZero();
463 return false;
464 }
465 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
466 shadow_frame.SetVRegLong(result_reg, kMinLong);
467 } else {
468 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
469 }
470 return true;
471}
472
Sebastien Hertzc6714852013-09-30 16:42:32 +0200473// Handles rem-long and rem-long-2addr instructions.
474// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200475static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
476 int64_t dividend, int64_t divisor)
477 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700478 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200479 if (UNLIKELY(divisor == 0)) {
480 ThrowArithmeticExceptionDivideByZero();
481 return false;
482 }
483 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
484 shadow_frame.SetVRegLong(result_reg, 0);
485 } else {
486 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
487 }
488 return true;
489}
490
Sebastien Hertzc6714852013-09-30 16:42:32 +0200491// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200492// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100493template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200494bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200495 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200496
Sebastien Hertzc6714852013-09-30 16:42:32 +0200497// Handles packed-switch instruction.
498// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200499static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
500 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200501 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
502 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
503 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200504 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200505 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
506 uint16_t size = switch_data[1];
507 DCHECK_GT(size, 0);
508 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
509 DCHECK(IsAligned<4>(keys));
510 int32_t first_key = keys[0];
511 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
512 DCHECK(IsAligned<4>(targets));
513 int32_t index = test_val - first_key;
514 if (index >= 0 && index < size) {
515 return targets[index];
516 } else {
517 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
518 return 3;
519 }
520}
521
Sebastien Hertzc6714852013-09-30 16:42:32 +0200522// Handles sparse-switch instruction.
523// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200524static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
525 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200526 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
527 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
528 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200529 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200530 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
531 uint16_t size = switch_data[1];
532 DCHECK_GT(size, 0);
533 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
534 DCHECK(IsAligned<4>(keys));
535 const int32_t* entries = keys + size;
536 DCHECK(IsAligned<4>(entries));
537 int lo = 0;
538 int hi = size - 1;
539 while (lo <= hi) {
540 int mid = (lo + hi) / 2;
541 int32_t foundVal = keys[mid];
542 if (test_val < foundVal) {
543 hi = mid - 1;
544 } else if (test_val > foundVal) {
545 lo = mid + 1;
546 } else {
547 return entries[mid];
548 }
549 }
550 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
551 return 3;
552}
553
554static inline uint32_t FindNextInstructionFollowingException(Thread* self,
555 ShadowFrame& shadow_frame,
556 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200557 mirror::Object* this_object,
558 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200559 ALWAYS_INLINE;
560
561static inline uint32_t FindNextInstructionFollowingException(Thread* self,
562 ShadowFrame& shadow_frame,
563 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200564 mirror::Object* this_object,
565 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200566 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
567 self->VerifyStack();
568 ThrowLocation throw_location;
569 mirror::Throwable* exception = self->GetException(&throw_location);
Sebastien Hertz947ff082013-09-17 14:10:13 +0200570 bool clear_exception = false;
Jeff Haoaa961912014-04-22 13:54:32 -0700571 SirtRef<mirror::Class> exception_class(self, exception->GetClass());
572 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200573 &clear_exception);
574 if (found_dex_pc == DexFile::kDexNoIndex) {
Sebastien Hertz947ff082013-09-17 14:10:13 +0200575 instrumentation->MethodUnwindEvent(self, this_object,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200576 shadow_frame.GetMethod(), dex_pc);
577 } else {
578 instrumentation->ExceptionCaughtEvent(self, throw_location,
579 shadow_frame.GetMethod(),
580 found_dex_pc, exception);
581 if (clear_exception) {
582 self->ClearException();
583 }
584 }
585 return found_dex_pc;
586}
587
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800588static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
589 __attribute__((cold, noreturn))
590 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200591
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800592static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200593 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile());
594 exit(0); // Unreachable, keep GCC happy.
595}
596
597static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700598 const uint32_t dex_pc, MethodHelper& mh)
599 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700600 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200601 if (kTracing) {
602#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700603 std::ostringstream oss;
604 oss << PrettyMethod(shadow_frame.GetMethod())
605 << StringPrintf("\n0x%x: ", dex_pc)
606 << inst->DumpString(&mh.GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800607 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200608 uint32_t raw_value = shadow_frame.GetVReg(i);
609 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800610 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200611 if (ref_value != NULL) {
612 if (ref_value->GetClass()->IsStringClass() &&
613 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700614 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200615 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700616 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200617 }
618 }
619 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700620 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200621#undef TRACE_LOG
622 }
623}
624
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200625static inline bool IsBackwardBranch(int32_t branch_offset) {
626 return branch_offset <= 0;
627}
628
Sebastien Hertzc6714852013-09-30 16:42:32 +0200629// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100630#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
631 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
632 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
633 const Instruction* inst, uint16_t inst_data, \
634 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200635
636#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
637 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
638 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
639 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
640 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
641
642EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
643EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
644EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
645EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
646EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
647#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
648#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
649
650// Explicitly instantiate all DoFieldGet functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100651#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
652 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
653 bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
654 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200655
656#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
657 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
658 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
659
660// iget-XXX
661EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean);
662EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte);
663EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar);
664EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort);
665EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt);
666EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong);
667EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot);
668
669// sget-XXX
670EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean);
671EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte);
672EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar);
673EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort);
674EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt);
675EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong);
676EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot);
677
678#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
679#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
680
681// Explicitly instantiate all DoFieldPut functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100682#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100683 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100684 bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \
685 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200686
687#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100688 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
689 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
690 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
691 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
Sebastien Hertzc6714852013-09-30 16:42:32 +0200692
693// iput-XXX
694EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean);
695EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte);
696EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar);
697EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort);
698EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt);
699EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong);
700EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot);
701
702// sput-XXX
703EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean);
704EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte);
705EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar);
706EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort);
707EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt);
708EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong);
709EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot);
710
711#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
712#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
713
714// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100715#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
716 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
717 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
718 const Instruction* inst, uint16_t inst_data, \
719 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200720
721EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
722EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
723#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
724
725// Explicitly instantiate all DoIGetQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100726#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
727 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
728 bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
729 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200730
731EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
732EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
733EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
734#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
735
736// Explicitly instantiate all DoIPutQuick functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100737#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
738 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
739 bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
740 const Instruction* inst, \
741 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200742
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100743#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
744 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
745 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
746
747EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
748EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
749EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
750#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
Sebastien Hertzc6714852013-09-30 16:42:32 +0200751#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
752
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200753} // namespace interpreter
754} // namespace art
755
756#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_