blob: cfc90a6618f91627ddea412031225b93a1439731 [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
87static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
88 ref->MonitorEnter(self);
89}
90
91static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
92 ref->MonitorExit(self);
93}
94
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -070095void AbortTransaction(Thread* self, const char* fmt, ...)
96 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
97
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010098void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
99 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
100
Sebastien Hertzc6714852013-09-30 16:42:32 +0200101// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
102// DoInvokeVirtualQuick functions.
103// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200104template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100105bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200106 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200107
Sebastien Hertzc6714852013-09-30 16:42:32 +0200108// Handles invoke-XXX/range instructions.
109// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200110template<InvokeType type, bool is_range, bool do_access_check>
111static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
112 uint16_t inst_data, JValue* result) {
113 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
114 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700115 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700116 mirror::ArtMethod* sf_method = shadow_frame.GetMethod();
117 ArtMethod* const method = FindMethodFromCode<type, do_access_check>(
118 method_idx, &receiver, &sf_method, self);
119 // The shadow frame should already be pushed, so we don't need to update it.
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200120 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200121 CHECK(self->IsExceptionPending());
122 result->SetJ(0);
123 return false;
124 } else if (UNLIKELY(method->IsAbstract())) {
125 ThrowAbstractMethodError(method);
126 result->SetJ(0);
127 return false;
128 } else {
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100129 return DoCall<is_range, do_access_check>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200130 }
131}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200132
Sebastien Hertzc6714852013-09-30 16:42:32 +0200133// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
134// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200135template<bool is_range>
136static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
137 const Instruction* inst, uint16_t inst_data,
138 JValue* result) {
139 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
140 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200141 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200142 // We lost the reference to the method index so we cannot get a more
143 // precised exception message.
144 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
145 return false;
146 }
147 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
148 ArtMethod* const method = receiver->GetClass()->GetVTable()->GetWithoutChecks(vtable_idx);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200149 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200150 CHECK(self->IsExceptionPending());
151 result->SetJ(0);
152 return false;
153 } else if (UNLIKELY(method->IsAbstract())) {
154 ThrowAbstractMethodError(method);
155 result->SetJ(0);
156 return false;
157 } else {
158 // No need to check since we've been quickened.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100159 return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200160 }
161}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200162
Sebastien Hertzc6714852013-09-30 16:42:32 +0200163// Handles iget-XXX and sget-XXX instructions.
164// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200165template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200166static SOMETIMES_INLINE_KEYWORD bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame,
167 const Instruction* inst, uint16_t inst_data) {
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200168 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
169 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
170 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
171 Primitive::FieldSize(field_type));
172 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200173 CHECK(self->IsExceptionPending());
174 return false;
175 }
176 Object* obj;
177 if (is_static) {
178 obj = f->GetDeclaringClass();
179 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200180 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200181 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200182 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), f, true);
183 return false;
184 }
185 }
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200186 // Report this field access to instrumentation if needed.
187 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
188 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
189 Object* this_object = f->IsStatic() ? nullptr : obj;
190 instrumentation->FieldReadEvent(self, this_object, shadow_frame.GetMethod(),
191 shadow_frame.GetDexPC(), f);
192 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200193 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200194 switch (field_type) {
195 case Primitive::kPrimBoolean:
196 shadow_frame.SetVReg(vregA, f->GetBoolean(obj));
197 break;
198 case Primitive::kPrimByte:
199 shadow_frame.SetVReg(vregA, f->GetByte(obj));
200 break;
201 case Primitive::kPrimChar:
202 shadow_frame.SetVReg(vregA, f->GetChar(obj));
203 break;
204 case Primitive::kPrimShort:
205 shadow_frame.SetVReg(vregA, f->GetShort(obj));
206 break;
207 case Primitive::kPrimInt:
208 shadow_frame.SetVReg(vregA, f->GetInt(obj));
209 break;
210 case Primitive::kPrimLong:
211 shadow_frame.SetVRegLong(vregA, f->GetLong(obj));
212 break;
213 case Primitive::kPrimNot:
214 shadow_frame.SetVRegReference(vregA, f->GetObject(obj));
215 break;
216 default:
217 LOG(FATAL) << "Unreachable: " << field_type;
218 }
219 return true;
220}
221
Sebastien Hertzc6714852013-09-30 16:42:32 +0200222// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
223// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200224template<Primitive::Type field_type>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200225static SOMETIMES_INLINE_KEYWORD bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200226 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200227 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200228 // We lost the reference to the field index so we cannot get a more
229 // precised exception message.
230 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
231 return false;
232 }
233 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200234 // Report this field access to instrumentation if needed. Since we only have the offset of
235 // the field from the base of the object, we need to look for it first.
236 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
237 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
238 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
239 field_offset.Uint32Value());
240 DCHECK(f != nullptr);
241 DCHECK(!f->IsStatic());
242 instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
243 shadow_frame.GetDexPC(), f);
244 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700245 // Note: iget-x-quick instructions are only for non-volatile fields.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200246 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200247 switch (field_type) {
248 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700249 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200250 break;
251 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700252 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200253 break;
254 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700255 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200256 break;
257 default:
258 LOG(FATAL) << "Unreachable: " << field_type;
259 }
260 return true;
261}
262
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200263template<Primitive::Type field_type>
264static inline JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
265 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
266 JValue field_value;
267 switch (field_type) {
268 case Primitive::kPrimBoolean:
269 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
270 break;
271 case Primitive::kPrimByte:
272 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
273 break;
274 case Primitive::kPrimChar:
275 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
276 break;
277 case Primitive::kPrimShort:
278 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
279 break;
280 case Primitive::kPrimInt:
281 field_value.SetI(shadow_frame.GetVReg(vreg));
282 break;
283 case Primitive::kPrimLong:
284 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
285 break;
286 case Primitive::kPrimNot:
287 field_value.SetL(shadow_frame.GetVRegReference(vreg));
288 break;
289 default:
290 LOG(FATAL) << "Unreachable: " << field_type;
291 break;
292 }
293 return field_value;
294}
295
Sebastien Hertzc6714852013-09-30 16:42:32 +0200296// Handles iput-XXX and sput-XXX instructions.
297// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100298template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, bool transaction_active>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200299static SOMETIMES_INLINE_KEYWORD bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame,
300 const Instruction* inst, uint16_t inst_data) {
Jeff Haoa3faaf42013-09-03 19:07:00 -0700301 bool do_assignability_check = do_access_check;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200302 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
303 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200304 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
305 Primitive::FieldSize(field_type));
306 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200307 CHECK(self->IsExceptionPending());
308 return false;
309 }
310 Object* obj;
311 if (is_static) {
312 obj = f->GetDeclaringClass();
313 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200314 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200315 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200316 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(),
317 f, false);
318 return false;
319 }
320 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200321 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200322 // Report this field access to instrumentation if needed. Since we only have the offset of
323 // the field from the base of the object, we need to look for it first.
324 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
325 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
326 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
327 Object* this_object = f->IsStatic() ? nullptr : obj;
328 instrumentation->FieldWriteEvent(self, this_object, shadow_frame.GetMethod(),
329 shadow_frame.GetDexPC(), f, field_value);
330 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200331 switch (field_type) {
332 case Primitive::kPrimBoolean:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100333 f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200334 break;
335 case Primitive::kPrimByte:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100336 f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200337 break;
338 case Primitive::kPrimChar:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100339 f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200340 break;
341 case Primitive::kPrimShort:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100342 f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200343 break;
344 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100345 f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200346 break;
347 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100348 f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200349 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700350 case Primitive::kPrimNot: {
351 Object* reg = shadow_frame.GetVRegReference(vregA);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200352 if (do_assignability_check && reg != nullptr) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700353 // FieldHelper::GetType can resolve classes, use a handle wrapper which will restore the
354 // object in the destructor.
355 StackHandleScope<1> hs(self);
356 HandleWrapper<mirror::Object> wrapper(hs.NewHandleWrapper(&obj));
Jeff Haoa3faaf42013-09-03 19:07:00 -0700357 Class* field_class = FieldHelper(f).GetType();
358 if (!reg->VerifierInstanceOf(field_class)) {
359 // This should never happen.
360 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(),
361 "Ljava/lang/VirtualMachineError;",
362 "Put '%s' that is not instance of field '%s' in '%s'",
Mathieu Chartierf8322842014-05-16 10:59:25 -0700363 reg->GetClass()->GetDescriptor().c_str(),
364 field_class->GetDescriptor().c_str(),
365 f->GetDeclaringClass()->GetDescriptor().c_str());
Jeff Haoa3faaf42013-09-03 19:07:00 -0700366 return false;
367 }
368 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100369 f->SetObj<transaction_active>(obj, reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200370 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700371 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200372 default:
373 LOG(FATAL) << "Unreachable: " << field_type;
374 }
375 return true;
376}
377
Sebastien Hertzc6714852013-09-30 16:42:32 +0200378// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
379// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100380template<Primitive::Type field_type, bool transaction_active>
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700381static SOMETIMES_INLINE_KEYWORD bool DoIPutQuick(const ShadowFrame& shadow_frame,
382 const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200383 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200384 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200385 // We lost the reference to the field index so we cannot get a more
386 // precised exception message.
387 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
388 return false;
389 }
390 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200391 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200392 // Report this field modification to instrumentation if needed. Since we only have the offset of
393 // the field from the base of the object, we need to look for it first.
394 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
395 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
396 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
397 field_offset.Uint32Value());
398 DCHECK(f != nullptr);
399 DCHECK(!f->IsStatic());
400 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
401 instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
402 shadow_frame.GetDexPC(), f, field_value);
403 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700404 // Note: iput-x-quick instructions are only for non-volatile fields.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200405 switch (field_type) {
406 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700407 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200408 break;
409 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700410 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200411 break;
412 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700413 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200414 break;
415 default:
416 LOG(FATAL) << "Unreachable: " << field_type;
417 }
418 return true;
419}
420
Sebastien Hertzc6714852013-09-30 16:42:32 +0200421// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
422// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200423static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
424 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800425 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200426 Class* java_lang_string_class = String::GetJavaLangString();
427 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
428 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700429 StackHandleScope<1> hs(self);
430 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
431 if (UNLIKELY(!class_linker->EnsureInitialized(h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200432 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800433 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200434 }
435 }
436 return mh.ResolveString(string_idx);
437}
438
Sebastien Hertzc6714852013-09-30 16:42:32 +0200439// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
440// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200441static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
442 int32_t dividend, int32_t divisor)
443 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700444 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200445 if (UNLIKELY(divisor == 0)) {
446 ThrowArithmeticExceptionDivideByZero();
447 return false;
448 }
449 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
450 shadow_frame.SetVReg(result_reg, kMinInt);
451 } else {
452 shadow_frame.SetVReg(result_reg, dividend / divisor);
453 }
454 return true;
455}
456
Sebastien Hertzc6714852013-09-30 16:42:32 +0200457// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
458// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200459static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
460 int32_t dividend, int32_t divisor)
461 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700462 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200463 if (UNLIKELY(divisor == 0)) {
464 ThrowArithmeticExceptionDivideByZero();
465 return false;
466 }
467 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
468 shadow_frame.SetVReg(result_reg, 0);
469 } else {
470 shadow_frame.SetVReg(result_reg, dividend % divisor);
471 }
472 return true;
473}
474
Sebastien Hertzc6714852013-09-30 16:42:32 +0200475// Handles div-long and div-long-2addr instructions.
476// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200477static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
478 int64_t dividend, int64_t divisor)
479 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700480 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200481 if (UNLIKELY(divisor == 0)) {
482 ThrowArithmeticExceptionDivideByZero();
483 return false;
484 }
485 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
486 shadow_frame.SetVRegLong(result_reg, kMinLong);
487 } else {
488 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
489 }
490 return true;
491}
492
Sebastien Hertzc6714852013-09-30 16:42:32 +0200493// Handles rem-long and rem-long-2addr instructions.
494// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200495static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
496 int64_t dividend, int64_t divisor)
497 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700498 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200499 if (UNLIKELY(divisor == 0)) {
500 ThrowArithmeticExceptionDivideByZero();
501 return false;
502 }
503 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
504 shadow_frame.SetVRegLong(result_reg, 0);
505 } else {
506 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
507 }
508 return true;
509}
510
Sebastien Hertzc6714852013-09-30 16:42:32 +0200511// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200512// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100513template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200514bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200515 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200516
Sebastien Hertzc6714852013-09-30 16:42:32 +0200517// Handles packed-switch instruction.
518// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200519static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
520 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200521 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
522 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
523 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200524 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200525 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
526 uint16_t size = switch_data[1];
527 DCHECK_GT(size, 0);
528 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
529 DCHECK(IsAligned<4>(keys));
530 int32_t first_key = keys[0];
531 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
532 DCHECK(IsAligned<4>(targets));
533 int32_t index = test_val - first_key;
534 if (index >= 0 && index < size) {
535 return targets[index];
536 } else {
537 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
538 return 3;
539 }
540}
541
Sebastien Hertzc6714852013-09-30 16:42:32 +0200542// Handles sparse-switch instruction.
543// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200544static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
545 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200546 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
547 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
548 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200549 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200550 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
551 uint16_t size = switch_data[1];
552 DCHECK_GT(size, 0);
553 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
554 DCHECK(IsAligned<4>(keys));
555 const int32_t* entries = keys + size;
556 DCHECK(IsAligned<4>(entries));
557 int lo = 0;
558 int hi = size - 1;
559 while (lo <= hi) {
560 int mid = (lo + hi) / 2;
561 int32_t foundVal = keys[mid];
562 if (test_val < foundVal) {
563 hi = mid - 1;
564 } else if (test_val > foundVal) {
565 lo = mid + 1;
566 } else {
567 return entries[mid];
568 }
569 }
570 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
571 return 3;
572}
573
574static inline uint32_t FindNextInstructionFollowingException(Thread* self,
575 ShadowFrame& shadow_frame,
576 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200577 mirror::Object* this_object,
578 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200579SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200580
581static inline uint32_t FindNextInstructionFollowingException(Thread* self,
582 ShadowFrame& shadow_frame,
583 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200584 mirror::Object* this_object,
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200585 const instrumentation::Instrumentation* instrumentation) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200586 self->VerifyStack();
587 ThrowLocation throw_location;
588 mirror::Throwable* exception = self->GetException(&throw_location);
Sebastien Hertz947ff082013-09-17 14:10:13 +0200589 bool clear_exception = false;
Andreas Gampe72b3e432014-05-13 21:42:05 -0700590 bool new_exception = false;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700591 StackHandleScope<3> hs(self);
592 Handle<mirror::Class> exception_class(hs.NewHandle(exception->GetClass()));
Jeff Haoaa961912014-04-22 13:54:32 -0700593 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc,
Andreas Gampe72b3e432014-05-13 21:42:05 -0700594 &clear_exception,
595 &new_exception);
596 if (UNLIKELY(new_exception)) {
597 // Update the exception.
598 exception = self->GetException(&throw_location);
599 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200600 if (found_dex_pc == DexFile::kDexNoIndex) {
Sebastien Hertz947ff082013-09-17 14:10:13 +0200601 instrumentation->MethodUnwindEvent(self, this_object,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200602 shadow_frame.GetMethod(), dex_pc);
603 } else {
604 instrumentation->ExceptionCaughtEvent(self, throw_location,
605 shadow_frame.GetMethod(),
606 found_dex_pc, exception);
607 if (clear_exception) {
608 self->ClearException();
609 }
610 }
611 return found_dex_pc;
612}
613
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800614static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
615 __attribute__((cold, noreturn))
616 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200617
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800618static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200619 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile());
620 exit(0); // Unreachable, keep GCC happy.
621}
622
623static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700624 const uint32_t dex_pc, MethodHelper& mh)
625 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700626 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200627 if (kTracing) {
628#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700629 std::ostringstream oss;
630 oss << PrettyMethod(shadow_frame.GetMethod())
631 << StringPrintf("\n0x%x: ", dex_pc)
632 << inst->DumpString(&mh.GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800633 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200634 uint32_t raw_value = shadow_frame.GetVReg(i);
635 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800636 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200637 if (ref_value != NULL) {
638 if (ref_value->GetClass()->IsStringClass() &&
639 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700640 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200641 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700642 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200643 }
644 }
645 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700646 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200647#undef TRACE_LOG
648 }
649}
650
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200651static inline bool IsBackwardBranch(int32_t branch_offset) {
652 return branch_offset <= 0;
653}
654
Sebastien Hertzc6714852013-09-30 16:42:32 +0200655// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100656#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200657 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100658 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
659 const Instruction* inst, uint16_t inst_data, \
660 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200661
662#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
663 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
664 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
665 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
666 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
667
668EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
669EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
670EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
671EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
672EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
673#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
674#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
675
676// Explicitly instantiate all DoFieldGet functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100677#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200678 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100679 bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
680 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200681
682#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
683 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
684 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
685
686// iget-XXX
687EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean);
688EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte);
689EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar);
690EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort);
691EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt);
692EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong);
693EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot);
694
695// sget-XXX
696EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean);
697EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte);
698EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar);
699EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort);
700EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt);
701EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong);
702EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot);
703
704#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
705#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
706
707// Explicitly instantiate all DoFieldPut functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100708#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200709 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100710 bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \
711 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200712
713#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100714 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
715 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
716 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
717 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
Sebastien Hertzc6714852013-09-30 16:42:32 +0200718
719// iput-XXX
720EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean);
721EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte);
722EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar);
723EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort);
724EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt);
725EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong);
726EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot);
727
728// sput-XXX
729EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean);
730EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte);
731EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar);
732EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort);
733EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt);
734EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong);
735EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot);
736
737#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
738#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
739
740// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100741#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200742 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100743 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
744 const Instruction* inst, uint16_t inst_data, \
745 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200746
747EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
748EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
749#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
750
751// Explicitly instantiate all DoIGetQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100752#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
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 DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
755 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200756
757EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
758EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
759EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
760#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
761
762// Explicitly instantiate all DoIPutQuick functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100763#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200764 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100765 bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
766 const Instruction* inst, \
767 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200768
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100769#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
770 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
771 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
772
773EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
774EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
775EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
776#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
Sebastien Hertzc6714852013-09-30 16:42:32 +0200777#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
778
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200779} // namespace interpreter
780} // namespace art
781
782#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_