blob: fb9817514c73d8b4af3a2ef599c102ebab51b040 [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"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020029#include "base/logging.h"
Andreas Gampe794ad762015-02-23 08:12:24 -080030#include "base/macros.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020031#include "class_linker-inl.h"
32#include "common_throws.h"
33#include "dex_file-inl.h"
34#include "dex_instruction-inl.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070035#include "entrypoints/entrypoint_utils-inl.h"
Mathieu Chartier0cd81352014-05-22 16:48:55 -070036#include "handle_scope-inl.h"
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +010037#include "jit/jit.h"
Igor Murashkin6918bf12015-09-27 19:19:06 -070038#include "lambda/art_lambda_method.h"
Igor Murashkine2facc52015-07-10 13:49:08 -070039#include "lambda/box_table.h"
Igor Murashkin6918bf12015-09-27 19:19:06 -070040#include "lambda/closure.h"
41#include "lambda/closure_builder-inl.h"
42#include "lambda/leaking_allocator.h"
43#include "lambda/shorty_field_type.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020044#include "mirror/class-inl.h"
Igor Murashkin2ee54e22015-06-18 10:05:11 -070045#include "mirror/method.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020046#include "mirror/object-inl.h"
47#include "mirror/object_array-inl.h"
Douglas Leung4965c022014-06-11 11:41:11 -070048#include "mirror/string-inl.h"
Andreas Gampe03ec9302015-08-27 17:41:47 -070049#include "stack.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020050#include "thread.h"
51#include "well_known_classes.h"
52
Mathieu Chartiere401d142015-04-22 13:56:20 -070053using ::art::ArtMethod;
Sebastien Hertz8ece0502013-08-07 11:26:41 +020054using ::art::mirror::Array;
55using ::art::mirror::BooleanArray;
56using ::art::mirror::ByteArray;
57using ::art::mirror::CharArray;
58using ::art::mirror::Class;
59using ::art::mirror::ClassLoader;
60using ::art::mirror::IntArray;
61using ::art::mirror::LongArray;
62using ::art::mirror::Object;
63using ::art::mirror::ObjectArray;
64using ::art::mirror::ShortArray;
65using ::art::mirror::String;
66using ::art::mirror::Throwable;
67
68namespace art {
69namespace interpreter {
70
buzbee1452bee2015-03-06 14:43:04 -080071// External references to all interpreter implementations.
Sebastien Hertz8ece0502013-08-07 11:26:41 +020072
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010073template<bool do_access_check, bool transaction_active>
Ian Rogerse94652f2014-12-02 11:13:19 -080074extern JValue ExecuteSwitchImpl(Thread* self, const DexFile::CodeItem* code_item,
buzbee1452bee2015-03-06 14:43:04 -080075 ShadowFrame& shadow_frame, JValue result_register,
76 bool interpret_one_instruction);
Sebastien Hertz8ece0502013-08-07 11:26:41 +020077
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010078template<bool do_access_check, bool transaction_active>
Ian Rogerse94652f2014-12-02 11:13:19 -080079extern JValue ExecuteGotoImpl(Thread* self, 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
buzbee1452bee2015-03-06 14:43:04 -080082// Mterp does not support transactions or access check, thus no templated versions.
83extern "C" bool ExecuteMterpImpl(Thread* self, const DexFile::CodeItem* code_item,
84 ShadowFrame* shadow_frame, JValue* result_register);
85
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000086void ThrowNullPointerExceptionFromInterpreter()
Mathieu Chartier90443472015-07-16 20:32:27 -070087 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzda843e12014-05-28 19:28:31 +020088
Andreas Gampe03ec9302015-08-27 17:41:47 -070089template <bool kMonitorCounting>
90static inline void DoMonitorEnter(Thread* self,
91 ShadowFrame* frame,
Mathieu Chartier2d096c92015-10-12 16:18:20 -070092 Object* ref)
93 NO_THREAD_SAFETY_ANALYSIS
94 REQUIRES(!Roles::uninterruptible_) {
95 StackHandleScope<1> hs(self);
96 Handle<Object> h_ref(hs.NewHandle(ref));
97 h_ref->MonitorEnter(self);
98 frame->GetLockCountData().AddMonitor<kMonitorCounting>(self, h_ref.Get());
Sebastien Hertz8ece0502013-08-07 11:26:41 +020099}
100
Andreas Gampe03ec9302015-08-27 17:41:47 -0700101template <bool kMonitorCounting>
102static inline void DoMonitorExit(Thread* self,
103 ShadowFrame* frame,
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700104 Object* ref)
105 NO_THREAD_SAFETY_ANALYSIS
106 REQUIRES(!Roles::uninterruptible_) {
107 StackHandleScope<1> hs(self);
108 Handle<Object> h_ref(hs.NewHandle(ref));
109 h_ref->MonitorExit(self);
110 frame->GetLockCountData().RemoveMonitorOrThrow<kMonitorCounting>(self, h_ref.Get());
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200111}
112
Sebastien Hertz45b15972015-04-03 16:07:05 +0200113void AbortTransactionF(Thread* self, const char* fmt, ...)
114 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700115 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz45b15972015-04-03 16:07:05 +0200116
117void AbortTransactionV(Thread* self, const char* fmt, va_list args)
Mathieu Chartier90443472015-07-16 20:32:27 -0700118 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700119
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100120void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
Mathieu Chartier90443472015-07-16 20:32:27 -0700121 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100122
Sebastien Hertzc6714852013-09-30 16:42:32 +0200123// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
124// DoInvokeVirtualQuick functions.
125// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200126template<bool is_range, bool do_assignability_check>
Ian Rogerse94652f2014-12-02 11:13:19 -0800127bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200128 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200129
Igor Murashkin158f35c2015-06-10 15:55:30 -0700130// Invokes the given lambda closure. This is part of the invocation support and is used by
131// DoLambdaInvoke functions.
132// Returns true on success, otherwise throws an exception and returns false.
133template<bool is_range, bool do_assignability_check>
134bool DoLambdaCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
135 const Instruction* inst, uint16_t inst_data, JValue* result);
136
137// Validates that the art method corresponding to a lambda method target
138// is semantically valid:
139//
140// Must be ACC_STATIC and ACC_LAMBDA. Must be a concrete managed implementation
141// (i.e. not native, not proxy, not abstract, ...).
142//
143// If the validation fails, return false and raise an exception.
144static inline bool IsValidLambdaTargetOrThrow(ArtMethod* called_method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700145 SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700146 bool success = false;
147
148 if (UNLIKELY(called_method == nullptr)) {
149 // The shadow frame should already be pushed, so we don't need to update it.
Alex Light9139e002015-10-09 15:59:48 -0700150 } else if (UNLIKELY(!called_method->IsInvokable())) {
151 called_method->ThrowInvocationTimeError();
152 // We got an error.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700153 // TODO(iam): Also handle the case when the method is non-static, what error do we throw?
154 // TODO(iam): Also make sure that ACC_LAMBDA is set.
155 } else if (UNLIKELY(called_method->GetCodeItem() == nullptr)) {
156 // Method could be native, proxy method, etc. Lambda targets have to be concrete impls,
157 // so don't allow this.
158 } else {
159 success = true;
160 }
161
162 return success;
163}
164
Igor Murashkin6918bf12015-09-27 19:19:06 -0700165// Write out the 'Closure*' into vreg and vreg+1, as if it was a jlong.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700166static inline void WriteLambdaClosureIntoVRegs(ShadowFrame& shadow_frame,
Igor Murashkin30c475a2015-10-06 13:59:43 -0700167 const lambda::Closure& lambda_closure,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700168 uint32_t vreg) {
169 // 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 -0700170 uint32_t closure_lo = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&lambda_closure));
171 uint32_t closure_hi = static_cast<uint32_t>(reinterpret_cast<uint64_t>(&lambda_closure)
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700172 >> BitSizeOf<uint32_t>());
173 // Use uint64_t instead of uintptr_t to allow shifting past the max on 32-bit.
174 static_assert(sizeof(uint64_t) >= sizeof(uintptr_t), "Impossible");
175
Igor Murashkin6918bf12015-09-27 19:19:06 -0700176 DCHECK_NE(closure_lo | closure_hi, 0u);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700177
Igor Murashkin6918bf12015-09-27 19:19:06 -0700178 shadow_frame.SetVReg(vreg, closure_lo);
179 shadow_frame.SetVReg(vreg + 1, closure_hi);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700180}
181
Igor Murashkin158f35c2015-06-10 15:55:30 -0700182// Handles create-lambda instructions.
183// Returns true on success, otherwise throws an exception and returns false.
184// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
185//
Igor Murashkin6918bf12015-09-27 19:19:06 -0700186// The closure must be allocated big enough to hold the data, and should not be
187// pre-initialized. It is initialized with the actual captured variables as a side-effect,
188// although this should be unimportant to the caller since this function also handles storing it to
189// the ShadowFrame.
190//
Igor Murashkin158f35c2015-06-10 15:55:30 -0700191// As a work-in-progress implementation, this shoves the ArtMethod object corresponding
192// to the target dex method index into the target register vA and vA + 1.
193template<bool do_access_check>
Igor Murashkin6918bf12015-09-27 19:19:06 -0700194static inline bool DoCreateLambda(Thread* self,
195 const Instruction* inst,
196 /*inout*/ShadowFrame& shadow_frame,
197 /*inout*/lambda::ClosureBuilder* closure_builder,
198 /*inout*/lambda::Closure* uninitialized_closure) {
199 DCHECK(closure_builder != nullptr);
200 DCHECK(uninitialized_closure != nullptr);
201 DCHECK_ALIGNED(uninitialized_closure, alignof(lambda::Closure));
202
Igor Murashkin30c475a2015-10-06 13:59:43 -0700203 using lambda::ArtLambdaMethod;
204 using lambda::LeakingAllocator;
205
Igor Murashkin158f35c2015-06-10 15:55:30 -0700206 /*
207 * create-lambda is opcode 0x21c
208 * - vA is the target register where the closure will be stored into
209 * (also stores into vA + 1)
210 * - vB is the method index which will be the target for a later invoke-lambda
211 */
212 const uint32_t method_idx = inst->VRegB_21c();
213 mirror::Object* receiver = nullptr; // Always static. (see 'kStatic')
214 ArtMethod* sf_method = shadow_frame.GetMethod();
215 ArtMethod* const called_method = FindMethodFromCode<kStatic, do_access_check>(
Andreas Gampe3a357142015-08-07 17:20:11 -0700216 method_idx, &receiver, sf_method, self);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700217
Igor Murashkin6918bf12015-09-27 19:19:06 -0700218 uint32_t vreg_dest_closure = inst->VRegA_21c();
Igor Murashkin158f35c2015-06-10 15:55:30 -0700219
220 if (UNLIKELY(!IsValidLambdaTargetOrThrow(called_method))) {
221 CHECK(self->IsExceptionPending());
Igor Murashkin6918bf12015-09-27 19:19:06 -0700222 shadow_frame.SetVReg(vreg_dest_closure, 0u);
223 shadow_frame.SetVReg(vreg_dest_closure + 1, 0u);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700224 return false;
225 }
226
Igor Murashkin30c475a2015-10-06 13:59:43 -0700227 ArtLambdaMethod* initialized_lambda_method;
Igor Murashkin6918bf12015-09-27 19:19:06 -0700228 // Initialize the ArtLambdaMethod with the right data.
229 {
Igor Murashkin30c475a2015-10-06 13:59:43 -0700230 // Allocate enough memory to store a well-aligned ArtLambdaMethod.
231 // This is not the final type yet since the data starts out uninitialized.
232 LeakingAllocator::AlignedMemoryStorage<ArtLambdaMethod>* uninitialized_lambda_method =
233 LeakingAllocator::AllocateMemory<ArtLambdaMethod>(self);
Igor Murashkin6918bf12015-09-27 19:19:06 -0700234
235 std::string captured_variables_shorty = closure_builder->GetCapturedVariableShortyTypes();
236 std::string captured_variables_long_type_desc;
237
238 // Synthesize a long type descriptor from the short one.
239 for (char shorty : captured_variables_shorty) {
240 lambda::ShortyFieldType shorty_field_type(shorty);
241 if (shorty_field_type.IsObject()) {
242 // Not the true type, but good enough until we implement verifier support.
243 captured_variables_long_type_desc += "Ljava/lang/Object;";
244 UNIMPLEMENTED(FATAL) << "create-lambda with an object captured variable";
245 } else if (shorty_field_type.IsLambda()) {
246 // Not the true type, but good enough until we implement verifier support.
247 captured_variables_long_type_desc += "Ljava/lang/Runnable;";
248 UNIMPLEMENTED(FATAL) << "create-lambda with a lambda captured variable";
249 } else {
250 // The primitive types have the same length shorty or not, so this is always correct.
251 DCHECK(shorty_field_type.IsPrimitive());
252 captured_variables_long_type_desc += shorty_field_type;
253 }
254 }
255
256 // Copy strings to dynamically allocated storage. This leaks, but that's ok. Fix it later.
257 // TODO: Strings need to come from the DexFile, so they won't need their own allocations.
Igor Murashkin30c475a2015-10-06 13:59:43 -0700258 char* captured_variables_type_desc = LeakingAllocator::MakeFlexibleInstance<char>(
Igor Murashkin6918bf12015-09-27 19:19:06 -0700259 self,
260 captured_variables_long_type_desc.size() + 1);
261 strcpy(captured_variables_type_desc, captured_variables_long_type_desc.c_str());
Igor Murashkin30c475a2015-10-06 13:59:43 -0700262 char* captured_variables_shorty_copy = LeakingAllocator::MakeFlexibleInstance<char>(
Igor Murashkin6918bf12015-09-27 19:19:06 -0700263 self,
264 captured_variables_shorty.size() + 1);
265 strcpy(captured_variables_shorty_copy, captured_variables_shorty.c_str());
266
Igor Murashkin30c475a2015-10-06 13:59:43 -0700267 // After initialization, the object at the storage is well-typed. Use strong type going forward.
268 initialized_lambda_method =
269 new (uninitialized_lambda_method) ArtLambdaMethod(called_method,
270 captured_variables_type_desc,
271 captured_variables_shorty_copy,
272 true); // innate lambda
Igor Murashkin6918bf12015-09-27 19:19:06 -0700273 }
274
275 // Write all the closure captured variables and the closure header into the closure.
Igor Murashkin30c475a2015-10-06 13:59:43 -0700276 lambda::Closure* initialized_closure =
277 closure_builder->CreateInPlace(uninitialized_closure, initialized_lambda_method);
Igor Murashkin6918bf12015-09-27 19:19:06 -0700278
Igor Murashkin30c475a2015-10-06 13:59:43 -0700279 WriteLambdaClosureIntoVRegs(/*inout*/shadow_frame, *initialized_closure, vreg_dest_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700280 return true;
281}
282
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700283// Reads out the 'ArtMethod*' stored inside of vreg and vreg+1
284//
285// Validates that the art method points to a valid lambda function, otherwise throws
286// an exception and returns null.
287// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
Igor Murashkin6918bf12015-09-27 19:19:06 -0700288static inline lambda::Closure* ReadLambdaClosureFromVRegsOrThrow(ShadowFrame& shadow_frame,
289 uint32_t vreg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700290 SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin6918bf12015-09-27 19:19:06 -0700291 // Lambda closures take up a consecutive pair of 2 virtual registers.
292 // On 32-bit the high bits are always 0.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700293 uint32_t vc_value_lo = shadow_frame.GetVReg(vreg);
294 uint32_t vc_value_hi = shadow_frame.GetVReg(vreg + 1);
295
296 uint64_t vc_value_ptr = (static_cast<uint64_t>(vc_value_hi) << BitSizeOf<uint32_t>())
297 | vc_value_lo;
298
299 // Use uint64_t instead of uintptr_t to allow left-shifting past the max on 32-bit.
300 static_assert(sizeof(uint64_t) >= sizeof(uintptr_t), "Impossible");
Igor Murashkin6918bf12015-09-27 19:19:06 -0700301 lambda::Closure* const lambda_closure = reinterpret_cast<lambda::Closure*>(vc_value_ptr);
302 DCHECK_ALIGNED(lambda_closure, alignof(lambda::Closure));
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700303
304 // Guard against the user passing a null closure, which is odd but (sadly) semantically valid.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700305 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700306 ThrowNullPointerExceptionFromInterpreter();
307 return nullptr;
Igor Murashkin6918bf12015-09-27 19:19:06 -0700308 } else if (UNLIKELY(!IsValidLambdaTargetOrThrow(lambda_closure->GetTargetMethod()))) {
309 // Sanity check against data corruption.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700310 return nullptr;
311 }
312
Igor Murashkin6918bf12015-09-27 19:19:06 -0700313 return lambda_closure;
314}
315
316// Forward declaration for lock annotations. See below for documentation.
317template <bool do_access_check>
318static inline const char* GetStringDataByDexStringIndexOrThrow(ShadowFrame& shadow_frame,
319 uint32_t string_idx)
320 SHARED_REQUIRES(Locks::mutator_lock_);
321
322// Find the c-string data corresponding to a dex file's string index.
323// Otherwise, returns null if not found and throws a VerifyError.
324//
325// Note that with do_access_check=false, we never return null because the verifier
326// must guard against invalid string indices.
327// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
328template <bool do_access_check>
329static inline const char* GetStringDataByDexStringIndexOrThrow(ShadowFrame& shadow_frame,
330 uint32_t string_idx) {
331 ArtMethod* method = shadow_frame.GetMethod();
332 const DexFile* dex_file = method->GetDexFile();
333
334 mirror::Class* declaring_class = method->GetDeclaringClass();
335 if (!do_access_check) {
336 // MethodVerifier refuses methods with string_idx out of bounds.
337 DCHECK_LT(string_idx, declaring_class->GetDexCache()->NumStrings());
338 } else {
339 // Access checks enabled: perform string index bounds ourselves.
340 if (string_idx >= dex_file->GetHeader().string_ids_size_) {
341 ThrowVerifyError(declaring_class, "String index '%" PRIu32 "' out of bounds",
342 string_idx);
343 return nullptr;
344 }
345 }
346
347 const char* type_string = dex_file->StringDataByIdx(string_idx);
348
349 if (UNLIKELY(type_string == nullptr)) {
350 CHECK_EQ(false, do_access_check)
351 << " verifier should've caught invalid string index " << string_idx;
352 CHECK_EQ(true, do_access_check)
353 << " string idx size check should've caught invalid string index " << string_idx;
354 }
355
356 return type_string;
357}
358
359// Handles capture-variable instructions.
360// Returns true on success, otherwise throws an exception and returns false.
361// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
362template<bool do_access_check>
363static inline bool DoCaptureVariable(Thread* self,
364 const Instruction* inst,
365 /*inout*/ShadowFrame& shadow_frame,
366 /*inout*/lambda::ClosureBuilder* closure_builder) {
367 DCHECK(closure_builder != nullptr);
368 using lambda::ShortyFieldType;
369 /*
370 * capture-variable is opcode 0xf6, fmt 0x21c
371 * - vA is the source register of the variable that will be captured
372 * - vB is the string ID of the variable's type that will be captured
373 */
374 const uint32_t source_vreg = inst->VRegA_21c();
375 const uint32_t string_idx = inst->VRegB_21c();
376 // TODO: this should be a proper [type id] instead of a [string ID] pointing to a type.
377
378 const char* type_string = GetStringDataByDexStringIndexOrThrow<do_access_check>(shadow_frame,
379 string_idx);
380 if (UNLIKELY(type_string == nullptr)) {
381 CHECK(self->IsExceptionPending());
382 return false;
383 }
384
385 char type_first_letter = type_string[0];
386 ShortyFieldType shorty_type;
387 if (do_access_check &&
388 UNLIKELY(!ShortyFieldType::MaybeCreate(type_first_letter, /*out*/&shorty_type))) { // NOLINT: [whitespace/comma] [3]
389 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
390 "capture-variable vB must be a valid type");
391 return false;
392 } else {
393 // Already verified that the type is valid.
394 shorty_type = ShortyFieldType(type_first_letter);
395 }
396
397 const size_t captured_variable_count = closure_builder->GetCaptureCount();
398
399 // Note: types are specified explicitly so that the closure is packed tightly.
400 switch (shorty_type) {
401 case ShortyFieldType::kBoolean: {
402 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
403 closure_builder->CaptureVariablePrimitive<bool>(primitive_narrow_value);
404 break;
405 }
406 case ShortyFieldType::kByte: {
407 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
408 closure_builder->CaptureVariablePrimitive<int8_t>(primitive_narrow_value);
409 break;
410 }
411 case ShortyFieldType::kChar: {
412 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
413 closure_builder->CaptureVariablePrimitive<uint16_t>(primitive_narrow_value);
414 break;
415 }
416 case ShortyFieldType::kShort: {
417 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
418 closure_builder->CaptureVariablePrimitive<int16_t>(primitive_narrow_value);
419 break;
420 }
421 case ShortyFieldType::kInt: {
422 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
423 closure_builder->CaptureVariablePrimitive<int32_t>(primitive_narrow_value);
424 break;
425 }
426 case ShortyFieldType::kDouble: {
427 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegDouble(source_vreg));
428 break;
429 }
430 case ShortyFieldType::kFloat: {
431 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegFloat(source_vreg));
432 break;
433 }
434 case ShortyFieldType::kLambda: {
435 UNIMPLEMENTED(FATAL) << " capture-variable with type kLambda";
436 // TODO: Capturing lambdas recursively will be done at a later time.
437 UNREACHABLE();
438 }
439 case ShortyFieldType::kLong: {
440 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegLong(source_vreg));
441 break;
442 }
443 case ShortyFieldType::kObject: {
444 closure_builder->CaptureVariableObject(shadow_frame.GetVRegReference(source_vreg));
445 UNIMPLEMENTED(FATAL) << " capture-variable with type kObject";
446 // TODO: finish implementing this. disabled for now since we can't track lambda refs for GC.
447 UNREACHABLE();
448 }
449
450 default:
451 LOG(FATAL) << "Invalid shorty type value " << shorty_type;
452 UNREACHABLE();
453 }
454
455 DCHECK_EQ(captured_variable_count + 1, closure_builder->GetCaptureCount());
456
457 return true;
458}
459
460// Handles capture-variable instructions.
461// Returns true on success, otherwise throws an exception and returns false.
462// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
463template<bool do_access_check>
464static inline bool DoLiberateVariable(Thread* self,
465 const Instruction* inst,
466 size_t captured_variable_index,
467 /*inout*/ShadowFrame& shadow_frame) {
468 using lambda::ShortyFieldType;
469 /*
470 * liberate-variable is opcode 0xf7, fmt 0x22c
471 * - vA is the destination register
472 * - vB is the register with the lambda closure in it
473 * - vC is the string ID which needs to be a valid field type descriptor
474 */
475
476 const uint32_t dest_vreg = inst->VRegA_22c();
477 const uint32_t closure_vreg = inst->VRegB_22c();
478 const uint32_t string_idx = inst->VRegC_22c();
479 // TODO: this should be a proper [type id] instead of a [string ID] pointing to a type.
480
481
482 // Synthesize a long type descriptor from a shorty type descriptor list.
483 // TODO: Fix the dex encoding to contain the long and short type descriptors.
484 const char* type_string = GetStringDataByDexStringIndexOrThrow<do_access_check>(shadow_frame,
485 string_idx);
486 if (UNLIKELY(do_access_check && type_string == nullptr)) {
487 CHECK(self->IsExceptionPending());
488 shadow_frame.SetVReg(dest_vreg, 0);
489 return false;
490 }
491
492 char type_first_letter = type_string[0];
493 ShortyFieldType shorty_type;
494 if (do_access_check &&
495 UNLIKELY(!ShortyFieldType::MaybeCreate(type_first_letter, /*out*/&shorty_type))) { // NOLINT: [whitespace/comma] [3]
496 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
497 "liberate-variable vC must be a valid type");
498 shadow_frame.SetVReg(dest_vreg, 0);
499 return false;
500 } else {
501 // Already verified that the type is valid.
502 shorty_type = ShortyFieldType(type_first_letter);
503 }
504
505 // Check for closure being null *after* the type check.
506 // This way we can access the type info in case we fail later, to know how many vregs to clear.
507 const lambda::Closure* lambda_closure =
508 ReadLambdaClosureFromVRegsOrThrow(/*inout*/shadow_frame, closure_vreg);
509
510 // Failed lambda target runtime check, an exception was raised.
511 if (UNLIKELY(lambda_closure == nullptr)) {
512 CHECK(self->IsExceptionPending());
513
514 // Clear the destination vreg(s) to be safe.
515 shadow_frame.SetVReg(dest_vreg, 0);
516 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
517 shadow_frame.SetVReg(dest_vreg + 1, 0);
518 }
519 return false;
520 }
521
522 if (do_access_check &&
523 UNLIKELY(captured_variable_index >= lambda_closure->GetNumberOfCapturedVariables())) {
524 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
525 "liberate-variable captured variable index %zu out of bounds",
526 lambda_closure->GetNumberOfCapturedVariables());
527 // Clear the destination vreg(s) to be safe.
528 shadow_frame.SetVReg(dest_vreg, 0);
529 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
530 shadow_frame.SetVReg(dest_vreg + 1, 0);
531 }
532 return false;
533 }
534
535 // Verify that the runtime type of the captured-variable matches the requested dex type.
536 if (do_access_check) {
537 ShortyFieldType actual_type = lambda_closure->GetCapturedShortyType(captured_variable_index);
538 if (actual_type != shorty_type) {
539 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
540 "cannot liberate-variable of runtime type '%c' to dex type '%c'",
541 static_cast<char>(actual_type),
542 static_cast<char>(shorty_type));
543
544 shadow_frame.SetVReg(dest_vreg, 0);
545 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
546 shadow_frame.SetVReg(dest_vreg + 1, 0);
547 }
548 return false;
549 }
550
551 if (actual_type.IsLambda() || actual_type.IsObject()) {
552 UNIMPLEMENTED(FATAL) << "liberate-variable type checks needs to "
553 << "parse full type descriptor for objects and lambdas";
554 }
555 }
556
557 // Unpack the captured variable from the closure into the correct type, then save it to the vreg.
558 if (shorty_type.IsPrimitiveNarrow()) {
559 uint32_t primitive_narrow_value =
560 lambda_closure->GetCapturedPrimitiveNarrow(captured_variable_index);
561 shadow_frame.SetVReg(dest_vreg, primitive_narrow_value);
562 } else if (shorty_type.IsPrimitiveWide()) {
563 uint64_t primitive_wide_value =
564 lambda_closure->GetCapturedPrimitiveWide(captured_variable_index);
565 shadow_frame.SetVRegLong(dest_vreg, static_cast<int64_t>(primitive_wide_value));
566 } else if (shorty_type.IsObject()) {
567 mirror::Object* unpacked_object =
568 lambda_closure->GetCapturedObject(captured_variable_index);
569 shadow_frame.SetVRegReference(dest_vreg, unpacked_object);
570
571 UNIMPLEMENTED(FATAL) << "liberate-variable cannot unpack objects yet";
572 } else if (shorty_type.IsLambda()) {
573 UNIMPLEMENTED(FATAL) << "liberate-variable cannot unpack lambdas yet";
574 } else {
575 LOG(FATAL) << "unreachable";
576 UNREACHABLE();
577 }
578
579 return true;
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700580}
581
Igor Murashkin158f35c2015-06-10 15:55:30 -0700582template<bool do_access_check>
583static inline bool DoInvokeLambda(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
584 uint16_t inst_data, JValue* result) {
585 /*
586 * invoke-lambda is opcode 0x25
587 *
588 * - vC is the closure register (both vC and vC + 1 will be used to store the closure).
589 * - vB is the number of additional registers up to |{vD,vE,vF,vG}| (4)
590 * - the rest of the registers are always var-args
591 *
592 * - reading var-args for 0x25 gets us vD,vE,vF,vG (but not vB)
593 */
Igor Murashkin6918bf12015-09-27 19:19:06 -0700594 uint32_t vreg_closure = inst->VRegC_25x();
595 const lambda::Closure* lambda_closure =
596 ReadLambdaClosureFromVRegsOrThrow(shadow_frame, vreg_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700597
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700598 // Failed lambda target runtime check, an exception was raised.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700599 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700600 CHECK(self->IsExceptionPending());
601 result->SetJ(0);
602 return false;
Igor Murashkin158f35c2015-06-10 15:55:30 -0700603 }
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700604
Igor Murashkin6918bf12015-09-27 19:19:06 -0700605 ArtMethod* const called_method = lambda_closure->GetTargetMethod();
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700606 // Invoke a non-range lambda
607 return DoLambdaCall<false, do_access_check>(called_method, self, shadow_frame, inst, inst_data,
608 result);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700609}
610
Igor Murashkin6918bf12015-09-27 19:19:06 -0700611// Handles invoke-XXX/range instructions (other than invoke-lambda[-range]).
Sebastien Hertzc6714852013-09-30 16:42:32 +0200612// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200613template<InvokeType type, bool is_range, bool do_access_check>
614static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
615 uint16_t inst_data, JValue* result) {
616 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
617 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700618 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700619 ArtMethod* sf_method = shadow_frame.GetMethod();
Ian Rogerse94652f2014-12-02 11:13:19 -0800620 ArtMethod* const called_method = FindMethodFromCode<type, do_access_check>(
Andreas Gampe3a357142015-08-07 17:20:11 -0700621 method_idx, &receiver, sf_method, self);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700622 // The shadow frame should already be pushed, so we don't need to update it.
Ian Rogerse94652f2014-12-02 11:13:19 -0800623 if (UNLIKELY(called_method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200624 CHECK(self->IsExceptionPending());
625 result->SetJ(0);
626 return false;
Alex Light9139e002015-10-09 15:59:48 -0700627 } else if (UNLIKELY(!called_method->IsInvokable())) {
628 called_method->ThrowInvocationTimeError();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200629 result->SetJ(0);
630 return false;
631 } else {
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100632 jit::Jit* jit = Runtime::Current()->GetJit();
633 if (jit != nullptr) {
634 if (type == kVirtual || type == kInterface) {
635 jit->InvokeVirtualOrInterface(
636 self, receiver, sf_method, shadow_frame.GetDexPC(), called_method);
637 }
638 jit->AddSamples(self, sf_method, 1);
639 }
640 // TODO: Remove the InvokeVirtualOrInterface instrumentation, as it was only used by the JIT.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100641 if (type == kVirtual || type == kInterface) {
642 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
643 if (UNLIKELY(instrumentation->HasInvokeVirtualOrInterfaceListeners())) {
644 instrumentation->InvokeVirtualOrInterface(
645 self, receiver, sf_method, shadow_frame.GetDexPC(), called_method);
646 }
647 }
Ian Rogerse94652f2014-12-02 11:13:19 -0800648 return DoCall<is_range, do_access_check>(called_method, self, shadow_frame, inst, inst_data,
649 result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200650 }
651}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200652
Sebastien Hertzc6714852013-09-30 16:42:32 +0200653// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
654// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200655template<bool is_range>
656static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
657 const Instruction* inst, uint16_t inst_data,
658 JValue* result) {
659 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
660 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200661 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200662 // We lost the reference to the method index so we cannot get a more
663 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000664 ThrowNullPointerExceptionFromDexPC();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200665 return false;
666 }
667 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700668 CHECK(receiver->GetClass()->ShouldHaveEmbeddedImtAndVTable());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700669 ArtMethod* const called_method = receiver->GetClass()->GetEmbeddedVTableEntry(
670 vtable_idx, sizeof(void*));
Ian Rogerse94652f2014-12-02 11:13:19 -0800671 if (UNLIKELY(called_method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200672 CHECK(self->IsExceptionPending());
673 result->SetJ(0);
674 return false;
Alex Light9139e002015-10-09 15:59:48 -0700675 } else if (UNLIKELY(!called_method->IsInvokable())) {
676 called_method->ThrowInvocationTimeError();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200677 result->SetJ(0);
678 return false;
679 } else {
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100680 jit::Jit* jit = Runtime::Current()->GetJit();
681 if (jit != nullptr) {
682 jit->InvokeVirtualOrInterface(
683 self, receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
684 jit->AddSamples(self, shadow_frame.GetMethod(), 1);
685 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100686 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100687 // TODO: Remove the InvokeVirtualOrInterface instrumentation, as it was only used by the JIT.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100688 if (UNLIKELY(instrumentation->HasInvokeVirtualOrInterfaceListeners())) {
689 instrumentation->InvokeVirtualOrInterface(
690 self, receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
691 }
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200692 // No need to check since we've been quickened.
Ian Rogerse94652f2014-12-02 11:13:19 -0800693 return DoCall<is_range, false>(called_method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200694 }
695}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200696
Sebastien Hertzc6714852013-09-30 16:42:32 +0200697// Handles iget-XXX and sget-XXX instructions.
698// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200699template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Ian Rogers54874942014-06-10 16:31:03 -0700700bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700701 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200702
Sebastien Hertzc6714852013-09-30 16:42:32 +0200703// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
704// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200705template<Primitive::Type field_type>
Ian Rogers54874942014-06-10 16:31:03 -0700706bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700707 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200708
Sebastien Hertzc6714852013-09-30 16:42:32 +0200709// Handles iput-XXX and sput-XXX instructions.
710// Returns true on success, otherwise throws an exception and returns false.
Ian Rogers54874942014-06-10 16:31:03 -0700711template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
712 bool transaction_active>
713bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700714 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200715
Sebastien Hertzc6714852013-09-30 16:42:32 +0200716// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
717// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100718template<Primitive::Type field_type, bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -0700719bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700720 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers54874942014-06-10 16:31:03 -0700721
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200722
Sebastien Hertzc6714852013-09-30 16:42:32 +0200723// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
724// java.lang.String class is initialized.
Ian Rogers6786a582014-10-28 12:49:06 -0700725static inline String* ResolveString(Thread* self, ShadowFrame& shadow_frame, uint32_t string_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700726 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200727 Class* java_lang_string_class = String::GetJavaLangString();
728 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
729 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700730 StackHandleScope<1> hs(self);
731 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
Ian Rogers7b078e82014-09-10 14:44:24 -0700732 if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200733 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800734 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200735 }
736 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700737 ArtMethod* method = shadow_frame.GetMethod();
Mathieu Chartiereace4582014-11-24 18:29:54 -0800738 mirror::Class* declaring_class = method->GetDeclaringClass();
Vladimir Marko05792b92015-08-03 11:56:49 +0100739 // MethodVerifier refuses methods with string_idx out of bounds.
740 DCHECK_LT(string_idx, declaring_class->GetDexCache()->NumStrings());
741 mirror::String* s = declaring_class->GetDexCacheStrings()[string_idx].Read();
Ian Rogers6786a582014-10-28 12:49:06 -0700742 if (UNLIKELY(s == nullptr)) {
743 StackHandleScope<1> hs(self);
Mathieu Chartiereace4582014-11-24 18:29:54 -0800744 Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache()));
Ian Rogers6786a582014-10-28 12:49:06 -0700745 s = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), string_idx,
746 dex_cache);
747 }
748 return s;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200749}
750
Sebastien Hertzc6714852013-09-30 16:42:32 +0200751// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
752// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200753static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
754 int32_t dividend, int32_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700755 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersf72a11d2014-10-30 15:41:08 -0700756 constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200757 if (UNLIKELY(divisor == 0)) {
758 ThrowArithmeticExceptionDivideByZero();
759 return false;
760 }
761 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
762 shadow_frame.SetVReg(result_reg, kMinInt);
763 } else {
764 shadow_frame.SetVReg(result_reg, dividend / divisor);
765 }
766 return true;
767}
768
Sebastien Hertzc6714852013-09-30 16:42:32 +0200769// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
770// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200771static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
772 int32_t dividend, int32_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700773 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersf72a11d2014-10-30 15:41:08 -0700774 constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200775 if (UNLIKELY(divisor == 0)) {
776 ThrowArithmeticExceptionDivideByZero();
777 return false;
778 }
779 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
780 shadow_frame.SetVReg(result_reg, 0);
781 } else {
782 shadow_frame.SetVReg(result_reg, dividend % divisor);
783 }
784 return true;
785}
786
Sebastien Hertzc6714852013-09-30 16:42:32 +0200787// Handles div-long and div-long-2addr instructions.
788// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200789static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
790 int64_t dividend, int64_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700791 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700792 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200793 if (UNLIKELY(divisor == 0)) {
794 ThrowArithmeticExceptionDivideByZero();
795 return false;
796 }
797 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
798 shadow_frame.SetVRegLong(result_reg, kMinLong);
799 } else {
800 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
801 }
802 return true;
803}
804
Sebastien Hertzc6714852013-09-30 16:42:32 +0200805// Handles rem-long and rem-long-2addr instructions.
806// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200807static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
808 int64_t dividend, int64_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700809 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700810 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200811 if (UNLIKELY(divisor == 0)) {
812 ThrowArithmeticExceptionDivideByZero();
813 return false;
814 }
815 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
816 shadow_frame.SetVRegLong(result_reg, 0);
817 } else {
818 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
819 }
820 return true;
821}
822
Sebastien Hertzc6714852013-09-30 16:42:32 +0200823// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200824// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100825template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200826bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200827 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200828
Sebastien Hertzc6714852013-09-30 16:42:32 +0200829// Handles packed-switch instruction.
830// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200831static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
832 uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700833 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200834 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
835 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200836 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200837 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
838 uint16_t size = switch_data[1];
David Brazdil2ef645b2015-06-17 18:20:52 +0100839 if (size == 0) {
840 // Empty packed switch, move forward by 3 (size of PACKED_SWITCH).
841 return 3;
842 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200843 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
Roland Levillain14d90572015-07-16 10:52:26 +0100844 DCHECK_ALIGNED(keys, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200845 int32_t first_key = keys[0];
846 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
Roland Levillain14d90572015-07-16 10:52:26 +0100847 DCHECK_ALIGNED(targets, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200848 int32_t index = test_val - first_key;
849 if (index >= 0 && index < size) {
850 return targets[index];
851 } else {
852 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
853 return 3;
854 }
855}
856
Sebastien Hertzc6714852013-09-30 16:42:32 +0200857// Handles sparse-switch instruction.
858// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200859static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
860 uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700861 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200862 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
863 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200864 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200865 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
866 uint16_t size = switch_data[1];
Jeff Hao935e01a2015-03-20 19:44:35 -0700867 // Return length of SPARSE_SWITCH if size is 0.
868 if (size == 0) {
869 return 3;
870 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200871 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
Roland Levillain14d90572015-07-16 10:52:26 +0100872 DCHECK_ALIGNED(keys, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200873 const int32_t* entries = keys + size;
Roland Levillain14d90572015-07-16 10:52:26 +0100874 DCHECK_ALIGNED(entries, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200875 int lo = 0;
876 int hi = size - 1;
877 while (lo <= hi) {
878 int mid = (lo + hi) / 2;
879 int32_t foundVal = keys[mid];
880 if (test_val < foundVal) {
881 hi = mid - 1;
882 } else if (test_val > foundVal) {
883 lo = mid + 1;
884 } else {
885 return entries[mid];
886 }
887 }
888 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
889 return 3;
890}
891
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700892template <bool _do_check>
893static inline bool DoBoxLambda(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700894 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700895 /*
896 * box-lambda vA, vB /// opcode 0xf8, format 22x
897 * - vA is the target register where the Object representation of the closure will be stored into
898 * - vB is a closure (made by create-lambda)
899 * (also reads vB + 1)
900 */
901 uint32_t vreg_target_object = inst->VRegA_22x(inst_data);
902 uint32_t vreg_source_closure = inst->VRegB_22x();
903
Igor Murashkin6918bf12015-09-27 19:19:06 -0700904 lambda::Closure* lambda_closure = ReadLambdaClosureFromVRegsOrThrow(shadow_frame,
905 vreg_source_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700906
907 // Failed lambda target runtime check, an exception was raised.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700908 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700909 CHECK(self->IsExceptionPending());
910 return false;
911 }
912
Igor Murashkine2facc52015-07-10 13:49:08 -0700913 mirror::Object* closure_as_object =
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000914 Runtime::Current()->GetLambdaBoxTable()->BoxLambda(lambda_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700915
Igor Murashkine2facc52015-07-10 13:49:08 -0700916 // Failed to box the lambda, an exception was raised.
917 if (UNLIKELY(closure_as_object == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700918 CHECK(self->IsExceptionPending());
919 return false;
920 }
921
Igor Murashkine2facc52015-07-10 13:49:08 -0700922 shadow_frame.SetVRegReference(vreg_target_object, closure_as_object);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700923 return true;
924}
925
Mathieu Chartier90443472015-07-16 20:32:27 -0700926template <bool _do_check> SHARED_REQUIRES(Locks::mutator_lock_)
Igor Murashkine2facc52015-07-10 13:49:08 -0700927static inline bool DoUnboxLambda(Thread* self,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700928 ShadowFrame& shadow_frame,
929 const Instruction* inst,
930 uint16_t inst_data) {
931 /*
932 * unbox-lambda vA, vB, [type id] /// opcode 0xf9, format 22c
933 * - vA is the target register where the closure will be written into
934 * (also writes vA + 1)
935 * - vB is the Object representation of the closure (made by box-lambda)
936 */
937 uint32_t vreg_target_closure = inst->VRegA_22c(inst_data);
938 uint32_t vreg_source_object = inst->VRegB_22c();
939
940 // Raise NullPointerException if object is null
941 mirror::Object* boxed_closure_object = shadow_frame.GetVRegReference(vreg_source_object);
942 if (UNLIKELY(boxed_closure_object == nullptr)) {
943 ThrowNullPointerExceptionFromInterpreter();
944 return false;
945 }
946
Igor Murashkin6918bf12015-09-27 19:19:06 -0700947 lambda::Closure* unboxed_closure = nullptr;
Igor Murashkine2facc52015-07-10 13:49:08 -0700948 // Raise an exception if unboxing fails.
949 if (!Runtime::Current()->GetLambdaBoxTable()->UnboxLambda(boxed_closure_object,
Igor Murashkin6918bf12015-09-27 19:19:06 -0700950 /*out*/&unboxed_closure)) {
Igor Murashkine2facc52015-07-10 13:49:08 -0700951 CHECK(self->IsExceptionPending());
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700952 return false;
953 }
954
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700955 DCHECK(unboxed_closure != nullptr);
Igor Murashkin30c475a2015-10-06 13:59:43 -0700956 WriteLambdaClosureIntoVRegs(/*inout*/shadow_frame, *unboxed_closure, vreg_target_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700957 return true;
958}
959
Ian Rogers54874942014-06-10 16:31:03 -0700960uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertz9f102032014-05-23 08:59:42 +0200961 uint32_t dex_pc, const instrumentation::Instrumentation* instrumentation)
Mathieu Chartier90443472015-07-16 20:32:27 -0700962 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200963
Andreas Gampe794ad762015-02-23 08:12:24 -0800964NO_RETURN void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame)
965 __attribute__((cold))
Mathieu Chartier90443472015-07-16 20:32:27 -0700966 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200967
Serguei Katkov9fb0ac72016-02-20 12:55:24 +0600968static inline bool TraceExecutionEnabled() {
969 // Return true if you want TraceExecution invocation before each bytecode execution.
970 return false;
971}
972
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200973static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Ian Rogerse94652f2014-12-02 11:13:19 -0800974 const uint32_t dex_pc)
Mathieu Chartier90443472015-07-16 20:32:27 -0700975 SHARED_REQUIRES(Locks::mutator_lock_) {
Serguei Katkov9fb0ac72016-02-20 12:55:24 +0600976 if (TraceExecutionEnabled()) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200977#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700978 std::ostringstream oss;
979 oss << PrettyMethod(shadow_frame.GetMethod())
980 << StringPrintf("\n0x%x: ", dex_pc)
Ian Rogerse94652f2014-12-02 11:13:19 -0800981 << inst->DumpString(shadow_frame.GetMethod()->GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800982 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200983 uint32_t raw_value = shadow_frame.GetVReg(i);
984 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800985 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700986 if (ref_value != nullptr) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200987 if (ref_value->GetClass()->IsStringClass() &&
Jeff Hao848f70a2014-01-15 13:49:50 -0800988 ref_value->AsString()->GetValue() != nullptr) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700989 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200990 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700991 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200992 }
993 }
994 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700995 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200996#undef TRACE_LOG
997 }
998}
999
Sebastien Hertz1eda2262013-09-09 16:53:14 +02001000static inline bool IsBackwardBranch(int32_t branch_offset) {
1001 return branch_offset <= 0;
1002}
1003
Siva Chandra05d24152016-01-05 17:43:17 -08001004void ArtInterpreterToCompiledCodeBridge(Thread* self, const DexFile::CodeItem* code_item,
1005 ShadowFrame* shadow_frame, JValue* result);
1006
Sebastien Hertzc6714852013-09-30 16:42:32 +02001007// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001008#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001009 template SHARED_REQUIRES(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001010 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
1011 const Instruction* inst, uint16_t inst_data, \
1012 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +02001013
1014#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
1015 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
1016 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
1017 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
1018 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
1019
Andreas Gampec8ccf682014-09-29 20:07:43 -07001020EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic) // invoke-static/range.
1021EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect) // invoke-direct/range.
1022EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual) // invoke-virtual/range.
1023EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper) // invoke-super/range.
1024EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface) // invoke-interface/range.
Sebastien Hertzc6714852013-09-30 16:42:32 +02001025#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
1026#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
1027
Sebastien Hertzc6714852013-09-30 16:42:32 +02001028// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001029#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001030 template SHARED_REQUIRES(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001031 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
1032 const Instruction* inst, uint16_t inst_data, \
1033 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +02001034
1035EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
1036EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
1037#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
1038
Igor Murashkin158f35c2015-06-10 15:55:30 -07001039// Explicitly instantiate all DoCreateLambda functions.
Igor Murashkin6918bf12015-09-27 19:19:06 -07001040#define EXPLICIT_DO_CREATE_LAMBDA_DECL(_do_check) \
1041template SHARED_REQUIRES(Locks::mutator_lock_) \
1042bool DoCreateLambda<_do_check>(Thread* self, \
1043 const Instruction* inst, \
1044 /*inout*/ShadowFrame& shadow_frame, \
1045 /*inout*/lambda::ClosureBuilder* closure_builder, \
1046 /*inout*/lambda::Closure* uninitialized_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001047
1048EXPLICIT_DO_CREATE_LAMBDA_DECL(false); // create-lambda
1049EXPLICIT_DO_CREATE_LAMBDA_DECL(true); // create-lambda
1050#undef EXPLICIT_DO_CREATE_LAMBDA_DECL
1051
1052// Explicitly instantiate all DoInvokeLambda functions.
1053#define EXPLICIT_DO_INVOKE_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001054template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin158f35c2015-06-10 15:55:30 -07001055bool DoInvokeLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1056 uint16_t inst_data, JValue* result);
1057
1058EXPLICIT_DO_INVOKE_LAMBDA_DECL(false); // invoke-lambda
1059EXPLICIT_DO_INVOKE_LAMBDA_DECL(true); // invoke-lambda
1060#undef EXPLICIT_DO_INVOKE_LAMBDA_DECL
1061
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001062// Explicitly instantiate all DoBoxLambda functions.
1063#define EXPLICIT_DO_BOX_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001064template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001065bool DoBoxLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1066 uint16_t inst_data);
1067
1068EXPLICIT_DO_BOX_LAMBDA_DECL(false); // box-lambda
1069EXPLICIT_DO_BOX_LAMBDA_DECL(true); // box-lambda
1070#undef EXPLICIT_DO_BOX_LAMBDA_DECL
1071
1072// Explicitly instantiate all DoUnBoxLambda functions.
1073#define EXPLICIT_DO_UNBOX_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001074template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001075bool DoUnboxLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1076 uint16_t inst_data);
1077
1078EXPLICIT_DO_UNBOX_LAMBDA_DECL(false); // unbox-lambda
1079EXPLICIT_DO_UNBOX_LAMBDA_DECL(true); // unbox-lambda
1080#undef EXPLICIT_DO_BOX_LAMBDA_DECL
1081
Igor Murashkin6918bf12015-09-27 19:19:06 -07001082// Explicitly instantiate all DoCaptureVariable functions.
1083#define EXPLICIT_DO_CAPTURE_VARIABLE_DECL(_do_check) \
1084template SHARED_REQUIRES(Locks::mutator_lock_) \
1085bool DoCaptureVariable<_do_check>(Thread* self, \
1086 const Instruction* inst, \
1087 ShadowFrame& shadow_frame, \
1088 lambda::ClosureBuilder* closure_builder);
Sebastien Hertzc6714852013-09-30 16:42:32 +02001089
Igor Murashkin6918bf12015-09-27 19:19:06 -07001090EXPLICIT_DO_CAPTURE_VARIABLE_DECL(false); // capture-variable
1091EXPLICIT_DO_CAPTURE_VARIABLE_DECL(true); // capture-variable
1092#undef EXPLICIT_DO_CREATE_LAMBDA_DECL
1093
1094// Explicitly instantiate all DoLiberateVariable functions.
1095#define EXPLICIT_DO_LIBERATE_VARIABLE_DECL(_do_check) \
1096template SHARED_REQUIRES(Locks::mutator_lock_) \
1097bool DoLiberateVariable<_do_check>(Thread* self, \
1098 const Instruction* inst, \
1099 size_t captured_variable_index, \
1100 ShadowFrame& shadow_frame); \
1101
1102EXPLICIT_DO_LIBERATE_VARIABLE_DECL(false); // liberate-variable
1103EXPLICIT_DO_LIBERATE_VARIABLE_DECL(true); // liberate-variable
1104#undef EXPLICIT_DO_LIBERATE_LAMBDA_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001105} // namespace interpreter
1106} // namespace art
1107
1108#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_