blob: 819b79d74f00555a713fbf35f18a5c00f94f77da [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
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -070085void AbortTransaction(Thread* self, const char* fmt, ...)
86 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
87
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010088void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
89 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
90
Sebastien Hertzc6714852013-09-30 16:42:32 +020091// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
92// DoInvokeVirtualQuick functions.
93// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +020094template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +010095bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +020096 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +020097
Sebastien Hertzc6714852013-09-30 16:42:32 +020098// Handles invoke-XXX/range instructions.
99// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200100template<InvokeType type, bool is_range, bool do_access_check>
101static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
102 uint16_t inst_data, JValue* result) {
103 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
104 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700105 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200106 ArtMethod* const method = FindMethodFromCode<type, do_access_check>(method_idx, receiver,
107 shadow_frame.GetMethod(),
108 self);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200109 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200110 CHECK(self->IsExceptionPending());
111 result->SetJ(0);
112 return false;
113 } else if (UNLIKELY(method->IsAbstract())) {
114 ThrowAbstractMethodError(method);
115 result->SetJ(0);
116 return false;
117 } else {
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100118 return DoCall<is_range, do_access_check>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200119 }
120}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200121
Sebastien Hertzc6714852013-09-30 16:42:32 +0200122// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
123// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200124template<bool is_range>
125static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
126 const Instruction* inst, uint16_t inst_data,
127 JValue* result) {
128 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
129 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200130 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200131 // We lost the reference to the method index so we cannot get a more
132 // precised exception message.
133 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
134 return false;
135 }
136 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
137 ArtMethod* const method = receiver->GetClass()->GetVTable()->GetWithoutChecks(vtable_idx);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200138 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200139 CHECK(self->IsExceptionPending());
140 result->SetJ(0);
141 return false;
142 } else if (UNLIKELY(method->IsAbstract())) {
143 ThrowAbstractMethodError(method);
144 result->SetJ(0);
145 return false;
146 } else {
147 // No need to check since we've been quickened.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100148 return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200149 }
150}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200151
Sebastien Hertzc6714852013-09-30 16:42:32 +0200152// Handles iget-XXX and sget-XXX instructions.
153// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200154template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
155static inline bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200156 const Instruction* inst, uint16_t inst_data) {
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200157 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
158 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
159 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
160 Primitive::FieldSize(field_type));
161 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200162 CHECK(self->IsExceptionPending());
163 return false;
164 }
165 Object* obj;
166 if (is_static) {
167 obj = f->GetDeclaringClass();
168 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200169 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200170 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200171 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), f, true);
172 return false;
173 }
174 }
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200175 // Report this field access to instrumentation if needed.
176 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
177 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
178 Object* this_object = f->IsStatic() ? nullptr : obj;
179 instrumentation->FieldReadEvent(self, this_object, shadow_frame.GetMethod(),
180 shadow_frame.GetDexPC(), f);
181 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200182 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200183 switch (field_type) {
184 case Primitive::kPrimBoolean:
185 shadow_frame.SetVReg(vregA, f->GetBoolean(obj));
186 break;
187 case Primitive::kPrimByte:
188 shadow_frame.SetVReg(vregA, f->GetByte(obj));
189 break;
190 case Primitive::kPrimChar:
191 shadow_frame.SetVReg(vregA, f->GetChar(obj));
192 break;
193 case Primitive::kPrimShort:
194 shadow_frame.SetVReg(vregA, f->GetShort(obj));
195 break;
196 case Primitive::kPrimInt:
197 shadow_frame.SetVReg(vregA, f->GetInt(obj));
198 break;
199 case Primitive::kPrimLong:
200 shadow_frame.SetVRegLong(vregA, f->GetLong(obj));
201 break;
202 case Primitive::kPrimNot:
203 shadow_frame.SetVRegReference(vregA, f->GetObject(obj));
204 break;
205 default:
206 LOG(FATAL) << "Unreachable: " << field_type;
207 }
208 return true;
209}
210
Sebastien Hertzc6714852013-09-30 16:42:32 +0200211// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
212// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200213template<Primitive::Type field_type>
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200214static inline bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
215 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200216 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200217 // We lost the reference to the field index so we cannot get a more
218 // precised exception message.
219 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
220 return false;
221 }
222 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200223 // Report this field access to instrumentation if needed. Since we only have the offset of
224 // the field from the base of the object, we need to look for it first.
225 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
226 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
227 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
228 field_offset.Uint32Value());
229 DCHECK(f != nullptr);
230 DCHECK(!f->IsStatic());
231 instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
232 shadow_frame.GetDexPC(), f);
233 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700234 // Note: iget-x-quick instructions are only for non-volatile fields.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200235 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200236 switch (field_type) {
237 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700238 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200239 break;
240 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700241 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200242 break;
243 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700244 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200245 break;
246 default:
247 LOG(FATAL) << "Unreachable: " << field_type;
248 }
249 return true;
250}
251
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200252template<Primitive::Type field_type>
253static inline JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
254 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
255 JValue field_value;
256 switch (field_type) {
257 case Primitive::kPrimBoolean:
258 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
259 break;
260 case Primitive::kPrimByte:
261 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
262 break;
263 case Primitive::kPrimChar:
264 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
265 break;
266 case Primitive::kPrimShort:
267 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
268 break;
269 case Primitive::kPrimInt:
270 field_value.SetI(shadow_frame.GetVReg(vreg));
271 break;
272 case Primitive::kPrimLong:
273 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
274 break;
275 case Primitive::kPrimNot:
276 field_value.SetL(shadow_frame.GetVRegReference(vreg));
277 break;
278 default:
279 LOG(FATAL) << "Unreachable: " << field_type;
280 break;
281 }
282 return field_value;
283}
284
Sebastien Hertzc6714852013-09-30 16:42:32 +0200285// Handles iput-XXX and sput-XXX instructions.
286// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100287template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200288static inline bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame,
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200289 const Instruction* inst, uint16_t inst_data) {
Jeff Haoa3faaf42013-09-03 19:07:00 -0700290 bool do_assignability_check = do_access_check;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200291 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
292 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200293 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
294 Primitive::FieldSize(field_type));
295 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200296 CHECK(self->IsExceptionPending());
297 return false;
298 }
299 Object* obj;
300 if (is_static) {
301 obj = f->GetDeclaringClass();
302 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200303 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200304 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200305 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(),
306 f, false);
307 return false;
308 }
309 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200310 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200311 // Report this field access to instrumentation if needed. Since we only have the offset of
312 // the field from the base of the object, we need to look for it first.
313 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
314 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
315 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
316 Object* this_object = f->IsStatic() ? nullptr : obj;
317 instrumentation->FieldWriteEvent(self, this_object, shadow_frame.GetMethod(),
318 shadow_frame.GetDexPC(), f, field_value);
319 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200320 switch (field_type) {
321 case Primitive::kPrimBoolean:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100322 f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200323 break;
324 case Primitive::kPrimByte:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100325 f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200326 break;
327 case Primitive::kPrimChar:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100328 f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200329 break;
330 case Primitive::kPrimShort:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100331 f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200332 break;
333 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100334 f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200335 break;
336 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100337 f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200338 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700339 case Primitive::kPrimNot: {
340 Object* reg = shadow_frame.GetVRegReference(vregA);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200341 if (do_assignability_check && reg != nullptr) {
Jeff Haoa3faaf42013-09-03 19:07:00 -0700342 Class* field_class = FieldHelper(f).GetType();
343 if (!reg->VerifierInstanceOf(field_class)) {
344 // This should never happen.
345 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(),
346 "Ljava/lang/VirtualMachineError;",
347 "Put '%s' that is not instance of field '%s' in '%s'",
348 ClassHelper(reg->GetClass()).GetDescriptor(),
349 ClassHelper(field_class).GetDescriptor(),
350 ClassHelper(f->GetDeclaringClass()).GetDescriptor());
351 return false;
352 }
353 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100354 f->SetObj<transaction_active>(obj, reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200355 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700356 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200357 default:
358 LOG(FATAL) << "Unreachable: " << field_type;
359 }
360 return true;
361}
362
Sebastien Hertzc6714852013-09-30 16:42:32 +0200363// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
364// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100365template<Primitive::Type field_type, bool transaction_active>
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200366static inline bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200367 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200368 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200369 // We lost the reference to the field index so we cannot get a more
370 // precised exception message.
371 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
372 return false;
373 }
374 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200375 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200376 // Report this field modification to instrumentation if needed. Since we only have the offset of
377 // the field from the base of the object, we need to look for it first.
378 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
379 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
380 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
381 field_offset.Uint32Value());
382 DCHECK(f != nullptr);
383 DCHECK(!f->IsStatic());
384 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
385 instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
386 shadow_frame.GetDexPC(), f, field_value);
387 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700388 // Note: iput-x-quick instructions are only for non-volatile fields.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200389 switch (field_type) {
390 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700391 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200392 break;
393 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700394 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200395 break;
396 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700397 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200398 break;
399 default:
400 LOG(FATAL) << "Unreachable: " << field_type;
401 }
402 return true;
403}
404
Sebastien Hertzc6714852013-09-30 16:42:32 +0200405// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
406// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200407static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
408 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800409 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200410 Class* java_lang_string_class = String::GetJavaLangString();
411 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
412 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800413 SirtRef<mirror::Class> sirt_class(self, java_lang_string_class);
414 if (UNLIKELY(!class_linker->EnsureInitialized(sirt_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200415 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800416 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200417 }
418 }
419 return mh.ResolveString(string_idx);
420}
421
Sebastien Hertzc6714852013-09-30 16:42:32 +0200422// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
423// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200424static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
425 int32_t dividend, int32_t divisor)
426 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700427 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200428 if (UNLIKELY(divisor == 0)) {
429 ThrowArithmeticExceptionDivideByZero();
430 return false;
431 }
432 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
433 shadow_frame.SetVReg(result_reg, kMinInt);
434 } else {
435 shadow_frame.SetVReg(result_reg, dividend / divisor);
436 }
437 return true;
438}
439
Sebastien Hertzc6714852013-09-30 16:42:32 +0200440// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
441// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200442static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
443 int32_t dividend, int32_t divisor)
444 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700445 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200446 if (UNLIKELY(divisor == 0)) {
447 ThrowArithmeticExceptionDivideByZero();
448 return false;
449 }
450 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
451 shadow_frame.SetVReg(result_reg, 0);
452 } else {
453 shadow_frame.SetVReg(result_reg, dividend % divisor);
454 }
455 return true;
456}
457
Sebastien Hertzc6714852013-09-30 16:42:32 +0200458// Handles div-long and div-long-2addr instructions.
459// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200460static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
461 int64_t dividend, int64_t divisor)
462 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700463 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200464 if (UNLIKELY(divisor == 0)) {
465 ThrowArithmeticExceptionDivideByZero();
466 return false;
467 }
468 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
469 shadow_frame.SetVRegLong(result_reg, kMinLong);
470 } else {
471 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
472 }
473 return true;
474}
475
Sebastien Hertzc6714852013-09-30 16:42:32 +0200476// Handles rem-long and rem-long-2addr instructions.
477// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200478static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
479 int64_t dividend, int64_t divisor)
480 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700481 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200482 if (UNLIKELY(divisor == 0)) {
483 ThrowArithmeticExceptionDivideByZero();
484 return false;
485 }
486 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
487 shadow_frame.SetVRegLong(result_reg, 0);
488 } else {
489 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
490 }
491 return true;
492}
493
Sebastien Hertzc6714852013-09-30 16:42:32 +0200494// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200495// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100496template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200497bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200498 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200499
Sebastien Hertzc6714852013-09-30 16:42:32 +0200500// Handles packed-switch instruction.
501// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200502static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
503 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200504 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
505 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
506 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200507 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200508 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
509 uint16_t size = switch_data[1];
510 DCHECK_GT(size, 0);
511 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
512 DCHECK(IsAligned<4>(keys));
513 int32_t first_key = keys[0];
514 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
515 DCHECK(IsAligned<4>(targets));
516 int32_t index = test_val - first_key;
517 if (index >= 0 && index < size) {
518 return targets[index];
519 } else {
520 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
521 return 3;
522 }
523}
524
Sebastien Hertzc6714852013-09-30 16:42:32 +0200525// Handles sparse-switch instruction.
526// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200527static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
528 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200529 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
530 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
531 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200532 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200533 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
534 uint16_t size = switch_data[1];
535 DCHECK_GT(size, 0);
536 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
537 DCHECK(IsAligned<4>(keys));
538 const int32_t* entries = keys + size;
539 DCHECK(IsAligned<4>(entries));
540 int lo = 0;
541 int hi = size - 1;
542 while (lo <= hi) {
543 int mid = (lo + hi) / 2;
544 int32_t foundVal = keys[mid];
545 if (test_val < foundVal) {
546 hi = mid - 1;
547 } else if (test_val > foundVal) {
548 lo = mid + 1;
549 } else {
550 return entries[mid];
551 }
552 }
553 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
554 return 3;
555}
556
557static inline uint32_t FindNextInstructionFollowingException(Thread* self,
558 ShadowFrame& shadow_frame,
559 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200560 mirror::Object* this_object,
561 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200562 ALWAYS_INLINE;
563
564static inline uint32_t FindNextInstructionFollowingException(Thread* self,
565 ShadowFrame& shadow_frame,
566 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200567 mirror::Object* this_object,
568 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200569 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
570 self->VerifyStack();
571 ThrowLocation throw_location;
572 mirror::Throwable* exception = self->GetException(&throw_location);
Sebastien Hertz947ff082013-09-17 14:10:13 +0200573 bool clear_exception = false;
Jeff Haoaa961912014-04-22 13:54:32 -0700574 SirtRef<mirror::Class> exception_class(self, exception->GetClass());
575 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200576 &clear_exception);
577 if (found_dex_pc == DexFile::kDexNoIndex) {
Sebastien Hertz947ff082013-09-17 14:10:13 +0200578 instrumentation->MethodUnwindEvent(self, this_object,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200579 shadow_frame.GetMethod(), dex_pc);
580 } else {
581 instrumentation->ExceptionCaughtEvent(self, throw_location,
582 shadow_frame.GetMethod(),
583 found_dex_pc, exception);
584 if (clear_exception) {
585 self->ClearException();
586 }
587 }
588 return found_dex_pc;
589}
590
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800591static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
592 __attribute__((cold, noreturn))
593 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200594
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800595static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200596 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile());
597 exit(0); // Unreachable, keep GCC happy.
598}
599
600static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700601 const uint32_t dex_pc, MethodHelper& mh)
602 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700603 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200604 if (kTracing) {
605#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700606 std::ostringstream oss;
607 oss << PrettyMethod(shadow_frame.GetMethod())
608 << StringPrintf("\n0x%x: ", dex_pc)
609 << inst->DumpString(&mh.GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800610 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200611 uint32_t raw_value = shadow_frame.GetVReg(i);
612 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800613 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200614 if (ref_value != NULL) {
615 if (ref_value->GetClass()->IsStringClass() &&
616 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700617 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200618 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700619 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200620 }
621 }
622 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700623 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200624#undef TRACE_LOG
625 }
626}
627
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200628static inline bool IsBackwardBranch(int32_t branch_offset) {
629 return branch_offset <= 0;
630}
631
Sebastien Hertzc6714852013-09-30 16:42:32 +0200632// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100633#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
634 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
635 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
636 const Instruction* inst, uint16_t inst_data, \
637 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200638
639#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
640 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
641 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
642 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
643 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
644
645EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
646EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
647EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
648EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
649EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
650#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
651#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
652
653// Explicitly instantiate all DoFieldGet functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100654#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
655 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
656 bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
657 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200658
659#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
660 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
661 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
662
663// iget-XXX
664EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean);
665EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte);
666EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar);
667EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort);
668EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt);
669EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong);
670EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot);
671
672// sget-XXX
673EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean);
674EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte);
675EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar);
676EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort);
677EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt);
678EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong);
679EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot);
680
681#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
682#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
683
684// Explicitly instantiate all DoFieldPut functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100685#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100686 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100687 bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \
688 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200689
690#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100691 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
692 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
693 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
694 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
Sebastien Hertzc6714852013-09-30 16:42:32 +0200695
696// iput-XXX
697EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean);
698EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte);
699EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar);
700EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort);
701EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt);
702EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong);
703EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot);
704
705// sput-XXX
706EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean);
707EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte);
708EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar);
709EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort);
710EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt);
711EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong);
712EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot);
713
714#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
715#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
716
717// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100718#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
719 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
720 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
721 const Instruction* inst, uint16_t inst_data, \
722 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200723
724EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
725EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
726#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
727
728// Explicitly instantiate all DoIGetQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100729#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
730 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
731 bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
732 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200733
734EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
735EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
736EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
737#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
738
739// Explicitly instantiate all DoIPutQuick functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100740#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
741 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
742 bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
743 const Instruction* inst, \
744 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200745
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100746#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
747 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
748 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
749
750EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
751EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
752EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
753#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
Sebastien Hertzc6714852013-09-30 16:42:32 +0200754#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
755
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200756} // namespace interpreter
757} // namespace art
758
759#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_