blob: 88a84689b52c00ab53efa52e53b6c98a283f40e7 [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.
Mathieu Chartier61c5ebc2014-06-05 17:42:53 -0700366 Class* field_class;
367 {
368 StackHandleScope<3> hs(self);
369 HandleWrapper<mirror::ArtField> h_f(hs.NewHandleWrapper(&f));
370 HandleWrapper<mirror::Object> h_reg(hs.NewHandleWrapper(&reg));
371 HandleWrapper<mirror::Object> h_obj(hs.NewHandleWrapper(&obj));
372 FieldHelper fh(h_f);
373 field_class = fh.GetType();
374 }
Jeff Haoa3faaf42013-09-03 19:07:00 -0700375 if (!reg->VerifierInstanceOf(field_class)) {
376 // This should never happen.
377 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(),
378 "Ljava/lang/VirtualMachineError;",
379 "Put '%s' that is not instance of field '%s' in '%s'",
Mathieu Chartierf8322842014-05-16 10:59:25 -0700380 reg->GetClass()->GetDescriptor().c_str(),
381 field_class->GetDescriptor().c_str(),
382 f->GetDeclaringClass()->GetDescriptor().c_str());
Jeff Haoa3faaf42013-09-03 19:07:00 -0700383 return false;
384 }
385 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100386 f->SetObj<transaction_active>(obj, reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200387 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700388 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200389 default:
390 LOG(FATAL) << "Unreachable: " << field_type;
391 }
392 return true;
393}
394
Sebastien Hertzc6714852013-09-30 16:42:32 +0200395// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
396// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100397template<Primitive::Type field_type, bool transaction_active>
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700398static SOMETIMES_INLINE_KEYWORD bool DoIPutQuick(const ShadowFrame& shadow_frame,
399 const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200400 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200401 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200402 // We lost the reference to the field index so we cannot get a more
403 // precised exception message.
404 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
405 return false;
406 }
407 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200408 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200409 // Report this field modification to instrumentation if needed. Since we only have the offset of
410 // the field from the base of the object, we need to look for it first.
411 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
412 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
413 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
414 field_offset.Uint32Value());
415 DCHECK(f != nullptr);
416 DCHECK(!f->IsStatic());
417 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
418 instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
419 shadow_frame.GetDexPC(), f, field_value);
420 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700421 // Note: iput-x-quick instructions are only for non-volatile fields.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200422 switch (field_type) {
423 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700424 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200425 break;
426 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700427 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200428 break;
429 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700430 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200431 break;
432 default:
433 LOG(FATAL) << "Unreachable: " << field_type;
434 }
435 return true;
436}
437
Sebastien Hertzc6714852013-09-30 16:42:32 +0200438// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
439// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200440static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
441 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800442 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200443 Class* java_lang_string_class = String::GetJavaLangString();
444 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
445 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700446 StackHandleScope<1> hs(self);
447 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
448 if (UNLIKELY(!class_linker->EnsureInitialized(h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200449 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800450 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200451 }
452 }
453 return mh.ResolveString(string_idx);
454}
455
Sebastien Hertzc6714852013-09-30 16:42:32 +0200456// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
457// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200458static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
459 int32_t dividend, int32_t divisor)
460 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700461 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200462 if (UNLIKELY(divisor == 0)) {
463 ThrowArithmeticExceptionDivideByZero();
464 return false;
465 }
466 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
467 shadow_frame.SetVReg(result_reg, kMinInt);
468 } else {
469 shadow_frame.SetVReg(result_reg, dividend / divisor);
470 }
471 return true;
472}
473
Sebastien Hertzc6714852013-09-30 16:42:32 +0200474// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
475// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200476static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
477 int32_t dividend, int32_t divisor)
478 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700479 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200480 if (UNLIKELY(divisor == 0)) {
481 ThrowArithmeticExceptionDivideByZero();
482 return false;
483 }
484 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
485 shadow_frame.SetVReg(result_reg, 0);
486 } else {
487 shadow_frame.SetVReg(result_reg, dividend % divisor);
488 }
489 return true;
490}
491
Sebastien Hertzc6714852013-09-30 16:42:32 +0200492// Handles div-long and div-long-2addr instructions.
493// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200494static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
495 int64_t dividend, int64_t divisor)
496 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700497 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200498 if (UNLIKELY(divisor == 0)) {
499 ThrowArithmeticExceptionDivideByZero();
500 return false;
501 }
502 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
503 shadow_frame.SetVRegLong(result_reg, kMinLong);
504 } else {
505 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
506 }
507 return true;
508}
509
Sebastien Hertzc6714852013-09-30 16:42:32 +0200510// Handles rem-long and rem-long-2addr instructions.
511// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200512static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
513 int64_t dividend, int64_t divisor)
514 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700515 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200516 if (UNLIKELY(divisor == 0)) {
517 ThrowArithmeticExceptionDivideByZero();
518 return false;
519 }
520 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
521 shadow_frame.SetVRegLong(result_reg, 0);
522 } else {
523 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
524 }
525 return true;
526}
527
Sebastien Hertzc6714852013-09-30 16:42:32 +0200528// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200529// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100530template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200531bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200532 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200533
Sebastien Hertzc6714852013-09-30 16:42:32 +0200534// Handles packed-switch instruction.
535// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200536static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
537 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200538 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
539 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
540 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200541 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200542 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
543 uint16_t size = switch_data[1];
544 DCHECK_GT(size, 0);
545 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
546 DCHECK(IsAligned<4>(keys));
547 int32_t first_key = keys[0];
548 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
549 DCHECK(IsAligned<4>(targets));
550 int32_t index = test_val - first_key;
551 if (index >= 0 && index < size) {
552 return targets[index];
553 } else {
554 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
555 return 3;
556 }
557}
558
Sebastien Hertzc6714852013-09-30 16:42:32 +0200559// Handles sparse-switch instruction.
560// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200561static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
562 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200563 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
564 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
565 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200566 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200567 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
568 uint16_t size = switch_data[1];
569 DCHECK_GT(size, 0);
570 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
571 DCHECK(IsAligned<4>(keys));
572 const int32_t* entries = keys + size;
573 DCHECK(IsAligned<4>(entries));
574 int lo = 0;
575 int hi = size - 1;
576 while (lo <= hi) {
577 int mid = (lo + hi) / 2;
578 int32_t foundVal = keys[mid];
579 if (test_val < foundVal) {
580 hi = mid - 1;
581 } else if (test_val > foundVal) {
582 lo = mid + 1;
583 } else {
584 return entries[mid];
585 }
586 }
587 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
588 return 3;
589}
590
591static inline uint32_t FindNextInstructionFollowingException(Thread* self,
592 ShadowFrame& shadow_frame,
593 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200594 mirror::Object* this_object,
595 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200596SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200597
598static inline uint32_t FindNextInstructionFollowingException(Thread* self,
599 ShadowFrame& shadow_frame,
600 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200601 mirror::Object* this_object,
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200602 const instrumentation::Instrumentation* instrumentation) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200603 self->VerifyStack();
604 ThrowLocation throw_location;
605 mirror::Throwable* exception = self->GetException(&throw_location);
Sebastien Hertz947ff082013-09-17 14:10:13 +0200606 bool clear_exception = false;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700607 uint32_t found_dex_pc;
608 {
609 StackHandleScope<3> hs(self);
610 Handle<mirror::Class> exception_class(hs.NewHandle(exception->GetClass()));
611 Handle<mirror::ArtMethod> h_method(hs.NewHandle(shadow_frame.GetMethod()));
612 HandleWrapper<mirror::Object> h(hs.NewHandleWrapper(&this_object));
613 found_dex_pc = mirror::ArtMethod::FindCatchBlock(h_method, exception_class, dex_pc,
614 &clear_exception);
615 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200616 if (found_dex_pc == DexFile::kDexNoIndex) {
Sebastien Hertz947ff082013-09-17 14:10:13 +0200617 instrumentation->MethodUnwindEvent(self, this_object,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200618 shadow_frame.GetMethod(), dex_pc);
619 } else {
620 instrumentation->ExceptionCaughtEvent(self, throw_location,
621 shadow_frame.GetMethod(),
622 found_dex_pc, exception);
623 if (clear_exception) {
624 self->ClearException();
625 }
626 }
627 return found_dex_pc;
628}
629
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800630static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
631 __attribute__((cold, noreturn))
632 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200633
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800634static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700635 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(mh.GetMethod()->GetDexFile());
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200636 exit(0); // Unreachable, keep GCC happy.
637}
638
639static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700640 const uint32_t dex_pc, MethodHelper& mh)
641 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700642 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200643 if (kTracing) {
644#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700645 std::ostringstream oss;
646 oss << PrettyMethod(shadow_frame.GetMethod())
647 << StringPrintf("\n0x%x: ", dex_pc)
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700648 << inst->DumpString(mh.GetMethod()->GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800649 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200650 uint32_t raw_value = shadow_frame.GetVReg(i);
651 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800652 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200653 if (ref_value != NULL) {
654 if (ref_value->GetClass()->IsStringClass() &&
655 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700656 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200657 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700658 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200659 }
660 }
661 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700662 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200663#undef TRACE_LOG
664 }
665}
666
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200667static inline bool IsBackwardBranch(int32_t branch_offset) {
668 return branch_offset <= 0;
669}
670
Sebastien Hertzc6714852013-09-30 16:42:32 +0200671// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100672#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200673 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100674 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
675 const Instruction* inst, uint16_t inst_data, \
676 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200677
678#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
679 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
680 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
681 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
682 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
683
684EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
685EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
686EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
687EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
688EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
689#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
690#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
691
692// Explicitly instantiate all DoFieldGet functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100693#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200694 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100695 bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
696 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200697
698#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
699 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
700 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
701
702// iget-XXX
703EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean);
704EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte);
705EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar);
706EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort);
707EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt);
708EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong);
709EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot);
710
711// sget-XXX
712EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean);
713EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte);
714EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar);
715EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort);
716EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt);
717EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong);
718EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot);
719
720#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
721#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
722
723// Explicitly instantiate all DoFieldPut functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100724#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200725 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100726 bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \
727 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200728
729#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100730 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
731 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
732 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
733 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
Sebastien Hertzc6714852013-09-30 16:42:32 +0200734
735// iput-XXX
736EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean);
737EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte);
738EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar);
739EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort);
740EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt);
741EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong);
742EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot);
743
744// sput-XXX
745EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean);
746EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte);
747EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar);
748EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort);
749EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt);
750EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong);
751EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot);
752
753#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
754#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
755
756// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100757#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200758 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100759 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
760 const Instruction* inst, uint16_t inst_data, \
761 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200762
763EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
764EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
765#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
766
767// Explicitly instantiate all DoIGetQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100768#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200769 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100770 bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
771 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200772
773EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
774EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
775EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
776#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
777
778// Explicitly instantiate all DoIPutQuick functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100779#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200780 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100781 bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
782 const Instruction* inst, \
783 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200784
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100785#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
786 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
787 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
788
789EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
790EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
791EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
792#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
Sebastien Hertzc6714852013-09-30 16:42:32 +0200793#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
794
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200795} // namespace interpreter
796} // namespace art
797
798#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_