blob: 174d4e08ae94f2b6fc22d6eac4cf669816bfe44a [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
Mathieu Chartierc7853442015-03-27 14:35:38 -070027#include "art_field-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070028#include "art_method-inl.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070029#include "base/enums.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020030#include "base/logging.h"
Andreas Gampe794ad762015-02-23 08:12:24 -080031#include "base/macros.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020032#include "class_linker-inl.h"
33#include "common_throws.h"
34#include "dex_file-inl.h"
35#include "dex_instruction-inl.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070036#include "entrypoints/entrypoint_utils-inl.h"
Mathieu Chartier0cd81352014-05-22 16:48:55 -070037#include "handle_scope-inl.h"
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +010038#include "jit/jit.h"
Igor Murashkin6918bf12015-09-27 19:19:06 -070039#include "lambda/art_lambda_method.h"
Igor Murashkine2facc52015-07-10 13:49:08 -070040#include "lambda/box_table.h"
Igor Murashkin6918bf12015-09-27 19:19:06 -070041#include "lambda/closure.h"
42#include "lambda/closure_builder-inl.h"
43#include "lambda/leaking_allocator.h"
44#include "lambda/shorty_field_type.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020045#include "mirror/class-inl.h"
Igor Murashkin2ee54e22015-06-18 10:05:11 -070046#include "mirror/method.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020047#include "mirror/object-inl.h"
48#include "mirror/object_array-inl.h"
Douglas Leung4965c022014-06-11 11:41:11 -070049#include "mirror/string-inl.h"
Andreas Gampe03ec9302015-08-27 17:41:47 -070050#include "stack.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020051#include "thread.h"
52#include "well_known_classes.h"
53
Mathieu Chartiere401d142015-04-22 13:56:20 -070054using ::art::ArtMethod;
Sebastien Hertz8ece0502013-08-07 11:26:41 +020055using ::art::mirror::Array;
56using ::art::mirror::BooleanArray;
57using ::art::mirror::ByteArray;
58using ::art::mirror::CharArray;
59using ::art::mirror::Class;
60using ::art::mirror::ClassLoader;
61using ::art::mirror::IntArray;
62using ::art::mirror::LongArray;
63using ::art::mirror::Object;
64using ::art::mirror::ObjectArray;
65using ::art::mirror::ShortArray;
66using ::art::mirror::String;
67using ::art::mirror::Throwable;
68
69namespace art {
70namespace interpreter {
71
buzbee1452bee2015-03-06 14:43:04 -080072// External references to all interpreter implementations.
Sebastien Hertz8ece0502013-08-07 11:26:41 +020073
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010074template<bool do_access_check, bool transaction_active>
Ian Rogerse94652f2014-12-02 11:13:19 -080075extern JValue ExecuteSwitchImpl(Thread* self, const DexFile::CodeItem* code_item,
buzbee1452bee2015-03-06 14:43:04 -080076 ShadowFrame& shadow_frame, JValue result_register,
77 bool interpret_one_instruction);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020078
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010079template<bool do_access_check, bool transaction_active>
Ian Rogerse94652f2014-12-02 11:13:19 -080080extern JValue ExecuteGotoImpl(Thread* self, const DexFile::CodeItem* code_item,
Sebastien Hertzc6714852013-09-30 16:42:32 +020081 ShadowFrame& shadow_frame, JValue result_register);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020082
buzbee1452bee2015-03-06 14:43:04 -080083// Mterp does not support transactions or access check, thus no templated versions.
84extern "C" bool ExecuteMterpImpl(Thread* self, const DexFile::CodeItem* code_item,
85 ShadowFrame* shadow_frame, JValue* result_register);
86
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000087void ThrowNullPointerExceptionFromInterpreter()
Mathieu Chartier90443472015-07-16 20:32:27 -070088 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzda843e12014-05-28 19:28:31 +020089
Andreas Gampe03ec9302015-08-27 17:41:47 -070090template <bool kMonitorCounting>
91static inline void DoMonitorEnter(Thread* self,
92 ShadowFrame* frame,
Mathieu Chartier2d096c92015-10-12 16:18:20 -070093 Object* ref)
94 NO_THREAD_SAFETY_ANALYSIS
95 REQUIRES(!Roles::uninterruptible_) {
96 StackHandleScope<1> hs(self);
97 Handle<Object> h_ref(hs.NewHandle(ref));
98 h_ref->MonitorEnter(self);
Andreas Gampe56fdd0e2016-04-28 14:56:54 -070099 if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) {
100 frame->GetLockCountData().AddMonitor(self, h_ref.Get());
101 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200102}
103
Andreas Gampe03ec9302015-08-27 17:41:47 -0700104template <bool kMonitorCounting>
105static inline void DoMonitorExit(Thread* self,
106 ShadowFrame* frame,
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700107 Object* ref)
108 NO_THREAD_SAFETY_ANALYSIS
109 REQUIRES(!Roles::uninterruptible_) {
110 StackHandleScope<1> hs(self);
111 Handle<Object> h_ref(hs.NewHandle(ref));
112 h_ref->MonitorExit(self);
Andreas Gampe56fdd0e2016-04-28 14:56:54 -0700113 if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) {
114 frame->GetLockCountData().RemoveMonitorOrThrow(self, h_ref.Get());
115 }
116}
117
118template <bool kMonitorCounting>
119static inline bool DoMonitorCheckOnExit(Thread* self, ShadowFrame* frame)
120 NO_THREAD_SAFETY_ANALYSIS
121 REQUIRES(!Roles::uninterruptible_) {
122 if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) {
123 return frame->GetLockCountData().CheckAllMonitorsReleasedOrThrow(self);
124 }
125 return true;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200126}
127
Sebastien Hertz45b15972015-04-03 16:07:05 +0200128void AbortTransactionF(Thread* self, const char* fmt, ...)
129 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700130 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz45b15972015-04-03 16:07:05 +0200131
132void AbortTransactionV(Thread* self, const char* fmt, va_list args)
Mathieu Chartier90443472015-07-16 20:32:27 -0700133 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700134
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100135void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
Mathieu Chartier90443472015-07-16 20:32:27 -0700136 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100137
Sebastien Hertzc6714852013-09-30 16:42:32 +0200138// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
139// DoInvokeVirtualQuick functions.
140// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200141template<bool is_range, bool do_assignability_check>
Ian Rogerse94652f2014-12-02 11:13:19 -0800142bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200143 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200144
Igor Murashkin158f35c2015-06-10 15:55:30 -0700145// Invokes the given lambda closure. This is part of the invocation support and is used by
146// DoLambdaInvoke functions.
147// Returns true on success, otherwise throws an exception and returns false.
148template<bool is_range, bool do_assignability_check>
149bool DoLambdaCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
150 const Instruction* inst, uint16_t inst_data, JValue* result);
151
152// Validates that the art method corresponding to a lambda method target
153// is semantically valid:
154//
155// Must be ACC_STATIC and ACC_LAMBDA. Must be a concrete managed implementation
156// (i.e. not native, not proxy, not abstract, ...).
157//
158// If the validation fails, return false and raise an exception.
159static inline bool IsValidLambdaTargetOrThrow(ArtMethod* called_method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700160 SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700161 bool success = false;
162
163 if (UNLIKELY(called_method == nullptr)) {
164 // The shadow frame should already be pushed, so we don't need to update it.
Alex Light9139e002015-10-09 15:59:48 -0700165 } else if (UNLIKELY(!called_method->IsInvokable())) {
166 called_method->ThrowInvocationTimeError();
167 // We got an error.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700168 // TODO(iam): Also handle the case when the method is non-static, what error do we throw?
169 // TODO(iam): Also make sure that ACC_LAMBDA is set.
170 } else if (UNLIKELY(called_method->GetCodeItem() == nullptr)) {
171 // Method could be native, proxy method, etc. Lambda targets have to be concrete impls,
172 // so don't allow this.
173 } else {
174 success = true;
175 }
176
177 return success;
178}
179
Igor Murashkin6918bf12015-09-27 19:19:06 -0700180// Write out the 'Closure*' into vreg and vreg+1, as if it was a jlong.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700181static inline void WriteLambdaClosureIntoVRegs(ShadowFrame& shadow_frame,
Igor Murashkin30c475a2015-10-06 13:59:43 -0700182 const lambda::Closure& lambda_closure,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700183 uint32_t vreg) {
184 // Split the method into a lo and hi 32 bits so we can encode them into 2 virtual registers.
Igor Murashkin30c475a2015-10-06 13:59:43 -0700185 uint32_t closure_lo = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&lambda_closure));
186 uint32_t closure_hi = static_cast<uint32_t>(reinterpret_cast<uint64_t>(&lambda_closure)
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700187 >> BitSizeOf<uint32_t>());
188 // Use uint64_t instead of uintptr_t to allow shifting past the max on 32-bit.
189 static_assert(sizeof(uint64_t) >= sizeof(uintptr_t), "Impossible");
190
Igor Murashkin6918bf12015-09-27 19:19:06 -0700191 DCHECK_NE(closure_lo | closure_hi, 0u);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700192
Igor Murashkin6918bf12015-09-27 19:19:06 -0700193 shadow_frame.SetVReg(vreg, closure_lo);
194 shadow_frame.SetVReg(vreg + 1, closure_hi);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700195}
196
Igor Murashkin158f35c2015-06-10 15:55:30 -0700197// Handles create-lambda instructions.
198// Returns true on success, otherwise throws an exception and returns false.
199// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
200//
Igor Murashkin6918bf12015-09-27 19:19:06 -0700201// The closure must be allocated big enough to hold the data, and should not be
202// pre-initialized. It is initialized with the actual captured variables as a side-effect,
203// although this should be unimportant to the caller since this function also handles storing it to
204// the ShadowFrame.
205//
Igor Murashkin158f35c2015-06-10 15:55:30 -0700206// As a work-in-progress implementation, this shoves the ArtMethod object corresponding
207// to the target dex method index into the target register vA and vA + 1.
208template<bool do_access_check>
Igor Murashkin6918bf12015-09-27 19:19:06 -0700209static inline bool DoCreateLambda(Thread* self,
210 const Instruction* inst,
211 /*inout*/ShadowFrame& shadow_frame,
212 /*inout*/lambda::ClosureBuilder* closure_builder,
213 /*inout*/lambda::Closure* uninitialized_closure) {
214 DCHECK(closure_builder != nullptr);
215 DCHECK(uninitialized_closure != nullptr);
216 DCHECK_ALIGNED(uninitialized_closure, alignof(lambda::Closure));
217
Igor Murashkin30c475a2015-10-06 13:59:43 -0700218 using lambda::ArtLambdaMethod;
219 using lambda::LeakingAllocator;
220
Igor Murashkin158f35c2015-06-10 15:55:30 -0700221 /*
222 * create-lambda is opcode 0x21c
223 * - vA is the target register where the closure will be stored into
224 * (also stores into vA + 1)
225 * - vB is the method index which will be the target for a later invoke-lambda
226 */
227 const uint32_t method_idx = inst->VRegB_21c();
228 mirror::Object* receiver = nullptr; // Always static. (see 'kStatic')
229 ArtMethod* sf_method = shadow_frame.GetMethod();
230 ArtMethod* const called_method = FindMethodFromCode<kStatic, do_access_check>(
Andreas Gampe3a357142015-08-07 17:20:11 -0700231 method_idx, &receiver, sf_method, self);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700232
Igor Murashkin6918bf12015-09-27 19:19:06 -0700233 uint32_t vreg_dest_closure = inst->VRegA_21c();
Igor Murashkin158f35c2015-06-10 15:55:30 -0700234
235 if (UNLIKELY(!IsValidLambdaTargetOrThrow(called_method))) {
236 CHECK(self->IsExceptionPending());
Igor Murashkin6918bf12015-09-27 19:19:06 -0700237 shadow_frame.SetVReg(vreg_dest_closure, 0u);
238 shadow_frame.SetVReg(vreg_dest_closure + 1, 0u);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700239 return false;
240 }
241
Igor Murashkin30c475a2015-10-06 13:59:43 -0700242 ArtLambdaMethod* initialized_lambda_method;
Igor Murashkin6918bf12015-09-27 19:19:06 -0700243 // Initialize the ArtLambdaMethod with the right data.
244 {
Igor Murashkin30c475a2015-10-06 13:59:43 -0700245 // Allocate enough memory to store a well-aligned ArtLambdaMethod.
246 // This is not the final type yet since the data starts out uninitialized.
247 LeakingAllocator::AlignedMemoryStorage<ArtLambdaMethod>* uninitialized_lambda_method =
248 LeakingAllocator::AllocateMemory<ArtLambdaMethod>(self);
Igor Murashkin6918bf12015-09-27 19:19:06 -0700249
250 std::string captured_variables_shorty = closure_builder->GetCapturedVariableShortyTypes();
251 std::string captured_variables_long_type_desc;
252
253 // Synthesize a long type descriptor from the short one.
254 for (char shorty : captured_variables_shorty) {
255 lambda::ShortyFieldType shorty_field_type(shorty);
256 if (shorty_field_type.IsObject()) {
257 // Not the true type, but good enough until we implement verifier support.
258 captured_variables_long_type_desc += "Ljava/lang/Object;";
259 UNIMPLEMENTED(FATAL) << "create-lambda with an object captured variable";
260 } else if (shorty_field_type.IsLambda()) {
261 // Not the true type, but good enough until we implement verifier support.
262 captured_variables_long_type_desc += "Ljava/lang/Runnable;";
263 UNIMPLEMENTED(FATAL) << "create-lambda with a lambda captured variable";
264 } else {
265 // The primitive types have the same length shorty or not, so this is always correct.
266 DCHECK(shorty_field_type.IsPrimitive());
267 captured_variables_long_type_desc += shorty_field_type;
268 }
269 }
270
271 // Copy strings to dynamically allocated storage. This leaks, but that's ok. Fix it later.
272 // TODO: Strings need to come from the DexFile, so they won't need their own allocations.
Igor Murashkin30c475a2015-10-06 13:59:43 -0700273 char* captured_variables_type_desc = LeakingAllocator::MakeFlexibleInstance<char>(
Igor Murashkin6918bf12015-09-27 19:19:06 -0700274 self,
275 captured_variables_long_type_desc.size() + 1);
276 strcpy(captured_variables_type_desc, captured_variables_long_type_desc.c_str());
Igor Murashkin30c475a2015-10-06 13:59:43 -0700277 char* captured_variables_shorty_copy = LeakingAllocator::MakeFlexibleInstance<char>(
Igor Murashkin6918bf12015-09-27 19:19:06 -0700278 self,
279 captured_variables_shorty.size() + 1);
280 strcpy(captured_variables_shorty_copy, captured_variables_shorty.c_str());
281
Igor Murashkin30c475a2015-10-06 13:59:43 -0700282 // After initialization, the object at the storage is well-typed. Use strong type going forward.
283 initialized_lambda_method =
284 new (uninitialized_lambda_method) ArtLambdaMethod(called_method,
285 captured_variables_type_desc,
286 captured_variables_shorty_copy,
287 true); // innate lambda
Igor Murashkin6918bf12015-09-27 19:19:06 -0700288 }
289
290 // Write all the closure captured variables and the closure header into the closure.
Igor Murashkin30c475a2015-10-06 13:59:43 -0700291 lambda::Closure* initialized_closure =
292 closure_builder->CreateInPlace(uninitialized_closure, initialized_lambda_method);
Igor Murashkin6918bf12015-09-27 19:19:06 -0700293
Igor Murashkin30c475a2015-10-06 13:59:43 -0700294 WriteLambdaClosureIntoVRegs(/*inout*/shadow_frame, *initialized_closure, vreg_dest_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700295 return true;
296}
297
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700298// Reads out the 'ArtMethod*' stored inside of vreg and vreg+1
299//
300// Validates that the art method points to a valid lambda function, otherwise throws
301// an exception and returns null.
302// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
Igor Murashkin6918bf12015-09-27 19:19:06 -0700303static inline lambda::Closure* ReadLambdaClosureFromVRegsOrThrow(ShadowFrame& shadow_frame,
304 uint32_t vreg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700305 SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin6918bf12015-09-27 19:19:06 -0700306 // Lambda closures take up a consecutive pair of 2 virtual registers.
307 // On 32-bit the high bits are always 0.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700308 uint32_t vc_value_lo = shadow_frame.GetVReg(vreg);
309 uint32_t vc_value_hi = shadow_frame.GetVReg(vreg + 1);
310
311 uint64_t vc_value_ptr = (static_cast<uint64_t>(vc_value_hi) << BitSizeOf<uint32_t>())
312 | vc_value_lo;
313
314 // Use uint64_t instead of uintptr_t to allow left-shifting past the max on 32-bit.
315 static_assert(sizeof(uint64_t) >= sizeof(uintptr_t), "Impossible");
Igor Murashkin6918bf12015-09-27 19:19:06 -0700316 lambda::Closure* const lambda_closure = reinterpret_cast<lambda::Closure*>(vc_value_ptr);
317 DCHECK_ALIGNED(lambda_closure, alignof(lambda::Closure));
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700318
319 // Guard against the user passing a null closure, which is odd but (sadly) semantically valid.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700320 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700321 ThrowNullPointerExceptionFromInterpreter();
322 return nullptr;
Igor Murashkin6918bf12015-09-27 19:19:06 -0700323 } else if (UNLIKELY(!IsValidLambdaTargetOrThrow(lambda_closure->GetTargetMethod()))) {
324 // Sanity check against data corruption.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700325 return nullptr;
326 }
327
Igor Murashkin6918bf12015-09-27 19:19:06 -0700328 return lambda_closure;
329}
330
331// Forward declaration for lock annotations. See below for documentation.
332template <bool do_access_check>
333static inline const char* GetStringDataByDexStringIndexOrThrow(ShadowFrame& shadow_frame,
334 uint32_t string_idx)
335 SHARED_REQUIRES(Locks::mutator_lock_);
336
337// Find the c-string data corresponding to a dex file's string index.
338// Otherwise, returns null if not found and throws a VerifyError.
339//
340// Note that with do_access_check=false, we never return null because the verifier
341// must guard against invalid string indices.
342// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
343template <bool do_access_check>
344static inline const char* GetStringDataByDexStringIndexOrThrow(ShadowFrame& shadow_frame,
345 uint32_t string_idx) {
346 ArtMethod* method = shadow_frame.GetMethod();
347 const DexFile* dex_file = method->GetDexFile();
348
349 mirror::Class* declaring_class = method->GetDeclaringClass();
350 if (!do_access_check) {
351 // MethodVerifier refuses methods with string_idx out of bounds.
352 DCHECK_LT(string_idx, declaring_class->GetDexCache()->NumStrings());
353 } else {
354 // Access checks enabled: perform string index bounds ourselves.
355 if (string_idx >= dex_file->GetHeader().string_ids_size_) {
356 ThrowVerifyError(declaring_class, "String index '%" PRIu32 "' out of bounds",
357 string_idx);
358 return nullptr;
359 }
360 }
361
362 const char* type_string = dex_file->StringDataByIdx(string_idx);
363
364 if (UNLIKELY(type_string == nullptr)) {
365 CHECK_EQ(false, do_access_check)
366 << " verifier should've caught invalid string index " << string_idx;
367 CHECK_EQ(true, do_access_check)
368 << " string idx size check should've caught invalid string index " << string_idx;
369 }
370
371 return type_string;
372}
373
374// Handles capture-variable instructions.
375// Returns true on success, otherwise throws an exception and returns false.
376// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
377template<bool do_access_check>
378static inline bool DoCaptureVariable(Thread* self,
379 const Instruction* inst,
380 /*inout*/ShadowFrame& shadow_frame,
381 /*inout*/lambda::ClosureBuilder* closure_builder) {
382 DCHECK(closure_builder != nullptr);
383 using lambda::ShortyFieldType;
384 /*
385 * capture-variable is opcode 0xf6, fmt 0x21c
386 * - vA is the source register of the variable that will be captured
387 * - vB is the string ID of the variable's type that will be captured
388 */
389 const uint32_t source_vreg = inst->VRegA_21c();
390 const uint32_t string_idx = inst->VRegB_21c();
391 // TODO: this should be a proper [type id] instead of a [string ID] pointing to a type.
392
393 const char* type_string = GetStringDataByDexStringIndexOrThrow<do_access_check>(shadow_frame,
394 string_idx);
395 if (UNLIKELY(type_string == nullptr)) {
396 CHECK(self->IsExceptionPending());
397 return false;
398 }
399
400 char type_first_letter = type_string[0];
401 ShortyFieldType shorty_type;
402 if (do_access_check &&
403 UNLIKELY(!ShortyFieldType::MaybeCreate(type_first_letter, /*out*/&shorty_type))) { // NOLINT: [whitespace/comma] [3]
404 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
405 "capture-variable vB must be a valid type");
406 return false;
407 } else {
408 // Already verified that the type is valid.
409 shorty_type = ShortyFieldType(type_first_letter);
410 }
411
412 const size_t captured_variable_count = closure_builder->GetCaptureCount();
413
414 // Note: types are specified explicitly so that the closure is packed tightly.
415 switch (shorty_type) {
416 case ShortyFieldType::kBoolean: {
417 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
418 closure_builder->CaptureVariablePrimitive<bool>(primitive_narrow_value);
419 break;
420 }
421 case ShortyFieldType::kByte: {
422 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
423 closure_builder->CaptureVariablePrimitive<int8_t>(primitive_narrow_value);
424 break;
425 }
426 case ShortyFieldType::kChar: {
427 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
428 closure_builder->CaptureVariablePrimitive<uint16_t>(primitive_narrow_value);
429 break;
430 }
431 case ShortyFieldType::kShort: {
432 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
433 closure_builder->CaptureVariablePrimitive<int16_t>(primitive_narrow_value);
434 break;
435 }
436 case ShortyFieldType::kInt: {
437 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
438 closure_builder->CaptureVariablePrimitive<int32_t>(primitive_narrow_value);
439 break;
440 }
441 case ShortyFieldType::kDouble: {
442 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegDouble(source_vreg));
443 break;
444 }
445 case ShortyFieldType::kFloat: {
446 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegFloat(source_vreg));
447 break;
448 }
449 case ShortyFieldType::kLambda: {
450 UNIMPLEMENTED(FATAL) << " capture-variable with type kLambda";
451 // TODO: Capturing lambdas recursively will be done at a later time.
452 UNREACHABLE();
453 }
454 case ShortyFieldType::kLong: {
455 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegLong(source_vreg));
456 break;
457 }
458 case ShortyFieldType::kObject: {
459 closure_builder->CaptureVariableObject(shadow_frame.GetVRegReference(source_vreg));
460 UNIMPLEMENTED(FATAL) << " capture-variable with type kObject";
461 // TODO: finish implementing this. disabled for now since we can't track lambda refs for GC.
462 UNREACHABLE();
463 }
464
465 default:
466 LOG(FATAL) << "Invalid shorty type value " << shorty_type;
467 UNREACHABLE();
468 }
469
470 DCHECK_EQ(captured_variable_count + 1, closure_builder->GetCaptureCount());
471
472 return true;
473}
474
475// Handles capture-variable instructions.
476// Returns true on success, otherwise throws an exception and returns false.
477// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
478template<bool do_access_check>
479static inline bool DoLiberateVariable(Thread* self,
480 const Instruction* inst,
481 size_t captured_variable_index,
482 /*inout*/ShadowFrame& shadow_frame) {
483 using lambda::ShortyFieldType;
484 /*
485 * liberate-variable is opcode 0xf7, fmt 0x22c
486 * - vA is the destination register
487 * - vB is the register with the lambda closure in it
488 * - vC is the string ID which needs to be a valid field type descriptor
489 */
490
491 const uint32_t dest_vreg = inst->VRegA_22c();
492 const uint32_t closure_vreg = inst->VRegB_22c();
493 const uint32_t string_idx = inst->VRegC_22c();
494 // TODO: this should be a proper [type id] instead of a [string ID] pointing to a type.
495
496
497 // Synthesize a long type descriptor from a shorty type descriptor list.
498 // TODO: Fix the dex encoding to contain the long and short type descriptors.
499 const char* type_string = GetStringDataByDexStringIndexOrThrow<do_access_check>(shadow_frame,
500 string_idx);
501 if (UNLIKELY(do_access_check && type_string == nullptr)) {
502 CHECK(self->IsExceptionPending());
503 shadow_frame.SetVReg(dest_vreg, 0);
504 return false;
505 }
506
507 char type_first_letter = type_string[0];
508 ShortyFieldType shorty_type;
509 if (do_access_check &&
510 UNLIKELY(!ShortyFieldType::MaybeCreate(type_first_letter, /*out*/&shorty_type))) { // NOLINT: [whitespace/comma] [3]
511 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
512 "liberate-variable vC must be a valid type");
513 shadow_frame.SetVReg(dest_vreg, 0);
514 return false;
515 } else {
516 // Already verified that the type is valid.
517 shorty_type = ShortyFieldType(type_first_letter);
518 }
519
520 // Check for closure being null *after* the type check.
521 // This way we can access the type info in case we fail later, to know how many vregs to clear.
522 const lambda::Closure* lambda_closure =
523 ReadLambdaClosureFromVRegsOrThrow(/*inout*/shadow_frame, closure_vreg);
524
525 // Failed lambda target runtime check, an exception was raised.
526 if (UNLIKELY(lambda_closure == nullptr)) {
527 CHECK(self->IsExceptionPending());
528
529 // Clear the destination vreg(s) to be safe.
530 shadow_frame.SetVReg(dest_vreg, 0);
531 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
532 shadow_frame.SetVReg(dest_vreg + 1, 0);
533 }
534 return false;
535 }
536
537 if (do_access_check &&
538 UNLIKELY(captured_variable_index >= lambda_closure->GetNumberOfCapturedVariables())) {
539 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
540 "liberate-variable captured variable index %zu out of bounds",
541 lambda_closure->GetNumberOfCapturedVariables());
542 // Clear the destination vreg(s) to be safe.
543 shadow_frame.SetVReg(dest_vreg, 0);
544 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
545 shadow_frame.SetVReg(dest_vreg + 1, 0);
546 }
547 return false;
548 }
549
550 // Verify that the runtime type of the captured-variable matches the requested dex type.
551 if (do_access_check) {
552 ShortyFieldType actual_type = lambda_closure->GetCapturedShortyType(captured_variable_index);
553 if (actual_type != shorty_type) {
554 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
555 "cannot liberate-variable of runtime type '%c' to dex type '%c'",
556 static_cast<char>(actual_type),
557 static_cast<char>(shorty_type));
558
559 shadow_frame.SetVReg(dest_vreg, 0);
560 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
561 shadow_frame.SetVReg(dest_vreg + 1, 0);
562 }
563 return false;
564 }
565
566 if (actual_type.IsLambda() || actual_type.IsObject()) {
567 UNIMPLEMENTED(FATAL) << "liberate-variable type checks needs to "
568 << "parse full type descriptor for objects and lambdas";
569 }
570 }
571
572 // Unpack the captured variable from the closure into the correct type, then save it to the vreg.
573 if (shorty_type.IsPrimitiveNarrow()) {
574 uint32_t primitive_narrow_value =
575 lambda_closure->GetCapturedPrimitiveNarrow(captured_variable_index);
576 shadow_frame.SetVReg(dest_vreg, primitive_narrow_value);
577 } else if (shorty_type.IsPrimitiveWide()) {
578 uint64_t primitive_wide_value =
579 lambda_closure->GetCapturedPrimitiveWide(captured_variable_index);
580 shadow_frame.SetVRegLong(dest_vreg, static_cast<int64_t>(primitive_wide_value));
581 } else if (shorty_type.IsObject()) {
582 mirror::Object* unpacked_object =
583 lambda_closure->GetCapturedObject(captured_variable_index);
584 shadow_frame.SetVRegReference(dest_vreg, unpacked_object);
585
586 UNIMPLEMENTED(FATAL) << "liberate-variable cannot unpack objects yet";
587 } else if (shorty_type.IsLambda()) {
588 UNIMPLEMENTED(FATAL) << "liberate-variable cannot unpack lambdas yet";
589 } else {
590 LOG(FATAL) << "unreachable";
591 UNREACHABLE();
592 }
593
594 return true;
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700595}
596
Igor Murashkin158f35c2015-06-10 15:55:30 -0700597template<bool do_access_check>
598static inline bool DoInvokeLambda(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
599 uint16_t inst_data, JValue* result) {
600 /*
601 * invoke-lambda is opcode 0x25
602 *
603 * - vC is the closure register (both vC and vC + 1 will be used to store the closure).
604 * - vB is the number of additional registers up to |{vD,vE,vF,vG}| (4)
605 * - the rest of the registers are always var-args
606 *
607 * - reading var-args for 0x25 gets us vD,vE,vF,vG (but not vB)
608 */
Igor Murashkin6918bf12015-09-27 19:19:06 -0700609 uint32_t vreg_closure = inst->VRegC_25x();
610 const lambda::Closure* lambda_closure =
611 ReadLambdaClosureFromVRegsOrThrow(shadow_frame, vreg_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700612
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700613 // Failed lambda target runtime check, an exception was raised.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700614 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700615 CHECK(self->IsExceptionPending());
616 result->SetJ(0);
617 return false;
Igor Murashkin158f35c2015-06-10 15:55:30 -0700618 }
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700619
Igor Murashkin6918bf12015-09-27 19:19:06 -0700620 ArtMethod* const called_method = lambda_closure->GetTargetMethod();
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700621 // Invoke a non-range lambda
622 return DoLambdaCall<false, do_access_check>(called_method, self, shadow_frame, inst, inst_data,
623 result);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700624}
625
Igor Murashkin6918bf12015-09-27 19:19:06 -0700626// Handles invoke-XXX/range instructions (other than invoke-lambda[-range]).
Sebastien Hertzc6714852013-09-30 16:42:32 +0200627// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200628template<InvokeType type, bool is_range, bool do_access_check>
629static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
630 uint16_t inst_data, JValue* result) {
631 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
632 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700633 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700634 ArtMethod* sf_method = shadow_frame.GetMethod();
Ian Rogerse94652f2014-12-02 11:13:19 -0800635 ArtMethod* const called_method = FindMethodFromCode<type, do_access_check>(
Andreas Gampe3a357142015-08-07 17:20:11 -0700636 method_idx, &receiver, sf_method, self);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700637 // The shadow frame should already be pushed, so we don't need to update it.
Ian Rogerse94652f2014-12-02 11:13:19 -0800638 if (UNLIKELY(called_method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200639 CHECK(self->IsExceptionPending());
640 result->SetJ(0);
641 return false;
Alex Light9139e002015-10-09 15:59:48 -0700642 } else if (UNLIKELY(!called_method->IsInvokable())) {
643 called_method->ThrowInvocationTimeError();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200644 result->SetJ(0);
645 return false;
646 } else {
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100647 jit::Jit* jit = Runtime::Current()->GetJit();
648 if (jit != nullptr) {
649 if (type == kVirtual || type == kInterface) {
650 jit->InvokeVirtualOrInterface(
651 self, receiver, sf_method, shadow_frame.GetDexPC(), called_method);
652 }
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100653 jit->AddSamples(self, sf_method, 1, /*with_backedges*/false);
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100654 }
655 // TODO: Remove the InvokeVirtualOrInterface instrumentation, as it was only used by the JIT.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100656 if (type == kVirtual || type == kInterface) {
657 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
658 if (UNLIKELY(instrumentation->HasInvokeVirtualOrInterfaceListeners())) {
659 instrumentation->InvokeVirtualOrInterface(
660 self, receiver, sf_method, shadow_frame.GetDexPC(), called_method);
661 }
662 }
Ian Rogerse94652f2014-12-02 11:13:19 -0800663 return DoCall<is_range, do_access_check>(called_method, self, shadow_frame, inst, inst_data,
664 result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200665 }
666}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200667
Sebastien Hertzc6714852013-09-30 16:42:32 +0200668// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
669// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200670template<bool is_range>
671static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
672 const Instruction* inst, uint16_t inst_data,
673 JValue* result) {
674 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
675 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200676 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200677 // We lost the reference to the method index so we cannot get a more
678 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000679 ThrowNullPointerExceptionFromDexPC();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200680 return false;
681 }
682 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
Artem Udovichenkoa62cb9b2016-06-30 09:18:25 +0000683 CHECK(receiver->GetClass()->ShouldHaveEmbeddedVTable());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700684 ArtMethod* const called_method = receiver->GetClass()->GetEmbeddedVTableEntry(
Andreas Gampe542451c2016-07-26 09:02:02 -0700685 vtable_idx, kRuntimePointerSize);
Ian Rogerse94652f2014-12-02 11:13:19 -0800686 if (UNLIKELY(called_method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200687 CHECK(self->IsExceptionPending());
688 result->SetJ(0);
689 return false;
Alex Light9139e002015-10-09 15:59:48 -0700690 } else if (UNLIKELY(!called_method->IsInvokable())) {
691 called_method->ThrowInvocationTimeError();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200692 result->SetJ(0);
693 return false;
694 } else {
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100695 jit::Jit* jit = Runtime::Current()->GetJit();
696 if (jit != nullptr) {
697 jit->InvokeVirtualOrInterface(
698 self, receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100699 jit->AddSamples(self, shadow_frame.GetMethod(), 1, /*with_backedges*/false);
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100700 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100701 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100702 // TODO: Remove the InvokeVirtualOrInterface instrumentation, as it was only used by the JIT.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100703 if (UNLIKELY(instrumentation->HasInvokeVirtualOrInterfaceListeners())) {
704 instrumentation->InvokeVirtualOrInterface(
705 self, receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
706 }
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200707 // No need to check since we've been quickened.
Ian Rogerse94652f2014-12-02 11:13:19 -0800708 return DoCall<is_range, false>(called_method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200709 }
710}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200711
Sebastien Hertzc6714852013-09-30 16:42:32 +0200712// Handles iget-XXX and sget-XXX instructions.
713// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200714template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Ian Rogers54874942014-06-10 16:31:03 -0700715bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700716 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200717
Sebastien Hertzc6714852013-09-30 16:42:32 +0200718// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
719// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200720template<Primitive::Type field_type>
Ian Rogers54874942014-06-10 16:31:03 -0700721bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700722 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200723
Sebastien Hertzc6714852013-09-30 16:42:32 +0200724// Handles iput-XXX and sput-XXX instructions.
725// Returns true on success, otherwise throws an exception and returns false.
Ian Rogers54874942014-06-10 16:31:03 -0700726template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
727 bool transaction_active>
728bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700729 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200730
Sebastien Hertzc6714852013-09-30 16:42:32 +0200731// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
732// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100733template<Primitive::Type field_type, bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -0700734bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700735 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers54874942014-06-10 16:31:03 -0700736
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200737
Sebastien Hertzc6714852013-09-30 16:42:32 +0200738// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
739// java.lang.String class is initialized.
Ian Rogers6786a582014-10-28 12:49:06 -0700740static inline String* ResolveString(Thread* self, ShadowFrame& shadow_frame, uint32_t string_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700741 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200742 Class* java_lang_string_class = String::GetJavaLangString();
743 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
744 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700745 StackHandleScope<1> hs(self);
746 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
Ian Rogers7b078e82014-09-10 14:44:24 -0700747 if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200748 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800749 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200750 }
751 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700752 ArtMethod* method = shadow_frame.GetMethod();
Mathieu Chartiereace4582014-11-24 18:29:54 -0800753 mirror::Class* declaring_class = method->GetDeclaringClass();
Vladimir Marko05792b92015-08-03 11:56:49 +0100754 // MethodVerifier refuses methods with string_idx out of bounds.
755 DCHECK_LT(string_idx, declaring_class->GetDexCache()->NumStrings());
756 mirror::String* s = declaring_class->GetDexCacheStrings()[string_idx].Read();
Ian Rogers6786a582014-10-28 12:49:06 -0700757 if (UNLIKELY(s == nullptr)) {
758 StackHandleScope<1> hs(self);
Mathieu Chartiereace4582014-11-24 18:29:54 -0800759 Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache()));
Ian Rogers6786a582014-10-28 12:49:06 -0700760 s = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), string_idx,
761 dex_cache);
762 }
763 return s;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200764}
765
Sebastien Hertzc6714852013-09-30 16:42:32 +0200766// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
767// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200768static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
769 int32_t dividend, int32_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700770 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersf72a11d2014-10-30 15:41:08 -0700771 constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200772 if (UNLIKELY(divisor == 0)) {
773 ThrowArithmeticExceptionDivideByZero();
774 return false;
775 }
776 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
777 shadow_frame.SetVReg(result_reg, kMinInt);
778 } else {
779 shadow_frame.SetVReg(result_reg, dividend / divisor);
780 }
781 return true;
782}
783
Sebastien Hertzc6714852013-09-30 16:42:32 +0200784// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
785// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200786static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
787 int32_t dividend, int32_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700788 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersf72a11d2014-10-30 15:41:08 -0700789 constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200790 if (UNLIKELY(divisor == 0)) {
791 ThrowArithmeticExceptionDivideByZero();
792 return false;
793 }
794 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
795 shadow_frame.SetVReg(result_reg, 0);
796 } else {
797 shadow_frame.SetVReg(result_reg, dividend % divisor);
798 }
799 return true;
800}
801
Sebastien Hertzc6714852013-09-30 16:42:32 +0200802// Handles div-long and div-long-2addr instructions.
803// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200804static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
805 int64_t dividend, int64_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700806 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700807 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200808 if (UNLIKELY(divisor == 0)) {
809 ThrowArithmeticExceptionDivideByZero();
810 return false;
811 }
812 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
813 shadow_frame.SetVRegLong(result_reg, kMinLong);
814 } else {
815 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
816 }
817 return true;
818}
819
Sebastien Hertzc6714852013-09-30 16:42:32 +0200820// Handles rem-long and rem-long-2addr instructions.
821// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200822static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
823 int64_t dividend, int64_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700824 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700825 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200826 if (UNLIKELY(divisor == 0)) {
827 ThrowArithmeticExceptionDivideByZero();
828 return false;
829 }
830 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
831 shadow_frame.SetVRegLong(result_reg, 0);
832 } else {
833 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
834 }
835 return true;
836}
837
Sebastien Hertzc6714852013-09-30 16:42:32 +0200838// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200839// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100840template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200841bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200842 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200843
Sebastien Hertzc6714852013-09-30 16:42:32 +0200844// Handles packed-switch instruction.
845// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200846static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
847 uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700848 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200849 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
850 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200851 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200852 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
853 uint16_t size = switch_data[1];
David Brazdil2ef645b2015-06-17 18:20:52 +0100854 if (size == 0) {
855 // Empty packed switch, move forward by 3 (size of PACKED_SWITCH).
856 return 3;
857 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200858 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
Roland Levillain14d90572015-07-16 10:52:26 +0100859 DCHECK_ALIGNED(keys, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200860 int32_t first_key = keys[0];
861 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
Roland Levillain14d90572015-07-16 10:52:26 +0100862 DCHECK_ALIGNED(targets, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200863 int32_t index = test_val - first_key;
864 if (index >= 0 && index < size) {
865 return targets[index];
866 } else {
867 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
868 return 3;
869 }
870}
871
Sebastien Hertzc6714852013-09-30 16:42:32 +0200872// Handles sparse-switch instruction.
873// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200874static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
875 uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700876 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200877 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
878 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200879 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200880 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
881 uint16_t size = switch_data[1];
Jeff Hao935e01a2015-03-20 19:44:35 -0700882 // Return length of SPARSE_SWITCH if size is 0.
883 if (size == 0) {
884 return 3;
885 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200886 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
Roland Levillain14d90572015-07-16 10:52:26 +0100887 DCHECK_ALIGNED(keys, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200888 const int32_t* entries = keys + size;
Roland Levillain14d90572015-07-16 10:52:26 +0100889 DCHECK_ALIGNED(entries, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200890 int lo = 0;
891 int hi = size - 1;
892 while (lo <= hi) {
893 int mid = (lo + hi) / 2;
894 int32_t foundVal = keys[mid];
895 if (test_val < foundVal) {
896 hi = mid - 1;
897 } else if (test_val > foundVal) {
898 lo = mid + 1;
899 } else {
900 return entries[mid];
901 }
902 }
903 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
904 return 3;
905}
906
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700907template <bool _do_check>
908static inline bool DoBoxLambda(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700909 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700910 /*
911 * box-lambda vA, vB /// opcode 0xf8, format 22x
912 * - vA is the target register where the Object representation of the closure will be stored into
913 * - vB is a closure (made by create-lambda)
914 * (also reads vB + 1)
915 */
916 uint32_t vreg_target_object = inst->VRegA_22x(inst_data);
917 uint32_t vreg_source_closure = inst->VRegB_22x();
918
Igor Murashkin6918bf12015-09-27 19:19:06 -0700919 lambda::Closure* lambda_closure = ReadLambdaClosureFromVRegsOrThrow(shadow_frame,
920 vreg_source_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700921
922 // Failed lambda target runtime check, an exception was raised.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700923 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700924 CHECK(self->IsExceptionPending());
925 return false;
926 }
927
Igor Murashkine2facc52015-07-10 13:49:08 -0700928 mirror::Object* closure_as_object =
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000929 Runtime::Current()->GetLambdaBoxTable()->BoxLambda(lambda_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700930
Igor Murashkine2facc52015-07-10 13:49:08 -0700931 // Failed to box the lambda, an exception was raised.
932 if (UNLIKELY(closure_as_object == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700933 CHECK(self->IsExceptionPending());
934 return false;
935 }
936
Igor Murashkine2facc52015-07-10 13:49:08 -0700937 shadow_frame.SetVRegReference(vreg_target_object, closure_as_object);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700938 return true;
939}
940
Mathieu Chartier90443472015-07-16 20:32:27 -0700941template <bool _do_check> SHARED_REQUIRES(Locks::mutator_lock_)
Igor Murashkine2facc52015-07-10 13:49:08 -0700942static inline bool DoUnboxLambda(Thread* self,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700943 ShadowFrame& shadow_frame,
944 const Instruction* inst,
945 uint16_t inst_data) {
946 /*
947 * unbox-lambda vA, vB, [type id] /// opcode 0xf9, format 22c
948 * - vA is the target register where the closure will be written into
949 * (also writes vA + 1)
950 * - vB is the Object representation of the closure (made by box-lambda)
951 */
952 uint32_t vreg_target_closure = inst->VRegA_22c(inst_data);
953 uint32_t vreg_source_object = inst->VRegB_22c();
954
955 // Raise NullPointerException if object is null
956 mirror::Object* boxed_closure_object = shadow_frame.GetVRegReference(vreg_source_object);
957 if (UNLIKELY(boxed_closure_object == nullptr)) {
958 ThrowNullPointerExceptionFromInterpreter();
959 return false;
960 }
961
Igor Murashkin6918bf12015-09-27 19:19:06 -0700962 lambda::Closure* unboxed_closure = nullptr;
Igor Murashkine2facc52015-07-10 13:49:08 -0700963 // Raise an exception if unboxing fails.
964 if (!Runtime::Current()->GetLambdaBoxTable()->UnboxLambda(boxed_closure_object,
Igor Murashkin6918bf12015-09-27 19:19:06 -0700965 /*out*/&unboxed_closure)) {
Igor Murashkine2facc52015-07-10 13:49:08 -0700966 CHECK(self->IsExceptionPending());
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700967 return false;
968 }
969
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700970 DCHECK(unboxed_closure != nullptr);
Igor Murashkin30c475a2015-10-06 13:59:43 -0700971 WriteLambdaClosureIntoVRegs(/*inout*/shadow_frame, *unboxed_closure, vreg_target_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700972 return true;
973}
974
Ian Rogers54874942014-06-10 16:31:03 -0700975uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertz9f102032014-05-23 08:59:42 +0200976 uint32_t dex_pc, const instrumentation::Instrumentation* instrumentation)
Mathieu Chartier90443472015-07-16 20:32:27 -0700977 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200978
Andreas Gampe794ad762015-02-23 08:12:24 -0800979NO_RETURN void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame)
980 __attribute__((cold))
Mathieu Chartier90443472015-07-16 20:32:27 -0700981 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200982
Bill Buzbeed47fd902016-07-07 14:42:43 +0000983// Set true if you want TraceExecution invocation before each bytecode execution.
984constexpr bool kTraceExecutionEnabled = false;
Serguei Katkov9fb0ac72016-02-20 12:55:24 +0600985
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200986static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Ian Rogerse94652f2014-12-02 11:13:19 -0800987 const uint32_t dex_pc)
Mathieu Chartier90443472015-07-16 20:32:27 -0700988 SHARED_REQUIRES(Locks::mutator_lock_) {
Bill Buzbeed47fd902016-07-07 14:42:43 +0000989 if (kTraceExecutionEnabled) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200990#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700991 std::ostringstream oss;
992 oss << PrettyMethod(shadow_frame.GetMethod())
993 << StringPrintf("\n0x%x: ", dex_pc)
Ian Rogerse94652f2014-12-02 11:13:19 -0800994 << inst->DumpString(shadow_frame.GetMethod()->GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800995 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200996 uint32_t raw_value = shadow_frame.GetVReg(i);
997 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800998 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700999 if (ref_value != nullptr) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001000 if (ref_value->GetClass()->IsStringClass() &&
Jeff Hao848f70a2014-01-15 13:49:50 -08001001 ref_value->AsString()->GetValue() != nullptr) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -07001002 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001003 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -07001004 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001005 }
1006 }
1007 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -07001008 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001009#undef TRACE_LOG
1010 }
1011}
1012
Sebastien Hertz1eda2262013-09-09 16:53:14 +02001013static inline bool IsBackwardBranch(int32_t branch_offset) {
1014 return branch_offset <= 0;
1015}
1016
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +01001017void ArtInterpreterToCompiledCodeBridge(Thread* self,
1018 ArtMethod* caller,
1019 const DexFile::CodeItem* code_item,
1020 ShadowFrame* shadow_frame,
1021 JValue* result);
Siva Chandra05d24152016-01-05 17:43:17 -08001022
Mingyao Yangffedec52016-05-19 10:48:40 -07001023// Set string value created from StringFactory.newStringFromXXX() into all aliases of
1024// StringFactory.newEmptyString().
1025void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame,
1026 uint16_t this_obj_vreg,
1027 JValue result);
1028
Sebastien Hertzc6714852013-09-30 16:42:32 +02001029// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001030#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001031 template SHARED_REQUIRES(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001032 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
1033 const Instruction* inst, uint16_t inst_data, \
1034 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +02001035
1036#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
1037 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
1038 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
1039 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
1040 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
1041
Andreas Gampec8ccf682014-09-29 20:07:43 -07001042EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic) // invoke-static/range.
1043EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect) // invoke-direct/range.
1044EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual) // invoke-virtual/range.
1045EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper) // invoke-super/range.
1046EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface) // invoke-interface/range.
Sebastien Hertzc6714852013-09-30 16:42:32 +02001047#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
1048#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
1049
Sebastien Hertzc6714852013-09-30 16:42:32 +02001050// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001051#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001052 template SHARED_REQUIRES(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001053 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
1054 const Instruction* inst, uint16_t inst_data, \
1055 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +02001056
1057EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
1058EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
1059#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
1060
Igor Murashkin158f35c2015-06-10 15:55:30 -07001061// Explicitly instantiate all DoCreateLambda functions.
Igor Murashkin6918bf12015-09-27 19:19:06 -07001062#define EXPLICIT_DO_CREATE_LAMBDA_DECL(_do_check) \
1063template SHARED_REQUIRES(Locks::mutator_lock_) \
1064bool DoCreateLambda<_do_check>(Thread* self, \
1065 const Instruction* inst, \
1066 /*inout*/ShadowFrame& shadow_frame, \
1067 /*inout*/lambda::ClosureBuilder* closure_builder, \
1068 /*inout*/lambda::Closure* uninitialized_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001069
1070EXPLICIT_DO_CREATE_LAMBDA_DECL(false); // create-lambda
1071EXPLICIT_DO_CREATE_LAMBDA_DECL(true); // create-lambda
1072#undef EXPLICIT_DO_CREATE_LAMBDA_DECL
1073
1074// Explicitly instantiate all DoInvokeLambda functions.
1075#define EXPLICIT_DO_INVOKE_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001076template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin158f35c2015-06-10 15:55:30 -07001077bool DoInvokeLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1078 uint16_t inst_data, JValue* result);
1079
1080EXPLICIT_DO_INVOKE_LAMBDA_DECL(false); // invoke-lambda
1081EXPLICIT_DO_INVOKE_LAMBDA_DECL(true); // invoke-lambda
1082#undef EXPLICIT_DO_INVOKE_LAMBDA_DECL
1083
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001084// Explicitly instantiate all DoBoxLambda functions.
1085#define EXPLICIT_DO_BOX_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001086template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001087bool DoBoxLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1088 uint16_t inst_data);
1089
1090EXPLICIT_DO_BOX_LAMBDA_DECL(false); // box-lambda
1091EXPLICIT_DO_BOX_LAMBDA_DECL(true); // box-lambda
1092#undef EXPLICIT_DO_BOX_LAMBDA_DECL
1093
1094// Explicitly instantiate all DoUnBoxLambda functions.
1095#define EXPLICIT_DO_UNBOX_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001096template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001097bool DoUnboxLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1098 uint16_t inst_data);
1099
1100EXPLICIT_DO_UNBOX_LAMBDA_DECL(false); // unbox-lambda
1101EXPLICIT_DO_UNBOX_LAMBDA_DECL(true); // unbox-lambda
1102#undef EXPLICIT_DO_BOX_LAMBDA_DECL
1103
Igor Murashkin6918bf12015-09-27 19:19:06 -07001104// Explicitly instantiate all DoCaptureVariable functions.
1105#define EXPLICIT_DO_CAPTURE_VARIABLE_DECL(_do_check) \
1106template SHARED_REQUIRES(Locks::mutator_lock_) \
1107bool DoCaptureVariable<_do_check>(Thread* self, \
1108 const Instruction* inst, \
1109 ShadowFrame& shadow_frame, \
1110 lambda::ClosureBuilder* closure_builder);
Sebastien Hertzc6714852013-09-30 16:42:32 +02001111
Igor Murashkin6918bf12015-09-27 19:19:06 -07001112EXPLICIT_DO_CAPTURE_VARIABLE_DECL(false); // capture-variable
1113EXPLICIT_DO_CAPTURE_VARIABLE_DECL(true); // capture-variable
1114#undef EXPLICIT_DO_CREATE_LAMBDA_DECL
1115
1116// Explicitly instantiate all DoLiberateVariable functions.
1117#define EXPLICIT_DO_LIBERATE_VARIABLE_DECL(_do_check) \
1118template SHARED_REQUIRES(Locks::mutator_lock_) \
1119bool DoLiberateVariable<_do_check>(Thread* self, \
1120 const Instruction* inst, \
1121 size_t captured_variable_index, \
1122 ShadowFrame& shadow_frame); \
1123
1124EXPLICIT_DO_LIBERATE_VARIABLE_DECL(false); // liberate-variable
1125EXPLICIT_DO_LIBERATE_VARIABLE_DECL(true); // liberate-variable
1126#undef EXPLICIT_DO_LIBERATE_LAMBDA_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001127} // namespace interpreter
1128} // namespace art
1129
1130#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_