blob: 708a7884fa4bd02d47661d27f15d101685ca8a4d [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"
Andreas Gampec5b75642018-05-16 15:12:11 -070027#include "jvalue-inl.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"
Vladimir Marko6ec2a1b2018-05-22 15:33:48 +010037#include "shadow_frame-inl.h"
Andreas Gampeb3025922015-09-01 14:45:00 -070038#include "stack.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070039#include "thread-inl.h"
Chang Xingbd208d82017-07-12 14:53:17 -070040#include "transaction.h"
Orion Hodson537a4fe2018-05-15 13:57:58 +010041#include "var_handles.h"
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010042#include "well_known_classes.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020043
44namespace art {
45namespace interpreter {
46
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000047void ThrowNullPointerExceptionFromInterpreter() {
48 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -070049}
50
Chang Xingbd208d82017-07-12 14:53:17 -070051template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
52 bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -070053bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
54 uint16_t inst_data) {
55 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
56 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Roland Levillain4b8f1ec2015-08-26 18:34:03 +010057 ArtField* f =
58 FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
59 Primitive::ComponentSize(field_type));
Ian Rogers54874942014-06-10 16:31:03 -070060 if (UNLIKELY(f == nullptr)) {
61 CHECK(self->IsExceptionPending());
62 return false;
63 }
Mathieu Chartieref41db72016-10-25 15:08:01 -070064 ObjPtr<mirror::Object> obj;
Ian Rogers54874942014-06-10 16:31:03 -070065 if (is_static) {
66 obj = f->GetDeclaringClass();
Chang Xingbd208d82017-07-12 14:53:17 -070067 if (transaction_active) {
68 if (Runtime::Current()->GetTransaction()->ReadConstraint(obj.Ptr(), f)) {
69 Runtime::Current()->AbortTransactionAndThrowAbortError(self, "Can't read static fields of "
70 + obj->PrettyTypeOf() + " since it does not belong to clinit's class.");
71 return false;
72 }
73 }
Ian Rogers54874942014-06-10 16:31:03 -070074 } else {
75 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
76 if (UNLIKELY(obj == nullptr)) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000077 ThrowNullPointerExceptionForFieldAccess(f, true);
Ian Rogers54874942014-06-10 16:31:03 -070078 return false;
79 }
80 }
Orion Hodson3d617ac2016-10-19 14:00:46 +010081
82 JValue result;
Alex Light084fa372017-06-16 08:58:34 -070083 if (UNLIKELY(!DoFieldGetCommon<field_type>(self, shadow_frame, obj, f, &result))) {
84 // Instrumentation threw an error!
85 CHECK(self->IsExceptionPending());
86 return false;
87 }
Ian Rogers54874942014-06-10 16:31:03 -070088 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
89 switch (field_type) {
90 case Primitive::kPrimBoolean:
Orion Hodson3d617ac2016-10-19 14:00:46 +010091 shadow_frame.SetVReg(vregA, result.GetZ());
Ian Rogers54874942014-06-10 16:31:03 -070092 break;
93 case Primitive::kPrimByte:
Orion Hodson3d617ac2016-10-19 14:00:46 +010094 shadow_frame.SetVReg(vregA, result.GetB());
Ian Rogers54874942014-06-10 16:31:03 -070095 break;
96 case Primitive::kPrimChar:
Orion Hodson3d617ac2016-10-19 14:00:46 +010097 shadow_frame.SetVReg(vregA, result.GetC());
Ian Rogers54874942014-06-10 16:31:03 -070098 break;
99 case Primitive::kPrimShort:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100100 shadow_frame.SetVReg(vregA, result.GetS());
Ian Rogers54874942014-06-10 16:31:03 -0700101 break;
102 case Primitive::kPrimInt:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100103 shadow_frame.SetVReg(vregA, result.GetI());
Ian Rogers54874942014-06-10 16:31:03 -0700104 break;
105 case Primitive::kPrimLong:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100106 shadow_frame.SetVRegLong(vregA, result.GetJ());
Ian Rogers54874942014-06-10 16:31:03 -0700107 break;
108 case Primitive::kPrimNot:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100109 shadow_frame.SetVRegReference(vregA, result.GetL());
Ian Rogers54874942014-06-10 16:31:03 -0700110 break;
111 default:
112 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700113 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700114 }
115 return true;
116}
117
118// Explicitly instantiate all DoFieldGet functions.
Chang Xingbd208d82017-07-12 14:53:17 -0700119#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
120 template bool DoFieldGet<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \
Ian Rogers54874942014-06-10 16:31:03 -0700121 ShadowFrame& shadow_frame, \
122 const Instruction* inst, \
123 uint16_t inst_data)
124
125#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Chang Xingbd208d82017-07-12 14:53:17 -0700126 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false, true); \
127 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false, false); \
128 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true, true); \
129 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true, false);
Ian Rogers54874942014-06-10 16:31:03 -0700130
131// iget-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700132EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean)
133EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte)
134EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar)
135EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort)
136EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt)
137EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong)
138EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700139
140// sget-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700141EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean)
142EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte)
143EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar)
144EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort)
145EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt)
146EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong)
147EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700148
149#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
150#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
151
152// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
153// Returns true on success, otherwise throws an exception and returns false.
154template<Primitive::Type field_type>
155bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700156 ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Ian Rogers54874942014-06-10 16:31:03 -0700157 if (UNLIKELY(obj == nullptr)) {
158 // We lost the reference to the field index so we cannot get a more
159 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000160 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -0700161 return false;
162 }
163 MemberOffset field_offset(inst->VRegC_22c());
164 // Report this field access to instrumentation if needed. Since we only have the offset of
165 // the field from the base of the object, we need to look for it first.
166 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
167 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
168 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
169 field_offset.Uint32Value());
170 DCHECK(f != nullptr);
171 DCHECK(!f->IsStatic());
Alex Light084fa372017-06-16 08:58:34 -0700172 Thread* self = Thread::Current();
173 StackHandleScope<1> hs(self);
Mathieu Chartiera3147732016-10-26 22:57:02 -0700174 // Save obj in case the instrumentation event has thread suspension.
175 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj);
Alex Light084fa372017-06-16 08:58:34 -0700176 instrumentation->FieldReadEvent(self,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700177 obj.Ptr(),
178 shadow_frame.GetMethod(),
179 shadow_frame.GetDexPC(),
180 f);
Alex Light084fa372017-06-16 08:58:34 -0700181 if (UNLIKELY(self->IsExceptionPending())) {
182 return false;
183 }
Ian Rogers54874942014-06-10 16:31:03 -0700184 }
185 // Note: iget-x-quick instructions are only for non-volatile fields.
186 const uint32_t vregA = inst->VRegA_22c(inst_data);
187 switch (field_type) {
188 case Primitive::kPrimInt:
189 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
190 break;
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800191 case Primitive::kPrimBoolean:
192 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldBoolean(field_offset)));
193 break;
194 case Primitive::kPrimByte:
195 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldByte(field_offset)));
196 break;
197 case Primitive::kPrimChar:
198 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldChar(field_offset)));
199 break;
200 case Primitive::kPrimShort:
201 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldShort(field_offset)));
202 break;
Ian Rogers54874942014-06-10 16:31:03 -0700203 case Primitive::kPrimLong:
204 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
205 break;
206 case Primitive::kPrimNot:
207 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
208 break;
209 default:
210 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700211 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700212 }
213 return true;
214}
215
216// Explicitly instantiate all DoIGetQuick functions.
217#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
218 template bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
219 uint16_t inst_data)
220
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800221EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
222EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimBoolean); // iget-boolean-quick.
223EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimByte); // iget-byte-quick.
224EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimChar); // iget-char-quick.
225EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimShort); // iget-short-quick.
226EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
227EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
Ian Rogers54874942014-06-10 16:31:03 -0700228#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
229
230template<Primitive::Type field_type>
231static JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700232 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers54874942014-06-10 16:31:03 -0700233 JValue field_value;
234 switch (field_type) {
235 case Primitive::kPrimBoolean:
236 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
237 break;
238 case Primitive::kPrimByte:
239 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
240 break;
241 case Primitive::kPrimChar:
242 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
243 break;
244 case Primitive::kPrimShort:
245 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
246 break;
247 case Primitive::kPrimInt:
248 field_value.SetI(shadow_frame.GetVReg(vreg));
249 break;
250 case Primitive::kPrimLong:
251 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
252 break;
253 case Primitive::kPrimNot:
254 field_value.SetL(shadow_frame.GetVRegReference(vreg));
255 break;
256 default:
257 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700258 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700259 }
260 return field_value;
261}
262
Orion Hodson3d617ac2016-10-19 14:00:46 +0100263template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
264 bool transaction_active>
265bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
266 uint16_t inst_data) {
267 const bool do_assignability_check = do_access_check;
268 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
269 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
270 ArtField* f =
271 FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
272 Primitive::ComponentSize(field_type));
273 if (UNLIKELY(f == nullptr)) {
274 CHECK(self->IsExceptionPending());
275 return false;
276 }
277 ObjPtr<mirror::Object> obj;
278 if (is_static) {
279 obj = f->GetDeclaringClass();
Chang Xingbd208d82017-07-12 14:53:17 -0700280 if (transaction_active) {
281 if (Runtime::Current()->GetTransaction()->WriteConstraint(obj.Ptr(), f)) {
282 Runtime::Current()->AbortTransactionAndThrowAbortError(
283 self, "Can't set fields of " + obj->PrettyTypeOf());
284 return false;
285 }
286 }
287
Orion Hodson3d617ac2016-10-19 14:00:46 +0100288 } else {
289 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
290 if (UNLIKELY(obj == nullptr)) {
291 ThrowNullPointerExceptionForFieldAccess(f, false);
292 return false;
293 }
294 }
295
296 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100297 JValue value = GetFieldValue<field_type>(shadow_frame, vregA);
Orion Hodson3d617ac2016-10-19 14:00:46 +0100298 return DoFieldPutCommon<field_type, do_assignability_check, transaction_active>(self,
299 shadow_frame,
300 obj,
301 f,
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100302 value);
Orion Hodson3d617ac2016-10-19 14:00:46 +0100303}
304
Ian Rogers54874942014-06-10 16:31:03 -0700305// Explicitly instantiate all DoFieldPut functions.
306#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
307 template bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \
308 const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
309
310#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
311 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
312 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
313 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
314 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
315
316// iput-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700317EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean)
318EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte)
319EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar)
320EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort)
321EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt)
322EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong)
323EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700324
325// sput-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700326EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean)
327EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte)
328EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar)
329EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort)
330EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt)
331EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong)
332EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700333
334#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
335#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
336
337template<Primitive::Type field_type, bool transaction_active>
338bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700339 ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Ian Rogers54874942014-06-10 16:31:03 -0700340 if (UNLIKELY(obj == nullptr)) {
341 // We lost the reference to the field index so we cannot get a more
342 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000343 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -0700344 return false;
345 }
346 MemberOffset field_offset(inst->VRegC_22c());
347 const uint32_t vregA = inst->VRegA_22c(inst_data);
348 // Report this field modification to instrumentation if needed. Since we only have the offset of
349 // the field from the base of the object, we need to look for it first.
350 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
351 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
352 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
353 field_offset.Uint32Value());
354 DCHECK(f != nullptr);
355 DCHECK(!f->IsStatic());
356 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
Alex Light084fa372017-06-16 08:58:34 -0700357 Thread* self = Thread::Current();
358 StackHandleScope<2> hs(self);
Mathieu Chartiera3147732016-10-26 22:57:02 -0700359 // Save obj in case the instrumentation event has thread suspension.
360 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj);
Alex Light084fa372017-06-16 08:58:34 -0700361 mirror::Object* fake_root = nullptr;
362 HandleWrapper<mirror::Object> ret(hs.NewHandleWrapper<mirror::Object>(
363 field_type == Primitive::kPrimNot ? field_value.GetGCRoot() : &fake_root));
364 instrumentation->FieldWriteEvent(self,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700365 obj.Ptr(),
366 shadow_frame.GetMethod(),
367 shadow_frame.GetDexPC(),
368 f,
369 field_value);
Alex Light084fa372017-06-16 08:58:34 -0700370 if (UNLIKELY(self->IsExceptionPending())) {
371 return false;
372 }
Ian Rogers54874942014-06-10 16:31:03 -0700373 }
374 // Note: iput-x-quick instructions are only for non-volatile fields.
375 switch (field_type) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700376 case Primitive::kPrimBoolean:
377 obj->SetFieldBoolean<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
378 break;
379 case Primitive::kPrimByte:
380 obj->SetFieldByte<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
381 break;
382 case Primitive::kPrimChar:
383 obj->SetFieldChar<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
384 break;
385 case Primitive::kPrimShort:
386 obj->SetFieldShort<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
387 break;
Ian Rogers54874942014-06-10 16:31:03 -0700388 case Primitive::kPrimInt:
389 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
390 break;
391 case Primitive::kPrimLong:
392 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
393 break;
394 case Primitive::kPrimNot:
395 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
396 break;
397 default:
398 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700399 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700400 }
401 return true;
402}
403
404// Explicitly instantiate all DoIPutQuick functions.
405#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
406 template bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
407 const Instruction* inst, \
408 uint16_t inst_data)
409
410#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
411 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
412 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
413
Andreas Gampec8ccf682014-09-29 20:07:43 -0700414EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt) // iput-quick.
415EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimBoolean) // iput-boolean-quick.
416EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimByte) // iput-byte-quick.
417EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimChar) // iput-char-quick.
418EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimShort) // iput-short-quick.
419EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong) // iput-wide-quick.
420EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot) // iput-object-quick.
Ian Rogers54874942014-06-10 16:31:03 -0700421#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
422#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
423
Alex Light9fb1ab12017-09-05 09:32:49 -0700424// We execute any instrumentation events that are triggered by this exception and change the
425// shadow_frame's dex_pc to that of the exception handler if there is one in the current method.
426// Return true if we should continue executing in the current method and false if we need to go up
427// the stack to find an exception handler.
Sebastien Hertz520633b2015-09-08 17:03:36 +0200428// We accept a null Instrumentation* meaning we must not report anything to the instrumentation.
Alex Light9fb1ab12017-09-05 09:32:49 -0700429// TODO We should have a better way to skip instrumentation reporting or possibly rethink that
430// behavior.
431bool MoveToExceptionHandler(Thread* self,
432 ShadowFrame& shadow_frame,
433 const instrumentation::Instrumentation* instrumentation) {
Ian Rogers54874942014-06-10 16:31:03 -0700434 self->VerifyStack();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700435 StackHandleScope<2> hs(self);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000436 Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException()));
Alex Light9fb1ab12017-09-05 09:32:49 -0700437 if (instrumentation != nullptr &&
438 instrumentation->HasExceptionThrownListeners() &&
439 self->IsExceptionThrownByCurrentMethod(exception.Get())) {
440 // 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 -0700441 instrumentation->ExceptionThrownEvent(self, exception.Get());
Sebastien Hertz9f102032014-05-23 08:59:42 +0200442 }
Ian Rogers54874942014-06-10 16:31:03 -0700443 bool clear_exception = false;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700444 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(
Alex Light9fb1ab12017-09-05 09:32:49 -0700445 hs.NewHandle(exception->GetClass()), shadow_frame.GetDexPC(), &clear_exception);
Andreas Gampee2abbc62017-09-15 11:59:26 -0700446 if (found_dex_pc == dex::kDexNoIndex) {
Alex Light9fb1ab12017-09-05 09:32:49 -0700447 if (instrumentation != nullptr) {
448 if (shadow_frame.NeedsNotifyPop()) {
449 instrumentation->WatchedFramePopped(self, shadow_frame);
450 }
451 // Exception is not caught by the current method. We will unwind to the
452 // caller. Notify any instrumentation listener.
453 instrumentation->MethodUnwindEvent(self,
454 shadow_frame.GetThisObject(),
455 shadow_frame.GetMethod(),
456 shadow_frame.GetDexPC());
Alex Lighte814f9d2017-07-31 16:14:39 -0700457 }
Alex Light9fb1ab12017-09-05 09:32:49 -0700458 return false;
Ian Rogers54874942014-06-10 16:31:03 -0700459 } else {
Alex Light9fb1ab12017-09-05 09:32:49 -0700460 shadow_frame.SetDexPC(found_dex_pc);
461 if (instrumentation != nullptr && instrumentation->HasExceptionHandledListeners()) {
462 self->ClearException();
463 instrumentation->ExceptionHandledEvent(self, exception.Get());
464 if (UNLIKELY(self->IsExceptionPending())) {
465 // Exception handled event threw an exception. Try to find the handler for this one.
466 return MoveToExceptionHandler(self, shadow_frame, instrumentation);
467 } else if (!clear_exception) {
468 self->SetException(exception.Get());
469 }
470 } else if (clear_exception) {
Ian Rogers54874942014-06-10 16:31:03 -0700471 self->ClearException();
472 }
Alex Light9fb1ab12017-09-05 09:32:49 -0700473 return true;
Ian Rogers54874942014-06-10 16:31:03 -0700474 }
Ian Rogers54874942014-06-10 16:31:03 -0700475}
476
Ian Rogerse94652f2014-12-02 11:13:19 -0800477void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) {
478 LOG(FATAL) << "Unexpected instruction: "
479 << inst->DumpString(shadow_frame.GetMethod()->GetDexFile());
480 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700481}
482
Sebastien Hertz45b15972015-04-03 16:07:05 +0200483void AbortTransactionF(Thread* self, const char* fmt, ...) {
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700484 va_list args;
485 va_start(args, fmt);
Sebastien Hertz45b15972015-04-03 16:07:05 +0200486 AbortTransactionV(self, fmt, args);
487 va_end(args);
488}
489
490void AbortTransactionV(Thread* self, const char* fmt, va_list args) {
491 CHECK(Runtime::Current()->IsActiveTransaction());
492 // Constructs abort message.
Sebastien Hertz1c80bec2015-02-03 11:58:06 +0100493 std::string abort_msg;
Andreas Gampe46ee31b2016-12-14 10:11:49 -0800494 android::base::StringAppendV(&abort_msg, fmt, args);
Sebastien Hertz1c80bec2015-02-03 11:58:06 +0100495 // Throws an exception so we can abort the transaction and rollback every change.
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200496 Runtime::Current()->AbortTransactionAndThrowAbortError(self, abort_msg);
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700497}
498
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100499// START DECLARATIONS :
500//
501// These additional declarations are required because clang complains
502// about ALWAYS_INLINE (-Werror, -Wgcc-compat) in definitions.
503//
504
Narayan Kamath9823e782016-08-03 12:46:58 +0100505template <bool is_range, bool do_assignability_check>
Vladimir Markod16363a2017-02-01 14:09:13 +0000506static ALWAYS_INLINE bool DoCallCommon(ArtMethod* called_method,
507 Thread* self,
508 ShadowFrame& shadow_frame,
509 JValue* result,
510 uint16_t number_of_inputs,
511 uint32_t (&arg)[Instruction::kMaxVarArgRegs],
512 uint32_t vregC) REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100513
514template <bool is_range>
Narayan Kamath2cb856c2016-11-02 12:01:26 +0000515ALWAYS_INLINE void CopyRegisters(ShadowFrame& caller_frame,
516 ShadowFrame* callee_frame,
517 const uint32_t (&arg)[Instruction::kMaxVarArgRegs],
518 const size_t first_src_reg,
519 const size_t first_dest_reg,
520 const size_t num_regs) REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100521
522// END DECLARATIONS.
523
Siva Chandra05d24152016-01-05 17:43:17 -0800524void ArtInterpreterToCompiledCodeBridge(Thread* self,
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100525 ArtMethod* caller,
Siva Chandra05d24152016-01-05 17:43:17 -0800526 ShadowFrame* shadow_frame,
Jeff Hao5ea84132017-05-05 16:59:29 -0700527 uint16_t arg_offset,
Siva Chandra05d24152016-01-05 17:43:17 -0800528 JValue* result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700529 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700530 ArtMethod* method = shadow_frame->GetMethod();
531 // Ensure static methods are initialized.
532 if (method->IsStatic()) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700533 ObjPtr<mirror::Class> declaringClass = method->GetDeclaringClass();
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700534 if (UNLIKELY(!declaringClass->IsInitialized())) {
535 self->PushShadowFrame(shadow_frame);
536 StackHandleScope<1> hs(self);
537 Handle<mirror::Class> h_class(hs.NewHandle(declaringClass));
Nicolas Geoffray01822292017-03-09 09:03:19 +0000538 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true,
539 true))) {
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700540 self->PopShadowFrame();
541 DCHECK(self->IsExceptionPending());
542 return;
543 }
544 self->PopShadowFrame();
545 CHECK(h_class->IsInitializing());
Nicolas Geoffray01822292017-03-09 09:03:19 +0000546 // Reload from shadow frame in case the method moved, this is faster than adding a handle.
547 method = shadow_frame->GetMethod();
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700548 }
549 }
Jeff Hao5ea84132017-05-05 16:59:29 -0700550 // Basic checks for the arg_offset. If there's no code item, the arg_offset must be 0. Otherwise,
551 // check that the arg_offset isn't greater than the number of registers. A stronger check is
552 // difficult since the frame may contain space for all the registers in the method, or only enough
553 // space for the arguments.
554 if (kIsDebugBuild) {
555 if (method->GetCodeItem() == nullptr) {
556 DCHECK_EQ(0u, arg_offset) << method->PrettyMethod();
557 } else {
558 DCHECK_LE(arg_offset, shadow_frame->NumberOfVRegs());
559 }
560 }
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100561 jit::Jit* jit = Runtime::Current()->GetJit();
562 if (jit != nullptr && caller != nullptr) {
563 jit->NotifyInterpreterToCompiledCodeTransition(self, caller);
564 }
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700565 method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset),
566 (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t),
Andreas Gampe542451c2016-07-26 09:02:02 -0700567 result, method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty());
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700568}
569
Mingyao Yangffedec52016-05-19 10:48:40 -0700570void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame,
571 uint16_t this_obj_vreg,
572 JValue result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700573 REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700574 ObjPtr<mirror::Object> existing = shadow_frame->GetVRegReference(this_obj_vreg);
Mingyao Yangffedec52016-05-19 10:48:40 -0700575 if (existing == nullptr) {
576 // If it's null, we come from compiled code that was deoptimized. Nothing to do,
577 // as the compiler verified there was no alias.
578 // Set the new string result of the StringFactory.
579 shadow_frame->SetVRegReference(this_obj_vreg, result.GetL());
580 return;
581 }
582 // Set the string init result into all aliases.
583 for (uint32_t i = 0, e = shadow_frame->NumberOfVRegs(); i < e; ++i) {
584 if (shadow_frame->GetVRegReference(i) == existing) {
585 DCHECK_EQ(shadow_frame->GetVRegReference(i),
586 reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i)));
587 shadow_frame->SetVRegReference(i, result.GetL());
588 DCHECK_EQ(shadow_frame->GetVRegReference(i),
589 reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i)));
590 }
591 }
592}
593
Orion Hodsonc069a302017-01-18 09:23:12 +0000594template<bool is_range>
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100595static bool DoMethodHandleInvokeCommon(Thread* self,
596 ShadowFrame& shadow_frame,
597 bool invoke_exact,
598 const Instruction* inst,
599 uint16_t inst_data,
600 JValue* result)
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100601 REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Light848574c2017-09-25 16:59:39 -0700602 // Make sure to check for async exceptions
603 if (UNLIKELY(self->ObserveAsyncException())) {
604 return false;
605 }
Narayan Kamath9823e782016-08-03 12:46:58 +0100606 // Invoke-polymorphic instructions always take a receiver. i.e, they are never static.
607 const uint32_t vRegC = (is_range) ? inst->VRegC_4rcc() : inst->VRegC_45cc();
Orion Hodson3d617ac2016-10-19 14:00:46 +0100608 const int invoke_method_idx = (is_range) ? inst->VRegB_4rcc() : inst->VRegB_45cc();
Narayan Kamath9823e782016-08-03 12:46:58 +0100609
Orion Hodson1a06f9f2016-11-09 08:32:42 +0000610 // Initialize |result| to 0 as this is the default return value for
611 // polymorphic invocations of method handle types with void return
612 // and provides sane return result in error cases.
613 result->SetJ(0);
614
Orion Hodson3d617ac2016-10-19 14:00:46 +0100615 // The invoke_method_idx here is the name of the signature polymorphic method that
Narayan Kamath9823e782016-08-03 12:46:58 +0100616 // was symbolically invoked in bytecode (say MethodHandle.invoke or MethodHandle.invokeExact)
617 // and not the method that we'll dispatch to in the end.
Orion Hodsone7732be2017-10-11 14:35:20 +0100618 StackHandleScope<2> hs(self);
Orion Hodsonc069a302017-01-18 09:23:12 +0000619 Handle<mirror::MethodHandle> method_handle(hs.NewHandle(
620 ObjPtr<mirror::MethodHandle>::DownCast(
Mathieu Chartieref41db72016-10-25 15:08:01 -0700621 MakeObjPtr(shadow_frame.GetVRegReference(vRegC)))));
Andreas Gampefa4333d2017-02-14 11:10:34 -0800622 if (UNLIKELY(method_handle == nullptr)) {
Narayan Kamath9823e782016-08-03 12:46:58 +0100623 // Note that the invoke type is kVirtual here because a call to a signature
624 // polymorphic method is shaped like a virtual call at the bytecode level.
Orion Hodson3d617ac2016-10-19 14:00:46 +0100625 ThrowNullPointerExceptionForMethodAccess(invoke_method_idx, InvokeType::kVirtual);
Narayan Kamath9823e782016-08-03 12:46:58 +0100626 return false;
627 }
628
629 // The vRegH value gives the index of the proto_id associated with this
Orion Hodson811bd5f2016-12-07 11:35:37 +0000630 // signature polymorphic call site.
Orion Hodson06d10a72018-05-14 08:53:38 +0100631 const uint16_t vRegH = (is_range) ? inst->VRegH_4rcc() : inst->VRegH_45cc();
632 const dex::ProtoIndex callsite_proto_id(vRegH);
Narayan Kamath9823e782016-08-03 12:46:58 +0100633
634 // Call through to the classlinker and ask it to resolve the static type associated
635 // with the callsite. This information is stored in the dex cache so it's
636 // guaranteed to be fast after the first resolution.
Narayan Kamath9823e782016-08-03 12:46:58 +0100637 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Orion Hodsone7732be2017-10-11 14:35:20 +0100638 Handle<mirror::MethodType> callsite_type(hs.NewHandle(
639 class_linker->ResolveMethodType(self, callsite_proto_id, shadow_frame.GetMethod())));
Narayan Kamath9823e782016-08-03 12:46:58 +0100640
641 // This implies we couldn't resolve one or more types in this method handle.
Andreas Gampefa4333d2017-02-14 11:10:34 -0800642 if (UNLIKELY(callsite_type == nullptr)) {
Narayan Kamath9823e782016-08-03 12:46:58 +0100643 CHECK(self->IsExceptionPending());
Narayan Kamath9823e782016-08-03 12:46:58 +0100644 return false;
645 }
646
Orion Hodson811bd5f2016-12-07 11:35:37 +0000647 // There is a common dispatch method for method handles that takes
648 // arguments either from a range or an array of arguments depending
649 // on whether the DEX instruction is invoke-polymorphic/range or
650 // invoke-polymorphic. The array here is for the latter.
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100651 if (UNLIKELY(is_range)) {
Orion Hodson811bd5f2016-12-07 11:35:37 +0000652 // VRegC is the register holding the method handle. Arguments passed
653 // to the method handle's target do not include the method handle.
Orion Hodson960d4f72017-11-10 15:32:38 +0000654 RangeInstructionOperands operands(inst->VRegC_4rcc() + 1, inst->VRegA_4rcc() - 1);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100655 if (invoke_exact) {
Orion Hodson960d4f72017-11-10 15:32:38 +0000656 return MethodHandleInvokeExact(self,
657 shadow_frame,
658 method_handle,
659 callsite_type,
660 &operands,
661 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100662 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +0000663 return MethodHandleInvoke(self,
664 shadow_frame,
665 method_handle,
666 callsite_type,
667 &operands,
668 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100669 }
Narayan Kamath9823e782016-08-03 12:46:58 +0100670 } else {
Orion Hodson811bd5f2016-12-07 11:35:37 +0000671 // Get the register arguments for the invoke.
Orion Hodson960d4f72017-11-10 15:32:38 +0000672 uint32_t args[Instruction::kMaxVarArgRegs] = {};
Orion Hodson811bd5f2016-12-07 11:35:37 +0000673 inst->GetVarArgs(args, inst_data);
674 // Drop the first register which is the method handle performing the invoke.
Alexey Frunze8631a462017-01-19 19:07:37 -0800675 memmove(args, args + 1, sizeof(args[0]) * (Instruction::kMaxVarArgRegs - 1));
Orion Hodson811bd5f2016-12-07 11:35:37 +0000676 args[Instruction::kMaxVarArgRegs - 1] = 0;
Orion Hodson960d4f72017-11-10 15:32:38 +0000677 VarArgsInstructionOperands operands(args, inst->VRegA_45cc() - 1);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100678 if (invoke_exact) {
Orion Hodson960d4f72017-11-10 15:32:38 +0000679 return MethodHandleInvokeExact(self,
680 shadow_frame,
681 method_handle,
682 callsite_type,
683 &operands,
684 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100685 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +0000686 return MethodHandleInvoke(self,
687 shadow_frame,
688 method_handle,
689 callsite_type,
690 &operands,
691 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100692 }
693 }
694}
695
696bool DoMethodHandleInvokeExact(Thread* self,
697 ShadowFrame& shadow_frame,
698 const Instruction* inst,
699 uint16_t inst_data,
700 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) {
701 if (inst->Opcode() == Instruction::INVOKE_POLYMORPHIC) {
702 static const bool kIsRange = false;
703 return DoMethodHandleInvokeCommon<kIsRange>(
704 self, shadow_frame, true /* is_exact */, inst, inst_data, result);
705 } else {
706 DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_POLYMORPHIC_RANGE);
707 static const bool kIsRange = true;
708 return DoMethodHandleInvokeCommon<kIsRange>(
709 self, shadow_frame, true /* is_exact */, inst, inst_data, result);
710 }
711}
712
713bool DoMethodHandleInvoke(Thread* self,
714 ShadowFrame& shadow_frame,
715 const Instruction* inst,
716 uint16_t inst_data,
717 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) {
718 if (inst->Opcode() == Instruction::INVOKE_POLYMORPHIC) {
719 static const bool kIsRange = false;
720 return DoMethodHandleInvokeCommon<kIsRange>(
721 self, shadow_frame, false /* is_exact */, inst, inst_data, result);
722 } else {
723 DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_POLYMORPHIC_RANGE);
724 static const bool kIsRange = true;
725 return DoMethodHandleInvokeCommon<kIsRange>(
726 self, shadow_frame, false /* is_exact */, inst, inst_data, result);
727 }
728}
729
Orion Hodson928033d2018-02-07 05:30:54 +0000730static bool DoVarHandleInvokeCommon(Thread* self,
731 ShadowFrame& shadow_frame,
732 const Instruction* inst,
733 uint16_t inst_data,
734 JValue* result,
735 mirror::VarHandle::AccessMode access_mode)
736 REQUIRES_SHARED(Locks::mutator_lock_) {
737 // Make sure to check for async exceptions
738 if (UNLIKELY(self->ObserveAsyncException())) {
739 return false;
740 }
741
Orion Hodson928033d2018-02-07 05:30:54 +0000742 StackHandleScope<2> hs(self);
Orion Hodson537a4fe2018-05-15 13:57:58 +0100743 bool is_var_args = inst->HasVarArgs();
Orion Hodson06d10a72018-05-14 08:53:38 +0100744 const uint16_t vRegH = is_var_args ? inst->VRegH_45cc() : inst->VRegH_4rcc();
Orion Hodson928033d2018-02-07 05:30:54 +0000745 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
746 Handle<mirror::MethodType> callsite_type(hs.NewHandle(
Orion Hodson06d10a72018-05-14 08:53:38 +0100747 class_linker->ResolveMethodType(self, dex::ProtoIndex(vRegH), shadow_frame.GetMethod())));
Orion Hodson928033d2018-02-07 05:30:54 +0000748 // This implies we couldn't resolve one or more types in this VarHandle.
749 if (UNLIKELY(callsite_type == nullptr)) {
750 CHECK(self->IsExceptionPending());
751 return false;
752 }
753
Orion Hodson537a4fe2018-05-15 13:57:58 +0100754 const uint32_t vRegC = is_var_args ? inst->VRegC_45cc() : inst->VRegC_4rcc();
755 ObjPtr<mirror::Object> receiver(shadow_frame.GetVRegReference(vRegC));
756 Handle<mirror::VarHandle> var_handle(hs.NewHandle(down_cast<mirror::VarHandle*>(receiver.Ptr())));
Orion Hodson928033d2018-02-07 05:30:54 +0000757 if (is_var_args) {
758 uint32_t args[Instruction::kMaxVarArgRegs];
759 inst->GetVarArgs(args, inst_data);
760 VarArgsInstructionOperands all_operands(args, inst->VRegA_45cc());
761 NoReceiverInstructionOperands operands(&all_operands);
Orion Hodson537a4fe2018-05-15 13:57:58 +0100762 return VarHandleInvokeAccessor(self,
763 shadow_frame,
764 var_handle,
765 callsite_type,
766 access_mode,
767 &operands,
768 result);
Orion Hodson928033d2018-02-07 05:30:54 +0000769 } else {
770 RangeInstructionOperands all_operands(inst->VRegC_4rcc(), inst->VRegA_4rcc());
771 NoReceiverInstructionOperands operands(&all_operands);
Orion Hodson537a4fe2018-05-15 13:57:58 +0100772 return VarHandleInvokeAccessor(self,
773 shadow_frame,
774 var_handle,
775 callsite_type,
776 access_mode,
777 &operands,
778 result);
Orion Hodson928033d2018-02-07 05:30:54 +0000779 }
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100780}
781
Orion Hodson928033d2018-02-07 05:30:54 +0000782#define DO_VAR_HANDLE_ACCESSOR(_access_mode) \
783bool DoVarHandle ## _access_mode(Thread* self, \
784 ShadowFrame& shadow_frame, \
785 const Instruction* inst, \
786 uint16_t inst_data, \
787 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) { \
788 const auto access_mode = mirror::VarHandle::AccessMode::k ## _access_mode; \
789 return DoVarHandleInvokeCommon(self, shadow_frame, inst, inst_data, result, access_mode); \
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100790}
791
Orion Hodson928033d2018-02-07 05:30:54 +0000792DO_VAR_HANDLE_ACCESSOR(CompareAndExchange)
793DO_VAR_HANDLE_ACCESSOR(CompareAndExchangeAcquire)
794DO_VAR_HANDLE_ACCESSOR(CompareAndExchangeRelease)
795DO_VAR_HANDLE_ACCESSOR(CompareAndSet)
796DO_VAR_HANDLE_ACCESSOR(Get)
797DO_VAR_HANDLE_ACCESSOR(GetAcquire)
798DO_VAR_HANDLE_ACCESSOR(GetAndAdd)
799DO_VAR_HANDLE_ACCESSOR(GetAndAddAcquire)
800DO_VAR_HANDLE_ACCESSOR(GetAndAddRelease)
801DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAnd)
802DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAndAcquire)
803DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAndRelease)
804DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOr)
805DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOrAcquire)
806DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOrRelease)
807DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXor)
808DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXorAcquire)
809DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXorRelease)
810DO_VAR_HANDLE_ACCESSOR(GetAndSet)
811DO_VAR_HANDLE_ACCESSOR(GetAndSetAcquire)
812DO_VAR_HANDLE_ACCESSOR(GetAndSetRelease)
813DO_VAR_HANDLE_ACCESSOR(GetOpaque)
814DO_VAR_HANDLE_ACCESSOR(GetVolatile)
815DO_VAR_HANDLE_ACCESSOR(Set)
816DO_VAR_HANDLE_ACCESSOR(SetOpaque)
817DO_VAR_HANDLE_ACCESSOR(SetRelease)
818DO_VAR_HANDLE_ACCESSOR(SetVolatile)
819DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSet)
820DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetAcquire)
821DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetPlain)
822DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetRelease)
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100823
Orion Hodson928033d2018-02-07 05:30:54 +0000824#undef DO_VAR_HANDLE_ACCESSOR
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100825
826template<bool is_range>
827bool DoInvokePolymorphic(Thread* self,
828 ShadowFrame& shadow_frame,
829 const Instruction* inst,
830 uint16_t inst_data,
831 JValue* result) {
832 const int invoke_method_idx = inst->VRegB();
833 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
834 ArtMethod* invoke_method =
835 class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
836 self, invoke_method_idx, shadow_frame.GetMethod(), kVirtual);
837
838 // Ensure intrinsic identifiers are initialized.
839 DCHECK(invoke_method->IsIntrinsic());
840
841 // Dispatch based on intrinsic identifier associated with method.
842 switch (static_cast<art::Intrinsics>(invoke_method->GetIntrinsic())) {
843#define CASE_SIGNATURE_POLYMORPHIC_INTRINSIC(Name, ...) \
844 case Intrinsics::k##Name: \
845 return Do ## Name(self, shadow_frame, inst, inst_data, result);
846#include "intrinsics_list.h"
847 SIGNATURE_POLYMORPHIC_INTRINSICS_LIST(CASE_SIGNATURE_POLYMORPHIC_INTRINSIC)
848#undef INTRINSICS_LIST
849#undef SIGNATURE_POLYMORPHIC_INTRINSICS_LIST
850#undef CASE_SIGNATURE_POLYMORPHIC_INTRINSIC
851 default:
852 LOG(FATAL) << "Unreachable: " << invoke_method->GetIntrinsic();
853 UNREACHABLE();
854 return false;
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100855 }
856}
857
Orion Hodsona5dca522018-02-27 12:42:11 +0000858static JValue ConvertScalarBootstrapArgument(jvalue value) {
859 // value either contains a primitive scalar value if it corresponds
860 // to a primitive type, or it contains an integer value if it
861 // corresponds to an object instance reference id (e.g. a string id).
862 return JValue::FromPrimitive(value.j);
863}
864
865static ObjPtr<mirror::Class> GetClassForBootstrapArgument(EncodedArrayValueIterator::ValueType type)
866 REQUIRES_SHARED(Locks::mutator_lock_) {
867 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
868 switch (type) {
869 case EncodedArrayValueIterator::ValueType::kBoolean:
870 case EncodedArrayValueIterator::ValueType::kByte:
871 case EncodedArrayValueIterator::ValueType::kChar:
872 case EncodedArrayValueIterator::ValueType::kShort:
873 // These types are disallowed by JVMS. Treat as integers. This
874 // will result in CCE's being raised if the BSM has one of these
875 // types.
876 case EncodedArrayValueIterator::ValueType::kInt:
877 return class_linker->FindPrimitiveClass('I');
878 case EncodedArrayValueIterator::ValueType::kLong:
879 return class_linker->FindPrimitiveClass('J');
880 case EncodedArrayValueIterator::ValueType::kFloat:
881 return class_linker->FindPrimitiveClass('F');
882 case EncodedArrayValueIterator::ValueType::kDouble:
883 return class_linker->FindPrimitiveClass('D');
884 case EncodedArrayValueIterator::ValueType::kMethodType:
885 return mirror::MethodType::StaticClass();
886 case EncodedArrayValueIterator::ValueType::kMethodHandle:
887 return mirror::MethodHandle::StaticClass();
888 case EncodedArrayValueIterator::ValueType::kString:
889 return mirror::String::GetJavaLangString();
890 case EncodedArrayValueIterator::ValueType::kType:
891 return mirror::Class::GetJavaLangClass();
892 case EncodedArrayValueIterator::ValueType::kField:
893 case EncodedArrayValueIterator::ValueType::kMethod:
894 case EncodedArrayValueIterator::ValueType::kEnum:
895 case EncodedArrayValueIterator::ValueType::kArray:
896 case EncodedArrayValueIterator::ValueType::kAnnotation:
897 case EncodedArrayValueIterator::ValueType::kNull:
898 return nullptr;
899 }
900}
901
902static bool GetArgumentForBootstrapMethod(Thread* self,
903 ArtMethod* referrer,
904 EncodedArrayValueIterator::ValueType type,
905 const JValue* encoded_value,
906 JValue* decoded_value)
907 REQUIRES_SHARED(Locks::mutator_lock_) {
908 // The encoded_value contains either a scalar value (IJDF) or a
909 // scalar DEX file index to a reference type to be materialized.
910 switch (type) {
911 case EncodedArrayValueIterator::ValueType::kInt:
912 case EncodedArrayValueIterator::ValueType::kFloat:
913 decoded_value->SetI(encoded_value->GetI());
914 return true;
915 case EncodedArrayValueIterator::ValueType::kLong:
916 case EncodedArrayValueIterator::ValueType::kDouble:
917 decoded_value->SetJ(encoded_value->GetJ());
918 return true;
919 case EncodedArrayValueIterator::ValueType::kMethodType: {
920 StackHandleScope<2> hs(self);
921 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
922 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
Orion Hodson06d10a72018-05-14 08:53:38 +0100923 dex::ProtoIndex proto_idx(encoded_value->GetC());
Orion Hodsona5dca522018-02-27 12:42:11 +0000924 ClassLinker* cl = Runtime::Current()->GetClassLinker();
Orion Hodson06d10a72018-05-14 08:53:38 +0100925 ObjPtr<mirror::MethodType> o =
926 cl->ResolveMethodType(self, proto_idx, dex_cache, class_loader);
Orion Hodsona5dca522018-02-27 12:42:11 +0000927 if (UNLIKELY(o.IsNull())) {
928 DCHECK(self->IsExceptionPending());
929 return false;
930 }
931 decoded_value->SetL(o);
932 return true;
933 }
934 case EncodedArrayValueIterator::ValueType::kMethodHandle: {
935 uint32_t index = static_cast<uint32_t>(encoded_value->GetI());
936 ClassLinker* cl = Runtime::Current()->GetClassLinker();
937 ObjPtr<mirror::MethodHandle> o = cl->ResolveMethodHandle(self, index, referrer);
938 if (UNLIKELY(o.IsNull())) {
939 DCHECK(self->IsExceptionPending());
940 return false;
941 }
942 decoded_value->SetL(o);
943 return true;
944 }
945 case EncodedArrayValueIterator::ValueType::kString: {
946 StackHandleScope<1> hs(self);
947 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
948 dex::StringIndex index(static_cast<uint32_t>(encoded_value->GetI()));
949 ClassLinker* cl = Runtime::Current()->GetClassLinker();
950 ObjPtr<mirror::String> o = cl->ResolveString(index, dex_cache);
951 if (UNLIKELY(o.IsNull())) {
952 DCHECK(self->IsExceptionPending());
953 return false;
954 }
955 decoded_value->SetL(o);
956 return true;
957 }
958 case EncodedArrayValueIterator::ValueType::kType: {
959 StackHandleScope<2> hs(self);
960 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
961 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
962 dex::TypeIndex index(static_cast<uint32_t>(encoded_value->GetI()));
963 ClassLinker* cl = Runtime::Current()->GetClassLinker();
964 ObjPtr<mirror::Class> o = cl->ResolveType(index, dex_cache, class_loader);
965 if (UNLIKELY(o.IsNull())) {
966 DCHECK(self->IsExceptionPending());
967 return false;
968 }
969 decoded_value->SetL(o);
970 return true;
971 }
972 case EncodedArrayValueIterator::ValueType::kBoolean:
973 case EncodedArrayValueIterator::ValueType::kByte:
974 case EncodedArrayValueIterator::ValueType::kChar:
975 case EncodedArrayValueIterator::ValueType::kShort:
976 case EncodedArrayValueIterator::ValueType::kField:
977 case EncodedArrayValueIterator::ValueType::kMethod:
978 case EncodedArrayValueIterator::ValueType::kEnum:
979 case EncodedArrayValueIterator::ValueType::kArray:
980 case EncodedArrayValueIterator::ValueType::kAnnotation:
981 case EncodedArrayValueIterator::ValueType::kNull:
982 // Unreachable - unsupported types that have been checked when
983 // determining the effect call site type based on the bootstrap
984 // argument types.
985 UNREACHABLE();
986 }
987}
988
989static bool PackArgumentForBootstrapMethod(Thread* self,
990 ArtMethod* referrer,
991 CallSiteArrayValueIterator* it,
992 ShadowFrameSetter* setter)
993 REQUIRES_SHARED(Locks::mutator_lock_) {
994 auto type = it->GetValueType();
995 const JValue encoded_value = ConvertScalarBootstrapArgument(it->GetJavaValue());
996 JValue decoded_value;
997 if (!GetArgumentForBootstrapMethod(self, referrer, type, &encoded_value, &decoded_value)) {
998 return false;
999 }
1000 switch (it->GetValueType()) {
1001 case EncodedArrayValueIterator::ValueType::kInt:
1002 case EncodedArrayValueIterator::ValueType::kFloat:
1003 setter->Set(static_cast<uint32_t>(decoded_value.GetI()));
1004 return true;
1005 case EncodedArrayValueIterator::ValueType::kLong:
1006 case EncodedArrayValueIterator::ValueType::kDouble:
1007 setter->SetLong(decoded_value.GetJ());
1008 return true;
1009 case EncodedArrayValueIterator::ValueType::kMethodType:
1010 case EncodedArrayValueIterator::ValueType::kMethodHandle:
1011 case EncodedArrayValueIterator::ValueType::kString:
1012 case EncodedArrayValueIterator::ValueType::kType:
1013 setter->SetReference(decoded_value.GetL());
1014 return true;
1015 case EncodedArrayValueIterator::ValueType::kBoolean:
1016 case EncodedArrayValueIterator::ValueType::kByte:
1017 case EncodedArrayValueIterator::ValueType::kChar:
1018 case EncodedArrayValueIterator::ValueType::kShort:
1019 case EncodedArrayValueIterator::ValueType::kField:
1020 case EncodedArrayValueIterator::ValueType::kMethod:
1021 case EncodedArrayValueIterator::ValueType::kEnum:
1022 case EncodedArrayValueIterator::ValueType::kArray:
1023 case EncodedArrayValueIterator::ValueType::kAnnotation:
1024 case EncodedArrayValueIterator::ValueType::kNull:
1025 // Unreachable - unsupported types that have been checked when
1026 // determining the effect call site type based on the bootstrap
1027 // argument types.
1028 UNREACHABLE();
1029 }
1030}
1031
1032static bool PackCollectorArrayForBootstrapMethod(Thread* self,
1033 ArtMethod* referrer,
1034 ObjPtr<mirror::Class> array_type,
1035 int32_t array_length,
1036 CallSiteArrayValueIterator* it,
1037 ShadowFrameSetter* setter)
1038 REQUIRES_SHARED(Locks::mutator_lock_) {
1039 StackHandleScope<1> hs(self);
1040 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
1041 JValue decoded_value;
1042
1043#define COLLECT_PRIMITIVE_ARRAY(Descriptor, Type) \
1044 Handle<mirror::Type ## Array> array = \
1045 hs.NewHandle(mirror::Type ## Array::Alloc(self, array_length)); \
1046 if (array.IsNull()) { \
1047 return false; \
1048 } \
1049 for (int32_t i = 0; it->HasNext(); it->Next(), ++i) { \
1050 auto type = it->GetValueType(); \
1051 DCHECK_EQ(type, EncodedArrayValueIterator::ValueType::k ## Type); \
1052 const JValue encoded_value = \
1053 ConvertScalarBootstrapArgument(it->GetJavaValue()); \
1054 GetArgumentForBootstrapMethod(self, \
1055 referrer, \
1056 type, \
1057 &encoded_value, \
1058 &decoded_value); \
1059 array->Set(i, decoded_value.Get ## Descriptor()); \
1060 } \
1061 setter->SetReference(array.Get()); \
1062 return true;
1063
1064#define COLLECT_REFERENCE_ARRAY(T, Type) \
1065 Handle<mirror::ObjectArray<T>> array = \
1066 hs.NewHandle(mirror::ObjectArray<T>::Alloc(self, \
1067 array_type, \
1068 array_length)); \
1069 if (array.IsNull()) { \
1070 return false; \
1071 } \
1072 for (int32_t i = 0; it->HasNext(); it->Next(), ++i) { \
1073 auto type = it->GetValueType(); \
1074 DCHECK_EQ(type, EncodedArrayValueIterator::ValueType::k ## Type); \
1075 const JValue encoded_value = \
1076 ConvertScalarBootstrapArgument(it->GetJavaValue()); \
1077 if (!GetArgumentForBootstrapMethod(self, \
1078 referrer, \
1079 type, \
1080 &encoded_value, \
1081 &decoded_value)) { \
1082 return false; \
1083 } \
1084 ObjPtr<mirror::Object> o = decoded_value.GetL(); \
1085 if (Runtime::Current()->IsActiveTransaction()) { \
1086 array->Set<true>(i, ObjPtr<T>::DownCast(o)); \
1087 } else { \
1088 array->Set<false>(i, ObjPtr<T>::DownCast(o)); \
1089 } \
1090 } \
1091 setter->SetReference(array.Get()); \
1092 return true;
1093
1094 if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('I')) {
1095 COLLECT_PRIMITIVE_ARRAY(I, Int);
1096 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('J')) {
1097 COLLECT_PRIMITIVE_ARRAY(J, Long);
1098 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('F')) {
1099 COLLECT_PRIMITIVE_ARRAY(F, Float);
1100 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('D')) {
1101 COLLECT_PRIMITIVE_ARRAY(D, Double);
1102 } else if (array_type->GetComponentType() == mirror::MethodType::StaticClass()) {
1103 COLLECT_REFERENCE_ARRAY(mirror::MethodType, MethodType);
1104 } else if (array_type->GetComponentType() == mirror::MethodHandle::StaticClass()) {
1105 COLLECT_REFERENCE_ARRAY(mirror::MethodHandle, MethodHandle);
1106 } else if (array_type->GetComponentType() == mirror::String::GetJavaLangString()) {
1107 COLLECT_REFERENCE_ARRAY(mirror::String, String);
1108 } else if (array_type->GetComponentType() == mirror::Class::GetJavaLangClass()) {
1109 COLLECT_REFERENCE_ARRAY(mirror::Class, Type);
1110 } else {
1111 UNREACHABLE();
1112 }
1113 #undef COLLECT_PRIMITIVE_ARRAY
1114 #undef COLLECT_REFERENCE_ARRAY
1115}
1116
1117static ObjPtr<mirror::MethodType> BuildCallSiteForBootstrapMethod(Thread* self,
1118 const DexFile* dex_file,
1119 uint32_t call_site_idx)
1120 REQUIRES_SHARED(Locks::mutator_lock_) {
1121 const DexFile::CallSiteIdItem& csi = dex_file->GetCallSiteId(call_site_idx);
1122 CallSiteArrayValueIterator it(*dex_file, csi);
1123 DCHECK_GE(it.Size(), 1u);
1124
1125 StackHandleScope<2> hs(self);
1126 // Create array for parameter types.
1127 ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
1128 mirror::Class* class_array_type =
1129 Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_type);
1130 Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle(
1131 mirror::ObjectArray<mirror::Class>::Alloc(self,
1132 class_array_type,
1133 static_cast<int>(it.Size())));
1134 if (ptypes.IsNull()) {
1135 DCHECK(self->IsExceptionPending());
1136 return nullptr;
1137 }
1138
1139 // Populate the first argument with an instance of j.l.i.MethodHandles.Lookup
1140 // that the runtime will construct.
1141 ptypes->Set(0, mirror::MethodHandlesLookup::StaticClass());
1142 it.Next();
1143
1144 // The remaining parameter types are derived from the types of
1145 // arguments present in the DEX file.
1146 int index = 1;
1147 while (it.HasNext()) {
1148 ObjPtr<mirror::Class> ptype = GetClassForBootstrapArgument(it.GetValueType());
1149 if (ptype.IsNull()) {
1150 ThrowClassCastException("Unsupported bootstrap argument type");
1151 return nullptr;
1152 }
1153 ptypes->Set(index, ptype);
1154 index++;
1155 it.Next();
1156 }
1157 DCHECK_EQ(static_cast<size_t>(index), it.Size());
1158
1159 // By definition, the return type is always a j.l.i.CallSite.
1160 Handle<mirror::Class> rtype = hs.NewHandle(mirror::CallSite::StaticClass());
1161 return mirror::MethodType::Create(self, rtype, ptypes);
1162}
1163
Orion Hodsonc069a302017-01-18 09:23:12 +00001164static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self,
1165 ShadowFrame& shadow_frame,
1166 uint32_t call_site_idx)
1167 REQUIRES_SHARED(Locks::mutator_lock_) {
Orion Hodsona5dca522018-02-27 12:42:11 +00001168 StackHandleScope<7> hs(self);
1169 // There are three mandatory arguments expected from the call site
1170 // value array in the DEX file: the bootstrap method handle, the
1171 // method name to pass to the bootstrap method, and the method type
1172 // to pass to the bootstrap method.
1173 static constexpr size_t kMandatoryArgumentsCount = 3;
Orion Hodsonc069a302017-01-18 09:23:12 +00001174 ArtMethod* referrer = shadow_frame.GetMethod();
1175 const DexFile* dex_file = referrer->GetDexFile();
1176 const DexFile::CallSiteIdItem& csi = dex_file->GetCallSiteId(call_site_idx);
Orion Hodsonc069a302017-01-18 09:23:12 +00001177 CallSiteArrayValueIterator it(*dex_file, csi);
Orion Hodsona5dca522018-02-27 12:42:11 +00001178 if (it.Size() < kMandatoryArgumentsCount) {
1179 ThrowBootstrapMethodError("Truncated bootstrap arguments (%zu < %zu)",
1180 it.Size(), kMandatoryArgumentsCount);
1181 return nullptr;
1182 }
1183
1184 if (it.GetValueType() != EncodedArrayValueIterator::ValueType::kMethodHandle) {
1185 ThrowBootstrapMethodError("First bootstrap argument is not a method handle");
1186 return nullptr;
1187 }
1188
1189 uint32_t bsm_index = static_cast<uint32_t>(it.GetJavaValue().i);
1190 it.Next();
1191
Orion Hodsonc069a302017-01-18 09:23:12 +00001192 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Orion Hodsona5dca522018-02-27 12:42:11 +00001193 Handle<mirror::MethodHandle> bsm =
1194 hs.NewHandle(class_linker->ResolveMethodHandle(self, bsm_index, referrer));
1195 if (bsm.IsNull()) {
Orion Hodsonc069a302017-01-18 09:23:12 +00001196 DCHECK(self->IsExceptionPending());
1197 return nullptr;
1198 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001199
Orion Hodsona5dca522018-02-27 12:42:11 +00001200 if (bsm->GetHandleKind() != mirror::MethodHandle::Kind::kInvokeStatic) {
1201 // JLS suggests also accepting constructors. This is currently
1202 // hard as constructor invocations happen via transformers in ART
1203 // today. The constructor would need to be a class derived from java.lang.invoke.CallSite.
1204 ThrowBootstrapMethodError("Unsupported bootstrap method invocation kind");
1205 return nullptr;
1206 }
1207
1208 // Construct the local call site type information based on the 3
1209 // mandatory arguments provided by the runtime and the static arguments
1210 // in the DEX file. We will use these arguments to build a shadow frame.
1211 MutableHandle<mirror::MethodType> call_site_type =
1212 hs.NewHandle(BuildCallSiteForBootstrapMethod(self, dex_file, call_site_idx));
1213 if (call_site_type.IsNull()) {
1214 DCHECK(self->IsExceptionPending());
1215 return nullptr;
1216 }
1217
1218 // Check if this BSM is targeting a variable arity method. If so,
1219 // we'll need to collect the trailing arguments into an array.
1220 Handle<mirror::Array> collector_arguments;
1221 int32_t collector_arguments_length;
1222 if (bsm->GetTargetMethod()->IsVarargs()) {
1223 int number_of_bsm_parameters = bsm->GetMethodType()->GetNumberOfPTypes();
1224 if (number_of_bsm_parameters == 0) {
1225 ThrowBootstrapMethodError("Variable arity BSM does not have any arguments");
1226 return nullptr;
1227 }
1228 Handle<mirror::Class> collector_array_class =
1229 hs.NewHandle(bsm->GetMethodType()->GetPTypes()->Get(number_of_bsm_parameters - 1));
1230 if (!collector_array_class->IsArrayClass()) {
1231 ThrowBootstrapMethodError("Variable arity BSM does not have array as final argument");
1232 return nullptr;
1233 }
1234 // The call site may include no arguments to be collected. In this
1235 // case the number of arguments must be at least the number of BSM
1236 // parameters less the collector array.
1237 if (call_site_type->GetNumberOfPTypes() < number_of_bsm_parameters - 1) {
1238 ThrowWrongMethodTypeException(bsm->GetMethodType(), call_site_type.Get());
1239 return nullptr;
1240 }
1241 // Check all the arguments to be collected match the collector array component type.
1242 for (int i = number_of_bsm_parameters - 1; i < call_site_type->GetNumberOfPTypes(); ++i) {
1243 if (call_site_type->GetPTypes()->Get(i) != collector_array_class->GetComponentType()) {
1244 ThrowClassCastException(collector_array_class->GetComponentType(),
1245 call_site_type->GetPTypes()->Get(i));
1246 return nullptr;
1247 }
1248 }
1249 // Update the call site method type so it now includes the collector array.
1250 int32_t collector_arguments_start = number_of_bsm_parameters - 1;
1251 collector_arguments_length = call_site_type->GetNumberOfPTypes() - number_of_bsm_parameters + 1;
1252 call_site_type.Assign(
1253 mirror::MethodType::CollectTrailingArguments(self,
1254 call_site_type.Get(),
1255 collector_array_class.Get(),
1256 collector_arguments_start));
1257 if (call_site_type.IsNull()) {
1258 DCHECK(self->IsExceptionPending());
1259 return nullptr;
1260 }
1261 } else {
1262 collector_arguments_length = 0;
1263 }
1264
1265 if (call_site_type->GetNumberOfPTypes() != bsm->GetMethodType()->GetNumberOfPTypes()) {
1266 ThrowWrongMethodTypeException(bsm->GetMethodType(), call_site_type.Get());
1267 return nullptr;
1268 }
1269
1270 // BSM invocation has a different set of exceptions that
1271 // j.l.i.MethodHandle.invoke(). Scan arguments looking for CCE
1272 // "opportunities". Unfortunately we cannot just leave this to the
1273 // method handle invocation as this might generate a WMTE.
1274 for (int32_t i = 0; i < call_site_type->GetNumberOfPTypes(); ++i) {
1275 ObjPtr<mirror::Class> from = call_site_type->GetPTypes()->Get(i);
1276 ObjPtr<mirror::Class> to = bsm->GetMethodType()->GetPTypes()->Get(i);
1277 if (!IsParameterTypeConvertible(from, to)) {
1278 ThrowClassCastException(from, to);
1279 return nullptr;
1280 }
1281 }
1282 if (!IsReturnTypeConvertible(call_site_type->GetRType(), bsm->GetMethodType()->GetRType())) {
1283 ThrowClassCastException(bsm->GetMethodType()->GetRType(), call_site_type->GetRType());
1284 return nullptr;
1285 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001286
1287 // Set-up a shadow frame for invoking the bootstrap method handle.
1288 ShadowFrameAllocaUniquePtr bootstrap_frame =
Orion Hodsona5dca522018-02-27 12:42:11 +00001289 CREATE_SHADOW_FRAME(call_site_type->NumberOfVRegs(),
1290 nullptr,
1291 referrer,
1292 shadow_frame.GetDexPC());
Orion Hodsonc069a302017-01-18 09:23:12 +00001293 ScopedStackedShadowFramePusher pusher(
1294 self, bootstrap_frame.get(), StackedShadowFrameType::kShadowFrameUnderConstruction);
Orion Hodsona5dca522018-02-27 12:42:11 +00001295 ShadowFrameSetter setter(bootstrap_frame.get(), 0u);
Orion Hodsonc069a302017-01-18 09:23:12 +00001296
1297 // The first parameter is a MethodHandles lookup instance.
Orion Hodsona5dca522018-02-27 12:42:11 +00001298 Handle<mirror::Class> lookup_class =
1299 hs.NewHandle(shadow_frame.GetMethod()->GetDeclaringClass());
1300 ObjPtr<mirror::MethodHandlesLookup> lookup =
1301 mirror::MethodHandlesLookup::Create(self, lookup_class);
1302 if (lookup.IsNull()) {
Orion Hodsonc069a302017-01-18 09:23:12 +00001303 DCHECK(self->IsExceptionPending());
1304 return nullptr;
1305 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001306 setter.SetReference(lookup);
Orion Hodsonc069a302017-01-18 09:23:12 +00001307
Orion Hodsona5dca522018-02-27 12:42:11 +00001308 // Pack the remaining arguments into the frame.
1309 int number_of_arguments = call_site_type->GetNumberOfPTypes();
1310 int argument_index;
1311 for (argument_index = 1; argument_index < number_of_arguments; ++argument_index) {
1312 if (argument_index == number_of_arguments - 1 &&
1313 call_site_type->GetPTypes()->Get(argument_index)->IsArrayClass()) {
1314 ObjPtr<mirror::Class> array_type = call_site_type->GetPTypes()->Get(argument_index);
1315 if (!PackCollectorArrayForBootstrapMethod(self,
1316 referrer,
1317 array_type,
1318 collector_arguments_length,
1319 &it,
1320 &setter)) {
1321 DCHECK(self->IsExceptionPending());
1322 return nullptr;
Orion Hodsonc069a302017-01-18 09:23:12 +00001323 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001324 } else if (!PackArgumentForBootstrapMethod(self, referrer, &it, &setter)) {
1325 DCHECK(self->IsExceptionPending());
1326 return nullptr;
Orion Hodsonc069a302017-01-18 09:23:12 +00001327 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001328 it.Next();
1329 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001330 DCHECK(!it.HasNext());
1331 DCHECK(setter.Done());
Orion Hodsonc069a302017-01-18 09:23:12 +00001332
1333 // Invoke the bootstrap method handle.
1334 JValue result;
Orion Hodsona5dca522018-02-27 12:42:11 +00001335 RangeInstructionOperands operands(0, bootstrap_frame->NumberOfVRegs());
1336 bool invoke_success = MethodHandleInvoke(self,
1337 *bootstrap_frame,
1338 bsm,
1339 call_site_type,
1340 &operands,
1341 &result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001342 if (!invoke_success) {
1343 DCHECK(self->IsExceptionPending());
1344 return nullptr;
1345 }
1346
1347 Handle<mirror::Object> object(hs.NewHandle(result.GetL()));
Orion Hodsonc069a302017-01-18 09:23:12 +00001348 if (UNLIKELY(object.IsNull())) {
Orion Hodsonda1cdd02018-01-31 18:08:28 +00001349 // This will typically be for LambdaMetafactory which is not supported.
Orion Hodson76e6adb2018-02-23 13:15:55 +00001350 ThrowClassCastException("Bootstrap method returned null");
Orion Hodsonc069a302017-01-18 09:23:12 +00001351 return nullptr;
1352 }
1353
Orion Hodsona5dca522018-02-27 12:42:11 +00001354 // Check the result type is a subclass of j.l.i.CallSite.
Orion Hodsonc069a302017-01-18 09:23:12 +00001355 if (UNLIKELY(!object->InstanceOf(mirror::CallSite::StaticClass()))) {
1356 ThrowClassCastException(object->GetClass(), mirror::CallSite::StaticClass());
1357 return nullptr;
1358 }
1359
Orion Hodsona5dca522018-02-27 12:42:11 +00001360 // Check the call site target is not null as we're going to invoke it.
Orion Hodsonc069a302017-01-18 09:23:12 +00001361 Handle<mirror::CallSite> call_site =
1362 hs.NewHandle(ObjPtr<mirror::CallSite>::DownCast(ObjPtr<mirror::Object>(result.GetL())));
Orion Hodsonc069a302017-01-18 09:23:12 +00001363 Handle<mirror::MethodHandle> target = hs.NewHandle(call_site->GetTarget());
1364 if (UNLIKELY(target.IsNull())) {
Orion Hodsona5dca522018-02-27 12:42:11 +00001365 ThrowClassCastException("Bootstrap method returned a CallSite with a null target");
Orion Hodsonc069a302017-01-18 09:23:12 +00001366 return nullptr;
1367 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001368 return call_site.Get();
1369}
1370
1371template<bool is_range>
1372bool DoInvokeCustom(Thread* self,
1373 ShadowFrame& shadow_frame,
1374 const Instruction* inst,
1375 uint16_t inst_data,
1376 JValue* result)
1377 REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Light848574c2017-09-25 16:59:39 -07001378 // Make sure to check for async exceptions
1379 if (UNLIKELY(self->ObserveAsyncException())) {
1380 return false;
1381 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001382 // invoke-custom is not supported in transactions. In transactions
1383 // there is a limited set of types supported. invoke-custom allows
1384 // running arbitrary code and instantiating arbitrary types.
1385 CHECK(!Runtime::Current()->IsActiveTransaction());
1386 StackHandleScope<4> hs(self);
1387 Handle<mirror::DexCache> dex_cache(hs.NewHandle(shadow_frame.GetMethod()->GetDexCache()));
1388 const uint32_t call_site_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
1389 MutableHandle<mirror::CallSite>
1390 call_site(hs.NewHandle(dex_cache->GetResolvedCallSite(call_site_idx)));
1391 if (call_site.IsNull()) {
1392 call_site.Assign(InvokeBootstrapMethod(self, shadow_frame, call_site_idx));
1393 if (UNLIKELY(call_site.IsNull())) {
1394 CHECK(self->IsExceptionPending());
Orion Hodsona5dca522018-02-27 12:42:11 +00001395 if (!self->GetException()->IsError()) {
1396 // Use a BootstrapMethodError if the exception is not an instance of java.lang.Error.
1397 ThrowWrappedBootstrapMethodError("Exception from call site #%u bootstrap method",
1398 call_site_idx);
1399 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001400 result->SetJ(0);
1401 return false;
1402 }
1403 mirror::CallSite* winning_call_site =
1404 dex_cache->SetResolvedCallSite(call_site_idx, call_site.Get());
1405 call_site.Assign(winning_call_site);
1406 }
1407
Orion Hodsonc069a302017-01-18 09:23:12 +00001408 Handle<mirror::MethodHandle> target = hs.NewHandle(call_site->GetTarget());
1409 Handle<mirror::MethodType> target_method_type = hs.NewHandle(target->GetMethodType());
1410 DCHECK_EQ(static_cast<size_t>(inst->VRegA()), target_method_type->NumberOfVRegs());
Orion Hodsonc069a302017-01-18 09:23:12 +00001411 if (is_range) {
Orion Hodson960d4f72017-11-10 15:32:38 +00001412 RangeInstructionOperands operands(inst->VRegC_3rc(), inst->VRegA_3rc());
1413 return MethodHandleInvokeExact(self,
1414 shadow_frame,
1415 target,
1416 target_method_type,
1417 &operands,
1418 result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001419 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +00001420 uint32_t args[Instruction::kMaxVarArgRegs];
Orion Hodsonc069a302017-01-18 09:23:12 +00001421 inst->GetVarArgs(args, inst_data);
Orion Hodson960d4f72017-11-10 15:32:38 +00001422 VarArgsInstructionOperands operands(args, inst->VRegA_35c());
1423 return MethodHandleInvokeExact(self,
1424 shadow_frame,
1425 target,
1426 target_method_type,
1427 &operands,
1428 result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001429 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001430}
1431
Vladimir Marko6ec2a1b2018-05-22 15:33:48 +01001432// Assign register 'src_reg' from shadow_frame to register 'dest_reg' into new_shadow_frame.
1433static inline void AssignRegister(ShadowFrame* new_shadow_frame, const ShadowFrame& shadow_frame,
1434 size_t dest_reg, size_t src_reg)
1435 REQUIRES_SHARED(Locks::mutator_lock_) {
1436 // Uint required, so that sign extension does not make this wrong on 64b systems
1437 uint32_t src_value = shadow_frame.GetVReg(src_reg);
1438 ObjPtr<mirror::Object> o = shadow_frame.GetVRegReference<kVerifyNone>(src_reg);
1439
1440 // If both register locations contains the same value, the register probably holds a reference.
1441 // Note: As an optimization, non-moving collectors leave a stale reference value
1442 // in the references array even after the original vreg was overwritten to a non-reference.
1443 if (src_value == reinterpret_cast<uintptr_t>(o.Ptr())) {
1444 new_shadow_frame->SetVRegReference(dest_reg, o);
1445 } else {
1446 new_shadow_frame->SetVReg(dest_reg, src_value);
1447 }
1448}
1449
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001450template <bool is_range>
1451inline void CopyRegisters(ShadowFrame& caller_frame,
1452 ShadowFrame* callee_frame,
1453 const uint32_t (&arg)[Instruction::kMaxVarArgRegs],
1454 const size_t first_src_reg,
1455 const size_t first_dest_reg,
1456 const size_t num_regs) {
1457 if (is_range) {
1458 const size_t dest_reg_bound = first_dest_reg + num_regs;
1459 for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < dest_reg_bound;
1460 ++dest_reg, ++src_reg) {
1461 AssignRegister(callee_frame, caller_frame, dest_reg, src_reg);
1462 }
1463 } else {
1464 DCHECK_LE(num_regs, arraysize(arg));
1465
1466 for (size_t arg_index = 0; arg_index < num_regs; ++arg_index) {
1467 AssignRegister(callee_frame, caller_frame, first_dest_reg + arg_index, arg[arg_index]);
1468 }
1469 }
1470}
1471
Igor Murashkin6918bf12015-09-27 19:19:06 -07001472template <bool is_range,
Narayan Kamath370423d2016-10-03 16:51:22 +01001473 bool do_assignability_check>
Igor Murashkin158f35c2015-06-10 15:55:30 -07001474static inline bool DoCallCommon(ArtMethod* called_method,
1475 Thread* self,
1476 ShadowFrame& shadow_frame,
1477 JValue* result,
1478 uint16_t number_of_inputs,
Narayan Kamath370423d2016-10-03 16:51:22 +01001479 uint32_t (&arg)[Instruction::kMaxVarArgRegs],
Igor Murashkin158f35c2015-06-10 15:55:30 -07001480 uint32_t vregC) {
Jeff Hao848f70a2014-01-15 13:49:50 -08001481 bool string_init = false;
1482 // Replace calls to String.<init> with equivalent StringFactory call.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001483 if (UNLIKELY(called_method->GetDeclaringClass()->IsStringClass()
1484 && called_method->IsConstructor())) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01001485 called_method = WellKnownClasses::StringInitToStringFactory(called_method);
Jeff Hao848f70a2014-01-15 13:49:50 -08001486 string_init = true;
1487 }
1488
Alex Lightdaf58c82016-03-16 23:00:49 +00001489 // Compute method information.
David Sehr0225f8e2018-01-31 08:52:24 +00001490 CodeItemDataAccessor accessor(called_method->DexInstructionData());
Igor Murashkin158f35c2015-06-10 15:55:30 -07001491 // Number of registers for the callee's call frame.
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001492 uint16_t num_regs;
Jeff Hao5ea84132017-05-05 16:59:29 -07001493 // Test whether to use the interpreter or compiler entrypoint, and save that result to pass to
1494 // PerformCall. A deoptimization could occur at any time, and we shouldn't change which
1495 // entrypoint to use once we start building the shadow frame.
Mathieu Chartier448bbcf2017-07-06 12:05:13 -07001496
1497 // For unstarted runtimes, always use the interpreter entrypoint. This fixes the case where we are
1498 // doing cross compilation. Note that GetEntryPointFromQuickCompiledCode doesn't use the image
1499 // pointer size here and this may case an overflow if it is called from the compiler. b/62402160
1500 const bool use_interpreter_entrypoint = !Runtime::Current()->IsStarted() ||
1501 ClassLinker::ShouldUseInterpreterEntrypoint(
1502 called_method,
1503 called_method->GetEntryPointFromQuickCompiledCode());
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001504 if (LIKELY(accessor.HasCodeItem())) {
Jeff Hao5ea84132017-05-05 16:59:29 -07001505 // When transitioning to compiled code, space only needs to be reserved for the input registers.
1506 // The rest of the frame gets discarded. This also prevents accessing the called method's code
1507 // item, saving memory by keeping code items of compiled code untouched.
Mathieu Chartier448bbcf2017-07-06 12:05:13 -07001508 if (!use_interpreter_entrypoint) {
1509 DCHECK(!Runtime::Current()->IsAotCompiler()) << "Compiler should use interpreter entrypoint";
Jeff Hao5ea84132017-05-05 16:59:29 -07001510 num_regs = number_of_inputs;
1511 } else {
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001512 num_regs = accessor.RegistersSize();
1513 DCHECK_EQ(string_init ? number_of_inputs - 1 : number_of_inputs, accessor.InsSize());
Jeff Hao5ea84132017-05-05 16:59:29 -07001514 }
Nicolas Geoffray01822292017-03-09 09:03:19 +00001515 } else {
1516 DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
1517 num_regs = number_of_inputs;
Jeff Haodf79ddb2017-02-27 14:47:06 -08001518 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001519
Igor Murashkin158f35c2015-06-10 15:55:30 -07001520 // Hack for String init:
1521 //
1522 // Rewrite invoke-x java.lang.String.<init>(this, a, b, c, ...) into:
1523 // invoke-x StringFactory(a, b, c, ...)
1524 // by effectively dropping the first virtual register from the invoke.
1525 //
1526 // (at this point the ArtMethod has already been replaced,
1527 // so we just need to fix-up the arguments)
David Brazdil65902e82016-01-15 09:35:13 +00001528 //
1529 // Note that FindMethodFromCode in entrypoint_utils-inl.h was also special-cased
1530 // to handle the compiler optimization of replacing `this` with null without
1531 // throwing NullPointerException.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001532 uint32_t string_init_vreg_this = is_range ? vregC : arg[0];
Igor Murashkina06b49b2015-06-25 15:18:12 -07001533 if (UNLIKELY(string_init)) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001534 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 -07001535
Igor Murashkin158f35c2015-06-10 15:55:30 -07001536 // The new StringFactory call is static and has one fewer argument.
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001537 if (!accessor.HasCodeItem()) {
Igor Murashkina06b49b2015-06-25 15:18:12 -07001538 DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
1539 num_regs--;
1540 } // 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 -07001541 number_of_inputs--;
1542
1543 // Rewrite the var-args, dropping the 0th argument ("this")
Igor Murashkin6918bf12015-09-27 19:19:06 -07001544 for (uint32_t i = 1; i < arraysize(arg); ++i) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001545 arg[i - 1] = arg[i];
1546 }
Igor Murashkin6918bf12015-09-27 19:19:06 -07001547 arg[arraysize(arg) - 1] = 0;
Igor Murashkin158f35c2015-06-10 15:55:30 -07001548
1549 // Rewrite the non-var-arg case
1550 vregC++; // Skips the 0th vreg in the range ("this").
1551 }
1552
1553 // Parameter registers go at the end of the shadow frame.
1554 DCHECK_GE(num_regs, number_of_inputs);
1555 size_t first_dest_reg = num_regs - number_of_inputs;
1556 DCHECK_NE(first_dest_reg, (size_t)-1);
1557
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001558 // Allocate shadow frame on the stack.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001559 const char* old_cause = self->StartAssertNoThreadSuspension("DoCallCommon");
Andreas Gampeb3025922015-09-01 14:45:00 -07001560 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe03ec9302015-08-27 17:41:47 -07001561 CREATE_SHADOW_FRAME(num_regs, &shadow_frame, called_method, /* dex pc */ 0);
Andreas Gampeb3025922015-09-01 14:45:00 -07001562 ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get();
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001563
Igor Murashkin158f35c2015-06-10 15:55:30 -07001564 // Initialize new shadow frame by copying the registers from the callee shadow frame.
Jeff Haoa3faaf42013-09-03 19:07:00 -07001565 if (do_assignability_check) {
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001566 // Slow path.
1567 // We might need to do class loading, which incurs a thread state change to kNative. So
1568 // register the shadow frame as under construction and allow suspension again.
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -07001569 ScopedStackedShadowFramePusher pusher(
Sebastien Hertzf7958692015-06-09 14:09:14 +02001570 self, new_shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction);
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001571 self->EndAssertNoThreadSuspension(old_cause);
1572
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001573 // ArtMethod here is needed to check type information of the call site against the callee.
1574 // Type information is retrieved from a DexFile/DexCache for that respective declared method.
1575 //
1576 // As a special case for proxy methods, which are not dex-backed,
1577 // we have to retrieve type information from the proxy's method
1578 // interface method instead (which is dex backed since proxies are never interfaces).
Andreas Gampe542451c2016-07-26 09:02:02 -07001579 ArtMethod* method =
1580 new_shadow_frame->GetMethod()->GetInterfaceMethodIfProxy(kRuntimePointerSize);
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001581
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001582 // We need to do runtime check on reference assignment. We need to load the shorty
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001583 // to get the exact type of each reference argument.
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001584 const DexFile::TypeList* params = method->GetParameterTypeList();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001585 uint32_t shorty_len = 0;
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001586 const char* shorty = method->GetShorty(&shorty_len);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001587
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001588 // Handle receiver apart since it's not part of the shorty.
1589 size_t dest_reg = first_dest_reg;
1590 size_t arg_offset = 0;
Igor Murashkin158f35c2015-06-10 15:55:30 -07001591
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001592 if (!method->IsStatic()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001593 size_t receiver_reg = is_range ? vregC : arg[0];
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001594 new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg));
1595 ++dest_reg;
1596 ++arg_offset;
Igor Murashkina06b49b2015-06-25 15:18:12 -07001597 DCHECK(!string_init); // All StringFactory methods are static.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001598 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001599
1600 // Copy the caller's invoke-* arguments into the callee's parameter registers.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001601 for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) {
Igor Murashkina06b49b2015-06-25 15:18:12 -07001602 // Skip the 0th 'shorty' type since it represents the return type.
1603 DCHECK_LT(shorty_pos + 1, shorty_len) << "for shorty '" << shorty << "'";
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001604 const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset];
1605 switch (shorty[shorty_pos + 1]) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001606 // Handle Object references. 1 virtual register slot.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001607 case 'L': {
Mathieu Chartieref41db72016-10-25 15:08:01 -07001608 ObjPtr<mirror::Object> o = shadow_frame.GetVRegReference(src_reg);
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001609 if (do_assignability_check && o != nullptr) {
Andreas Gampea5b09a62016-11-17 15:21:22 -08001610 const dex::TypeIndex type_idx = params->GetTypeItem(shorty_pos).type_idx_;
Vladimir Marko942fd312017-01-16 20:52:19 +00001611 ObjPtr<mirror::Class> arg_type = method->GetDexCache()->GetResolvedType(type_idx);
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001612 if (arg_type == nullptr) {
Mathieu Chartiere22305b2016-10-26 21:04:58 -07001613 StackHandleScope<1> hs(self);
1614 // Preserve o since it is used below and GetClassFromTypeIndex may cause thread
1615 // suspension.
1616 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&o);
Vladimir Markob45528c2017-07-27 14:14:28 +01001617 arg_type = method->ResolveClassFromTypeIndex(type_idx);
Mathieu Chartiere22305b2016-10-26 21:04:58 -07001618 if (arg_type == nullptr) {
1619 CHECK(self->IsExceptionPending());
1620 return false;
1621 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001622 }
1623 if (!o->VerifierInstanceOf(arg_type)) {
1624 // This should never happen.
Ian Rogers1ff3c982014-08-12 02:30:58 -07001625 std::string temp1, temp2;
Orion Hodsonfef06642016-11-25 16:07:11 +00001626 self->ThrowNewExceptionF("Ljava/lang/InternalError;",
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001627 "Invoking %s with bad arg %d, type '%s' not instance of '%s'",
Ian Rogerse94652f2014-12-02 11:13:19 -08001628 new_shadow_frame->GetMethod()->GetName(), shorty_pos,
Ian Rogers1ff3c982014-08-12 02:30:58 -07001629 o->GetClass()->GetDescriptor(&temp1),
1630 arg_type->GetDescriptor(&temp2));
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001631 return false;
1632 }
Jeff Haoa3faaf42013-09-03 19:07:00 -07001633 }
Vladimir Marko6ec2a1b2018-05-22 15:33:48 +01001634 new_shadow_frame->SetVRegReference(dest_reg, o);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001635 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -07001636 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001637 // Handle doubles and longs. 2 consecutive virtual register slots.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001638 case 'J': case 'D': {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001639 uint64_t wide_value =
1640 (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << BitSizeOf<uint32_t>()) |
1641 static_cast<uint32_t>(shadow_frame.GetVReg(src_reg));
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001642 new_shadow_frame->SetVRegLong(dest_reg, wide_value);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001643 // Skip the next virtual register slot since we already used it.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001644 ++dest_reg;
1645 ++arg_offset;
1646 break;
1647 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001648 // Handle all other primitives that are always 1 virtual register slot.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001649 default:
1650 new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg));
1651 break;
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001652 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001653 }
1654 } else {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001655 if (is_range) {
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001656 DCHECK_EQ(num_regs, first_dest_reg + number_of_inputs);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001657 }
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001658
1659 CopyRegisters<is_range>(shadow_frame,
1660 new_shadow_frame,
1661 arg,
1662 vregC,
1663 first_dest_reg,
1664 number_of_inputs);
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001665 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001666 }
1667
Jeff Hao5ea84132017-05-05 16:59:29 -07001668 PerformCall(self,
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001669 accessor,
Jeff Hao5ea84132017-05-05 16:59:29 -07001670 shadow_frame.GetMethod(),
1671 first_dest_reg,
1672 new_shadow_frame,
1673 result,
1674 use_interpreter_entrypoint);
Jeff Hao848f70a2014-01-15 13:49:50 -08001675
1676 if (string_init && !self->IsExceptionPending()) {
Mingyao Yangffedec52016-05-19 10:48:40 -07001677 SetStringInitValueToAllAliases(&shadow_frame, string_init_vreg_this, *result);
Jeff Hao848f70a2014-01-15 13:49:50 -08001678 }
1679
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001680 return !self->IsExceptionPending();
1681}
1682
Igor Murashkin158f35c2015-06-10 15:55:30 -07001683template<bool is_range, bool do_assignability_check>
Igor Murashkin158f35c2015-06-10 15:55:30 -07001684bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
1685 const Instruction* inst, uint16_t inst_data, JValue* result) {
1686 // Argument word count.
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001687 const uint16_t number_of_inputs =
1688 (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001689
1690 // TODO: find a cleaner way to separate non-range and range information without duplicating
1691 // code.
Igor Murashkin6918bf12015-09-27 19:19:06 -07001692 uint32_t arg[Instruction::kMaxVarArgRegs] = {}; // only used in invoke-XXX.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001693 uint32_t vregC = 0;
1694 if (is_range) {
1695 vregC = inst->VRegC_3rc();
1696 } else {
1697 vregC = inst->VRegC_35c();
1698 inst->GetVarArgs(arg, inst_data);
1699 }
1700
1701 return DoCallCommon<is_range, do_assignability_check>(
1702 called_method, self, shadow_frame,
1703 result, number_of_inputs, arg, vregC);
1704}
1705
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001706template <bool is_range, bool do_access_check, bool transaction_active>
Mathieu Chartieref41db72016-10-25 15:08:01 -07001707bool DoFilledNewArray(const Instruction* inst,
1708 const ShadowFrame& shadow_frame,
1709 Thread* self,
1710 JValue* result) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001711 DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY ||
1712 inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE);
1713 const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c();
1714 if (!is_range) {
1715 // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments.
1716 CHECK_LE(length, 5);
1717 }
1718 if (UNLIKELY(length < 0)) {
1719 ThrowNegativeArraySizeException(length);
1720 return false;
1721 }
1722 uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
Andreas Gampea5b09a62016-11-17 15:21:22 -08001723 ObjPtr<mirror::Class> array_class = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
Mathieu Chartieref41db72016-10-25 15:08:01 -07001724 shadow_frame.GetMethod(),
1725 self,
1726 false,
1727 do_access_check);
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001728 if (UNLIKELY(array_class == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001729 DCHECK(self->IsExceptionPending());
1730 return false;
1731 }
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001732 CHECK(array_class->IsArrayClass());
Mathieu Chartieref41db72016-10-25 15:08:01 -07001733 ObjPtr<mirror::Class> component_class = array_class->GetComponentType();
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001734 const bool is_primitive_int_component = component_class->IsPrimitiveInt();
1735 if (UNLIKELY(component_class->IsPrimitive() && !is_primitive_int_component)) {
1736 if (component_class->IsPrimitiveLong() || component_class->IsPrimitiveDouble()) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001737 ThrowRuntimeException("Bad filled array request for type %s",
David Sehr709b0702016-10-13 09:12:37 -07001738 component_class->PrettyDescriptor().c_str());
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001739 } else {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +00001740 self->ThrowNewExceptionF("Ljava/lang/InternalError;",
Brian Carlstrom4fa0bcd2013-12-10 11:24:21 -08001741 "Found type %s; filled-new-array not implemented for anything but 'int'",
David Sehr709b0702016-10-13 09:12:37 -07001742 component_class->PrettyDescriptor().c_str());
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001743 }
1744 return false;
1745 }
Mathieu Chartieref41db72016-10-25 15:08:01 -07001746 ObjPtr<mirror::Object> new_array = mirror::Array::Alloc<true>(
1747 self,
1748 array_class,
1749 length,
1750 array_class->GetComponentSizeShift(),
1751 Runtime::Current()->GetHeap()->GetCurrentAllocator());
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001752 if (UNLIKELY(new_array == nullptr)) {
1753 self->AssertPendingOOMException();
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001754 return false;
1755 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001756 uint32_t arg[Instruction::kMaxVarArgRegs]; // only used in filled-new-array.
1757 uint32_t vregC = 0; // only used in filled-new-array-range.
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001758 if (is_range) {
Sebastien Hertzabff6432014-01-27 18:01:39 +01001759 vregC = inst->VRegC_3rc();
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001760 } else {
Ian Rogers29a26482014-05-02 15:27:29 -07001761 inst->GetVarArgs(arg);
Sebastien Hertzabff6432014-01-27 18:01:39 +01001762 }
Sebastien Hertzabff6432014-01-27 18:01:39 +01001763 for (int32_t i = 0; i < length; ++i) {
1764 size_t src_reg = is_range ? vregC + i : arg[i];
1765 if (is_primitive_int_component) {
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001766 new_array->AsIntArray()->SetWithoutChecks<transaction_active>(
1767 i, shadow_frame.GetVReg(src_reg));
Sebastien Hertzabff6432014-01-27 18:01:39 +01001768 } else {
Mathieu Chartieref41db72016-10-25 15:08:01 -07001769 new_array->AsObjectArray<mirror::Object>()->SetWithoutChecks<transaction_active>(
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001770 i, shadow_frame.GetVRegReference(src_reg));
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001771 }
1772 }
1773
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001774 result->SetL(new_array);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001775 return true;
1776}
1777
Mathieu Chartieref41db72016-10-25 15:08:01 -07001778// TODO: Use ObjPtr here.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001779template<typename T>
Mathieu Chartieref41db72016-10-25 15:08:01 -07001780static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array,
1781 int32_t count)
1782 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001783 Runtime* runtime = Runtime::Current();
1784 for (int32_t i = 0; i < count; ++i) {
1785 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i));
1786 }
1787}
1788
Mathieu Chartieref41db72016-10-25 15:08:01 -07001789void RecordArrayElementsInTransaction(ObjPtr<mirror::Array> array, int32_t count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001790 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001791 DCHECK(Runtime::Current()->IsActiveTransaction());
1792 DCHECK(array != nullptr);
1793 DCHECK_LE(count, array->GetLength());
1794 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType();
1795 switch (primitive_component_type) {
1796 case Primitive::kPrimBoolean:
1797 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count);
1798 break;
1799 case Primitive::kPrimByte:
1800 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count);
1801 break;
1802 case Primitive::kPrimChar:
1803 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count);
1804 break;
1805 case Primitive::kPrimShort:
1806 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count);
1807 break;
1808 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001809 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count);
1810 break;
Mathieu Chartiere401d142015-04-22 13:56:20 -07001811 case Primitive::kPrimFloat:
1812 RecordArrayElementsInTransactionImpl(array->AsFloatArray(), count);
1813 break;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001814 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001815 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count);
1816 break;
Mathieu Chartiere401d142015-04-22 13:56:20 -07001817 case Primitive::kPrimDouble:
1818 RecordArrayElementsInTransactionImpl(array->AsDoubleArray(), count);
1819 break;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001820 default:
1821 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type
1822 << " in fill-array-data";
1823 break;
1824 }
1825}
1826
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001827// Explicit DoCall template function declarations.
Sebastien Hertzc6714852013-09-30 16:42:32 +02001828#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001829 template REQUIRES_SHARED(Locks::mutator_lock_) \
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001830 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \
1831 ShadowFrame& shadow_frame, \
Sebastien Hertzc6714852013-09-30 16:42:32 +02001832 const Instruction* inst, uint16_t inst_data, \
1833 JValue* result)
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001834EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false);
1835EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true);
1836EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false);
1837EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true);
1838#undef EXPLICIT_DO_CALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001839
Orion Hodsonc069a302017-01-18 09:23:12 +00001840// Explicit DoInvokePolymorphic template function declarations.
1841#define EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(_is_range) \
1842 template REQUIRES_SHARED(Locks::mutator_lock_) \
1843 bool DoInvokePolymorphic<_is_range>( \
1844 Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1845 uint16_t inst_data, JValue* result)
1846EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(false);
1847EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(true);
Narayan Kamath9823e782016-08-03 12:46:58 +01001848#undef EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL
1849
Orion Hodson43f0cdb2017-10-10 14:47:32 +01001850// Explicit DoInvokeCustom template function declarations.
1851#define EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(_is_range) \
1852 template REQUIRES_SHARED(Locks::mutator_lock_) \
1853 bool DoInvokeCustom<_is_range>( \
1854 Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1855 uint16_t inst_data, JValue* result)
1856EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(false);
1857EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(true);
1858#undef EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL
1859
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001860// Explicit DoFilledNewArray template function declarations.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001861#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001862 template REQUIRES_SHARED(Locks::mutator_lock_) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001863 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \
1864 const ShadowFrame& shadow_frame, \
1865 Thread* self, JValue* result)
1866#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \
1867 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \
1868 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \
1869 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \
1870 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active)
1871EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false);
1872EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true);
1873#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001874#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL
1875
1876} // namespace interpreter
1877} // namespace art