blob: d30bc104506c8f5aaa99b8bdedf8272ebfc512a1 [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#include "interpreter_common.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070018
Andreas Gampef0e128a2015-02-27 20:08:34 -080019#include <cmath>
20
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Daniel Mihalyieb076692014-08-22 17:33:31 +020022#include "debugger.h"
David Sehr9e734c72018-01-04 17:56:19 -080023#include "dex/dex_file_types.h"
Nicolas Geoffray7bf2b4f2015-07-08 10:11:59 +000024#include "entrypoints/runtime_asm_entrypoints.h"
Orion Hodson43f0cdb2017-10-10 14:47:32 +010025#include "intrinsics_enum.h"
Tamas Berghammerdd5e5e92016-02-12 16:29:00 +000026#include "jit/jit.h"
Narayan Kamath9823e782016-08-03 12:46:58 +010027#include "jvalue.h"
Narayan Kamath208f8572016-08-03 12:46:58 +010028#include "method_handles-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070029#include "method_handles.h"
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010030#include "mirror/array-inl.h"
Narayan Kamath9823e782016-08-03 12:46:58 +010031#include "mirror/class.h"
Narayan Kamath000e1882016-10-24 17:14:25 +010032#include "mirror/emulated_stack_frame.h"
Andreas Gampec6ea7d02017-02-01 16:46:28 -080033#include "mirror/method_handle_impl-inl.h"
Orion Hodson928033d2018-02-07 05:30:54 +000034#include "mirror/var_handle.h"
Narayan Kamath9823e782016-08-03 12:46:58 +010035#include "reflection-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070036#include "reflection.h"
Andreas Gampeb3025922015-09-01 14:45:00 -070037#include "stack.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070038#include "thread-inl.h"
Chang Xingbd208d82017-07-12 14:53:17 -070039#include "transaction.h"
Orion Hodson537a4fe2018-05-15 13:57:58 +010040#include "var_handles.h"
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010041#include "well_known_classes.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020042
43namespace art {
44namespace interpreter {
45
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000046void ThrowNullPointerExceptionFromInterpreter() {
47 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -070048}
49
Chang Xingbd208d82017-07-12 14:53:17 -070050template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
51 bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -070052bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
53 uint16_t inst_data) {
54 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
55 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Roland Levillain4b8f1ec2015-08-26 18:34:03 +010056 ArtField* f =
57 FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
58 Primitive::ComponentSize(field_type));
Ian Rogers54874942014-06-10 16:31:03 -070059 if (UNLIKELY(f == nullptr)) {
60 CHECK(self->IsExceptionPending());
61 return false;
62 }
Mathieu Chartieref41db72016-10-25 15:08:01 -070063 ObjPtr<mirror::Object> obj;
Ian Rogers54874942014-06-10 16:31:03 -070064 if (is_static) {
65 obj = f->GetDeclaringClass();
Chang Xingbd208d82017-07-12 14:53:17 -070066 if (transaction_active) {
67 if (Runtime::Current()->GetTransaction()->ReadConstraint(obj.Ptr(), f)) {
68 Runtime::Current()->AbortTransactionAndThrowAbortError(self, "Can't read static fields of "
69 + obj->PrettyTypeOf() + " since it does not belong to clinit's class.");
70 return false;
71 }
72 }
Ian Rogers54874942014-06-10 16:31:03 -070073 } else {
74 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
75 if (UNLIKELY(obj == nullptr)) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000076 ThrowNullPointerExceptionForFieldAccess(f, true);
Ian Rogers54874942014-06-10 16:31:03 -070077 return false;
78 }
79 }
Orion Hodson3d617ac2016-10-19 14:00:46 +010080
81 JValue result;
Alex Light084fa372017-06-16 08:58:34 -070082 if (UNLIKELY(!DoFieldGetCommon<field_type>(self, shadow_frame, obj, f, &result))) {
83 // Instrumentation threw an error!
84 CHECK(self->IsExceptionPending());
85 return false;
86 }
Ian Rogers54874942014-06-10 16:31:03 -070087 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
88 switch (field_type) {
89 case Primitive::kPrimBoolean:
Orion Hodson3d617ac2016-10-19 14:00:46 +010090 shadow_frame.SetVReg(vregA, result.GetZ());
Ian Rogers54874942014-06-10 16:31:03 -070091 break;
92 case Primitive::kPrimByte:
Orion Hodson3d617ac2016-10-19 14:00:46 +010093 shadow_frame.SetVReg(vregA, result.GetB());
Ian Rogers54874942014-06-10 16:31:03 -070094 break;
95 case Primitive::kPrimChar:
Orion Hodson3d617ac2016-10-19 14:00:46 +010096 shadow_frame.SetVReg(vregA, result.GetC());
Ian Rogers54874942014-06-10 16:31:03 -070097 break;
98 case Primitive::kPrimShort:
Orion Hodson3d617ac2016-10-19 14:00:46 +010099 shadow_frame.SetVReg(vregA, result.GetS());
Ian Rogers54874942014-06-10 16:31:03 -0700100 break;
101 case Primitive::kPrimInt:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100102 shadow_frame.SetVReg(vregA, result.GetI());
Ian Rogers54874942014-06-10 16:31:03 -0700103 break;
104 case Primitive::kPrimLong:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100105 shadow_frame.SetVRegLong(vregA, result.GetJ());
Ian Rogers54874942014-06-10 16:31:03 -0700106 break;
107 case Primitive::kPrimNot:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100108 shadow_frame.SetVRegReference(vregA, result.GetL());
Ian Rogers54874942014-06-10 16:31:03 -0700109 break;
110 default:
111 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700112 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700113 }
114 return true;
115}
116
117// Explicitly instantiate all DoFieldGet functions.
Chang Xingbd208d82017-07-12 14:53:17 -0700118#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
119 template bool DoFieldGet<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \
Ian Rogers54874942014-06-10 16:31:03 -0700120 ShadowFrame& shadow_frame, \
121 const Instruction* inst, \
122 uint16_t inst_data)
123
124#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Chang Xingbd208d82017-07-12 14:53:17 -0700125 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false, true); \
126 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false, false); \
127 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true, true); \
128 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true, false);
Ian Rogers54874942014-06-10 16:31:03 -0700129
130// iget-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700131EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean)
132EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte)
133EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar)
134EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort)
135EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt)
136EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong)
137EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700138
139// sget-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700140EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean)
141EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte)
142EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar)
143EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort)
144EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt)
145EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong)
146EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700147
148#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
149#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
150
151// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
152// Returns true on success, otherwise throws an exception and returns false.
153template<Primitive::Type field_type>
154bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700155 ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Ian Rogers54874942014-06-10 16:31:03 -0700156 if (UNLIKELY(obj == nullptr)) {
157 // We lost the reference to the field index so we cannot get a more
158 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000159 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -0700160 return false;
161 }
162 MemberOffset field_offset(inst->VRegC_22c());
163 // Report this field access to instrumentation if needed. Since we only have the offset of
164 // the field from the base of the object, we need to look for it first.
165 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
166 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
167 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
168 field_offset.Uint32Value());
169 DCHECK(f != nullptr);
170 DCHECK(!f->IsStatic());
Alex Light084fa372017-06-16 08:58:34 -0700171 Thread* self = Thread::Current();
172 StackHandleScope<1> hs(self);
Mathieu Chartiera3147732016-10-26 22:57:02 -0700173 // Save obj in case the instrumentation event has thread suspension.
174 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj);
Alex Light084fa372017-06-16 08:58:34 -0700175 instrumentation->FieldReadEvent(self,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700176 obj.Ptr(),
177 shadow_frame.GetMethod(),
178 shadow_frame.GetDexPC(),
179 f);
Alex Light084fa372017-06-16 08:58:34 -0700180 if (UNLIKELY(self->IsExceptionPending())) {
181 return false;
182 }
Ian Rogers54874942014-06-10 16:31:03 -0700183 }
184 // Note: iget-x-quick instructions are only for non-volatile fields.
185 const uint32_t vregA = inst->VRegA_22c(inst_data);
186 switch (field_type) {
187 case Primitive::kPrimInt:
188 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
189 break;
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800190 case Primitive::kPrimBoolean:
191 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldBoolean(field_offset)));
192 break;
193 case Primitive::kPrimByte:
194 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldByte(field_offset)));
195 break;
196 case Primitive::kPrimChar:
197 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldChar(field_offset)));
198 break;
199 case Primitive::kPrimShort:
200 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldShort(field_offset)));
201 break;
Ian Rogers54874942014-06-10 16:31:03 -0700202 case Primitive::kPrimLong:
203 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
204 break;
205 case Primitive::kPrimNot:
206 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
207 break;
208 default:
209 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700210 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700211 }
212 return true;
213}
214
215// Explicitly instantiate all DoIGetQuick functions.
216#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
217 template bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
218 uint16_t inst_data)
219
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800220EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
221EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimBoolean); // iget-boolean-quick.
222EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimByte); // iget-byte-quick.
223EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimChar); // iget-char-quick.
224EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimShort); // iget-short-quick.
225EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
226EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
Ian Rogers54874942014-06-10 16:31:03 -0700227#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
228
229template<Primitive::Type field_type>
230static JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700231 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers54874942014-06-10 16:31:03 -0700232 JValue field_value;
233 switch (field_type) {
234 case Primitive::kPrimBoolean:
235 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
236 break;
237 case Primitive::kPrimByte:
238 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
239 break;
240 case Primitive::kPrimChar:
241 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
242 break;
243 case Primitive::kPrimShort:
244 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
245 break;
246 case Primitive::kPrimInt:
247 field_value.SetI(shadow_frame.GetVReg(vreg));
248 break;
249 case Primitive::kPrimLong:
250 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
251 break;
252 case Primitive::kPrimNot:
253 field_value.SetL(shadow_frame.GetVRegReference(vreg));
254 break;
255 default:
256 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700257 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700258 }
259 return field_value;
260}
261
Orion Hodson3d617ac2016-10-19 14:00:46 +0100262template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
263 bool transaction_active>
264bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
265 uint16_t inst_data) {
266 const bool do_assignability_check = do_access_check;
267 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
268 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
269 ArtField* f =
270 FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
271 Primitive::ComponentSize(field_type));
272 if (UNLIKELY(f == nullptr)) {
273 CHECK(self->IsExceptionPending());
274 return false;
275 }
276 ObjPtr<mirror::Object> obj;
277 if (is_static) {
278 obj = f->GetDeclaringClass();
Chang Xingbd208d82017-07-12 14:53:17 -0700279 if (transaction_active) {
280 if (Runtime::Current()->GetTransaction()->WriteConstraint(obj.Ptr(), f)) {
281 Runtime::Current()->AbortTransactionAndThrowAbortError(
282 self, "Can't set fields of " + obj->PrettyTypeOf());
283 return false;
284 }
285 }
286
Orion Hodson3d617ac2016-10-19 14:00:46 +0100287 } else {
288 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
289 if (UNLIKELY(obj == nullptr)) {
290 ThrowNullPointerExceptionForFieldAccess(f, false);
291 return false;
292 }
293 }
294
295 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100296 JValue value = GetFieldValue<field_type>(shadow_frame, vregA);
Orion Hodson3d617ac2016-10-19 14:00:46 +0100297 return DoFieldPutCommon<field_type, do_assignability_check, transaction_active>(self,
298 shadow_frame,
299 obj,
300 f,
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100301 value);
Orion Hodson3d617ac2016-10-19 14:00:46 +0100302}
303
Ian Rogers54874942014-06-10 16:31:03 -0700304// Explicitly instantiate all DoFieldPut functions.
305#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
306 template bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \
307 const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
308
309#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
310 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
311 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
312 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
313 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
314
315// iput-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700316EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean)
317EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte)
318EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar)
319EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort)
320EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt)
321EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong)
322EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700323
324// sput-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700325EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean)
326EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte)
327EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar)
328EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort)
329EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt)
330EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong)
331EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700332
333#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
334#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
335
336template<Primitive::Type field_type, bool transaction_active>
337bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700338 ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Ian Rogers54874942014-06-10 16:31:03 -0700339 if (UNLIKELY(obj == nullptr)) {
340 // We lost the reference to the field index so we cannot get a more
341 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000342 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -0700343 return false;
344 }
345 MemberOffset field_offset(inst->VRegC_22c());
346 const uint32_t vregA = inst->VRegA_22c(inst_data);
347 // Report this field modification to instrumentation if needed. Since we only have the offset of
348 // the field from the base of the object, we need to look for it first.
349 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
350 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
351 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
352 field_offset.Uint32Value());
353 DCHECK(f != nullptr);
354 DCHECK(!f->IsStatic());
355 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
Alex Light084fa372017-06-16 08:58:34 -0700356 Thread* self = Thread::Current();
357 StackHandleScope<2> hs(self);
Mathieu Chartiera3147732016-10-26 22:57:02 -0700358 // Save obj in case the instrumentation event has thread suspension.
359 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj);
Alex Light084fa372017-06-16 08:58:34 -0700360 mirror::Object* fake_root = nullptr;
361 HandleWrapper<mirror::Object> ret(hs.NewHandleWrapper<mirror::Object>(
362 field_type == Primitive::kPrimNot ? field_value.GetGCRoot() : &fake_root));
363 instrumentation->FieldWriteEvent(self,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700364 obj.Ptr(),
365 shadow_frame.GetMethod(),
366 shadow_frame.GetDexPC(),
367 f,
368 field_value);
Alex Light084fa372017-06-16 08:58:34 -0700369 if (UNLIKELY(self->IsExceptionPending())) {
370 return false;
371 }
Ian Rogers54874942014-06-10 16:31:03 -0700372 }
373 // Note: iput-x-quick instructions are only for non-volatile fields.
374 switch (field_type) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700375 case Primitive::kPrimBoolean:
376 obj->SetFieldBoolean<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
377 break;
378 case Primitive::kPrimByte:
379 obj->SetFieldByte<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
380 break;
381 case Primitive::kPrimChar:
382 obj->SetFieldChar<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
383 break;
384 case Primitive::kPrimShort:
385 obj->SetFieldShort<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
386 break;
Ian Rogers54874942014-06-10 16:31:03 -0700387 case Primitive::kPrimInt:
388 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
389 break;
390 case Primitive::kPrimLong:
391 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
392 break;
393 case Primitive::kPrimNot:
394 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
395 break;
396 default:
397 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700398 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700399 }
400 return true;
401}
402
403// Explicitly instantiate all DoIPutQuick functions.
404#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
405 template bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
406 const Instruction* inst, \
407 uint16_t inst_data)
408
409#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
410 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
411 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
412
Andreas Gampec8ccf682014-09-29 20:07:43 -0700413EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt) // iput-quick.
414EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimBoolean) // iput-boolean-quick.
415EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimByte) // iput-byte-quick.
416EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimChar) // iput-char-quick.
417EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimShort) // iput-short-quick.
418EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong) // iput-wide-quick.
419EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot) // iput-object-quick.
Ian Rogers54874942014-06-10 16:31:03 -0700420#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
421#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
422
Alex Light9fb1ab12017-09-05 09:32:49 -0700423// We execute any instrumentation events that are triggered by this exception and change the
424// shadow_frame's dex_pc to that of the exception handler if there is one in the current method.
425// Return true if we should continue executing in the current method and false if we need to go up
426// the stack to find an exception handler.
Sebastien Hertz520633b2015-09-08 17:03:36 +0200427// We accept a null Instrumentation* meaning we must not report anything to the instrumentation.
Alex Light9fb1ab12017-09-05 09:32:49 -0700428// TODO We should have a better way to skip instrumentation reporting or possibly rethink that
429// behavior.
430bool MoveToExceptionHandler(Thread* self,
431 ShadowFrame& shadow_frame,
432 const instrumentation::Instrumentation* instrumentation) {
Ian Rogers54874942014-06-10 16:31:03 -0700433 self->VerifyStack();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700434 StackHandleScope<2> hs(self);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000435 Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException()));
Alex Light9fb1ab12017-09-05 09:32:49 -0700436 if (instrumentation != nullptr &&
437 instrumentation->HasExceptionThrownListeners() &&
438 self->IsExceptionThrownByCurrentMethod(exception.Get())) {
439 // See b/65049545 for why we don't need to check to see if the exception has changed.
Alex Light6e1607e2017-08-23 10:06:18 -0700440 instrumentation->ExceptionThrownEvent(self, exception.Get());
Sebastien Hertz9f102032014-05-23 08:59:42 +0200441 }
Ian Rogers54874942014-06-10 16:31:03 -0700442 bool clear_exception = false;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700443 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(
Alex Light9fb1ab12017-09-05 09:32:49 -0700444 hs.NewHandle(exception->GetClass()), shadow_frame.GetDexPC(), &clear_exception);
Andreas Gampee2abbc62017-09-15 11:59:26 -0700445 if (found_dex_pc == dex::kDexNoIndex) {
Alex Light9fb1ab12017-09-05 09:32:49 -0700446 if (instrumentation != nullptr) {
447 if (shadow_frame.NeedsNotifyPop()) {
448 instrumentation->WatchedFramePopped(self, shadow_frame);
449 }
450 // Exception is not caught by the current method. We will unwind to the
451 // caller. Notify any instrumentation listener.
452 instrumentation->MethodUnwindEvent(self,
453 shadow_frame.GetThisObject(),
454 shadow_frame.GetMethod(),
455 shadow_frame.GetDexPC());
Alex Lighte814f9d2017-07-31 16:14:39 -0700456 }
Alex Light9fb1ab12017-09-05 09:32:49 -0700457 return false;
Ian Rogers54874942014-06-10 16:31:03 -0700458 } else {
Alex Light9fb1ab12017-09-05 09:32:49 -0700459 shadow_frame.SetDexPC(found_dex_pc);
460 if (instrumentation != nullptr && instrumentation->HasExceptionHandledListeners()) {
461 self->ClearException();
462 instrumentation->ExceptionHandledEvent(self, exception.Get());
463 if (UNLIKELY(self->IsExceptionPending())) {
464 // Exception handled event threw an exception. Try to find the handler for this one.
465 return MoveToExceptionHandler(self, shadow_frame, instrumentation);
466 } else if (!clear_exception) {
467 self->SetException(exception.Get());
468 }
469 } else if (clear_exception) {
Ian Rogers54874942014-06-10 16:31:03 -0700470 self->ClearException();
471 }
Alex Light9fb1ab12017-09-05 09:32:49 -0700472 return true;
Ian Rogers54874942014-06-10 16:31:03 -0700473 }
Ian Rogers54874942014-06-10 16:31:03 -0700474}
475
Ian Rogerse94652f2014-12-02 11:13:19 -0800476void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) {
477 LOG(FATAL) << "Unexpected instruction: "
478 << inst->DumpString(shadow_frame.GetMethod()->GetDexFile());
479 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700480}
481
Sebastien Hertz45b15972015-04-03 16:07:05 +0200482void AbortTransactionF(Thread* self, const char* fmt, ...) {
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700483 va_list args;
484 va_start(args, fmt);
Sebastien Hertz45b15972015-04-03 16:07:05 +0200485 AbortTransactionV(self, fmt, args);
486 va_end(args);
487}
488
489void AbortTransactionV(Thread* self, const char* fmt, va_list args) {
490 CHECK(Runtime::Current()->IsActiveTransaction());
491 // Constructs abort message.
Sebastien Hertz1c80bec2015-02-03 11:58:06 +0100492 std::string abort_msg;
Andreas Gampe46ee31b2016-12-14 10:11:49 -0800493 android::base::StringAppendV(&abort_msg, fmt, args);
Sebastien Hertz1c80bec2015-02-03 11:58:06 +0100494 // Throws an exception so we can abort the transaction and rollback every change.
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200495 Runtime::Current()->AbortTransactionAndThrowAbortError(self, abort_msg);
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700496}
497
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100498// START DECLARATIONS :
499//
500// These additional declarations are required because clang complains
501// about ALWAYS_INLINE (-Werror, -Wgcc-compat) in definitions.
502//
503
Narayan Kamath9823e782016-08-03 12:46:58 +0100504template <bool is_range, bool do_assignability_check>
Vladimir Markod16363a2017-02-01 14:09:13 +0000505static ALWAYS_INLINE bool DoCallCommon(ArtMethod* called_method,
506 Thread* self,
507 ShadowFrame& shadow_frame,
508 JValue* result,
509 uint16_t number_of_inputs,
510 uint32_t (&arg)[Instruction::kMaxVarArgRegs],
511 uint32_t vregC) REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100512
513template <bool is_range>
Narayan Kamath2cb856c2016-11-02 12:01:26 +0000514ALWAYS_INLINE void CopyRegisters(ShadowFrame& caller_frame,
515 ShadowFrame* callee_frame,
516 const uint32_t (&arg)[Instruction::kMaxVarArgRegs],
517 const size_t first_src_reg,
518 const size_t first_dest_reg,
519 const size_t num_regs) REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100520
521// END DECLARATIONS.
522
Siva Chandra05d24152016-01-05 17:43:17 -0800523void ArtInterpreterToCompiledCodeBridge(Thread* self,
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100524 ArtMethod* caller,
Siva Chandra05d24152016-01-05 17:43:17 -0800525 ShadowFrame* shadow_frame,
Jeff Hao5ea84132017-05-05 16:59:29 -0700526 uint16_t arg_offset,
Siva Chandra05d24152016-01-05 17:43:17 -0800527 JValue* result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700528 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700529 ArtMethod* method = shadow_frame->GetMethod();
530 // Ensure static methods are initialized.
531 if (method->IsStatic()) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700532 ObjPtr<mirror::Class> declaringClass = method->GetDeclaringClass();
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700533 if (UNLIKELY(!declaringClass->IsInitialized())) {
534 self->PushShadowFrame(shadow_frame);
535 StackHandleScope<1> hs(self);
536 Handle<mirror::Class> h_class(hs.NewHandle(declaringClass));
Nicolas Geoffray01822292017-03-09 09:03:19 +0000537 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true,
538 true))) {
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700539 self->PopShadowFrame();
540 DCHECK(self->IsExceptionPending());
541 return;
542 }
543 self->PopShadowFrame();
544 CHECK(h_class->IsInitializing());
Nicolas Geoffray01822292017-03-09 09:03:19 +0000545 // Reload from shadow frame in case the method moved, this is faster than adding a handle.
546 method = shadow_frame->GetMethod();
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700547 }
548 }
Jeff Hao5ea84132017-05-05 16:59:29 -0700549 // Basic checks for the arg_offset. If there's no code item, the arg_offset must be 0. Otherwise,
550 // check that the arg_offset isn't greater than the number of registers. A stronger check is
551 // difficult since the frame may contain space for all the registers in the method, or only enough
552 // space for the arguments.
553 if (kIsDebugBuild) {
554 if (method->GetCodeItem() == nullptr) {
555 DCHECK_EQ(0u, arg_offset) << method->PrettyMethod();
556 } else {
557 DCHECK_LE(arg_offset, shadow_frame->NumberOfVRegs());
558 }
559 }
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100560 jit::Jit* jit = Runtime::Current()->GetJit();
561 if (jit != nullptr && caller != nullptr) {
562 jit->NotifyInterpreterToCompiledCodeTransition(self, caller);
563 }
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700564 method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset),
565 (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t),
Andreas Gampe542451c2016-07-26 09:02:02 -0700566 result, method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty());
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700567}
568
Mingyao Yangffedec52016-05-19 10:48:40 -0700569void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame,
570 uint16_t this_obj_vreg,
571 JValue result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700572 REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700573 ObjPtr<mirror::Object> existing = shadow_frame->GetVRegReference(this_obj_vreg);
Mingyao Yangffedec52016-05-19 10:48:40 -0700574 if (existing == nullptr) {
575 // If it's null, we come from compiled code that was deoptimized. Nothing to do,
576 // as the compiler verified there was no alias.
577 // Set the new string result of the StringFactory.
578 shadow_frame->SetVRegReference(this_obj_vreg, result.GetL());
579 return;
580 }
581 // Set the string init result into all aliases.
582 for (uint32_t i = 0, e = shadow_frame->NumberOfVRegs(); i < e; ++i) {
583 if (shadow_frame->GetVRegReference(i) == existing) {
584 DCHECK_EQ(shadow_frame->GetVRegReference(i),
585 reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i)));
586 shadow_frame->SetVRegReference(i, result.GetL());
587 DCHECK_EQ(shadow_frame->GetVRegReference(i),
588 reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i)));
589 }
590 }
591}
592
Orion Hodsonc069a302017-01-18 09:23:12 +0000593template<bool is_range>
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100594static bool DoMethodHandleInvokeCommon(Thread* self,
595 ShadowFrame& shadow_frame,
596 bool invoke_exact,
597 const Instruction* inst,
598 uint16_t inst_data,
599 JValue* result)
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100600 REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Light848574c2017-09-25 16:59:39 -0700601 // Make sure to check for async exceptions
602 if (UNLIKELY(self->ObserveAsyncException())) {
603 return false;
604 }
Narayan Kamath9823e782016-08-03 12:46:58 +0100605 // Invoke-polymorphic instructions always take a receiver. i.e, they are never static.
606 const uint32_t vRegC = (is_range) ? inst->VRegC_4rcc() : inst->VRegC_45cc();
Orion Hodson3d617ac2016-10-19 14:00:46 +0100607 const int invoke_method_idx = (is_range) ? inst->VRegB_4rcc() : inst->VRegB_45cc();
Narayan Kamath9823e782016-08-03 12:46:58 +0100608
Orion Hodson1a06f9f2016-11-09 08:32:42 +0000609 // Initialize |result| to 0 as this is the default return value for
610 // polymorphic invocations of method handle types with void return
611 // and provides sane return result in error cases.
612 result->SetJ(0);
613
Orion Hodson3d617ac2016-10-19 14:00:46 +0100614 // The invoke_method_idx here is the name of the signature polymorphic method that
Narayan Kamath9823e782016-08-03 12:46:58 +0100615 // was symbolically invoked in bytecode (say MethodHandle.invoke or MethodHandle.invokeExact)
616 // and not the method that we'll dispatch to in the end.
Orion Hodsone7732be2017-10-11 14:35:20 +0100617 StackHandleScope<2> hs(self);
Orion Hodsonc069a302017-01-18 09:23:12 +0000618 Handle<mirror::MethodHandle> method_handle(hs.NewHandle(
619 ObjPtr<mirror::MethodHandle>::DownCast(
Mathieu Chartieref41db72016-10-25 15:08:01 -0700620 MakeObjPtr(shadow_frame.GetVRegReference(vRegC)))));
Andreas Gampefa4333d2017-02-14 11:10:34 -0800621 if (UNLIKELY(method_handle == nullptr)) {
Narayan Kamath9823e782016-08-03 12:46:58 +0100622 // Note that the invoke type is kVirtual here because a call to a signature
623 // polymorphic method is shaped like a virtual call at the bytecode level.
Orion Hodson3d617ac2016-10-19 14:00:46 +0100624 ThrowNullPointerExceptionForMethodAccess(invoke_method_idx, InvokeType::kVirtual);
Narayan Kamath9823e782016-08-03 12:46:58 +0100625 return false;
626 }
627
628 // The vRegH value gives the index of the proto_id associated with this
Orion Hodson811bd5f2016-12-07 11:35:37 +0000629 // signature polymorphic call site.
Orion Hodson06d10a72018-05-14 08:53:38 +0100630 const uint16_t vRegH = (is_range) ? inst->VRegH_4rcc() : inst->VRegH_45cc();
631 const dex::ProtoIndex callsite_proto_id(vRegH);
Narayan Kamath9823e782016-08-03 12:46:58 +0100632
633 // Call through to the classlinker and ask it to resolve the static type associated
634 // with the callsite. This information is stored in the dex cache so it's
635 // guaranteed to be fast after the first resolution.
Narayan Kamath9823e782016-08-03 12:46:58 +0100636 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Orion Hodsone7732be2017-10-11 14:35:20 +0100637 Handle<mirror::MethodType> callsite_type(hs.NewHandle(
638 class_linker->ResolveMethodType(self, callsite_proto_id, shadow_frame.GetMethod())));
Narayan Kamath9823e782016-08-03 12:46:58 +0100639
640 // This implies we couldn't resolve one or more types in this method handle.
Andreas Gampefa4333d2017-02-14 11:10:34 -0800641 if (UNLIKELY(callsite_type == nullptr)) {
Narayan Kamath9823e782016-08-03 12:46:58 +0100642 CHECK(self->IsExceptionPending());
Narayan Kamath9823e782016-08-03 12:46:58 +0100643 return false;
644 }
645
Orion Hodson811bd5f2016-12-07 11:35:37 +0000646 // There is a common dispatch method for method handles that takes
647 // arguments either from a range or an array of arguments depending
648 // on whether the DEX instruction is invoke-polymorphic/range or
649 // invoke-polymorphic. The array here is for the latter.
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100650 if (UNLIKELY(is_range)) {
Orion Hodson811bd5f2016-12-07 11:35:37 +0000651 // VRegC is the register holding the method handle. Arguments passed
652 // to the method handle's target do not include the method handle.
Orion Hodson960d4f72017-11-10 15:32:38 +0000653 RangeInstructionOperands operands(inst->VRegC_4rcc() + 1, inst->VRegA_4rcc() - 1);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100654 if (invoke_exact) {
Orion Hodson960d4f72017-11-10 15:32:38 +0000655 return MethodHandleInvokeExact(self,
656 shadow_frame,
657 method_handle,
658 callsite_type,
659 &operands,
660 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100661 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +0000662 return MethodHandleInvoke(self,
663 shadow_frame,
664 method_handle,
665 callsite_type,
666 &operands,
667 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100668 }
Narayan Kamath9823e782016-08-03 12:46:58 +0100669 } else {
Orion Hodson811bd5f2016-12-07 11:35:37 +0000670 // Get the register arguments for the invoke.
Orion Hodson960d4f72017-11-10 15:32:38 +0000671 uint32_t args[Instruction::kMaxVarArgRegs] = {};
Orion Hodson811bd5f2016-12-07 11:35:37 +0000672 inst->GetVarArgs(args, inst_data);
673 // Drop the first register which is the method handle performing the invoke.
Alexey Frunze8631a462017-01-19 19:07:37 -0800674 memmove(args, args + 1, sizeof(args[0]) * (Instruction::kMaxVarArgRegs - 1));
Orion Hodson811bd5f2016-12-07 11:35:37 +0000675 args[Instruction::kMaxVarArgRegs - 1] = 0;
Orion Hodson960d4f72017-11-10 15:32:38 +0000676 VarArgsInstructionOperands operands(args, inst->VRegA_45cc() - 1);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100677 if (invoke_exact) {
Orion Hodson960d4f72017-11-10 15:32:38 +0000678 return MethodHandleInvokeExact(self,
679 shadow_frame,
680 method_handle,
681 callsite_type,
682 &operands,
683 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100684 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +0000685 return MethodHandleInvoke(self,
686 shadow_frame,
687 method_handle,
688 callsite_type,
689 &operands,
690 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100691 }
692 }
693}
694
695bool DoMethodHandleInvokeExact(Thread* self,
696 ShadowFrame& shadow_frame,
697 const Instruction* inst,
698 uint16_t inst_data,
699 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) {
700 if (inst->Opcode() == Instruction::INVOKE_POLYMORPHIC) {
701 static const bool kIsRange = false;
702 return DoMethodHandleInvokeCommon<kIsRange>(
703 self, shadow_frame, true /* is_exact */, inst, inst_data, result);
704 } else {
705 DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_POLYMORPHIC_RANGE);
706 static const bool kIsRange = true;
707 return DoMethodHandleInvokeCommon<kIsRange>(
708 self, shadow_frame, true /* is_exact */, inst, inst_data, result);
709 }
710}
711
712bool DoMethodHandleInvoke(Thread* self,
713 ShadowFrame& shadow_frame,
714 const Instruction* inst,
715 uint16_t inst_data,
716 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) {
717 if (inst->Opcode() == Instruction::INVOKE_POLYMORPHIC) {
718 static const bool kIsRange = false;
719 return DoMethodHandleInvokeCommon<kIsRange>(
720 self, shadow_frame, false /* is_exact */, inst, inst_data, result);
721 } else {
722 DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_POLYMORPHIC_RANGE);
723 static const bool kIsRange = true;
724 return DoMethodHandleInvokeCommon<kIsRange>(
725 self, shadow_frame, false /* is_exact */, inst, inst_data, result);
726 }
727}
728
Orion Hodson928033d2018-02-07 05:30:54 +0000729static bool DoVarHandleInvokeCommon(Thread* self,
730 ShadowFrame& shadow_frame,
731 const Instruction* inst,
732 uint16_t inst_data,
733 JValue* result,
734 mirror::VarHandle::AccessMode access_mode)
735 REQUIRES_SHARED(Locks::mutator_lock_) {
736 // Make sure to check for async exceptions
737 if (UNLIKELY(self->ObserveAsyncException())) {
738 return false;
739 }
740
Orion Hodson928033d2018-02-07 05:30:54 +0000741 StackHandleScope<2> hs(self);
Orion Hodson537a4fe2018-05-15 13:57:58 +0100742 bool is_var_args = inst->HasVarArgs();
Orion Hodson06d10a72018-05-14 08:53:38 +0100743 const uint16_t vRegH = is_var_args ? inst->VRegH_45cc() : inst->VRegH_4rcc();
Orion Hodson928033d2018-02-07 05:30:54 +0000744 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
745 Handle<mirror::MethodType> callsite_type(hs.NewHandle(
Orion Hodson06d10a72018-05-14 08:53:38 +0100746 class_linker->ResolveMethodType(self, dex::ProtoIndex(vRegH), shadow_frame.GetMethod())));
Orion Hodson928033d2018-02-07 05:30:54 +0000747 // This implies we couldn't resolve one or more types in this VarHandle.
748 if (UNLIKELY(callsite_type == nullptr)) {
749 CHECK(self->IsExceptionPending());
750 return false;
751 }
752
Orion Hodson537a4fe2018-05-15 13:57:58 +0100753 const uint32_t vRegC = is_var_args ? inst->VRegC_45cc() : inst->VRegC_4rcc();
754 ObjPtr<mirror::Object> receiver(shadow_frame.GetVRegReference(vRegC));
755 Handle<mirror::VarHandle> var_handle(hs.NewHandle(down_cast<mirror::VarHandle*>(receiver.Ptr())));
Orion Hodson928033d2018-02-07 05:30:54 +0000756 if (is_var_args) {
757 uint32_t args[Instruction::kMaxVarArgRegs];
758 inst->GetVarArgs(args, inst_data);
759 VarArgsInstructionOperands all_operands(args, inst->VRegA_45cc());
760 NoReceiverInstructionOperands operands(&all_operands);
Orion Hodson537a4fe2018-05-15 13:57:58 +0100761 return VarHandleInvokeAccessor(self,
762 shadow_frame,
763 var_handle,
764 callsite_type,
765 access_mode,
766 &operands,
767 result);
Orion Hodson928033d2018-02-07 05:30:54 +0000768 } else {
769 RangeInstructionOperands all_operands(inst->VRegC_4rcc(), inst->VRegA_4rcc());
770 NoReceiverInstructionOperands operands(&all_operands);
Orion Hodson537a4fe2018-05-15 13:57:58 +0100771 return VarHandleInvokeAccessor(self,
772 shadow_frame,
773 var_handle,
774 callsite_type,
775 access_mode,
776 &operands,
777 result);
Orion Hodson928033d2018-02-07 05:30:54 +0000778 }
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100779}
780
Orion Hodson928033d2018-02-07 05:30:54 +0000781#define DO_VAR_HANDLE_ACCESSOR(_access_mode) \
782bool DoVarHandle ## _access_mode(Thread* self, \
783 ShadowFrame& shadow_frame, \
784 const Instruction* inst, \
785 uint16_t inst_data, \
786 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) { \
787 const auto access_mode = mirror::VarHandle::AccessMode::k ## _access_mode; \
788 return DoVarHandleInvokeCommon(self, shadow_frame, inst, inst_data, result, access_mode); \
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100789}
790
Orion Hodson928033d2018-02-07 05:30:54 +0000791DO_VAR_HANDLE_ACCESSOR(CompareAndExchange)
792DO_VAR_HANDLE_ACCESSOR(CompareAndExchangeAcquire)
793DO_VAR_HANDLE_ACCESSOR(CompareAndExchangeRelease)
794DO_VAR_HANDLE_ACCESSOR(CompareAndSet)
795DO_VAR_HANDLE_ACCESSOR(Get)
796DO_VAR_HANDLE_ACCESSOR(GetAcquire)
797DO_VAR_HANDLE_ACCESSOR(GetAndAdd)
798DO_VAR_HANDLE_ACCESSOR(GetAndAddAcquire)
799DO_VAR_HANDLE_ACCESSOR(GetAndAddRelease)
800DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAnd)
801DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAndAcquire)
802DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAndRelease)
803DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOr)
804DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOrAcquire)
805DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOrRelease)
806DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXor)
807DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXorAcquire)
808DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXorRelease)
809DO_VAR_HANDLE_ACCESSOR(GetAndSet)
810DO_VAR_HANDLE_ACCESSOR(GetAndSetAcquire)
811DO_VAR_HANDLE_ACCESSOR(GetAndSetRelease)
812DO_VAR_HANDLE_ACCESSOR(GetOpaque)
813DO_VAR_HANDLE_ACCESSOR(GetVolatile)
814DO_VAR_HANDLE_ACCESSOR(Set)
815DO_VAR_HANDLE_ACCESSOR(SetOpaque)
816DO_VAR_HANDLE_ACCESSOR(SetRelease)
817DO_VAR_HANDLE_ACCESSOR(SetVolatile)
818DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSet)
819DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetAcquire)
820DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetPlain)
821DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetRelease)
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100822
Orion Hodson928033d2018-02-07 05:30:54 +0000823#undef DO_VAR_HANDLE_ACCESSOR
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100824
825template<bool is_range>
826bool DoInvokePolymorphic(Thread* self,
827 ShadowFrame& shadow_frame,
828 const Instruction* inst,
829 uint16_t inst_data,
830 JValue* result) {
831 const int invoke_method_idx = inst->VRegB();
832 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
833 ArtMethod* invoke_method =
834 class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
835 self, invoke_method_idx, shadow_frame.GetMethod(), kVirtual);
836
837 // Ensure intrinsic identifiers are initialized.
838 DCHECK(invoke_method->IsIntrinsic());
839
840 // Dispatch based on intrinsic identifier associated with method.
841 switch (static_cast<art::Intrinsics>(invoke_method->GetIntrinsic())) {
842#define CASE_SIGNATURE_POLYMORPHIC_INTRINSIC(Name, ...) \
843 case Intrinsics::k##Name: \
844 return Do ## Name(self, shadow_frame, inst, inst_data, result);
845#include "intrinsics_list.h"
846 SIGNATURE_POLYMORPHIC_INTRINSICS_LIST(CASE_SIGNATURE_POLYMORPHIC_INTRINSIC)
847#undef INTRINSICS_LIST
848#undef SIGNATURE_POLYMORPHIC_INTRINSICS_LIST
849#undef CASE_SIGNATURE_POLYMORPHIC_INTRINSIC
850 default:
851 LOG(FATAL) << "Unreachable: " << invoke_method->GetIntrinsic();
852 UNREACHABLE();
853 return false;
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100854 }
855}
856
Orion Hodsona5dca522018-02-27 12:42:11 +0000857static JValue ConvertScalarBootstrapArgument(jvalue value) {
858 // value either contains a primitive scalar value if it corresponds
859 // to a primitive type, or it contains an integer value if it
860 // corresponds to an object instance reference id (e.g. a string id).
861 return JValue::FromPrimitive(value.j);
862}
863
864static ObjPtr<mirror::Class> GetClassForBootstrapArgument(EncodedArrayValueIterator::ValueType type)
865 REQUIRES_SHARED(Locks::mutator_lock_) {
866 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
867 switch (type) {
868 case EncodedArrayValueIterator::ValueType::kBoolean:
869 case EncodedArrayValueIterator::ValueType::kByte:
870 case EncodedArrayValueIterator::ValueType::kChar:
871 case EncodedArrayValueIterator::ValueType::kShort:
872 // These types are disallowed by JVMS. Treat as integers. This
873 // will result in CCE's being raised if the BSM has one of these
874 // types.
875 case EncodedArrayValueIterator::ValueType::kInt:
876 return class_linker->FindPrimitiveClass('I');
877 case EncodedArrayValueIterator::ValueType::kLong:
878 return class_linker->FindPrimitiveClass('J');
879 case EncodedArrayValueIterator::ValueType::kFloat:
880 return class_linker->FindPrimitiveClass('F');
881 case EncodedArrayValueIterator::ValueType::kDouble:
882 return class_linker->FindPrimitiveClass('D');
883 case EncodedArrayValueIterator::ValueType::kMethodType:
884 return mirror::MethodType::StaticClass();
885 case EncodedArrayValueIterator::ValueType::kMethodHandle:
886 return mirror::MethodHandle::StaticClass();
887 case EncodedArrayValueIterator::ValueType::kString:
888 return mirror::String::GetJavaLangString();
889 case EncodedArrayValueIterator::ValueType::kType:
890 return mirror::Class::GetJavaLangClass();
891 case EncodedArrayValueIterator::ValueType::kField:
892 case EncodedArrayValueIterator::ValueType::kMethod:
893 case EncodedArrayValueIterator::ValueType::kEnum:
894 case EncodedArrayValueIterator::ValueType::kArray:
895 case EncodedArrayValueIterator::ValueType::kAnnotation:
896 case EncodedArrayValueIterator::ValueType::kNull:
897 return nullptr;
898 }
899}
900
901static bool GetArgumentForBootstrapMethod(Thread* self,
902 ArtMethod* referrer,
903 EncodedArrayValueIterator::ValueType type,
904 const JValue* encoded_value,
905 JValue* decoded_value)
906 REQUIRES_SHARED(Locks::mutator_lock_) {
907 // The encoded_value contains either a scalar value (IJDF) or a
908 // scalar DEX file index to a reference type to be materialized.
909 switch (type) {
910 case EncodedArrayValueIterator::ValueType::kInt:
911 case EncodedArrayValueIterator::ValueType::kFloat:
912 decoded_value->SetI(encoded_value->GetI());
913 return true;
914 case EncodedArrayValueIterator::ValueType::kLong:
915 case EncodedArrayValueIterator::ValueType::kDouble:
916 decoded_value->SetJ(encoded_value->GetJ());
917 return true;
918 case EncodedArrayValueIterator::ValueType::kMethodType: {
919 StackHandleScope<2> hs(self);
920 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
921 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
Orion Hodson06d10a72018-05-14 08:53:38 +0100922 dex::ProtoIndex proto_idx(encoded_value->GetC());
Orion Hodsona5dca522018-02-27 12:42:11 +0000923 ClassLinker* cl = Runtime::Current()->GetClassLinker();
Orion Hodson06d10a72018-05-14 08:53:38 +0100924 ObjPtr<mirror::MethodType> o =
925 cl->ResolveMethodType(self, proto_idx, dex_cache, class_loader);
Orion Hodsona5dca522018-02-27 12:42:11 +0000926 if (UNLIKELY(o.IsNull())) {
927 DCHECK(self->IsExceptionPending());
928 return false;
929 }
930 decoded_value->SetL(o);
931 return true;
932 }
933 case EncodedArrayValueIterator::ValueType::kMethodHandle: {
934 uint32_t index = static_cast<uint32_t>(encoded_value->GetI());
935 ClassLinker* cl = Runtime::Current()->GetClassLinker();
936 ObjPtr<mirror::MethodHandle> o = cl->ResolveMethodHandle(self, index, referrer);
937 if (UNLIKELY(o.IsNull())) {
938 DCHECK(self->IsExceptionPending());
939 return false;
940 }
941 decoded_value->SetL(o);
942 return true;
943 }
944 case EncodedArrayValueIterator::ValueType::kString: {
945 StackHandleScope<1> hs(self);
946 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
947 dex::StringIndex index(static_cast<uint32_t>(encoded_value->GetI()));
948 ClassLinker* cl = Runtime::Current()->GetClassLinker();
949 ObjPtr<mirror::String> o = cl->ResolveString(index, dex_cache);
950 if (UNLIKELY(o.IsNull())) {
951 DCHECK(self->IsExceptionPending());
952 return false;
953 }
954 decoded_value->SetL(o);
955 return true;
956 }
957 case EncodedArrayValueIterator::ValueType::kType: {
958 StackHandleScope<2> hs(self);
959 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
960 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
961 dex::TypeIndex index(static_cast<uint32_t>(encoded_value->GetI()));
962 ClassLinker* cl = Runtime::Current()->GetClassLinker();
963 ObjPtr<mirror::Class> o = cl->ResolveType(index, dex_cache, class_loader);
964 if (UNLIKELY(o.IsNull())) {
965 DCHECK(self->IsExceptionPending());
966 return false;
967 }
968 decoded_value->SetL(o);
969 return true;
970 }
971 case EncodedArrayValueIterator::ValueType::kBoolean:
972 case EncodedArrayValueIterator::ValueType::kByte:
973 case EncodedArrayValueIterator::ValueType::kChar:
974 case EncodedArrayValueIterator::ValueType::kShort:
975 case EncodedArrayValueIterator::ValueType::kField:
976 case EncodedArrayValueIterator::ValueType::kMethod:
977 case EncodedArrayValueIterator::ValueType::kEnum:
978 case EncodedArrayValueIterator::ValueType::kArray:
979 case EncodedArrayValueIterator::ValueType::kAnnotation:
980 case EncodedArrayValueIterator::ValueType::kNull:
981 // Unreachable - unsupported types that have been checked when
982 // determining the effect call site type based on the bootstrap
983 // argument types.
984 UNREACHABLE();
985 }
986}
987
988static bool PackArgumentForBootstrapMethod(Thread* self,
989 ArtMethod* referrer,
990 CallSiteArrayValueIterator* it,
991 ShadowFrameSetter* setter)
992 REQUIRES_SHARED(Locks::mutator_lock_) {
993 auto type = it->GetValueType();
994 const JValue encoded_value = ConvertScalarBootstrapArgument(it->GetJavaValue());
995 JValue decoded_value;
996 if (!GetArgumentForBootstrapMethod(self, referrer, type, &encoded_value, &decoded_value)) {
997 return false;
998 }
999 switch (it->GetValueType()) {
1000 case EncodedArrayValueIterator::ValueType::kInt:
1001 case EncodedArrayValueIterator::ValueType::kFloat:
1002 setter->Set(static_cast<uint32_t>(decoded_value.GetI()));
1003 return true;
1004 case EncodedArrayValueIterator::ValueType::kLong:
1005 case EncodedArrayValueIterator::ValueType::kDouble:
1006 setter->SetLong(decoded_value.GetJ());
1007 return true;
1008 case EncodedArrayValueIterator::ValueType::kMethodType:
1009 case EncodedArrayValueIterator::ValueType::kMethodHandle:
1010 case EncodedArrayValueIterator::ValueType::kString:
1011 case EncodedArrayValueIterator::ValueType::kType:
1012 setter->SetReference(decoded_value.GetL());
1013 return true;
1014 case EncodedArrayValueIterator::ValueType::kBoolean:
1015 case EncodedArrayValueIterator::ValueType::kByte:
1016 case EncodedArrayValueIterator::ValueType::kChar:
1017 case EncodedArrayValueIterator::ValueType::kShort:
1018 case EncodedArrayValueIterator::ValueType::kField:
1019 case EncodedArrayValueIterator::ValueType::kMethod:
1020 case EncodedArrayValueIterator::ValueType::kEnum:
1021 case EncodedArrayValueIterator::ValueType::kArray:
1022 case EncodedArrayValueIterator::ValueType::kAnnotation:
1023 case EncodedArrayValueIterator::ValueType::kNull:
1024 // Unreachable - unsupported types that have been checked when
1025 // determining the effect call site type based on the bootstrap
1026 // argument types.
1027 UNREACHABLE();
1028 }
1029}
1030
1031static bool PackCollectorArrayForBootstrapMethod(Thread* self,
1032 ArtMethod* referrer,
1033 ObjPtr<mirror::Class> array_type,
1034 int32_t array_length,
1035 CallSiteArrayValueIterator* it,
1036 ShadowFrameSetter* setter)
1037 REQUIRES_SHARED(Locks::mutator_lock_) {
1038 StackHandleScope<1> hs(self);
1039 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
1040 JValue decoded_value;
1041
1042#define COLLECT_PRIMITIVE_ARRAY(Descriptor, Type) \
1043 Handle<mirror::Type ## Array> array = \
1044 hs.NewHandle(mirror::Type ## Array::Alloc(self, array_length)); \
1045 if (array.IsNull()) { \
1046 return false; \
1047 } \
1048 for (int32_t i = 0; it->HasNext(); it->Next(), ++i) { \
1049 auto type = it->GetValueType(); \
1050 DCHECK_EQ(type, EncodedArrayValueIterator::ValueType::k ## Type); \
1051 const JValue encoded_value = \
1052 ConvertScalarBootstrapArgument(it->GetJavaValue()); \
1053 GetArgumentForBootstrapMethod(self, \
1054 referrer, \
1055 type, \
1056 &encoded_value, \
1057 &decoded_value); \
1058 array->Set(i, decoded_value.Get ## Descriptor()); \
1059 } \
1060 setter->SetReference(array.Get()); \
1061 return true;
1062
1063#define COLLECT_REFERENCE_ARRAY(T, Type) \
1064 Handle<mirror::ObjectArray<T>> array = \
1065 hs.NewHandle(mirror::ObjectArray<T>::Alloc(self, \
1066 array_type, \
1067 array_length)); \
1068 if (array.IsNull()) { \
1069 return false; \
1070 } \
1071 for (int32_t i = 0; it->HasNext(); it->Next(), ++i) { \
1072 auto type = it->GetValueType(); \
1073 DCHECK_EQ(type, EncodedArrayValueIterator::ValueType::k ## Type); \
1074 const JValue encoded_value = \
1075 ConvertScalarBootstrapArgument(it->GetJavaValue()); \
1076 if (!GetArgumentForBootstrapMethod(self, \
1077 referrer, \
1078 type, \
1079 &encoded_value, \
1080 &decoded_value)) { \
1081 return false; \
1082 } \
1083 ObjPtr<mirror::Object> o = decoded_value.GetL(); \
1084 if (Runtime::Current()->IsActiveTransaction()) { \
1085 array->Set<true>(i, ObjPtr<T>::DownCast(o)); \
1086 } else { \
1087 array->Set<false>(i, ObjPtr<T>::DownCast(o)); \
1088 } \
1089 } \
1090 setter->SetReference(array.Get()); \
1091 return true;
1092
1093 if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('I')) {
1094 COLLECT_PRIMITIVE_ARRAY(I, Int);
1095 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('J')) {
1096 COLLECT_PRIMITIVE_ARRAY(J, Long);
1097 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('F')) {
1098 COLLECT_PRIMITIVE_ARRAY(F, Float);
1099 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('D')) {
1100 COLLECT_PRIMITIVE_ARRAY(D, Double);
1101 } else if (array_type->GetComponentType() == mirror::MethodType::StaticClass()) {
1102 COLLECT_REFERENCE_ARRAY(mirror::MethodType, MethodType);
1103 } else if (array_type->GetComponentType() == mirror::MethodHandle::StaticClass()) {
1104 COLLECT_REFERENCE_ARRAY(mirror::MethodHandle, MethodHandle);
1105 } else if (array_type->GetComponentType() == mirror::String::GetJavaLangString()) {
1106 COLLECT_REFERENCE_ARRAY(mirror::String, String);
1107 } else if (array_type->GetComponentType() == mirror::Class::GetJavaLangClass()) {
1108 COLLECT_REFERENCE_ARRAY(mirror::Class, Type);
1109 } else {
1110 UNREACHABLE();
1111 }
1112 #undef COLLECT_PRIMITIVE_ARRAY
1113 #undef COLLECT_REFERENCE_ARRAY
1114}
1115
1116static ObjPtr<mirror::MethodType> BuildCallSiteForBootstrapMethod(Thread* self,
1117 const DexFile* dex_file,
1118 uint32_t call_site_idx)
1119 REQUIRES_SHARED(Locks::mutator_lock_) {
1120 const DexFile::CallSiteIdItem& csi = dex_file->GetCallSiteId(call_site_idx);
1121 CallSiteArrayValueIterator it(*dex_file, csi);
1122 DCHECK_GE(it.Size(), 1u);
1123
1124 StackHandleScope<2> hs(self);
1125 // Create array for parameter types.
1126 ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
1127 mirror::Class* class_array_type =
1128 Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_type);
1129 Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle(
1130 mirror::ObjectArray<mirror::Class>::Alloc(self,
1131 class_array_type,
1132 static_cast<int>(it.Size())));
1133 if (ptypes.IsNull()) {
1134 DCHECK(self->IsExceptionPending());
1135 return nullptr;
1136 }
1137
1138 // Populate the first argument with an instance of j.l.i.MethodHandles.Lookup
1139 // that the runtime will construct.
1140 ptypes->Set(0, mirror::MethodHandlesLookup::StaticClass());
1141 it.Next();
1142
1143 // The remaining parameter types are derived from the types of
1144 // arguments present in the DEX file.
1145 int index = 1;
1146 while (it.HasNext()) {
1147 ObjPtr<mirror::Class> ptype = GetClassForBootstrapArgument(it.GetValueType());
1148 if (ptype.IsNull()) {
1149 ThrowClassCastException("Unsupported bootstrap argument type");
1150 return nullptr;
1151 }
1152 ptypes->Set(index, ptype);
1153 index++;
1154 it.Next();
1155 }
1156 DCHECK_EQ(static_cast<size_t>(index), it.Size());
1157
1158 // By definition, the return type is always a j.l.i.CallSite.
1159 Handle<mirror::Class> rtype = hs.NewHandle(mirror::CallSite::StaticClass());
1160 return mirror::MethodType::Create(self, rtype, ptypes);
1161}
1162
Orion Hodsonc069a302017-01-18 09:23:12 +00001163static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self,
1164 ShadowFrame& shadow_frame,
1165 uint32_t call_site_idx)
1166 REQUIRES_SHARED(Locks::mutator_lock_) {
Orion Hodsona5dca522018-02-27 12:42:11 +00001167 StackHandleScope<7> hs(self);
1168 // There are three mandatory arguments expected from the call site
1169 // value array in the DEX file: the bootstrap method handle, the
1170 // method name to pass to the bootstrap method, and the method type
1171 // to pass to the bootstrap method.
1172 static constexpr size_t kMandatoryArgumentsCount = 3;
Orion Hodsonc069a302017-01-18 09:23:12 +00001173 ArtMethod* referrer = shadow_frame.GetMethod();
1174 const DexFile* dex_file = referrer->GetDexFile();
1175 const DexFile::CallSiteIdItem& csi = dex_file->GetCallSiteId(call_site_idx);
Orion Hodsonc069a302017-01-18 09:23:12 +00001176 CallSiteArrayValueIterator it(*dex_file, csi);
Orion Hodsona5dca522018-02-27 12:42:11 +00001177 if (it.Size() < kMandatoryArgumentsCount) {
1178 ThrowBootstrapMethodError("Truncated bootstrap arguments (%zu < %zu)",
1179 it.Size(), kMandatoryArgumentsCount);
1180 return nullptr;
1181 }
1182
1183 if (it.GetValueType() != EncodedArrayValueIterator::ValueType::kMethodHandle) {
1184 ThrowBootstrapMethodError("First bootstrap argument is not a method handle");
1185 return nullptr;
1186 }
1187
1188 uint32_t bsm_index = static_cast<uint32_t>(it.GetJavaValue().i);
1189 it.Next();
1190
Orion Hodsonc069a302017-01-18 09:23:12 +00001191 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Orion Hodsona5dca522018-02-27 12:42:11 +00001192 Handle<mirror::MethodHandle> bsm =
1193 hs.NewHandle(class_linker->ResolveMethodHandle(self, bsm_index, referrer));
1194 if (bsm.IsNull()) {
Orion Hodsonc069a302017-01-18 09:23:12 +00001195 DCHECK(self->IsExceptionPending());
1196 return nullptr;
1197 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001198
Orion Hodsona5dca522018-02-27 12:42:11 +00001199 if (bsm->GetHandleKind() != mirror::MethodHandle::Kind::kInvokeStatic) {
1200 // JLS suggests also accepting constructors. This is currently
1201 // hard as constructor invocations happen via transformers in ART
1202 // today. The constructor would need to be a class derived from java.lang.invoke.CallSite.
1203 ThrowBootstrapMethodError("Unsupported bootstrap method invocation kind");
1204 return nullptr;
1205 }
1206
1207 // Construct the local call site type information based on the 3
1208 // mandatory arguments provided by the runtime and the static arguments
1209 // in the DEX file. We will use these arguments to build a shadow frame.
1210 MutableHandle<mirror::MethodType> call_site_type =
1211 hs.NewHandle(BuildCallSiteForBootstrapMethod(self, dex_file, call_site_idx));
1212 if (call_site_type.IsNull()) {
1213 DCHECK(self->IsExceptionPending());
1214 return nullptr;
1215 }
1216
1217 // Check if this BSM is targeting a variable arity method. If so,
1218 // we'll need to collect the trailing arguments into an array.
1219 Handle<mirror::Array> collector_arguments;
1220 int32_t collector_arguments_length;
1221 if (bsm->GetTargetMethod()->IsVarargs()) {
1222 int number_of_bsm_parameters = bsm->GetMethodType()->GetNumberOfPTypes();
1223 if (number_of_bsm_parameters == 0) {
1224 ThrowBootstrapMethodError("Variable arity BSM does not have any arguments");
1225 return nullptr;
1226 }
1227 Handle<mirror::Class> collector_array_class =
1228 hs.NewHandle(bsm->GetMethodType()->GetPTypes()->Get(number_of_bsm_parameters - 1));
1229 if (!collector_array_class->IsArrayClass()) {
1230 ThrowBootstrapMethodError("Variable arity BSM does not have array as final argument");
1231 return nullptr;
1232 }
1233 // The call site may include no arguments to be collected. In this
1234 // case the number of arguments must be at least the number of BSM
1235 // parameters less the collector array.
1236 if (call_site_type->GetNumberOfPTypes() < number_of_bsm_parameters - 1) {
1237 ThrowWrongMethodTypeException(bsm->GetMethodType(), call_site_type.Get());
1238 return nullptr;
1239 }
1240 // Check all the arguments to be collected match the collector array component type.
1241 for (int i = number_of_bsm_parameters - 1; i < call_site_type->GetNumberOfPTypes(); ++i) {
1242 if (call_site_type->GetPTypes()->Get(i) != collector_array_class->GetComponentType()) {
1243 ThrowClassCastException(collector_array_class->GetComponentType(),
1244 call_site_type->GetPTypes()->Get(i));
1245 return nullptr;
1246 }
1247 }
1248 // Update the call site method type so it now includes the collector array.
1249 int32_t collector_arguments_start = number_of_bsm_parameters - 1;
1250 collector_arguments_length = call_site_type->GetNumberOfPTypes() - number_of_bsm_parameters + 1;
1251 call_site_type.Assign(
1252 mirror::MethodType::CollectTrailingArguments(self,
1253 call_site_type.Get(),
1254 collector_array_class.Get(),
1255 collector_arguments_start));
1256 if (call_site_type.IsNull()) {
1257 DCHECK(self->IsExceptionPending());
1258 return nullptr;
1259 }
1260 } else {
1261 collector_arguments_length = 0;
1262 }
1263
1264 if (call_site_type->GetNumberOfPTypes() != bsm->GetMethodType()->GetNumberOfPTypes()) {
1265 ThrowWrongMethodTypeException(bsm->GetMethodType(), call_site_type.Get());
1266 return nullptr;
1267 }
1268
1269 // BSM invocation has a different set of exceptions that
1270 // j.l.i.MethodHandle.invoke(). Scan arguments looking for CCE
1271 // "opportunities". Unfortunately we cannot just leave this to the
1272 // method handle invocation as this might generate a WMTE.
1273 for (int32_t i = 0; i < call_site_type->GetNumberOfPTypes(); ++i) {
1274 ObjPtr<mirror::Class> from = call_site_type->GetPTypes()->Get(i);
1275 ObjPtr<mirror::Class> to = bsm->GetMethodType()->GetPTypes()->Get(i);
1276 if (!IsParameterTypeConvertible(from, to)) {
1277 ThrowClassCastException(from, to);
1278 return nullptr;
1279 }
1280 }
1281 if (!IsReturnTypeConvertible(call_site_type->GetRType(), bsm->GetMethodType()->GetRType())) {
1282 ThrowClassCastException(bsm->GetMethodType()->GetRType(), call_site_type->GetRType());
1283 return nullptr;
1284 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001285
1286 // Set-up a shadow frame for invoking the bootstrap method handle.
1287 ShadowFrameAllocaUniquePtr bootstrap_frame =
Orion Hodsona5dca522018-02-27 12:42:11 +00001288 CREATE_SHADOW_FRAME(call_site_type->NumberOfVRegs(),
1289 nullptr,
1290 referrer,
1291 shadow_frame.GetDexPC());
Orion Hodsonc069a302017-01-18 09:23:12 +00001292 ScopedStackedShadowFramePusher pusher(
1293 self, bootstrap_frame.get(), StackedShadowFrameType::kShadowFrameUnderConstruction);
Orion Hodsona5dca522018-02-27 12:42:11 +00001294 ShadowFrameSetter setter(bootstrap_frame.get(), 0u);
Orion Hodsonc069a302017-01-18 09:23:12 +00001295
1296 // The first parameter is a MethodHandles lookup instance.
Orion Hodsona5dca522018-02-27 12:42:11 +00001297 Handle<mirror::Class> lookup_class =
1298 hs.NewHandle(shadow_frame.GetMethod()->GetDeclaringClass());
1299 ObjPtr<mirror::MethodHandlesLookup> lookup =
1300 mirror::MethodHandlesLookup::Create(self, lookup_class);
1301 if (lookup.IsNull()) {
Orion Hodsonc069a302017-01-18 09:23:12 +00001302 DCHECK(self->IsExceptionPending());
1303 return nullptr;
1304 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001305 setter.SetReference(lookup);
Orion Hodsonc069a302017-01-18 09:23:12 +00001306
Orion Hodsona5dca522018-02-27 12:42:11 +00001307 // Pack the remaining arguments into the frame.
1308 int number_of_arguments = call_site_type->GetNumberOfPTypes();
1309 int argument_index;
1310 for (argument_index = 1; argument_index < number_of_arguments; ++argument_index) {
1311 if (argument_index == number_of_arguments - 1 &&
1312 call_site_type->GetPTypes()->Get(argument_index)->IsArrayClass()) {
1313 ObjPtr<mirror::Class> array_type = call_site_type->GetPTypes()->Get(argument_index);
1314 if (!PackCollectorArrayForBootstrapMethod(self,
1315 referrer,
1316 array_type,
1317 collector_arguments_length,
1318 &it,
1319 &setter)) {
1320 DCHECK(self->IsExceptionPending());
1321 return nullptr;
Orion Hodsonc069a302017-01-18 09:23:12 +00001322 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001323 } else if (!PackArgumentForBootstrapMethod(self, referrer, &it, &setter)) {
1324 DCHECK(self->IsExceptionPending());
1325 return nullptr;
Orion Hodsonc069a302017-01-18 09:23:12 +00001326 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001327 it.Next();
1328 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001329 DCHECK(!it.HasNext());
1330 DCHECK(setter.Done());
Orion Hodsonc069a302017-01-18 09:23:12 +00001331
1332 // Invoke the bootstrap method handle.
1333 JValue result;
Orion Hodsona5dca522018-02-27 12:42:11 +00001334 RangeInstructionOperands operands(0, bootstrap_frame->NumberOfVRegs());
1335 bool invoke_success = MethodHandleInvoke(self,
1336 *bootstrap_frame,
1337 bsm,
1338 call_site_type,
1339 &operands,
1340 &result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001341 if (!invoke_success) {
1342 DCHECK(self->IsExceptionPending());
1343 return nullptr;
1344 }
1345
1346 Handle<mirror::Object> object(hs.NewHandle(result.GetL()));
Orion Hodsonc069a302017-01-18 09:23:12 +00001347 if (UNLIKELY(object.IsNull())) {
Orion Hodsonda1cdd02018-01-31 18:08:28 +00001348 // This will typically be for LambdaMetafactory which is not supported.
Orion Hodson76e6adb2018-02-23 13:15:55 +00001349 ThrowClassCastException("Bootstrap method returned null");
Orion Hodsonc069a302017-01-18 09:23:12 +00001350 return nullptr;
1351 }
1352
Orion Hodsona5dca522018-02-27 12:42:11 +00001353 // Check the result type is a subclass of j.l.i.CallSite.
Orion Hodsonc069a302017-01-18 09:23:12 +00001354 if (UNLIKELY(!object->InstanceOf(mirror::CallSite::StaticClass()))) {
1355 ThrowClassCastException(object->GetClass(), mirror::CallSite::StaticClass());
1356 return nullptr;
1357 }
1358
Orion Hodsona5dca522018-02-27 12:42:11 +00001359 // Check the call site target is not null as we're going to invoke it.
Orion Hodsonc069a302017-01-18 09:23:12 +00001360 Handle<mirror::CallSite> call_site =
1361 hs.NewHandle(ObjPtr<mirror::CallSite>::DownCast(ObjPtr<mirror::Object>(result.GetL())));
Orion Hodsonc069a302017-01-18 09:23:12 +00001362 Handle<mirror::MethodHandle> target = hs.NewHandle(call_site->GetTarget());
1363 if (UNLIKELY(target.IsNull())) {
Orion Hodsona5dca522018-02-27 12:42:11 +00001364 ThrowClassCastException("Bootstrap method returned a CallSite with a null target");
Orion Hodsonc069a302017-01-18 09:23:12 +00001365 return nullptr;
1366 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001367 return call_site.Get();
1368}
1369
1370template<bool is_range>
1371bool DoInvokeCustom(Thread* self,
1372 ShadowFrame& shadow_frame,
1373 const Instruction* inst,
1374 uint16_t inst_data,
1375 JValue* result)
1376 REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Light848574c2017-09-25 16:59:39 -07001377 // Make sure to check for async exceptions
1378 if (UNLIKELY(self->ObserveAsyncException())) {
1379 return false;
1380 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001381 // invoke-custom is not supported in transactions. In transactions
1382 // there is a limited set of types supported. invoke-custom allows
1383 // running arbitrary code and instantiating arbitrary types.
1384 CHECK(!Runtime::Current()->IsActiveTransaction());
1385 StackHandleScope<4> hs(self);
1386 Handle<mirror::DexCache> dex_cache(hs.NewHandle(shadow_frame.GetMethod()->GetDexCache()));
1387 const uint32_t call_site_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
1388 MutableHandle<mirror::CallSite>
1389 call_site(hs.NewHandle(dex_cache->GetResolvedCallSite(call_site_idx)));
1390 if (call_site.IsNull()) {
1391 call_site.Assign(InvokeBootstrapMethod(self, shadow_frame, call_site_idx));
1392 if (UNLIKELY(call_site.IsNull())) {
1393 CHECK(self->IsExceptionPending());
Orion Hodsona5dca522018-02-27 12:42:11 +00001394 if (!self->GetException()->IsError()) {
1395 // Use a BootstrapMethodError if the exception is not an instance of java.lang.Error.
1396 ThrowWrappedBootstrapMethodError("Exception from call site #%u bootstrap method",
1397 call_site_idx);
1398 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001399 result->SetJ(0);
1400 return false;
1401 }
1402 mirror::CallSite* winning_call_site =
1403 dex_cache->SetResolvedCallSite(call_site_idx, call_site.Get());
1404 call_site.Assign(winning_call_site);
1405 }
1406
Orion Hodsonc069a302017-01-18 09:23:12 +00001407 Handle<mirror::MethodHandle> target = hs.NewHandle(call_site->GetTarget());
1408 Handle<mirror::MethodType> target_method_type = hs.NewHandle(target->GetMethodType());
1409 DCHECK_EQ(static_cast<size_t>(inst->VRegA()), target_method_type->NumberOfVRegs());
Orion Hodsonc069a302017-01-18 09:23:12 +00001410 if (is_range) {
Orion Hodson960d4f72017-11-10 15:32:38 +00001411 RangeInstructionOperands operands(inst->VRegC_3rc(), inst->VRegA_3rc());
1412 return MethodHandleInvokeExact(self,
1413 shadow_frame,
1414 target,
1415 target_method_type,
1416 &operands,
1417 result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001418 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +00001419 uint32_t args[Instruction::kMaxVarArgRegs];
Orion Hodsonc069a302017-01-18 09:23:12 +00001420 inst->GetVarArgs(args, inst_data);
Orion Hodson960d4f72017-11-10 15:32:38 +00001421 VarArgsInstructionOperands operands(args, inst->VRegA_35c());
1422 return MethodHandleInvokeExact(self,
1423 shadow_frame,
1424 target,
1425 target_method_type,
1426 &operands,
1427 result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001428 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001429}
1430
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001431template <bool is_range>
1432inline void CopyRegisters(ShadowFrame& caller_frame,
1433 ShadowFrame* callee_frame,
1434 const uint32_t (&arg)[Instruction::kMaxVarArgRegs],
1435 const size_t first_src_reg,
1436 const size_t first_dest_reg,
1437 const size_t num_regs) {
1438 if (is_range) {
1439 const size_t dest_reg_bound = first_dest_reg + num_regs;
1440 for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < dest_reg_bound;
1441 ++dest_reg, ++src_reg) {
1442 AssignRegister(callee_frame, caller_frame, dest_reg, src_reg);
1443 }
1444 } else {
1445 DCHECK_LE(num_regs, arraysize(arg));
1446
1447 for (size_t arg_index = 0; arg_index < num_regs; ++arg_index) {
1448 AssignRegister(callee_frame, caller_frame, first_dest_reg + arg_index, arg[arg_index]);
1449 }
1450 }
1451}
1452
Igor Murashkin6918bf12015-09-27 19:19:06 -07001453template <bool is_range,
Narayan Kamath370423d2016-10-03 16:51:22 +01001454 bool do_assignability_check>
Igor Murashkin158f35c2015-06-10 15:55:30 -07001455static inline bool DoCallCommon(ArtMethod* called_method,
1456 Thread* self,
1457 ShadowFrame& shadow_frame,
1458 JValue* result,
1459 uint16_t number_of_inputs,
Narayan Kamath370423d2016-10-03 16:51:22 +01001460 uint32_t (&arg)[Instruction::kMaxVarArgRegs],
Igor Murashkin158f35c2015-06-10 15:55:30 -07001461 uint32_t vregC) {
Jeff Hao848f70a2014-01-15 13:49:50 -08001462 bool string_init = false;
1463 // Replace calls to String.<init> with equivalent StringFactory call.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001464 if (UNLIKELY(called_method->GetDeclaringClass()->IsStringClass()
1465 && called_method->IsConstructor())) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01001466 called_method = WellKnownClasses::StringInitToStringFactory(called_method);
Jeff Hao848f70a2014-01-15 13:49:50 -08001467 string_init = true;
1468 }
1469
Alex Lightdaf58c82016-03-16 23:00:49 +00001470 // Compute method information.
David Sehr0225f8e2018-01-31 08:52:24 +00001471 CodeItemDataAccessor accessor(called_method->DexInstructionData());
Igor Murashkin158f35c2015-06-10 15:55:30 -07001472 // Number of registers for the callee's call frame.
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001473 uint16_t num_regs;
Jeff Hao5ea84132017-05-05 16:59:29 -07001474 // Test whether to use the interpreter or compiler entrypoint, and save that result to pass to
1475 // PerformCall. A deoptimization could occur at any time, and we shouldn't change which
1476 // entrypoint to use once we start building the shadow frame.
Mathieu Chartier448bbcf2017-07-06 12:05:13 -07001477
1478 // For unstarted runtimes, always use the interpreter entrypoint. This fixes the case where we are
1479 // doing cross compilation. Note that GetEntryPointFromQuickCompiledCode doesn't use the image
1480 // pointer size here and this may case an overflow if it is called from the compiler. b/62402160
1481 const bool use_interpreter_entrypoint = !Runtime::Current()->IsStarted() ||
1482 ClassLinker::ShouldUseInterpreterEntrypoint(
1483 called_method,
1484 called_method->GetEntryPointFromQuickCompiledCode());
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001485 if (LIKELY(accessor.HasCodeItem())) {
Jeff Hao5ea84132017-05-05 16:59:29 -07001486 // When transitioning to compiled code, space only needs to be reserved for the input registers.
1487 // The rest of the frame gets discarded. This also prevents accessing the called method's code
1488 // item, saving memory by keeping code items of compiled code untouched.
Mathieu Chartier448bbcf2017-07-06 12:05:13 -07001489 if (!use_interpreter_entrypoint) {
1490 DCHECK(!Runtime::Current()->IsAotCompiler()) << "Compiler should use interpreter entrypoint";
Jeff Hao5ea84132017-05-05 16:59:29 -07001491 num_regs = number_of_inputs;
1492 } else {
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001493 num_regs = accessor.RegistersSize();
1494 DCHECK_EQ(string_init ? number_of_inputs - 1 : number_of_inputs, accessor.InsSize());
Jeff Hao5ea84132017-05-05 16:59:29 -07001495 }
Nicolas Geoffray01822292017-03-09 09:03:19 +00001496 } else {
1497 DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
1498 num_regs = number_of_inputs;
Jeff Haodf79ddb2017-02-27 14:47:06 -08001499 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001500
Igor Murashkin158f35c2015-06-10 15:55:30 -07001501 // Hack for String init:
1502 //
1503 // Rewrite invoke-x java.lang.String.<init>(this, a, b, c, ...) into:
1504 // invoke-x StringFactory(a, b, c, ...)
1505 // by effectively dropping the first virtual register from the invoke.
1506 //
1507 // (at this point the ArtMethod has already been replaced,
1508 // so we just need to fix-up the arguments)
David Brazdil65902e82016-01-15 09:35:13 +00001509 //
1510 // Note that FindMethodFromCode in entrypoint_utils-inl.h was also special-cased
1511 // to handle the compiler optimization of replacing `this` with null without
1512 // throwing NullPointerException.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001513 uint32_t string_init_vreg_this = is_range ? vregC : arg[0];
Igor Murashkina06b49b2015-06-25 15:18:12 -07001514 if (UNLIKELY(string_init)) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001515 DCHECK_GT(num_regs, 0u); // As the method is an instance method, there should be at least 1.
Igor Murashkina06b49b2015-06-25 15:18:12 -07001516
Igor Murashkin158f35c2015-06-10 15:55:30 -07001517 // The new StringFactory call is static and has one fewer argument.
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001518 if (!accessor.HasCodeItem()) {
Igor Murashkina06b49b2015-06-25 15:18:12 -07001519 DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
1520 num_regs--;
1521 } // else ... don't need to change num_regs since it comes up from the string_init's code item
Igor Murashkin158f35c2015-06-10 15:55:30 -07001522 number_of_inputs--;
1523
1524 // Rewrite the var-args, dropping the 0th argument ("this")
Igor Murashkin6918bf12015-09-27 19:19:06 -07001525 for (uint32_t i = 1; i < arraysize(arg); ++i) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001526 arg[i - 1] = arg[i];
1527 }
Igor Murashkin6918bf12015-09-27 19:19:06 -07001528 arg[arraysize(arg) - 1] = 0;
Igor Murashkin158f35c2015-06-10 15:55:30 -07001529
1530 // Rewrite the non-var-arg case
1531 vregC++; // Skips the 0th vreg in the range ("this").
1532 }
1533
1534 // Parameter registers go at the end of the shadow frame.
1535 DCHECK_GE(num_regs, number_of_inputs);
1536 size_t first_dest_reg = num_regs - number_of_inputs;
1537 DCHECK_NE(first_dest_reg, (size_t)-1);
1538
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001539 // Allocate shadow frame on the stack.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001540 const char* old_cause = self->StartAssertNoThreadSuspension("DoCallCommon");
Andreas Gampeb3025922015-09-01 14:45:00 -07001541 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe03ec9302015-08-27 17:41:47 -07001542 CREATE_SHADOW_FRAME(num_regs, &shadow_frame, called_method, /* dex pc */ 0);
Andreas Gampeb3025922015-09-01 14:45:00 -07001543 ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get();
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001544
Igor Murashkin158f35c2015-06-10 15:55:30 -07001545 // Initialize new shadow frame by copying the registers from the callee shadow frame.
Jeff Haoa3faaf42013-09-03 19:07:00 -07001546 if (do_assignability_check) {
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001547 // Slow path.
1548 // We might need to do class loading, which incurs a thread state change to kNative. So
1549 // register the shadow frame as under construction and allow suspension again.
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -07001550 ScopedStackedShadowFramePusher pusher(
Sebastien Hertzf7958692015-06-09 14:09:14 +02001551 self, new_shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction);
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001552 self->EndAssertNoThreadSuspension(old_cause);
1553
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001554 // ArtMethod here is needed to check type information of the call site against the callee.
1555 // Type information is retrieved from a DexFile/DexCache for that respective declared method.
1556 //
1557 // As a special case for proxy methods, which are not dex-backed,
1558 // we have to retrieve type information from the proxy's method
1559 // interface method instead (which is dex backed since proxies are never interfaces).
Andreas Gampe542451c2016-07-26 09:02:02 -07001560 ArtMethod* method =
1561 new_shadow_frame->GetMethod()->GetInterfaceMethodIfProxy(kRuntimePointerSize);
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001562
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001563 // We need to do runtime check on reference assignment. We need to load the shorty
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001564 // to get the exact type of each reference argument.
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001565 const DexFile::TypeList* params = method->GetParameterTypeList();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001566 uint32_t shorty_len = 0;
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001567 const char* shorty = method->GetShorty(&shorty_len);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001568
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001569 // Handle receiver apart since it's not part of the shorty.
1570 size_t dest_reg = first_dest_reg;
1571 size_t arg_offset = 0;
Igor Murashkin158f35c2015-06-10 15:55:30 -07001572
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001573 if (!method->IsStatic()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001574 size_t receiver_reg = is_range ? vregC : arg[0];
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001575 new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg));
1576 ++dest_reg;
1577 ++arg_offset;
Igor Murashkina06b49b2015-06-25 15:18:12 -07001578 DCHECK(!string_init); // All StringFactory methods are static.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001579 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001580
1581 // Copy the caller's invoke-* arguments into the callee's parameter registers.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001582 for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) {
Igor Murashkina06b49b2015-06-25 15:18:12 -07001583 // Skip the 0th 'shorty' type since it represents the return type.
1584 DCHECK_LT(shorty_pos + 1, shorty_len) << "for shorty '" << shorty << "'";
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001585 const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset];
1586 switch (shorty[shorty_pos + 1]) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001587 // Handle Object references. 1 virtual register slot.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001588 case 'L': {
Mathieu Chartieref41db72016-10-25 15:08:01 -07001589 ObjPtr<mirror::Object> o = shadow_frame.GetVRegReference(src_reg);
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001590 if (do_assignability_check && o != nullptr) {
Andreas Gampea5b09a62016-11-17 15:21:22 -08001591 const dex::TypeIndex type_idx = params->GetTypeItem(shorty_pos).type_idx_;
Vladimir Marko942fd312017-01-16 20:52:19 +00001592 ObjPtr<mirror::Class> arg_type = method->GetDexCache()->GetResolvedType(type_idx);
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001593 if (arg_type == nullptr) {
Mathieu Chartiere22305b2016-10-26 21:04:58 -07001594 StackHandleScope<1> hs(self);
1595 // Preserve o since it is used below and GetClassFromTypeIndex may cause thread
1596 // suspension.
1597 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&o);
Vladimir Markob45528c2017-07-27 14:14:28 +01001598 arg_type = method->ResolveClassFromTypeIndex(type_idx);
Mathieu Chartiere22305b2016-10-26 21:04:58 -07001599 if (arg_type == nullptr) {
1600 CHECK(self->IsExceptionPending());
1601 return false;
1602 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001603 }
1604 if (!o->VerifierInstanceOf(arg_type)) {
1605 // This should never happen.
Ian Rogers1ff3c982014-08-12 02:30:58 -07001606 std::string temp1, temp2;
Orion Hodsonfef06642016-11-25 16:07:11 +00001607 self->ThrowNewExceptionF("Ljava/lang/InternalError;",
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001608 "Invoking %s with bad arg %d, type '%s' not instance of '%s'",
Ian Rogerse94652f2014-12-02 11:13:19 -08001609 new_shadow_frame->GetMethod()->GetName(), shorty_pos,
Ian Rogers1ff3c982014-08-12 02:30:58 -07001610 o->GetClass()->GetDescriptor(&temp1),
1611 arg_type->GetDescriptor(&temp2));
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001612 return false;
1613 }
Jeff Haoa3faaf42013-09-03 19:07:00 -07001614 }
Mathieu Chartieref41db72016-10-25 15:08:01 -07001615 new_shadow_frame->SetVRegReference(dest_reg, o.Ptr());
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001616 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -07001617 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001618 // Handle doubles and longs. 2 consecutive virtual register slots.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001619 case 'J': case 'D': {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001620 uint64_t wide_value =
1621 (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << BitSizeOf<uint32_t>()) |
1622 static_cast<uint32_t>(shadow_frame.GetVReg(src_reg));
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001623 new_shadow_frame->SetVRegLong(dest_reg, wide_value);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001624 // Skip the next virtual register slot since we already used it.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001625 ++dest_reg;
1626 ++arg_offset;
1627 break;
1628 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001629 // Handle all other primitives that are always 1 virtual register slot.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001630 default:
1631 new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg));
1632 break;
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001633 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001634 }
1635 } else {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001636 if (is_range) {
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001637 DCHECK_EQ(num_regs, first_dest_reg + number_of_inputs);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001638 }
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001639
1640 CopyRegisters<is_range>(shadow_frame,
1641 new_shadow_frame,
1642 arg,
1643 vregC,
1644 first_dest_reg,
1645 number_of_inputs);
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001646 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001647 }
1648
Jeff Hao5ea84132017-05-05 16:59:29 -07001649 PerformCall(self,
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001650 accessor,
Jeff Hao5ea84132017-05-05 16:59:29 -07001651 shadow_frame.GetMethod(),
1652 first_dest_reg,
1653 new_shadow_frame,
1654 result,
1655 use_interpreter_entrypoint);
Jeff Hao848f70a2014-01-15 13:49:50 -08001656
1657 if (string_init && !self->IsExceptionPending()) {
Mingyao Yangffedec52016-05-19 10:48:40 -07001658 SetStringInitValueToAllAliases(&shadow_frame, string_init_vreg_this, *result);
Jeff Hao848f70a2014-01-15 13:49:50 -08001659 }
1660
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001661 return !self->IsExceptionPending();
1662}
1663
Igor Murashkin158f35c2015-06-10 15:55:30 -07001664template<bool is_range, bool do_assignability_check>
Igor Murashkin158f35c2015-06-10 15:55:30 -07001665bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
1666 const Instruction* inst, uint16_t inst_data, JValue* result) {
1667 // Argument word count.
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001668 const uint16_t number_of_inputs =
1669 (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001670
1671 // TODO: find a cleaner way to separate non-range and range information without duplicating
1672 // code.
Igor Murashkin6918bf12015-09-27 19:19:06 -07001673 uint32_t arg[Instruction::kMaxVarArgRegs] = {}; // only used in invoke-XXX.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001674 uint32_t vregC = 0;
1675 if (is_range) {
1676 vregC = inst->VRegC_3rc();
1677 } else {
1678 vregC = inst->VRegC_35c();
1679 inst->GetVarArgs(arg, inst_data);
1680 }
1681
1682 return DoCallCommon<is_range, do_assignability_check>(
1683 called_method, self, shadow_frame,
1684 result, number_of_inputs, arg, vregC);
1685}
1686
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001687template <bool is_range, bool do_access_check, bool transaction_active>
Mathieu Chartieref41db72016-10-25 15:08:01 -07001688bool DoFilledNewArray(const Instruction* inst,
1689 const ShadowFrame& shadow_frame,
1690 Thread* self,
1691 JValue* result) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001692 DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY ||
1693 inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE);
1694 const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c();
1695 if (!is_range) {
1696 // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments.
1697 CHECK_LE(length, 5);
1698 }
1699 if (UNLIKELY(length < 0)) {
1700 ThrowNegativeArraySizeException(length);
1701 return false;
1702 }
1703 uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
Andreas Gampea5b09a62016-11-17 15:21:22 -08001704 ObjPtr<mirror::Class> array_class = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
Mathieu Chartieref41db72016-10-25 15:08:01 -07001705 shadow_frame.GetMethod(),
1706 self,
1707 false,
1708 do_access_check);
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001709 if (UNLIKELY(array_class == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001710 DCHECK(self->IsExceptionPending());
1711 return false;
1712 }
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001713 CHECK(array_class->IsArrayClass());
Mathieu Chartieref41db72016-10-25 15:08:01 -07001714 ObjPtr<mirror::Class> component_class = array_class->GetComponentType();
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001715 const bool is_primitive_int_component = component_class->IsPrimitiveInt();
1716 if (UNLIKELY(component_class->IsPrimitive() && !is_primitive_int_component)) {
1717 if (component_class->IsPrimitiveLong() || component_class->IsPrimitiveDouble()) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001718 ThrowRuntimeException("Bad filled array request for type %s",
David Sehr709b0702016-10-13 09:12:37 -07001719 component_class->PrettyDescriptor().c_str());
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001720 } else {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +00001721 self->ThrowNewExceptionF("Ljava/lang/InternalError;",
Brian Carlstrom4fa0bcd2013-12-10 11:24:21 -08001722 "Found type %s; filled-new-array not implemented for anything but 'int'",
David Sehr709b0702016-10-13 09:12:37 -07001723 component_class->PrettyDescriptor().c_str());
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001724 }
1725 return false;
1726 }
Mathieu Chartieref41db72016-10-25 15:08:01 -07001727 ObjPtr<mirror::Object> new_array = mirror::Array::Alloc<true>(
1728 self,
1729 array_class,
1730 length,
1731 array_class->GetComponentSizeShift(),
1732 Runtime::Current()->GetHeap()->GetCurrentAllocator());
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001733 if (UNLIKELY(new_array == nullptr)) {
1734 self->AssertPendingOOMException();
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001735 return false;
1736 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001737 uint32_t arg[Instruction::kMaxVarArgRegs]; // only used in filled-new-array.
1738 uint32_t vregC = 0; // only used in filled-new-array-range.
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001739 if (is_range) {
Sebastien Hertzabff6432014-01-27 18:01:39 +01001740 vregC = inst->VRegC_3rc();
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001741 } else {
Ian Rogers29a26482014-05-02 15:27:29 -07001742 inst->GetVarArgs(arg);
Sebastien Hertzabff6432014-01-27 18:01:39 +01001743 }
Sebastien Hertzabff6432014-01-27 18:01:39 +01001744 for (int32_t i = 0; i < length; ++i) {
1745 size_t src_reg = is_range ? vregC + i : arg[i];
1746 if (is_primitive_int_component) {
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001747 new_array->AsIntArray()->SetWithoutChecks<transaction_active>(
1748 i, shadow_frame.GetVReg(src_reg));
Sebastien Hertzabff6432014-01-27 18:01:39 +01001749 } else {
Mathieu Chartieref41db72016-10-25 15:08:01 -07001750 new_array->AsObjectArray<mirror::Object>()->SetWithoutChecks<transaction_active>(
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001751 i, shadow_frame.GetVRegReference(src_reg));
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001752 }
1753 }
1754
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001755 result->SetL(new_array);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001756 return true;
1757}
1758
Mathieu Chartieref41db72016-10-25 15:08:01 -07001759// TODO: Use ObjPtr here.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001760template<typename T>
Mathieu Chartieref41db72016-10-25 15:08:01 -07001761static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array,
1762 int32_t count)
1763 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001764 Runtime* runtime = Runtime::Current();
1765 for (int32_t i = 0; i < count; ++i) {
1766 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i));
1767 }
1768}
1769
Mathieu Chartieref41db72016-10-25 15:08:01 -07001770void RecordArrayElementsInTransaction(ObjPtr<mirror::Array> array, int32_t count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001771 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001772 DCHECK(Runtime::Current()->IsActiveTransaction());
1773 DCHECK(array != nullptr);
1774 DCHECK_LE(count, array->GetLength());
1775 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType();
1776 switch (primitive_component_type) {
1777 case Primitive::kPrimBoolean:
1778 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count);
1779 break;
1780 case Primitive::kPrimByte:
1781 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count);
1782 break;
1783 case Primitive::kPrimChar:
1784 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count);
1785 break;
1786 case Primitive::kPrimShort:
1787 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count);
1788 break;
1789 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001790 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count);
1791 break;
Mathieu Chartiere401d142015-04-22 13:56:20 -07001792 case Primitive::kPrimFloat:
1793 RecordArrayElementsInTransactionImpl(array->AsFloatArray(), count);
1794 break;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001795 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001796 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count);
1797 break;
Mathieu Chartiere401d142015-04-22 13:56:20 -07001798 case Primitive::kPrimDouble:
1799 RecordArrayElementsInTransactionImpl(array->AsDoubleArray(), count);
1800 break;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001801 default:
1802 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type
1803 << " in fill-array-data";
1804 break;
1805 }
1806}
1807
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001808// Explicit DoCall template function declarations.
Sebastien Hertzc6714852013-09-30 16:42:32 +02001809#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001810 template REQUIRES_SHARED(Locks::mutator_lock_) \
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001811 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \
1812 ShadowFrame& shadow_frame, \
Sebastien Hertzc6714852013-09-30 16:42:32 +02001813 const Instruction* inst, uint16_t inst_data, \
1814 JValue* result)
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001815EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false);
1816EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true);
1817EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false);
1818EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true);
1819#undef EXPLICIT_DO_CALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001820
Orion Hodsonc069a302017-01-18 09:23:12 +00001821// Explicit DoInvokePolymorphic template function declarations.
1822#define EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(_is_range) \
1823 template REQUIRES_SHARED(Locks::mutator_lock_) \
1824 bool DoInvokePolymorphic<_is_range>( \
1825 Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1826 uint16_t inst_data, JValue* result)
1827EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(false);
1828EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(true);
Narayan Kamath9823e782016-08-03 12:46:58 +01001829#undef EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL
1830
Orion Hodson43f0cdb2017-10-10 14:47:32 +01001831// Explicit DoInvokeCustom template function declarations.
1832#define EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(_is_range) \
1833 template REQUIRES_SHARED(Locks::mutator_lock_) \
1834 bool DoInvokeCustom<_is_range>( \
1835 Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1836 uint16_t inst_data, JValue* result)
1837EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(false);
1838EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(true);
1839#undef EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL
1840
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001841// Explicit DoFilledNewArray template function declarations.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001842#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001843 template REQUIRES_SHARED(Locks::mutator_lock_) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001844 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \
1845 const ShadowFrame& shadow_frame, \
1846 Thread* self, JValue* result)
1847#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \
1848 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \
1849 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \
1850 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \
1851 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active)
1852EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false);
1853EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true);
1854#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001855#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL
1856
1857} // namespace interpreter
1858} // namespace art