blob: 69376fd7a170461d3977292455aa492e07aa6414 [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);
Andreas Gampe56fdd0e2016-04-28 14:56:54 -070098 if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) {
99 frame->GetLockCountData().AddMonitor(self, h_ref.Get());
100 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200101}
102
Andreas Gampe03ec9302015-08-27 17:41:47 -0700103template <bool kMonitorCounting>
104static inline void DoMonitorExit(Thread* self,
105 ShadowFrame* frame,
Mathieu Chartier2d096c92015-10-12 16:18:20 -0700106 Object* ref)
107 NO_THREAD_SAFETY_ANALYSIS
108 REQUIRES(!Roles::uninterruptible_) {
109 StackHandleScope<1> hs(self);
110 Handle<Object> h_ref(hs.NewHandle(ref));
111 h_ref->MonitorExit(self);
Andreas Gampe56fdd0e2016-04-28 14:56:54 -0700112 if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) {
113 frame->GetLockCountData().RemoveMonitorOrThrow(self, h_ref.Get());
114 }
115}
116
117template <bool kMonitorCounting>
118static inline bool DoMonitorCheckOnExit(Thread* self, ShadowFrame* frame)
119 NO_THREAD_SAFETY_ANALYSIS
120 REQUIRES(!Roles::uninterruptible_) {
121 if (kMonitorCounting && frame->GetMethod()->MustCountLocks()) {
122 return frame->GetLockCountData().CheckAllMonitorsReleasedOrThrow(self);
123 }
124 return true;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200125}
126
Sebastien Hertz45b15972015-04-03 16:07:05 +0200127void AbortTransactionF(Thread* self, const char* fmt, ...)
128 __attribute__((__format__(__printf__, 2, 3)))
Mathieu Chartier90443472015-07-16 20:32:27 -0700129 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz45b15972015-04-03 16:07:05 +0200130
131void AbortTransactionV(Thread* self, const char* fmt, va_list args)
Mathieu Chartier90443472015-07-16 20:32:27 -0700132 SHARED_REQUIRES(Locks::mutator_lock_);
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700133
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100134void RecordArrayElementsInTransaction(mirror::Array* array, int32_t count)
Mathieu Chartier90443472015-07-16 20:32:27 -0700135 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100136
Sebastien Hertzc6714852013-09-30 16:42:32 +0200137// Invokes the given method. This is part of the invocation support and is used by DoInvoke and
138// DoInvokeVirtualQuick functions.
139// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200140template<bool is_range, bool do_assignability_check>
Ian Rogerse94652f2014-12-02 11:13:19 -0800141bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200142 const Instruction* inst, uint16_t inst_data, JValue* result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200143
Igor Murashkin158f35c2015-06-10 15:55:30 -0700144// Invokes the given lambda closure. This is part of the invocation support and is used by
145// DoLambdaInvoke functions.
146// Returns true on success, otherwise throws an exception and returns false.
147template<bool is_range, bool do_assignability_check>
148bool DoLambdaCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
149 const Instruction* inst, uint16_t inst_data, JValue* result);
150
151// Validates that the art method corresponding to a lambda method target
152// is semantically valid:
153//
154// Must be ACC_STATIC and ACC_LAMBDA. Must be a concrete managed implementation
155// (i.e. not native, not proxy, not abstract, ...).
156//
157// If the validation fails, return false and raise an exception.
158static inline bool IsValidLambdaTargetOrThrow(ArtMethod* called_method)
Mathieu Chartier90443472015-07-16 20:32:27 -0700159 SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700160 bool success = false;
161
162 if (UNLIKELY(called_method == nullptr)) {
163 // The shadow frame should already be pushed, so we don't need to update it.
Alex Light9139e002015-10-09 15:59:48 -0700164 } else if (UNLIKELY(!called_method->IsInvokable())) {
165 called_method->ThrowInvocationTimeError();
166 // We got an error.
Igor Murashkin158f35c2015-06-10 15:55:30 -0700167 // TODO(iam): Also handle the case when the method is non-static, what error do we throw?
168 // TODO(iam): Also make sure that ACC_LAMBDA is set.
169 } else if (UNLIKELY(called_method->GetCodeItem() == nullptr)) {
170 // Method could be native, proxy method, etc. Lambda targets have to be concrete impls,
171 // so don't allow this.
172 } else {
173 success = true;
174 }
175
176 return success;
177}
178
Igor Murashkin6918bf12015-09-27 19:19:06 -0700179// Write out the 'Closure*' into vreg and vreg+1, as if it was a jlong.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700180static inline void WriteLambdaClosureIntoVRegs(ShadowFrame& shadow_frame,
Igor Murashkin30c475a2015-10-06 13:59:43 -0700181 const lambda::Closure& lambda_closure,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700182 uint32_t vreg) {
183 // 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 -0700184 uint32_t closure_lo = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&lambda_closure));
185 uint32_t closure_hi = static_cast<uint32_t>(reinterpret_cast<uint64_t>(&lambda_closure)
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700186 >> BitSizeOf<uint32_t>());
187 // Use uint64_t instead of uintptr_t to allow shifting past the max on 32-bit.
188 static_assert(sizeof(uint64_t) >= sizeof(uintptr_t), "Impossible");
189
Igor Murashkin6918bf12015-09-27 19:19:06 -0700190 DCHECK_NE(closure_lo | closure_hi, 0u);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700191
Igor Murashkin6918bf12015-09-27 19:19:06 -0700192 shadow_frame.SetVReg(vreg, closure_lo);
193 shadow_frame.SetVReg(vreg + 1, closure_hi);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700194}
195
Igor Murashkin158f35c2015-06-10 15:55:30 -0700196// Handles create-lambda instructions.
197// Returns true on success, otherwise throws an exception and returns false.
198// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
199//
Igor Murashkin6918bf12015-09-27 19:19:06 -0700200// The closure must be allocated big enough to hold the data, and should not be
201// pre-initialized. It is initialized with the actual captured variables as a side-effect,
202// although this should be unimportant to the caller since this function also handles storing it to
203// the ShadowFrame.
204//
Igor Murashkin158f35c2015-06-10 15:55:30 -0700205// As a work-in-progress implementation, this shoves the ArtMethod object corresponding
206// to the target dex method index into the target register vA and vA + 1.
207template<bool do_access_check>
Igor Murashkin6918bf12015-09-27 19:19:06 -0700208static inline bool DoCreateLambda(Thread* self,
209 const Instruction* inst,
210 /*inout*/ShadowFrame& shadow_frame,
211 /*inout*/lambda::ClosureBuilder* closure_builder,
212 /*inout*/lambda::Closure* uninitialized_closure) {
213 DCHECK(closure_builder != nullptr);
214 DCHECK(uninitialized_closure != nullptr);
215 DCHECK_ALIGNED(uninitialized_closure, alignof(lambda::Closure));
216
Igor Murashkin30c475a2015-10-06 13:59:43 -0700217 using lambda::ArtLambdaMethod;
218 using lambda::LeakingAllocator;
219
Igor Murashkin158f35c2015-06-10 15:55:30 -0700220 /*
221 * create-lambda is opcode 0x21c
222 * - vA is the target register where the closure will be stored into
223 * (also stores into vA + 1)
224 * - vB is the method index which will be the target for a later invoke-lambda
225 */
226 const uint32_t method_idx = inst->VRegB_21c();
227 mirror::Object* receiver = nullptr; // Always static. (see 'kStatic')
228 ArtMethod* sf_method = shadow_frame.GetMethod();
229 ArtMethod* const called_method = FindMethodFromCode<kStatic, do_access_check>(
Andreas Gampe3a357142015-08-07 17:20:11 -0700230 method_idx, &receiver, sf_method, self);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700231
Igor Murashkin6918bf12015-09-27 19:19:06 -0700232 uint32_t vreg_dest_closure = inst->VRegA_21c();
Igor Murashkin158f35c2015-06-10 15:55:30 -0700233
234 if (UNLIKELY(!IsValidLambdaTargetOrThrow(called_method))) {
235 CHECK(self->IsExceptionPending());
Igor Murashkin6918bf12015-09-27 19:19:06 -0700236 shadow_frame.SetVReg(vreg_dest_closure, 0u);
237 shadow_frame.SetVReg(vreg_dest_closure + 1, 0u);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700238 return false;
239 }
240
Igor Murashkin30c475a2015-10-06 13:59:43 -0700241 ArtLambdaMethod* initialized_lambda_method;
Igor Murashkin6918bf12015-09-27 19:19:06 -0700242 // Initialize the ArtLambdaMethod with the right data.
243 {
Igor Murashkin30c475a2015-10-06 13:59:43 -0700244 // Allocate enough memory to store a well-aligned ArtLambdaMethod.
245 // This is not the final type yet since the data starts out uninitialized.
246 LeakingAllocator::AlignedMemoryStorage<ArtLambdaMethod>* uninitialized_lambda_method =
247 LeakingAllocator::AllocateMemory<ArtLambdaMethod>(self);
Igor Murashkin6918bf12015-09-27 19:19:06 -0700248
249 std::string captured_variables_shorty = closure_builder->GetCapturedVariableShortyTypes();
250 std::string captured_variables_long_type_desc;
251
252 // Synthesize a long type descriptor from the short one.
253 for (char shorty : captured_variables_shorty) {
254 lambda::ShortyFieldType shorty_field_type(shorty);
255 if (shorty_field_type.IsObject()) {
256 // Not the true type, but good enough until we implement verifier support.
257 captured_variables_long_type_desc += "Ljava/lang/Object;";
258 UNIMPLEMENTED(FATAL) << "create-lambda with an object captured variable";
259 } else if (shorty_field_type.IsLambda()) {
260 // Not the true type, but good enough until we implement verifier support.
261 captured_variables_long_type_desc += "Ljava/lang/Runnable;";
262 UNIMPLEMENTED(FATAL) << "create-lambda with a lambda captured variable";
263 } else {
264 // The primitive types have the same length shorty or not, so this is always correct.
265 DCHECK(shorty_field_type.IsPrimitive());
266 captured_variables_long_type_desc += shorty_field_type;
267 }
268 }
269
270 // Copy strings to dynamically allocated storage. This leaks, but that's ok. Fix it later.
271 // TODO: Strings need to come from the DexFile, so they won't need their own allocations.
Igor Murashkin30c475a2015-10-06 13:59:43 -0700272 char* captured_variables_type_desc = LeakingAllocator::MakeFlexibleInstance<char>(
Igor Murashkin6918bf12015-09-27 19:19:06 -0700273 self,
274 captured_variables_long_type_desc.size() + 1);
275 strcpy(captured_variables_type_desc, captured_variables_long_type_desc.c_str());
Igor Murashkin30c475a2015-10-06 13:59:43 -0700276 char* captured_variables_shorty_copy = LeakingAllocator::MakeFlexibleInstance<char>(
Igor Murashkin6918bf12015-09-27 19:19:06 -0700277 self,
278 captured_variables_shorty.size() + 1);
279 strcpy(captured_variables_shorty_copy, captured_variables_shorty.c_str());
280
Igor Murashkin30c475a2015-10-06 13:59:43 -0700281 // After initialization, the object at the storage is well-typed. Use strong type going forward.
282 initialized_lambda_method =
283 new (uninitialized_lambda_method) ArtLambdaMethod(called_method,
284 captured_variables_type_desc,
285 captured_variables_shorty_copy,
286 true); // innate lambda
Igor Murashkin6918bf12015-09-27 19:19:06 -0700287 }
288
289 // Write all the closure captured variables and the closure header into the closure.
Igor Murashkin30c475a2015-10-06 13:59:43 -0700290 lambda::Closure* initialized_closure =
291 closure_builder->CreateInPlace(uninitialized_closure, initialized_lambda_method);
Igor Murashkin6918bf12015-09-27 19:19:06 -0700292
Igor Murashkin30c475a2015-10-06 13:59:43 -0700293 WriteLambdaClosureIntoVRegs(/*inout*/shadow_frame, *initialized_closure, vreg_dest_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700294 return true;
295}
296
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700297// Reads out the 'ArtMethod*' stored inside of vreg and vreg+1
298//
299// Validates that the art method points to a valid lambda function, otherwise throws
300// an exception and returns null.
301// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
Igor Murashkin6918bf12015-09-27 19:19:06 -0700302static inline lambda::Closure* ReadLambdaClosureFromVRegsOrThrow(ShadowFrame& shadow_frame,
303 uint32_t vreg)
Mathieu Chartier90443472015-07-16 20:32:27 -0700304 SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin6918bf12015-09-27 19:19:06 -0700305 // Lambda closures take up a consecutive pair of 2 virtual registers.
306 // On 32-bit the high bits are always 0.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700307 uint32_t vc_value_lo = shadow_frame.GetVReg(vreg);
308 uint32_t vc_value_hi = shadow_frame.GetVReg(vreg + 1);
309
310 uint64_t vc_value_ptr = (static_cast<uint64_t>(vc_value_hi) << BitSizeOf<uint32_t>())
311 | vc_value_lo;
312
313 // Use uint64_t instead of uintptr_t to allow left-shifting past the max on 32-bit.
314 static_assert(sizeof(uint64_t) >= sizeof(uintptr_t), "Impossible");
Igor Murashkin6918bf12015-09-27 19:19:06 -0700315 lambda::Closure* const lambda_closure = reinterpret_cast<lambda::Closure*>(vc_value_ptr);
316 DCHECK_ALIGNED(lambda_closure, alignof(lambda::Closure));
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700317
318 // Guard against the user passing a null closure, which is odd but (sadly) semantically valid.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700319 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700320 ThrowNullPointerExceptionFromInterpreter();
321 return nullptr;
Igor Murashkin6918bf12015-09-27 19:19:06 -0700322 } else if (UNLIKELY(!IsValidLambdaTargetOrThrow(lambda_closure->GetTargetMethod()))) {
323 // Sanity check against data corruption.
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700324 return nullptr;
325 }
326
Igor Murashkin6918bf12015-09-27 19:19:06 -0700327 return lambda_closure;
328}
329
330// Forward declaration for lock annotations. See below for documentation.
331template <bool do_access_check>
332static inline const char* GetStringDataByDexStringIndexOrThrow(ShadowFrame& shadow_frame,
333 uint32_t string_idx)
334 SHARED_REQUIRES(Locks::mutator_lock_);
335
336// Find the c-string data corresponding to a dex file's string index.
337// Otherwise, returns null if not found and throws a VerifyError.
338//
339// Note that with do_access_check=false, we never return null because the verifier
340// must guard against invalid string indices.
341// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
342template <bool do_access_check>
343static inline const char* GetStringDataByDexStringIndexOrThrow(ShadowFrame& shadow_frame,
344 uint32_t string_idx) {
345 ArtMethod* method = shadow_frame.GetMethod();
346 const DexFile* dex_file = method->GetDexFile();
347
348 mirror::Class* declaring_class = method->GetDeclaringClass();
349 if (!do_access_check) {
350 // MethodVerifier refuses methods with string_idx out of bounds.
351 DCHECK_LT(string_idx, declaring_class->GetDexCache()->NumStrings());
352 } else {
353 // Access checks enabled: perform string index bounds ourselves.
354 if (string_idx >= dex_file->GetHeader().string_ids_size_) {
355 ThrowVerifyError(declaring_class, "String index '%" PRIu32 "' out of bounds",
356 string_idx);
357 return nullptr;
358 }
359 }
360
361 const char* type_string = dex_file->StringDataByIdx(string_idx);
362
363 if (UNLIKELY(type_string == nullptr)) {
364 CHECK_EQ(false, do_access_check)
365 << " verifier should've caught invalid string index " << string_idx;
366 CHECK_EQ(true, do_access_check)
367 << " string idx size check should've caught invalid string index " << string_idx;
368 }
369
370 return type_string;
371}
372
373// Handles capture-variable instructions.
374// Returns true on success, otherwise throws an exception and returns false.
375// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
376template<bool do_access_check>
377static inline bool DoCaptureVariable(Thread* self,
378 const Instruction* inst,
379 /*inout*/ShadowFrame& shadow_frame,
380 /*inout*/lambda::ClosureBuilder* closure_builder) {
381 DCHECK(closure_builder != nullptr);
382 using lambda::ShortyFieldType;
383 /*
384 * capture-variable is opcode 0xf6, fmt 0x21c
385 * - vA is the source register of the variable that will be captured
386 * - vB is the string ID of the variable's type that will be captured
387 */
388 const uint32_t source_vreg = inst->VRegA_21c();
389 const uint32_t string_idx = inst->VRegB_21c();
390 // TODO: this should be a proper [type id] instead of a [string ID] pointing to a type.
391
392 const char* type_string = GetStringDataByDexStringIndexOrThrow<do_access_check>(shadow_frame,
393 string_idx);
394 if (UNLIKELY(type_string == nullptr)) {
395 CHECK(self->IsExceptionPending());
396 return false;
397 }
398
399 char type_first_letter = type_string[0];
400 ShortyFieldType shorty_type;
401 if (do_access_check &&
402 UNLIKELY(!ShortyFieldType::MaybeCreate(type_first_letter, /*out*/&shorty_type))) { // NOLINT: [whitespace/comma] [3]
403 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
404 "capture-variable vB must be a valid type");
405 return false;
406 } else {
407 // Already verified that the type is valid.
408 shorty_type = ShortyFieldType(type_first_letter);
409 }
410
411 const size_t captured_variable_count = closure_builder->GetCaptureCount();
412
413 // Note: types are specified explicitly so that the closure is packed tightly.
414 switch (shorty_type) {
415 case ShortyFieldType::kBoolean: {
416 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
417 closure_builder->CaptureVariablePrimitive<bool>(primitive_narrow_value);
418 break;
419 }
420 case ShortyFieldType::kByte: {
421 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
422 closure_builder->CaptureVariablePrimitive<int8_t>(primitive_narrow_value);
423 break;
424 }
425 case ShortyFieldType::kChar: {
426 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
427 closure_builder->CaptureVariablePrimitive<uint16_t>(primitive_narrow_value);
428 break;
429 }
430 case ShortyFieldType::kShort: {
431 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
432 closure_builder->CaptureVariablePrimitive<int16_t>(primitive_narrow_value);
433 break;
434 }
435 case ShortyFieldType::kInt: {
436 uint32_t primitive_narrow_value = shadow_frame.GetVReg(source_vreg);
437 closure_builder->CaptureVariablePrimitive<int32_t>(primitive_narrow_value);
438 break;
439 }
440 case ShortyFieldType::kDouble: {
441 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegDouble(source_vreg));
442 break;
443 }
444 case ShortyFieldType::kFloat: {
445 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegFloat(source_vreg));
446 break;
447 }
448 case ShortyFieldType::kLambda: {
449 UNIMPLEMENTED(FATAL) << " capture-variable with type kLambda";
450 // TODO: Capturing lambdas recursively will be done at a later time.
451 UNREACHABLE();
452 }
453 case ShortyFieldType::kLong: {
454 closure_builder->CaptureVariablePrimitive(shadow_frame.GetVRegLong(source_vreg));
455 break;
456 }
457 case ShortyFieldType::kObject: {
458 closure_builder->CaptureVariableObject(shadow_frame.GetVRegReference(source_vreg));
459 UNIMPLEMENTED(FATAL) << " capture-variable with type kObject";
460 // TODO: finish implementing this. disabled for now since we can't track lambda refs for GC.
461 UNREACHABLE();
462 }
463
464 default:
465 LOG(FATAL) << "Invalid shorty type value " << shorty_type;
466 UNREACHABLE();
467 }
468
469 DCHECK_EQ(captured_variable_count + 1, closure_builder->GetCaptureCount());
470
471 return true;
472}
473
474// Handles capture-variable instructions.
475// Returns true on success, otherwise throws an exception and returns false.
476// (Exceptions are thrown by creating a new exception and then being put in the thread TLS)
477template<bool do_access_check>
478static inline bool DoLiberateVariable(Thread* self,
479 const Instruction* inst,
480 size_t captured_variable_index,
481 /*inout*/ShadowFrame& shadow_frame) {
482 using lambda::ShortyFieldType;
483 /*
484 * liberate-variable is opcode 0xf7, fmt 0x22c
485 * - vA is the destination register
486 * - vB is the register with the lambda closure in it
487 * - vC is the string ID which needs to be a valid field type descriptor
488 */
489
490 const uint32_t dest_vreg = inst->VRegA_22c();
491 const uint32_t closure_vreg = inst->VRegB_22c();
492 const uint32_t string_idx = inst->VRegC_22c();
493 // TODO: this should be a proper [type id] instead of a [string ID] pointing to a type.
494
495
496 // Synthesize a long type descriptor from a shorty type descriptor list.
497 // TODO: Fix the dex encoding to contain the long and short type descriptors.
498 const char* type_string = GetStringDataByDexStringIndexOrThrow<do_access_check>(shadow_frame,
499 string_idx);
500 if (UNLIKELY(do_access_check && type_string == nullptr)) {
501 CHECK(self->IsExceptionPending());
502 shadow_frame.SetVReg(dest_vreg, 0);
503 return false;
504 }
505
506 char type_first_letter = type_string[0];
507 ShortyFieldType shorty_type;
508 if (do_access_check &&
509 UNLIKELY(!ShortyFieldType::MaybeCreate(type_first_letter, /*out*/&shorty_type))) { // NOLINT: [whitespace/comma] [3]
510 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
511 "liberate-variable vC must be a valid type");
512 shadow_frame.SetVReg(dest_vreg, 0);
513 return false;
514 } else {
515 // Already verified that the type is valid.
516 shorty_type = ShortyFieldType(type_first_letter);
517 }
518
519 // Check for closure being null *after* the type check.
520 // This way we can access the type info in case we fail later, to know how many vregs to clear.
521 const lambda::Closure* lambda_closure =
522 ReadLambdaClosureFromVRegsOrThrow(/*inout*/shadow_frame, closure_vreg);
523
524 // Failed lambda target runtime check, an exception was raised.
525 if (UNLIKELY(lambda_closure == nullptr)) {
526 CHECK(self->IsExceptionPending());
527
528 // Clear the destination vreg(s) to be safe.
529 shadow_frame.SetVReg(dest_vreg, 0);
530 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
531 shadow_frame.SetVReg(dest_vreg + 1, 0);
532 }
533 return false;
534 }
535
536 if (do_access_check &&
537 UNLIKELY(captured_variable_index >= lambda_closure->GetNumberOfCapturedVariables())) {
538 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
539 "liberate-variable captured variable index %zu out of bounds",
540 lambda_closure->GetNumberOfCapturedVariables());
541 // Clear the destination vreg(s) to be safe.
542 shadow_frame.SetVReg(dest_vreg, 0);
543 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
544 shadow_frame.SetVReg(dest_vreg + 1, 0);
545 }
546 return false;
547 }
548
549 // Verify that the runtime type of the captured-variable matches the requested dex type.
550 if (do_access_check) {
551 ShortyFieldType actual_type = lambda_closure->GetCapturedShortyType(captured_variable_index);
552 if (actual_type != shorty_type) {
553 ThrowVerifyError(shadow_frame.GetMethod()->GetDeclaringClass(),
554 "cannot liberate-variable of runtime type '%c' to dex type '%c'",
555 static_cast<char>(actual_type),
556 static_cast<char>(shorty_type));
557
558 shadow_frame.SetVReg(dest_vreg, 0);
559 if (shorty_type.IsPrimitiveWide() || shorty_type.IsLambda()) {
560 shadow_frame.SetVReg(dest_vreg + 1, 0);
561 }
562 return false;
563 }
564
565 if (actual_type.IsLambda() || actual_type.IsObject()) {
566 UNIMPLEMENTED(FATAL) << "liberate-variable type checks needs to "
567 << "parse full type descriptor for objects and lambdas";
568 }
569 }
570
571 // Unpack the captured variable from the closure into the correct type, then save it to the vreg.
572 if (shorty_type.IsPrimitiveNarrow()) {
573 uint32_t primitive_narrow_value =
574 lambda_closure->GetCapturedPrimitiveNarrow(captured_variable_index);
575 shadow_frame.SetVReg(dest_vreg, primitive_narrow_value);
576 } else if (shorty_type.IsPrimitiveWide()) {
577 uint64_t primitive_wide_value =
578 lambda_closure->GetCapturedPrimitiveWide(captured_variable_index);
579 shadow_frame.SetVRegLong(dest_vreg, static_cast<int64_t>(primitive_wide_value));
580 } else if (shorty_type.IsObject()) {
581 mirror::Object* unpacked_object =
582 lambda_closure->GetCapturedObject(captured_variable_index);
583 shadow_frame.SetVRegReference(dest_vreg, unpacked_object);
584
585 UNIMPLEMENTED(FATAL) << "liberate-variable cannot unpack objects yet";
586 } else if (shorty_type.IsLambda()) {
587 UNIMPLEMENTED(FATAL) << "liberate-variable cannot unpack lambdas yet";
588 } else {
589 LOG(FATAL) << "unreachable";
590 UNREACHABLE();
591 }
592
593 return true;
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700594}
595
Igor Murashkin158f35c2015-06-10 15:55:30 -0700596template<bool do_access_check>
597static inline bool DoInvokeLambda(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
598 uint16_t inst_data, JValue* result) {
599 /*
600 * invoke-lambda is opcode 0x25
601 *
602 * - vC is the closure register (both vC and vC + 1 will be used to store the closure).
603 * - vB is the number of additional registers up to |{vD,vE,vF,vG}| (4)
604 * - the rest of the registers are always var-args
605 *
606 * - reading var-args for 0x25 gets us vD,vE,vF,vG (but not vB)
607 */
Igor Murashkin6918bf12015-09-27 19:19:06 -0700608 uint32_t vreg_closure = inst->VRegC_25x();
609 const lambda::Closure* lambda_closure =
610 ReadLambdaClosureFromVRegsOrThrow(shadow_frame, vreg_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700611
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700612 // Failed lambda target runtime check, an exception was raised.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700613 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin158f35c2015-06-10 15:55:30 -0700614 CHECK(self->IsExceptionPending());
615 result->SetJ(0);
616 return false;
Igor Murashkin158f35c2015-06-10 15:55:30 -0700617 }
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700618
Igor Murashkin6918bf12015-09-27 19:19:06 -0700619 ArtMethod* const called_method = lambda_closure->GetTargetMethod();
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700620 // Invoke a non-range lambda
621 return DoLambdaCall<false, do_access_check>(called_method, self, shadow_frame, inst, inst_data,
622 result);
Igor Murashkin158f35c2015-06-10 15:55:30 -0700623}
624
Igor Murashkin6918bf12015-09-27 19:19:06 -0700625// Handles invoke-XXX/range instructions (other than invoke-lambda[-range]).
Sebastien Hertzc6714852013-09-30 16:42:32 +0200626// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200627template<InvokeType type, bool is_range, bool do_access_check>
628static inline bool DoInvoke(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
629 uint16_t inst_data, JValue* result) {
630 const uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
631 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700632 Object* receiver = (type == kStatic) ? nullptr : shadow_frame.GetVRegReference(vregC);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700633 ArtMethod* sf_method = shadow_frame.GetMethod();
Ian Rogerse94652f2014-12-02 11:13:19 -0800634 ArtMethod* const called_method = FindMethodFromCode<type, do_access_check>(
Andreas Gampe3a357142015-08-07 17:20:11 -0700635 method_idx, &receiver, sf_method, self);
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700636 // The shadow frame should already be pushed, so we don't need to update it.
Ian Rogerse94652f2014-12-02 11:13:19 -0800637 if (UNLIKELY(called_method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200638 CHECK(self->IsExceptionPending());
639 result->SetJ(0);
640 return false;
Alex Light9139e002015-10-09 15:59:48 -0700641 } else if (UNLIKELY(!called_method->IsInvokable())) {
642 called_method->ThrowInvocationTimeError();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200643 result->SetJ(0);
644 return false;
645 } else {
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100646 jit::Jit* jit = Runtime::Current()->GetJit();
647 if (jit != nullptr) {
648 if (type == kVirtual || type == kInterface) {
649 jit->InvokeVirtualOrInterface(
650 self, receiver, sf_method, shadow_frame.GetDexPC(), called_method);
651 }
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100652 jit->AddSamples(self, sf_method, 1, /*with_backedges*/false);
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100653 }
654 // TODO: Remove the InvokeVirtualOrInterface instrumentation, as it was only used by the JIT.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100655 if (type == kVirtual || type == kInterface) {
656 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
657 if (UNLIKELY(instrumentation->HasInvokeVirtualOrInterfaceListeners())) {
658 instrumentation->InvokeVirtualOrInterface(
659 self, receiver, sf_method, shadow_frame.GetDexPC(), called_method);
660 }
661 }
Ian Rogerse94652f2014-12-02 11:13:19 -0800662 return DoCall<is_range, do_access_check>(called_method, self, shadow_frame, inst, inst_data,
663 result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200664 }
665}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200666
Sebastien Hertzc6714852013-09-30 16:42:32 +0200667// Handles invoke-virtual-quick and invoke-virtual-quick-range instructions.
668// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200669template<bool is_range>
670static inline bool DoInvokeVirtualQuick(Thread* self, ShadowFrame& shadow_frame,
671 const Instruction* inst, uint16_t inst_data,
672 JValue* result) {
673 const uint32_t vregC = (is_range) ? inst->VRegC_3rc() : inst->VRegC_35c();
674 Object* const receiver = shadow_frame.GetVRegReference(vregC);
Sebastien Hertzd4beb6b2013-10-02 17:07:20 +0200675 if (UNLIKELY(receiver == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200676 // We lost the reference to the method index so we cannot get a more
677 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000678 ThrowNullPointerExceptionFromDexPC();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200679 return false;
680 }
681 const uint32_t vtable_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c();
Mingyao Yang2cdbad72014-07-16 10:44:41 -0700682 CHECK(receiver->GetClass()->ShouldHaveEmbeddedImtAndVTable());
Mathieu Chartiere401d142015-04-22 13:56:20 -0700683 ArtMethod* const called_method = receiver->GetClass()->GetEmbeddedVTableEntry(
684 vtable_idx, sizeof(void*));
Ian Rogerse94652f2014-12-02 11:13:19 -0800685 if (UNLIKELY(called_method == nullptr)) {
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200686 CHECK(self->IsExceptionPending());
687 result->SetJ(0);
688 return false;
Alex Light9139e002015-10-09 15:59:48 -0700689 } else if (UNLIKELY(!called_method->IsInvokable())) {
690 called_method->ThrowInvocationTimeError();
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200691 result->SetJ(0);
692 return false;
693 } else {
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100694 jit::Jit* jit = Runtime::Current()->GetJit();
695 if (jit != nullptr) {
696 jit->InvokeVirtualOrInterface(
697 self, receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100698 jit->AddSamples(self, shadow_frame.GetMethod(), 1, /*with_backedges*/false);
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100699 }
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100700 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Nicolas Geoffray274fe4a2016-04-12 16:33:24 +0100701 // TODO: Remove the InvokeVirtualOrInterface instrumentation, as it was only used by the JIT.
Nicolas Geoffray5550ca82015-08-21 18:38:30 +0100702 if (UNLIKELY(instrumentation->HasInvokeVirtualOrInterfaceListeners())) {
703 instrumentation->InvokeVirtualOrInterface(
704 self, receiver, shadow_frame.GetMethod(), shadow_frame.GetDexPC(), called_method);
705 }
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200706 // No need to check since we've been quickened.
Ian Rogerse94652f2014-12-02 11:13:19 -0800707 return DoCall<is_range, false>(called_method, self, shadow_frame, inst, inst_data, result);
Sebastien Hertzc61124b2013-09-10 11:44:19 +0200708 }
709}
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200710
Sebastien Hertzc6714852013-09-30 16:42:32 +0200711// Handles iget-XXX and sget-XXX instructions.
712// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200713template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check>
Ian Rogers54874942014-06-10 16:31:03 -0700714bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700715 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200716
Sebastien Hertzc6714852013-09-30 16:42:32 +0200717// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
718// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200719template<Primitive::Type field_type>
Ian Rogers54874942014-06-10 16:31:03 -0700720bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700721 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz479fc1e2014-04-04 17:51:34 +0200722
Sebastien Hertzc6714852013-09-30 16:42:32 +0200723// Handles iput-XXX and sput-XXX instructions.
724// Returns true on success, otherwise throws an exception and returns false.
Ian Rogers54874942014-06-10 16:31:03 -0700725template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
726 bool transaction_active>
727bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700728 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200729
Sebastien Hertzc6714852013-09-30 16:42:32 +0200730// Handles iput-quick, iput-wide-quick and iput-object-quick instructions.
731// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100732template<Primitive::Type field_type, bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -0700733bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700734 SHARED_REQUIRES(Locks::mutator_lock_);
Ian Rogers54874942014-06-10 16:31:03 -0700735
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200736
Sebastien Hertzc6714852013-09-30 16:42:32 +0200737// Handles string resolution for const-string and const-string-jumbo instructions. Also ensures the
738// java.lang.String class is initialized.
Ian Rogers6786a582014-10-28 12:49:06 -0700739static inline String* ResolveString(Thread* self, ShadowFrame& shadow_frame, uint32_t string_idx)
Mathieu Chartier90443472015-07-16 20:32:27 -0700740 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200741 Class* java_lang_string_class = String::GetJavaLangString();
742 if (UNLIKELY(!java_lang_string_class->IsInitialized())) {
743 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700744 StackHandleScope<1> hs(self);
745 Handle<mirror::Class> h_class(hs.NewHandle(java_lang_string_class));
Ian Rogers7b078e82014-09-10 14:44:24 -0700746 if (UNLIKELY(!class_linker->EnsureInitialized(self, h_class, true, true))) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200747 DCHECK(self->IsExceptionPending());
Mathieu Chartierc528dba2013-11-26 12:00:11 -0800748 return nullptr;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200749 }
750 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700751 ArtMethod* method = shadow_frame.GetMethod();
Mathieu Chartiereace4582014-11-24 18:29:54 -0800752 mirror::Class* declaring_class = method->GetDeclaringClass();
Vladimir Marko05792b92015-08-03 11:56:49 +0100753 // MethodVerifier refuses methods with string_idx out of bounds.
754 DCHECK_LT(string_idx, declaring_class->GetDexCache()->NumStrings());
755 mirror::String* s = declaring_class->GetDexCacheStrings()[string_idx].Read();
Ian Rogers6786a582014-10-28 12:49:06 -0700756 if (UNLIKELY(s == nullptr)) {
757 StackHandleScope<1> hs(self);
Mathieu Chartiereace4582014-11-24 18:29:54 -0800758 Handle<mirror::DexCache> dex_cache(hs.NewHandle(declaring_class->GetDexCache()));
Ian Rogers6786a582014-10-28 12:49:06 -0700759 s = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), string_idx,
760 dex_cache);
761 }
762 return s;
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200763}
764
Sebastien Hertzc6714852013-09-30 16:42:32 +0200765// Handles div-int, div-int/2addr, div-int/li16 and div-int/lit8 instructions.
766// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200767static inline bool DoIntDivide(ShadowFrame& shadow_frame, size_t result_reg,
768 int32_t dividend, int32_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700769 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersf72a11d2014-10-30 15:41:08 -0700770 constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200771 if (UNLIKELY(divisor == 0)) {
772 ThrowArithmeticExceptionDivideByZero();
773 return false;
774 }
775 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
776 shadow_frame.SetVReg(result_reg, kMinInt);
777 } else {
778 shadow_frame.SetVReg(result_reg, dividend / divisor);
779 }
780 return true;
781}
782
Sebastien Hertzc6714852013-09-30 16:42:32 +0200783// Handles rem-int, rem-int/2addr, rem-int/li16 and rem-int/lit8 instructions.
784// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200785static inline bool DoIntRemainder(ShadowFrame& shadow_frame, size_t result_reg,
786 int32_t dividend, int32_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700787 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogersf72a11d2014-10-30 15:41:08 -0700788 constexpr int32_t kMinInt = std::numeric_limits<int32_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200789 if (UNLIKELY(divisor == 0)) {
790 ThrowArithmeticExceptionDivideByZero();
791 return false;
792 }
793 if (UNLIKELY(dividend == kMinInt && divisor == -1)) {
794 shadow_frame.SetVReg(result_reg, 0);
795 } else {
796 shadow_frame.SetVReg(result_reg, dividend % divisor);
797 }
798 return true;
799}
800
Sebastien Hertzc6714852013-09-30 16:42:32 +0200801// Handles div-long and div-long-2addr instructions.
802// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200803static inline bool DoLongDivide(ShadowFrame& shadow_frame, size_t result_reg,
804 int64_t dividend, int64_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700805 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700806 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200807 if (UNLIKELY(divisor == 0)) {
808 ThrowArithmeticExceptionDivideByZero();
809 return false;
810 }
811 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
812 shadow_frame.SetVRegLong(result_reg, kMinLong);
813 } else {
814 shadow_frame.SetVRegLong(result_reg, dividend / divisor);
815 }
816 return true;
817}
818
Sebastien Hertzc6714852013-09-30 16:42:32 +0200819// Handles rem-long and rem-long-2addr instructions.
820// Returns true on success, otherwise throws a java.lang.ArithmeticException and return false.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200821static inline bool DoLongRemainder(ShadowFrame& shadow_frame, size_t result_reg,
822 int64_t dividend, int64_t divisor)
Mathieu Chartier90443472015-07-16 20:32:27 -0700823 SHARED_REQUIRES(Locks::mutator_lock_) {
Ian Rogers2e2deeb2013-09-23 11:58:57 -0700824 const int64_t kMinLong = std::numeric_limits<int64_t>::min();
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200825 if (UNLIKELY(divisor == 0)) {
826 ThrowArithmeticExceptionDivideByZero();
827 return false;
828 }
829 if (UNLIKELY(dividend == kMinLong && divisor == -1)) {
830 shadow_frame.SetVRegLong(result_reg, 0);
831 } else {
832 shadow_frame.SetVRegLong(result_reg, dividend % divisor);
833 }
834 return true;
835}
836
Sebastien Hertzc6714852013-09-30 16:42:32 +0200837// Handles filled-new-array and filled-new-array-range instructions.
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200838// Returns true on success, otherwise throws an exception and returns false.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +0100839template <bool is_range, bool do_access_check, bool transaction_active>
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200840bool DoFilledNewArray(const Instruction* inst, const ShadowFrame& shadow_frame,
Sebastien Hertzc6714852013-09-30 16:42:32 +0200841 Thread* self, JValue* result);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200842
Sebastien Hertzc6714852013-09-30 16:42:32 +0200843// Handles packed-switch instruction.
844// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200845static inline int32_t DoPackedSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
846 uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700847 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200848 DCHECK(inst->Opcode() == Instruction::PACKED_SWITCH);
849 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200850 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200851 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kPackedSwitchSignature));
852 uint16_t size = switch_data[1];
David Brazdil2ef645b2015-06-17 18:20:52 +0100853 if (size == 0) {
854 // Empty packed switch, move forward by 3 (size of PACKED_SWITCH).
855 return 3;
856 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200857 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
Roland Levillain14d90572015-07-16 10:52:26 +0100858 DCHECK_ALIGNED(keys, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200859 int32_t first_key = keys[0];
860 const int32_t* targets = reinterpret_cast<const int32_t*>(&switch_data[4]);
Roland Levillain14d90572015-07-16 10:52:26 +0100861 DCHECK_ALIGNED(targets, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200862 int32_t index = test_val - first_key;
863 if (index >= 0 && index < size) {
864 return targets[index];
865 } else {
866 // No corresponding value: move forward by 3 (size of PACKED_SWITCH).
867 return 3;
868 }
869}
870
Sebastien Hertzc6714852013-09-30 16:42:32 +0200871// Handles sparse-switch instruction.
872// Returns the branch offset to the next instruction to execute.
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200873static inline int32_t DoSparseSwitch(const Instruction* inst, const ShadowFrame& shadow_frame,
874 uint16_t inst_data)
Mathieu Chartier90443472015-07-16 20:32:27 -0700875 SHARED_REQUIRES(Locks::mutator_lock_) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200876 DCHECK(inst->Opcode() == Instruction::SPARSE_SWITCH);
877 const uint16_t* switch_data = reinterpret_cast<const uint16_t*>(inst) + inst->VRegB_31t();
Sebastien Hertz3b588e02013-09-11 14:33:18 +0200878 int32_t test_val = shadow_frame.GetVReg(inst->VRegA_31t(inst_data));
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200879 DCHECK_EQ(switch_data[0], static_cast<uint16_t>(Instruction::kSparseSwitchSignature));
880 uint16_t size = switch_data[1];
Jeff Hao935e01a2015-03-20 19:44:35 -0700881 // Return length of SPARSE_SWITCH if size is 0.
882 if (size == 0) {
883 return 3;
884 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200885 const int32_t* keys = reinterpret_cast<const int32_t*>(&switch_data[2]);
Roland Levillain14d90572015-07-16 10:52:26 +0100886 DCHECK_ALIGNED(keys, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200887 const int32_t* entries = keys + size;
Roland Levillain14d90572015-07-16 10:52:26 +0100888 DCHECK_ALIGNED(entries, 4);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200889 int lo = 0;
890 int hi = size - 1;
891 while (lo <= hi) {
892 int mid = (lo + hi) / 2;
893 int32_t foundVal = keys[mid];
894 if (test_val < foundVal) {
895 hi = mid - 1;
896 } else if (test_val > foundVal) {
897 lo = mid + 1;
898 } else {
899 return entries[mid];
900 }
901 }
902 // No corresponding value: move forward by 3 (size of SPARSE_SWITCH).
903 return 3;
904}
905
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700906template <bool _do_check>
907static inline bool DoBoxLambda(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
Mathieu Chartier90443472015-07-16 20:32:27 -0700908 uint16_t inst_data) SHARED_REQUIRES(Locks::mutator_lock_) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700909 /*
910 * box-lambda vA, vB /// opcode 0xf8, format 22x
911 * - vA is the target register where the Object representation of the closure will be stored into
912 * - vB is a closure (made by create-lambda)
913 * (also reads vB + 1)
914 */
915 uint32_t vreg_target_object = inst->VRegA_22x(inst_data);
916 uint32_t vreg_source_closure = inst->VRegB_22x();
917
Igor Murashkin6918bf12015-09-27 19:19:06 -0700918 lambda::Closure* lambda_closure = ReadLambdaClosureFromVRegsOrThrow(shadow_frame,
919 vreg_source_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700920
921 // Failed lambda target runtime check, an exception was raised.
Igor Murashkin6918bf12015-09-27 19:19:06 -0700922 if (UNLIKELY(lambda_closure == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700923 CHECK(self->IsExceptionPending());
924 return false;
925 }
926
Igor Murashkine2facc52015-07-10 13:49:08 -0700927 mirror::Object* closure_as_object =
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000928 Runtime::Current()->GetLambdaBoxTable()->BoxLambda(lambda_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700929
Igor Murashkine2facc52015-07-10 13:49:08 -0700930 // Failed to box the lambda, an exception was raised.
931 if (UNLIKELY(closure_as_object == nullptr)) {
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700932 CHECK(self->IsExceptionPending());
933 return false;
934 }
935
Igor Murashkine2facc52015-07-10 13:49:08 -0700936 shadow_frame.SetVRegReference(vreg_target_object, closure_as_object);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700937 return true;
938}
939
Mathieu Chartier90443472015-07-16 20:32:27 -0700940template <bool _do_check> SHARED_REQUIRES(Locks::mutator_lock_)
Igor Murashkine2facc52015-07-10 13:49:08 -0700941static inline bool DoUnboxLambda(Thread* self,
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700942 ShadowFrame& shadow_frame,
943 const Instruction* inst,
944 uint16_t inst_data) {
945 /*
946 * unbox-lambda vA, vB, [type id] /// opcode 0xf9, format 22c
947 * - vA is the target register where the closure will be written into
948 * (also writes vA + 1)
949 * - vB is the Object representation of the closure (made by box-lambda)
950 */
951 uint32_t vreg_target_closure = inst->VRegA_22c(inst_data);
952 uint32_t vreg_source_object = inst->VRegB_22c();
953
954 // Raise NullPointerException if object is null
955 mirror::Object* boxed_closure_object = shadow_frame.GetVRegReference(vreg_source_object);
956 if (UNLIKELY(boxed_closure_object == nullptr)) {
957 ThrowNullPointerExceptionFromInterpreter();
958 return false;
959 }
960
Igor Murashkin6918bf12015-09-27 19:19:06 -0700961 lambda::Closure* unboxed_closure = nullptr;
Igor Murashkine2facc52015-07-10 13:49:08 -0700962 // Raise an exception if unboxing fails.
963 if (!Runtime::Current()->GetLambdaBoxTable()->UnboxLambda(boxed_closure_object,
Igor Murashkin6918bf12015-09-27 19:19:06 -0700964 /*out*/&unboxed_closure)) {
Igor Murashkine2facc52015-07-10 13:49:08 -0700965 CHECK(self->IsExceptionPending());
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700966 return false;
967 }
968
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700969 DCHECK(unboxed_closure != nullptr);
Igor Murashkin30c475a2015-10-06 13:59:43 -0700970 WriteLambdaClosureIntoVRegs(/*inout*/shadow_frame, *unboxed_closure, vreg_target_closure);
Igor Murashkin2ee54e22015-06-18 10:05:11 -0700971 return true;
972}
973
Ian Rogers54874942014-06-10 16:31:03 -0700974uint32_t FindNextInstructionFollowingException(Thread* self, ShadowFrame& shadow_frame,
Sebastien Hertz9f102032014-05-23 08:59:42 +0200975 uint32_t dex_pc, const instrumentation::Instrumentation* instrumentation)
Mathieu Chartier90443472015-07-16 20:32:27 -0700976 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200977
Andreas Gampe794ad762015-02-23 08:12:24 -0800978NO_RETURN void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame)
979 __attribute__((cold))
Mathieu Chartier90443472015-07-16 20:32:27 -0700980 SHARED_REQUIRES(Locks::mutator_lock_);
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200981
Serguei Katkov9fb0ac72016-02-20 12:55:24 +0600982static inline bool TraceExecutionEnabled() {
983 // Return true if you want TraceExecution invocation before each bytecode execution.
984 return false;
985}
986
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200987static inline void TraceExecution(const ShadowFrame& shadow_frame, const Instruction* inst,
Ian Rogerse94652f2014-12-02 11:13:19 -0800988 const uint32_t dex_pc)
Mathieu Chartier90443472015-07-16 20:32:27 -0700989 SHARED_REQUIRES(Locks::mutator_lock_) {
Serguei Katkov9fb0ac72016-02-20 12:55:24 +0600990 if (TraceExecutionEnabled()) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200991#define TRACE_LOG std::cerr
Mathieu Chartiere861ebd2013-10-09 15:01:21 -0700992 std::ostringstream oss;
993 oss << PrettyMethod(shadow_frame.GetMethod())
994 << StringPrintf("\n0x%x: ", dex_pc)
Ian Rogerse94652f2014-12-02 11:13:19 -0800995 << inst->DumpString(shadow_frame.GetMethod()->GetDexFile()) << "\n";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800996 for (uint32_t i = 0; i < shadow_frame.NumberOfVRegs(); ++i) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +0200997 uint32_t raw_value = shadow_frame.GetVReg(i);
998 Object* ref_value = shadow_frame.GetVRegReference(i);
Ian Rogersef7d42f2014-01-06 12:55:46 -0800999 oss << StringPrintf(" vreg%u=0x%08X", i, raw_value);
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001000 if (ref_value != nullptr) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001001 if (ref_value->GetClass()->IsStringClass() &&
Jeff Hao848f70a2014-01-15 13:49:50 -08001002 ref_value->AsString()->GetValue() != nullptr) {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -07001003 oss << "/java.lang.String \"" << ref_value->AsString()->ToModifiedUtf8() << "\"";
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001004 } else {
Mathieu Chartiere861ebd2013-10-09 15:01:21 -07001005 oss << "/" << PrettyTypeOf(ref_value);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001006 }
1007 }
1008 }
Mathieu Chartiere861ebd2013-10-09 15:01:21 -07001009 TRACE_LOG << oss.str() << "\n";
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001010#undef TRACE_LOG
1011 }
1012}
1013
Sebastien Hertz1eda2262013-09-09 16:53:14 +02001014static inline bool IsBackwardBranch(int32_t branch_offset) {
1015 return branch_offset <= 0;
1016}
1017
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +01001018void ArtInterpreterToCompiledCodeBridge(Thread* self,
1019 ArtMethod* caller,
1020 const DexFile::CodeItem* code_item,
1021 ShadowFrame* shadow_frame,
1022 JValue* result);
Siva Chandra05d24152016-01-05 17:43:17 -08001023
Sebastien Hertzc6714852013-09-30 16:42:32 +02001024// Explicitly instantiate all DoInvoke functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001025#define EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, _is_range, _do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001026 template SHARED_REQUIRES(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001027 bool DoInvoke<_type, _is_range, _do_check>(Thread* self, ShadowFrame& shadow_frame, \
1028 const Instruction* inst, uint16_t inst_data, \
1029 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +02001030
1031#define EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(_type) \
1032 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, false); \
1033 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, false, true); \
1034 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, false); \
1035 EXPLICIT_DO_INVOKE_TEMPLATE_DECL(_type, true, true);
1036
Andreas Gampec8ccf682014-09-29 20:07:43 -07001037EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kStatic) // invoke-static/range.
1038EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kDirect) // invoke-direct/range.
1039EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kVirtual) // invoke-virtual/range.
1040EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kSuper) // invoke-super/range.
1041EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL(kInterface) // invoke-interface/range.
Sebastien Hertzc6714852013-09-30 16:42:32 +02001042#undef EXPLICIT_DO_INVOKE_ALL_TEMPLATE_DECL
1043#undef EXPLICIT_DO_INVOKE_TEMPLATE_DECL
1044
Sebastien Hertzc6714852013-09-30 16:42:32 +02001045// Explicitly instantiate all DoInvokeVirtualQuick functions.
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001046#define EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(_is_range) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001047 template SHARED_REQUIRES(Locks::mutator_lock_) \
Bernhard Rosenkränzer46053622013-12-12 02:15:52 +01001048 bool DoInvokeVirtualQuick<_is_range>(Thread* self, ShadowFrame& shadow_frame, \
1049 const Instruction* inst, uint16_t inst_data, \
1050 JValue* result)
Sebastien Hertzc6714852013-09-30 16:42:32 +02001051
1052EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(false); // invoke-virtual-quick.
1053EXPLICIT_DO_INVOKE_VIRTUAL_QUICK_TEMPLATE_DECL(true); // invoke-virtual-quick-range.
1054#undef EXPLICIT_INSTANTIATION_DO_INVOKE_VIRTUAL_QUICK
1055
Igor Murashkin158f35c2015-06-10 15:55:30 -07001056// Explicitly instantiate all DoCreateLambda functions.
Igor Murashkin6918bf12015-09-27 19:19:06 -07001057#define EXPLICIT_DO_CREATE_LAMBDA_DECL(_do_check) \
1058template SHARED_REQUIRES(Locks::mutator_lock_) \
1059bool DoCreateLambda<_do_check>(Thread* self, \
1060 const Instruction* inst, \
1061 /*inout*/ShadowFrame& shadow_frame, \
1062 /*inout*/lambda::ClosureBuilder* closure_builder, \
1063 /*inout*/lambda::Closure* uninitialized_closure);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001064
1065EXPLICIT_DO_CREATE_LAMBDA_DECL(false); // create-lambda
1066EXPLICIT_DO_CREATE_LAMBDA_DECL(true); // create-lambda
1067#undef EXPLICIT_DO_CREATE_LAMBDA_DECL
1068
1069// Explicitly instantiate all DoInvokeLambda functions.
1070#define EXPLICIT_DO_INVOKE_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001071template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin158f35c2015-06-10 15:55:30 -07001072bool DoInvokeLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1073 uint16_t inst_data, JValue* result);
1074
1075EXPLICIT_DO_INVOKE_LAMBDA_DECL(false); // invoke-lambda
1076EXPLICIT_DO_INVOKE_LAMBDA_DECL(true); // invoke-lambda
1077#undef EXPLICIT_DO_INVOKE_LAMBDA_DECL
1078
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001079// Explicitly instantiate all DoBoxLambda functions.
1080#define EXPLICIT_DO_BOX_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001081template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001082bool DoBoxLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1083 uint16_t inst_data);
1084
1085EXPLICIT_DO_BOX_LAMBDA_DECL(false); // box-lambda
1086EXPLICIT_DO_BOX_LAMBDA_DECL(true); // box-lambda
1087#undef EXPLICIT_DO_BOX_LAMBDA_DECL
1088
1089// Explicitly instantiate all DoUnBoxLambda functions.
1090#define EXPLICIT_DO_UNBOX_LAMBDA_DECL(_do_check) \
Mathieu Chartier90443472015-07-16 20:32:27 -07001091template SHARED_REQUIRES(Locks::mutator_lock_) \
Igor Murashkin2ee54e22015-06-18 10:05:11 -07001092bool DoUnboxLambda<_do_check>(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1093 uint16_t inst_data);
1094
1095EXPLICIT_DO_UNBOX_LAMBDA_DECL(false); // unbox-lambda
1096EXPLICIT_DO_UNBOX_LAMBDA_DECL(true); // unbox-lambda
1097#undef EXPLICIT_DO_BOX_LAMBDA_DECL
1098
Igor Murashkin6918bf12015-09-27 19:19:06 -07001099// Explicitly instantiate all DoCaptureVariable functions.
1100#define EXPLICIT_DO_CAPTURE_VARIABLE_DECL(_do_check) \
1101template SHARED_REQUIRES(Locks::mutator_lock_) \
1102bool DoCaptureVariable<_do_check>(Thread* self, \
1103 const Instruction* inst, \
1104 ShadowFrame& shadow_frame, \
1105 lambda::ClosureBuilder* closure_builder);
Sebastien Hertzc6714852013-09-30 16:42:32 +02001106
Igor Murashkin6918bf12015-09-27 19:19:06 -07001107EXPLICIT_DO_CAPTURE_VARIABLE_DECL(false); // capture-variable
1108EXPLICIT_DO_CAPTURE_VARIABLE_DECL(true); // capture-variable
1109#undef EXPLICIT_DO_CREATE_LAMBDA_DECL
1110
1111// Explicitly instantiate all DoLiberateVariable functions.
1112#define EXPLICIT_DO_LIBERATE_VARIABLE_DECL(_do_check) \
1113template SHARED_REQUIRES(Locks::mutator_lock_) \
1114bool DoLiberateVariable<_do_check>(Thread* self, \
1115 const Instruction* inst, \
1116 size_t captured_variable_index, \
1117 ShadowFrame& shadow_frame); \
1118
1119EXPLICIT_DO_LIBERATE_VARIABLE_DECL(false); // liberate-variable
1120EXPLICIT_DO_LIBERATE_VARIABLE_DECL(true); // liberate-variable
1121#undef EXPLICIT_DO_LIBERATE_LAMBDA_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001122} // namespace interpreter
1123} // namespace art
1124
1125#endif // ART_RUNTIME_INTERPRETER_INTERPRETER_COMMON_H_