blob: b42af11986108b34ff13569c054267f051199096 [file] [log] [blame]
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_
18#define ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_
19
20#include "interpreter.h"
21
22#include <math.h>
23
24#include "base/logging.h"
25#include "class_linker-inl.h"
26#include "common_throws.h"
27#include "dex_file-inl.h"
28#include "dex_instruction-inl.h"
29#include "dex_instruction.h"
30#include "entrypoints/entrypoint_utils.h"
31#include "gc/accounting/card_table-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020032#include "nth_caller_visitor.h"
33#include "mirror/art_field-inl.h"
34#include "mirror/art_method.h"
35#include "mirror/art_method-inl.h"
36#include "mirror/class.h"
37#include "mirror/class-inl.h"
38#include "mirror/object-inl.h"
39#include "mirror/object_array-inl.h"
40#include "object_utils.h"
41#include "ScopedLocalRef.h"
42#include "scoped_thread_state_change.h"
43#include "thread.h"
44#include "well_known_classes.h"
45
46using ::art::mirror::ArtField;
47using ::art::mirror::ArtMethod;
48using ::art::mirror::Array;
49using ::art::mirror::BooleanArray;
50using ::art::mirror::ByteArray;
51using ::art::mirror::CharArray;
52using ::art::mirror::Class;
53using ::art::mirror::ClassLoader;
54using ::art::mirror::IntArray;
55using ::art::mirror::LongArray;
56using ::art::mirror::Object;
57using ::art::mirror::ObjectArray;
58using ::art::mirror::ShortArray;
59using ::art::mirror::String;
60using ::art::mirror::Throwable;
61
Sebastien Hertz82aeddb2014-05-20 20:09:45 +020062// b/14882674 Workaround stack overflow issue with clang
63#if defined(__clang__) && defined(__aarch64__)
64#define SOMETIMES_INLINE __attribute__((noinline))
65#define SOMETIMES_INLINE_KEYWORD
66#else
67#define SOMETIMES_INLINE ALWAYS_INLINE
68#define SOMETIMES_INLINE_KEYWORD inline
69#endif
70
Sebastien Hertz8ece0502013-08-07 11:26:41 +020071namespace art {
72namespace interpreter {
73
74// External references to both interpreter implementations.
75
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010076template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020077extern JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh,
78 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020079 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020080
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010081template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020082extern JValue ExecuteGotoImpl(Thread* self, MethodHelper& mh,
83 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020084 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020085
86static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
87 ref->MonitorEnter(self);
88}
89
90static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
91 ref->MonitorExit(self);
92}
93
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -070094void AbortTransaction(Thread* self, const char* fmt, ...)
95 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
96
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010097void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
98 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
99
Sebastien Hertzc6714852013-09-30 16:42:32 +0200100// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
101// DoInvokeVirtualQuick functions.
102// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200103template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100104bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200105 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200106
Sebastien Hertzc6714852013-09-30 16:42:32 +0200107// Handles invoke-XXX/range instructions.
108// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200109template<InvokeType type, bool is_range, bool do_access_check>
110static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
111 uint16_t inst_data, JValue* result) {
112 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
113 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700114 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200115 ArtMethod* const method = FindMethodFromCode<type, do_access_check>(method_idx, receiver,
116 shadow_frame.GetMethod(),
117 self);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200118 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200119 CHECK(self->IsExceptionPending());
120 result->SetJ(0);
121 return false;
122 } else if (UNLIKELY(method->IsAbstract())) {
123 ThrowAbstractMethodError(method);
124 result->SetJ(0);
125 return false;
126 } else {
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100127 return DoCall<is_range, do_access_check>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200128 }
129}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200130
Sebastien Hertzc6714852013-09-30 16:42:32 +0200131// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
132// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200133template<bool is_range>
134static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
135 const Instruction* inst, uint16_t inst_data,
136 JValue* result) {
137 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
138 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200139 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200140 // We lost the reference to the method index so we cannot get a more
141 // precised exception message.
142 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
143 return false;
144 }
145 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
146 ArtMethod* const method = receiver->GetClass()->GetVTable()->GetWithoutChecks(vtable_idx);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200147 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200148 CHECK(self->IsExceptionPending());
149 result->SetJ(0);
150 return false;
151 } else if (UNLIKELY(method->IsAbstract())) {
152 ThrowAbstractMethodError(method);
153 result->SetJ(0);
154 return false;
155 } else {
156 // No need to check since we've been quickened.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100157 return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200158 }
159}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200160
Sebastien Hertzc6714852013-09-30 16:42:32 +0200161// Handles iget-XXX and sget-XXX instructions.
162// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200163template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200164static SOMETIMES_INLINE_KEYWORD bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame,
165 const Instruction* inst, uint16_t inst_data) {
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200166 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
167 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
168 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
169 Primitive::FieldSize(field_type));
170 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200171 CHECK(self->IsExceptionPending());
172 return false;
173 }
174 Object* obj;
175 if (is_static) {
176 obj = f->GetDeclaringClass();
177 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200178 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200179 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200180 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(), f, true);
181 return false;
182 }
183 }
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200184 // Report this field access to instrumentation if needed.
185 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
186 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
187 Object* this_object = f->IsStatic() ? nullptr : obj;
188 instrumentation->FieldReadEvent(self, this_object, shadow_frame.GetMethod(),
189 shadow_frame.GetDexPC(), f);
190 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200191 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200192 switch (field_type) {
193 case Primitive::kPrimBoolean:
194 shadow_frame.SetVReg(vregA, f->GetBoolean(obj));
195 break;
196 case Primitive::kPrimByte:
197 shadow_frame.SetVReg(vregA, f->GetByte(obj));
198 break;
199 case Primitive::kPrimChar:
200 shadow_frame.SetVReg(vregA, f->GetChar(obj));
201 break;
202 case Primitive::kPrimShort:
203 shadow_frame.SetVReg(vregA, f->GetShort(obj));
204 break;
205 case Primitive::kPrimInt:
206 shadow_frame.SetVReg(vregA, f->GetInt(obj));
207 break;
208 case Primitive::kPrimLong:
209 shadow_frame.SetVRegLong(vregA, f->GetLong(obj));
210 break;
211 case Primitive::kPrimNot:
212 shadow_frame.SetVRegReference(vregA, f->GetObject(obj));
213 break;
214 default:
215 LOG(FATAL) << "Unreachable: " << field_type;
216 }
217 return true;
218}
219
Sebastien Hertzc6714852013-09-30 16:42:32 +0200220// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
221// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200222template<Primitive::Type field_type>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200223static SOMETIMES_INLINE_KEYWORD bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200224 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200225 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200226 // We lost the reference to the field index so we cannot get a more
227 // precised exception message.
228 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
229 return false;
230 }
231 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200232 // Report this field access to instrumentation if needed. Since we only have the offset of
233 // the field from the base of the object, we need to look for it first.
234 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
235 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
236 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
237 field_offset.Uint32Value());
238 DCHECK(f != nullptr);
239 DCHECK(!f->IsStatic());
240 instrumentation->FieldReadEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
241 shadow_frame.GetDexPC(), f);
242 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700243 // Note: iget-x-quick instructions are only for non-volatile fields.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200244 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200245 switch (field_type) {
246 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700247 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200248 break;
249 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700250 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200251 break;
252 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700253 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200254 break;
255 default:
256 LOG(FATAL) << "Unreachable: " << field_type;
257 }
258 return true;
259}
260
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200261template<Primitive::Type field_type>
262static inline JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
263 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
264 JValue field_value;
265 switch (field_type) {
266 case Primitive::kPrimBoolean:
267 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
268 break;
269 case Primitive::kPrimByte:
270 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
271 break;
272 case Primitive::kPrimChar:
273 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
274 break;
275 case Primitive::kPrimShort:
276 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
277 break;
278 case Primitive::kPrimInt:
279 field_value.SetI(shadow_frame.GetVReg(vreg));
280 break;
281 case Primitive::kPrimLong:
282 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
283 break;
284 case Primitive::kPrimNot:
285 field_value.SetL(shadow_frame.GetVRegReference(vreg));
286 break;
287 default:
288 LOG(FATAL) << "Unreachable: " << field_type;
289 break;
290 }
291 return field_value;
292}
293
Sebastien Hertzc6714852013-09-30 16:42:32 +0200294// Handles iput-XXX and sput-XXX instructions.
295// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100296template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check, bool transaction_active>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200297static SOMETIMES_INLINE_KEYWORD bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame,
298 const Instruction* inst, uint16_t inst_data) {
Jeff Haoa3faaf42013-09-03 19:07:00 -0700299 bool do_assignability_check = do_access_check;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200300 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
301 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200302 ArtField* f = FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
303 Primitive::FieldSize(field_type));
304 if (UNLIKELY(f == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200305 CHECK(self->IsExceptionPending());
306 return false;
307 }
308 Object* obj;
309 if (is_static) {
310 obj = f->GetDeclaringClass();
311 } else {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200312 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200313 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200314 ThrowNullPointerExceptionForFieldAccess(shadow_frame.GetCurrentLocationForThrow(),
315 f, false);
316 return false;
317 }
318 }
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200319 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200320 // Report this field access to instrumentation if needed. Since we only have the offset of
321 // the field from the base of the object, we need to look for it first.
322 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
323 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
324 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
325 Object* this_object = f->IsStatic() ? nullptr : obj;
326 instrumentation->FieldWriteEvent(self, this_object, shadow_frame.GetMethod(),
327 shadow_frame.GetDexPC(), f, field_value);
328 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200329 switch (field_type) {
330 case Primitive::kPrimBoolean:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100331 f->SetBoolean<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200332 break;
333 case Primitive::kPrimByte:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100334 f->SetByte<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200335 break;
336 case Primitive::kPrimChar:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100337 f->SetChar<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200338 break;
339 case Primitive::kPrimShort:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100340 f->SetShort<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200341 break;
342 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100343 f->SetInt<transaction_active>(obj, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200344 break;
345 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100346 f->SetLong<transaction_active>(obj, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200347 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700348 case Primitive::kPrimNot: {
349 Object* reg = shadow_frame.GetVRegReference(vregA);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200350 if (do_assignability_check && reg != nullptr) {
Jeff Haoa3faaf42013-09-03 19:07:00 -0700351 Class* field_class = FieldHelper(f).GetType();
352 if (!reg->VerifierInstanceOf(field_class)) {
353 // This should never happen.
354 self->ThrowNewExceptionF(self->GetCurrentLocationForThrow(),
355 "Ljava/lang/VirtualMachineError;",
356 "Put '%s' that is not instance of field '%s' in '%s'",
Mathieu Chartierf8322842014-05-16 10:59:25 -0700357 reg->GetClass()->GetDescriptor().c_str(),
358 field_class->GetDescriptor().c_str(),
359 f->GetDeclaringClass()->GetDescriptor().c_str());
Jeff Haoa3faaf42013-09-03 19:07:00 -0700360 return false;
361 }
362 }
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100363 f->SetObj<transaction_active>(obj, reg);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200364 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -0700365 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200366 default:
367 LOG(FATAL) << "Unreachable: " << field_type;
368 }
369 return true;
370}
371
Sebastien Hertzc6714852013-09-30 16:42:32 +0200372// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
373// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100374template<Primitive::Type field_type, bool transaction_active>
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200375static SOMETIMES_INLINE_KEYWORD bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200376 Object* obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200377 if (UNLIKELY(obj == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200378 // We lost the reference to the field index so we cannot get a more
379 // precised exception message.
380 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
381 return false;
382 }
383 MemberOffset field_offset(inst->VRegC_22c());
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200384 const uint32_t vregA = inst->VRegA_22c(inst_data);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200385 // Report this field modification to instrumentation if needed. Since we only have the offset of
386 // the field from the base of the object, we need to look for it first.
387 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
388 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
389 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
390 field_offset.Uint32Value());
391 DCHECK(f != nullptr);
392 DCHECK(!f->IsStatic());
393 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
394 instrumentation->FieldWriteEvent(Thread::Current(), obj, shadow_frame.GetMethod(),
395 shadow_frame.GetDexPC(), f, field_value);
396 }
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700397 // Note: iput-x-quick instructions are only for non-volatile fields.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200398 switch (field_type) {
399 case Primitive::kPrimInt:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700400 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200401 break;
402 case Primitive::kPrimLong:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700403 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200404 break;
405 case Primitive::kPrimNot:
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700406 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200407 break;
408 default:
409 LOG(FATAL) << "Unreachable: " << field_type;
410 }
411 return true;
412}
413
Sebastien Hertzc6714852013-09-30 16:42:32 +0200414// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
415// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200416static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
417 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800418 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200419 Class* java_lang_string_class = String::GetJavaLangString();
420 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
421 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700422 StackHandleScope<1> hs(self);
423 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
424 if (UNLIKELY(!class_linker->EnsureInitialized(h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200425 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800426 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200427 }
428 }
429 return mh.ResolveString(string_idx);
430}
431
Sebastien Hertzc6714852013-09-30 16:42:32 +0200432// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
433// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200434static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
435 int32_t dividend, int32_t divisor)
436 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700437 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200438 if (UNLIKELY(divisor == 0)) {
439 ThrowArithmeticExceptionDivideByZero();
440 return false;
441 }
442 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
443 shadow_frame.SetVReg(result_reg, kMinInt);
444 } else {
445 shadow_frame.SetVReg(result_reg, dividend / divisor);
446 }
447 return true;
448}
449
Sebastien Hertzc6714852013-09-30 16:42:32 +0200450// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-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 DoIntRemainder(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, 0);
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 div-long and div-long-2addr 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 DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
471 int64_t dividend, int64_t divisor)
472 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700473 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200474 if (UNLIKELY(divisor == 0)) {
475 ThrowArithmeticExceptionDivideByZero();
476 return false;
477 }
478 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
479 shadow_frame.SetVRegLong(result_reg, kMinLong);
480 } else {
481 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
482 }
483 return true;
484}
485
Sebastien Hertzc6714852013-09-30 16:42:32 +0200486// Handles rem-long and rem-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 DoLongRemainder(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, 0);
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 filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200505// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100506template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200507bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200508 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200509
Sebastien Hertzc6714852013-09-30 16:42:32 +0200510// Handles packed-switch instruction.
511// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200512static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
513 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200514 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
515 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
516 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200517 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200518 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
519 uint16_t size = switch_data[1];
520 DCHECK_GT(size, 0);
521 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
522 DCHECK(IsAligned<4>(keys));
523 int32_t first_key = keys[0];
524 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
525 DCHECK(IsAligned<4>(targets));
526 int32_t index = test_val - first_key;
527 if (index >= 0 && index < size) {
528 return targets[index];
529 } else {
530 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
531 return 3;
532 }
533}
534
Sebastien Hertzc6714852013-09-30 16:42:32 +0200535// Handles sparse-switch instruction.
536// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200537static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
538 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200539 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
540 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
541 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200542 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200543 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
544 uint16_t size = switch_data[1];
545 DCHECK_GT(size, 0);
546 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
547 DCHECK(IsAligned<4>(keys));
548 const int32_t* entries = keys + size;
549 DCHECK(IsAligned<4>(entries));
550 int lo = 0;
551 int hi = size - 1;
552 while (lo <= hi) {
553 int mid = (lo + hi) / 2;
554 int32_t foundVal = keys[mid];
555 if (test_val < foundVal) {
556 hi = mid - 1;
557 } else if (test_val > foundVal) {
558 lo = mid + 1;
559 } else {
560 return entries[mid];
561 }
562 }
563 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
564 return 3;
565}
566
567static inline uint32_t FindNextInstructionFollowingException(Thread* self,
568 ShadowFrame& shadow_frame,
569 uint32_t dex_pc,
Sebastien Hertz947ff082013-09-17 14:10:13 +0200570 mirror::Object* this_object,
571 const instrumentation::Instrumentation* instrumentation)
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200572SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200573
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,
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200578 const instrumentation::Instrumentation* instrumentation) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200579 self->VerifyStack();
580 ThrowLocation throw_location;
581 mirror::Throwable* exception = self->GetException(&throw_location);
Sebastien Hertz947ff082013-09-17 14:10:13 +0200582 bool clear_exception = false;
Andreas Gampe72b3e432014-05-13 21:42:05 -0700583 bool new_exception = false;
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700584 StackHandleScope<3> hs(self);
585 Handle<mirror::Class> exception_class(hs.NewHandle(exception->GetClass()));
Jeff Haoaa961912014-04-22 13:54:32 -0700586 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(exception_class, dex_pc,
Andreas Gampe72b3e432014-05-13 21:42:05 -0700587 &clear_exception,
588 &new_exception);
589 if (UNLIKELY(new_exception)) {
590 // Update the exception.
591 exception = self->GetException(&throw_location);
592 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200593 if (found_dex_pc == DexFile::kDexNoIndex) {
Sebastien Hertz947ff082013-09-17 14:10:13 +0200594 instrumentation->MethodUnwindEvent(self, this_object,
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200595 shadow_frame.GetMethod(), dex_pc);
596 } else {
597 instrumentation->ExceptionCaughtEvent(self, throw_location,
598 shadow_frame.GetMethod(),
599 found_dex_pc, exception);
600 if (clear_exception) {
601 self->ClearException();
602 }
603 }
604 return found_dex_pc;
605}
606
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800607static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
608 __attribute__((cold, noreturn))
609 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200610
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800611static inline void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200612 LOG(FATAL) << "Unexpected instruction: " << inst->DumpString(&mh.GetDexFile());
613 exit(0); // Unreachable, keep GCC happy.
614}
615
616static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700617 const uint32_t dex_pc, MethodHelper& mh)
618 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700619 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200620 if (kTracing) {
621#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700622 std::ostringstream oss;
623 oss << PrettyMethod(shadow_frame.GetMethod())
624 << StringPrintf("\n0x%x: ", dex_pc)
625 << inst->DumpString(&mh.GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800626 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200627 uint32_t raw_value = shadow_frame.GetVReg(i);
628 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800629 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200630 if (ref_value != NULL) {
631 if (ref_value->GetClass()->IsStringClass() &&
632 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700633 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200634 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700635 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200636 }
637 }
638 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700639 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200640#undef TRACE_LOG
641 }
642}
643
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200644static inline bool IsBackwardBranch(int32_t branch_offset) {
645 return branch_offset <= 0;
646}
647
Sebastien Hertzc6714852013-09-30 16:42:32 +0200648// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100649#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200650 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100651 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
652 const Instruction* inst, uint16_t inst_data, \
653 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200654
655#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
656 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
657 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
658 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
659 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
660
661EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
662EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
663EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
664EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
665EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
666#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
667#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
668
669// Explicitly instantiate all DoFieldGet functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100670#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200671 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100672 bool DoFieldGet<_find_type, _field_type, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
673 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200674
675#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
676 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false); \
677 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true);
678
679// iget-XXX
680EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean);
681EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte);
682EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar);
683EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort);
684EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt);
685EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong);
686EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot);
687
688// sget-XXX
689EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean);
690EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte);
691EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar);
692EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort);
693EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt);
694EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong);
695EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot);
696
697#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
698#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
699
700// Explicitly instantiate all DoFieldPut functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100701#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200702 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100703 bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, const ShadowFrame& shadow_frame, \
704 const Instruction* inst, uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200705
706#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100707 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
708 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
709 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
710 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
Sebastien Hertzc6714852013-09-30 16:42:32 +0200711
712// iput-XXX
713EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean);
714EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte);
715EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar);
716EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort);
717EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt);
718EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong);
719EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot);
720
721// sput-XXX
722EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean);
723EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte);
724EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar);
725EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort);
726EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt);
727EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong);
728EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot);
729
730#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
731#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
732
733// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100734#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200735 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100736 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
737 const Instruction* inst, uint16_t inst_data, \
738 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200739
740EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
741EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
742#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
743
744// Explicitly instantiate all DoIGetQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100745#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200746 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100747 bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
748 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200749
750EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
751EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
752EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
753#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
754
755// Explicitly instantiate all DoIPutQuick functions.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100756#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
Sebastien Hertz82aeddb2014-05-20 20:09:45 +0200757 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) SOMETIMES_INLINE \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100758 bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
759 const Instruction* inst, \
760 uint16_t inst_data)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200761
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100762#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
763 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
764 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
765
766EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
767EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
768EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
769#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
Sebastien Hertzc6714852013-09-30 16:42:32 +0200770#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
771
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200772} // namespace interpreter
773} // namespace art
774
775#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_