blob: b8c228603d7bf3dd7ed0636943e6f277fcb7a155 [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"
Mathieu Chartier0cd81352014-05-22 16:48:55 -070032#include "handle_scope-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020033#include "nth_caller_visitor.h"
34#include "mirror/art_field-inl.h"
35#include "mirror/art_method.h"
36#include "mirror/art_method-inl.h"
37#include "mirror/class.h"
38#include "mirror/class-inl.h"
39#include "mirror/object-inl.h"
40#include "mirror/object_array-inl.h"
41#include "object_utils.h"
42#include "ScopedLocalRef.h"
43#include "scoped_thread_state_change.h"
44#include "thread.h"
45#include "well_known_classes.h"
46
47using ::art::mirror::ArtField;
48using ::art::mirror::ArtMethod;
49using ::art::mirror::Array;
50using ::art::mirror::BooleanArray;
51using ::art::mirror::ByteArray;
52using ::art::mirror::CharArray;
53using ::art::mirror::Class;
54using ::art::mirror::ClassLoader;
55using ::art::mirror::IntArray;
56using ::art::mirror::LongArray;
57using ::art::mirror::Object;
58using ::art::mirror::ObjectArray;
59using ::art::mirror::ShortArray;
60using ::art::mirror::String;
61using ::art::mirror::Throwable;
62
Sebastien Hertz82aeddb2014-05-20 20:09:45 +020063// b/14882674 Workaround stack overflow issue with clang
64#if defined(__clang__) && defined(__aarch64__)
65#define SOMETIMES_INLINE __attribute__((noinline))
66#define SOMETIMES_INLINE_KEYWORD
67#else
68#define SOMETIMES_INLINE ALWAYS_INLINE
69#define SOMETIMES_INLINE_KEYWORD inline
70#endif
71
Sebastien Hertz8ece0502013-08-07 11:26:41 +020072namespace art {
73namespace interpreter {
74
75// External references to both interpreter implementations.
76
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010077template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020078extern JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh,
79 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020080 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020081
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010082template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020083extern JValue ExecuteGotoImpl(Thread* self, MethodHelper& mh,
84 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020085 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020086
Sebastien Hertzda843e12014-05-28 19:28:31 +020087// Workaround for b/14882674 where clang allocates stack for each ThrowLocation created by calls to
88// ShadowFrame::GetCurrentLocationForThrow(). Moving the call here prevents from doing such
89// allocation in the interpreter itself.
90static inline void ThrowNullPointerExceptionFromInterpreter(const ShadowFrame& shadow_frame)
91 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE;
92
93static inline void ThrowNullPointerExceptionFromInterpreter(
94 const ShadowFrame& shadow_frame) {
95 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
96}
97
Sebastien Hertz8ece0502013-08-07 11:26:41 +020098static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
99 ref->MonitorEnter(self);
100}
101
102static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
103 ref->MonitorExit(self);
104}
105
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700106void AbortTransaction(Thread* self, const char* fmt, ...)
107 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
108
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100109void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
110 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
111
Sebastien Hertzc6714852013-09-30 16:42:32 +0200112// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
113// DoInvokeVirtualQuick functions.
114// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200115template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100116bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200117 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200118
Sebastien Hertzc6714852013-09-30 16:42:32 +0200119// Handles invoke-XXX/range instructions.
120// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200121template<InvokeType type, bool is_range, bool do_access_check>
122static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
123 uint16_t inst_data, JValue* result) {
124 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
125 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700126 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700127 mirror::ArtMethod* sf_method = shadow_frame.GetMethod();
128 ArtMethod* const method = FindMethodFromCode<type, do_access_check>(
129 method_idx, &receiver, &sf_method, self);
130 // The shadow frame should already be pushed, so we don't need to update it.
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200131 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200132 CHECK(self->IsExceptionPending());
133 result->SetJ(0);
134 return false;
135 } else if (UNLIKELY(method->IsAbstract())) {
136 ThrowAbstractMethodError(method);
137 result->SetJ(0);
138 return false;
139 } else {
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100140 return DoCall<is_range, do_access_check>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200141 }
142}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200143
Sebastien Hertzc6714852013-09-30 16:42:32 +0200144// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
145// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200146template<bool is_range>
147static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
148 const Instruction* inst, uint16_t inst_data,
149 JValue* result) {
150 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
151 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200152 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200153 // We lost the reference to the method index so we cannot get a more
154 // precised exception message.
155 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
156 return false;
157 }
158 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
159 ArtMethod* const method = receiver->GetClass()->GetVTable()->GetWithoutChecks(vtable_idx);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200160 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200161 CHECK(self->IsExceptionPending());
162 result->SetJ(0);
163 return false;
164 } else if (UNLIKELY(method->IsAbstract())) {
165 ThrowAbstractMethodError(method);
166 result->SetJ(0);
167 return false;
168 } else {
169 // No need to check since we've been quickened.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100170 return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200171 }
172}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200173
Sebastien Hertzc6714852013-09-30 16:42:32 +0200174// Handles iget-XXX and sget-XXX instructions.
175// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200176template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200177static SOMETIMES_INLINE_KEYWORD bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame,
178 const Instruction* inst, uint16_t inst_data) {
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200179 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
180 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
181 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
182 Primitive::FieldSize(field_type));
183 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200184 CHECK(self->IsExceptionPending());
185 return false;
186 }
187 Object* obj;
188 if (is_static) {
189 obj = f->GetDeclaringClass();
190 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200191 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200192 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200193 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), f, true);
194 return false;
195 }
196 }
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200197 // Report this field access to instrumentation if needed.
198 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
199 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
200 Object* this_object = f->IsStatic() ? nullptr : obj;
201 instrumentation->FieldReadEvent(self, this_object, shadow_frame.GetMethod(),
202 shadow_frame.GetDexPC(), f);
203 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200204 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200205 switch (field_type) {
206 case Primitive::kPrimBoolean:
207 shadow_frame.SetVReg(vregA, f->GetBoolean(obj));
208 break;
209 case Primitive::kPrimByte:
210 shadow_frame.SetVReg(vregA, f->GetByte(obj));
211 break;
212 case Primitive::kPrimChar:
213 shadow_frame.SetVReg(vregA, f->GetChar(obj));
214 break;
215 case Primitive::kPrimShort:
216 shadow_frame.SetVReg(vregA, f->GetShort(obj));
217 break;
218 case Primitive::kPrimInt:
219 shadow_frame.SetVReg(vregA, f->GetInt(obj));
220 break;
221 case Primitive::kPrimLong:
222 shadow_frame.SetVRegLong(vregA, f->GetLong(obj));
223 break;
224 case Primitive::kPrimNot:
225 shadow_frame.SetVRegReference(vregA, f->GetObject(obj));
226 break;
227 default:
228 LOG(FATAL) << "Unreachable: " << field_type;
229 }
230 return true;
231}
232
Sebastien Hertzc6714852013-09-30 16:42:32 +0200233// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
234// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200235template<Primitive::Type field_type>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200236static SOMETIMES_INLINE_KEYWORD bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200237 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200238 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200239 // We lost the reference to the field index so we cannot get a more
240 // precised exception message.
241 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
242 return false;
243 }
244 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200245 // Report this field access to instrumentation if needed. Since we only have the offset of
246 // the field from the base of the object, we need to look for it first.
247 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
248 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
249 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
250 field_offset.Uint32Value());
251 DCHECK(f != nullptr);
252 DCHECK(!f->IsStatic());
253 instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
254 shadow_frame.GetDexPC(), f);
255 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700256 // Note: iget-x-quick instructions are only for non-volatile fields.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200257 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200258 switch (field_type) {
259 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700260 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200261 break;
262 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700263 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200264 break;
265 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700266 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200267 break;
268 default:
269 LOG(FATAL) << "Unreachable: " << field_type;
270 }
271 return true;
272}
273
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200274template<Primitive::Type field_type>
275static inline JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
276 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
277 JValue field_value;
278 switch (field_type) {
279 case Primitive::kPrimBoolean:
280 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
281 break;
282 case Primitive::kPrimByte:
283 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
284 break;
285 case Primitive::kPrimChar:
286 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
287 break;
288 case Primitive::kPrimShort:
289 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
290 break;
291 case Primitive::kPrimInt:
292 field_value.SetI(shadow_frame.GetVReg(vreg));
293 break;
294 case Primitive::kPrimLong:
295 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
296 break;
297 case Primitive::kPrimNot:
298 field_value.SetL(shadow_frame.GetVRegReference(vreg));
299 break;
300 default:
301 LOG(FATAL) << "Unreachable: " << field_type;
302 break;
303 }
304 return field_value;
305}
306
Sebastien Hertzc6714852013-09-30 16:42:32 +0200307// Handles iput-XXX and sput-XXX instructions.
308// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100309template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, bool transaction_active>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200310static SOMETIMES_INLINE_KEYWORD bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame,
311 const Instruction* inst, uint16_t inst_data) {
Jeff Haoa3faaf42013-09-03 19:07:00 -0700312 bool do_assignability_check = do_access_check;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200313 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
314 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200315 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
316 Primitive::FieldSize(field_type));
317 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200318 CHECK(self->IsExceptionPending());
319 return false;
320 }
321 Object* obj;
322 if (is_static) {
323 obj = f->GetDeclaringClass();
324 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200325 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200326 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200327 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(),
328 f, false);
329 return false;
330 }
331 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200332 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200333 // Report this field access to instrumentation if needed. Since we only have the offset of
334 // the field from the base of the object, we need to look for it first.
335 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
336 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
337 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
338 Object* this_object = f->IsStatic() ? nullptr : obj;
339 instrumentation->FieldWriteEvent(self, this_object, shadow_frame.GetMethod(),
340 shadow_frame.GetDexPC(), f, field_value);
341 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200342 switch (field_type) {
343 case Primitive::kPrimBoolean:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100344 f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200345 break;
346 case Primitive::kPrimByte:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100347 f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200348 break;
349 case Primitive::kPrimChar:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100350 f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200351 break;
352 case Primitive::kPrimShort:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100353 f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200354 break;
355 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100356 f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200357 break;
358 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100359 f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200360 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700361 case Primitive::kPrimNot: {
362 Object* reg = shadow_frame.GetVRegReference(vregA);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200363 if (do_assignability_check && reg != nullptr) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700364 // FieldHelper::GetType can resolve classes, use a handle wrapper which will restore the
365 // object in the destructor.
366 StackHandleScope<1> hs(self);
367 HandleWrapper<mirror::Object> wrapper(hs.NewHandleWrapper(&obj));
Jeff Haoa3faaf42013-09-03 19:07:00 -0700368 Class* field_class = FieldHelper(f).GetType();
369 if (!reg->VerifierInstanceOf(field_class)) {
370 // This should never happen.
371 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(),
372 "Ljava/lang/VirtualMachineError;",
373 "Put '%s' that is not instance of field '%s' in '%s'",
Mathieu Chartierf8322842014-05-16 10:59:25 -0700374 reg->GetClass()->GetDescriptor().c_str(),
375 field_class->GetDescriptor().c_str(),
376 f->GetDeclaringClass()->GetDescriptor().c_str());
Jeff Haoa3faaf42013-09-03 19:07:00 -0700377 return false;
378 }
379 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100380 f->SetObj<transaction_active>(obj, reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200381 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700382 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200383 default:
384 LOG(FATAL) << "Unreachable: " << field_type;
385 }
386 return true;
387}
388
Sebastien Hertzc6714852013-09-30 16:42:32 +0200389// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
390// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100391template<Primitive::Type field_type, bool transaction_active>
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700392static SOMETIMES_INLINE_KEYWORD bool DoIPutQuick(const ShadowFrame& shadow_frame,
393 const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200394 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200395 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200396 // We lost the reference to the field index so we cannot get a more
397 // precised exception message.
398 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
399 return false;
400 }
401 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200402 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200403 // Report this field modification to instrumentation if needed. Since we only have the offset of
404 // the field from the base of the object, we need to look for it first.
405 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
406 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
407 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
408 field_offset.Uint32Value());
409 DCHECK(f != nullptr);
410 DCHECK(!f->IsStatic());
411 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
412 instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
413 shadow_frame.GetDexPC(), f, field_value);
414 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700415 // Note: iput-x-quick instructions are only for non-volatile fields.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200416 switch (field_type) {
417 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700418 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200419 break;
420 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700421 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200422 break;
423 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700424 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200425 break;
426 default:
427 LOG(FATAL) << "Unreachable: " << field_type;
428 }
429 return true;
430}
431
Sebastien Hertzc6714852013-09-30 16:42:32 +0200432// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
433// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200434static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
435 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800436 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200437 Class* java_lang_string_class = String::GetJavaLangString();
438 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
439 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700440 StackHandleScope<1> hs(self);
441 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
442 if (UNLIKELY(!class_linker->EnsureInitialized(h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200443 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800444 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200445 }
446 }
447 return mh.ResolveString(string_idx);
448}
449
Sebastien Hertzc6714852013-09-30 16:42:32 +0200450// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
451// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200452static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
453 int32_t dividend, int32_t divisor)
454 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700455 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200456 if (UNLIKELY(divisor == 0)) {
457 ThrowArithmeticExceptionDivideByZero();
458 return false;
459 }
460 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
461 shadow_frame.SetVReg(result_reg, kMinInt);
462 } else {
463 shadow_frame.SetVReg(result_reg, dividend / divisor);
464 }
465 return true;
466}
467
Sebastien Hertzc6714852013-09-30 16:42:32 +0200468// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
469// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200470static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
471 int32_t dividend, int32_t divisor)
472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700473 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200474 if (UNLIKELY(divisor == 0)) {
475 ThrowArithmeticExceptionDivideByZero();
476 return false;
477 }
478 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
479 shadow_frame.SetVReg(result_reg, 0);
480 } else {
481 shadow_frame.SetVReg(result_reg, dividend % divisor);
482 }
483 return true;
484}
485
Sebastien Hertzc6714852013-09-30 16:42:32 +0200486// Handles div-long and div-long-2addr instructions.
487// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200488static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
489 int64_t dividend, int64_t divisor)
490 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700491 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200492 if (UNLIKELY(divisor == 0)) {
493 ThrowArithmeticExceptionDivideByZero();
494 return false;
495 }
496 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
497 shadow_frame.SetVRegLong(result_reg, kMinLong);
498 } else {
499 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
500 }
501 return true;
502}
503
Sebastien Hertzc6714852013-09-30 16:42:32 +0200504// Handles rem-long and rem-long-2addr instructions.
505// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200506static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
507 int64_t dividend, int64_t divisor)
508 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700509 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200510 if (UNLIKELY(divisor == 0)) {
511 ThrowArithmeticExceptionDivideByZero();
512 return false;
513 }
514 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
515 shadow_frame.SetVRegLong(result_reg, 0);
516 } else {
517 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
518 }
519 return true;
520}
521
Sebastien Hertzc6714852013-09-30 16:42:32 +0200522// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200523// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100524template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200525bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200526 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200527
Sebastien Hertzc6714852013-09-30 16:42:32 +0200528// Handles packed-switch instruction.
529// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200530static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
531 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200532 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
533 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
534 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200535 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200536 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
537 uint16_t size = switch_data[1];
538 DCHECK_GT(size, 0);
539 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
540 DCHECK(IsAligned<4>(keys));
541 int32_t first_key = keys[0];
542 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
543 DCHECK(IsAligned<4>(targets));
544 int32_t index = test_val - first_key;
545 if (index >= 0 && index < size) {
546 return targets[index];
547 } else {
548 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
549 return 3;
550 }
551}
552
Sebastien Hertzc6714852013-09-30 16:42:32 +0200553// Handles sparse-switch instruction.
554// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200555static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
556 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200557 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
558 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
559 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200560 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200561 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
562 uint16_t size = switch_data[1];
563 DCHECK_GT(size, 0);
564 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
565 DCHECK(IsAligned<4>(keys));
566 const int32_t* entries = keys + size;
567 DCHECK(IsAligned<4>(entries));
568 int lo = 0;
569 int hi = size - 1;
570 while (lo <= hi) {
571 int mid = (lo + hi) / 2;
572 int32_t foundVal = keys[mid];
573 if (test_val < foundVal) {
574 hi = mid - 1;
575 } else if (test_val > foundVal) {
576 lo = mid + 1;
577 } else {
578 return entries[mid];
579 }
580 }
581 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
582 return 3;
583}
584
585static inline uint32_t FindNextInstructionFollowingException(Thread* self,
586 ShadowFrame& shadow_frame,
587 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200588 mirror::Object* this_object,
589 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200590SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200591
592static inline uint32_t FindNextInstructionFollowingException(Thread* self,
593 ShadowFrame& shadow_frame,
594 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200595 mirror::Object* this_object,
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200596 const instrumentation::Instrumentation* instrumentation) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200597 self->VerifyStack();
598 ThrowLocation throw_location;
599 mirror::Throwable* exception = self->GetException(&throw_location);
Sebastien Hertz947ff082013-09-17 14:10:13 +0200600 bool clear_exception = false;
Andreas Gampe72b3e432014-05-13 21:42:05 -0700601 bool new_exception = false;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700602 StackHandleScope<3> hs(self);
603 Handle<mirror::Class> exception_class(hs.NewHandle(exception->GetClass()));
Jeff Haoaa961912014-04-22 13:54:32 -0700604 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc,
Andreas Gampe72b3e432014-05-13 21:42:05 -0700605 &clear_exception,
606 &new_exception);
607 if (UNLIKELY(new_exception)) {
608 // Update the exception.
609 exception = self->GetException(&throw_location);
610 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200611 if (found_dex_pc == DexFile::kDexNoIndex) {
Sebastien Hertz947ff082013-09-17 14:10:13 +0200612 instrumentation->MethodUnwindEvent(self, this_object,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200613 shadow_frame.GetMethod(), dex_pc);
614 } else {
615 instrumentation->ExceptionCaughtEvent(self, throw_location,
616 shadow_frame.GetMethod(),
617 found_dex_pc, exception);
618 if (clear_exception) {
619 self->ClearException();
620 }
621 }
622 return found_dex_pc;
623}
624
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800625static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
626 __attribute__((cold, noreturn))
627 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200628
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800629static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200630 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile());
631 exit(0); // Unreachable, keep GCC happy.
632}
633
634static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700635 const uint32_t dex_pc, MethodHelper& mh)
636 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700637 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200638 if (kTracing) {
639#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700640 std::ostringstream oss;
641 oss << PrettyMethod(shadow_frame.GetMethod())
642 << StringPrintf("\n0x%x: ", dex_pc)
643 << inst->DumpString(&mh.GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800644 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200645 uint32_t raw_value = shadow_frame.GetVReg(i);
646 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800647 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200648 if (ref_value != NULL) {
649 if (ref_value->GetClass()->IsStringClass() &&
650 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700651 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200652 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700653 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200654 }
655 }
656 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700657 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200658#undef TRACE_LOG
659 }
660}
661
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200662static inline bool IsBackwardBranch(int32_t branch_offset) {
663 return branch_offset <= 0;
664}
665
Sebastien Hertzc6714852013-09-30 16:42:32 +0200666// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100667#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200668 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100669 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
670 const Instruction* inst, uint16_t inst_data, \
671 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200672
673#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
674 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
675 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
676 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
677 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
678
679EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
680EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
681EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
682EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
683EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
684#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
685#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
686
687// Explicitly instantiate all DoFieldGet functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100688#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200689 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100690 bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
691 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200692
693#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
694 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
695 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
696
697// iget-XXX
698EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean);
699EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte);
700EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar);
701EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort);
702EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt);
703EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong);
704EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot);
705
706// sget-XXX
707EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean);
708EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte);
709EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar);
710EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort);
711EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt);
712EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong);
713EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot);
714
715#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
716#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
717
718// Explicitly instantiate all DoFieldPut functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100719#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200720 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100721 bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \
722 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200723
724#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100725 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
726 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
727 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
728 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
Sebastien Hertzc6714852013-09-30 16:42:32 +0200729
730// iput-XXX
731EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean);
732EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte);
733EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar);
734EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort);
735EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt);
736EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong);
737EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot);
738
739// sput-XXX
740EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean);
741EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte);
742EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar);
743EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort);
744EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt);
745EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong);
746EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot);
747
748#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
749#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
750
751// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100752#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200753 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100754 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
755 const Instruction* inst, uint16_t inst_data, \
756 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200757
758EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
759EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
760#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
761
762// Explicitly instantiate all DoIGetQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100763#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200764 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100765 bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
766 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200767
768EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
769EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
770EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
771#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
772
773// Explicitly instantiate all DoIPutQuick functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100774#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200775 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100776 bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
777 const Instruction* inst, \
778 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200779
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100780#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
781 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
782 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
783
784EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
785EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
786EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
787#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
Sebastien Hertzc6714852013-09-30 16:42:32 +0200788#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
789
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200790} // namespace interpreter
791} // namespace art
792
793#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_