blob: 0c69fe9cb641bf0a11dc3665d973431b044574d9 [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
63namespace art {
64namespace interpreter {
65
66// External references to both interpreter implementations.
67
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010068template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020069extern JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh,
70 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020071 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020072
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010073template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020074extern JValue ExecuteGotoImpl(Thread* self, MethodHelper& mh,
75 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020076 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020077
Ian Rogers54874942014-06-10 16:31:03 -070078void ThrowNullPointerExceptionFromInterpreter(const ShadowFrame& shadow_frame)
79 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzda843e12014-05-28 19:28:31 +020080
Sebastien Hertz8ece0502013-08-07 11:26:41 +020081static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
82 ref->MonitorEnter(self);
83}
84
85static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
86 ref->MonitorExit(self);
87}
88
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -070089void AbortTransaction(Thread* self, const char* fmt, ...)
90 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
91
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010092void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
93 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
94
Sebastien Hertzc6714852013-09-30 16:42:32 +020095// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
96// DoInvokeVirtualQuick functions.
97// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +020098template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +010099bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200100 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200101
Sebastien Hertzc6714852013-09-30 16:42:32 +0200102// Handles invoke-XXX/range instructions.
103// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200104template<InvokeType type, bool is_range, bool do_access_check>
105static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
106 uint16_t inst_data, JValue* result) {
107 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
108 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700109 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700110 mirror::ArtMethod* sf_method = shadow_frame.GetMethod();
111 ArtMethod* const method = FindMethodFromCode<type, do_access_check>(
112 method_idx, &receiver, &sf_method, self);
113 // The shadow frame should already be pushed, so we don't need to update it.
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200114 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200115 CHECK(self->IsExceptionPending());
116 result->SetJ(0);
117 return false;
118 } else if (UNLIKELY(method->IsAbstract())) {
119 ThrowAbstractMethodError(method);
120 result->SetJ(0);
121 return false;
122 } else {
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100123 return DoCall<is_range, do_access_check>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200124 }
125}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200126
Sebastien Hertzc6714852013-09-30 16:42:32 +0200127// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
128// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200129template<bool is_range>
130static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
131 const Instruction* inst, uint16_t inst_data,
132 JValue* result) {
133 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
134 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200135 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200136 // We lost the reference to the method index so we cannot get a more
137 // precised exception message.
138 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
139 return false;
140 }
141 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
142 ArtMethod* const method = receiver->GetClass()->GetVTable()->GetWithoutChecks(vtable_idx);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200143 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200144 CHECK(self->IsExceptionPending());
145 result->SetJ(0);
146 return false;
147 } else if (UNLIKELY(method->IsAbstract())) {
148 ThrowAbstractMethodError(method);
149 result->SetJ(0);
150 return false;
151 } else {
152 // No need to check since we've been quickened.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100153 return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200154 }
155}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200156
Sebastien Hertzc6714852013-09-30 16:42:32 +0200157// Handles iget-XXX and sget-XXX instructions.
158// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200159template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Ian Rogers54874942014-06-10 16:31:03 -0700160bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
161 uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200162
Sebastien Hertzc6714852013-09-30 16:42:32 +0200163// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
164// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200165template<Primitive::Type field_type>
Ian Rogers54874942014-06-10 16:31:03 -0700166bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
167 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200168
Sebastien Hertzc6714852013-09-30 16:42:32 +0200169// Handles iput-XXX and sput-XXX instructions.
170// Returns true on success, otherwise throws an exception and returns false.
Ian Rogers54874942014-06-10 16:31:03 -0700171template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
172 bool transaction_active>
173bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
174 uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200175
Sebastien Hertzc6714852013-09-30 16:42:32 +0200176// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
177// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100178template<Primitive::Type field_type, bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -0700179bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
180 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
181
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200182
Sebastien Hertzc6714852013-09-30 16:42:32 +0200183// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
184// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200185static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
186 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800187 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200188 Class* java_lang_string_class = String::GetJavaLangString();
189 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
190 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700191 StackHandleScope<1> hs(self);
192 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
193 if (UNLIKELY(!class_linker->EnsureInitialized(h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200194 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800195 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200196 }
197 }
198 return mh.ResolveString(string_idx);
199}
200
Sebastien Hertzc6714852013-09-30 16:42:32 +0200201// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
202// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200203static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
204 int32_t dividend, int32_t divisor)
205 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700206 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200207 if (UNLIKELY(divisor == 0)) {
208 ThrowArithmeticExceptionDivideByZero();
209 return false;
210 }
211 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
212 shadow_frame.SetVReg(result_reg, kMinInt);
213 } else {
214 shadow_frame.SetVReg(result_reg, dividend / divisor);
215 }
216 return true;
217}
218
Sebastien Hertzc6714852013-09-30 16:42:32 +0200219// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
220// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200221static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
222 int32_t dividend, int32_t divisor)
223 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700224 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200225 if (UNLIKELY(divisor == 0)) {
226 ThrowArithmeticExceptionDivideByZero();
227 return false;
228 }
229 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
230 shadow_frame.SetVReg(result_reg, 0);
231 } else {
232 shadow_frame.SetVReg(result_reg, dividend % divisor);
233 }
234 return true;
235}
236
Sebastien Hertzc6714852013-09-30 16:42:32 +0200237// Handles div-long and div-long-2addr instructions.
238// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200239static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
240 int64_t dividend, int64_t divisor)
241 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700242 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200243 if (UNLIKELY(divisor == 0)) {
244 ThrowArithmeticExceptionDivideByZero();
245 return false;
246 }
247 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
248 shadow_frame.SetVRegLong(result_reg, kMinLong);
249 } else {
250 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
251 }
252 return true;
253}
254
Sebastien Hertzc6714852013-09-30 16:42:32 +0200255// Handles rem-long and rem-long-2addr instructions.
256// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200257static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
258 int64_t dividend, int64_t divisor)
259 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700260 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200261 if (UNLIKELY(divisor == 0)) {
262 ThrowArithmeticExceptionDivideByZero();
263 return false;
264 }
265 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
266 shadow_frame.SetVRegLong(result_reg, 0);
267 } else {
268 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
269 }
270 return true;
271}
272
Sebastien Hertzc6714852013-09-30 16:42:32 +0200273// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200274// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100275template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200276bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200277 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200278
Sebastien Hertzc6714852013-09-30 16:42:32 +0200279// Handles packed-switch instruction.
280// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200281static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
282 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200283 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
284 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
285 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200286 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200287 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
288 uint16_t size = switch_data[1];
289 DCHECK_GT(size, 0);
290 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
291 DCHECK(IsAligned<4>(keys));
292 int32_t first_key = keys[0];
293 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
294 DCHECK(IsAligned<4>(targets));
295 int32_t index = test_val - first_key;
296 if (index >= 0 && index < size) {
297 return targets[index];
298 } else {
299 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
300 return 3;
301 }
302}
303
Sebastien Hertzc6714852013-09-30 16:42:32 +0200304// Handles sparse-switch instruction.
305// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200306static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
307 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200308 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
309 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
310 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200311 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200312 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
313 uint16_t size = switch_data[1];
314 DCHECK_GT(size, 0);
315 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
316 DCHECK(IsAligned<4>(keys));
317 const int32_t* entries = keys + size;
318 DCHECK(IsAligned<4>(entries));
319 int lo = 0;
320 int hi = size - 1;
321 while (lo <= hi) {
322 int mid = (lo + hi) / 2;
323 int32_t foundVal = keys[mid];
324 if (test_val < foundVal) {
325 hi = mid - 1;
326 } else if (test_val > foundVal) {
327 lo = mid + 1;
328 } else {
329 return entries[mid];
330 }
331 }
332 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
333 return 3;
334}
335
Ian Rogers54874942014-06-10 16:31:03 -0700336uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame,
337 uint32_t dex_pc, mirror::Object* this_object,
338 const instrumentation::Instrumentation* instrumentation)
339 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200340
Ian Rogers54874942014-06-10 16:31:03 -0700341void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800342 __attribute__((cold, noreturn))
343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200344
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200345static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700346 const uint32_t dex_pc, MethodHelper& mh)
347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700348 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200349 if (kTracing) {
350#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700351 std::ostringstream oss;
352 oss << PrettyMethod(shadow_frame.GetMethod())
353 << StringPrintf("\n0x%x: ", dex_pc)
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700354 << inst->DumpString(mh.GetMethod()->GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800355 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200356 uint32_t raw_value = shadow_frame.GetVReg(i);
357 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800358 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200359 if (ref_value != NULL) {
360 if (ref_value->GetClass()->IsStringClass() &&
361 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700362 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200363 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700364 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200365 }
366 }
367 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700368 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200369#undef TRACE_LOG
370 }
371}
372
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200373static inline bool IsBackwardBranch(int32_t branch_offset) {
374 return branch_offset <= 0;
375}
376
Sebastien Hertzc6714852013-09-30 16:42:32 +0200377// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100378#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Ian Rogers54874942014-06-10 16:31:03 -0700379 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100380 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
381 const Instruction* inst, uint16_t inst_data, \
382 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200383
384#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
385 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
386 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
387 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
388 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
389
390EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic); // invoke-static/range.
391EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect); // invoke-direct/range.
392EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual); // invoke-virtual/range.
393EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper); // invoke-super/range.
394EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface); // invoke-interface/range.
395#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
396#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
397
Sebastien Hertzc6714852013-09-30 16:42:32 +0200398// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100399#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Ian Rogers54874942014-06-10 16:31:03 -0700400 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100401 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
402 const Instruction* inst, uint16_t inst_data, \
403 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200404
405EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
406EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
407#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
408
Sebastien Hertzc6714852013-09-30 16:42:32 +0200409
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200410} // namespace interpreter
411} // namespace art
412
413#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_