blob: af8b53445ae4d7bb760d8e63f057a0caf8631eb4 [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 Chartiereb8167a2014-05-07 15:43:14 -0700413 StackHandleScope<1> hs(self);
414 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
415 if (UNLIKELY(!class_linker->EnsureInitialized(h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200416 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800417 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200418 }
419 }
420 return mh.ResolveString(string_idx);
421}
422
Sebastien Hertzc6714852013-09-30 16:42:32 +0200423// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
424// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200425static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
426 int32_t dividend, int32_t divisor)
427 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700428 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200429 if (UNLIKELY(divisor == 0)) {
430 ThrowArithmeticExceptionDivideByZero();
431 return false;
432 }
433 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
434 shadow_frame.SetVReg(result_reg, kMinInt);
435 } else {
436 shadow_frame.SetVReg(result_reg, dividend / divisor);
437 }
438 return true;
439}
440
Sebastien Hertzc6714852013-09-30 16:42:32 +0200441// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
442// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200443static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
444 int32_t dividend, int32_t divisor)
445 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700446 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200447 if (UNLIKELY(divisor == 0)) {
448 ThrowArithmeticExceptionDivideByZero();
449 return false;
450 }
451 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
452 shadow_frame.SetVReg(result_reg, 0);
453 } else {
454 shadow_frame.SetVReg(result_reg, dividend % divisor);
455 }
456 return true;
457}
458
Sebastien Hertzc6714852013-09-30 16:42:32 +0200459// Handles div-long and div-long-2addr instructions.
460// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200461static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
462 int64_t dividend, int64_t divisor)
463 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700464 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200465 if (UNLIKELY(divisor == 0)) {
466 ThrowArithmeticExceptionDivideByZero();
467 return false;
468 }
469 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
470 shadow_frame.SetVRegLong(result_reg, kMinLong);
471 } else {
472 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
473 }
474 return true;
475}
476
Sebastien Hertzc6714852013-09-30 16:42:32 +0200477// Handles rem-long and rem-long-2addr instructions.
478// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200479static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
480 int64_t dividend, int64_t divisor)
481 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700482 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200483 if (UNLIKELY(divisor == 0)) {
484 ThrowArithmeticExceptionDivideByZero();
485 return false;
486 }
487 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
488 shadow_frame.SetVRegLong(result_reg, 0);
489 } else {
490 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
491 }
492 return true;
493}
494
Sebastien Hertzc6714852013-09-30 16:42:32 +0200495// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200496// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100497template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200498bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200499 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200500
Sebastien Hertzc6714852013-09-30 16:42:32 +0200501// Handles packed-switch instruction.
502// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200503static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
504 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200505 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
506 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
507 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200508 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200509 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
510 uint16_t size = switch_data[1];
511 DCHECK_GT(size, 0);
512 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
513 DCHECK(IsAligned<4>(keys));
514 int32_t first_key = keys[0];
515 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
516 DCHECK(IsAligned<4>(targets));
517 int32_t index = test_val - first_key;
518 if (index >= 0 && index < size) {
519 return targets[index];
520 } else {
521 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
522 return 3;
523 }
524}
525
Sebastien Hertzc6714852013-09-30 16:42:32 +0200526// Handles sparse-switch instruction.
527// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200528static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
529 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200530 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
531 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
532 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200533 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200534 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
535 uint16_t size = switch_data[1];
536 DCHECK_GT(size, 0);
537 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
538 DCHECK(IsAligned<4>(keys));
539 const int32_t* entries = keys + size;
540 DCHECK(IsAligned<4>(entries));
541 int lo = 0;
542 int hi = size - 1;
543 while (lo <= hi) {
544 int mid = (lo + hi) / 2;
545 int32_t foundVal = keys[mid];
546 if (test_val < foundVal) {
547 hi = mid - 1;
548 } else if (test_val > foundVal) {
549 lo = mid + 1;
550 } else {
551 return entries[mid];
552 }
553 }
554 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
555 return 3;
556}
557
558static inline uint32_t FindNextInstructionFollowingException(Thread* self,
559 ShadowFrame& shadow_frame,
560 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200561 mirror::Object* this_object,
562 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200563 ALWAYS_INLINE;
564
565static inline uint32_t FindNextInstructionFollowingException(Thread* self,
566 ShadowFrame& shadow_frame,
567 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200568 mirror::Object* this_object,
569 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200570 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
571 self->VerifyStack();
572 ThrowLocation throw_location;
573 mirror::Throwable* exception = self->GetException(&throw_location);
Sebastien Hertz947ff082013-09-17 14:10:13 +0200574 bool clear_exception = false;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700575 StackHandleScope<3> hs(self);
576 Handle<mirror::Class> exception_class(hs.NewHandle(exception->GetClass()));
Jeff Haoaa961912014-04-22 13:54:32 -0700577 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200578 &clear_exception);
579 if (found_dex_pc == DexFile::kDexNoIndex) {
Sebastien Hertz947ff082013-09-17 14:10:13 +0200580 instrumentation->MethodUnwindEvent(self, this_object,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200581 shadow_frame.GetMethod(), dex_pc);
582 } else {
583 instrumentation->ExceptionCaughtEvent(self, throw_location,
584 shadow_frame.GetMethod(),
585 found_dex_pc, exception);
586 if (clear_exception) {
587 self->ClearException();
588 }
589 }
590 return found_dex_pc;
591}
592
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800593static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
594 __attribute__((cold, noreturn))
595 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200596
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800597static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200598 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile());
599 exit(0); // Unreachable, keep GCC happy.
600}
601
602static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700603 const uint32_t dex_pc, MethodHelper& mh)
604 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700605 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200606 if (kTracing) {
607#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700608 std::ostringstream oss;
609 oss << PrettyMethod(shadow_frame.GetMethod())
610 << StringPrintf("\n0x%x: ", dex_pc)
611 << inst->DumpString(&mh.GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800612 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200613 uint32_t raw_value = shadow_frame.GetVReg(i);
614 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800615 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200616 if (ref_value != NULL) {
617 if (ref_value->GetClass()->IsStringClass() &&
618 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700619 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200620 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700621 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200622 }
623 }
624 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700625 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200626#undef TRACE_LOG
627 }
628}
629
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200630static inline bool IsBackwardBranch(int32_t branch_offset) {
631 return branch_offset <= 0;
632}
633
Sebastien Hertzc6714852013-09-30 16:42:32 +0200634// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100635#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
636 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
637 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
638 const Instruction* inst, uint16_t inst_data, \
639 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200640
641#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
642 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
643 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
644 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
645 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
646
647EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
648EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
649EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
650EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
651EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
652#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
653#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
654
655// Explicitly instantiate all DoFieldGet functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100656#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
657 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
658 bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
659 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200660
661#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
662 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
663 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
664
665// iget-XXX
666EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean);
667EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte);
668EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar);
669EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort);
670EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt);
671EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong);
672EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot);
673
674// sget-XXX
675EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean);
676EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte);
677EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar);
678EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort);
679EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt);
680EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong);
681EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot);
682
683#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
684#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
685
686// Explicitly instantiate all DoFieldPut functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100687#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100688 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100689 bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \
690 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200691
692#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100693 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
694 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
695 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
696 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
Sebastien Hertzc6714852013-09-30 16:42:32 +0200697
698// iput-XXX
699EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean);
700EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte);
701EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar);
702EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort);
703EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt);
704EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong);
705EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot);
706
707// sput-XXX
708EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean);
709EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte);
710EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar);
711EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort);
712EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt);
713EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong);
714EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot);
715
716#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
717#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
718
719// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100720#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
721 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
722 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
723 const Instruction* inst, uint16_t inst_data, \
724 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200725
726EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
727EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
728#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
729
730// Explicitly instantiate all DoIGetQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100731#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
732 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
733 bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
734 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200735
736EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
737EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
738EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
739#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
740
741// Explicitly instantiate all DoIPutQuick functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100742#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
743 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) ALWAYS_INLINE \
744 bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
745 const Instruction* inst, \
746 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200747
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100748#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
749 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
750 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
751
752EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
753EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
754EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
755#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
Sebastien Hertzc6714852013-09-30 16:42:32 +0200756#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
757
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200758} // namespace interpreter
759} // namespace art
760
761#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_