blob: fa03fc7fa92abd5c603a22f24d8aec6997938794 [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
Ian Rogerscf7f1912014-10-22 22:06:39 -070024#include <iostream>
Ian Rogersc7dd2952014-10-21 23:31:19 -070025#include <sstream>
26
Sebastien Hertz8ece0502013-08-07 11:26:41 +020027#include "base/logging.h"
28#include "class_linker-inl.h"
29#include "common_throws.h"
30#include "dex_file-inl.h"
31#include "dex_instruction-inl.h"
32#include "dex_instruction.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070033#include "entrypoints/entrypoint_utils-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020034#include "gc/accounting/card_table-inl.h"
Mathieu Chartier0cd81352014-05-22 16:48:55 -070035#include "handle_scope-inl.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070036#include "method_helper-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020037#include "nth_caller_visitor.h"
38#include "mirror/art_field-inl.h"
39#include "mirror/art_method.h"
40#include "mirror/art_method-inl.h"
41#include "mirror/class.h"
42#include "mirror/class-inl.h"
43#include "mirror/object-inl.h"
44#include "mirror/object_array-inl.h"
Douglas Leung4965c022014-06-11 11:41:11 -070045#include "mirror/string-inl.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020046#include "ScopedLocalRef.h"
47#include "scoped_thread_state_change.h"
48#include "thread.h"
49#include "well_known_classes.h"
50
51using ::art::mirror::ArtField;
52using ::art::mirror::ArtMethod;
53using ::art::mirror::Array;
54using ::art::mirror::BooleanArray;
55using ::art::mirror::ByteArray;
56using ::art::mirror::CharArray;
57using ::art::mirror::Class;
58using ::art::mirror::ClassLoader;
59using ::art::mirror::IntArray;
60using ::art::mirror::LongArray;
61using ::art::mirror::Object;
62using ::art::mirror::ObjectArray;
63using ::art::mirror::ShortArray;
64using ::art::mirror::String;
65using ::art::mirror::Throwable;
66
67namespace art {
68namespace interpreter {
69
70// External references to both interpreter implementations.
71
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010072template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020073extern JValue ExecuteSwitchImpl(Thread* self, MethodHelper& mh,
74 const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020075 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020076
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010077template<bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +020078extern JValue ExecuteGotoImpl(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
Ian Rogers54874942014-06-10 16:31:03 -070082void ThrowNullPointerExceptionFromInterpreter(const ShadowFrame& shadow_frame)
83 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertzda843e12014-05-28 19:28:31 +020084
Sebastien Hertz8ece0502013-08-07 11:26:41 +020085static inline void DoMonitorEnter(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
86 ref->MonitorEnter(self);
87}
88
89static inline void DoMonitorExit(Thread* self, Object* ref) NO_THREAD_SAFETY_ANALYSIS {
90 ref->MonitorExit(self);
91}
92
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -070093void AbortTransaction(Thread* self, const char* fmt, ...)
94 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
95
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010096void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
97 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
98
Sebastien Hertzc6714852013-09-30 16:42:32 +020099// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
100// DoInvokeVirtualQuick functions.
101// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200102template<bool is_range, bool do_assignability_check>
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100103bool DoCall(ArtMethod* method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200104 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200105
Sebastien Hertzc6714852013-09-30 16:42:32 +0200106// Handles invoke-XXX/range instructions.
107// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200108template<InvokeType type, bool is_range, bool do_access_check>
109static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
110 uint16_t inst_data, JValue* result) {
111 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
112 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700113 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700114 mirror::ArtMethod* sf_method = shadow_frame.GetMethod();
115 ArtMethod* const method = FindMethodFromCode<type, do_access_check>(
116 method_idx, &receiver, &sf_method, self);
117 // The shadow frame should already be pushed, so we don't need to update it.
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();
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700146 CHECK(receiver->GetClass()->ShouldHaveEmbeddedImtAndVTable());
147 ArtMethod* const method = receiver->GetClass()->GetEmbeddedVTableEntry(vtable_idx);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200148 if (UNLIKELY(method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200149 CHECK(self->IsExceptionPending());
150 result->SetJ(0);
151 return false;
152 } else if (UNLIKELY(method->IsAbstract())) {
153 ThrowAbstractMethodError(method);
154 result->SetJ(0);
155 return false;
156 } else {
157 // No need to check since we've been quickened.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +0100158 return DoCall<is_range, false>(method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200159 }
160}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200161
Sebastien Hertzc6714852013-09-30 16:42:32 +0200162// Handles iget-XXX and sget-XXX instructions.
163// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200164template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Ian Rogers54874942014-06-10 16:31:03 -0700165bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
166 uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200167
Sebastien Hertzc6714852013-09-30 16:42:32 +0200168// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
169// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200170template<Primitive::Type field_type>
Ian Rogers54874942014-06-10 16:31:03 -0700171bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
172 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200173
Sebastien Hertzc6714852013-09-30 16:42:32 +0200174// Handles iput-XXX and sput-XXX instructions.
175// Returns true on success, otherwise throws an exception and returns false.
Ian Rogers54874942014-06-10 16:31:03 -0700176template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
177 bool transaction_active>
178bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
179 uint16_t inst_data) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200180
Sebastien Hertzc6714852013-09-30 16:42:32 +0200181// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
182// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100183template<Primitive::Type field_type, bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -0700184bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
185 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
186
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200187
Sebastien Hertzc6714852013-09-30 16:42:32 +0200188// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
189// java.lang.String class is initialized.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200190static inline String* ResolveString(Thread* self, MethodHelper& mh, uint32_t string_idx)
191 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800192 CHECK(!kMovingMethods);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200193 Class* java_lang_string_class = String::GetJavaLangString();
194 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
195 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700196 StackHandleScope<1> hs(self);
197 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
Ian Rogers7b078e82014-09-10 14:44:24 -0700198 if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200199 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800200 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200201 }
202 }
203 return mh.ResolveString(string_idx);
204}
205
Sebastien Hertzc6714852013-09-30 16:42:32 +0200206// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
207// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200208static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
209 int32_t dividend, int32_t divisor)
210 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700211 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200212 if (UNLIKELY(divisor == 0)) {
213 ThrowArithmeticExceptionDivideByZero();
214 return false;
215 }
216 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
217 shadow_frame.SetVReg(result_reg, kMinInt);
218 } else {
219 shadow_frame.SetVReg(result_reg, dividend / divisor);
220 }
221 return true;
222}
223
Sebastien Hertzc6714852013-09-30 16:42:32 +0200224// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
225// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200226static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
227 int32_t dividend, int32_t divisor)
228 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700229 const int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200230 if (UNLIKELY(divisor == 0)) {
231 ThrowArithmeticExceptionDivideByZero();
232 return false;
233 }
234 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
235 shadow_frame.SetVReg(result_reg, 0);
236 } else {
237 shadow_frame.SetVReg(result_reg, dividend % divisor);
238 }
239 return true;
240}
241
Sebastien Hertzc6714852013-09-30 16:42:32 +0200242// Handles div-long and div-long-2addr instructions.
243// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200244static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
245 int64_t dividend, int64_t divisor)
246 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700247 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200248 if (UNLIKELY(divisor == 0)) {
249 ThrowArithmeticExceptionDivideByZero();
250 return false;
251 }
252 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
253 shadow_frame.SetVRegLong(result_reg, kMinLong);
254 } else {
255 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
256 }
257 return true;
258}
259
Sebastien Hertzc6714852013-09-30 16:42:32 +0200260// Handles rem-long and rem-long-2addr instructions.
261// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200262static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
263 int64_t dividend, int64_t divisor)
264 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700265 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200266 if (UNLIKELY(divisor == 0)) {
267 ThrowArithmeticExceptionDivideByZero();
268 return false;
269 }
270 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
271 shadow_frame.SetVRegLong(result_reg, 0);
272 } else {
273 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
274 }
275 return true;
276}
277
Sebastien Hertzc6714852013-09-30 16:42:32 +0200278// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200279// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100280template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200281bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200282 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200283
Sebastien Hertzc6714852013-09-30 16:42:32 +0200284// Handles packed-switch instruction.
285// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200286static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
287 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200288 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
289 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
290 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200291 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200292 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
293 uint16_t size = switch_data[1];
294 DCHECK_GT(size, 0);
295 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
296 DCHECK(IsAligned<4>(keys));
297 int32_t first_key = keys[0];
298 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
299 DCHECK(IsAligned<4>(targets));
300 int32_t index = test_val - first_key;
301 if (index >= 0 && index < size) {
302 return targets[index];
303 } else {
304 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
305 return 3;
306 }
307}
308
Sebastien Hertzc6714852013-09-30 16:42:32 +0200309// Handles sparse-switch instruction.
310// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200311static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
312 uint16_t inst_data)
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200313 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
314 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
315 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200316 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200317 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
318 uint16_t size = switch_data[1];
319 DCHECK_GT(size, 0);
320 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
321 DCHECK(IsAligned<4>(keys));
322 const int32_t* entries = keys + size;
323 DCHECK(IsAligned<4>(entries));
324 int lo = 0;
325 int hi = size - 1;
326 while (lo <= hi) {
327 int mid = (lo + hi) / 2;
328 int32_t foundVal = keys[mid];
329 if (test_val < foundVal) {
330 hi = mid - 1;
331 } else if (test_val > foundVal) {
332 lo = mid + 1;
333 } else {
334 return entries[mid];
335 }
336 }
337 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
338 return 3;
339}
340
Ian Rogers54874942014-06-10 16:31:03 -0700341uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertz9f102032014-05-23 08:59:42 +0200342 uint32_t dex_pc, const instrumentation::Instrumentation* instrumentation)
Ian Rogers54874942014-06-10 16:31:03 -0700343 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200344
Ian Rogers54874942014-06-10 16:31:03 -0700345void UnexpectedOpcode(const Instruction* inst, MethodHelper& mh)
Ian Rogersb48b9eb2014-02-28 16:20:21 -0800346 __attribute__((cold, noreturn))
347 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200348
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200349static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Jeff Haoa3faaf42013-09-03 19:07:00 -0700350 const uint32_t dex_pc, MethodHelper& mh)
351 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700352 constexpr bool kTracing = false;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200353 if (kTracing) {
354#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700355 std::ostringstream oss;
356 oss << PrettyMethod(shadow_frame.GetMethod())
357 << StringPrintf("\n0x%x: ", dex_pc)
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700358 << inst->DumpString(mh.GetMethod()->GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800359 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200360 uint32_t raw_value = shadow_frame.GetVReg(i);
361 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800362 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200363 if (ref_value != NULL) {
364 if (ref_value->GetClass()->IsStringClass() &&
365 ref_value->AsString()->GetCharArray() != NULL) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700366 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200367 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700368 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200369 }
370 }
371 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700372 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200373#undef TRACE_LOG
374 }
375}
376
Sebastien Hertz1eda2262013-09-09 16:53:14 +0200377static inline bool IsBackwardBranch(int32_t branch_offset) {
378 return branch_offset <= 0;
379}
380
Sebastien Hertzc6714852013-09-30 16:42:32 +0200381// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100382#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Ian Rogers54874942014-06-10 16:31:03 -0700383 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100384 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
385 const Instruction* inst, uint16_t inst_data, \
386 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200387
388#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
389 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
390 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
391 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
392 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
393
Andreas Gampec8ccf682014-09-29 20:07:43 -0700394EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic) // invoke-static/range.
395EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect) // invoke-direct/range.
396EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual) // invoke-virtual/range.
397EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper) // invoke-super/range.
398EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface) // invoke-interface/range.
Sebastien Hertzc6714852013-09-30 16:42:32 +0200399#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
400#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
401
Sebastien Hertzc6714852013-09-30 16:42:32 +0200402// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100403#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Ian Rogers54874942014-06-10 16:31:03 -0700404 template SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +0100405 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
406 const Instruction* inst, uint16_t inst_data, \
407 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +0200408
409EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
410EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
411#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
412
Sebastien Hertzc6714852013-09-30 16:42:32 +0200413
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200414} // namespace interpreter
415} // namespace art
416
417#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_