blob: db42eb06f1ae4136223d3bdc6c3f259b4bde7af8 [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"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070030#include "entrypoints/entrypoint_utils-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020031#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"
Douglas Leung4965c022014-06-11 11:41:11 -070041#include "mirror/string-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020042#include "object_utils.h"
43#include "ScopedLocalRef.h"
44#include "scoped_thread_state_change.h"
45#include "thread.h"
46#include "well_known_classes.h"
47
48using ::art::mirror::ArtField;
49using ::art::mirror::ArtMethod;
50using ::art::mirror::Array;
51using ::art::mirror::BooleanArray;
52using ::art::mirror::ByteArray;
53using ::art::mirror::CharArray;
54using ::art::mirror::Class;
55using ::art::mirror::ClassLoader;
56using ::art::mirror::IntArray;
57using ::art::mirror::LongArray;
58using ::art::mirror::Object;
59using ::art::mirror::ObjectArray;
60using ::art::mirror::ShortArray;
61using ::art::mirror::String;
62using ::art::mirror::Throwable;
63
64namespace art {
65namespace interpreter {
66
67// External references to both interpreter implementations.
68
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010069template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020070extern JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh,
71 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020072 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020073
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010074template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020075extern JValue ExecuteGotoImpl(Thread* self, MethodHelper& mh,
76 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020077 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020078
Ian Rogers54874942014-06-10 16:31:03 -070079void ThrowNullPointerExceptionFromInterpreter(const ShadowFrame& shadow_frame)
80 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzda843e12014-05-28 19:28:31 +020081
Sebastien Hertz8ece0502013-08-07 11:26:41 +020082static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
83 ref->MonitorEnter(self);
84}
85
86static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
87 ref->MonitorExit(self);
88}
89
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -070090void AbortTransaction(Thread* self, const char* fmt, ...)
91 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
92
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010093void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
94 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
95
Sebastien Hertzc6714852013-09-30 16:42:32 +020096// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
97// DoInvokeVirtualQuick functions.
98// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +020099template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100100bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200101 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200102
Sebastien Hertzc6714852013-09-30 16:42:32 +0200103// Handles invoke-XXX/range instructions.
104// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200105template<InvokeType type, bool is_range, bool do_access_check>
106static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
107 uint16_t inst_data, JValue* result) {
108 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
109 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700110 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700111 mirror::ArtMethod* sf_method = shadow_frame.GetMethod();
112 ArtMethod* const method = FindMethodFromCode<type, do_access_check>(
113 method_idx, &receiver, &sf_method, self);
114 // The shadow frame should already be pushed, so we don't need to update it.
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200115 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200116 CHECK(self->IsExceptionPending());
117 result->SetJ(0);
118 return false;
119 } else if (UNLIKELY(method->IsAbstract())) {
120 ThrowAbstractMethodError(method);
121 result->SetJ(0);
122 return false;
123 } else {
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100124 return DoCall<is_range, do_access_check>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200125 }
126}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200127
Sebastien Hertzc6714852013-09-30 16:42:32 +0200128// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
129// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200130template<bool is_range>
131static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
132 const Instruction* inst, uint16_t inst_data,
133 JValue* result) {
134 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
135 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200136 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200137 // We lost the reference to the method index so we cannot get a more
138 // precised exception message.
139 ThrowNullPointerExceptionFromDexPC(shadow_frame.GetCurrentLocationForThrow());
140 return false;
141 }
142 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
143 ArtMethod* const method = receiver->GetClass()->GetVTable()->GetWithoutChecks(vtable_idx);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200144 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200145 CHECK(self->IsExceptionPending());
146 result->SetJ(0);
147 return false;
148 } else if (UNLIKELY(method->IsAbstract())) {
149 ThrowAbstractMethodError(method);
150 result->SetJ(0);
151 return false;
152 } else {
153 // No need to check since we've been quickened.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100154 return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200155 }
156}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200157
Sebastien Hertzc6714852013-09-30 16:42:32 +0200158// Handles iget-XXX and sget-XXX instructions.
159// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200160template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Ian Rogers54874942014-06-10 16:31:03 -0700161bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
162 uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200163
Sebastien Hertzc6714852013-09-30 16:42:32 +0200164// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
165// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200166template<Primitive::Type field_type>
Ian Rogers54874942014-06-10 16:31:03 -0700167bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
168 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200169
Sebastien Hertzc6714852013-09-30 16:42:32 +0200170// Handles iput-XXX and sput-XXX instructions.
171// Returns true on success, otherwise throws an exception and returns false.
Ian Rogers54874942014-06-10 16:31:03 -0700172template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
173 bool transaction_active>
174bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
175 uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200176
Sebastien Hertzc6714852013-09-30 16:42:32 +0200177// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
178// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100179template<Primitive::Type field_type, bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -0700180bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
181 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
182
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200183
Sebastien Hertzc6714852013-09-30 16:42:32 +0200184// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
185// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200186static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
187 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800188 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200189 Class* java_lang_string_class = String::GetJavaLangString();
190 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
191 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700192 StackHandleScope<1> hs(self);
193 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
194 if (UNLIKELY(!class_linker->EnsureInitialized(h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200195 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800196 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200197 }
198 }
199 return mh.ResolveString(string_idx);
200}
201
Sebastien Hertzc6714852013-09-30 16:42:32 +0200202// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
203// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200204static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
205 int32_t dividend, int32_t divisor)
206 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700207 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200208 if (UNLIKELY(divisor == 0)) {
209 ThrowArithmeticExceptionDivideByZero();
210 return false;
211 }
212 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
213 shadow_frame.SetVReg(result_reg, kMinInt);
214 } else {
215 shadow_frame.SetVReg(result_reg, dividend / divisor);
216 }
217 return true;
218}
219
Sebastien Hertzc6714852013-09-30 16:42:32 +0200220// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
221// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200222static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
223 int32_t dividend, int32_t divisor)
224 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700225 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200226 if (UNLIKELY(divisor == 0)) {
227 ThrowArithmeticExceptionDivideByZero();
228 return false;
229 }
230 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
231 shadow_frame.SetVReg(result_reg, 0);
232 } else {
233 shadow_frame.SetVReg(result_reg, dividend % divisor);
234 }
235 return true;
236}
237
Sebastien Hertzc6714852013-09-30 16:42:32 +0200238// Handles div-long and div-long-2addr instructions.
239// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200240static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
241 int64_t dividend, int64_t divisor)
242 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700243 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200244 if (UNLIKELY(divisor == 0)) {
245 ThrowArithmeticExceptionDivideByZero();
246 return false;
247 }
248 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
249 shadow_frame.SetVRegLong(result_reg, kMinLong);
250 } else {
251 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
252 }
253 return true;
254}
255
Sebastien Hertzc6714852013-09-30 16:42:32 +0200256// Handles rem-long and rem-long-2addr instructions.
257// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200258static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
259 int64_t dividend, int64_t divisor)
260 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700261 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200262 if (UNLIKELY(divisor == 0)) {
263 ThrowArithmeticExceptionDivideByZero();
264 return false;
265 }
266 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
267 shadow_frame.SetVRegLong(result_reg, 0);
268 } else {
269 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
270 }
271 return true;
272}
273
Sebastien Hertzc6714852013-09-30 16:42:32 +0200274// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200275// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100276template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200277bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200278 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200279
Sebastien Hertzc6714852013-09-30 16:42:32 +0200280// Handles packed-switch instruction.
281// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200282static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
283 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200284 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
285 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
286 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200287 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200288 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
289 uint16_t size = switch_data[1];
290 DCHECK_GT(size, 0);
291 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
292 DCHECK(IsAligned<4>(keys));
293 int32_t first_key = keys[0];
294 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
295 DCHECK(IsAligned<4>(targets));
296 int32_t index = test_val - first_key;
297 if (index >= 0 && index < size) {
298 return targets[index];
299 } else {
300 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
301 return 3;
302 }
303}
304
Sebastien Hertzc6714852013-09-30 16:42:32 +0200305// Handles sparse-switch instruction.
306// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200307static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
308 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200309 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
310 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
311 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200312 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200313 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
314 uint16_t size = switch_data[1];
315 DCHECK_GT(size, 0);
316 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
317 DCHECK(IsAligned<4>(keys));
318 const int32_t* entries = keys + size;
319 DCHECK(IsAligned<4>(entries));
320 int lo = 0;
321 int hi = size - 1;
322 while (lo <= hi) {
323 int mid = (lo + hi) / 2;
324 int32_t foundVal = keys[mid];
325 if (test_val < foundVal) {
326 hi = mid - 1;
327 } else if (test_val > foundVal) {
328 lo = mid + 1;
329 } else {
330 return entries[mid];
331 }
332 }
333 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
334 return 3;
335}
336
Ian Rogers54874942014-06-10 16:31:03 -0700337uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertz9f102032014-05-23 08:59:42 +0200338 uint32_t dex_pc, const instrumentation::Instrumentation* instrumentation)
Ian Rogers54874942014-06-10 16:31:03 -0700339 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_