blob: ded8cefb8fda5d799f33c962a6e5c25450b449f5 [file] [log] [blame]
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "interpreter_common.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070018
Andreas Gampef0e128a2015-02-27 20:08:34 -080019#include <cmath>
20
Andreas Gampe542451c2016-07-26 09:02:02 -070021#include "base/enums.h"
Daniel Mihalyieb076692014-08-22 17:33:31 +020022#include "debugger.h"
David Sehr9e734c72018-01-04 17:56:19 -080023#include "dex/dex_file_types.h"
Nicolas Geoffray7bf2b4f2015-07-08 10:11:59 +000024#include "entrypoints/runtime_asm_entrypoints.h"
Orion Hodson43f0cdb2017-10-10 14:47:32 +010025#include "intrinsics_enum.h"
Tamas Berghammerdd5e5e92016-02-12 16:29:00 +000026#include "jit/jit.h"
Narayan Kamath9823e782016-08-03 12:46:58 +010027#include "jvalue.h"
Narayan Kamath208f8572016-08-03 12:46:58 +010028#include "method_handles-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070029#include "method_handles.h"
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +010030#include "mirror/array-inl.h"
Narayan Kamath9823e782016-08-03 12:46:58 +010031#include "mirror/class.h"
Narayan Kamath000e1882016-10-24 17:14:25 +010032#include "mirror/emulated_stack_frame.h"
Andreas Gampec6ea7d02017-02-01 16:46:28 -080033#include "mirror/method_handle_impl-inl.h"
Orion Hodson928033d2018-02-07 05:30:54 +000034#include "mirror/var_handle.h"
Narayan Kamath9823e782016-08-03 12:46:58 +010035#include "reflection-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070036#include "reflection.h"
Andreas Gampeb3025922015-09-01 14:45:00 -070037#include "stack.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070038#include "thread-inl.h"
Chang Xingbd208d82017-07-12 14:53:17 -070039#include "transaction.h"
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +010040#include "well_known_classes.h"
Sebastien Hertz8ece0502013-08-07 11:26:41 +020041
42namespace art {
43namespace interpreter {
44
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000045void ThrowNullPointerExceptionFromInterpreter() {
46 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -070047}
48
Chang Xingbd208d82017-07-12 14:53:17 -070049template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
50 bool transaction_active>
Ian Rogers54874942014-06-10 16:31:03 -070051bool DoFieldGet(Thread* self, ShadowFrame& shadow_frame, const Instruction* inst,
52 uint16_t inst_data) {
53 const bool is_static = (find_type == StaticObjectRead) || (find_type == StaticPrimitiveRead);
54 const uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
Roland Levillain4b8f1ec2015-08-26 18:34:03 +010055 ArtField* f =
56 FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
57 Primitive::ComponentSize(field_type));
Ian Rogers54874942014-06-10 16:31:03 -070058 if (UNLIKELY(f == nullptr)) {
59 CHECK(self->IsExceptionPending());
60 return false;
61 }
Mathieu Chartieref41db72016-10-25 15:08:01 -070062 ObjPtr<mirror::Object> obj;
Ian Rogers54874942014-06-10 16:31:03 -070063 if (is_static) {
64 obj = f->GetDeclaringClass();
Chang Xingbd208d82017-07-12 14:53:17 -070065 if (transaction_active) {
66 if (Runtime::Current()->GetTransaction()->ReadConstraint(obj.Ptr(), f)) {
67 Runtime::Current()->AbortTransactionAndThrowAbortError(self, "Can't read static fields of "
68 + obj->PrettyTypeOf() + " since it does not belong to clinit's class.");
69 return false;
70 }
71 }
Ian Rogers54874942014-06-10 16:31:03 -070072 } else {
73 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
74 if (UNLIKELY(obj == nullptr)) {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +000075 ThrowNullPointerExceptionForFieldAccess(f, true);
Ian Rogers54874942014-06-10 16:31:03 -070076 return false;
77 }
78 }
Orion Hodson3d617ac2016-10-19 14:00:46 +010079
80 JValue result;
Alex Light084fa372017-06-16 08:58:34 -070081 if (UNLIKELY(!DoFieldGetCommon<field_type>(self, shadow_frame, obj, f, &result))) {
82 // Instrumentation threw an error!
83 CHECK(self->IsExceptionPending());
84 return false;
85 }
Ian Rogers54874942014-06-10 16:31:03 -070086 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
87 switch (field_type) {
88 case Primitive::kPrimBoolean:
Orion Hodson3d617ac2016-10-19 14:00:46 +010089 shadow_frame.SetVReg(vregA, result.GetZ());
Ian Rogers54874942014-06-10 16:31:03 -070090 break;
91 case Primitive::kPrimByte:
Orion Hodson3d617ac2016-10-19 14:00:46 +010092 shadow_frame.SetVReg(vregA, result.GetB());
Ian Rogers54874942014-06-10 16:31:03 -070093 break;
94 case Primitive::kPrimChar:
Orion Hodson3d617ac2016-10-19 14:00:46 +010095 shadow_frame.SetVReg(vregA, result.GetC());
Ian Rogers54874942014-06-10 16:31:03 -070096 break;
97 case Primitive::kPrimShort:
Orion Hodson3d617ac2016-10-19 14:00:46 +010098 shadow_frame.SetVReg(vregA, result.GetS());
Ian Rogers54874942014-06-10 16:31:03 -070099 break;
100 case Primitive::kPrimInt:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100101 shadow_frame.SetVReg(vregA, result.GetI());
Ian Rogers54874942014-06-10 16:31:03 -0700102 break;
103 case Primitive::kPrimLong:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100104 shadow_frame.SetVRegLong(vregA, result.GetJ());
Ian Rogers54874942014-06-10 16:31:03 -0700105 break;
106 case Primitive::kPrimNot:
Orion Hodson3d617ac2016-10-19 14:00:46 +0100107 shadow_frame.SetVRegReference(vregA, result.GetL());
Ian Rogers54874942014-06-10 16:31:03 -0700108 break;
109 default:
110 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700111 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700112 }
113 return true;
114}
115
116// Explicitly instantiate all DoFieldGet functions.
Chang Xingbd208d82017-07-12 14:53:17 -0700117#define EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
118 template bool DoFieldGet<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \
Ian Rogers54874942014-06-10 16:31:03 -0700119 ShadowFrame& shadow_frame, \
120 const Instruction* inst, \
121 uint16_t inst_data)
122
123#define EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(_find_type, _field_type) \
Chang Xingbd208d82017-07-12 14:53:17 -0700124 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false, true); \
125 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, false, false); \
126 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true, true); \
127 EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL(_find_type, _field_type, true, false);
Ian Rogers54874942014-06-10 16:31:03 -0700128
129// iget-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700130EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimBoolean)
131EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimByte)
132EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimChar)
133EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimShort)
134EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimInt)
135EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstancePrimitiveRead, Primitive::kPrimLong)
136EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(InstanceObjectRead, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700137
138// sget-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700139EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimBoolean)
140EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimByte)
141EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimChar)
142EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimShort)
143EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimInt)
144EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticPrimitiveRead, Primitive::kPrimLong)
145EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL(StaticObjectRead, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700146
147#undef EXPLICIT_DO_FIELD_GET_ALL_TEMPLATE_DECL
148#undef EXPLICIT_DO_FIELD_GET_TEMPLATE_DECL
149
150// Handles iget-quick, iget-wide-quick and iget-object-quick instructions.
151// Returns true on success, otherwise throws an exception and returns false.
152template<Primitive::Type field_type>
153bool DoIGetQuick(ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700154 ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Ian Rogers54874942014-06-10 16:31:03 -0700155 if (UNLIKELY(obj == nullptr)) {
156 // We lost the reference to the field index so we cannot get a more
157 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000158 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -0700159 return false;
160 }
161 MemberOffset field_offset(inst->VRegC_22c());
162 // Report this field access to instrumentation if needed. Since we only have the offset of
163 // the field from the base of the object, we need to look for it first.
164 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
165 if (UNLIKELY(instrumentation->HasFieldReadListeners())) {
166 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
167 field_offset.Uint32Value());
168 DCHECK(f != nullptr);
169 DCHECK(!f->IsStatic());
Alex Light084fa372017-06-16 08:58:34 -0700170 Thread* self = Thread::Current();
171 StackHandleScope<1> hs(self);
Mathieu Chartiera3147732016-10-26 22:57:02 -0700172 // Save obj in case the instrumentation event has thread suspension.
173 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj);
Alex Light084fa372017-06-16 08:58:34 -0700174 instrumentation->FieldReadEvent(self,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700175 obj.Ptr(),
176 shadow_frame.GetMethod(),
177 shadow_frame.GetDexPC(),
178 f);
Alex Light084fa372017-06-16 08:58:34 -0700179 if (UNLIKELY(self->IsExceptionPending())) {
180 return false;
181 }
Ian Rogers54874942014-06-10 16:31:03 -0700182 }
183 // Note: iget-x-quick instructions are only for non-volatile fields.
184 const uint32_t vregA = inst->VRegA_22c(inst_data);
185 switch (field_type) {
186 case Primitive::kPrimInt:
187 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetField32(field_offset)));
188 break;
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800189 case Primitive::kPrimBoolean:
190 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldBoolean(field_offset)));
191 break;
192 case Primitive::kPrimByte:
193 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldByte(field_offset)));
194 break;
195 case Primitive::kPrimChar:
196 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldChar(field_offset)));
197 break;
198 case Primitive::kPrimShort:
199 shadow_frame.SetVReg(vregA, static_cast<int32_t>(obj->GetFieldShort(field_offset)));
200 break;
Ian Rogers54874942014-06-10 16:31:03 -0700201 case Primitive::kPrimLong:
202 shadow_frame.SetVRegLong(vregA, static_cast<int64_t>(obj->GetField64(field_offset)));
203 break;
204 case Primitive::kPrimNot:
205 shadow_frame.SetVRegReference(vregA, obj->GetFieldObject<mirror::Object>(field_offset));
206 break;
207 default:
208 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700209 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700210 }
211 return true;
212}
213
214// Explicitly instantiate all DoIGetQuick functions.
215#define EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(_field_type) \
216 template bool DoIGetQuick<_field_type>(ShadowFrame& shadow_frame, const Instruction* inst, \
217 uint16_t inst_data)
218
Mathieu Chartierffc605c2014-12-10 10:35:44 -0800219EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimInt); // iget-quick.
220EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimBoolean); // iget-boolean-quick.
221EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimByte); // iget-byte-quick.
222EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimChar); // iget-char-quick.
223EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimShort); // iget-short-quick.
224EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimLong); // iget-wide-quick.
225EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL(Primitive::kPrimNot); // iget-object-quick.
Ian Rogers54874942014-06-10 16:31:03 -0700226#undef EXPLICIT_DO_IGET_QUICK_TEMPLATE_DECL
227
228template<Primitive::Type field_type>
229static JValue GetFieldValue(const ShadowFrame& shadow_frame, uint32_t vreg)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700230 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers54874942014-06-10 16:31:03 -0700231 JValue field_value;
232 switch (field_type) {
233 case Primitive::kPrimBoolean:
234 field_value.SetZ(static_cast<uint8_t>(shadow_frame.GetVReg(vreg)));
235 break;
236 case Primitive::kPrimByte:
237 field_value.SetB(static_cast<int8_t>(shadow_frame.GetVReg(vreg)));
238 break;
239 case Primitive::kPrimChar:
240 field_value.SetC(static_cast<uint16_t>(shadow_frame.GetVReg(vreg)));
241 break;
242 case Primitive::kPrimShort:
243 field_value.SetS(static_cast<int16_t>(shadow_frame.GetVReg(vreg)));
244 break;
245 case Primitive::kPrimInt:
246 field_value.SetI(shadow_frame.GetVReg(vreg));
247 break;
248 case Primitive::kPrimLong:
249 field_value.SetJ(shadow_frame.GetVRegLong(vreg));
250 break;
251 case Primitive::kPrimNot:
252 field_value.SetL(shadow_frame.GetVRegReference(vreg));
253 break;
254 default:
255 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700256 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700257 }
258 return field_value;
259}
260
Orion Hodson3d617ac2016-10-19 14:00:46 +0100261template<FindFieldType find_type, Primitive::Type field_type, bool do_access_check,
262 bool transaction_active>
263bool DoFieldPut(Thread* self, const ShadowFrame& shadow_frame, const Instruction* inst,
264 uint16_t inst_data) {
265 const bool do_assignability_check = do_access_check;
266 bool is_static = (find_type == StaticObjectWrite) || (find_type == StaticPrimitiveWrite);
267 uint32_t field_idx = is_static ? inst->VRegB_21c() : inst->VRegC_22c();
268 ArtField* f =
269 FindFieldFromCode<find_type, do_access_check>(field_idx, shadow_frame.GetMethod(), self,
270 Primitive::ComponentSize(field_type));
271 if (UNLIKELY(f == nullptr)) {
272 CHECK(self->IsExceptionPending());
273 return false;
274 }
275 ObjPtr<mirror::Object> obj;
276 if (is_static) {
277 obj = f->GetDeclaringClass();
Chang Xingbd208d82017-07-12 14:53:17 -0700278 if (transaction_active) {
279 if (Runtime::Current()->GetTransaction()->WriteConstraint(obj.Ptr(), f)) {
280 Runtime::Current()->AbortTransactionAndThrowAbortError(
281 self, "Can't set fields of " + obj->PrettyTypeOf());
282 return false;
283 }
284 }
285
Orion Hodson3d617ac2016-10-19 14:00:46 +0100286 } else {
287 obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
288 if (UNLIKELY(obj == nullptr)) {
289 ThrowNullPointerExceptionForFieldAccess(f, false);
290 return false;
291 }
292 }
293
294 uint32_t vregA = is_static ? inst->VRegA_21c(inst_data) : inst->VRegA_22c(inst_data);
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100295 JValue value = GetFieldValue<field_type>(shadow_frame, vregA);
Orion Hodson3d617ac2016-10-19 14:00:46 +0100296 return DoFieldPutCommon<field_type, do_assignability_check, transaction_active>(self,
297 shadow_frame,
298 obj,
299 f,
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100300 value);
Orion Hodson3d617ac2016-10-19 14:00:46 +0100301}
302
Ian Rogers54874942014-06-10 16:31:03 -0700303// Explicitly instantiate all DoFieldPut functions.
304#define EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, _do_check, _transaction_active) \
305 template bool DoFieldPut<_find_type, _field_type, _do_check, _transaction_active>(Thread* self, \
306 const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data)
307
308#define EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(_find_type, _field_type) \
309 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, false); \
310 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, false); \
311 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, false, true); \
312 EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL(_find_type, _field_type, true, true);
313
314// iput-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700315EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimBoolean)
316EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimByte)
317EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimChar)
318EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimShort)
319EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimInt)
320EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstancePrimitiveWrite, Primitive::kPrimLong)
321EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(InstanceObjectWrite, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700322
323// sput-XXX
Andreas Gampec8ccf682014-09-29 20:07:43 -0700324EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimBoolean)
325EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimByte)
326EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimChar)
327EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimShort)
328EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimInt)
329EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticPrimitiveWrite, Primitive::kPrimLong)
330EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL(StaticObjectWrite, Primitive::kPrimNot)
Ian Rogers54874942014-06-10 16:31:03 -0700331
332#undef EXPLICIT_DO_FIELD_PUT_ALL_TEMPLATE_DECL
333#undef EXPLICIT_DO_FIELD_PUT_TEMPLATE_DECL
334
335template<Primitive::Type field_type, bool transaction_active>
336bool DoIPutQuick(const ShadowFrame& shadow_frame, const Instruction* inst, uint16_t inst_data) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700337 ObjPtr<mirror::Object> obj = shadow_frame.GetVRegReference(inst->VRegB_22c(inst_data));
Ian Rogers54874942014-06-10 16:31:03 -0700338 if (UNLIKELY(obj == nullptr)) {
339 // We lost the reference to the field index so we cannot get a more
340 // precised exception message.
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +0000341 ThrowNullPointerExceptionFromDexPC();
Ian Rogers54874942014-06-10 16:31:03 -0700342 return false;
343 }
344 MemberOffset field_offset(inst->VRegC_22c());
345 const uint32_t vregA = inst->VRegA_22c(inst_data);
346 // Report this field modification to instrumentation if needed. Since we only have the offset of
347 // the field from the base of the object, we need to look for it first.
348 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
349 if (UNLIKELY(instrumentation->HasFieldWriteListeners())) {
350 ArtField* f = ArtField::FindInstanceFieldWithOffset(obj->GetClass(),
351 field_offset.Uint32Value());
352 DCHECK(f != nullptr);
353 DCHECK(!f->IsStatic());
354 JValue field_value = GetFieldValue<field_type>(shadow_frame, vregA);
Alex Light084fa372017-06-16 08:58:34 -0700355 Thread* self = Thread::Current();
356 StackHandleScope<2> hs(self);
Mathieu Chartiera3147732016-10-26 22:57:02 -0700357 // Save obj in case the instrumentation event has thread suspension.
358 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&obj);
Alex Light084fa372017-06-16 08:58:34 -0700359 mirror::Object* fake_root = nullptr;
360 HandleWrapper<mirror::Object> ret(hs.NewHandleWrapper<mirror::Object>(
361 field_type == Primitive::kPrimNot ? field_value.GetGCRoot() : &fake_root));
362 instrumentation->FieldWriteEvent(self,
Mathieu Chartieref41db72016-10-25 15:08:01 -0700363 obj.Ptr(),
364 shadow_frame.GetMethod(),
365 shadow_frame.GetDexPC(),
366 f,
367 field_value);
Alex Light084fa372017-06-16 08:58:34 -0700368 if (UNLIKELY(self->IsExceptionPending())) {
369 return false;
370 }
Ian Rogers54874942014-06-10 16:31:03 -0700371 }
372 // Note: iput-x-quick instructions are only for non-volatile fields.
373 switch (field_type) {
Fred Shih37f05ef2014-07-16 18:38:08 -0700374 case Primitive::kPrimBoolean:
375 obj->SetFieldBoolean<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
376 break;
377 case Primitive::kPrimByte:
378 obj->SetFieldByte<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
379 break;
380 case Primitive::kPrimChar:
381 obj->SetFieldChar<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
382 break;
383 case Primitive::kPrimShort:
384 obj->SetFieldShort<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
385 break;
Ian Rogers54874942014-06-10 16:31:03 -0700386 case Primitive::kPrimInt:
387 obj->SetField32<transaction_active>(field_offset, shadow_frame.GetVReg(vregA));
388 break;
389 case Primitive::kPrimLong:
390 obj->SetField64<transaction_active>(field_offset, shadow_frame.GetVRegLong(vregA));
391 break;
392 case Primitive::kPrimNot:
393 obj->SetFieldObject<transaction_active>(field_offset, shadow_frame.GetVRegReference(vregA));
394 break;
395 default:
396 LOG(FATAL) << "Unreachable: " << field_type;
Ian Rogers2c4257b2014-10-24 14:20:06 -0700397 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700398 }
399 return true;
400}
401
402// Explicitly instantiate all DoIPutQuick functions.
403#define EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, _transaction_active) \
404 template bool DoIPutQuick<_field_type, _transaction_active>(const ShadowFrame& shadow_frame, \
405 const Instruction* inst, \
406 uint16_t inst_data)
407
408#define EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(_field_type) \
409 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, false); \
410 EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL(_field_type, true);
411
Andreas Gampec8ccf682014-09-29 20:07:43 -0700412EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimInt) // iput-quick.
413EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimBoolean) // iput-boolean-quick.
414EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimByte) // iput-byte-quick.
415EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimChar) // iput-char-quick.
416EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimShort) // iput-short-quick.
417EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimLong) // iput-wide-quick.
418EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL(Primitive::kPrimNot) // iput-object-quick.
Ian Rogers54874942014-06-10 16:31:03 -0700419#undef EXPLICIT_DO_IPUT_QUICK_ALL_TEMPLATE_DECL
420#undef EXPLICIT_DO_IPUT_QUICK_TEMPLATE_DECL
421
Alex Light9fb1ab12017-09-05 09:32:49 -0700422// We execute any instrumentation events that are triggered by this exception and change the
423// shadow_frame's dex_pc to that of the exception handler if there is one in the current method.
424// Return true if we should continue executing in the current method and false if we need to go up
425// the stack to find an exception handler.
Sebastien Hertz520633b2015-09-08 17:03:36 +0200426// We accept a null Instrumentation* meaning we must not report anything to the instrumentation.
Alex Light9fb1ab12017-09-05 09:32:49 -0700427// TODO We should have a better way to skip instrumentation reporting or possibly rethink that
428// behavior.
429bool MoveToExceptionHandler(Thread* self,
430 ShadowFrame& shadow_frame,
431 const instrumentation::Instrumentation* instrumentation) {
Ian Rogers54874942014-06-10 16:31:03 -0700432 self->VerifyStack();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700433 StackHandleScope<2> hs(self);
Nicolas Geoffray14691c52015-03-05 10:40:17 +0000434 Handle<mirror::Throwable> exception(hs.NewHandle(self->GetException()));
Alex Light9fb1ab12017-09-05 09:32:49 -0700435 if (instrumentation != nullptr &&
436 instrumentation->HasExceptionThrownListeners() &&
437 self->IsExceptionThrownByCurrentMethod(exception.Get())) {
438 // 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 -0700439 instrumentation->ExceptionThrownEvent(self, exception.Get());
Sebastien Hertz9f102032014-05-23 08:59:42 +0200440 }
Ian Rogers54874942014-06-10 16:31:03 -0700441 bool clear_exception = false;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700442 uint32_t found_dex_pc = shadow_frame.GetMethod()->FindCatchBlock(
Alex Light9fb1ab12017-09-05 09:32:49 -0700443 hs.NewHandle(exception->GetClass()), shadow_frame.GetDexPC(), &clear_exception);
Andreas Gampee2abbc62017-09-15 11:59:26 -0700444 if (found_dex_pc == dex::kDexNoIndex) {
Alex Light9fb1ab12017-09-05 09:32:49 -0700445 if (instrumentation != nullptr) {
446 if (shadow_frame.NeedsNotifyPop()) {
447 instrumentation->WatchedFramePopped(self, shadow_frame);
448 }
449 // Exception is not caught by the current method. We will unwind to the
450 // caller. Notify any instrumentation listener.
451 instrumentation->MethodUnwindEvent(self,
452 shadow_frame.GetThisObject(),
453 shadow_frame.GetMethod(),
454 shadow_frame.GetDexPC());
Alex Lighte814f9d2017-07-31 16:14:39 -0700455 }
Alex Light9fb1ab12017-09-05 09:32:49 -0700456 return false;
Ian Rogers54874942014-06-10 16:31:03 -0700457 } else {
Alex Light9fb1ab12017-09-05 09:32:49 -0700458 shadow_frame.SetDexPC(found_dex_pc);
459 if (instrumentation != nullptr && instrumentation->HasExceptionHandledListeners()) {
460 self->ClearException();
461 instrumentation->ExceptionHandledEvent(self, exception.Get());
462 if (UNLIKELY(self->IsExceptionPending())) {
463 // Exception handled event threw an exception. Try to find the handler for this one.
464 return MoveToExceptionHandler(self, shadow_frame, instrumentation);
465 } else if (!clear_exception) {
466 self->SetException(exception.Get());
467 }
468 } else if (clear_exception) {
Ian Rogers54874942014-06-10 16:31:03 -0700469 self->ClearException();
470 }
Alex Light9fb1ab12017-09-05 09:32:49 -0700471 return true;
Ian Rogers54874942014-06-10 16:31:03 -0700472 }
Ian Rogers54874942014-06-10 16:31:03 -0700473}
474
Ian Rogerse94652f2014-12-02 11:13:19 -0800475void UnexpectedOpcode(const Instruction* inst, const ShadowFrame& shadow_frame) {
476 LOG(FATAL) << "Unexpected instruction: "
477 << inst->DumpString(shadow_frame.GetMethod()->GetDexFile());
478 UNREACHABLE();
Ian Rogers54874942014-06-10 16:31:03 -0700479}
480
Sebastien Hertz45b15972015-04-03 16:07:05 +0200481void AbortTransactionF(Thread* self, const char* fmt, ...) {
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700482 va_list args;
483 va_start(args, fmt);
Sebastien Hertz45b15972015-04-03 16:07:05 +0200484 AbortTransactionV(self, fmt, args);
485 va_end(args);
486}
487
488void AbortTransactionV(Thread* self, const char* fmt, va_list args) {
489 CHECK(Runtime::Current()->IsActiveTransaction());
490 // Constructs abort message.
Sebastien Hertz1c80bec2015-02-03 11:58:06 +0100491 std::string abort_msg;
Andreas Gampe46ee31b2016-12-14 10:11:49 -0800492 android::base::StringAppendV(&abort_msg, fmt, args);
Sebastien Hertz1c80bec2015-02-03 11:58:06 +0100493 // Throws an exception so we can abort the transaction and rollback every change.
Sebastien Hertz2fd7e692015-04-02 11:11:19 +0200494 Runtime::Current()->AbortTransactionAndThrowAbortError(self, abort_msg);
Mathieu Chartierb2c7ead2014-04-29 11:13:16 -0700495}
496
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100497// START DECLARATIONS :
498//
499// These additional declarations are required because clang complains
500// about ALWAYS_INLINE (-Werror, -Wgcc-compat) in definitions.
501//
502
Narayan Kamath9823e782016-08-03 12:46:58 +0100503template <bool is_range, bool do_assignability_check>
Vladimir Markod16363a2017-02-01 14:09:13 +0000504static ALWAYS_INLINE bool DoCallCommon(ArtMethod* called_method,
505 Thread* self,
506 ShadowFrame& shadow_frame,
507 JValue* result,
508 uint16_t number_of_inputs,
509 uint32_t (&arg)[Instruction::kMaxVarArgRegs],
510 uint32_t vregC) REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100511
512template <bool is_range>
Narayan Kamath2cb856c2016-11-02 12:01:26 +0000513ALWAYS_INLINE void CopyRegisters(ShadowFrame& caller_frame,
514 ShadowFrame* callee_frame,
515 const uint32_t (&arg)[Instruction::kMaxVarArgRegs],
516 const size_t first_src_reg,
517 const size_t first_dest_reg,
518 const size_t num_regs) REQUIRES_SHARED(Locks::mutator_lock_);
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100519
520// END DECLARATIONS.
521
Siva Chandra05d24152016-01-05 17:43:17 -0800522void ArtInterpreterToCompiledCodeBridge(Thread* self,
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100523 ArtMethod* caller,
Siva Chandra05d24152016-01-05 17:43:17 -0800524 ShadowFrame* shadow_frame,
Jeff Hao5ea84132017-05-05 16:59:29 -0700525 uint16_t arg_offset,
Siva Chandra05d24152016-01-05 17:43:17 -0800526 JValue* result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700527 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700528 ArtMethod* method = shadow_frame->GetMethod();
529 // Ensure static methods are initialized.
530 if (method->IsStatic()) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700531 ObjPtr<mirror::Class> declaringClass = method->GetDeclaringClass();
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700532 if (UNLIKELY(!declaringClass->IsInitialized())) {
533 self->PushShadowFrame(shadow_frame);
534 StackHandleScope<1> hs(self);
535 Handle<mirror::Class> h_class(hs.NewHandle(declaringClass));
Nicolas Geoffray01822292017-03-09 09:03:19 +0000536 if (UNLIKELY(!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true,
537 true))) {
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700538 self->PopShadowFrame();
539 DCHECK(self->IsExceptionPending());
540 return;
541 }
542 self->PopShadowFrame();
543 CHECK(h_class->IsInitializing());
Nicolas Geoffray01822292017-03-09 09:03:19 +0000544 // Reload from shadow frame in case the method moved, this is faster than adding a handle.
545 method = shadow_frame->GetMethod();
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700546 }
547 }
Jeff Hao5ea84132017-05-05 16:59:29 -0700548 // Basic checks for the arg_offset. If there's no code item, the arg_offset must be 0. Otherwise,
549 // check that the arg_offset isn't greater than the number of registers. A stronger check is
550 // difficult since the frame may contain space for all the registers in the method, or only enough
551 // space for the arguments.
552 if (kIsDebugBuild) {
553 if (method->GetCodeItem() == nullptr) {
554 DCHECK_EQ(0u, arg_offset) << method->PrettyMethod();
555 } else {
556 DCHECK_LE(arg_offset, shadow_frame->NumberOfVRegs());
557 }
558 }
Nicolas Geoffray71cd50f2016-04-14 15:00:33 +0100559 jit::Jit* jit = Runtime::Current()->GetJit();
560 if (jit != nullptr && caller != nullptr) {
561 jit->NotifyInterpreterToCompiledCodeTransition(self, caller);
562 }
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700563 method->Invoke(self, shadow_frame->GetVRegArgs(arg_offset),
564 (shadow_frame->NumberOfVRegs() - arg_offset) * sizeof(uint32_t),
Andreas Gampe542451c2016-07-26 09:02:02 -0700565 result, method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty());
Andreas Gampe3cfa4d02015-10-06 17:04:01 -0700566}
567
Mingyao Yangffedec52016-05-19 10:48:40 -0700568void SetStringInitValueToAllAliases(ShadowFrame* shadow_frame,
569 uint16_t this_obj_vreg,
570 JValue result)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700571 REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartieref41db72016-10-25 15:08:01 -0700572 ObjPtr<mirror::Object> existing = shadow_frame->GetVRegReference(this_obj_vreg);
Mingyao Yangffedec52016-05-19 10:48:40 -0700573 if (existing == nullptr) {
574 // If it's null, we come from compiled code that was deoptimized. Nothing to do,
575 // as the compiler verified there was no alias.
576 // Set the new string result of the StringFactory.
577 shadow_frame->SetVRegReference(this_obj_vreg, result.GetL());
578 return;
579 }
580 // Set the string init result into all aliases.
581 for (uint32_t i = 0, e = shadow_frame->NumberOfVRegs(); i < e; ++i) {
582 if (shadow_frame->GetVRegReference(i) == existing) {
583 DCHECK_EQ(shadow_frame->GetVRegReference(i),
584 reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i)));
585 shadow_frame->SetVRegReference(i, result.GetL());
586 DCHECK_EQ(shadow_frame->GetVRegReference(i),
587 reinterpret_cast<mirror::Object*>(shadow_frame->GetVReg(i)));
588 }
589 }
590}
591
Orion Hodsonc069a302017-01-18 09:23:12 +0000592template<bool is_range>
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100593static bool DoMethodHandleInvokeCommon(Thread* self,
594 ShadowFrame& shadow_frame,
595 bool invoke_exact,
596 const Instruction* inst,
597 uint16_t inst_data,
598 JValue* result)
Orion Hodsonba28f9f2016-10-26 10:56:25 +0100599 REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Light848574c2017-09-25 16:59:39 -0700600 // Make sure to check for async exceptions
601 if (UNLIKELY(self->ObserveAsyncException())) {
602 return false;
603 }
Narayan Kamath9823e782016-08-03 12:46:58 +0100604 // Invoke-polymorphic instructions always take a receiver. i.e, they are never static.
605 const uint32_t vRegC = (is_range) ? inst->VRegC_4rcc() : inst->VRegC_45cc();
Orion Hodson3d617ac2016-10-19 14:00:46 +0100606 const int invoke_method_idx = (is_range) ? inst->VRegB_4rcc() : inst->VRegB_45cc();
Narayan Kamath9823e782016-08-03 12:46:58 +0100607
Orion Hodson1a06f9f2016-11-09 08:32:42 +0000608 // Initialize |result| to 0 as this is the default return value for
609 // polymorphic invocations of method handle types with void return
610 // and provides sane return result in error cases.
611 result->SetJ(0);
612
Orion Hodson3d617ac2016-10-19 14:00:46 +0100613 // The invoke_method_idx here is the name of the signature polymorphic method that
Narayan Kamath9823e782016-08-03 12:46:58 +0100614 // was symbolically invoked in bytecode (say MethodHandle.invoke or MethodHandle.invokeExact)
615 // and not the method that we'll dispatch to in the end.
Orion Hodsone7732be2017-10-11 14:35:20 +0100616 StackHandleScope<2> hs(self);
Orion Hodsonc069a302017-01-18 09:23:12 +0000617 Handle<mirror::MethodHandle> method_handle(hs.NewHandle(
618 ObjPtr<mirror::MethodHandle>::DownCast(
Mathieu Chartieref41db72016-10-25 15:08:01 -0700619 MakeObjPtr(shadow_frame.GetVRegReference(vRegC)))));
Andreas Gampefa4333d2017-02-14 11:10:34 -0800620 if (UNLIKELY(method_handle == nullptr)) {
Narayan Kamath9823e782016-08-03 12:46:58 +0100621 // Note that the invoke type is kVirtual here because a call to a signature
622 // polymorphic method is shaped like a virtual call at the bytecode level.
Orion Hodson3d617ac2016-10-19 14:00:46 +0100623 ThrowNullPointerExceptionForMethodAccess(invoke_method_idx, InvokeType::kVirtual);
Narayan Kamath9823e782016-08-03 12:46:58 +0100624 return false;
625 }
626
627 // The vRegH value gives the index of the proto_id associated with this
Orion Hodson811bd5f2016-12-07 11:35:37 +0000628 // signature polymorphic call site.
Orion Hodson06d10a72018-05-14 08:53:38 +0100629 const uint16_t vRegH = (is_range) ? inst->VRegH_4rcc() : inst->VRegH_45cc();
630 const dex::ProtoIndex callsite_proto_id(vRegH);
Narayan Kamath9823e782016-08-03 12:46:58 +0100631
632 // Call through to the classlinker and ask it to resolve the static type associated
633 // with the callsite. This information is stored in the dex cache so it's
634 // guaranteed to be fast after the first resolution.
Narayan Kamath9823e782016-08-03 12:46:58 +0100635 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Orion Hodsone7732be2017-10-11 14:35:20 +0100636 Handle<mirror::MethodType> callsite_type(hs.NewHandle(
637 class_linker->ResolveMethodType(self, callsite_proto_id, shadow_frame.GetMethod())));
Narayan Kamath9823e782016-08-03 12:46:58 +0100638
639 // This implies we couldn't resolve one or more types in this method handle.
Andreas Gampefa4333d2017-02-14 11:10:34 -0800640 if (UNLIKELY(callsite_type == nullptr)) {
Narayan Kamath9823e782016-08-03 12:46:58 +0100641 CHECK(self->IsExceptionPending());
Narayan Kamath9823e782016-08-03 12:46:58 +0100642 return false;
643 }
644
Orion Hodson811bd5f2016-12-07 11:35:37 +0000645 // There is a common dispatch method for method handles that takes
646 // arguments either from a range or an array of arguments depending
647 // on whether the DEX instruction is invoke-polymorphic/range or
648 // invoke-polymorphic. The array here is for the latter.
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100649 if (UNLIKELY(is_range)) {
Orion Hodson811bd5f2016-12-07 11:35:37 +0000650 // VRegC is the register holding the method handle. Arguments passed
651 // to the method handle's target do not include the method handle.
Orion Hodson960d4f72017-11-10 15:32:38 +0000652 RangeInstructionOperands operands(inst->VRegC_4rcc() + 1, inst->VRegA_4rcc() - 1);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100653 if (invoke_exact) {
Orion Hodson960d4f72017-11-10 15:32:38 +0000654 return MethodHandleInvokeExact(self,
655 shadow_frame,
656 method_handle,
657 callsite_type,
658 &operands,
659 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100660 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +0000661 return MethodHandleInvoke(self,
662 shadow_frame,
663 method_handle,
664 callsite_type,
665 &operands,
666 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100667 }
Narayan Kamath9823e782016-08-03 12:46:58 +0100668 } else {
Orion Hodson811bd5f2016-12-07 11:35:37 +0000669 // Get the register arguments for the invoke.
Orion Hodson960d4f72017-11-10 15:32:38 +0000670 uint32_t args[Instruction::kMaxVarArgRegs] = {};
Orion Hodson811bd5f2016-12-07 11:35:37 +0000671 inst->GetVarArgs(args, inst_data);
672 // Drop the first register which is the method handle performing the invoke.
Alexey Frunze8631a462017-01-19 19:07:37 -0800673 memmove(args, args + 1, sizeof(args[0]) * (Instruction::kMaxVarArgRegs - 1));
Orion Hodson811bd5f2016-12-07 11:35:37 +0000674 args[Instruction::kMaxVarArgRegs - 1] = 0;
Orion Hodson960d4f72017-11-10 15:32:38 +0000675 VarArgsInstructionOperands operands(args, inst->VRegA_45cc() - 1);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100676 if (invoke_exact) {
Orion Hodson960d4f72017-11-10 15:32:38 +0000677 return MethodHandleInvokeExact(self,
678 shadow_frame,
679 method_handle,
680 callsite_type,
681 &operands,
682 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100683 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +0000684 return MethodHandleInvoke(self,
685 shadow_frame,
686 method_handle,
687 callsite_type,
688 &operands,
689 result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100690 }
691 }
692}
693
694bool DoMethodHandleInvokeExact(Thread* self,
695 ShadowFrame& shadow_frame,
696 const Instruction* inst,
697 uint16_t inst_data,
698 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) {
699 if (inst->Opcode() == Instruction::INVOKE_POLYMORPHIC) {
700 static const bool kIsRange = false;
701 return DoMethodHandleInvokeCommon<kIsRange>(
702 self, shadow_frame, true /* is_exact */, inst, inst_data, result);
703 } else {
704 DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_POLYMORPHIC_RANGE);
705 static const bool kIsRange = true;
706 return DoMethodHandleInvokeCommon<kIsRange>(
707 self, shadow_frame, true /* is_exact */, inst, inst_data, result);
708 }
709}
710
711bool DoMethodHandleInvoke(Thread* self,
712 ShadowFrame& shadow_frame,
713 const Instruction* inst,
714 uint16_t inst_data,
715 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) {
716 if (inst->Opcode() == Instruction::INVOKE_POLYMORPHIC) {
717 static const bool kIsRange = false;
718 return DoMethodHandleInvokeCommon<kIsRange>(
719 self, shadow_frame, false /* is_exact */, inst, inst_data, result);
720 } else {
721 DCHECK_EQ(inst->Opcode(), Instruction::INVOKE_POLYMORPHIC_RANGE);
722 static const bool kIsRange = true;
723 return DoMethodHandleInvokeCommon<kIsRange>(
724 self, shadow_frame, false /* is_exact */, inst, inst_data, result);
725 }
726}
727
Orion Hodson928033d2018-02-07 05:30:54 +0000728static bool DoVarHandleInvokeChecked(Thread* self,
729 Handle<mirror::VarHandle> var_handle,
730 Handle<mirror::MethodType> callsite_type,
731 mirror::VarHandle::AccessMode access_mode,
732 ShadowFrame& shadow_frame,
733 InstructionOperands* operands,
734 JValue* result)
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100735 REQUIRES_SHARED(Locks::mutator_lock_) {
Orion Hodson928033d2018-02-07 05:30:54 +0000736 // TODO(oth): GetMethodTypeForAccessMode() allocates a MethodType()
737 // which is only required if we need to convert argument and/or
738 // return types.
739 StackHandleScope<1> hs(self);
740 Handle<mirror::MethodType> accessor_type(hs.NewHandle(
741 var_handle->GetMethodTypeForAccessMode(self, access_mode)));
742 const size_t num_vregs = accessor_type->NumberOfVRegs();
743 const int num_params = accessor_type->GetPTypes()->GetLength();
744 ShadowFrameAllocaUniquePtr accessor_frame =
745 CREATE_SHADOW_FRAME(num_vregs, nullptr, shadow_frame.GetMethod(), shadow_frame.GetDexPC());
746 ShadowFrameGetter getter(shadow_frame, operands);
747 static const uint32_t kFirstDestinationReg = 0;
748 ShadowFrameSetter setter(accessor_frame.get(), kFirstDestinationReg);
749 if (!PerformConversions(self, callsite_type, accessor_type, &getter, &setter, num_params)) {
750 return false;
751 }
752 RangeInstructionOperands accessor_operands(kFirstDestinationReg,
753 kFirstDestinationReg + num_vregs);
754 if (!var_handle->Access(access_mode, accessor_frame.get(), &accessor_operands, result)) {
755 return false;
756 }
757 return ConvertReturnValue(callsite_type, accessor_type, result);
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100758}
759
Orion Hodson928033d2018-02-07 05:30:54 +0000760static bool DoVarHandleInvokeCommon(Thread* self,
761 ShadowFrame& shadow_frame,
762 const Instruction* inst,
763 uint16_t inst_data,
764 JValue* result,
765 mirror::VarHandle::AccessMode access_mode)
766 REQUIRES_SHARED(Locks::mutator_lock_) {
767 // Make sure to check for async exceptions
768 if (UNLIKELY(self->ObserveAsyncException())) {
769 return false;
770 }
771
772 bool is_var_args = inst->HasVarArgs();
773 const uint32_t vRegC = is_var_args ? inst->VRegC_45cc() : inst->VRegC_4rcc();
774 ObjPtr<mirror::Object> receiver(shadow_frame.GetVRegReference(vRegC));
775 if (receiver.IsNull()) {
776 ThrowNullPointerExceptionFromDexPC();
777 return false;
778 }
779
780 StackHandleScope<2> hs(self);
781 Handle<mirror::VarHandle> var_handle(hs.NewHandle(down_cast<mirror::VarHandle*>(receiver.Ptr())));
782 if (!var_handle->IsAccessModeSupported(access_mode)) {
783 ThrowUnsupportedOperationException();
784 return false;
785 }
786
Orion Hodson06d10a72018-05-14 08:53:38 +0100787 const uint16_t vRegH = is_var_args ? inst->VRegH_45cc() : inst->VRegH_4rcc();
Orion Hodson928033d2018-02-07 05:30:54 +0000788 ClassLinker* const class_linker = Runtime::Current()->GetClassLinker();
789 Handle<mirror::MethodType> callsite_type(hs.NewHandle(
Orion Hodson06d10a72018-05-14 08:53:38 +0100790 class_linker->ResolveMethodType(self, dex::ProtoIndex(vRegH), shadow_frame.GetMethod())));
Orion Hodson928033d2018-02-07 05:30:54 +0000791 // This implies we couldn't resolve one or more types in this VarHandle.
792 if (UNLIKELY(callsite_type == nullptr)) {
793 CHECK(self->IsExceptionPending());
794 return false;
795 }
796
797 if (!var_handle->IsMethodTypeCompatible(access_mode, callsite_type.Get())) {
798 ThrowWrongMethodTypeException(var_handle->GetMethodTypeForAccessMode(self, access_mode),
799 callsite_type.Get());
800 return false;
801 }
802
803 if (is_var_args) {
804 uint32_t args[Instruction::kMaxVarArgRegs];
805 inst->GetVarArgs(args, inst_data);
806 VarArgsInstructionOperands all_operands(args, inst->VRegA_45cc());
807 NoReceiverInstructionOperands operands(&all_operands);
808 return DoVarHandleInvokeChecked(self,
809 var_handle,
810 callsite_type,
811 access_mode,
812 shadow_frame,
813 &operands,
814 result);
815 } else {
816 RangeInstructionOperands all_operands(inst->VRegC_4rcc(), inst->VRegA_4rcc());
817 NoReceiverInstructionOperands operands(&all_operands);
818 return DoVarHandleInvokeChecked(self,
819 var_handle,
820 callsite_type,
821 access_mode,
822 shadow_frame,
823 &operands,
824 result);
825 }
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100826}
827
Orion Hodson928033d2018-02-07 05:30:54 +0000828#define DO_VAR_HANDLE_ACCESSOR(_access_mode) \
829bool DoVarHandle ## _access_mode(Thread* self, \
830 ShadowFrame& shadow_frame, \
831 const Instruction* inst, \
832 uint16_t inst_data, \
833 JValue* result) REQUIRES_SHARED(Locks::mutator_lock_) { \
834 const auto access_mode = mirror::VarHandle::AccessMode::k ## _access_mode; \
835 return DoVarHandleInvokeCommon(self, shadow_frame, inst, inst_data, result, access_mode); \
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100836}
837
Orion Hodson928033d2018-02-07 05:30:54 +0000838DO_VAR_HANDLE_ACCESSOR(CompareAndExchange)
839DO_VAR_HANDLE_ACCESSOR(CompareAndExchangeAcquire)
840DO_VAR_HANDLE_ACCESSOR(CompareAndExchangeRelease)
841DO_VAR_HANDLE_ACCESSOR(CompareAndSet)
842DO_VAR_HANDLE_ACCESSOR(Get)
843DO_VAR_HANDLE_ACCESSOR(GetAcquire)
844DO_VAR_HANDLE_ACCESSOR(GetAndAdd)
845DO_VAR_HANDLE_ACCESSOR(GetAndAddAcquire)
846DO_VAR_HANDLE_ACCESSOR(GetAndAddRelease)
847DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAnd)
848DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAndAcquire)
849DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseAndRelease)
850DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOr)
851DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOrAcquire)
852DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseOrRelease)
853DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXor)
854DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXorAcquire)
855DO_VAR_HANDLE_ACCESSOR(GetAndBitwiseXorRelease)
856DO_VAR_HANDLE_ACCESSOR(GetAndSet)
857DO_VAR_HANDLE_ACCESSOR(GetAndSetAcquire)
858DO_VAR_HANDLE_ACCESSOR(GetAndSetRelease)
859DO_VAR_HANDLE_ACCESSOR(GetOpaque)
860DO_VAR_HANDLE_ACCESSOR(GetVolatile)
861DO_VAR_HANDLE_ACCESSOR(Set)
862DO_VAR_HANDLE_ACCESSOR(SetOpaque)
863DO_VAR_HANDLE_ACCESSOR(SetRelease)
864DO_VAR_HANDLE_ACCESSOR(SetVolatile)
865DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSet)
866DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetAcquire)
867DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetPlain)
868DO_VAR_HANDLE_ACCESSOR(WeakCompareAndSetRelease)
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100869
Orion Hodson928033d2018-02-07 05:30:54 +0000870#undef DO_VAR_HANDLE_ACCESSOR
Orion Hodson43f0cdb2017-10-10 14:47:32 +0100871
872template<bool is_range>
873bool DoInvokePolymorphic(Thread* self,
874 ShadowFrame& shadow_frame,
875 const Instruction* inst,
876 uint16_t inst_data,
877 JValue* result) {
878 const int invoke_method_idx = inst->VRegB();
879 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
880 ArtMethod* invoke_method =
881 class_linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
882 self, invoke_method_idx, shadow_frame.GetMethod(), kVirtual);
883
884 // Ensure intrinsic identifiers are initialized.
885 DCHECK(invoke_method->IsIntrinsic());
886
887 // Dispatch based on intrinsic identifier associated with method.
888 switch (static_cast<art::Intrinsics>(invoke_method->GetIntrinsic())) {
889#define CASE_SIGNATURE_POLYMORPHIC_INTRINSIC(Name, ...) \
890 case Intrinsics::k##Name: \
891 return Do ## Name(self, shadow_frame, inst, inst_data, result);
892#include "intrinsics_list.h"
893 SIGNATURE_POLYMORPHIC_INTRINSICS_LIST(CASE_SIGNATURE_POLYMORPHIC_INTRINSIC)
894#undef INTRINSICS_LIST
895#undef SIGNATURE_POLYMORPHIC_INTRINSICS_LIST
896#undef CASE_SIGNATURE_POLYMORPHIC_INTRINSIC
897 default:
898 LOG(FATAL) << "Unreachable: " << invoke_method->GetIntrinsic();
899 UNREACHABLE();
900 return false;
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +0100901 }
902}
903
Orion Hodsona5dca522018-02-27 12:42:11 +0000904static JValue ConvertScalarBootstrapArgument(jvalue value) {
905 // value either contains a primitive scalar value if it corresponds
906 // to a primitive type, or it contains an integer value if it
907 // corresponds to an object instance reference id (e.g. a string id).
908 return JValue::FromPrimitive(value.j);
909}
910
911static ObjPtr<mirror::Class> GetClassForBootstrapArgument(EncodedArrayValueIterator::ValueType type)
912 REQUIRES_SHARED(Locks::mutator_lock_) {
913 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
914 switch (type) {
915 case EncodedArrayValueIterator::ValueType::kBoolean:
916 case EncodedArrayValueIterator::ValueType::kByte:
917 case EncodedArrayValueIterator::ValueType::kChar:
918 case EncodedArrayValueIterator::ValueType::kShort:
919 // These types are disallowed by JVMS. Treat as integers. This
920 // will result in CCE's being raised if the BSM has one of these
921 // types.
922 case EncodedArrayValueIterator::ValueType::kInt:
923 return class_linker->FindPrimitiveClass('I');
924 case EncodedArrayValueIterator::ValueType::kLong:
925 return class_linker->FindPrimitiveClass('J');
926 case EncodedArrayValueIterator::ValueType::kFloat:
927 return class_linker->FindPrimitiveClass('F');
928 case EncodedArrayValueIterator::ValueType::kDouble:
929 return class_linker->FindPrimitiveClass('D');
930 case EncodedArrayValueIterator::ValueType::kMethodType:
931 return mirror::MethodType::StaticClass();
932 case EncodedArrayValueIterator::ValueType::kMethodHandle:
933 return mirror::MethodHandle::StaticClass();
934 case EncodedArrayValueIterator::ValueType::kString:
935 return mirror::String::GetJavaLangString();
936 case EncodedArrayValueIterator::ValueType::kType:
937 return mirror::Class::GetJavaLangClass();
938 case EncodedArrayValueIterator::ValueType::kField:
939 case EncodedArrayValueIterator::ValueType::kMethod:
940 case EncodedArrayValueIterator::ValueType::kEnum:
941 case EncodedArrayValueIterator::ValueType::kArray:
942 case EncodedArrayValueIterator::ValueType::kAnnotation:
943 case EncodedArrayValueIterator::ValueType::kNull:
944 return nullptr;
945 }
946}
947
948static bool GetArgumentForBootstrapMethod(Thread* self,
949 ArtMethod* referrer,
950 EncodedArrayValueIterator::ValueType type,
951 const JValue* encoded_value,
952 JValue* decoded_value)
953 REQUIRES_SHARED(Locks::mutator_lock_) {
954 // The encoded_value contains either a scalar value (IJDF) or a
955 // scalar DEX file index to a reference type to be materialized.
956 switch (type) {
957 case EncodedArrayValueIterator::ValueType::kInt:
958 case EncodedArrayValueIterator::ValueType::kFloat:
959 decoded_value->SetI(encoded_value->GetI());
960 return true;
961 case EncodedArrayValueIterator::ValueType::kLong:
962 case EncodedArrayValueIterator::ValueType::kDouble:
963 decoded_value->SetJ(encoded_value->GetJ());
964 return true;
965 case EncodedArrayValueIterator::ValueType::kMethodType: {
966 StackHandleScope<2> hs(self);
967 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
968 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
Orion Hodson06d10a72018-05-14 08:53:38 +0100969 dex::ProtoIndex proto_idx(encoded_value->GetC());
Orion Hodsona5dca522018-02-27 12:42:11 +0000970 ClassLinker* cl = Runtime::Current()->GetClassLinker();
Orion Hodson06d10a72018-05-14 08:53:38 +0100971 ObjPtr<mirror::MethodType> o =
972 cl->ResolveMethodType(self, proto_idx, dex_cache, class_loader);
Orion Hodsona5dca522018-02-27 12:42:11 +0000973 if (UNLIKELY(o.IsNull())) {
974 DCHECK(self->IsExceptionPending());
975 return false;
976 }
977 decoded_value->SetL(o);
978 return true;
979 }
980 case EncodedArrayValueIterator::ValueType::kMethodHandle: {
981 uint32_t index = static_cast<uint32_t>(encoded_value->GetI());
982 ClassLinker* cl = Runtime::Current()->GetClassLinker();
983 ObjPtr<mirror::MethodHandle> o = cl->ResolveMethodHandle(self, index, referrer);
984 if (UNLIKELY(o.IsNull())) {
985 DCHECK(self->IsExceptionPending());
986 return false;
987 }
988 decoded_value->SetL(o);
989 return true;
990 }
991 case EncodedArrayValueIterator::ValueType::kString: {
992 StackHandleScope<1> hs(self);
993 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
994 dex::StringIndex index(static_cast<uint32_t>(encoded_value->GetI()));
995 ClassLinker* cl = Runtime::Current()->GetClassLinker();
996 ObjPtr<mirror::String> o = cl->ResolveString(index, dex_cache);
997 if (UNLIKELY(o.IsNull())) {
998 DCHECK(self->IsExceptionPending());
999 return false;
1000 }
1001 decoded_value->SetL(o);
1002 return true;
1003 }
1004 case EncodedArrayValueIterator::ValueType::kType: {
1005 StackHandleScope<2> hs(self);
1006 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
1007 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
1008 dex::TypeIndex index(static_cast<uint32_t>(encoded_value->GetI()));
1009 ClassLinker* cl = Runtime::Current()->GetClassLinker();
1010 ObjPtr<mirror::Class> o = cl->ResolveType(index, dex_cache, class_loader);
1011 if (UNLIKELY(o.IsNull())) {
1012 DCHECK(self->IsExceptionPending());
1013 return false;
1014 }
1015 decoded_value->SetL(o);
1016 return true;
1017 }
1018 case EncodedArrayValueIterator::ValueType::kBoolean:
1019 case EncodedArrayValueIterator::ValueType::kByte:
1020 case EncodedArrayValueIterator::ValueType::kChar:
1021 case EncodedArrayValueIterator::ValueType::kShort:
1022 case EncodedArrayValueIterator::ValueType::kField:
1023 case EncodedArrayValueIterator::ValueType::kMethod:
1024 case EncodedArrayValueIterator::ValueType::kEnum:
1025 case EncodedArrayValueIterator::ValueType::kArray:
1026 case EncodedArrayValueIterator::ValueType::kAnnotation:
1027 case EncodedArrayValueIterator::ValueType::kNull:
1028 // Unreachable - unsupported types that have been checked when
1029 // determining the effect call site type based on the bootstrap
1030 // argument types.
1031 UNREACHABLE();
1032 }
1033}
1034
1035static bool PackArgumentForBootstrapMethod(Thread* self,
1036 ArtMethod* referrer,
1037 CallSiteArrayValueIterator* it,
1038 ShadowFrameSetter* setter)
1039 REQUIRES_SHARED(Locks::mutator_lock_) {
1040 auto type = it->GetValueType();
1041 const JValue encoded_value = ConvertScalarBootstrapArgument(it->GetJavaValue());
1042 JValue decoded_value;
1043 if (!GetArgumentForBootstrapMethod(self, referrer, type, &encoded_value, &decoded_value)) {
1044 return false;
1045 }
1046 switch (it->GetValueType()) {
1047 case EncodedArrayValueIterator::ValueType::kInt:
1048 case EncodedArrayValueIterator::ValueType::kFloat:
1049 setter->Set(static_cast<uint32_t>(decoded_value.GetI()));
1050 return true;
1051 case EncodedArrayValueIterator::ValueType::kLong:
1052 case EncodedArrayValueIterator::ValueType::kDouble:
1053 setter->SetLong(decoded_value.GetJ());
1054 return true;
1055 case EncodedArrayValueIterator::ValueType::kMethodType:
1056 case EncodedArrayValueIterator::ValueType::kMethodHandle:
1057 case EncodedArrayValueIterator::ValueType::kString:
1058 case EncodedArrayValueIterator::ValueType::kType:
1059 setter->SetReference(decoded_value.GetL());
1060 return true;
1061 case EncodedArrayValueIterator::ValueType::kBoolean:
1062 case EncodedArrayValueIterator::ValueType::kByte:
1063 case EncodedArrayValueIterator::ValueType::kChar:
1064 case EncodedArrayValueIterator::ValueType::kShort:
1065 case EncodedArrayValueIterator::ValueType::kField:
1066 case EncodedArrayValueIterator::ValueType::kMethod:
1067 case EncodedArrayValueIterator::ValueType::kEnum:
1068 case EncodedArrayValueIterator::ValueType::kArray:
1069 case EncodedArrayValueIterator::ValueType::kAnnotation:
1070 case EncodedArrayValueIterator::ValueType::kNull:
1071 // Unreachable - unsupported types that have been checked when
1072 // determining the effect call site type based on the bootstrap
1073 // argument types.
1074 UNREACHABLE();
1075 }
1076}
1077
1078static bool PackCollectorArrayForBootstrapMethod(Thread* self,
1079 ArtMethod* referrer,
1080 ObjPtr<mirror::Class> array_type,
1081 int32_t array_length,
1082 CallSiteArrayValueIterator* it,
1083 ShadowFrameSetter* setter)
1084 REQUIRES_SHARED(Locks::mutator_lock_) {
1085 StackHandleScope<1> hs(self);
1086 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
1087 JValue decoded_value;
1088
1089#define COLLECT_PRIMITIVE_ARRAY(Descriptor, Type) \
1090 Handle<mirror::Type ## Array> array = \
1091 hs.NewHandle(mirror::Type ## Array::Alloc(self, array_length)); \
1092 if (array.IsNull()) { \
1093 return false; \
1094 } \
1095 for (int32_t i = 0; it->HasNext(); it->Next(), ++i) { \
1096 auto type = it->GetValueType(); \
1097 DCHECK_EQ(type, EncodedArrayValueIterator::ValueType::k ## Type); \
1098 const JValue encoded_value = \
1099 ConvertScalarBootstrapArgument(it->GetJavaValue()); \
1100 GetArgumentForBootstrapMethod(self, \
1101 referrer, \
1102 type, \
1103 &encoded_value, \
1104 &decoded_value); \
1105 array->Set(i, decoded_value.Get ## Descriptor()); \
1106 } \
1107 setter->SetReference(array.Get()); \
1108 return true;
1109
1110#define COLLECT_REFERENCE_ARRAY(T, Type) \
1111 Handle<mirror::ObjectArray<T>> array = \
1112 hs.NewHandle(mirror::ObjectArray<T>::Alloc(self, \
1113 array_type, \
1114 array_length)); \
1115 if (array.IsNull()) { \
1116 return false; \
1117 } \
1118 for (int32_t i = 0; it->HasNext(); it->Next(), ++i) { \
1119 auto type = it->GetValueType(); \
1120 DCHECK_EQ(type, EncodedArrayValueIterator::ValueType::k ## Type); \
1121 const JValue encoded_value = \
1122 ConvertScalarBootstrapArgument(it->GetJavaValue()); \
1123 if (!GetArgumentForBootstrapMethod(self, \
1124 referrer, \
1125 type, \
1126 &encoded_value, \
1127 &decoded_value)) { \
1128 return false; \
1129 } \
1130 ObjPtr<mirror::Object> o = decoded_value.GetL(); \
1131 if (Runtime::Current()->IsActiveTransaction()) { \
1132 array->Set<true>(i, ObjPtr<T>::DownCast(o)); \
1133 } else { \
1134 array->Set<false>(i, ObjPtr<T>::DownCast(o)); \
1135 } \
1136 } \
1137 setter->SetReference(array.Get()); \
1138 return true;
1139
1140 if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('I')) {
1141 COLLECT_PRIMITIVE_ARRAY(I, Int);
1142 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('J')) {
1143 COLLECT_PRIMITIVE_ARRAY(J, Long);
1144 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('F')) {
1145 COLLECT_PRIMITIVE_ARRAY(F, Float);
1146 } else if (array_type->GetComponentType() == class_linker->FindPrimitiveClass('D')) {
1147 COLLECT_PRIMITIVE_ARRAY(D, Double);
1148 } else if (array_type->GetComponentType() == mirror::MethodType::StaticClass()) {
1149 COLLECT_REFERENCE_ARRAY(mirror::MethodType, MethodType);
1150 } else if (array_type->GetComponentType() == mirror::MethodHandle::StaticClass()) {
1151 COLLECT_REFERENCE_ARRAY(mirror::MethodHandle, MethodHandle);
1152 } else if (array_type->GetComponentType() == mirror::String::GetJavaLangString()) {
1153 COLLECT_REFERENCE_ARRAY(mirror::String, String);
1154 } else if (array_type->GetComponentType() == mirror::Class::GetJavaLangClass()) {
1155 COLLECT_REFERENCE_ARRAY(mirror::Class, Type);
1156 } else {
1157 UNREACHABLE();
1158 }
1159 #undef COLLECT_PRIMITIVE_ARRAY
1160 #undef COLLECT_REFERENCE_ARRAY
1161}
1162
1163static ObjPtr<mirror::MethodType> BuildCallSiteForBootstrapMethod(Thread* self,
1164 const DexFile* dex_file,
1165 uint32_t call_site_idx)
1166 REQUIRES_SHARED(Locks::mutator_lock_) {
1167 const DexFile::CallSiteIdItem& csi = dex_file->GetCallSiteId(call_site_idx);
1168 CallSiteArrayValueIterator it(*dex_file, csi);
1169 DCHECK_GE(it.Size(), 1u);
1170
1171 StackHandleScope<2> hs(self);
1172 // Create array for parameter types.
1173 ObjPtr<mirror::Class> class_type = mirror::Class::GetJavaLangClass();
1174 mirror::Class* class_array_type =
1175 Runtime::Current()->GetClassLinker()->FindArrayClass(self, &class_type);
1176 Handle<mirror::ObjectArray<mirror::Class>> ptypes = hs.NewHandle(
1177 mirror::ObjectArray<mirror::Class>::Alloc(self,
1178 class_array_type,
1179 static_cast<int>(it.Size())));
1180 if (ptypes.IsNull()) {
1181 DCHECK(self->IsExceptionPending());
1182 return nullptr;
1183 }
1184
1185 // Populate the first argument with an instance of j.l.i.MethodHandles.Lookup
1186 // that the runtime will construct.
1187 ptypes->Set(0, mirror::MethodHandlesLookup::StaticClass());
1188 it.Next();
1189
1190 // The remaining parameter types are derived from the types of
1191 // arguments present in the DEX file.
1192 int index = 1;
1193 while (it.HasNext()) {
1194 ObjPtr<mirror::Class> ptype = GetClassForBootstrapArgument(it.GetValueType());
1195 if (ptype.IsNull()) {
1196 ThrowClassCastException("Unsupported bootstrap argument type");
1197 return nullptr;
1198 }
1199 ptypes->Set(index, ptype);
1200 index++;
1201 it.Next();
1202 }
1203 DCHECK_EQ(static_cast<size_t>(index), it.Size());
1204
1205 // By definition, the return type is always a j.l.i.CallSite.
1206 Handle<mirror::Class> rtype = hs.NewHandle(mirror::CallSite::StaticClass());
1207 return mirror::MethodType::Create(self, rtype, ptypes);
1208}
1209
Orion Hodsonc069a302017-01-18 09:23:12 +00001210static ObjPtr<mirror::CallSite> InvokeBootstrapMethod(Thread* self,
1211 ShadowFrame& shadow_frame,
1212 uint32_t call_site_idx)
1213 REQUIRES_SHARED(Locks::mutator_lock_) {
Orion Hodsona5dca522018-02-27 12:42:11 +00001214 StackHandleScope<7> hs(self);
1215 // There are three mandatory arguments expected from the call site
1216 // value array in the DEX file: the bootstrap method handle, the
1217 // method name to pass to the bootstrap method, and the method type
1218 // to pass to the bootstrap method.
1219 static constexpr size_t kMandatoryArgumentsCount = 3;
Orion Hodsonc069a302017-01-18 09:23:12 +00001220 ArtMethod* referrer = shadow_frame.GetMethod();
1221 const DexFile* dex_file = referrer->GetDexFile();
1222 const DexFile::CallSiteIdItem& csi = dex_file->GetCallSiteId(call_site_idx);
Orion Hodsonc069a302017-01-18 09:23:12 +00001223 CallSiteArrayValueIterator it(*dex_file, csi);
Orion Hodsona5dca522018-02-27 12:42:11 +00001224 if (it.Size() < kMandatoryArgumentsCount) {
1225 ThrowBootstrapMethodError("Truncated bootstrap arguments (%zu < %zu)",
1226 it.Size(), kMandatoryArgumentsCount);
1227 return nullptr;
1228 }
1229
1230 if (it.GetValueType() != EncodedArrayValueIterator::ValueType::kMethodHandle) {
1231 ThrowBootstrapMethodError("First bootstrap argument is not a method handle");
1232 return nullptr;
1233 }
1234
1235 uint32_t bsm_index = static_cast<uint32_t>(it.GetJavaValue().i);
1236 it.Next();
1237
Orion Hodsonc069a302017-01-18 09:23:12 +00001238 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
Orion Hodsona5dca522018-02-27 12:42:11 +00001239 Handle<mirror::MethodHandle> bsm =
1240 hs.NewHandle(class_linker->ResolveMethodHandle(self, bsm_index, referrer));
1241 if (bsm.IsNull()) {
Orion Hodsonc069a302017-01-18 09:23:12 +00001242 DCHECK(self->IsExceptionPending());
1243 return nullptr;
1244 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001245
Orion Hodsona5dca522018-02-27 12:42:11 +00001246 if (bsm->GetHandleKind() != mirror::MethodHandle::Kind::kInvokeStatic) {
1247 // JLS suggests also accepting constructors. This is currently
1248 // hard as constructor invocations happen via transformers in ART
1249 // today. The constructor would need to be a class derived from java.lang.invoke.CallSite.
1250 ThrowBootstrapMethodError("Unsupported bootstrap method invocation kind");
1251 return nullptr;
1252 }
1253
1254 // Construct the local call site type information based on the 3
1255 // mandatory arguments provided by the runtime and the static arguments
1256 // in the DEX file. We will use these arguments to build a shadow frame.
1257 MutableHandle<mirror::MethodType> call_site_type =
1258 hs.NewHandle(BuildCallSiteForBootstrapMethod(self, dex_file, call_site_idx));
1259 if (call_site_type.IsNull()) {
1260 DCHECK(self->IsExceptionPending());
1261 return nullptr;
1262 }
1263
1264 // Check if this BSM is targeting a variable arity method. If so,
1265 // we'll need to collect the trailing arguments into an array.
1266 Handle<mirror::Array> collector_arguments;
1267 int32_t collector_arguments_length;
1268 if (bsm->GetTargetMethod()->IsVarargs()) {
1269 int number_of_bsm_parameters = bsm->GetMethodType()->GetNumberOfPTypes();
1270 if (number_of_bsm_parameters == 0) {
1271 ThrowBootstrapMethodError("Variable arity BSM does not have any arguments");
1272 return nullptr;
1273 }
1274 Handle<mirror::Class> collector_array_class =
1275 hs.NewHandle(bsm->GetMethodType()->GetPTypes()->Get(number_of_bsm_parameters - 1));
1276 if (!collector_array_class->IsArrayClass()) {
1277 ThrowBootstrapMethodError("Variable arity BSM does not have array as final argument");
1278 return nullptr;
1279 }
1280 // The call site may include no arguments to be collected. In this
1281 // case the number of arguments must be at least the number of BSM
1282 // parameters less the collector array.
1283 if (call_site_type->GetNumberOfPTypes() < number_of_bsm_parameters - 1) {
1284 ThrowWrongMethodTypeException(bsm->GetMethodType(), call_site_type.Get());
1285 return nullptr;
1286 }
1287 // Check all the arguments to be collected match the collector array component type.
1288 for (int i = number_of_bsm_parameters - 1; i < call_site_type->GetNumberOfPTypes(); ++i) {
1289 if (call_site_type->GetPTypes()->Get(i) != collector_array_class->GetComponentType()) {
1290 ThrowClassCastException(collector_array_class->GetComponentType(),
1291 call_site_type->GetPTypes()->Get(i));
1292 return nullptr;
1293 }
1294 }
1295 // Update the call site method type so it now includes the collector array.
1296 int32_t collector_arguments_start = number_of_bsm_parameters - 1;
1297 collector_arguments_length = call_site_type->GetNumberOfPTypes() - number_of_bsm_parameters + 1;
1298 call_site_type.Assign(
1299 mirror::MethodType::CollectTrailingArguments(self,
1300 call_site_type.Get(),
1301 collector_array_class.Get(),
1302 collector_arguments_start));
1303 if (call_site_type.IsNull()) {
1304 DCHECK(self->IsExceptionPending());
1305 return nullptr;
1306 }
1307 } else {
1308 collector_arguments_length = 0;
1309 }
1310
1311 if (call_site_type->GetNumberOfPTypes() != bsm->GetMethodType()->GetNumberOfPTypes()) {
1312 ThrowWrongMethodTypeException(bsm->GetMethodType(), call_site_type.Get());
1313 return nullptr;
1314 }
1315
1316 // BSM invocation has a different set of exceptions that
1317 // j.l.i.MethodHandle.invoke(). Scan arguments looking for CCE
1318 // "opportunities". Unfortunately we cannot just leave this to the
1319 // method handle invocation as this might generate a WMTE.
1320 for (int32_t i = 0; i < call_site_type->GetNumberOfPTypes(); ++i) {
1321 ObjPtr<mirror::Class> from = call_site_type->GetPTypes()->Get(i);
1322 ObjPtr<mirror::Class> to = bsm->GetMethodType()->GetPTypes()->Get(i);
1323 if (!IsParameterTypeConvertible(from, to)) {
1324 ThrowClassCastException(from, to);
1325 return nullptr;
1326 }
1327 }
1328 if (!IsReturnTypeConvertible(call_site_type->GetRType(), bsm->GetMethodType()->GetRType())) {
1329 ThrowClassCastException(bsm->GetMethodType()->GetRType(), call_site_type->GetRType());
1330 return nullptr;
1331 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001332
1333 // Set-up a shadow frame for invoking the bootstrap method handle.
1334 ShadowFrameAllocaUniquePtr bootstrap_frame =
Orion Hodsona5dca522018-02-27 12:42:11 +00001335 CREATE_SHADOW_FRAME(call_site_type->NumberOfVRegs(),
1336 nullptr,
1337 referrer,
1338 shadow_frame.GetDexPC());
Orion Hodsonc069a302017-01-18 09:23:12 +00001339 ScopedStackedShadowFramePusher pusher(
1340 self, bootstrap_frame.get(), StackedShadowFrameType::kShadowFrameUnderConstruction);
Orion Hodsona5dca522018-02-27 12:42:11 +00001341 ShadowFrameSetter setter(bootstrap_frame.get(), 0u);
Orion Hodsonc069a302017-01-18 09:23:12 +00001342
1343 // The first parameter is a MethodHandles lookup instance.
Orion Hodsona5dca522018-02-27 12:42:11 +00001344 Handle<mirror::Class> lookup_class =
1345 hs.NewHandle(shadow_frame.GetMethod()->GetDeclaringClass());
1346 ObjPtr<mirror::MethodHandlesLookup> lookup =
1347 mirror::MethodHandlesLookup::Create(self, lookup_class);
1348 if (lookup.IsNull()) {
Orion Hodsonc069a302017-01-18 09:23:12 +00001349 DCHECK(self->IsExceptionPending());
1350 return nullptr;
1351 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001352 setter.SetReference(lookup);
Orion Hodsonc069a302017-01-18 09:23:12 +00001353
Orion Hodsona5dca522018-02-27 12:42:11 +00001354 // Pack the remaining arguments into the frame.
1355 int number_of_arguments = call_site_type->GetNumberOfPTypes();
1356 int argument_index;
1357 for (argument_index = 1; argument_index < number_of_arguments; ++argument_index) {
1358 if (argument_index == number_of_arguments - 1 &&
1359 call_site_type->GetPTypes()->Get(argument_index)->IsArrayClass()) {
1360 ObjPtr<mirror::Class> array_type = call_site_type->GetPTypes()->Get(argument_index);
1361 if (!PackCollectorArrayForBootstrapMethod(self,
1362 referrer,
1363 array_type,
1364 collector_arguments_length,
1365 &it,
1366 &setter)) {
1367 DCHECK(self->IsExceptionPending());
1368 return nullptr;
Orion Hodsonc069a302017-01-18 09:23:12 +00001369 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001370 } else if (!PackArgumentForBootstrapMethod(self, referrer, &it, &setter)) {
1371 DCHECK(self->IsExceptionPending());
1372 return nullptr;
Orion Hodsonc069a302017-01-18 09:23:12 +00001373 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001374 it.Next();
1375 }
Orion Hodsona5dca522018-02-27 12:42:11 +00001376 DCHECK(!it.HasNext());
1377 DCHECK(setter.Done());
Orion Hodsonc069a302017-01-18 09:23:12 +00001378
1379 // Invoke the bootstrap method handle.
1380 JValue result;
Orion Hodsona5dca522018-02-27 12:42:11 +00001381 RangeInstructionOperands operands(0, bootstrap_frame->NumberOfVRegs());
1382 bool invoke_success = MethodHandleInvoke(self,
1383 *bootstrap_frame,
1384 bsm,
1385 call_site_type,
1386 &operands,
1387 &result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001388 if (!invoke_success) {
1389 DCHECK(self->IsExceptionPending());
1390 return nullptr;
1391 }
1392
1393 Handle<mirror::Object> object(hs.NewHandle(result.GetL()));
Orion Hodsonc069a302017-01-18 09:23:12 +00001394 if (UNLIKELY(object.IsNull())) {
Orion Hodsonda1cdd02018-01-31 18:08:28 +00001395 // This will typically be for LambdaMetafactory which is not supported.
Orion Hodson76e6adb2018-02-23 13:15:55 +00001396 ThrowClassCastException("Bootstrap method returned null");
Orion Hodsonc069a302017-01-18 09:23:12 +00001397 return nullptr;
1398 }
1399
Orion Hodsona5dca522018-02-27 12:42:11 +00001400 // Check the result type is a subclass of j.l.i.CallSite.
Orion Hodsonc069a302017-01-18 09:23:12 +00001401 if (UNLIKELY(!object->InstanceOf(mirror::CallSite::StaticClass()))) {
1402 ThrowClassCastException(object->GetClass(), mirror::CallSite::StaticClass());
1403 return nullptr;
1404 }
1405
Orion Hodsona5dca522018-02-27 12:42:11 +00001406 // Check the call site target is not null as we're going to invoke it.
Orion Hodsonc069a302017-01-18 09:23:12 +00001407 Handle<mirror::CallSite> call_site =
1408 hs.NewHandle(ObjPtr<mirror::CallSite>::DownCast(ObjPtr<mirror::Object>(result.GetL())));
Orion Hodsonc069a302017-01-18 09:23:12 +00001409 Handle<mirror::MethodHandle> target = hs.NewHandle(call_site->GetTarget());
1410 if (UNLIKELY(target.IsNull())) {
Orion Hodsona5dca522018-02-27 12:42:11 +00001411 ThrowClassCastException("Bootstrap method returned a CallSite with a null target");
Orion Hodsonc069a302017-01-18 09:23:12 +00001412 return nullptr;
1413 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001414 return call_site.Get();
1415}
1416
1417template<bool is_range>
1418bool DoInvokeCustom(Thread* self,
1419 ShadowFrame& shadow_frame,
1420 const Instruction* inst,
1421 uint16_t inst_data,
1422 JValue* result)
1423 REQUIRES_SHARED(Locks::mutator_lock_) {
Alex Light848574c2017-09-25 16:59:39 -07001424 // Make sure to check for async exceptions
1425 if (UNLIKELY(self->ObserveAsyncException())) {
1426 return false;
1427 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001428 // invoke-custom is not supported in transactions. In transactions
1429 // there is a limited set of types supported. invoke-custom allows
1430 // running arbitrary code and instantiating arbitrary types.
1431 CHECK(!Runtime::Current()->IsActiveTransaction());
1432 StackHandleScope<4> hs(self);
1433 Handle<mirror::DexCache> dex_cache(hs.NewHandle(shadow_frame.GetMethod()->GetDexCache()));
1434 const uint32_t call_site_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
1435 MutableHandle<mirror::CallSite>
1436 call_site(hs.NewHandle(dex_cache->GetResolvedCallSite(call_site_idx)));
1437 if (call_site.IsNull()) {
1438 call_site.Assign(InvokeBootstrapMethod(self, shadow_frame, call_site_idx));
1439 if (UNLIKELY(call_site.IsNull())) {
1440 CHECK(self->IsExceptionPending());
Orion Hodsona5dca522018-02-27 12:42:11 +00001441 if (!self->GetException()->IsError()) {
1442 // Use a BootstrapMethodError if the exception is not an instance of java.lang.Error.
1443 ThrowWrappedBootstrapMethodError("Exception from call site #%u bootstrap method",
1444 call_site_idx);
1445 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001446 result->SetJ(0);
1447 return false;
1448 }
1449 mirror::CallSite* winning_call_site =
1450 dex_cache->SetResolvedCallSite(call_site_idx, call_site.Get());
1451 call_site.Assign(winning_call_site);
1452 }
1453
Orion Hodsonc069a302017-01-18 09:23:12 +00001454 Handle<mirror::MethodHandle> target = hs.NewHandle(call_site->GetTarget());
1455 Handle<mirror::MethodType> target_method_type = hs.NewHandle(target->GetMethodType());
1456 DCHECK_EQ(static_cast<size_t>(inst->VRegA()), target_method_type->NumberOfVRegs());
Orion Hodsonc069a302017-01-18 09:23:12 +00001457 if (is_range) {
Orion Hodson960d4f72017-11-10 15:32:38 +00001458 RangeInstructionOperands operands(inst->VRegC_3rc(), inst->VRegA_3rc());
1459 return MethodHandleInvokeExact(self,
1460 shadow_frame,
1461 target,
1462 target_method_type,
1463 &operands,
1464 result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001465 } else {
Orion Hodson960d4f72017-11-10 15:32:38 +00001466 uint32_t args[Instruction::kMaxVarArgRegs];
Orion Hodsonc069a302017-01-18 09:23:12 +00001467 inst->GetVarArgs(args, inst_data);
Orion Hodson960d4f72017-11-10 15:32:38 +00001468 VarArgsInstructionOperands operands(args, inst->VRegA_35c());
1469 return MethodHandleInvokeExact(self,
1470 shadow_frame,
1471 target,
1472 target_method_type,
1473 &operands,
1474 result);
Orion Hodsonc069a302017-01-18 09:23:12 +00001475 }
Orion Hodsonc069a302017-01-18 09:23:12 +00001476}
1477
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001478template <bool is_range>
1479inline void CopyRegisters(ShadowFrame& caller_frame,
1480 ShadowFrame* callee_frame,
1481 const uint32_t (&arg)[Instruction::kMaxVarArgRegs],
1482 const size_t first_src_reg,
1483 const size_t first_dest_reg,
1484 const size_t num_regs) {
1485 if (is_range) {
1486 const size_t dest_reg_bound = first_dest_reg + num_regs;
1487 for (size_t src_reg = first_src_reg, dest_reg = first_dest_reg; dest_reg < dest_reg_bound;
1488 ++dest_reg, ++src_reg) {
1489 AssignRegister(callee_frame, caller_frame, dest_reg, src_reg);
1490 }
1491 } else {
1492 DCHECK_LE(num_regs, arraysize(arg));
1493
1494 for (size_t arg_index = 0; arg_index < num_regs; ++arg_index) {
1495 AssignRegister(callee_frame, caller_frame, first_dest_reg + arg_index, arg[arg_index]);
1496 }
1497 }
1498}
1499
Igor Murashkin6918bf12015-09-27 19:19:06 -07001500template <bool is_range,
Narayan Kamath370423d2016-10-03 16:51:22 +01001501 bool do_assignability_check>
Igor Murashkin158f35c2015-06-10 15:55:30 -07001502static inline bool DoCallCommon(ArtMethod* called_method,
1503 Thread* self,
1504 ShadowFrame& shadow_frame,
1505 JValue* result,
1506 uint16_t number_of_inputs,
Narayan Kamath370423d2016-10-03 16:51:22 +01001507 uint32_t (&arg)[Instruction::kMaxVarArgRegs],
Igor Murashkin158f35c2015-06-10 15:55:30 -07001508 uint32_t vregC) {
Jeff Hao848f70a2014-01-15 13:49:50 -08001509 bool string_init = false;
1510 // Replace calls to String.<init> with equivalent StringFactory call.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001511 if (UNLIKELY(called_method->GetDeclaringClass()->IsStringClass()
1512 && called_method->IsConstructor())) {
Nicolas Geoffrayda079bb2016-09-26 17:56:07 +01001513 called_method = WellKnownClasses::StringInitToStringFactory(called_method);
Jeff Hao848f70a2014-01-15 13:49:50 -08001514 string_init = true;
1515 }
1516
Alex Lightdaf58c82016-03-16 23:00:49 +00001517 // Compute method information.
David Sehr0225f8e2018-01-31 08:52:24 +00001518 CodeItemDataAccessor accessor(called_method->DexInstructionData());
Igor Murashkin158f35c2015-06-10 15:55:30 -07001519 // Number of registers for the callee's call frame.
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001520 uint16_t num_regs;
Jeff Hao5ea84132017-05-05 16:59:29 -07001521 // Test whether to use the interpreter or compiler entrypoint, and save that result to pass to
1522 // PerformCall. A deoptimization could occur at any time, and we shouldn't change which
1523 // entrypoint to use once we start building the shadow frame.
Mathieu Chartier448bbcf2017-07-06 12:05:13 -07001524
1525 // For unstarted runtimes, always use the interpreter entrypoint. This fixes the case where we are
1526 // doing cross compilation. Note that GetEntryPointFromQuickCompiledCode doesn't use the image
1527 // pointer size here and this may case an overflow if it is called from the compiler. b/62402160
1528 const bool use_interpreter_entrypoint = !Runtime::Current()->IsStarted() ||
1529 ClassLinker::ShouldUseInterpreterEntrypoint(
1530 called_method,
1531 called_method->GetEntryPointFromQuickCompiledCode());
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001532 if (LIKELY(accessor.HasCodeItem())) {
Jeff Hao5ea84132017-05-05 16:59:29 -07001533 // When transitioning to compiled code, space only needs to be reserved for the input registers.
1534 // The rest of the frame gets discarded. This also prevents accessing the called method's code
1535 // item, saving memory by keeping code items of compiled code untouched.
Mathieu Chartier448bbcf2017-07-06 12:05:13 -07001536 if (!use_interpreter_entrypoint) {
1537 DCHECK(!Runtime::Current()->IsAotCompiler()) << "Compiler should use interpreter entrypoint";
Jeff Hao5ea84132017-05-05 16:59:29 -07001538 num_regs = number_of_inputs;
1539 } else {
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001540 num_regs = accessor.RegistersSize();
1541 DCHECK_EQ(string_init ? number_of_inputs - 1 : number_of_inputs, accessor.InsSize());
Jeff Hao5ea84132017-05-05 16:59:29 -07001542 }
Nicolas Geoffray01822292017-03-09 09:03:19 +00001543 } else {
1544 DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
1545 num_regs = number_of_inputs;
Jeff Haodf79ddb2017-02-27 14:47:06 -08001546 }
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001547
Igor Murashkin158f35c2015-06-10 15:55:30 -07001548 // Hack for String init:
1549 //
1550 // Rewrite invoke-x java.lang.String.<init>(this, a, b, c, ...) into:
1551 // invoke-x StringFactory(a, b, c, ...)
1552 // by effectively dropping the first virtual register from the invoke.
1553 //
1554 // (at this point the ArtMethod has already been replaced,
1555 // so we just need to fix-up the arguments)
David Brazdil65902e82016-01-15 09:35:13 +00001556 //
1557 // Note that FindMethodFromCode in entrypoint_utils-inl.h was also special-cased
1558 // to handle the compiler optimization of replacing `this` with null without
1559 // throwing NullPointerException.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001560 uint32_t string_init_vreg_this = is_range ? vregC : arg[0];
Igor Murashkina06b49b2015-06-25 15:18:12 -07001561 if (UNLIKELY(string_init)) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001562 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 -07001563
Igor Murashkin158f35c2015-06-10 15:55:30 -07001564 // The new StringFactory call is static and has one fewer argument.
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001565 if (!accessor.HasCodeItem()) {
Igor Murashkina06b49b2015-06-25 15:18:12 -07001566 DCHECK(called_method->IsNative() || called_method->IsProxyMethod());
1567 num_regs--;
1568 } // 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 -07001569 number_of_inputs--;
1570
1571 // Rewrite the var-args, dropping the 0th argument ("this")
Igor Murashkin6918bf12015-09-27 19:19:06 -07001572 for (uint32_t i = 1; i < arraysize(arg); ++i) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001573 arg[i - 1] = arg[i];
1574 }
Igor Murashkin6918bf12015-09-27 19:19:06 -07001575 arg[arraysize(arg) - 1] = 0;
Igor Murashkin158f35c2015-06-10 15:55:30 -07001576
1577 // Rewrite the non-var-arg case
1578 vregC++; // Skips the 0th vreg in the range ("this").
1579 }
1580
1581 // Parameter registers go at the end of the shadow frame.
1582 DCHECK_GE(num_regs, number_of_inputs);
1583 size_t first_dest_reg = num_regs - number_of_inputs;
1584 DCHECK_NE(first_dest_reg, (size_t)-1);
1585
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001586 // Allocate shadow frame on the stack.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001587 const char* old_cause = self->StartAssertNoThreadSuspension("DoCallCommon");
Andreas Gampeb3025922015-09-01 14:45:00 -07001588 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe03ec9302015-08-27 17:41:47 -07001589 CREATE_SHADOW_FRAME(num_regs, &shadow_frame, called_method, /* dex pc */ 0);
Andreas Gampeb3025922015-09-01 14:45:00 -07001590 ShadowFrame* new_shadow_frame = shadow_frame_unique_ptr.get();
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001591
Igor Murashkin158f35c2015-06-10 15:55:30 -07001592 // Initialize new shadow frame by copying the registers from the callee shadow frame.
Jeff Haoa3faaf42013-09-03 19:07:00 -07001593 if (do_assignability_check) {
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001594 // Slow path.
1595 // We might need to do class loading, which incurs a thread state change to kNative. So
1596 // register the shadow frame as under construction and allow suspension again.
Mingyao Yang1f2d3ba2015-05-18 12:12:50 -07001597 ScopedStackedShadowFramePusher pusher(
Sebastien Hertzf7958692015-06-09 14:09:14 +02001598 self, new_shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction);
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001599 self->EndAssertNoThreadSuspension(old_cause);
1600
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001601 // ArtMethod here is needed to check type information of the call site against the callee.
1602 // Type information is retrieved from a DexFile/DexCache for that respective declared method.
1603 //
1604 // As a special case for proxy methods, which are not dex-backed,
1605 // we have to retrieve type information from the proxy's method
1606 // interface method instead (which is dex backed since proxies are never interfaces).
Andreas Gampe542451c2016-07-26 09:02:02 -07001607 ArtMethod* method =
1608 new_shadow_frame->GetMethod()->GetInterfaceMethodIfProxy(kRuntimePointerSize);
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001609
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001610 // We need to do runtime check on reference assignment. We need to load the shorty
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001611 // to get the exact type of each reference argument.
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001612 const DexFile::TypeList* params = method->GetParameterTypeList();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001613 uint32_t shorty_len = 0;
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001614 const char* shorty = method->GetShorty(&shorty_len);
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001615
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001616 // Handle receiver apart since it's not part of the shorty.
1617 size_t dest_reg = first_dest_reg;
1618 size_t arg_offset = 0;
Igor Murashkin158f35c2015-06-10 15:55:30 -07001619
Igor Murashkin9f95ba72016-02-01 14:21:25 -08001620 if (!method->IsStatic()) {
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07001621 size_t receiver_reg = is_range ? vregC : arg[0];
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001622 new_shadow_frame->SetVRegReference(dest_reg, shadow_frame.GetVRegReference(receiver_reg));
1623 ++dest_reg;
1624 ++arg_offset;
Igor Murashkina06b49b2015-06-25 15:18:12 -07001625 DCHECK(!string_init); // All StringFactory methods are static.
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001626 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001627
1628 // Copy the caller's invoke-* arguments into the callee's parameter registers.
Ian Rogersef7d42f2014-01-06 12:55:46 -08001629 for (uint32_t shorty_pos = 0; dest_reg < num_regs; ++shorty_pos, ++dest_reg, ++arg_offset) {
Igor Murashkina06b49b2015-06-25 15:18:12 -07001630 // Skip the 0th 'shorty' type since it represents the return type.
1631 DCHECK_LT(shorty_pos + 1, shorty_len) << "for shorty '" << shorty << "'";
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001632 const size_t src_reg = (is_range) ? vregC + arg_offset : arg[arg_offset];
1633 switch (shorty[shorty_pos + 1]) {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001634 // Handle Object references. 1 virtual register slot.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001635 case 'L': {
Mathieu Chartieref41db72016-10-25 15:08:01 -07001636 ObjPtr<mirror::Object> o = shadow_frame.GetVRegReference(src_reg);
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001637 if (do_assignability_check && o != nullptr) {
Andreas Gampea5b09a62016-11-17 15:21:22 -08001638 const dex::TypeIndex type_idx = params->GetTypeItem(shorty_pos).type_idx_;
Vladimir Marko942fd312017-01-16 20:52:19 +00001639 ObjPtr<mirror::Class> arg_type = method->GetDexCache()->GetResolvedType(type_idx);
Mathieu Chartier2cebb242015-04-21 16:50:40 -07001640 if (arg_type == nullptr) {
Mathieu Chartiere22305b2016-10-26 21:04:58 -07001641 StackHandleScope<1> hs(self);
1642 // Preserve o since it is used below and GetClassFromTypeIndex may cause thread
1643 // suspension.
1644 HandleWrapperObjPtr<mirror::Object> h = hs.NewHandleWrapper(&o);
Vladimir Markob45528c2017-07-27 14:14:28 +01001645 arg_type = method->ResolveClassFromTypeIndex(type_idx);
Mathieu Chartiere22305b2016-10-26 21:04:58 -07001646 if (arg_type == nullptr) {
1647 CHECK(self->IsExceptionPending());
1648 return false;
1649 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001650 }
1651 if (!o->VerifierInstanceOf(arg_type)) {
1652 // This should never happen.
Ian Rogers1ff3c982014-08-12 02:30:58 -07001653 std::string temp1, temp2;
Orion Hodsonfef06642016-11-25 16:07:11 +00001654 self->ThrowNewExceptionF("Ljava/lang/InternalError;",
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001655 "Invoking %s with bad arg %d, type '%s' not instance of '%s'",
Ian Rogerse94652f2014-12-02 11:13:19 -08001656 new_shadow_frame->GetMethod()->GetName(), shorty_pos,
Ian Rogers1ff3c982014-08-12 02:30:58 -07001657 o->GetClass()->GetDescriptor(&temp1),
1658 arg_type->GetDescriptor(&temp2));
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001659 return false;
1660 }
Jeff Haoa3faaf42013-09-03 19:07:00 -07001661 }
Mathieu Chartieref41db72016-10-25 15:08:01 -07001662 new_shadow_frame->SetVRegReference(dest_reg, o.Ptr());
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001663 break;
Jeff Haoa3faaf42013-09-03 19:07:00 -07001664 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001665 // Handle doubles and longs. 2 consecutive virtual register slots.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001666 case 'J': case 'D': {
Igor Murashkin158f35c2015-06-10 15:55:30 -07001667 uint64_t wide_value =
1668 (static_cast<uint64_t>(shadow_frame.GetVReg(src_reg + 1)) << BitSizeOf<uint32_t>()) |
1669 static_cast<uint32_t>(shadow_frame.GetVReg(src_reg));
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001670 new_shadow_frame->SetVRegLong(dest_reg, wide_value);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001671 // Skip the next virtual register slot since we already used it.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001672 ++dest_reg;
1673 ++arg_offset;
1674 break;
1675 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001676 // Handle all other primitives that are always 1 virtual register slot.
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001677 default:
1678 new_shadow_frame->SetVReg(dest_reg, shadow_frame.GetVReg(src_reg));
1679 break;
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001680 }
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001681 }
1682 } else {
Sebastien Hertz9ace87b2013-09-27 11:48:09 +02001683 if (is_range) {
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001684 DCHECK_EQ(num_regs, first_dest_reg + number_of_inputs);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001685 }
Narayan Kamathc3b7f1a2016-10-19 11:05:04 +01001686
1687 CopyRegisters<is_range>(shadow_frame,
1688 new_shadow_frame,
1689 arg,
1690 vregC,
1691 first_dest_reg,
1692 number_of_inputs);
Andreas Gampe2a0d4ec2014-06-02 22:05:22 -07001693 self->EndAssertNoThreadSuspension(old_cause);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001694 }
1695
Jeff Hao5ea84132017-05-05 16:59:29 -07001696 PerformCall(self,
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001697 accessor,
Jeff Hao5ea84132017-05-05 16:59:29 -07001698 shadow_frame.GetMethod(),
1699 first_dest_reg,
1700 new_shadow_frame,
1701 result,
1702 use_interpreter_entrypoint);
Jeff Hao848f70a2014-01-15 13:49:50 -08001703
1704 if (string_init && !self->IsExceptionPending()) {
Mingyao Yangffedec52016-05-19 10:48:40 -07001705 SetStringInitValueToAllAliases(&shadow_frame, string_init_vreg_this, *result);
Jeff Hao848f70a2014-01-15 13:49:50 -08001706 }
1707
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001708 return !self->IsExceptionPending();
1709}
1710
Igor Murashkin158f35c2015-06-10 15:55:30 -07001711template<bool is_range, bool do_assignability_check>
Igor Murashkin158f35c2015-06-10 15:55:30 -07001712bool DoCall(ArtMethod* called_method, Thread* self, ShadowFrame& shadow_frame,
1713 const Instruction* inst, uint16_t inst_data, JValue* result) {
1714 // Argument word count.
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001715 const uint16_t number_of_inputs =
1716 (is_range) ? inst->VRegA_3rc(inst_data) : inst->VRegA_35c(inst_data);
Igor Murashkin158f35c2015-06-10 15:55:30 -07001717
1718 // TODO: find a cleaner way to separate non-range and range information without duplicating
1719 // code.
Igor Murashkin6918bf12015-09-27 19:19:06 -07001720 uint32_t arg[Instruction::kMaxVarArgRegs] = {}; // only used in invoke-XXX.
Igor Murashkin158f35c2015-06-10 15:55:30 -07001721 uint32_t vregC = 0;
1722 if (is_range) {
1723 vregC = inst->VRegC_3rc();
1724 } else {
1725 vregC = inst->VRegC_35c();
1726 inst->GetVarArgs(arg, inst_data);
1727 }
1728
1729 return DoCallCommon<is_range, do_assignability_check>(
1730 called_method, self, shadow_frame,
1731 result, number_of_inputs, arg, vregC);
1732}
1733
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001734template <bool is_range, bool do_access_check, bool transaction_active>
Mathieu Chartieref41db72016-10-25 15:08:01 -07001735bool DoFilledNewArray(const Instruction* inst,
1736 const ShadowFrame& shadow_frame,
1737 Thread* self,
1738 JValue* result) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001739 DCHECK(inst->Opcode() == Instruction::FILLED_NEW_ARRAY ||
1740 inst->Opcode() == Instruction::FILLED_NEW_ARRAY_RANGE);
1741 const int32_t length = is_range ? inst->VRegA_3rc() : inst->VRegA_35c();
1742 if (!is_range) {
1743 // Checks FILLED_NEW_ARRAY's length does not exceed 5 arguments.
1744 CHECK_LE(length, 5);
1745 }
1746 if (UNLIKELY(length < 0)) {
1747 ThrowNegativeArraySizeException(length);
1748 return false;
1749 }
1750 uint16_t type_idx = is_range ? inst->VRegB_3rc() : inst->VRegB_35c();
Andreas Gampea5b09a62016-11-17 15:21:22 -08001751 ObjPtr<mirror::Class> array_class = ResolveVerifyAndClinit(dex::TypeIndex(type_idx),
Mathieu Chartieref41db72016-10-25 15:08:01 -07001752 shadow_frame.GetMethod(),
1753 self,
1754 false,
1755 do_access_check);
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001756 if (UNLIKELY(array_class == nullptr)) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001757 DCHECK(self->IsExceptionPending());
1758 return false;
1759 }
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001760 CHECK(array_class->IsArrayClass());
Mathieu Chartieref41db72016-10-25 15:08:01 -07001761 ObjPtr<mirror::Class> component_class = array_class->GetComponentType();
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001762 const bool is_primitive_int_component = component_class->IsPrimitiveInt();
1763 if (UNLIKELY(component_class->IsPrimitive() && !is_primitive_int_component)) {
1764 if (component_class->IsPrimitiveLong() || component_class->IsPrimitiveDouble()) {
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001765 ThrowRuntimeException("Bad filled array request for type %s",
David Sehr709b0702016-10-13 09:12:37 -07001766 component_class->PrettyDescriptor().c_str());
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001767 } else {
Nicolas Geoffray0aa50ce2015-03-10 11:03:29 +00001768 self->ThrowNewExceptionF("Ljava/lang/InternalError;",
Brian Carlstrom4fa0bcd2013-12-10 11:24:21 -08001769 "Found type %s; filled-new-array not implemented for anything but 'int'",
David Sehr709b0702016-10-13 09:12:37 -07001770 component_class->PrettyDescriptor().c_str());
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001771 }
1772 return false;
1773 }
Mathieu Chartieref41db72016-10-25 15:08:01 -07001774 ObjPtr<mirror::Object> new_array = mirror::Array::Alloc<true>(
1775 self,
1776 array_class,
1777 length,
1778 array_class->GetComponentSizeShift(),
1779 Runtime::Current()->GetHeap()->GetCurrentAllocator());
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001780 if (UNLIKELY(new_array == nullptr)) {
1781 self->AssertPendingOOMException();
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001782 return false;
1783 }
Igor Murashkin158f35c2015-06-10 15:55:30 -07001784 uint32_t arg[Instruction::kMaxVarArgRegs]; // only used in filled-new-array.
1785 uint32_t vregC = 0; // only used in filled-new-array-range.
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001786 if (is_range) {
Sebastien Hertzabff6432014-01-27 18:01:39 +01001787 vregC = inst->VRegC_3rc();
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001788 } else {
Ian Rogers29a26482014-05-02 15:27:29 -07001789 inst->GetVarArgs(arg);
Sebastien Hertzabff6432014-01-27 18:01:39 +01001790 }
Sebastien Hertzabff6432014-01-27 18:01:39 +01001791 for (int32_t i = 0; i < length; ++i) {
1792 size_t src_reg = is_range ? vregC + i : arg[i];
1793 if (is_primitive_int_component) {
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001794 new_array->AsIntArray()->SetWithoutChecks<transaction_active>(
1795 i, shadow_frame.GetVReg(src_reg));
Sebastien Hertzabff6432014-01-27 18:01:39 +01001796 } else {
Mathieu Chartieref41db72016-10-25 15:08:01 -07001797 new_array->AsObjectArray<mirror::Object>()->SetWithoutChecks<transaction_active>(
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001798 i, shadow_frame.GetVRegReference(src_reg));
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001799 }
1800 }
1801
Mathieu Chartier52ea33b2015-06-18 16:48:52 -07001802 result->SetL(new_array);
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001803 return true;
1804}
1805
Mathieu Chartieref41db72016-10-25 15:08:01 -07001806// TODO: Use ObjPtr here.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001807template<typename T>
Mathieu Chartieref41db72016-10-25 15:08:01 -07001808static void RecordArrayElementsInTransactionImpl(mirror::PrimitiveArray<T>* array,
1809 int32_t count)
1810 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001811 Runtime* runtime = Runtime::Current();
1812 for (int32_t i = 0; i < count; ++i) {
1813 runtime->RecordWriteArray(array, i, array->GetWithoutChecks(i));
1814 }
1815}
1816
Mathieu Chartieref41db72016-10-25 15:08:01 -07001817void RecordArrayElementsInTransaction(ObjPtr<mirror::Array> array, int32_t count)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001818 REQUIRES_SHARED(Locks::mutator_lock_) {
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001819 DCHECK(Runtime::Current()->IsActiveTransaction());
1820 DCHECK(array != nullptr);
1821 DCHECK_LE(count, array->GetLength());
1822 Primitive::Type primitive_component_type = array->GetClass()->GetComponentType()->GetPrimitiveType();
1823 switch (primitive_component_type) {
1824 case Primitive::kPrimBoolean:
1825 RecordArrayElementsInTransactionImpl(array->AsBooleanArray(), count);
1826 break;
1827 case Primitive::kPrimByte:
1828 RecordArrayElementsInTransactionImpl(array->AsByteArray(), count);
1829 break;
1830 case Primitive::kPrimChar:
1831 RecordArrayElementsInTransactionImpl(array->AsCharArray(), count);
1832 break;
1833 case Primitive::kPrimShort:
1834 RecordArrayElementsInTransactionImpl(array->AsShortArray(), count);
1835 break;
1836 case Primitive::kPrimInt:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001837 RecordArrayElementsInTransactionImpl(array->AsIntArray(), count);
1838 break;
Mathieu Chartiere401d142015-04-22 13:56:20 -07001839 case Primitive::kPrimFloat:
1840 RecordArrayElementsInTransactionImpl(array->AsFloatArray(), count);
1841 break;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001842 case Primitive::kPrimLong:
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001843 RecordArrayElementsInTransactionImpl(array->AsLongArray(), count);
1844 break;
Mathieu Chartiere401d142015-04-22 13:56:20 -07001845 case Primitive::kPrimDouble:
1846 RecordArrayElementsInTransactionImpl(array->AsDoubleArray(), count);
1847 break;
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001848 default:
1849 LOG(FATAL) << "Unsupported primitive type " << primitive_component_type
1850 << " in fill-array-data";
1851 break;
1852 }
1853}
1854
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001855// Explicit DoCall template function declarations.
Sebastien Hertzc6714852013-09-30 16:42:32 +02001856#define EXPLICIT_DO_CALL_TEMPLATE_DECL(_is_range, _do_assignability_check) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001857 template REQUIRES_SHARED(Locks::mutator_lock_) \
Sebastien Hertz9119c5f2013-12-16 11:31:45 +01001858 bool DoCall<_is_range, _do_assignability_check>(ArtMethod* method, Thread* self, \
1859 ShadowFrame& shadow_frame, \
Sebastien Hertzc6714852013-09-30 16:42:32 +02001860 const Instruction* inst, uint16_t inst_data, \
1861 JValue* result)
Sebastien Hertzc61124b2013-09-10 11:44:19 +02001862EXPLICIT_DO_CALL_TEMPLATE_DECL(false, false);
1863EXPLICIT_DO_CALL_TEMPLATE_DECL(false, true);
1864EXPLICIT_DO_CALL_TEMPLATE_DECL(true, false);
1865EXPLICIT_DO_CALL_TEMPLATE_DECL(true, true);
1866#undef EXPLICIT_DO_CALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001867
Orion Hodsonc069a302017-01-18 09:23:12 +00001868// Explicit DoInvokePolymorphic template function declarations.
1869#define EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(_is_range) \
1870 template REQUIRES_SHARED(Locks::mutator_lock_) \
1871 bool DoInvokePolymorphic<_is_range>( \
1872 Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1873 uint16_t inst_data, JValue* result)
1874EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(false);
1875EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL(true);
Narayan Kamath9823e782016-08-03 12:46:58 +01001876#undef EXPLICIT_DO_INVOKE_POLYMORPHIC_TEMPLATE_DECL
1877
Orion Hodson43f0cdb2017-10-10 14:47:32 +01001878// Explicit DoInvokeCustom template function declarations.
1879#define EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(_is_range) \
1880 template REQUIRES_SHARED(Locks::mutator_lock_) \
1881 bool DoInvokeCustom<_is_range>( \
1882 Thread* self, ShadowFrame& shadow_frame, const Instruction* inst, \
1883 uint16_t inst_data, JValue* result)
1884EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(false);
1885EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL(true);
1886#undef EXPLICIT_DO_INVOKE_CUSTOM_TEMPLATE_DECL
1887
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001888// Explicit DoFilledNewArray template function declarations.
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001889#define EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(_is_range_, _check, _transaction_active) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001890 template REQUIRES_SHARED(Locks::mutator_lock_) \
Sebastien Hertzd2fe10a2014-01-15 10:20:56 +01001891 bool DoFilledNewArray<_is_range_, _check, _transaction_active>(const Instruction* inst, \
1892 const ShadowFrame& shadow_frame, \
1893 Thread* self, JValue* result)
1894#define EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(_transaction_active) \
1895 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, false, _transaction_active); \
1896 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(false, true, _transaction_active); \
1897 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, false, _transaction_active); \
1898 EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL(true, true, _transaction_active)
1899EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(false);
1900EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL(true);
1901#undef EXPLICIT_DO_FILLED_NEW_ARRAY_ALL_TEMPLATE_DECL
Sebastien Hertz8ece0502013-08-07 11:26:41 +02001902#undef EXPLICIT_DO_FILLED_NEW_ARRAY_TEMPLATE_DECL
1903
1904} // namespace interpreter
1905} // namespace art