blob: cc1fa0c94f66df5337e0fa05b91aefa9262d95a3 [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 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200231 const bool is_volatile = false; // iget-x-quick only on 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:
235 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset, is_volatile)));
236 break;
237 case Primitive::kPrimLong:
238 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset, is_volatile)));
239 break;
240 case Primitive::kPrimNot:
Ian Rogersef7d42f2014-01-06 12:55:46 -0800241 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset, is_volatile));
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 }
385 const bool is_volatile = false; // iput-x-quick only on non volatile fields.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200386 switch (field_type) {
387 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100388 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA), is_volatile);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200389 break;
390 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100391 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA),
392 is_volatile);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200393 break;
394 case Primitive::kPrimNot:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100395 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA),
396 is_volatile);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200397 break;
398 default:
399 LOG(FATAL) << "Unreachable: " << field_type;
400 }
401 return true;
402}
403
Sebastien Hertzc6714852013-09-30 16:42:32 +0200404// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
405// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200406static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
407 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800408 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200409 Class* java_lang_string_class = String::GetJavaLangString();
410 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
411 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800412 SirtRef<mirror::Class> sirt_class(self, java_lang_string_class);
413 if (UNLIKELY(!class_linker->EnsureInitialized(sirt_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200414 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800415 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200416 }
417 }
418 return mh.ResolveString(string_idx);
419}
420
Sebastien Hertzc6714852013-09-30 16:42:32 +0200421// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
422// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200423static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
424 int32_t dividend, int32_t divisor)
425 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700426 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200427 if (UNLIKELY(divisor == 0)) {
428 ThrowArithmeticExceptionDivideByZero();
429 return false;
430 }
431 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
432 shadow_frame.SetVReg(result_reg, kMinInt);
433 } else {
434 shadow_frame.SetVReg(result_reg, dividend / divisor);
435 }
436 return true;
437}
438
Sebastien Hertzc6714852013-09-30 16:42:32 +0200439// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
440// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200441static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
442 int32_t dividend, int32_t divisor)
443 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700444 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200445 if (UNLIKELY(divisor == 0)) {
446 ThrowArithmeticExceptionDivideByZero();
447 return false;
448 }
449 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
450 shadow_frame.SetVReg(result_reg, 0);
451 } else {
452 shadow_frame.SetVReg(result_reg, dividend % divisor);
453 }
454 return true;
455}
456
Sebastien Hertzc6714852013-09-30 16:42:32 +0200457// Handles div-long and div-long-2addr instructions.
458// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200459static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
460 int64_t dividend, int64_t divisor)
461 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700462 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200463 if (UNLIKELY(divisor == 0)) {
464 ThrowArithmeticExceptionDivideByZero();
465 return false;
466 }
467 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
468 shadow_frame.SetVRegLong(result_reg, kMinLong);
469 } else {
470 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
471 }
472 return true;
473}
474
Sebastien Hertzc6714852013-09-30 16:42:32 +0200475// Handles rem-long and rem-long-2addr instructions.
476// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200477static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
478 int64_t dividend, int64_t divisor)
479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700480 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200481 if (UNLIKELY(divisor == 0)) {
482 ThrowArithmeticExceptionDivideByZero();
483 return false;
484 }
485 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
486 shadow_frame.SetVRegLong(result_reg, 0);
487 } else {
488 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
489 }
490 return true;
491}
492
Sebastien Hertzc6714852013-09-30 16:42:32 +0200493// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200494// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100495template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200496bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200497 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200498
Sebastien Hertzc6714852013-09-30 16:42:32 +0200499// Handles packed-switch instruction.
500// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200501static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
502 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200503 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
504 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
505 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200506 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200507 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
508 uint16_t size = switch_data[1];
509 DCHECK_GT(size, 0);
510 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
511 DCHECK(IsAligned<4>(keys));
512 int32_t first_key = keys[0];
513 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
514 DCHECK(IsAligned<4>(targets));
515 int32_t index = test_val - first_key;
516 if (index >= 0 && index < size) {
517 return targets[index];
518 } else {
519 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
520 return 3;
521 }
522}
523
Sebastien Hertzc6714852013-09-30 16:42:32 +0200524// Handles sparse-switch instruction.
525// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200526static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
527 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200528 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
529 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
530 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200531 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200532 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
533 uint16_t size = switch_data[1];
534 DCHECK_GT(size, 0);
535 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
536 DCHECK(IsAligned<4>(keys));
537 const int32_t* entries = keys + size;
538 DCHECK(IsAligned<4>(entries));
539 int lo = 0;
540 int hi = size - 1;
541 while (lo <= hi) {
542 int mid = (lo + hi) / 2;
543 int32_t foundVal = keys[mid];
544 if (test_val < foundVal) {
545 hi = mid - 1;
546 } else if (test_val > foundVal) {
547 lo = mid + 1;
548 } else {
549 return entries[mid];
550 }
551 }
552 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
553 return 3;
554}
555
556static inline uint32_t FindNextInstructionFollowingException(Thread* self,
557 ShadowFrame& shadow_frame,
558 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200559 mirror::Object* this_object,
560 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200561 ALWAYS_INLINE;
562
563static inline uint32_t FindNextInstructionFollowingException(Thread* self,
564 ShadowFrame& shadow_frame,
565 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200566 mirror::Object* this_object,
567 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200568 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
569 self->VerifyStack();
570 ThrowLocation throw_location;
571 mirror::Throwable* exception = self->GetException(&throw_location);
Sebastien Hertz947ff082013-09-17 14:10:13 +0200572 bool clear_exception = false;
Jeff Haoaa961912014-04-22 13:54:32 -0700573 SirtRef<mirror::Class> exception_class(self, exception->GetClass());
574 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200575 &clear_exception);
576 if (found_dex_pc == DexFile::kDexNoIndex) {
Sebastien Hertz947ff082013-09-17 14:10:13 +0200577 instrumentation->MethodUnwindEvent(self, this_object,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200578 shadow_frame.GetMethod(), dex_pc);
579 } else {
580 instrumentation->ExceptionCaughtEvent(self, throw_location,
581 shadow_frame.GetMethod(),
582 found_dex_pc, exception);
583 if (clear_exception) {
584 self->ClearException();
585 }
586 }
587 return found_dex_pc;
588}
589
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800590static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
591 __attribute__((cold, noreturn))
592 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200593
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800594static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200595 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile());
596 exit(0); // Unreachable, keep GCC happy.
597}
598
599static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700600 const uint32_t dex_pc, MethodHelper& mh)
601 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700602 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200603 if (kTracing) {
604#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700605 std::ostringstream oss;
606 oss << PrettyMethod(shadow_frame.GetMethod())
607 << StringPrintf("\n0x%x: ", dex_pc)
608 << inst->DumpString(&mh.GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800609 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200610 uint32_t raw_value = shadow_frame.GetVReg(i);
611 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800612 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200613 if (ref_value != NULL) {
614 if (ref_value->GetClass()->IsStringClass() &&
615 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700616 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200617 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700618 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200619 }
620 }
621 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700622 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200623#undef TRACE_LOG
624 }
625}
626
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200627static inline bool IsBackwardBranch(int32_t branch_offset) {
628 return branch_offset <= 0;
629}
630
Sebastien Hertzc6714852013-09-30 16:42:32 +0200631// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100632#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
633 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
634 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
635 const Instruction* inst, uint16_t inst_data, \
636 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200637
638#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
639 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
640 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
641 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
642 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
643
644EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
645EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
646EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
647EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
648EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
649#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
650#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
651
652// Explicitly instantiate all DoFieldGet functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100653#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
654 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
655 bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
656 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200657
658#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
659 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
660 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
661
662// iget-XXX
663EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean);
664EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte);
665EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar);
666EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort);
667EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt);
668EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong);
669EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot);
670
671// sget-XXX
672EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean);
673EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte);
674EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar);
675EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort);
676EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt);
677EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong);
678EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot);
679
680#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
681#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
682
683// Explicitly instantiate all DoFieldPut functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100684#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100685 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100686 bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \
687 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200688
689#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100690 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
691 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
692 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
693 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
Sebastien Hertzc6714852013-09-30 16:42:32 +0200694
695// iput-XXX
696EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean);
697EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte);
698EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar);
699EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort);
700EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt);
701EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong);
702EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot);
703
704// sput-XXX
705EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean);
706EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte);
707EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar);
708EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort);
709EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt);
710EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong);
711EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot);
712
713#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
714#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
715
716// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100717#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
718 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
719 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
720 const Instruction* inst, uint16_t inst_data, \
721 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200722
723EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
724EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
725#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
726
727// Explicitly instantiate all DoIGetQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100728#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
729 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
730 bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
731 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200732
733EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
734EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
735EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
736#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
737
738// Explicitly instantiate all DoIPutQuick functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100739#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
740 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
741 bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
742 const Instruction* inst, \
743 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200744
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100745#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
746 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
747 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
748
749EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
750EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
751EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
752#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
Sebastien Hertzc6714852013-09-30 16:42:32 +0200753#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
754
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200755} // namespace interpreter
756} // namespace art
757
758#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_