blob: cfcf10e3ef75e9bc628533b4e2603dc2b44aac9a [file] [log] [blame]
Ian Rogers848871b2013-08-05 10:56:33 -07001/*
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
Mathieu Chartiere401d142015-04-22 13:56:20 -070017#include "art_method-inl.h"
Andreas Gampe8228cdf2017-05-30 15:03:54 -070018#include "base/callee_save_type.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070019#include "base/enums.h"
Ian Rogers848871b2013-08-05 10:56:33 -070020#include "callee_save_frame.h"
Dragos Sbirleabd136a22013-08-13 18:07:04 -070021#include "common_throws.h"
Vladimir Marko5868ada2020-05-12 11:50:34 +010022#include "class_root-inl.h"
Vladimir Marko606adb32018-04-05 14:49:24 +010023#include "debug_print.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070024#include "debugger.h"
David Sehr9e734c72018-01-04 17:56:19 -080025#include "dex/dex_file-inl.h"
26#include "dex/dex_file_types.h"
27#include "dex/dex_instruction-inl.h"
David Sehr312f3b22018-03-19 08:39:26 -070028#include "dex/method_reference.h"
Mingyao Yang98d1cc82014-05-15 17:02:16 -070029#include "entrypoints/entrypoint_utils-inl.h"
Vladimir Markod3083dd2018-05-17 08:43:47 +010030#include "entrypoints/quick/callee_save_frame.h"
Ian Rogers6f3dbba2014-10-14 17:41:57 -070031#include "entrypoints/runtime_asm_entrypoints.h"
Ian Rogers83883d72013-10-21 21:07:24 -070032#include "gc/accounting/card_table-inl.h"
Andreas Gampe75a7db62016-09-26 12:04:26 -070033#include "imt_conflict_table.h"
34#include "imtable-inl.h"
Alex Lightb7edcda2017-04-27 13:20:31 -070035#include "instrumentation.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070036#include "interpreter/interpreter.h"
Orion Hodson4c8e12e2018-05-18 08:33:20 +010037#include "interpreter/interpreter_common.h"
Vladimir Marko6ec2a1b2018-05-22 15:33:48 +010038#include "interpreter/shadow_frame-inl.h"
Vladimir Marko2196c652017-11-30 16:16:07 +000039#include "jit/jit.h"
Alex Light2d441b12018-06-08 15:33:21 -070040#include "jit/jit_code_cache.h"
Nicolas Geoffray796d6302016-03-13 22:22:31 +000041#include "linear_alloc.h"
Orion Hodsonac141392017-01-13 11:53:47 +000042#include "method_handles.h"
Ian Rogers848871b2013-08-05 10:56:33 -070043#include "mirror/class-inl.h"
Mathieu Chartier5f3ded42014-04-03 15:25:30 -070044#include "mirror/dex_cache-inl.h"
Mathieu Chartierfc58af42015-04-16 18:00:39 -070045#include "mirror/method.h"
Orion Hodsonac141392017-01-13 11:53:47 +000046#include "mirror/method_handle_impl.h"
Ian Rogers848871b2013-08-05 10:56:33 -070047#include "mirror/object-inl.h"
48#include "mirror/object_array-inl.h"
Orion Hodson537a4fe2018-05-15 13:57:58 +010049#include "mirror/var_handle.h"
Vladimir Markod3d00c02019-11-07 15:09:07 +000050#include "oat.h"
Vladimir Marko0eb882b2017-05-15 13:39:18 +010051#include "oat_file.h"
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +010052#include "oat_quick_method_header.h"
Andreas Gampe639bdd12015-06-03 11:22:45 -070053#include "quick_exception_handler.h"
Ian Rogers848871b2013-08-05 10:56:33 -070054#include "runtime.h"
Mathieu Chartier0795f232016-09-27 18:43:30 -070055#include "scoped_thread_state_change-inl.h"
Andreas Gampeb3025922015-09-01 14:45:00 -070056#include "stack.h"
Andreas Gampe513061a2017-06-01 09:17:34 -070057#include "thread-inl.h"
Orion Hodson537a4fe2018-05-15 13:57:58 +010058#include "var_handles.h"
Orion Hodsonac141392017-01-13 11:53:47 +000059#include "well_known_classes.h"
Ian Rogers848871b2013-08-05 10:56:33 -070060
61namespace art {
62
Mythri Alle5097f832021-11-02 14:52:30 +000063extern "C" NO_RETURN void artDeoptimizeFromCompiledCode(DeoptimizationKind kind, Thread* self);
64extern "C" NO_RETURN void artDeoptimize(Thread* self);
65
Andreas Gampe8228cdf2017-05-30 15:03:54 -070066// Visits the arguments as saved to the stack by a CalleeSaveType::kRefAndArgs callee save frame.
Ian Rogers848871b2013-08-05 10:56:33 -070067class QuickArgumentVisitor {
Ian Rogers936b37f2014-02-14 00:52:24 -080068 // Number of bytes for each out register in the caller method's frame.
69 static constexpr size_t kBytesStackArgLocation = 4;
Alexei Zavjalov41c507a2014-05-15 16:02:46 +070070 // Frame size in bytes of a callee-save frame for RefsAndArgs.
71 static constexpr size_t kQuickCalleeSaveFrame_RefAndArgs_FrameSize =
Vladimir Markod3083dd2018-05-17 08:43:47 +010072 RuntimeCalleeSaveFrame::GetFrameSize(CalleeSaveType::kSaveRefsAndArgs);
73 // Offset of first GPR arg.
74 static constexpr size_t kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset =
75 RuntimeCalleeSaveFrame::GetGpr1Offset(CalleeSaveType::kSaveRefsAndArgs);
76 // Offset of first FPR arg.
77 static constexpr size_t kQuickCalleeSaveFrame_RefAndArgs_Fpr1Offset =
78 RuntimeCalleeSaveFrame::GetFpr1Offset(CalleeSaveType::kSaveRefsAndArgs);
79 // Offset of return address.
80 static constexpr size_t kQuickCalleeSaveFrame_RefAndArgs_ReturnPcOffset =
81 RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveRefsAndArgs);
Ian Rogers848871b2013-08-05 10:56:33 -070082#if defined(__arm__)
83 // The callee save frame is pointed to by SP.
84 // | argN | |
85 // | ... | |
86 // | arg4 | |
87 // | arg3 spill | | Caller's frame
88 // | arg2 spill | |
89 // | arg1 spill | |
90 // | Method* | ---
91 // | LR |
Zheng Xu5667fdb2014-10-23 18:29:55 +080092 // | ... | 4x6 bytes callee saves
93 // | R3 |
94 // | R2 |
95 // | R1 |
96 // | S15 |
97 // | : |
98 // | S0 |
99 // | | 4x2 bytes padding
Ian Rogers848871b2013-08-05 10:56:33 -0700100 // | Method* | <- sp
Andreas Gampe217d6d32017-09-18 12:48:20 -0700101 static constexpr bool kSplitPairAcrossRegisterAndStack = false;
102 static constexpr bool kAlignPairRegister = true;
103 static constexpr bool kQuickSoftFloatAbi = false;
104 static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = true;
Goran Jakovljevicff734982015-08-24 12:58:55 +0000105 static constexpr bool kQuickSkipOddFpRegisters = false;
Zheng Xu5667fdb2014-10-23 18:29:55 +0800106 static constexpr size_t kNumQuickGprArgs = 3;
Andreas Gampe217d6d32017-09-18 12:48:20 -0700107 static constexpr size_t kNumQuickFprArgs = 16;
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800108 static constexpr bool kGprFprLockstep = false;
Ian Rogers936b37f2014-02-14 00:52:24 -0800109 static size_t GprIndexToGprOffset(uint32_t gpr_index) {
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000110 return gpr_index * GetBytesPerGprSpillLocation(kRuntimeISA);
Ian Rogers936b37f2014-02-14 00:52:24 -0800111 }
Stuart Monteithb95a5342014-03-12 13:32:32 +0000112#elif defined(__aarch64__)
113 // The callee save frame is pointed to by SP.
114 // | argN | |
115 // | ... | |
116 // | arg4 | |
117 // | arg3 spill | | Caller's frame
118 // | arg2 spill | |
119 // | arg1 spill | |
120 // | Method* | ---
121 // | LR |
Zheng Xub551fdc2014-07-25 11:49:42 +0800122 // | X29 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000123 // | : |
Serban Constantinescu9bd88b02015-04-22 16:24:46 +0100124 // | X20 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000125 // | X7 |
126 // | : |
127 // | X1 |
Zheng Xub551fdc2014-07-25 11:49:42 +0800128 // | D7 |
Stuart Monteithb95a5342014-03-12 13:32:32 +0000129 // | : |
130 // | D0 |
131 // | | padding
132 // | Method* | <- sp
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500133 static constexpr bool kSplitPairAcrossRegisterAndStack = false;
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000134 static constexpr bool kAlignPairRegister = false;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000135 static constexpr bool kQuickSoftFloatAbi = false; // This is a hard float ABI.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800136 static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = false;
Goran Jakovljevicff734982015-08-24 12:58:55 +0000137 static constexpr bool kQuickSkipOddFpRegisters = false;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000138 static constexpr size_t kNumQuickGprArgs = 7; // 7 arguments passed in GPRs.
139 static constexpr size_t kNumQuickFprArgs = 8; // 8 arguments passed in FPRs.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800140 static constexpr bool kGprFprLockstep = false;
Stuart Monteithb95a5342014-03-12 13:32:32 +0000141 static size_t GprIndexToGprOffset(uint32_t gpr_index) {
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000142 return gpr_index * GetBytesPerGprSpillLocation(kRuntimeISA);
Stuart Monteithb95a5342014-03-12 13:32:32 +0000143 }
Ian Rogers848871b2013-08-05 10:56:33 -0700144#elif defined(__i386__)
145 // The callee save frame is pointed to by SP.
146 // | argN | |
147 // | ... | |
148 // | arg4 | |
149 // | arg3 spill | | Caller's frame
150 // | arg2 spill | |
151 // | arg1 spill | |
152 // | Method* | ---
153 // | Return |
154 // | EBP,ESI,EDI | callee saves
155 // | EBX | arg3
156 // | EDX | arg2
157 // | ECX | arg1
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000158 // | XMM3 | float arg 4
159 // | XMM2 | float arg 3
160 // | XMM1 | float arg 2
161 // | XMM0 | float arg 1
Ian Rogers848871b2013-08-05 10:56:33 -0700162 // | EAX/Method* | <- sp
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500163 static constexpr bool kSplitPairAcrossRegisterAndStack = false;
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000164 static constexpr bool kAlignPairRegister = false;
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000165 static constexpr bool kQuickSoftFloatAbi = false; // This is a hard float ABI.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800166 static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = false;
Goran Jakovljevicff734982015-08-24 12:58:55 +0000167 static constexpr bool kQuickSkipOddFpRegisters = false;
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800168 static constexpr size_t kNumQuickGprArgs = 3; // 3 arguments passed in GPRs.
Mark P Mendell966c3ae2015-01-27 15:45:27 +0000169 static constexpr size_t kNumQuickFprArgs = 4; // 4 arguments passed in FPRs.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800170 static constexpr bool kGprFprLockstep = false;
Ian Rogers936b37f2014-02-14 00:52:24 -0800171 static size_t GprIndexToGprOffset(uint32_t gpr_index) {
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000172 return gpr_index * GetBytesPerGprSpillLocation(kRuntimeISA);
Ian Rogers936b37f2014-02-14 00:52:24 -0800173 }
Ian Rogersef7d42f2014-01-06 12:55:46 -0800174#elif defined(__x86_64__)
Ian Rogers936b37f2014-02-14 00:52:24 -0800175 // The callee save frame is pointed to by SP.
176 // | argN | |
177 // | ... | |
178 // | reg. arg spills | | Caller's frame
179 // | Method* | ---
180 // | Return |
181 // | R15 | callee save
182 // | R14 | callee save
183 // | R13 | callee save
184 // | R12 | callee save
185 // | R9 | arg5
186 // | R8 | arg4
187 // | RSI/R6 | arg1
188 // | RBP/R5 | callee save
189 // | RBX/R3 | callee save
190 // | RDX/R2 | arg2
191 // | RCX/R1 | arg3
192 // | XMM7 | float arg 8
193 // | XMM6 | float arg 7
194 // | XMM5 | float arg 6
195 // | XMM4 | float arg 5
196 // | XMM3 | float arg 4
197 // | XMM2 | float arg 3
198 // | XMM1 | float arg 2
199 // | XMM0 | float arg 1
200 // | Padding |
201 // | RDI/Method* | <- sp
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500202 static constexpr bool kSplitPairAcrossRegisterAndStack = false;
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000203 static constexpr bool kAlignPairRegister = false;
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800204 static constexpr bool kQuickSoftFloatAbi = false; // This is a hard float ABI.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800205 static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = false;
Goran Jakovljevicff734982015-08-24 12:58:55 +0000206 static constexpr bool kQuickSkipOddFpRegisters = false;
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700207 static constexpr size_t kNumQuickGprArgs = 5; // 5 arguments passed in GPRs.
Dmitry Petrochenko58994cd2014-05-17 01:02:18 +0700208 static constexpr size_t kNumQuickFprArgs = 8; // 8 arguments passed in FPRs.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800209 static constexpr bool kGprFprLockstep = false;
Ian Rogers936b37f2014-02-14 00:52:24 -0800210 static size_t GprIndexToGprOffset(uint32_t gpr_index) {
211 switch (gpr_index) {
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000212 case 0: return (4 * GetBytesPerGprSpillLocation(kRuntimeISA));
213 case 1: return (1 * GetBytesPerGprSpillLocation(kRuntimeISA));
214 case 2: return (0 * GetBytesPerGprSpillLocation(kRuntimeISA));
215 case 3: return (5 * GetBytesPerGprSpillLocation(kRuntimeISA));
216 case 4: return (6 * GetBytesPerGprSpillLocation(kRuntimeISA));
Ian Rogers936b37f2014-02-14 00:52:24 -0800217 default:
Andreas Gampec200a4a2014-06-16 18:39:09 -0700218 LOG(FATAL) << "Unexpected GPR index: " << gpr_index;
Elliott Hughesc1896c92018-11-29 11:33:18 -0800219 UNREACHABLE();
Ian Rogers936b37f2014-02-14 00:52:24 -0800220 }
221 }
Ian Rogers848871b2013-08-05 10:56:33 -0700222#else
223#error "Unsupported architecture"
Ian Rogers848871b2013-08-05 10:56:33 -0700224#endif
225
Ian Rogers936b37f2014-02-14 00:52:24 -0800226 public:
Sebastien Hertza836bc92014-11-25 16:30:53 +0100227 // Special handling for proxy methods. Proxy methods are instance methods so the
228 // 'this' object is the 1st argument. They also have the same frame layout as the
229 // kRefAndArgs runtime method. Since 'this' is a reference, it is located in the
230 // 1st GPR.
Roland Levillainfa854e42018-02-07 13:09:55 +0000231 static StackReference<mirror::Object>* GetProxyThisObjectReference(ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700232 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray3a090922015-11-24 09:17:30 +0000233 CHECK((*sp)->IsProxyMethod());
Sebastien Hertza836bc92014-11-25 16:30:53 +0100234 CHECK_GT(kNumQuickGprArgs, 0u);
235 constexpr uint32_t kThisGprIndex = 0u; // 'this' is in the 1st GPR.
236 size_t this_arg_offset = kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset +
237 GprIndexToGprOffset(kThisGprIndex);
238 uint8_t* this_arg_address = reinterpret_cast<uint8_t*>(sp) + this_arg_offset;
Roland Levillainfa854e42018-02-07 13:09:55 +0000239 return reinterpret_cast<StackReference<mirror::Object>*>(this_arg_address);
Sebastien Hertza836bc92014-11-25 16:30:53 +0100240 }
241
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700242 static ArtMethod* GetCallingMethod(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700243 DCHECK((*sp)->IsCalleeSaveMethod());
Andreas Gampe8228cdf2017-05-30 15:03:54 -0700244 return GetCalleeSaveMethodCaller(sp, CalleeSaveType::kSaveRefsAndArgs);
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +0100245 }
246
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700247 static ArtMethod* GetOuterMethod(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700248 DCHECK((*sp)->IsCalleeSaveMethod());
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100249 uint8_t* previous_sp =
250 reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_FrameSize;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700251 return *reinterpret_cast<ArtMethod**>(previous_sp);
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100252 }
253
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700254 static uint32_t GetCallingDexPc(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700255 DCHECK((*sp)->IsCalleeSaveMethod());
Vladimir Markod3083dd2018-05-17 08:43:47 +0100256 constexpr size_t callee_frame_size =
257 RuntimeCalleeSaveFrame::GetFrameSize(CalleeSaveType::kSaveRefsAndArgs);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700258 ArtMethod** caller_sp = reinterpret_cast<ArtMethod**>(
259 reinterpret_cast<uintptr_t>(sp) + callee_frame_size);
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100260 uintptr_t outer_pc = QuickArgumentVisitor::GetCallingPc(sp);
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100261 const OatQuickMethodHeader* current_code = (*caller_sp)->GetOatQuickMethodHeader(outer_pc);
262 uintptr_t outer_pc_offset = current_code->NativeQuickPcOffset(outer_pc);
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100263
Nicolas Geoffray524e7ea2015-10-16 17:13:34 +0100264 if (current_code->IsOptimized()) {
David Srbecky0d4567f2019-05-30 22:45:40 +0100265 CodeInfo code_info = CodeInfo::DecodeInlineInfoOnly(current_code);
David Srbecky052f8ca2018-04-26 15:42:54 +0100266 StackMap stack_map = code_info.GetStackMapForNativePcOffset(outer_pc_offset);
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100267 DCHECK(stack_map.IsValid());
David Srbecky93bd3612018-07-02 19:30:18 +0100268 BitTableRange<InlineInfo> inline_infos = code_info.GetInlineInfosOf(stack_map);
269 if (!inline_infos.empty()) {
270 return inline_infos.back().GetDexPc();
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100271 } else {
David Srbecky052f8ca2018-04-26 15:42:54 +0100272 return stack_map.GetDexPc();
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100273 }
274 } else {
Nicolas Geoffraya00b54b2019-12-03 14:36:42 +0000275 return current_code->ToDexPc(caller_sp, outer_pc);
Nicolas Geoffrayd23eeef2015-05-18 22:31:29 +0100276 }
Ian Rogers848871b2013-08-05 10:56:33 -0700277 }
278
Nicolas Geoffraye91e7952020-01-23 10:15:56 +0000279 static uint8_t* GetCallingPcAddr(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700280 DCHECK((*sp)->IsCalleeSaveMethod());
Vladimir Markod3083dd2018-05-17 08:43:47 +0100281 uint8_t* return_adress_spill =
282 reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_ReturnPcOffset;
Nicolas Geoffraye91e7952020-01-23 10:15:56 +0000283 return return_adress_spill;
284 }
285
286 // For the given quick ref and args quick frame, return the caller's PC.
287 static uintptr_t GetCallingPc(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) {
288 return *reinterpret_cast<uintptr_t*>(GetCallingPcAddr(sp));
Ian Rogers848871b2013-08-05 10:56:33 -0700289 }
290
Mathieu Chartiere401d142015-04-22 13:56:20 -0700291 QuickArgumentVisitor(ArtMethod** sp, bool is_static, const char* shorty,
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700292 uint32_t shorty_len) REQUIRES_SHARED(Locks::mutator_lock_) :
Andreas Gampec200a4a2014-06-16 18:39:09 -0700293 is_static_(is_static), shorty_(shorty), shorty_len_(shorty_len),
Ian Rogers13735952014-10-08 12:43:28 -0700294 gpr_args_(reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset),
295 fpr_args_(reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_Fpr1Offset),
296 stack_args_(reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_FrameSize
Mathieu Chartiere401d142015-04-22 13:56:20 -0700297 + sizeof(ArtMethod*)), // Skip ArtMethod*.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800298 gpr_index_(0), fpr_index_(0), fpr_double_index_(0), stack_index_(0),
299 cur_type_(Primitive::kPrimVoid), is_split_long_or_double_(false) {
Andreas Gampe575e78c2014-11-03 23:41:03 -0800300 static_assert(kQuickSoftFloatAbi == (kNumQuickFprArgs == 0),
301 "Number of Quick FPR arguments unexpected");
302 static_assert(!(kQuickSoftFloatAbi && kQuickDoubleRegAlignedFloatBackFilled),
303 "Double alignment unexpected");
Zheng Xu5667fdb2014-10-23 18:29:55 +0800304 // For register alignment, we want to assume that counters(fpr_double_index_) are even if the
305 // next register is even.
Andreas Gampe575e78c2014-11-03 23:41:03 -0800306 static_assert(!kQuickDoubleRegAlignedFloatBackFilled || kNumQuickFprArgs % 2 == 0,
307 "Number of Quick FPR arguments not even");
Andreas Gampe542451c2016-07-26 09:02:02 -0700308 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
Zheng Xu5667fdb2014-10-23 18:29:55 +0800309 }
Ian Rogers848871b2013-08-05 10:56:33 -0700310
311 virtual ~QuickArgumentVisitor() {}
312
313 virtual void Visit() = 0;
314
Ian Rogers936b37f2014-02-14 00:52:24 -0800315 Primitive::Type GetParamPrimitiveType() const {
316 return cur_type_;
Ian Rogers848871b2013-08-05 10:56:33 -0700317 }
318
Ian Rogers13735952014-10-08 12:43:28 -0700319 uint8_t* GetParamAddress() const {
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800320 if (!kQuickSoftFloatAbi) {
Ian Rogers936b37f2014-02-14 00:52:24 -0800321 Primitive::Type type = GetParamPrimitiveType();
322 if (UNLIKELY((type == Primitive::kPrimDouble) || (type == Primitive::kPrimFloat))) {
Zheng Xu5667fdb2014-10-23 18:29:55 +0800323 if (type == Primitive::kPrimDouble && kQuickDoubleRegAlignedFloatBackFilled) {
324 if (fpr_double_index_ + 2 < kNumQuickFprArgs + 1) {
325 return fpr_args_ + (fpr_double_index_ * GetBytesPerFprSpillLocation(kRuntimeISA));
326 }
327 } else if (fpr_index_ + 1 < kNumQuickFprArgs + 1) {
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000328 return fpr_args_ + (fpr_index_ * GetBytesPerFprSpillLocation(kRuntimeISA));
Ian Rogers936b37f2014-02-14 00:52:24 -0800329 }
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +0700330 return stack_args_ + (stack_index_ * kBytesStackArgLocation);
Ian Rogers936b37f2014-02-14 00:52:24 -0800331 }
332 }
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800333 if (gpr_index_ < kNumQuickGprArgs) {
Ian Rogers936b37f2014-02-14 00:52:24 -0800334 return gpr_args_ + GprIndexToGprOffset(gpr_index_);
335 }
336 return stack_args_ + (stack_index_ * kBytesStackArgLocation);
Ian Rogers848871b2013-08-05 10:56:33 -0700337 }
338
339 bool IsSplitLongOrDouble() const {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700340 if ((GetBytesPerGprSpillLocation(kRuntimeISA) == 4) ||
341 (GetBytesPerFprSpillLocation(kRuntimeISA) == 4)) {
Ian Rogers936b37f2014-02-14 00:52:24 -0800342 return is_split_long_or_double_;
343 } else {
344 return false; // An optimization for when GPR and FPRs are 64bit.
345 }
Ian Rogers848871b2013-08-05 10:56:33 -0700346 }
347
Ian Rogers936b37f2014-02-14 00:52:24 -0800348 bool IsParamAReference() const {
Ian Rogers848871b2013-08-05 10:56:33 -0700349 return GetParamPrimitiveType() == Primitive::kPrimNot;
350 }
351
Ian Rogers936b37f2014-02-14 00:52:24 -0800352 bool IsParamALongOrDouble() const {
Ian Rogers848871b2013-08-05 10:56:33 -0700353 Primitive::Type type = GetParamPrimitiveType();
354 return type == Primitive::kPrimLong || type == Primitive::kPrimDouble;
355 }
356
357 uint64_t ReadSplitLongParam() const {
Nicolas Geoffray425f2392015-01-08 14:52:29 +0000358 // The splitted long is always available through the stack.
359 return *reinterpret_cast<uint64_t*>(stack_args_
360 + stack_index_ * kBytesStackArgLocation);
Ian Rogers848871b2013-08-05 10:56:33 -0700361 }
362
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800363 void IncGprIndex() {
364 gpr_index_++;
365 if (kGprFprLockstep) {
366 fpr_index_++;
367 }
368 }
369
370 void IncFprIndex() {
371 fpr_index_++;
372 if (kGprFprLockstep) {
373 gpr_index_++;
374 }
375 }
376
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700377 void VisitArguments() REQUIRES_SHARED(Locks::mutator_lock_) {
Zheng Xu5667fdb2014-10-23 18:29:55 +0800378 // (a) 'stack_args_' should point to the first method's argument
379 // (b) whatever the argument type it is, the 'stack_index_' should
380 // be moved forward along with every visiting.
Ian Rogers936b37f2014-02-14 00:52:24 -0800381 gpr_index_ = 0;
382 fpr_index_ = 0;
Zheng Xu5667fdb2014-10-23 18:29:55 +0800383 if (kQuickDoubleRegAlignedFloatBackFilled) {
384 fpr_double_index_ = 0;
385 }
Ian Rogers936b37f2014-02-14 00:52:24 -0800386 stack_index_ = 0;
387 if (!is_static_) { // Handle this.
388 cur_type_ = Primitive::kPrimNot;
389 is_split_long_or_double_ = false;
Ian Rogers848871b2013-08-05 10:56:33 -0700390 Visit();
Zheng Xu5667fdb2014-10-23 18:29:55 +0800391 stack_index_++;
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800392 if (kNumQuickGprArgs > 0) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800393 IncGprIndex();
Ian Rogers936b37f2014-02-14 00:52:24 -0800394 }
Ian Rogers848871b2013-08-05 10:56:33 -0700395 }
Ian Rogers936b37f2014-02-14 00:52:24 -0800396 for (uint32_t shorty_index = 1; shorty_index < shorty_len_; ++shorty_index) {
397 cur_type_ = Primitive::GetType(shorty_[shorty_index]);
398 switch (cur_type_) {
399 case Primitive::kPrimNot:
400 case Primitive::kPrimBoolean:
401 case Primitive::kPrimByte:
402 case Primitive::kPrimChar:
403 case Primitive::kPrimShort:
404 case Primitive::kPrimInt:
405 is_split_long_or_double_ = false;
406 Visit();
Zheng Xu5667fdb2014-10-23 18:29:55 +0800407 stack_index_++;
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800408 if (gpr_index_ < kNumQuickGprArgs) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800409 IncGprIndex();
Ian Rogers936b37f2014-02-14 00:52:24 -0800410 }
411 break;
412 case Primitive::kPrimFloat:
413 is_split_long_or_double_ = false;
414 Visit();
Zheng Xu5667fdb2014-10-23 18:29:55 +0800415 stack_index_++;
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800416 if (kQuickSoftFloatAbi) {
417 if (gpr_index_ < kNumQuickGprArgs) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800418 IncGprIndex();
Ian Rogers936b37f2014-02-14 00:52:24 -0800419 }
420 } else {
Zheng Xu5667fdb2014-10-23 18:29:55 +0800421 if (fpr_index_ + 1 < kNumQuickFprArgs + 1) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800422 IncFprIndex();
Zheng Xu5667fdb2014-10-23 18:29:55 +0800423 if (kQuickDoubleRegAlignedFloatBackFilled) {
424 // Double should not overlap with float.
425 // For example, if fpr_index_ = 3, fpr_double_index_ should be at least 4.
426 fpr_double_index_ = std::max(fpr_double_index_, RoundUp(fpr_index_, 2));
427 // Float should not overlap with double.
428 if (fpr_index_ % 2 == 0) {
429 fpr_index_ = std::max(fpr_double_index_, fpr_index_);
430 }
Goran Jakovljevicff734982015-08-24 12:58:55 +0000431 } else if (kQuickSkipOddFpRegisters) {
432 IncFprIndex();
Zheng Xu5667fdb2014-10-23 18:29:55 +0800433 }
Ian Rogers936b37f2014-02-14 00:52:24 -0800434 }
435 }
436 break;
437 case Primitive::kPrimDouble:
438 case Primitive::kPrimLong:
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800439 if (kQuickSoftFloatAbi || (cur_type_ == Primitive::kPrimLong)) {
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800440 if (cur_type_ == Primitive::kPrimLong &&
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800441 gpr_index_ == 0 &&
Alexey Frunze1b8464d2016-11-12 17:22:05 -0800442 kAlignPairRegister) {
Vladimir Marko41b605c2020-02-12 10:52:22 +0000443 // Currently, this is only for ARM, where we align long parameters with
444 // even-numbered registers by skipping R1 and using R2 instead.
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800445 IncGprIndex();
Nicolas Geoffray69c15d32015-01-13 11:42:13 +0000446 }
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000447 is_split_long_or_double_ = (GetBytesPerGprSpillLocation(kRuntimeISA) == 4) &&
Andreas Gampebf6b92a2014-03-05 16:11:04 -0800448 ((gpr_index_ + 1) == kNumQuickGprArgs);
Mark Mendell3e6a3bf2015-01-19 14:09:22 -0500449 if (!kSplitPairAcrossRegisterAndStack && is_split_long_or_double_) {
450 // We don't want to split this. Pass over this register.
451 gpr_index_++;
452 is_split_long_or_double_ = false;
453 }
Ian Rogers936b37f2014-02-14 00:52:24 -0800454 Visit();
Zheng Xu5667fdb2014-10-23 18:29:55 +0800455 if (kBytesStackArgLocation == 4) {
456 stack_index_+= 2;
457 } else {
458 CHECK_EQ(kBytesStackArgLocation, 8U);
459 stack_index_++;
Ian Rogers936b37f2014-02-14 00:52:24 -0800460 }
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +0700461 if (gpr_index_ < kNumQuickGprArgs) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800462 IncGprIndex();
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000463 if (GetBytesPerGprSpillLocation(kRuntimeISA) == 4) {
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +0700464 if (gpr_index_ < kNumQuickGprArgs) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800465 IncGprIndex();
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +0700466 }
467 }
468 }
Ian Rogers936b37f2014-02-14 00:52:24 -0800469 } else {
Nicolas Geoffray42fcd982014-04-22 11:03:52 +0000470 is_split_long_or_double_ = (GetBytesPerFprSpillLocation(kRuntimeISA) == 4) &&
Zheng Xu5667fdb2014-10-23 18:29:55 +0800471 ((fpr_index_ + 1) == kNumQuickFprArgs) && !kQuickDoubleRegAlignedFloatBackFilled;
Ian Rogers936b37f2014-02-14 00:52:24 -0800472 Visit();
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +0700473 if (kBytesStackArgLocation == 4) {
474 stack_index_+= 2;
Ian Rogers936b37f2014-02-14 00:52:24 -0800475 } else {
Vladimir Kostyukov1dd61ba2014-04-02 18:42:20 +0700476 CHECK_EQ(kBytesStackArgLocation, 8U);
477 stack_index_++;
Ian Rogers936b37f2014-02-14 00:52:24 -0800478 }
Zheng Xu5667fdb2014-10-23 18:29:55 +0800479 if (kQuickDoubleRegAlignedFloatBackFilled) {
480 if (fpr_double_index_ + 2 < kNumQuickFprArgs + 1) {
481 fpr_double_index_ += 2;
482 // Float should not overlap with double.
483 if (fpr_index_ % 2 == 0) {
484 fpr_index_ = std::max(fpr_double_index_, fpr_index_);
485 }
486 }
487 } else if (fpr_index_ + 1 < kNumQuickFprArgs + 1) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800488 IncFprIndex();
Zheng Xu5667fdb2014-10-23 18:29:55 +0800489 if (GetBytesPerFprSpillLocation(kRuntimeISA) == 4) {
490 if (fpr_index_ + 1 < kNumQuickFprArgs + 1) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -0800491 IncFprIndex();
Zheng Xu5667fdb2014-10-23 18:29:55 +0800492 }
493 }
494 }
Ian Rogers936b37f2014-02-14 00:52:24 -0800495 }
496 break;
497 default:
498 LOG(FATAL) << "Unexpected type: " << cur_type_ << " in " << shorty_;
499 }
Ian Rogers848871b2013-08-05 10:56:33 -0700500 }
501 }
502
Andreas Gampec200a4a2014-06-16 18:39:09 -0700503 protected:
Ian Rogers848871b2013-08-05 10:56:33 -0700504 const bool is_static_;
505 const char* const shorty_;
506 const uint32_t shorty_len_;
Andreas Gampec200a4a2014-06-16 18:39:09 -0700507
508 private:
Ian Rogers13735952014-10-08 12:43:28 -0700509 uint8_t* const gpr_args_; // Address of GPR arguments in callee save frame.
510 uint8_t* const fpr_args_; // Address of FPR arguments in callee save frame.
511 uint8_t* const stack_args_; // Address of stack arguments in caller's frame.
Ian Rogers936b37f2014-02-14 00:52:24 -0800512 uint32_t gpr_index_; // Index into spilled GPRs.
Zheng Xu5667fdb2014-10-23 18:29:55 +0800513 // Index into spilled FPRs.
514 // In case kQuickDoubleRegAlignedFloatBackFilled, it may index a hole while fpr_double_index_
515 // holds a higher register number.
516 uint32_t fpr_index_;
517 // Index into spilled FPRs for aligned double.
518 // Only used when kQuickDoubleRegAlignedFloatBackFilled. Next available double register indexed in
519 // terms of singles, may be behind fpr_index.
520 uint32_t fpr_double_index_;
Ian Rogers936b37f2014-02-14 00:52:24 -0800521 uint32_t stack_index_; // Index into arguments on the stack.
522 // The current type of argument during VisitArguments.
523 Primitive::Type cur_type_;
Ian Rogers848871b2013-08-05 10:56:33 -0700524 // Does a 64bit parameter straddle the register and stack arguments?
525 bool is_split_long_or_double_;
526};
527
Sebastien Hertza836bc92014-11-25 16:30:53 +0100528// Returns the 'this' object of a proxy method. This function is only used by StackVisitor. It
529// allows to use the QuickArgumentVisitor constants without moving all the code in its own module.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700530extern "C" mirror::Object* artQuickGetProxyThisObject(ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700531 REQUIRES_SHARED(Locks::mutator_lock_) {
Roland Levillainfa854e42018-02-07 13:09:55 +0000532 return QuickArgumentVisitor::GetProxyThisObjectReference(sp)->AsMirrorPtr();
533}
Sebastien Hertza836bc92014-11-25 16:30:53 +0100534
Ian Rogers848871b2013-08-05 10:56:33 -0700535// Visits arguments on the stack placing them into the shadow frame.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100536class BuildQuickShadowFrameVisitor final : public QuickArgumentVisitor {
Ian Rogers848871b2013-08-05 10:56:33 -0700537 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700538 BuildQuickShadowFrameVisitor(ArtMethod** sp, bool is_static, const char* shorty,
539 uint32_t shorty_len, ShadowFrame* sf, size_t first_arg_reg) :
Andreas Gampec200a4a2014-06-16 18:39:09 -0700540 QuickArgumentVisitor(sp, is_static, shorty, shorty_len), sf_(sf), cur_reg_(first_arg_reg) {}
Ian Rogers848871b2013-08-05 10:56:33 -0700541
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100542 void Visit() REQUIRES_SHARED(Locks::mutator_lock_) override;
Ian Rogers848871b2013-08-05 10:56:33 -0700543
544 private:
Ian Rogers936b37f2014-02-14 00:52:24 -0800545 ShadowFrame* const sf_;
546 uint32_t cur_reg_;
Ian Rogers848871b2013-08-05 10:56:33 -0700547
Dragos Sbirleabd136a22013-08-13 18:07:04 -0700548 DISALLOW_COPY_AND_ASSIGN(BuildQuickShadowFrameVisitor);
Ian Rogers848871b2013-08-05 10:56:33 -0700549};
550
Andreas Gampec200a4a2014-06-16 18:39:09 -0700551void BuildQuickShadowFrameVisitor::Visit() {
Ian Rogers9758f792014-03-13 09:02:55 -0700552 Primitive::Type type = GetParamPrimitiveType();
553 switch (type) {
554 case Primitive::kPrimLong: // Fall-through.
555 case Primitive::kPrimDouble:
556 if (IsSplitLongOrDouble()) {
557 sf_->SetVRegLong(cur_reg_, ReadSplitLongParam());
558 } else {
559 sf_->SetVRegLong(cur_reg_, *reinterpret_cast<jlong*>(GetParamAddress()));
560 }
561 ++cur_reg_;
562 break;
563 case Primitive::kPrimNot: {
564 StackReference<mirror::Object>* stack_ref =
565 reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress());
566 sf_->SetVRegReference(cur_reg_, stack_ref->AsMirrorPtr());
567 }
568 break;
569 case Primitive::kPrimBoolean: // Fall-through.
570 case Primitive::kPrimByte: // Fall-through.
571 case Primitive::kPrimChar: // Fall-through.
572 case Primitive::kPrimShort: // Fall-through.
573 case Primitive::kPrimInt: // Fall-through.
574 case Primitive::kPrimFloat:
575 sf_->SetVReg(cur_reg_, *reinterpret_cast<jint*>(GetParamAddress()));
576 break;
577 case Primitive::kPrimVoid:
578 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -0700579 UNREACHABLE();
Ian Rogers9758f792014-03-13 09:02:55 -0700580 }
581 ++cur_reg_;
582}
583
Mingyao Yang417528d2017-09-13 12:10:40 -0700584// Don't inline. See b/65159206.
585NO_INLINE
586static void HandleDeoptimization(JValue* result,
587 ArtMethod* method,
588 ShadowFrame* deopt_frame,
589 ManagedStack* fragment)
590 REQUIRES_SHARED(Locks::mutator_lock_) {
591 // Coming from partial-fragment deopt.
592 Thread* self = Thread::Current();
593 if (kIsDebugBuild) {
David Srbecky346fd962020-07-27 16:51:00 +0100594 // Consistency-check: are the methods as expected? We check that the last shadow frame
595 // (the bottom of the call-stack) corresponds to the called method.
Mingyao Yang417528d2017-09-13 12:10:40 -0700596 ShadowFrame* linked = deopt_frame;
597 while (linked->GetLink() != nullptr) {
598 linked = linked->GetLink();
599 }
600 CHECK_EQ(method, linked->GetMethod()) << method->PrettyMethod() << " "
601 << ArtMethod::PrettyMethod(linked->GetMethod());
602 }
603
604 if (VLOG_IS_ON(deopt)) {
605 // Print out the stack to verify that it was a partial-fragment deopt.
606 LOG(INFO) << "Continue-ing from deopt. Stack is:";
607 QuickExceptionHandler::DumpFramesWithType(self, true);
608 }
609
610 ObjPtr<mirror::Throwable> pending_exception;
611 bool from_code = false;
612 DeoptimizationMethodType method_type;
613 self->PopDeoptimizationContext(/* out */ result,
614 /* out */ &pending_exception,
615 /* out */ &from_code,
616 /* out */ &method_type);
617
618 // Push a transition back into managed code onto the linked list in thread.
619 self->PushManagedStackFragment(fragment);
620
621 // Ensure that the stack is still in order.
622 if (kIsDebugBuild) {
Orion Hodson6aaa49d2020-07-28 15:53:04 +0100623 class EntireStackVisitor : public StackVisitor {
Mingyao Yang417528d2017-09-13 12:10:40 -0700624 public:
Orion Hodson6aaa49d2020-07-28 15:53:04 +0100625 explicit EntireStackVisitor(Thread* self_in) REQUIRES_SHARED(Locks::mutator_lock_)
Mingyao Yang417528d2017-09-13 12:10:40 -0700626 : StackVisitor(self_in, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {}
627
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100628 bool VisitFrame() override REQUIRES_SHARED(Locks::mutator_lock_) {
Orion Hodson6aaa49d2020-07-28 15:53:04 +0100629 // Nothing to do here. In a debug build, ValidateFrame will do the work in the walking
Mingyao Yang417528d2017-09-13 12:10:40 -0700630 // logic. Just always say we want to continue.
631 return true;
632 }
633 };
Orion Hodson6aaa49d2020-07-28 15:53:04 +0100634 EntireStackVisitor esv(self);
635 esv.WalkStack();
Mingyao Yang417528d2017-09-13 12:10:40 -0700636 }
637
638 // Restore the exception that was pending before deoptimization then interpret the
639 // deoptimized frames.
640 if (pending_exception != nullptr) {
641 self->SetException(pending_exception);
642 }
643 interpreter::EnterInterpreterFromDeoptimize(self,
644 deopt_frame,
645 result,
646 from_code,
Nicolas Geoffray5f778892021-11-26 14:51:50 +0000647 method_type);
Mingyao Yang417528d2017-09-13 12:10:40 -0700648}
649
Mathieu Chartiere401d142015-04-22 13:56:20 -0700650extern "C" uint64_t artQuickToInterpreterBridge(ArtMethod* method, Thread* self, ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700651 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers848871b2013-08-05 10:56:33 -0700652 // Ensure we don't get thread suspension until the object arguments are safely in the shadow
653 // frame.
Ian Rogers1d8cdbc2014-09-22 22:51:09 -0700654 ScopedQuickEntrypointChecks sqec(self);
Ian Rogers848871b2013-08-05 10:56:33 -0700655
Alex Light9139e002015-10-09 15:59:48 -0700656 if (UNLIKELY(!method->IsInvokable())) {
657 method->ThrowInvocationTimeError();
Ian Rogers848871b2013-08-05 10:56:33 -0700658 return 0;
Andreas Gampe639bdd12015-06-03 11:22:45 -0700659 }
660
661 JValue tmp_value;
662 ShadowFrame* deopt_frame = self->PopStackedShadowFrame(
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700663 StackedShadowFrameType::kDeoptimizationShadowFrame, false);
Andreas Gampe639bdd12015-06-03 11:22:45 -0700664 ManagedStack fragment;
665
David Sehr709b0702016-10-13 09:12:37 -0700666 DCHECK(!method->IsNative()) << method->PrettyMethod();
Andreas Gampe639bdd12015-06-03 11:22:45 -0700667 uint32_t shorty_len = 0;
Andreas Gampe542451c2016-07-26 09:02:02 -0700668 ArtMethod* non_proxy_method = method->GetInterfaceMethodIfProxy(kRuntimePointerSize);
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800669 DCHECK(non_proxy_method->GetCodeItem() != nullptr) << method->PrettyMethod();
David Sehr0225f8e2018-01-31 08:52:24 +0000670 CodeItemDataAccessor accessor(non_proxy_method->DexInstructionData());
Andreas Gampe639bdd12015-06-03 11:22:45 -0700671 const char* shorty = non_proxy_method->GetShorty(&shorty_len);
672
673 JValue result;
Alex Light0aa7a5a2018-10-10 15:58:14 +0000674 bool force_frame_pop = false;
Andreas Gampe639bdd12015-06-03 11:22:45 -0700675
Mingyao Yang417528d2017-09-13 12:10:40 -0700676 if (UNLIKELY(deopt_frame != nullptr)) {
677 HandleDeoptimization(&result, method, deopt_frame, &fragment);
Ian Rogers848871b2013-08-05 10:56:33 -0700678 } else {
Andreas Gampec200a4a2014-06-16 18:39:09 -0700679 const char* old_cause = self->StartAssertNoThreadSuspension(
680 "Building interpreter shadow frame");
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800681 uint16_t num_regs = accessor.RegistersSize();
Andreas Gampec200a4a2014-06-16 18:39:09 -0700682 // No last shadow coming from quick.
Andreas Gampeb3025922015-09-01 14:45:00 -0700683 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700684 CREATE_SHADOW_FRAME(num_regs, /* link= */ nullptr, method, /* dex_pc= */ 0);
Andreas Gampeb3025922015-09-01 14:45:00 -0700685 ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get();
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800686 size_t first_arg_reg = accessor.RegistersSize() - accessor.InsSize();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700687 BuildQuickShadowFrameVisitor shadow_frame_builder(sp, method->IsStatic(), shorty, shorty_len,
Ian Rogers936b37f2014-02-14 00:52:24 -0800688 shadow_frame, first_arg_reg);
Ian Rogers848871b2013-08-05 10:56:33 -0700689 shadow_frame_builder.VisitArguments();
690 // Push a transition back into managed code onto the linked list in thread.
Ian Rogers848871b2013-08-05 10:56:33 -0700691 self->PushManagedStackFragment(&fragment);
692 self->PushShadowFrame(shadow_frame);
693 self->EndAssertNoThreadSuspension(old_cause);
694
Vladimir Marko5115a4d2019-10-17 14:56:47 +0100695 if (NeedsClinitCheckBeforeCall(method)) {
Vladimir Markobf121912019-06-04 13:49:05 +0100696 ObjPtr<mirror::Class> declaring_class = method->GetDeclaringClass();
Vladimir Marko8e110652019-07-30 10:14:41 +0100697 if (UNLIKELY(!declaring_class->IsVisiblyInitialized())) {
Vladimir Markobf121912019-06-04 13:49:05 +0100698 // Ensure static method's class is initialized.
699 StackHandleScope<1> hs(self);
Vladimir Marko8e110652019-07-30 10:14:41 +0100700 Handle<mirror::Class> h_class(hs.NewHandle(declaring_class));
Vladimir Markobf121912019-06-04 13:49:05 +0100701 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true, true)) {
Vladimir Marko8e110652019-07-30 10:14:41 +0100702 DCHECK(Thread::Current()->IsExceptionPending()) << method->PrettyMethod();
Vladimir Markobf121912019-06-04 13:49:05 +0100703 self->PopManagedStackFragment(fragment);
704 return 0;
705 }
Ian Rogers848871b2013-08-05 10:56:33 -0700706 }
707 }
Daniel Mihalyieb076692014-08-22 17:33:31 +0200708
Mathieu Chartier808c7a52017-12-15 11:19:33 -0800709 result = interpreter::EnterInterpreterFromEntryPoint(self, accessor, shadow_frame);
Alex Light0aa7a5a2018-10-10 15:58:14 +0000710 force_frame_pop = shadow_frame->GetForcePopFrame();
Ian Rogers848871b2013-08-05 10:56:33 -0700711 }
Andreas Gampe639bdd12015-06-03 11:22:45 -0700712
713 // Pop transition.
714 self->PopManagedStackFragment(fragment);
715
716 // Request a stack deoptimization if needed
717 ArtMethod* caller = QuickArgumentVisitor::GetCallingMethod(sp);
Mingyao Yangf711f2c2016-05-23 12:29:39 -0700718 uintptr_t caller_pc = QuickArgumentVisitor::GetCallingPc(sp);
Mingyao Yanga3549d22016-06-02 17:01:02 -0700719 // If caller_pc is the instrumentation exit stub, the stub will check to see if deoptimization
Alex Light3dacdd62019-03-12 15:45:47 +0000720 // should be done and it knows the real return pc. NB If the upcall is null we don't need to do
721 // anything. This can happen during shutdown or early startup.
722 if (UNLIKELY(
723 caller != nullptr &&
724 caller_pc != reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()) &&
725 (self->IsForceInterpreter() || Dbg::IsForcedInterpreterNeededForUpcall(self, caller)))) {
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000726 if (!Runtime::Current()->IsAsyncDeoptimizeable(caller_pc)) {
727 LOG(WARNING) << "Got a deoptimization request on un-deoptimizable method "
728 << caller->PrettyMethod();
729 } else {
Alex Light0aa7a5a2018-10-10 15:58:14 +0000730 VLOG(deopt) << "Forcing deoptimization on return from method " << method->PrettyMethod()
731 << " to " << caller->PrettyMethod()
732 << (force_frame_pop ? " for frame-pop" : "");
733 DCHECK(!force_frame_pop || result.GetJ() == 0) << "Force frame pop should have no result.";
734 if (force_frame_pop && self->GetException() != nullptr) {
735 LOG(WARNING) << "Suppressing exception for instruction-retry: "
736 << self->GetException()->Dump();
737 }
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000738 // Push the context of the deoptimization stack so we can restore the return value and the
739 // exception before executing the deoptimized frames.
740 self->PushDeoptimizationContext(
Mingyao Yang2ee17902017-08-30 11:37:08 -0700741 result,
742 shorty[0] == 'L' || shorty[0] == '[', /* class or array */
Alex Light0aa7a5a2018-10-10 15:58:14 +0000743 force_frame_pop ? nullptr : self->GetException(),
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700744 /* from_code= */ false,
Mingyao Yang2ee17902017-08-30 11:37:08 -0700745 DeoptimizationMethodType::kDefault);
Andreas Gampe639bdd12015-06-03 11:22:45 -0700746
Nicolas Geoffray433b79a2017-01-30 20:54:45 +0000747 // Set special exception to cause deoptimization.
748 self->SetException(Thread::GetDeoptimizationException());
749 }
Andreas Gampe639bdd12015-06-03 11:22:45 -0700750 }
751
752 // No need to restore the args since the method has already been run by the interpreter.
753 return result.GetJ();
Ian Rogers848871b2013-08-05 10:56:33 -0700754}
755
756// Visits arguments on the stack placing them into the args vector, Object* arguments are converted
757// to jobjects.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100758class BuildQuickArgumentVisitor final : public QuickArgumentVisitor {
Ian Rogers848871b2013-08-05 10:56:33 -0700759 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700760 BuildQuickArgumentVisitor(ArtMethod** sp, bool is_static, const char* shorty, uint32_t shorty_len,
Andreas Gampecf4035a2014-05-28 22:43:01 -0700761 ScopedObjectAccessUnchecked* soa, std::vector<jvalue>* args) :
Andreas Gampec200a4a2014-06-16 18:39:09 -0700762 QuickArgumentVisitor(sp, is_static, shorty, shorty_len), soa_(soa), args_(args) {}
Ian Rogers848871b2013-08-05 10:56:33 -0700763
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100764 void Visit() REQUIRES_SHARED(Locks::mutator_lock_) override;
Ian Rogers848871b2013-08-05 10:56:33 -0700765
766 private:
Ian Rogers9758f792014-03-13 09:02:55 -0700767 ScopedObjectAccessUnchecked* const soa_;
768 std::vector<jvalue>* const args_;
Ian Rogers9758f792014-03-13 09:02:55 -0700769
Ian Rogers848871b2013-08-05 10:56:33 -0700770 DISALLOW_COPY_AND_ASSIGN(BuildQuickArgumentVisitor);
771};
772
Ian Rogers9758f792014-03-13 09:02:55 -0700773void BuildQuickArgumentVisitor::Visit() {
774 jvalue val;
775 Primitive::Type type = GetParamPrimitiveType();
776 switch (type) {
777 case Primitive::kPrimNot: {
778 StackReference<mirror::Object>* stack_ref =
779 reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress());
780 val.l = soa_->AddLocalReference<jobject>(stack_ref->AsMirrorPtr());
Ian Rogers9758f792014-03-13 09:02:55 -0700781 break;
782 }
783 case Primitive::kPrimLong: // Fall-through.
784 case Primitive::kPrimDouble:
785 if (IsSplitLongOrDouble()) {
786 val.j = ReadSplitLongParam();
787 } else {
788 val.j = *reinterpret_cast<jlong*>(GetParamAddress());
789 }
790 break;
791 case Primitive::kPrimBoolean: // Fall-through.
792 case Primitive::kPrimByte: // Fall-through.
793 case Primitive::kPrimChar: // Fall-through.
794 case Primitive::kPrimShort: // Fall-through.
795 case Primitive::kPrimInt: // Fall-through.
796 case Primitive::kPrimFloat:
797 val.i = *reinterpret_cast<jint*>(GetParamAddress());
798 break;
799 case Primitive::kPrimVoid:
800 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -0700801 UNREACHABLE();
Ian Rogers9758f792014-03-13 09:02:55 -0700802 }
803 args_->push_back(val);
804}
805
Ian Rogers848871b2013-08-05 10:56:33 -0700806// Handler for invocation on proxy methods. On entry a frame will exist for the proxy object method
807// which is responsible for recording callee save registers. We explicitly place into jobjects the
808// incoming reference arguments (so they survive GC). We invoke the invocation handler, which is a
809// field within the proxy object, which will box the primitive arguments and deal with error cases.
Mathieu Chartiere401d142015-04-22 13:56:20 -0700810extern "C" uint64_t artQuickProxyInvokeHandler(
811 ArtMethod* proxy_method, mirror::Object* receiver, Thread* self, ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700812 REQUIRES_SHARED(Locks::mutator_lock_) {
David Sehr709b0702016-10-13 09:12:37 -0700813 DCHECK(proxy_method->IsProxyMethod()) << proxy_method->PrettyMethod();
814 DCHECK(receiver->GetClass()->IsProxyClass()) << proxy_method->PrettyMethod();
Ian Rogers848871b2013-08-05 10:56:33 -0700815 // Ensure we don't get thread suspension until the object arguments are safely in jobjects.
816 const char* old_cause =
817 self->StartAssertNoThreadSuspension("Adding to IRT proxy object arguments");
818 // Register the top of the managed stack, making stack crawlable.
David Sehr709b0702016-10-13 09:12:37 -0700819 DCHECK_EQ((*sp), proxy_method) << proxy_method->PrettyMethod();
Ian Rogers848871b2013-08-05 10:56:33 -0700820 self->VerifyStack();
821 // Start new JNI local reference state.
822 JNIEnvExt* env = self->GetJniEnv();
823 ScopedObjectAccessUnchecked soa(env);
824 ScopedJniEnvLocalRefState env_state(env);
825 // Create local ref. copies of proxy method and the receiver.
826 jobject rcvr_jobj = soa.AddLocalReference<jobject>(receiver);
827
828 // Placing arguments into args vector and remove the receiver.
Andreas Gampe542451c2016-07-26 09:02:02 -0700829 ArtMethod* non_proxy_method = proxy_method->GetInterfaceMethodIfProxy(kRuntimePointerSize);
David Sehr709b0702016-10-13 09:12:37 -0700830 CHECK(!non_proxy_method->IsStatic()) << proxy_method->PrettyMethod() << " "
831 << non_proxy_method->PrettyMethod();
Ian Rogers848871b2013-08-05 10:56:33 -0700832 std::vector<jvalue> args;
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700833 uint32_t shorty_len = 0;
Mathieu Chartiere401d142015-04-22 13:56:20 -0700834 const char* shorty = non_proxy_method->GetShorty(&shorty_len);
Roland Levillainad0777d2018-02-12 20:00:18 +0000835 BuildQuickArgumentVisitor local_ref_visitor(
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700836 sp, /* is_static= */ false, shorty, shorty_len, &soa, &args);
Brian Carlstromd3633d52013-08-20 21:06:26 -0700837
Ian Rogers848871b2013-08-05 10:56:33 -0700838 local_ref_visitor.VisitArguments();
David Sehr709b0702016-10-13 09:12:37 -0700839 DCHECK_GT(args.size(), 0U) << proxy_method->PrettyMethod();
Ian Rogers848871b2013-08-05 10:56:33 -0700840 args.erase(args.begin());
841
842 // Convert proxy method into expected interface method.
Andreas Gampe542451c2016-07-26 09:02:02 -0700843 ArtMethod* interface_method = proxy_method->FindOverriddenMethod(kRuntimePointerSize);
David Sehr709b0702016-10-13 09:12:37 -0700844 DCHECK(interface_method != nullptr) << proxy_method->PrettyMethod();
845 DCHECK(!interface_method->IsProxyMethod()) << interface_method->PrettyMethod();
Mathieu Chartierfc58af42015-04-16 18:00:39 -0700846 self->EndAssertNoThreadSuspension(old_cause);
Andreas Gampe542451c2016-07-26 09:02:02 -0700847 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
Andreas Gampee01e3642016-07-25 13:06:04 -0700848 DCHECK(!Runtime::Current()->IsActiveTransaction());
Andreas Gampeee29a072017-11-02 15:28:09 -0700849 ObjPtr<mirror::Method> interface_reflect_method =
Vladimir Markob6f4c792020-05-04 15:37:29 +0100850 mirror::Method::CreateFromArtMethod<kRuntimePointerSize>(soa.Self(), interface_method);
Andreas Gampeee29a072017-11-02 15:28:09 -0700851 if (interface_reflect_method == nullptr) {
852 soa.Self()->AssertPendingOOMException();
853 return 0;
854 }
855 jobject interface_method_jobj = soa.AddLocalReference<jobject>(interface_reflect_method);
Ian Rogers848871b2013-08-05 10:56:33 -0700856
857 // All naked Object*s should now be in jobjects, so its safe to go into the main invoke code
Alex Lightc9167362018-06-11 16:46:43 -0700858 // that performs allocations or instrumentation events.
859 instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation();
860 if (instr->HasMethodEntryListeners()) {
Mythri Alle9cc65df2021-09-21 15:09:58 +0000861 instr->MethodEnterEvent(soa.Self(), proxy_method);
Alex Lightc9167362018-06-11 16:46:43 -0700862 if (soa.Self()->IsExceptionPending()) {
863 instr->MethodUnwindEvent(self,
Vladimir Marko19711d42019-04-12 14:05:34 +0100864 soa.Decode<mirror::Object>(rcvr_jobj),
Alex Lightc9167362018-06-11 16:46:43 -0700865 proxy_method,
866 0);
867 return 0;
868 }
869 }
Mathieu Chartierbfd9a432014-05-21 17:43:44 -0700870 JValue result = InvokeProxyInvocationHandler(soa, shorty, rcvr_jobj, interface_method_jobj, args);
Alex Lightc9167362018-06-11 16:46:43 -0700871 if (soa.Self()->IsExceptionPending()) {
872 if (instr->HasMethodUnwindListeners()) {
873 instr->MethodUnwindEvent(self,
Vladimir Marko19711d42019-04-12 14:05:34 +0100874 soa.Decode<mirror::Object>(rcvr_jobj),
Alex Lightc9167362018-06-11 16:46:43 -0700875 proxy_method,
876 0);
877 }
878 } else if (instr->HasMethodExitListeners()) {
879 instr->MethodExitEvent(self,
Alex Lightc9167362018-06-11 16:46:43 -0700880 proxy_method,
Alex Lightb7c640d2019-03-20 15:52:13 -0700881 {},
Alex Lightc9167362018-06-11 16:46:43 -0700882 result);
883 }
Ian Rogers848871b2013-08-05 10:56:33 -0700884 return result.GetJ();
885}
886
Roland Levillainad0777d2018-02-12 20:00:18 +0000887// Visitor returning a reference argument at a given position in a Quick stack frame.
888// NOTE: Only used for testing purposes.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100889class GetQuickReferenceArgumentAtVisitor final : public QuickArgumentVisitor {
Roland Levillainad0777d2018-02-12 20:00:18 +0000890 public:
891 GetQuickReferenceArgumentAtVisitor(ArtMethod** sp,
892 const char* shorty,
893 uint32_t shorty_len,
894 size_t arg_pos)
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700895 : QuickArgumentVisitor(sp, /* is_static= */ false, shorty, shorty_len),
Roland Levillainad0777d2018-02-12 20:00:18 +0000896 cur_pos_(0u),
897 arg_pos_(arg_pos),
898 ref_arg_(nullptr) {
899 CHECK_LT(arg_pos, shorty_len) << "Argument position greater than the number arguments";
900 }
901
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100902 void Visit() REQUIRES_SHARED(Locks::mutator_lock_) override {
Roland Levillainad0777d2018-02-12 20:00:18 +0000903 if (cur_pos_ == arg_pos_) {
904 Primitive::Type type = GetParamPrimitiveType();
905 CHECK_EQ(type, Primitive::kPrimNot) << "Argument at searched position is not a reference";
906 ref_arg_ = reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress());
907 }
908 ++cur_pos_;
909 }
910
911 StackReference<mirror::Object>* GetReferenceArgument() {
912 return ref_arg_;
913 }
914
915 private:
916 // The position of the currently visited argument.
917 size_t cur_pos_;
918 // The position of the searched argument.
919 const size_t arg_pos_;
920 // The reference argument, if found.
921 StackReference<mirror::Object>* ref_arg_;
922
923 DISALLOW_COPY_AND_ASSIGN(GetQuickReferenceArgumentAtVisitor);
924};
925
926// Returning reference argument at position `arg_pos` in Quick stack frame at address `sp`.
927// NOTE: Only used for testing purposes.
928extern "C" StackReference<mirror::Object>* artQuickGetProxyReferenceArgumentAt(size_t arg_pos,
929 ArtMethod** sp)
930 REQUIRES_SHARED(Locks::mutator_lock_) {
931 ArtMethod* proxy_method = *sp;
932 ArtMethod* non_proxy_method = proxy_method->GetInterfaceMethodIfProxy(kRuntimePointerSize);
933 CHECK(!non_proxy_method->IsStatic())
934 << proxy_method->PrettyMethod() << " " << non_proxy_method->PrettyMethod();
935 uint32_t shorty_len = 0;
936 const char* shorty = non_proxy_method->GetShorty(&shorty_len);
937 GetQuickReferenceArgumentAtVisitor ref_arg_visitor(sp, shorty, shorty_len, arg_pos);
938 ref_arg_visitor.VisitArguments();
939 StackReference<mirror::Object>* ref_arg = ref_arg_visitor.GetReferenceArgument();
940 return ref_arg;
941}
942
943// Visitor returning all the reference arguments in a Quick stack frame.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100944class GetQuickReferenceArgumentsVisitor final : public QuickArgumentVisitor {
Roland Levillainad0777d2018-02-12 20:00:18 +0000945 public:
946 GetQuickReferenceArgumentsVisitor(ArtMethod** sp,
947 bool is_static,
948 const char* shorty,
949 uint32_t shorty_len)
950 : QuickArgumentVisitor(sp, is_static, shorty, shorty_len) {}
951
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100952 void Visit() REQUIRES_SHARED(Locks::mutator_lock_) override {
Roland Levillainad0777d2018-02-12 20:00:18 +0000953 Primitive::Type type = GetParamPrimitiveType();
954 if (type == Primitive::kPrimNot) {
955 StackReference<mirror::Object>* ref_arg =
956 reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress());
957 ref_args_.push_back(ref_arg);
958 }
959 }
960
961 std::vector<StackReference<mirror::Object>*> GetReferenceArguments() {
962 return ref_args_;
963 }
964
965 private:
966 // The reference arguments.
967 std::vector<StackReference<mirror::Object>*> ref_args_;
968
969 DISALLOW_COPY_AND_ASSIGN(GetQuickReferenceArgumentsVisitor);
970};
971
972// Returning all reference arguments in Quick stack frame at address `sp`.
973std::vector<StackReference<mirror::Object>*> GetProxyReferenceArguments(ArtMethod** sp)
974 REQUIRES_SHARED(Locks::mutator_lock_) {
975 ArtMethod* proxy_method = *sp;
976 ArtMethod* non_proxy_method = proxy_method->GetInterfaceMethodIfProxy(kRuntimePointerSize);
977 CHECK(!non_proxy_method->IsStatic())
978 << proxy_method->PrettyMethod() << " " << non_proxy_method->PrettyMethod();
979 uint32_t shorty_len = 0;
980 const char* shorty = non_proxy_method->GetShorty(&shorty_len);
Andreas Gampe98ea9d92018-10-19 14:06:15 -0700981 GetQuickReferenceArgumentsVisitor ref_args_visitor(sp, /*is_static=*/ false, shorty, shorty_len);
Roland Levillainad0777d2018-02-12 20:00:18 +0000982 ref_args_visitor.VisitArguments();
983 std::vector<StackReference<mirror::Object>*> ref_args = ref_args_visitor.GetReferenceArguments();
984 return ref_args;
985}
986
Ian Rogers848871b2013-08-05 10:56:33 -0700987// Read object references held in arguments from quick frames and place in a JNI local references,
988// so they don't get garbage collected.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100989class RememberForGcArgumentVisitor final : public QuickArgumentVisitor {
Ian Rogers848871b2013-08-05 10:56:33 -0700990 public:
Mathieu Chartiere401d142015-04-22 13:56:20 -0700991 RememberForGcArgumentVisitor(ArtMethod** sp, bool is_static, const char* shorty,
992 uint32_t shorty_len, ScopedObjectAccessUnchecked* soa) :
Andreas Gampec200a4a2014-06-16 18:39:09 -0700993 QuickArgumentVisitor(sp, is_static, shorty, shorty_len), soa_(soa) {}
Ian Rogers848871b2013-08-05 10:56:33 -0700994
Roland Levillainbbc6e7e2018-08-24 16:58:47 +0100995 void Visit() REQUIRES_SHARED(Locks::mutator_lock_) override;
Mathieu Chartier07d447b2013-09-26 11:57:43 -0700996
Andreas Gampebdf7f1c2016-08-30 16:38:47 -0700997 void FixupReferences() REQUIRES_SHARED(Locks::mutator_lock_);
Ian Rogers848871b2013-08-05 10:56:33 -0700998
999 private:
Ian Rogers9758f792014-03-13 09:02:55 -07001000 ScopedObjectAccessUnchecked* const soa_;
Mathieu Chartier5275bcb2014-02-20 17:16:42 -08001001 // References which we must update when exiting in case the GC moved the objects.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001002 std::vector<std::pair<jobject, StackReference<mirror::Object>*> > references_;
1003
Mathieu Chartier590fee92013-09-13 13:46:47 -07001004 DISALLOW_COPY_AND_ASSIGN(RememberForGcArgumentVisitor);
Ian Rogers848871b2013-08-05 10:56:33 -07001005};
1006
Ian Rogers9758f792014-03-13 09:02:55 -07001007void RememberForGcArgumentVisitor::Visit() {
1008 if (IsParamAReference()) {
1009 StackReference<mirror::Object>* stack_ref =
1010 reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress());
1011 jobject reference =
1012 soa_->AddLocalReference<jobject>(stack_ref->AsMirrorPtr());
1013 references_.push_back(std::make_pair(reference, stack_ref));
1014 }
1015}
1016
1017void RememberForGcArgumentVisitor::FixupReferences() {
1018 // Fixup any references which may have changed.
1019 for (const auto& pair : references_) {
Mathieu Chartier1a5337f2016-10-13 13:48:23 -07001020 pair.second->Assign(soa_->Decode<mirror::Object>(pair.first));
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07001021 soa_->Env()->DeleteLocalRef(pair.first);
Ian Rogers9758f792014-03-13 09:02:55 -07001022 }
1023}
1024
Alex Lightb7edcda2017-04-27 13:20:31 -07001025extern "C" const void* artInstrumentationMethodEntryFromCode(ArtMethod* method,
1026 mirror::Object* this_object,
1027 Thread* self,
1028 ArtMethod** sp)
1029 REQUIRES_SHARED(Locks::mutator_lock_) {
1030 const void* result;
1031 // Instrumentation changes the stack. Thus, when exiting, the stack cannot be verified, so skip
1032 // that part.
1033 ScopedQuickEntrypointChecks sqec(self, kIsDebugBuild, false);
1034 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
Alex Light6cae5ea2018-06-07 17:07:02 -07001035 DCHECK(!method->IsProxyMethod())
1036 << "Proxy method " << method->PrettyMethod()
1037 << " (declaring class: " << method->GetDeclaringClass()->PrettyClass() << ")"
1038 << " should not hit instrumentation entrypoint.";
Nicolas Geoffrayc25a9f92021-12-13 17:22:43 +00001039 DCHECK(!instrumentation->IsDeoptimized(method));
1040 // This will get the entry point either from the oat file, the JIT or the appropriate bridge
1041 // method if none of those can be found.
1042 result = instrumentation->GetCodeForInvoke(method);
1043 jit::Jit* jit = Runtime::Current()->GetJit();
1044 DCHECK_NE(result, GetQuickInstrumentationEntryPoint()) << method->PrettyMethod();
1045 DCHECK(jit == nullptr ||
1046 // Native methods come through here in Interpreter entrypoints. We might not have
1047 // disabled jit-gc but that is fine since we won't return jit-code for native methods.
1048 method->IsNative() ||
1049 !jit->GetCodeCache()->GetGarbageCollectCode());
1050 DCHECK(!method->IsNative() ||
1051 jit == nullptr ||
1052 !jit->GetCodeCache()->ContainsPc(result))
1053 << method->PrettyMethod() << " code will jump to possibly cleaned up jit code!";
Alex Lightb7edcda2017-04-27 13:20:31 -07001054
1055 bool interpreter_entry = (result == GetQuickToInterpreterBridge());
1056 bool is_static = method->IsStatic();
1057 uint32_t shorty_len;
1058 const char* shorty =
1059 method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(&shorty_len);
1060
1061 ScopedObjectAccessUnchecked soa(self);
1062 RememberForGcArgumentVisitor visitor(sp, is_static, shorty, shorty_len, &soa);
1063 visitor.VisitArguments();
1064
Nicolas Geoffrayc71fe162021-12-09 14:02:48 +00001065 StackHandleScope<2> hs(self);
1066 Handle<mirror::Object> h_object(hs.NewHandle(is_static ? nullptr : this_object));
1067 Handle<mirror::Class> h_class(hs.NewHandle(method->GetDeclaringClass()));
1068
1069 // Ensure that the called method's class is initialized.
1070 if (NeedsClinitCheckBeforeCall(method) && !h_class->IsVisiblyInitialized()) {
1071 if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true, true)) {
1072 visitor.FixupReferences();
1073 DCHECK(self->IsExceptionPending());
1074 return nullptr;
1075 }
1076 }
1077
Alex Lightb7edcda2017-04-27 13:20:31 -07001078 instrumentation->PushInstrumentationStackFrame(self,
Nicolas Geoffrayc71fe162021-12-09 14:02:48 +00001079 is_static ? nullptr : h_object.Get(),
Alex Lightb7edcda2017-04-27 13:20:31 -07001080 method,
Nicolas Geoffraye91e7952020-01-23 10:15:56 +00001081 reinterpret_cast<uintptr_t>(
1082 QuickArgumentVisitor::GetCallingPcAddr(sp)),
Alex Lightb7edcda2017-04-27 13:20:31 -07001083 QuickArgumentVisitor::GetCallingPc(sp),
1084 interpreter_entry);
1085
1086 visitor.FixupReferences();
1087 if (UNLIKELY(self->IsExceptionPending())) {
1088 return nullptr;
1089 }
1090 CHECK(result != nullptr) << method->PrettyMethod();
1091 return result;
1092}
1093
1094extern "C" TwoWordReturn artInstrumentationMethodExitFromCode(Thread* self,
1095 ArtMethod** sp,
1096 uint64_t* gpr_result,
1097 uint64_t* fpr_result)
1098 REQUIRES_SHARED(Locks::mutator_lock_) {
1099 DCHECK_EQ(reinterpret_cast<uintptr_t>(self), reinterpret_cast<uintptr_t>(Thread::Current()));
1100 CHECK(gpr_result != nullptr);
1101 CHECK(fpr_result != nullptr);
1102 // Instrumentation exit stub must not be entered with a pending exception.
1103 CHECK(!self->IsExceptionPending()) << "Enter instrumentation exit stub with pending exception "
1104 << self->GetException()->Dump();
David Srbecky346fd962020-07-27 16:51:00 +01001105 // Compute address of return PC and check that it currently holds 0.
Vladimir Markod3083dd2018-05-17 08:43:47 +01001106 constexpr size_t return_pc_offset =
1107 RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveEverything);
Nicolas Geoffraye91e7952020-01-23 10:15:56 +00001108 uintptr_t* return_pc_addr = reinterpret_cast<uintptr_t*>(reinterpret_cast<uint8_t*>(sp) +
1109 return_pc_offset);
1110 CHECK_EQ(*return_pc_addr, 0U);
Alex Lightb7edcda2017-04-27 13:20:31 -07001111
1112 // Pop the frame filling in the return pc. The low half of the return value is 0 when
1113 // deoptimization shouldn't be performed with the high-half having the return address. When
1114 // deoptimization should be performed the low half is zero and the high-half the address of the
1115 // deoptimization entry point.
1116 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
1117 TwoWordReturn return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame(
Nicolas Geoffraye91e7952020-01-23 10:15:56 +00001118 self, return_pc_addr, gpr_result, fpr_result);
Vladimir Markofac21782018-03-13 17:01:09 +00001119 if (self->IsExceptionPending() || self->ObserveAsyncException()) {
Alex Lightb7edcda2017-04-27 13:20:31 -07001120 return GetTwoWordFailureValue();
1121 }
1122 return return_or_deoptimize_pc;
1123}
1124
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001125static std::string DumpInstruction(ArtMethod* method, uint32_t dex_pc)
1126 REQUIRES_SHARED(Locks::mutator_lock_) {
1127 if (dex_pc == static_cast<uint32_t>(-1)) {
1128 CHECK(method == jni::DecodeArtMethod(WellKnownClasses::java_lang_String_charAt));
1129 return "<native>";
1130 } else {
1131 CodeItemInstructionAccessor accessor = method->DexInstructions();
1132 CHECK_LT(dex_pc, accessor.InsnsSizeInCodeUnits());
1133 return accessor.InstructionAt(dex_pc).DumpString(method->GetDexFile());
1134 }
1135}
1136
Vladimir Marko606adb32018-04-05 14:49:24 +01001137static void DumpB74410240ClassData(ObjPtr<mirror::Class> klass)
1138 REQUIRES_SHARED(Locks::mutator_lock_) {
1139 std::string storage;
1140 const char* descriptor = klass->GetDescriptor(&storage);
1141 LOG(FATAL_WITHOUT_ABORT) << " " << DescribeLoaders(klass->GetClassLoader(), descriptor);
1142 const OatDexFile* oat_dex_file = klass->GetDexFile().GetOatDexFile();
1143 if (oat_dex_file != nullptr) {
1144 const OatFile* oat_file = oat_dex_file->GetOatFile();
1145 const char* dex2oat_cmdline =
1146 oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kDex2OatCmdLineKey);
1147 LOG(FATAL_WITHOUT_ABORT) << " OatFile: " << oat_file->GetLocation()
1148 << "; " << (dex2oat_cmdline != nullptr ? dex2oat_cmdline : "<not recorded>");
1149 }
1150}
1151
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001152static void DumpB74410240DebugData(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) {
1153 // Mimick the search for the caller and dump some data while doing so.
Vladimir Marko606adb32018-04-05 14:49:24 +01001154 LOG(FATAL_WITHOUT_ABORT) << "Dumping debugging data, please attach a bugreport to b/74410240.";
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001155
1156 constexpr CalleeSaveType type = CalleeSaveType::kSaveRefsAndArgs;
1157 CHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(type));
1158
Vladimir Markod3083dd2018-05-17 08:43:47 +01001159 constexpr size_t callee_frame_size = RuntimeCalleeSaveFrame::GetFrameSize(type);
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001160 auto** caller_sp = reinterpret_cast<ArtMethod**>(
1161 reinterpret_cast<uintptr_t>(sp) + callee_frame_size);
Vladimir Markod3083dd2018-05-17 08:43:47 +01001162 constexpr size_t callee_return_pc_offset = RuntimeCalleeSaveFrame::GetReturnPcOffset(type);
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001163 uintptr_t caller_pc = *reinterpret_cast<uintptr_t*>(
1164 (reinterpret_cast<uint8_t*>(sp) + callee_return_pc_offset));
1165 ArtMethod* outer_method = *caller_sp;
1166
1167 if (UNLIKELY(caller_pc == reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()))) {
1168 LOG(FATAL_WITHOUT_ABORT) << "Method: " << outer_method->PrettyMethod()
1169 << " native pc: " << caller_pc << " Instrumented!";
1170 return;
1171 }
1172
1173 const OatQuickMethodHeader* current_code = outer_method->GetOatQuickMethodHeader(caller_pc);
1174 CHECK(current_code != nullptr);
1175 CHECK(current_code->IsOptimized());
1176 uintptr_t native_pc_offset = current_code->NativeQuickPcOffset(caller_pc);
David Srbecky052f8ca2018-04-26 15:42:54 +01001177 CodeInfo code_info(current_code);
David Srbecky052f8ca2018-04-26 15:42:54 +01001178 StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset);
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001179 CHECK(stack_map.IsValid());
David Srbecky052f8ca2018-04-26 15:42:54 +01001180 uint32_t dex_pc = stack_map.GetDexPc();
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001181
1182 // Log the outer method and its associated dex file and class table pointer which can be used
1183 // to find out if the inlined methods were defined by other dex file(s) or class loader(s).
1184 ClassLinker* class_linker = Runtime::Current()->GetClassLinker();
1185 LOG(FATAL_WITHOUT_ABORT) << "Outer: " << outer_method->PrettyMethod()
1186 << " native pc: " << caller_pc
1187 << " dex pc: " << dex_pc
1188 << " dex file: " << outer_method->GetDexFile()->GetLocation()
1189 << " class table: " << class_linker->ClassTableForClassLoader(outer_method->GetClassLoader());
Vladimir Marko606adb32018-04-05 14:49:24 +01001190 DumpB74410240ClassData(outer_method->GetDeclaringClass());
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001191 LOG(FATAL_WITHOUT_ABORT) << " instruction: " << DumpInstruction(outer_method, dex_pc);
1192
1193 ArtMethod* caller = outer_method;
David Srbecky93bd3612018-07-02 19:30:18 +01001194 BitTableRange<InlineInfo> inline_infos = code_info.GetInlineInfosOf(stack_map);
1195 for (InlineInfo inline_info : inline_infos) {
1196 const char* tag = "";
1197 dex_pc = inline_info.GetDexPc();
1198 if (inline_info.EncodesArtMethod()) {
1199 tag = "encoded ";
1200 caller = inline_info.GetArtMethod();
1201 } else {
David Srbecky8cd54542018-07-15 23:58:44 +01001202 uint32_t method_index = code_info.GetMethodIndexOf(inline_info);
David Srbecky93bd3612018-07-02 19:30:18 +01001203 if (dex_pc == static_cast<uint32_t>(-1)) {
1204 tag = "special ";
1205 CHECK(inline_info.Equals(inline_infos.back()));
1206 caller = jni::DecodeArtMethod(WellKnownClasses::java_lang_String_charAt);
1207 CHECK_EQ(caller->GetDexMethodIndex(), method_index);
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001208 } else {
David Srbecky93bd3612018-07-02 19:30:18 +01001209 ObjPtr<mirror::DexCache> dex_cache = caller->GetDexCache();
1210 ObjPtr<mirror::ClassLoader> class_loader = caller->GetClassLoader();
1211 caller = class_linker->LookupResolvedMethod(method_index, dex_cache, class_loader);
1212 CHECK(caller != nullptr);
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001213 }
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001214 }
David Srbecky93bd3612018-07-02 19:30:18 +01001215 LOG(FATAL_WITHOUT_ABORT) << "InlineInfo #" << inline_info.Row()
1216 << ": " << tag << caller->PrettyMethod()
1217 << " dex pc: " << dex_pc
1218 << " dex file: " << caller->GetDexFile()->GetLocation()
1219 << " class table: "
1220 << class_linker->ClassTableForClassLoader(caller->GetClassLoader());
1221 DumpB74410240ClassData(caller->GetDeclaringClass());
1222 LOG(FATAL_WITHOUT_ABORT) << " instruction: " << DumpInstruction(caller, dex_pc);
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001223 }
1224}
1225
Ian Rogers848871b2013-08-05 10:56:33 -07001226// Lazily resolve a method for quick. Called by stub code.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001227extern "C" const void* artQuickResolutionTrampoline(
1228 ArtMethod* called, mirror::Object* receiver, Thread* self, ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001229 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe3b45ef22015-05-26 21:34:09 -07001230 // The resolution trampoline stashes the resolved method into the callee-save frame to transport
1231 // it. Thus, when exiting, the stack cannot be verified (as the resolved method most likely
1232 // does not have the same stack layout as the callee-save method).
1233 ScopedQuickEntrypointChecks sqec(self, kIsDebugBuild, false);
Ian Rogers848871b2013-08-05 10:56:33 -07001234 // Start new JNI local reference state
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001235 JNIEnvExt* env = self->GetJniEnv();
Ian Rogers848871b2013-08-05 10:56:33 -07001236 ScopedObjectAccessUnchecked soa(env);
1237 ScopedJniEnvLocalRefState env_state(env);
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001238 const char* old_cause = self->StartAssertNoThreadSuspension("Quick method resolution set up");
Ian Rogers848871b2013-08-05 10:56:33 -07001239
1240 // Compute details about the called method (avoid GCs)
1241 ClassLinker* linker = Runtime::Current()->GetClassLinker();
Ian Rogers848871b2013-08-05 10:56:33 -07001242 InvokeType invoke_type;
Ian Rogerse0a02da2014-12-02 14:10:53 -08001243 MethodReference called_method(nullptr, 0);
1244 const bool called_method_known_on_entry = !called->IsRuntimeMethod();
Mathieu Chartiere401d142015-04-22 13:56:20 -07001245 ArtMethod* caller = nullptr;
Ian Rogerse0a02da2014-12-02 14:10:53 -08001246 if (!called_method_known_on_entry) {
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +01001247 caller = QuickArgumentVisitor::GetCallingMethod(sp);
Ian Rogerse0a02da2014-12-02 14:10:53 -08001248 called_method.dex_file = caller->GetDexFile();
Mathieu Chartierd776ff02017-01-17 09:32:18 -08001249
David Srbecky2c762572018-06-27 10:09:11 +01001250 {
Mathieu Chartierd776ff02017-01-17 09:32:18 -08001251 uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp);
David Sehr0225f8e2018-01-31 08:52:24 +00001252 CodeItemInstructionAccessor accessor(caller->DexInstructions());
Mathieu Chartier808c7a52017-12-15 11:19:33 -08001253 CHECK_LT(dex_pc, accessor.InsnsSizeInCodeUnits());
1254 const Instruction& instr = accessor.InstructionAt(dex_pc);
Vladimir Markod7559b72017-09-28 13:50:37 +01001255 Instruction::Code instr_code = instr.Opcode();
Mathieu Chartierd776ff02017-01-17 09:32:18 -08001256 bool is_range;
1257 switch (instr_code) {
1258 case Instruction::INVOKE_DIRECT:
1259 invoke_type = kDirect;
1260 is_range = false;
1261 break;
1262 case Instruction::INVOKE_DIRECT_RANGE:
1263 invoke_type = kDirect;
1264 is_range = true;
1265 break;
1266 case Instruction::INVOKE_STATIC:
1267 invoke_type = kStatic;
1268 is_range = false;
1269 break;
1270 case Instruction::INVOKE_STATIC_RANGE:
1271 invoke_type = kStatic;
1272 is_range = true;
1273 break;
1274 case Instruction::INVOKE_SUPER:
1275 invoke_type = kSuper;
1276 is_range = false;
1277 break;
1278 case Instruction::INVOKE_SUPER_RANGE:
1279 invoke_type = kSuper;
1280 is_range = true;
1281 break;
1282 case Instruction::INVOKE_VIRTUAL:
1283 invoke_type = kVirtual;
1284 is_range = false;
1285 break;
1286 case Instruction::INVOKE_VIRTUAL_RANGE:
1287 invoke_type = kVirtual;
1288 is_range = true;
1289 break;
1290 case Instruction::INVOKE_INTERFACE:
1291 invoke_type = kInterface;
1292 is_range = false;
1293 break;
1294 case Instruction::INVOKE_INTERFACE_RANGE:
1295 invoke_type = kInterface;
1296 is_range = true;
1297 break;
1298 default:
Vladimir Marko5b4b9a02018-03-16 09:42:09 +00001299 DumpB74410240DebugData(sp);
Vladimir Markod7559b72017-09-28 13:50:37 +01001300 LOG(FATAL) << "Unexpected call into trampoline: " << instr.DumpString(nullptr);
Mathieu Chartierd776ff02017-01-17 09:32:18 -08001301 UNREACHABLE();
1302 }
Vladimir Markod7559b72017-09-28 13:50:37 +01001303 called_method.index = (is_range) ? instr.VRegB_3rc() : instr.VRegB_35c();
David Srbecky2c762572018-06-27 10:09:11 +01001304 VLOG(dex) << "Accessed dex file for invoke " << invoke_type << " "
1305 << called_method.index;
Ian Rogers848871b2013-08-05 10:56:33 -07001306 }
Ian Rogers848871b2013-08-05 10:56:33 -07001307 } else {
1308 invoke_type = kStatic;
Ian Rogerse0a02da2014-12-02 14:10:53 -08001309 called_method.dex_file = called->GetDexFile();
Mathieu Chartierfc8b4222017-09-17 13:44:24 -07001310 called_method.index = called->GetDexMethodIndex();
Ian Rogers848871b2013-08-05 10:56:33 -07001311 }
1312 uint32_t shorty_len;
1313 const char* shorty =
Mathieu Chartierfc8b4222017-09-17 13:44:24 -07001314 called_method.dex_file->GetMethodShorty(called_method.GetMethodId(), &shorty_len);
Mathieu Chartier590fee92013-09-13 13:46:47 -07001315 RememberForGcArgumentVisitor visitor(sp, invoke_type == kStatic, shorty, shorty_len, &soa);
Ian Rogers848871b2013-08-05 10:56:33 -07001316 visitor.VisitArguments();
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001317 self->EndAssertNoThreadSuspension(old_cause);
Ian Rogerse0a02da2014-12-02 14:10:53 -08001318 const bool virtual_or_interface = invoke_type == kVirtual || invoke_type == kInterface;
Ian Rogers848871b2013-08-05 10:56:33 -07001319 // Resolve method filling in dex cache.
Ian Rogerse0a02da2014-12-02 14:10:53 -08001320 if (!called_method_known_on_entry) {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07001321 StackHandleScope<1> hs(self);
Orion Hodson6aaa49d2020-07-28 15:53:04 +01001322 mirror::Object* fake_receiver = nullptr;
Mathieu Chartier0cd81352014-05-22 16:48:55 -07001323 HandleWrapper<mirror::Object> h_receiver(
Orion Hodson6aaa49d2020-07-28 15:53:04 +01001324 hs.NewHandleWrapper(virtual_or_interface ? &receiver : &fake_receiver));
Ian Rogerse0a02da2014-12-02 14:10:53 -08001325 DCHECK_EQ(caller->GetDexFile(), called_method.dex_file);
Vladimir Markoba118822017-06-12 15:41:56 +01001326 called = linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
Mathieu Chartierfc8b4222017-09-17 13:44:24 -07001327 self, called_method.index, caller, invoke_type);
Ian Rogers848871b2013-08-05 10:56:33 -07001328 }
Ian Rogerse0a02da2014-12-02 14:10:53 -08001329 const void* code = nullptr;
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001330 if (LIKELY(!self->IsExceptionPending())) {
Ian Rogers848871b2013-08-05 10:56:33 -07001331 // Incompatible class change should have been handled in resolve method.
Brian Carlstrom2ec65202014-03-03 15:16:37 -08001332 CHECK(!called->CheckIncompatibleClassChange(invoke_type))
David Sehr709b0702016-10-13 09:12:37 -07001333 << called->PrettyMethod() << " " << invoke_type;
Nicolas Geoffraye5234232015-12-02 09:06:11 +00001334 if (virtual_or_interface || invoke_type == kSuper) {
1335 // Refine called method based on receiver for kVirtual/kInterface, and
1336 // caller for kSuper.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001337 ArtMethod* orig_called = called;
Mathieu Chartier55871bf2014-02-27 10:24:50 -08001338 if (invoke_type == kVirtual) {
Nicolas Geoffraye5234232015-12-02 09:06:11 +00001339 CHECK(receiver != nullptr) << invoke_type;
Andreas Gampe542451c2016-07-26 09:02:02 -07001340 called = receiver->GetClass()->FindVirtualMethodForVirtual(called, kRuntimePointerSize);
Nicolas Geoffraye5234232015-12-02 09:06:11 +00001341 } else if (invoke_type == kInterface) {
1342 CHECK(receiver != nullptr) << invoke_type;
Andreas Gampe542451c2016-07-26 09:02:02 -07001343 called = receiver->GetClass()->FindVirtualMethodForInterface(called, kRuntimePointerSize);
Nicolas Geoffraye5234232015-12-02 09:06:11 +00001344 } else {
1345 DCHECK_EQ(invoke_type, kSuper);
1346 CHECK(caller != nullptr) << invoke_type;
Vladimir Markoba118822017-06-12 15:41:56 +01001347 ObjPtr<mirror::Class> ref_class = linker->LookupResolvedType(
Vladimir Marko666ee3d2017-12-11 18:37:36 +00001348 caller->GetDexFile()->GetMethodId(called_method.index).class_idx_, caller);
Alex Lightfedd91d2016-01-07 14:49:16 -08001349 if (ref_class->IsInterface()) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001350 called = ref_class->FindVirtualMethodForInterfaceSuper(called, kRuntimePointerSize);
Alex Lightfedd91d2016-01-07 14:49:16 -08001351 } else {
1352 called = caller->GetDeclaringClass()->GetSuperClass()->GetVTableEntry(
Andreas Gampe542451c2016-07-26 09:02:02 -07001353 called->GetMethodIndex(), kRuntimePointerSize);
Alex Lightfedd91d2016-01-07 14:49:16 -08001354 }
Mathieu Chartier55871bf2014-02-27 10:24:50 -08001355 }
Mingyao Yangf4867782014-05-05 11:55:02 -07001356
David Sehr709b0702016-10-13 09:12:37 -07001357 CHECK(called != nullptr) << orig_called->PrettyMethod() << " "
1358 << mirror::Object::PrettyTypeOf(receiver) << " "
Mingyao Yangf4867782014-05-05 11:55:02 -07001359 << invoke_type << " " << orig_called->GetVtableIndex();
Ian Rogers83883d72013-10-21 21:07:24 -07001360 }
Nicolas Geoffray1de6f012020-09-23 13:28:00 +01001361 // Now that we know the actual target, update .bss entry in oat file, if
1362 // any.
1363 if (!called_method_known_on_entry) {
1364 // We only put non copied methods in the BSS. Putting a copy can lead to an
1365 // odd situation where the ArtMethod being executed is unrelated to the
1366 // receiver of the method.
1367 called = called->GetCanonicalMethod();
Nicolas Geoffrayec068092021-05-10 17:28:32 +00001368 if (invoke_type == kSuper || invoke_type == kInterface || invoke_type == kVirtual) {
Nicolas Geoffray1de6f012020-09-23 13:28:00 +01001369 if (called->GetDexFile() == called_method.dex_file) {
1370 called_method.index = called->GetDexMethodIndex();
1371 } else {
1372 called_method.index = called->FindDexMethodIndexInOtherDexFile(
1373 *called_method.dex_file, called_method.index);
1374 DCHECK_NE(called_method.index, dex::kDexNoIndex);
1375 }
1376 }
1377 MaybeUpdateBssMethodEntry(called, called_method);
1378 }
Daniel Mihalyieb076692014-08-22 17:33:31 +02001379
Vladimir Marko6217fc22020-05-21 11:59:11 +01001380 // Static invokes need class initialization check but instance invokes can proceed even if
1381 // the class is erroneous, i.e. in the edge case of escaping instances of erroneous classes.
1382 bool success = true;
Vladimir Marko5115a4d2019-10-17 14:56:47 +01001383 ObjPtr<mirror::Class> called_class = called->GetDeclaringClass();
1384 if (NeedsClinitCheckBeforeCall(called) && !called_class->IsVisiblyInitialized()) {
1385 // Ensure that the called method's class is initialized.
1386 StackHandleScope<1> hs(soa.Self());
1387 HandleWrapperObjPtr<mirror::Class> h_called_class(hs.NewHandleWrapper(&called_class));
Vladimir Marko6217fc22020-05-21 11:59:11 +01001388 success = linker->EnsureInitialized(soa.Self(), h_called_class, true, true);
Vladimir Marko5115a4d2019-10-17 14:56:47 +01001389 }
Vladimir Marko6217fc22020-05-21 11:59:11 +01001390 if (success) {
Nicolas Geoffrayc25a9f92021-12-13 17:22:43 +00001391 instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation();
1392 code = instrumentation->GetCodeForInvoke(called);
Ian Rogers848871b2013-08-05 10:56:33 -07001393 } else {
1394 DCHECK(called_class->IsErroneous());
Vladimir Marko6217fc22020-05-21 11:59:11 +01001395 DCHECK(self->IsExceptionPending());
Ian Rogers848871b2013-08-05 10:56:33 -07001396 }
1397 }
Ian Rogerse0a02da2014-12-02 14:10:53 -08001398 CHECK_EQ(code == nullptr, self->IsExceptionPending());
Mathieu Chartier07d447b2013-09-26 11:57:43 -07001399 // Fixup any locally saved objects may have moved during a GC.
1400 visitor.FixupReferences();
Ian Rogers848871b2013-08-05 10:56:33 -07001401 // Place called method in callee-save frame to be placed as first argument to quick method.
Mathieu Chartiere401d142015-04-22 13:56:20 -07001402 *sp = called;
1403
Ian Rogers848871b2013-08-05 10:56:33 -07001404 return code;
1405}
1406
Andreas Gampec147b002014-03-06 18:11:06 -08001407/*
1408 * This class uses a couple of observations to unite the different calling conventions through
1409 * a few constants.
1410 *
1411 * 1) Number of registers used for passing is normally even, so counting down has no penalty for
1412 * possible alignment.
1413 * 2) Known 64b architectures store 8B units on the stack, both for integral and floating point
1414 * types, so using uintptr_t is OK. Also means that we can use kRegistersNeededX to denote
1415 * when we have to split things
1416 * 3) The only soft-float, Arm, is 32b, so no widening needs to be taken into account for floats
1417 * and we can use Int handling directly.
1418 * 4) Only 64b architectures widen, and their stack is aligned 8B anyways, so no padding code
1419 * necessary when widening. Also, widening of Ints will take place implicitly, and the
1420 * extension should be compatible with Aarch64, which mandates copying the available bits
1421 * into LSB and leaving the rest unspecified.
1422 * 5) Aligning longs and doubles is necessary on arm only, and it's the same in registers and on
1423 * the stack.
1424 * 6) There is only little endian.
1425 *
1426 *
1427 * Actual work is supposed to be done in a delegate of the template type. The interface is as
1428 * follows:
1429 *
1430 * void PushGpr(uintptr_t): Add a value for the next GPR
1431 *
1432 * void PushFpr4(float): Add a value for the next FPR of size 32b. Is only called if we need
1433 * padding, that is, think the architecture is 32b and aligns 64b.
1434 *
1435 * void PushFpr8(uint64_t): Push a double. We _will_ call this on 32b, it's the callee's job to
1436 * split this if necessary. The current state will have aligned, if
1437 * necessary.
1438 *
1439 * void PushStack(uintptr_t): Push a value to the stack.
Andreas Gampec147b002014-03-06 18:11:06 -08001440 */
Andreas Gampec200a4a2014-06-16 18:39:09 -07001441template<class T> class BuildNativeCallFrameStateMachine {
Andreas Gampec147b002014-03-06 18:11:06 -08001442 public:
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001443#if defined(__arm__)
Andreas Gampec147b002014-03-06 18:11:06 -08001444 static constexpr bool kNativeSoftFloatAbi = true;
1445 static constexpr size_t kNumNativeGprArgs = 4; // 4 arguments passed in GPRs, r0-r3
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001446 static constexpr size_t kNumNativeFprArgs = 0; // 0 arguments passed in FPRs.
1447
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001448 static constexpr size_t kRegistersNeededForLong = 2;
1449 static constexpr size_t kRegistersNeededForDouble = 2;
Andreas Gampec147b002014-03-06 18:11:06 -08001450 static constexpr bool kMultiRegistersAligned = true;
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001451 static constexpr bool kMultiFPRegistersWidened = false;
1452 static constexpr bool kMultiGPRegistersWidened = false;
Andreas Gampec147b002014-03-06 18:11:06 -08001453 static constexpr bool kAlignLongOnStack = true;
1454 static constexpr bool kAlignDoubleOnStack = true;
Stuart Monteithb95a5342014-03-12 13:32:32 +00001455#elif defined(__aarch64__)
1456 static constexpr bool kNativeSoftFloatAbi = false; // This is a hard float ABI.
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001457 static constexpr size_t kNumNativeGprArgs = 8; // 8 arguments passed in GPRs.
Stuart Monteithb95a5342014-03-12 13:32:32 +00001458 static constexpr size_t kNumNativeFprArgs = 8; // 8 arguments passed in FPRs.
1459
1460 static constexpr size_t kRegistersNeededForLong = 1;
1461 static constexpr size_t kRegistersNeededForDouble = 1;
1462 static constexpr bool kMultiRegistersAligned = false;
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001463 static constexpr bool kMultiFPRegistersWidened = false;
1464 static constexpr bool kMultiGPRegistersWidened = false;
Stuart Monteithb95a5342014-03-12 13:32:32 +00001465 static constexpr bool kAlignLongOnStack = false;
1466 static constexpr bool kAlignDoubleOnStack = false;
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001467#elif defined(__i386__)
Andreas Gampec147b002014-03-06 18:11:06 -08001468 static constexpr bool kNativeSoftFloatAbi = false; // Not using int registers for fp
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001469 static constexpr size_t kNumNativeGprArgs = 0; // 0 arguments passed in GPRs.
1470 static constexpr size_t kNumNativeFprArgs = 0; // 0 arguments passed in FPRs.
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001471
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001472 static constexpr size_t kRegistersNeededForLong = 2;
1473 static constexpr size_t kRegistersNeededForDouble = 2;
Andreas Gampec200a4a2014-06-16 18:39:09 -07001474 static constexpr bool kMultiRegistersAligned = false; // x86 not using regs, anyways
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001475 static constexpr bool kMultiFPRegistersWidened = false;
1476 static constexpr bool kMultiGPRegistersWidened = false;
Andreas Gampec147b002014-03-06 18:11:06 -08001477 static constexpr bool kAlignLongOnStack = false;
1478 static constexpr bool kAlignDoubleOnStack = false;
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001479#elif defined(__x86_64__)
1480 static constexpr bool kNativeSoftFloatAbi = false; // This is a hard float ABI.
1481 static constexpr size_t kNumNativeGprArgs = 6; // 6 arguments passed in GPRs.
1482 static constexpr size_t kNumNativeFprArgs = 8; // 8 arguments passed in FPRs.
1483
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001484 static constexpr size_t kRegistersNeededForLong = 1;
1485 static constexpr size_t kRegistersNeededForDouble = 1;
Andreas Gampec147b002014-03-06 18:11:06 -08001486 static constexpr bool kMultiRegistersAligned = false;
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001487 static constexpr bool kMultiFPRegistersWidened = false;
1488 static constexpr bool kMultiGPRegistersWidened = false;
Andreas Gampec147b002014-03-06 18:11:06 -08001489 static constexpr bool kAlignLongOnStack = false;
1490 static constexpr bool kAlignDoubleOnStack = false;
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001491#else
1492#error "Unsupported architecture"
1493#endif
1494
Andreas Gampec147b002014-03-06 18:11:06 -08001495 public:
Andreas Gampec200a4a2014-06-16 18:39:09 -07001496 explicit BuildNativeCallFrameStateMachine(T* delegate)
1497 : gpr_index_(kNumNativeGprArgs),
1498 fpr_index_(kNumNativeFprArgs),
1499 stack_entries_(0),
1500 delegate_(delegate) {
Andreas Gampec147b002014-03-06 18:11:06 -08001501 // For register alignment, we want to assume that counters (gpr_index_, fpr_index_) are even iff
1502 // the next register is even; counting down is just to make the compiler happy...
Andreas Gampe575e78c2014-11-03 23:41:03 -08001503 static_assert(kNumNativeGprArgs % 2 == 0U, "Number of native GPR arguments not even");
1504 static_assert(kNumNativeFprArgs % 2 == 0U, "Number of native FPR arguments not even");
Andreas Gampec147b002014-03-06 18:11:06 -08001505 }
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001506
Andreas Gampec200a4a2014-06-16 18:39:09 -07001507 virtual ~BuildNativeCallFrameStateMachine() {}
Andreas Gampec147b002014-03-06 18:11:06 -08001508
Ian Rogers1428dce2014-10-21 15:02:15 -07001509 bool HavePointerGpr() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001510 return gpr_index_ > 0;
1511 }
1512
Andreas Gampec200a4a2014-06-16 18:39:09 -07001513 void AdvancePointer(const void* val) {
Andreas Gampec147b002014-03-06 18:11:06 -08001514 if (HavePointerGpr()) {
1515 gpr_index_--;
1516 PushGpr(reinterpret_cast<uintptr_t>(val));
1517 } else {
Andreas Gampec200a4a2014-06-16 18:39:09 -07001518 stack_entries_++; // TODO: have a field for pointer length as multiple of 32b
Andreas Gampec147b002014-03-06 18:11:06 -08001519 PushStack(reinterpret_cast<uintptr_t>(val));
1520 gpr_index_ = 0;
1521 }
1522 }
1523
Ian Rogers1428dce2014-10-21 15:02:15 -07001524 bool HaveIntGpr() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001525 return gpr_index_ > 0;
1526 }
1527
1528 void AdvanceInt(uint32_t val) {
1529 if (HaveIntGpr()) {
1530 gpr_index_--;
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001531 if (kMultiGPRegistersWidened) {
1532 DCHECK_EQ(sizeof(uintptr_t), sizeof(int64_t));
Roland Levillainda4d79b2015-03-24 14:36:11 +00001533 PushGpr(static_cast<int64_t>(bit_cast<int32_t, uint32_t>(val)));
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001534 } else {
1535 PushGpr(val);
1536 }
Andreas Gampec147b002014-03-06 18:11:06 -08001537 } else {
1538 stack_entries_++;
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001539 if (kMultiGPRegistersWidened) {
1540 DCHECK_EQ(sizeof(uintptr_t), sizeof(int64_t));
Roland Levillainda4d79b2015-03-24 14:36:11 +00001541 PushStack(static_cast<int64_t>(bit_cast<int32_t, uint32_t>(val)));
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001542 } else {
1543 PushStack(val);
1544 }
Andreas Gampec147b002014-03-06 18:11:06 -08001545 gpr_index_ = 0;
1546 }
1547 }
1548
Ian Rogers1428dce2014-10-21 15:02:15 -07001549 bool HaveLongGpr() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001550 return gpr_index_ >= kRegistersNeededForLong + (LongGprNeedsPadding() ? 1 : 0);
1551 }
1552
Ian Rogers1428dce2014-10-21 15:02:15 -07001553 bool LongGprNeedsPadding() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001554 return kRegistersNeededForLong > 1 && // only pad when using multiple registers
1555 kAlignLongOnStack && // and when it needs alignment
1556 (gpr_index_ & 1) == 1; // counter is odd, see constructor
1557 }
1558
Ian Rogers1428dce2014-10-21 15:02:15 -07001559 bool LongStackNeedsPadding() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001560 return kRegistersNeededForLong > 1 && // only pad when using multiple registers
1561 kAlignLongOnStack && // and when it needs 8B alignment
1562 (stack_entries_ & 1) == 1; // counter is odd
1563 }
1564
1565 void AdvanceLong(uint64_t val) {
1566 if (HaveLongGpr()) {
1567 if (LongGprNeedsPadding()) {
1568 PushGpr(0);
1569 gpr_index_--;
1570 }
1571 if (kRegistersNeededForLong == 1) {
1572 PushGpr(static_cast<uintptr_t>(val));
1573 } else {
1574 PushGpr(static_cast<uintptr_t>(val & 0xFFFFFFFF));
1575 PushGpr(static_cast<uintptr_t>((val >> 32) & 0xFFFFFFFF));
1576 }
1577 gpr_index_ -= kRegistersNeededForLong;
1578 } else {
1579 if (LongStackNeedsPadding()) {
1580 PushStack(0);
1581 stack_entries_++;
1582 }
1583 if (kRegistersNeededForLong == 1) {
1584 PushStack(static_cast<uintptr_t>(val));
1585 stack_entries_++;
1586 } else {
1587 PushStack(static_cast<uintptr_t>(val & 0xFFFFFFFF));
1588 PushStack(static_cast<uintptr_t>((val >> 32) & 0xFFFFFFFF));
1589 stack_entries_ += 2;
1590 }
1591 gpr_index_ = 0;
1592 }
1593 }
1594
Ian Rogers1428dce2014-10-21 15:02:15 -07001595 bool HaveFloatFpr() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001596 return fpr_index_ > 0;
1597 }
1598
Andreas Gampec147b002014-03-06 18:11:06 -08001599 void AdvanceFloat(float val) {
1600 if (kNativeSoftFloatAbi) {
Roland Levillainda4d79b2015-03-24 14:36:11 +00001601 AdvanceInt(bit_cast<uint32_t, float>(val));
Andreas Gampec147b002014-03-06 18:11:06 -08001602 } else {
1603 if (HaveFloatFpr()) {
1604 fpr_index_--;
1605 if (kRegistersNeededForDouble == 1) {
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001606 if (kMultiFPRegistersWidened) {
Roland Levillainda4d79b2015-03-24 14:36:11 +00001607 PushFpr8(bit_cast<uint64_t, double>(val));
Andreas Gampec147b002014-03-06 18:11:06 -08001608 } else {
1609 // No widening, just use the bits.
Roland Levillainda4d79b2015-03-24 14:36:11 +00001610 PushFpr8(static_cast<uint64_t>(bit_cast<uint32_t, float>(val)));
Andreas Gampec147b002014-03-06 18:11:06 -08001611 }
1612 } else {
1613 PushFpr4(val);
1614 }
1615 } else {
1616 stack_entries_++;
Andreas Gampe1a5c4062015-01-15 12:10:47 -08001617 if (kRegistersNeededForDouble == 1 && kMultiFPRegistersWidened) {
Andreas Gampec147b002014-03-06 18:11:06 -08001618 // Need to widen before storing: Note the "double" in the template instantiation.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001619 // Note: We need to jump through those hoops to make the compiler happy.
1620 DCHECK_EQ(sizeof(uintptr_t), sizeof(uint64_t));
Roland Levillainda4d79b2015-03-24 14:36:11 +00001621 PushStack(static_cast<uintptr_t>(bit_cast<uint64_t, double>(val)));
Andreas Gampec147b002014-03-06 18:11:06 -08001622 } else {
Roland Levillainda4d79b2015-03-24 14:36:11 +00001623 PushStack(static_cast<uintptr_t>(bit_cast<uint32_t, float>(val)));
Andreas Gampec147b002014-03-06 18:11:06 -08001624 }
1625 fpr_index_ = 0;
1626 }
1627 }
1628 }
1629
Ian Rogers1428dce2014-10-21 15:02:15 -07001630 bool HaveDoubleFpr() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001631 return fpr_index_ >= kRegistersNeededForDouble + (DoubleFprNeedsPadding() ? 1 : 0);
1632 }
1633
Ian Rogers1428dce2014-10-21 15:02:15 -07001634 bool DoubleFprNeedsPadding() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001635 return kRegistersNeededForDouble > 1 && // only pad when using multiple registers
1636 kAlignDoubleOnStack && // and when it needs alignment
1637 (fpr_index_ & 1) == 1; // counter is odd, see constructor
1638 }
1639
Ian Rogers1428dce2014-10-21 15:02:15 -07001640 bool DoubleStackNeedsPadding() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001641 return kRegistersNeededForDouble > 1 && // only pad when using multiple registers
1642 kAlignDoubleOnStack && // and when it needs 8B alignment
1643 (stack_entries_ & 1) == 1; // counter is odd
1644 }
1645
1646 void AdvanceDouble(uint64_t val) {
1647 if (kNativeSoftFloatAbi) {
1648 AdvanceLong(val);
1649 } else {
1650 if (HaveDoubleFpr()) {
1651 if (DoubleFprNeedsPadding()) {
1652 PushFpr4(0);
1653 fpr_index_--;
1654 }
1655 PushFpr8(val);
1656 fpr_index_ -= kRegistersNeededForDouble;
1657 } else {
1658 if (DoubleStackNeedsPadding()) {
1659 PushStack(0);
1660 stack_entries_++;
1661 }
1662 if (kRegistersNeededForDouble == 1) {
1663 PushStack(static_cast<uintptr_t>(val));
1664 stack_entries_++;
1665 } else {
1666 PushStack(static_cast<uintptr_t>(val & 0xFFFFFFFF));
1667 PushStack(static_cast<uintptr_t>((val >> 32) & 0xFFFFFFFF));
1668 stack_entries_ += 2;
1669 }
1670 fpr_index_ = 0;
1671 }
1672 }
1673 }
1674
Ian Rogers1428dce2014-10-21 15:02:15 -07001675 uint32_t GetStackEntries() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001676 return stack_entries_;
1677 }
1678
Ian Rogers1428dce2014-10-21 15:02:15 -07001679 uint32_t GetNumberOfUsedGprs() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001680 return kNumNativeGprArgs - gpr_index_;
1681 }
1682
Ian Rogers1428dce2014-10-21 15:02:15 -07001683 uint32_t GetNumberOfUsedFprs() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001684 return kNumNativeFprArgs - fpr_index_;
1685 }
1686
1687 private:
1688 void PushGpr(uintptr_t val) {
1689 delegate_->PushGpr(val);
1690 }
1691 void PushFpr4(float val) {
1692 delegate_->PushFpr4(val);
1693 }
1694 void PushFpr8(uint64_t val) {
1695 delegate_->PushFpr8(val);
1696 }
1697 void PushStack(uintptr_t val) {
1698 delegate_->PushStack(val);
1699 }
Andreas Gampec147b002014-03-06 18:11:06 -08001700
1701 uint32_t gpr_index_; // Number of free GPRs
1702 uint32_t fpr_index_; // Number of free FPRs
1703 uint32_t stack_entries_; // Stack entries are in multiples of 32b, as floats are usually not
1704 // extended
Ian Rogers1428dce2014-10-21 15:02:15 -07001705 T* const delegate_; // What Push implementation gets called
Andreas Gampec147b002014-03-06 18:11:06 -08001706};
1707
Andreas Gampec200a4a2014-06-16 18:39:09 -07001708// Computes the sizes of register stacks and call stack area. Handling of references can be extended
1709// in subclasses.
1710//
1711// To handle native pointers, use "L" in the shorty for an object reference, which simulates
1712// them with handles.
1713class ComputeNativeCallFrameSize {
Andreas Gampec147b002014-03-06 18:11:06 -08001714 public:
Andreas Gampec200a4a2014-06-16 18:39:09 -07001715 ComputeNativeCallFrameSize() : num_stack_entries_(0) {}
1716
1717 virtual ~ComputeNativeCallFrameSize() {}
Andreas Gampec147b002014-03-06 18:11:06 -08001718
Ian Rogers1428dce2014-10-21 15:02:15 -07001719 uint32_t GetStackSize() const {
Andreas Gampec147b002014-03-06 18:11:06 -08001720 return num_stack_entries_ * sizeof(uintptr_t);
1721 }
1722
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001723 uint8_t* LayoutStackArgs(uint8_t* sp8) const {
Andreas Gampec147b002014-03-06 18:11:06 -08001724 sp8 -= GetStackSize();
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001725 // Align by kStackAlignment; it is at least as strict as native stack alignment.
Andreas Gampe779f8c92014-06-09 18:29:38 -07001726 sp8 = reinterpret_cast<uint8_t*>(RoundDown(reinterpret_cast<uintptr_t>(sp8), kStackAlignment));
Andreas Gampec200a4a2014-06-16 18:39:09 -07001727 return sp8;
Andreas Gampec147b002014-03-06 18:11:06 -08001728 }
1729
Roland Levillain4b8f1ec2015-08-26 18:34:03 +01001730 virtual void WalkHeader(
1731 BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>* sm ATTRIBUTE_UNUSED)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001732 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers6a3c1fc2014-10-31 00:33:20 -07001733 }
Andreas Gampec200a4a2014-06-16 18:39:09 -07001734
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001735 void Walk(const char* shorty, uint32_t shorty_len) REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampec200a4a2014-06-16 18:39:09 -07001736 BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize> sm(this);
1737
1738 WalkHeader(&sm);
Andreas Gampec147b002014-03-06 18:11:06 -08001739
1740 for (uint32_t i = 1; i < shorty_len; ++i) {
1741 Primitive::Type cur_type_ = Primitive::GetType(shorty[i]);
1742 switch (cur_type_) {
1743 case Primitive::kPrimNot:
Vladimir Markocedec9d2021-02-08 16:16:13 +00001744 sm.AdvancePointer(nullptr);
Andreas Gampec147b002014-03-06 18:11:06 -08001745 break;
Andreas Gampec147b002014-03-06 18:11:06 -08001746 case Primitive::kPrimBoolean:
1747 case Primitive::kPrimByte:
1748 case Primitive::kPrimChar:
1749 case Primitive::kPrimShort:
1750 case Primitive::kPrimInt:
1751 sm.AdvanceInt(0);
1752 break;
1753 case Primitive::kPrimFloat:
1754 sm.AdvanceFloat(0);
1755 break;
1756 case Primitive::kPrimDouble:
1757 sm.AdvanceDouble(0);
1758 break;
1759 case Primitive::kPrimLong:
1760 sm.AdvanceLong(0);
1761 break;
1762 default:
1763 LOG(FATAL) << "Unexpected type: " << cur_type_ << " in " << shorty;
Ian Rogerse0a02da2014-12-02 14:10:53 -08001764 UNREACHABLE();
Andreas Gampec147b002014-03-06 18:11:06 -08001765 }
1766 }
1767
Ian Rogers1428dce2014-10-21 15:02:15 -07001768 num_stack_entries_ = sm.GetStackEntries();
Andreas Gampec147b002014-03-06 18:11:06 -08001769 }
1770
1771 void PushGpr(uintptr_t /* val */) {
1772 // not optimizing registers, yet
1773 }
1774
1775 void PushFpr4(float /* val */) {
1776 // not optimizing registers, yet
1777 }
1778
1779 void PushFpr8(uint64_t /* val */) {
1780 // not optimizing registers, yet
1781 }
1782
1783 void PushStack(uintptr_t /* val */) {
1784 // counting is already done in the superclass
1785 }
1786
Andreas Gampec200a4a2014-06-16 18:39:09 -07001787 protected:
Andreas Gampec147b002014-03-06 18:11:06 -08001788 uint32_t num_stack_entries_;
1789};
1790
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001791class ComputeGenericJniFrameSize final : public ComputeNativeCallFrameSize {
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001792 public:
Igor Murashkin06a04e02016-09-13 15:57:37 -07001793 explicit ComputeGenericJniFrameSize(bool critical_native)
Vladimir Markocedec9d2021-02-08 16:16:13 +00001794 : critical_native_(critical_native) {}
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001795
Vladimir Markocedec9d2021-02-08 16:16:13 +00001796 uintptr_t* ComputeLayout(ArtMethod** managed_sp, const char* shorty, uint32_t shorty_len)
1797 REQUIRES_SHARED(Locks::mutator_lock_) {
Andreas Gampe542451c2016-07-26 09:02:02 -07001798 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize);
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001799
Andreas Gampec200a4a2014-06-16 18:39:09 -07001800 Walk(shorty, shorty_len);
1801
Vladimir Markocedec9d2021-02-08 16:16:13 +00001802 // Add space for cookie.
1803 DCHECK_ALIGNED(managed_sp, sizeof(uintptr_t));
1804 static_assert(sizeof(uintptr_t) >= sizeof(IRTSegmentState));
1805 uint8_t* sp8 = reinterpret_cast<uint8_t*>(managed_sp) - sizeof(uintptr_t);
Andreas Gampec200a4a2014-06-16 18:39:09 -07001806
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001807 // Layout stack arguments.
1808 sp8 = LayoutStackArgs(sp8);
Andreas Gampec200a4a2014-06-16 18:39:09 -07001809
1810 // Return the new bottom.
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001811 DCHECK_ALIGNED(sp8, sizeof(uintptr_t));
1812 return reinterpret_cast<uintptr_t*>(sp8);
1813 }
1814
1815 static uintptr_t* GetStartGprRegs(uintptr_t* reserved_area) {
1816 return reserved_area;
1817 }
1818
1819 static uint32_t* GetStartFprRegs(uintptr_t* reserved_area) {
1820 constexpr size_t num_gprs =
1821 BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>::kNumNativeGprArgs;
1822 return reinterpret_cast<uint32_t*>(GetStartGprRegs(reserved_area) + num_gprs);
1823 }
1824
1825 static uintptr_t* GetHiddenArgSlot(uintptr_t* reserved_area) {
1826 // Note: `num_fprs` is 0 on architectures where sizeof(uintptr_t) does not match the
1827 // FP register size (it is actually 0 on all supported 32-bit architectures).
1828 constexpr size_t num_fprs =
1829 BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>::kNumNativeFprArgs;
1830 return reinterpret_cast<uintptr_t*>(GetStartFprRegs(reserved_area)) + num_fprs;
1831 }
1832
1833 static uintptr_t* GetOutArgsSpSlot(uintptr_t* reserved_area) {
1834 return GetHiddenArgSlot(reserved_area) + 1;
Andreas Gampec200a4a2014-06-16 18:39:09 -07001835 }
1836
Andreas Gampec200a4a2014-06-16 18:39:09 -07001837 // Add JNIEnv* and jobj/jclass before the shorty-derived elements.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001838 void WalkHeader(BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>* sm) override
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07001839 REQUIRES_SHARED(Locks::mutator_lock_);
Andreas Gampec200a4a2014-06-16 18:39:09 -07001840
1841 private:
Igor Murashkin06a04e02016-09-13 15:57:37 -07001842 const bool critical_native_;
Andreas Gampec200a4a2014-06-16 18:39:09 -07001843};
1844
Andreas Gampec200a4a2014-06-16 18:39:09 -07001845void ComputeGenericJniFrameSize::WalkHeader(
1846 BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>* sm) {
Igor Murashkin06a04e02016-09-13 15:57:37 -07001847 // First 2 parameters are always excluded for @CriticalNative.
1848 if (UNLIKELY(critical_native_)) {
1849 return;
1850 }
1851
Andreas Gampec200a4a2014-06-16 18:39:09 -07001852 // JNIEnv
1853 sm->AdvancePointer(nullptr);
1854
1855 // Class object or this as first argument
Vladimir Markocedec9d2021-02-08 16:16:13 +00001856 sm->AdvancePointer(nullptr);
Andreas Gampec200a4a2014-06-16 18:39:09 -07001857}
1858
1859// Class to push values to three separate regions. Used to fill the native call part. Adheres to
1860// the template requirements of BuildGenericJniFrameStateMachine.
1861class FillNativeCall {
1862 public:
1863 FillNativeCall(uintptr_t* gpr_regs, uint32_t* fpr_regs, uintptr_t* stack_args) :
1864 cur_gpr_reg_(gpr_regs), cur_fpr_reg_(fpr_regs), cur_stack_arg_(stack_args) {}
1865
1866 virtual ~FillNativeCall() {}
1867
1868 void Reset(uintptr_t* gpr_regs, uint32_t* fpr_regs, uintptr_t* stack_args) {
1869 cur_gpr_reg_ = gpr_regs;
1870 cur_fpr_reg_ = fpr_regs;
1871 cur_stack_arg_ = stack_args;
Andreas Gampec147b002014-03-06 18:11:06 -08001872 }
1873
1874 void PushGpr(uintptr_t val) {
1875 *cur_gpr_reg_ = val;
1876 cur_gpr_reg_++;
1877 }
1878
1879 void PushFpr4(float val) {
1880 *cur_fpr_reg_ = val;
1881 cur_fpr_reg_++;
1882 }
1883
1884 void PushFpr8(uint64_t val) {
1885 uint64_t* tmp = reinterpret_cast<uint64_t*>(cur_fpr_reg_);
1886 *tmp = val;
1887 cur_fpr_reg_ += 2;
1888 }
1889
1890 void PushStack(uintptr_t val) {
1891 *cur_stack_arg_ = val;
1892 cur_stack_arg_++;
1893 }
1894
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001895 private:
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001896 uintptr_t* cur_gpr_reg_;
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001897 uint32_t* cur_fpr_reg_;
1898 uintptr_t* cur_stack_arg_;
Andreas Gampec200a4a2014-06-16 18:39:09 -07001899};
Andreas Gampec147b002014-03-06 18:11:06 -08001900
Andreas Gampec200a4a2014-06-16 18:39:09 -07001901// Visits arguments on the stack placing them into a region lower down the stack for the benefit
1902// of transitioning into native code.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001903class BuildGenericJniFrameVisitor final : public QuickArgumentVisitor {
Andreas Gampec200a4a2014-06-16 18:39:09 -07001904 public:
Igor Murashkin06a04e02016-09-13 15:57:37 -07001905 BuildGenericJniFrameVisitor(Thread* self,
1906 bool is_static,
1907 bool critical_native,
1908 const char* shorty,
1909 uint32_t shorty_len,
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001910 ArtMethod** managed_sp,
1911 uintptr_t* reserved_area)
1912 : QuickArgumentVisitor(managed_sp, is_static, shorty, shorty_len),
Vladimir Markocedec9d2021-02-08 16:16:13 +00001913 jni_call_(nullptr, nullptr, nullptr, critical_native),
1914 sm_(&jni_call_),
1915 current_vreg_(nullptr) {
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001916 DCHECK_ALIGNED(managed_sp, kStackAlignment);
1917 DCHECK_ALIGNED(reserved_area, sizeof(uintptr_t));
Andreas Gampec200a4a2014-06-16 18:39:09 -07001918
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001919 ComputeGenericJniFrameSize fsc(critical_native);
Vladimir Markocedec9d2021-02-08 16:16:13 +00001920 uintptr_t* out_args_sp = fsc.ComputeLayout(managed_sp, shorty, shorty_len);
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001921
1922 // Store hidden argument for @CriticalNative.
1923 uintptr_t* hidden_arg_slot = fsc.GetHiddenArgSlot(reserved_area);
1924 constexpr uintptr_t kGenericJniTag = 1u;
1925 ArtMethod* method = *managed_sp;
1926 *hidden_arg_slot = critical_native ? (reinterpret_cast<uintptr_t>(method) | kGenericJniTag)
1927 : 0xebad6a89u; // Bad value.
1928
1929 // Set out args SP.
1930 uintptr_t* out_args_sp_slot = fsc.GetOutArgsSpSlot(reserved_area);
1931 *out_args_sp_slot = reinterpret_cast<uintptr_t>(out_args_sp);
1932
Vladimir Markocedec9d2021-02-08 16:16:13 +00001933 // Prepare vreg pointer for spilling references.
1934 static constexpr size_t frame_size =
1935 RuntimeCalleeSaveFrame::GetFrameSize(CalleeSaveType::kSaveRefsAndArgs);
1936 current_vreg_ = reinterpret_cast<uint32_t*>(
1937 reinterpret_cast<uint8_t*>(managed_sp) + frame_size + sizeof(ArtMethod*));
1938
Vladimir Marko6e043bb2020-02-10 16:56:54 +00001939 jni_call_.Reset(fsc.GetStartGprRegs(reserved_area),
1940 fsc.GetStartFprRegs(reserved_area),
Vladimir Markocedec9d2021-02-08 16:16:13 +00001941 out_args_sp);
Andreas Gampec200a4a2014-06-16 18:39:09 -07001942
Igor Murashkin06a04e02016-09-13 15:57:37 -07001943 // First 2 parameters are always excluded for CriticalNative methods.
1944 if (LIKELY(!critical_native)) {
1945 // jni environment is always first argument
1946 sm_.AdvancePointer(self->GetJniEnv());
Andreas Gampec200a4a2014-06-16 18:39:09 -07001947
Igor Murashkin06a04e02016-09-13 15:57:37 -07001948 if (is_static) {
Vladimir Markocedec9d2021-02-08 16:16:13 +00001949 // The `jclass` is a pointer to the method's declaring class.
1950 // The declaring class must be marked.
Vladimir Marko0eebdcc2021-02-26 09:34:13 +00001951 auto* declaring_class = reinterpret_cast<mirror::CompressedReference<mirror::Class>*>(
1952 method->GetDeclaringClassAddressWithoutBarrier());
1953 if (kUseReadBarrier) {
Vladimir Marko8439e452021-11-25 15:36:29 +00001954 artJniReadBarrier(method);
Vladimir Marko0eebdcc2021-02-26 09:34:13 +00001955 }
1956 sm_.AdvancePointer(declaring_class);
Igor Murashkin06a04e02016-09-13 15:57:37 -07001957 } // else "this" reference is already handled by QuickArgumentVisitor.
Andreas Gampec200a4a2014-06-16 18:39:09 -07001958 }
1959 }
1960
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001961 void Visit() REQUIRES_SHARED(Locks::mutator_lock_) override;
Andreas Gampec200a4a2014-06-16 18:39:09 -07001962
Andreas Gampec200a4a2014-06-16 18:39:09 -07001963 private:
1964 // A class to fill a JNI call. Adds reference/handle-scope management to FillNativeCall.
Roland Levillainbbc6e7e2018-08-24 16:58:47 +01001965 class FillJniCall final : public FillNativeCall {
Andreas Gampec200a4a2014-06-16 18:39:09 -07001966 public:
Vladimir Markocedec9d2021-02-08 16:16:13 +00001967 FillJniCall(uintptr_t* gpr_regs,
1968 uint32_t* fpr_regs,
1969 uintptr_t* stack_args,
1970 bool critical_native)
1971 : FillNativeCall(gpr_regs, fpr_regs, stack_args),
1972 cur_entry_(0),
1973 critical_native_(critical_native) {}
Andreas Gampec200a4a2014-06-16 18:39:09 -07001974
Vladimir Markocedec9d2021-02-08 16:16:13 +00001975 void Reset(uintptr_t* gpr_regs, uint32_t* fpr_regs, uintptr_t* stack_args) {
Andreas Gampec200a4a2014-06-16 18:39:09 -07001976 FillNativeCall::Reset(gpr_regs, fpr_regs, stack_args);
Andreas Gampec200a4a2014-06-16 18:39:09 -07001977 cur_entry_ = 0U;
1978 }
1979
Mathieu Chartier1432a5b2016-10-04 15:41:42 -07001980 bool CriticalNative() const {
1981 return critical_native_;
1982 }
1983
Andreas Gampec200a4a2014-06-16 18:39:09 -07001984 private:
Andreas Gampec200a4a2014-06-16 18:39:09 -07001985 size_t cur_entry_;
Igor Murashkin06a04e02016-09-13 15:57:37 -07001986 const bool critical_native_;
Andreas Gampec200a4a2014-06-16 18:39:09 -07001987 };
1988
Andreas Gampec200a4a2014-06-16 18:39:09 -07001989 FillJniCall jni_call_;
Andreas Gampec200a4a2014-06-16 18:39:09 -07001990 BuildNativeCallFrameStateMachine<FillJniCall> sm_;
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001991
Vladimir Markocedec9d2021-02-08 16:16:13 +00001992 // Pointer to the current vreg in caller's reserved out vreg area.
1993 // Used for spilling reference arguments.
1994 uint32_t* current_vreg_;
1995
Andreas Gampebf6b92a2014-03-05 16:11:04 -08001996 DISALLOW_COPY_AND_ASSIGN(BuildGenericJniFrameVisitor);
1997};
1998
Ian Rogers9758f792014-03-13 09:02:55 -07001999void BuildGenericJniFrameVisitor::Visit() {
2000 Primitive::Type type = GetParamPrimitiveType();
2001 switch (type) {
2002 case Primitive::kPrimLong: {
2003 jlong long_arg;
2004 if (IsSplitLongOrDouble()) {
2005 long_arg = ReadSplitLongParam();
2006 } else {
2007 long_arg = *reinterpret_cast<jlong*>(GetParamAddress());
2008 }
2009 sm_.AdvanceLong(long_arg);
Vladimir Markocedec9d2021-02-08 16:16:13 +00002010 current_vreg_ += 2u;
Ian Rogers9758f792014-03-13 09:02:55 -07002011 break;
2012 }
2013 case Primitive::kPrimDouble: {
2014 uint64_t double_arg;
2015 if (IsSplitLongOrDouble()) {
2016 // Read into union so that we don't case to a double.
2017 double_arg = ReadSplitLongParam();
2018 } else {
2019 double_arg = *reinterpret_cast<uint64_t*>(GetParamAddress());
2020 }
2021 sm_.AdvanceDouble(double_arg);
Vladimir Markocedec9d2021-02-08 16:16:13 +00002022 current_vreg_ += 2u;
Ian Rogers9758f792014-03-13 09:02:55 -07002023 break;
2024 }
2025 case Primitive::kPrimNot: {
Vladimir Markocedec9d2021-02-08 16:16:13 +00002026 mirror::Object* obj =
2027 reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress())->AsMirrorPtr();
2028 StackReference<mirror::Object>* spill_ref =
2029 reinterpret_cast<StackReference<mirror::Object>*>(current_vreg_);
2030 spill_ref->Assign(obj);
2031 sm_.AdvancePointer(obj != nullptr ? spill_ref : nullptr);
2032 current_vreg_ += 1u;
Ian Rogers9758f792014-03-13 09:02:55 -07002033 break;
2034 }
2035 case Primitive::kPrimFloat:
2036 sm_.AdvanceFloat(*reinterpret_cast<float*>(GetParamAddress()));
Vladimir Markocedec9d2021-02-08 16:16:13 +00002037 current_vreg_ += 1u;
Ian Rogers9758f792014-03-13 09:02:55 -07002038 break;
2039 case Primitive::kPrimBoolean: // Fall-through.
2040 case Primitive::kPrimByte: // Fall-through.
2041 case Primitive::kPrimChar: // Fall-through.
2042 case Primitive::kPrimShort: // Fall-through.
2043 case Primitive::kPrimInt: // Fall-through.
2044 sm_.AdvanceInt(*reinterpret_cast<jint*>(GetParamAddress()));
Vladimir Markocedec9d2021-02-08 16:16:13 +00002045 current_vreg_ += 1u;
Ian Rogers9758f792014-03-13 09:02:55 -07002046 break;
2047 case Primitive::kPrimVoid:
2048 LOG(FATAL) << "UNREACHABLE";
Ian Rogers2c4257b2014-10-24 14:20:06 -07002049 UNREACHABLE();
Ian Rogers9758f792014-03-13 09:02:55 -07002050 }
2051}
2052
Andreas Gampec147b002014-03-06 18:11:06 -08002053/*
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002054 * Initializes the reserved area assumed to be directly below `managed_sp` for a native call:
Andreas Gampec147b002014-03-06 18:11:06 -08002055 *
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002056 * On entry, the stack has a standard callee-save frame above `managed_sp`,
2057 * and the reserved area below it. Starting below `managed_sp`, we reserve space
2058 * for local reference cookie (not present for @CriticalNative), HandleScope
2059 * (not present for @CriticalNative) and stack args (if args do not fit into
2060 * registers). At the bottom of the reserved area, there is space for register
2061 * arguments, hidden arg (for @CriticalNative) and the SP for the native call
2062 * (i.e. pointer to the stack args area), which the calling stub shall load
2063 * to perform the native call. We fill all these fields, perform class init
2064 * check (for static methods) and/or locking (for synchronized methods) if
2065 * needed and return to the stub.
Andreas Gampe36fea8d2014-03-10 13:37:40 -07002066 *
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002067 * The return value is the pointer to the native code, null on failure.
Vladimir Marko4d527152021-11-23 12:07:04 +00002068 *
2069 * NO_THREAD_SAFETY_ANALYSIS: Depending on the use case, the trampoline may
2070 * or may not lock a synchronization object and transition out of Runnable.
Andreas Gampec147b002014-03-06 18:11:06 -08002071 */
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002072extern "C" const void* artQuickGenericJniTrampoline(Thread* self,
2073 ArtMethod** managed_sp,
2074 uintptr_t* reserved_area)
Vladimir Marko4d527152021-11-23 12:07:04 +00002075 REQUIRES_SHARED(Locks::mutator_lock_) NO_THREAD_SAFETY_ANALYSIS {
Vladimir Markob0a6aee2017-10-27 10:34:04 +01002076 // Note: We cannot walk the stack properly until fixed up below.
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002077 ArtMethod* called = *managed_sp;
David Sehr709b0702016-10-13 09:12:37 -07002078 DCHECK(called->IsNative()) << called->PrettyMethod(true);
Vladimir Marko2196c652017-11-30 16:16:07 +00002079 Runtime* runtime = Runtime::Current();
Mathieu Chartierbfd9a432014-05-21 17:43:44 -07002080 uint32_t shorty_len = 0;
2081 const char* shorty = called->GetShorty(&shorty_len);
Vladimir Markob0a6aee2017-10-27 10:34:04 +01002082 bool critical_native = called->IsCriticalNative();
2083 bool fast_native = called->IsFastNative();
Igor Murashkin06a04e02016-09-13 15:57:37 -07002084 bool normal_native = !critical_native && !fast_native;
Andreas Gampec200a4a2014-06-16 18:39:09 -07002085
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002086 // Run the visitor and update sp.
Igor Murashkin06a04e02016-09-13 15:57:37 -07002087 BuildGenericJniFrameVisitor visitor(self,
2088 called->IsStatic(),
2089 critical_native,
2090 shorty,
2091 shorty_len,
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002092 managed_sp,
2093 reserved_area);
Mathieu Chartierbe08cf52016-09-13 13:41:24 -07002094 {
2095 ScopedAssertNoThreadSuspension sants(__FUNCTION__);
2096 visitor.VisitArguments();
Mathieu Chartierbe08cf52016-09-13 13:41:24 -07002097 }
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002098
Vladimir Markob0a6aee2017-10-27 10:34:04 +01002099 // Fix up managed-stack things in Thread. After this we can walk the stack.
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002100 self->SetTopOfStackTagged(managed_sp);
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002101
Ian Rogerse0dcd462014-03-08 15:21:04 -08002102 self->VerifyStack();
2103
Vladimir Markof8655b32018-03-21 17:53:56 +00002104 // We can now walk the stack if needed by JIT GC from MethodEntered() for JIT-on-first-use.
2105 jit::Jit* jit = runtime->GetJit();
2106 if (jit != nullptr) {
2107 jit->MethodEntered(self, called);
2108 }
2109
Nicolas Geoffray5a0b6722019-09-24 15:09:40 +01002110 // We can set the entrypoint of a native method to generic JNI even when the
2111 // class hasn't been initialized, so we need to do the initialization check
2112 // before invoking the native code.
Vladimir Marko5115a4d2019-10-17 14:56:47 +01002113 if (NeedsClinitCheckBeforeCall(called)) {
2114 ObjPtr<mirror::Class> declaring_class = called->GetDeclaringClass();
2115 if (UNLIKELY(!declaring_class->IsVisiblyInitialized())) {
2116 // Ensure static method's class is initialized.
2117 StackHandleScope<1> hs(self);
2118 Handle<mirror::Class> h_class(hs.NewHandle(declaring_class));
Vladimir Marko7dac8642019-11-06 17:09:30 +00002119 if (!runtime->GetClassLinker()->EnsureInitialized(self, h_class, true, true)) {
Vladimir Marko5115a4d2019-10-17 14:56:47 +01002120 DCHECK(Thread::Current()->IsExceptionPending()) << called->PrettyMethod();
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002121 return nullptr; // Report error.
Vladimir Marko5115a4d2019-10-17 14:56:47 +01002122 }
Nicolas Geoffray5a0b6722019-09-24 15:09:40 +01002123 }
2124 }
2125
Vladimir Markoce2a3442021-11-24 15:10:26 +00002126 // Skip calling `artJniMethodStart()` for @CriticalNative and @FastNative.
Vladimir Marko46a89102021-10-21 13:05:46 +00002127 if (LIKELY(normal_native)) {
Vladimir Markod95a1f22021-03-23 16:32:52 +00002128 // Start JNI.
Igor Murashkin06a04e02016-09-13 15:57:37 -07002129 if (called->IsSynchronized()) {
Vladimir Marko4d527152021-11-23 12:07:04 +00002130 ObjPtr<mirror::Object> lock = GetGenericJniSynchronizationObject(self, called);
2131 DCHECK(lock != nullptr);
2132 lock->MonitorEnter(self);
Igor Murashkin06a04e02016-09-13 15:57:37 -07002133 if (self->IsExceptionPending()) {
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002134 return nullptr; // Report error.
Igor Murashkin06a04e02016-09-13 15:57:37 -07002135 }
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002136 }
Vladimir Markoce2a3442021-11-24 15:10:26 +00002137 artJniMethodStart(self);
Vladimir Marko46a89102021-10-21 13:05:46 +00002138 } else {
2139 DCHECK(!called->IsSynchronized())
2140 << "@FastNative/@CriticalNative and synchronize is not supported";
2141 }
Vladimir Markod95a1f22021-03-23 16:32:52 +00002142
Vladimir Marko46a89102021-10-21 13:05:46 +00002143 // Skip pushing IRT frame for @CriticalNative.
2144 if (LIKELY(!critical_native)) {
Vladimir Markod95a1f22021-03-23 16:32:52 +00002145 // Push local reference frame.
2146 JNIEnvExt* env = self->GetJniEnv();
2147 DCHECK(env != nullptr);
2148 uint32_t cookie = bit_cast<uint32_t>(env->GetLocalRefCookie());
2149 env->SetLocalRefCookie(env->GetLocalsSegmentState());
2150
2151 // Save the cookie on the stack.
2152 uint32_t* sp32 = reinterpret_cast<uint32_t*>(managed_sp);
Igor Murashkin06a04e02016-09-13 15:57:37 -07002153 *(sp32 - 1) = cookie;
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002154 }
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002155
Andreas Gampe90546832014-03-12 18:07:19 -07002156 // Retrieve the stored native code.
Vladimir Marko08d09842019-12-02 12:38:49 +00002157 // Note that it may point to the lookup stub or trampoline.
2158 // FIXME: This is broken for @CriticalNative as the art_jni_dlsym_lookup_stub
2159 // does not handle that case. Calls from compiled stubs are also broken.
Alex Lightd78ddec2017-04-18 15:20:38 -07002160 void const* nativeCode = called->GetEntryPointFromJni();
Andreas Gampe90546832014-03-12 18:07:19 -07002161
Andreas Gampe21a6ec52019-03-28 10:55:50 -07002162 VLOG(third_party_jni) << "GenericJNI: "
2163 << called->PrettyMethod()
2164 << " -> "
2165 << std::hex << reinterpret_cast<uintptr_t>(nativeCode);
2166
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002167 // Return native code.
2168 return nativeCode;
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002169}
2170
Hiroshi Yamauchia23b4682015-09-28 17:47:32 -07002171// Defined in quick_jni_entrypoints.cc.
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002172extern uint64_t GenericJniMethodEnd(Thread* self,
2173 uint32_t saved_local_ref_cookie,
2174 jvalue result,
2175 uint64_t result_f,
2176 ArtMethod* called);
2177
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002178/*
Mathieu Chartiereb8167a2014-05-07 15:43:14 -07002179 * Is called after the native JNI code. Responsible for cleanup (handle scope, saved state) and
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002180 * unlocking.
2181 */
Hiroshi Yamauchia23b4682015-09-28 17:47:32 -07002182extern "C" uint64_t artQuickGenericJniEndTrampoline(Thread* self,
2183 jvalue result,
2184 uint64_t result_f) {
2185 // We're here just back from a native call. We don't have the shared mutator lock at this point
2186 // yet until we call GoToRunnable() later in GenericJniMethodEnd(). Accessing objects or doing
2187 // anything that requires a mutator lock before that would cause problems as GC may have the
2188 // exclusive mutator lock and may be moving objects, etc.
Mathieu Chartiere401d142015-04-22 13:56:20 -07002189 ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame();
Vladimir Marko2196c652017-11-30 16:16:07 +00002190 DCHECK(self->GetManagedStack()->GetTopQuickFrameTag());
Andreas Gampebf6b92a2014-03-05 16:11:04 -08002191 uint32_t* sp32 = reinterpret_cast<uint32_t*>(sp);
Mathieu Chartiere401d142015-04-22 13:56:20 -07002192 ArtMethod* called = *sp;
Ian Rogerse0dcd462014-03-08 15:21:04 -08002193 uint32_t cookie = *(sp32 - 1);
Vladimir Marko6e043bb2020-02-10 16:56:54 +00002194 return GenericJniMethodEnd(self, cookie, result, result_f, called);
Andreas Gampe2da88232014-02-27 12:26:20 -08002195}
2196
Andreas Gamped58342c2014-06-05 14:18:08 -07002197// We use TwoWordReturn to optimize scalar returns. We use the hi value for code, and the lo value
2198// for the method pointer.
Andreas Gampe51f76352014-05-21 08:28:48 -07002199//
Andreas Gamped58342c2014-06-05 14:18:08 -07002200// It is valid to use this, as at the usage points here (returns from C functions) we are assuming
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07002201// to hold the mutator lock (see REQUIRES_SHARED(Locks::mutator_lock_) annotations).
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002202
Vladimir Markof79aa7f2017-07-04 16:58:55 +01002203template <InvokeType type, bool access_check>
Mathieu Chartieref41db72016-10-25 15:08:01 -07002204static TwoWordReturn artInvokeCommon(uint32_t method_idx,
2205 ObjPtr<mirror::Object> this_object,
2206 Thread* self,
Mathieu Chartiere401d142015-04-22 13:56:20 -07002207 ArtMethod** sp) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002208 ScopedQuickEntrypointChecks sqec(self);
Andreas Gampe8228cdf2017-05-30 15:03:54 -07002209 DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs));
Mathieu Chartiere401d142015-04-22 13:56:20 -07002210 ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp);
Vladimir Markof79aa7f2017-07-04 16:58:55 +01002211 ArtMethod* method = FindMethodFast<type, access_check>(method_idx, this_object, caller_method);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002212 if (UNLIKELY(method == nullptr)) {
Vladimir Marko7e097372018-11-28 16:40:59 +00002213 const DexFile* dex_file = caller_method->GetDexFile();
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002214 uint32_t shorty_len;
Andreas Gampec200a4a2014-06-16 18:39:09 -07002215 const char* shorty = dex_file->GetMethodShorty(dex_file->GetMethodId(method_idx), &shorty_len);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002216 {
2217 // Remember the args in case a GC happens in FindMethodFromCode.
2218 ScopedObjectAccessUnchecked soa(self->GetJniEnv());
2219 RememberForGcArgumentVisitor visitor(sp, type == kStatic, shorty, shorty_len, &soa);
2220 visitor.VisitArguments();
Mathieu Chartieref41db72016-10-25 15:08:01 -07002221 method = FindMethodFromCode<type, access_check>(method_idx,
2222 &this_object,
2223 caller_method,
Mathieu Chartier0cd81352014-05-22 16:48:55 -07002224 self);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002225 visitor.FixupReferences();
2226 }
2227
Ian Rogerse0a02da2014-12-02 14:10:53 -08002228 if (UNLIKELY(method == nullptr)) {
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002229 CHECK(self->IsExceptionPending());
Andreas Gamped58342c2014-06-05 14:18:08 -07002230 return GetTwoWordFailureValue(); // Failure.
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002231 }
2232 }
2233 DCHECK(!self->IsExceptionPending());
2234 const void* code = method->GetEntryPointFromQuickCompiledCode();
2235
2236 // When we return, the caller will branch to this address, so it had better not be 0!
David Sehr709b0702016-10-13 09:12:37 -07002237 DCHECK(code != nullptr) << "Code was null in method: " << method->PrettyMethod()
Andreas Gampec200a4a2014-06-16 18:39:09 -07002238 << " location: "
2239 << method->GetDexFile()->GetLocation();
Andreas Gampe51f76352014-05-21 08:28:48 -07002240
Andreas Gamped58342c2014-06-05 14:18:08 -07002241 return GetTwoWordSuccessValue(reinterpret_cast<uintptr_t>(code),
2242 reinterpret_cast<uintptr_t>(method));
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002243}
2244
Nicolas Geoffray8689a0a2014-04-04 09:26:24 +01002245// Explicit artInvokeCommon template function declarations to please analysis tool.
2246#define EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(type, access_check) \
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07002247 template REQUIRES_SHARED(Locks::mutator_lock_) \
Mathieu Chartiere401d142015-04-22 13:56:20 -07002248 TwoWordReturn artInvokeCommon<type, access_check>( \
Mathieu Chartieref41db72016-10-25 15:08:01 -07002249 uint32_t method_idx, ObjPtr<mirror::Object> his_object, Thread* self, ArtMethod** sp)
Nicolas Geoffray8689a0a2014-04-04 09:26:24 +01002250
2251EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kVirtual, false);
2252EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kVirtual, true);
2253EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kInterface, false);
2254EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kInterface, true);
2255EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kDirect, false);
2256EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kDirect, true);
2257EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kStatic, false);
2258EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kStatic, true);
2259EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kSuper, false);
2260EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kSuper, true);
2261#undef EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL
2262
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002263// See comments in runtime_support_asm.S
Andreas Gampec200a4a2014-06-16 18:39:09 -07002264extern "C" TwoWordReturn artInvokeInterfaceTrampolineWithAccessCheck(
Mathieu Chartiere401d142015-04-22 13:56:20 -07002265 uint32_t method_idx, mirror::Object* this_object, Thread* self, ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07002266 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +01002267 return artInvokeCommon<kInterface, true>(method_idx, this_object, self, sp);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002268}
2269
Andreas Gampec200a4a2014-06-16 18:39:09 -07002270extern "C" TwoWordReturn artInvokeDirectTrampolineWithAccessCheck(
Mathieu Chartiere401d142015-04-22 13:56:20 -07002271 uint32_t method_idx, mirror::Object* this_object, Thread* self, ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07002272 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +01002273 return artInvokeCommon<kDirect, true>(method_idx, this_object, self, sp);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002274}
2275
Andreas Gampec200a4a2014-06-16 18:39:09 -07002276extern "C" TwoWordReturn artInvokeStaticTrampolineWithAccessCheck(
Mathieu Chartieref41db72016-10-25 15:08:01 -07002277 uint32_t method_idx,
2278 mirror::Object* this_object ATTRIBUTE_UNUSED,
2279 Thread* self,
2280 ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) {
2281 // For static, this_object is not required and may be random garbage. Don't pass it down so that
2282 // it doesn't cause ObjPtr alignment failure check.
2283 return artInvokeCommon<kStatic, true>(method_idx, nullptr, self, sp);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002284}
2285
Andreas Gampec200a4a2014-06-16 18:39:09 -07002286extern "C" TwoWordReturn artInvokeSuperTrampolineWithAccessCheck(
Mathieu Chartiere401d142015-04-22 13:56:20 -07002287 uint32_t method_idx, mirror::Object* this_object, Thread* self, ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07002288 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +01002289 return artInvokeCommon<kSuper, true>(method_idx, this_object, self, sp);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002290}
2291
Andreas Gampec200a4a2014-06-16 18:39:09 -07002292extern "C" TwoWordReturn artInvokeVirtualTrampolineWithAccessCheck(
Mathieu Chartiere401d142015-04-22 13:56:20 -07002293 uint32_t method_idx, mirror::Object* this_object, Thread* self, ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07002294 REQUIRES_SHARED(Locks::mutator_lock_) {
Nicolas Geoffray7ea6a172015-05-19 18:58:54 +01002295 return artInvokeCommon<kVirtual, true>(method_idx, this_object, self, sp);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002296}
2297
Jeff Hao5667f562017-02-27 19:32:01 -08002298// Determine target of interface dispatch. The interface method and this object are known non-null.
2299// The interface method is the method returned by the dex cache in the conflict trampoline.
2300extern "C" TwoWordReturn artInvokeInterfaceTrampoline(ArtMethod* interface_method,
Mathieu Chartieref41db72016-10-25 15:08:01 -07002301 mirror::Object* raw_this_object,
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002302 Thread* self,
2303 ArtMethod** sp)
Andreas Gampebdf7f1c2016-08-30 16:38:47 -07002304 REQUIRES_SHARED(Locks::mutator_lock_) {
Ian Rogers1d8cdbc2014-09-22 22:51:09 -07002305 ScopedQuickEntrypointChecks sqec(self);
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002306
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002307 Runtime* runtime = Runtime::Current();
2308 bool resolve_method = ((interface_method == nullptr) || interface_method->IsRuntimeMethod());
2309 if (UNLIKELY(resolve_method)) {
Vladimir Marko07bfbac2017-07-06 14:55:02 +01002310 // The interface method is unresolved, so resolve it in the dex file of the caller.
Jeff Hao5667f562017-02-27 19:32:01 -08002311 // Fetch the dex_method_idx of the target interface method from the caller.
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002312 StackHandleScope<1> hs(self);
2313 Handle<mirror::Object> this_object = hs.NewHandle(raw_this_object);
2314 ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp);
Jeff Hao5667f562017-02-27 19:32:01 -08002315 uint32_t dex_method_idx;
2316 uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp);
Mathieu Chartier808c7a52017-12-15 11:19:33 -08002317 const Instruction& instr = caller_method->DexInstructions().InstructionAt(dex_pc);
Vladimir Markod7559b72017-09-28 13:50:37 +01002318 Instruction::Code instr_code = instr.Opcode();
Jeff Hao5667f562017-02-27 19:32:01 -08002319 DCHECK(instr_code == Instruction::INVOKE_INTERFACE ||
2320 instr_code == Instruction::INVOKE_INTERFACE_RANGE)
Vladimir Markod7559b72017-09-28 13:50:37 +01002321 << "Unexpected call into interface trampoline: " << instr.DumpString(nullptr);
Jeff Hao5667f562017-02-27 19:32:01 -08002322 if (instr_code == Instruction::INVOKE_INTERFACE) {
Vladimir Markod7559b72017-09-28 13:50:37 +01002323 dex_method_idx = instr.VRegB_35c();
Jeff Hao5667f562017-02-27 19:32:01 -08002324 } else {
2325 DCHECK_EQ(instr_code, Instruction::INVOKE_INTERFACE_RANGE);
Vladimir Markod7559b72017-09-28 13:50:37 +01002326 dex_method_idx = instr.VRegB_3rc();
Jeff Hao5667f562017-02-27 19:32:01 -08002327 }
2328
Vladimir Marko7e097372018-11-28 16:40:59 +00002329 const DexFile& dex_file = *caller_method->GetDexFile();
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002330 uint32_t shorty_len;
Vladimir Marko302f69c2017-07-25 15:27:15 +01002331 const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(dex_method_idx),
2332 &shorty_len);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002333 {
Vladimir Marko302f69c2017-07-25 15:27:15 +01002334 // Remember the args in case a GC happens in ClassLinker::ResolveMethod().
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002335 ScopedObjectAccessUnchecked soa(self->GetJniEnv());
2336 RememberForGcArgumentVisitor visitor(sp, false, shorty, shorty_len, &soa);
2337 visitor.VisitArguments();
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002338 ClassLinker* class_linker = runtime->GetClassLinker();
Vladimir Marko302f69c2017-07-25 15:27:15 +01002339 interface_method = class_linker->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>(
2340 self, dex_method_idx, caller_method, kInterface);
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002341 visitor.FixupReferences();
2342 }
2343
Vladimir Marko302f69c2017-07-25 15:27:15 +01002344 if (UNLIKELY(interface_method == nullptr)) {
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002345 CHECK(self->IsExceptionPending());
Andreas Gamped58342c2014-06-05 14:18:08 -07002346 return GetTwoWordFailureValue(); // Failure.
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002347 }
Nicolas Geoffray8d34a182020-09-16 09:46:58 +01002348 MaybeUpdateBssMethodEntry(interface_method, MethodReference(&dex_file, dex_method_idx));
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002349
2350 // Refresh `raw_this_object` which may have changed after resolution.
2351 raw_this_object = this_object.Get();
Vladimir Marko302f69c2017-07-25 15:27:15 +01002352 }
2353
Nicolas Geoffray29253112020-02-17 09:40:14 +00002354 // The compiler and interpreter make sure the conflict trampoline is never
2355 // called on a method that resolves to j.l.Object.
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002356 DCHECK(!interface_method->GetDeclaringClass()->IsObjectClass());
2357 DCHECK(interface_method->GetDeclaringClass()->IsInterface());
Vladimir Marko302f69c2017-07-25 15:27:15 +01002358 DCHECK(!interface_method->IsRuntimeMethod());
Nicolas Geoffrayd5a86952021-01-19 10:35:54 +00002359 DCHECK(!interface_method->IsCopied());
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002360
2361 ObjPtr<mirror::Object> obj_this = raw_this_object;
2362 ObjPtr<mirror::Class> cls = obj_this->GetClass();
David Srbeckye36e7f22018-11-14 14:21:23 +00002363 uint32_t imt_index = interface_method->GetImtIndex();
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002364 ImTable* imt = cls->GetImt(kRuntimePointerSize);
Vladimir Marko302f69c2017-07-25 15:27:15 +01002365 ArtMethod* conflict_method = imt->Get(imt_index, kRuntimePointerSize);
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002366 DCHECK(conflict_method->IsRuntimeMethod());
2367
2368 if (UNLIKELY(resolve_method)) {
2369 // Now that we know the interface method, look it up in the conflict table.
Vladimir Marko302f69c2017-07-25 15:27:15 +01002370 ImtConflictTable* current_table = conflict_method->GetImtConflictTable(kRuntimePointerSize);
2371 DCHECK(current_table != nullptr);
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002372 ArtMethod* method = current_table->Lookup(interface_method, kRuntimePointerSize);
2373 if (method != nullptr) {
2374 return GetTwoWordSuccessValue(
2375 reinterpret_cast<uintptr_t>(method->GetEntryPointFromQuickCompiledCode()),
2376 reinterpret_cast<uintptr_t>(method));
Vladimir Marko302f69c2017-07-25 15:27:15 +01002377 }
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002378 // Interface method is not in the conflict table. Continue looking up in the
2379 // iftable.
Vladimir Marko302f69c2017-07-25 15:27:15 +01002380 }
2381
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002382 ArtMethod* method = cls->FindVirtualMethodForInterface(interface_method, kRuntimePointerSize);
Vladimir Marko302f69c2017-07-25 15:27:15 +01002383 if (UNLIKELY(method == nullptr)) {
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002384 ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp);
Vladimir Marko302f69c2017-07-25 15:27:15 +01002385 ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch(
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002386 interface_method, obj_this.Ptr(), caller_method);
2387 return GetTwoWordFailureValue();
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002388 }
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002389
2390 // We arrive here if we have found an implementation, and it is not in the ImtConflictTable.
2391 // We create a new table with the new pair { interface_method, method }.
Nicolas Geoffrayd8fd5992020-02-19 22:25:19 +00002392
2393 // Classes in the boot image should never need to update conflict methods in
2394 // their IMT.
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002395 CHECK(!runtime->GetHeap()->ObjectIsInBootImageSpace(cls.Ptr())) << cls->PrettyClass();
2396 ArtMethod* new_conflict_method = runtime->GetClassLinker()->AddMethodToConflictTable(
2397 cls.Ptr(),
Vladimir Marko302f69c2017-07-25 15:27:15 +01002398 conflict_method,
2399 interface_method,
Nicolas Geoffray47213e42020-12-30 15:12:00 +00002400 method);
Vladimir Marko302f69c2017-07-25 15:27:15 +01002401 if (new_conflict_method != conflict_method) {
2402 // Update the IMT if we create a new conflict method. No fence needed here, as the
2403 // data is consistent.
2404 imt->Set(imt_index,
2405 new_conflict_method,
2406 kRuntimePointerSize);
Nicolas Geoffray796d6302016-03-13 22:22:31 +00002407 }
2408
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002409 const void* code = method->GetEntryPointFromQuickCompiledCode();
2410
2411 // When we return, the caller will branch to this address, so it had better not be 0!
David Sehr709b0702016-10-13 09:12:37 -07002412 DCHECK(code != nullptr) << "Code was null in method: " << method->PrettyMethod()
Andreas Gampec200a4a2014-06-16 18:39:09 -07002413 << " location: " << method->GetDexFile()->GetLocation();
Andreas Gampe51f76352014-05-21 08:28:48 -07002414
Andreas Gamped58342c2014-06-05 14:18:08 -07002415 return GetTwoWordSuccessValue(reinterpret_cast<uintptr_t>(code),
2416 reinterpret_cast<uintptr_t>(method));
Mathieu Chartier5f3ded42014-04-03 15:25:30 -07002417}
2418
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002419// Returns uint64_t representing raw bits from JValue.
2420extern "C" uint64_t artInvokePolymorphic(mirror::Object* raw_receiver, Thread* self, ArtMethod** sp)
Orion Hodsonac141392017-01-13 11:53:47 +00002421 REQUIRES_SHARED(Locks::mutator_lock_) {
2422 ScopedQuickEntrypointChecks sqec(self);
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002423 DCHECK(raw_receiver != nullptr);
Andreas Gampe8228cdf2017-05-30 15:03:54 -07002424 DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs));
Orion Hodsonac141392017-01-13 11:53:47 +00002425
2426 // Start new JNI local reference state
2427 JNIEnvExt* env = self->GetJniEnv();
2428 ScopedObjectAccessUnchecked soa(env);
2429 ScopedJniEnvLocalRefState env_state(env);
2430 const char* old_cause = self->StartAssertNoThreadSuspension("Making stack arguments safe.");
2431
2432 // From the instruction, get the |callsite_shorty| and expose arguments on the stack to the GC.
2433 ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp);
2434 uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp);
Mathieu Chartier73f21d42018-01-02 14:26:50 -08002435 const Instruction& inst = caller_method->DexInstructions().InstructionAt(dex_pc);
Vladimir Markod7559b72017-09-28 13:50:37 +01002436 DCHECK(inst.Opcode() == Instruction::INVOKE_POLYMORPHIC ||
2437 inst.Opcode() == Instruction::INVOKE_POLYMORPHIC_RANGE);
Orion Hodson06d10a72018-05-14 08:53:38 +01002438 const dex::ProtoIndex proto_idx(inst.VRegH());
Vladimir Marko666ee3d2017-12-11 18:37:36 +00002439 const char* shorty = caller_method->GetDexFile()->GetShorty(proto_idx);
Orion Hodsonac141392017-01-13 11:53:47 +00002440 const size_t shorty_length = strlen(shorty);
2441 static const bool kMethodIsStatic = false; // invoke() and invokeExact() are not static.
2442 RememberForGcArgumentVisitor gc_visitor(sp, kMethodIsStatic, shorty, shorty_length, &soa);
Orion Hodsonfea84dd2017-01-16 13:52:20 +00002443 gc_visitor.VisitArguments();
Orion Hodsonac141392017-01-13 11:53:47 +00002444
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002445 // Wrap raw_receiver in a Handle for safety.
2446 StackHandleScope<3> hs(self);
2447 Handle<mirror::Object> receiver_handle(hs.NewHandle(raw_receiver));
2448 raw_receiver = nullptr;
Orion Hodsonac141392017-01-13 11:53:47 +00002449 self->EndAssertNoThreadSuspension(old_cause);
2450
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002451 // Resolve method.
Orion Hodsonac141392017-01-13 11:53:47 +00002452 ClassLinker* linker = Runtime::Current()->GetClassLinker();
Vladimir Markoba118822017-06-12 15:41:56 +01002453 ArtMethod* resolved_method = linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>(
Vladimir Markod7559b72017-09-28 13:50:37 +01002454 self, inst.VRegB(), caller_method, kVirtual);
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002455
Orion Hodsone7732be2017-10-11 14:35:20 +01002456 Handle<mirror::MethodType> method_type(
2457 hs.NewHandle(linker->ResolveMethodType(self, proto_idx, caller_method)));
Orion Hodsonac141392017-01-13 11:53:47 +00002458 if (UNLIKELY(method_type.IsNull())) {
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002459 // This implies we couldn't resolve one or more types in this method handle.
Orion Hodsonac141392017-01-13 11:53:47 +00002460 CHECK(self->IsExceptionPending());
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002461 return 0UL;
Orion Hodsonac141392017-01-13 11:53:47 +00002462 }
2463
Vladimir Markod7559b72017-09-28 13:50:37 +01002464 DCHECK_EQ(ArtMethod::NumArgRegisters(shorty) + 1u, (uint32_t)inst.VRegA());
Orion Hodsonac141392017-01-13 11:53:47 +00002465 DCHECK_EQ(resolved_method->IsStatic(), kMethodIsStatic);
2466
2467 // Fix references before constructing the shadow frame.
2468 gc_visitor.FixupReferences();
2469
2470 // Construct shadow frame placing arguments consecutively from |first_arg|.
Vladimir Markod7559b72017-09-28 13:50:37 +01002471 const bool is_range = (inst.Opcode() == Instruction::INVOKE_POLYMORPHIC_RANGE);
2472 const size_t num_vregs = is_range ? inst.VRegA_4rcc() : inst.VRegA_45cc();
Orion Hodsonac141392017-01-13 11:53:47 +00002473 const size_t first_arg = 0;
2474 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe98ea9d92018-10-19 14:06:15 -07002475 CREATE_SHADOW_FRAME(num_vregs, /* link= */ nullptr, resolved_method, dex_pc);
Orion Hodsonac141392017-01-13 11:53:47 +00002476 ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get();
2477 ScopedStackedShadowFramePusher
2478 frame_pusher(self, shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction);
2479 BuildQuickShadowFrameVisitor shadow_frame_builder(sp,
2480 kMethodIsStatic,
2481 shorty,
2482 strlen(shorty),
2483 shadow_frame,
2484 first_arg);
2485 shadow_frame_builder.VisitArguments();
2486
2487 // Push a transition back into managed code onto the linked list in thread.
2488 ManagedStack fragment;
2489 self->PushManagedStackFragment(&fragment);
2490
2491 // Call DoInvokePolymorphic with |is_range| = true, as shadow frame has argument registers in
2492 // consecutive order.
Orion Hodson960d4f72017-11-10 15:32:38 +00002493 RangeInstructionOperands operands(first_arg + 1, num_vregs - 1);
Orion Hodson537a4fe2018-05-15 13:57:58 +01002494 Intrinsics intrinsic = static_cast<Intrinsics>(resolved_method->GetIntrinsic());
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002495 JValue result;
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002496 bool success = false;
Vladimir Markoc7aa87e2018-05-24 15:19:52 +01002497 if (resolved_method->GetDeclaringClass() == GetClassRoot<mirror::MethodHandle>(linker)) {
Orion Hodson537a4fe2018-05-15 13:57:58 +01002498 Handle<mirror::MethodHandle> method_handle(hs.NewHandle(
Vladimir Markod7e9bbf2019-03-28 13:18:57 +00002499 ObjPtr<mirror::MethodHandle>::DownCast(receiver_handle.Get())));
Orion Hodson537a4fe2018-05-15 13:57:58 +01002500 if (intrinsic == Intrinsics::kMethodHandleInvokeExact) {
2501 success = MethodHandleInvokeExact(self,
2502 *shadow_frame,
2503 method_handle,
2504 method_type,
2505 &operands,
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002506 &result);
Orion Hodson537a4fe2018-05-15 13:57:58 +01002507 } else {
2508 DCHECK_EQ(static_cast<uint32_t>(intrinsic),
2509 static_cast<uint32_t>(Intrinsics::kMethodHandleInvoke));
2510 success = MethodHandleInvoke(self,
2511 *shadow_frame,
2512 method_handle,
2513 method_type,
2514 &operands,
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002515 &result);
Orion Hodson537a4fe2018-05-15 13:57:58 +01002516 }
2517 } else {
Vladimir Markoc7aa87e2018-05-24 15:19:52 +01002518 DCHECK_EQ(GetClassRoot<mirror::VarHandle>(linker), resolved_method->GetDeclaringClass());
Orion Hodson537a4fe2018-05-15 13:57:58 +01002519 Handle<mirror::VarHandle> var_handle(hs.NewHandle(
Vladimir Markod7e9bbf2019-03-28 13:18:57 +00002520 ObjPtr<mirror::VarHandle>::DownCast(receiver_handle.Get())));
Orion Hodson537a4fe2018-05-15 13:57:58 +01002521 mirror::VarHandle::AccessMode access_mode =
2522 mirror::VarHandle::GetAccessModeByIntrinsic(intrinsic);
2523 success = VarHandleInvokeAccessor(self,
Orion Hodson960d4f72017-11-10 15:32:38 +00002524 *shadow_frame,
Orion Hodson537a4fe2018-05-15 13:57:58 +01002525 var_handle,
Orion Hodson960d4f72017-11-10 15:32:38 +00002526 method_type,
Orion Hodson537a4fe2018-05-15 13:57:58 +01002527 access_mode,
Orion Hodson960d4f72017-11-10 15:32:38 +00002528 &operands,
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002529 &result);
Orion Hodsonac141392017-01-13 11:53:47 +00002530 }
Orion Hodson537a4fe2018-05-15 13:57:58 +01002531
Orion Hodson43f0cdb2017-10-10 14:47:32 +01002532 DCHECK(success || self->IsExceptionPending());
Orion Hodsonac141392017-01-13 11:53:47 +00002533
2534 // Pop transition record.
2535 self->PopManagedStackFragment(fragment);
2536
Orion Hodsoncd260eb2018-06-06 09:04:17 +01002537 return result.GetJ();
Orion Hodsonac141392017-01-13 11:53:47 +00002538}
2539
Orion Hodson4c8e12e2018-05-18 08:33:20 +01002540// Returns uint64_t representing raw bits from JValue.
2541extern "C" uint64_t artInvokeCustom(uint32_t call_site_idx, Thread* self, ArtMethod** sp)
2542 REQUIRES_SHARED(Locks::mutator_lock_) {
2543 ScopedQuickEntrypointChecks sqec(self);
2544 DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs));
2545
2546 // invoke-custom is effectively a static call (no receiver).
2547 static constexpr bool kMethodIsStatic = true;
2548
2549 // Start new JNI local reference state
2550 JNIEnvExt* env = self->GetJniEnv();
2551 ScopedObjectAccessUnchecked soa(env);
2552 ScopedJniEnvLocalRefState env_state(env);
2553
2554 const char* old_cause = self->StartAssertNoThreadSuspension("Making stack arguments safe.");
2555
2556 // From the instruction, get the |callsite_shorty| and expose arguments on the stack to the GC.
2557 ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp);
2558 uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp);
2559 const DexFile* dex_file = caller_method->GetDexFile();
2560 const dex::ProtoIndex proto_idx(dex_file->GetProtoIndexForCallSite(call_site_idx));
2561 const char* shorty = caller_method->GetDexFile()->GetShorty(proto_idx);
2562 const uint32_t shorty_len = strlen(shorty);
2563
2564 // Construct the shadow frame placing arguments consecutively from |first_arg|.
2565 const size_t first_arg = 0;
2566 const size_t num_vregs = ArtMethod::NumArgRegisters(shorty);
2567 ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr =
Andreas Gampe98ea9d92018-10-19 14:06:15 -07002568 CREATE_SHADOW_FRAME(num_vregs, /* link= */ nullptr, caller_method, dex_pc);
Orion Hodson4c8e12e2018-05-18 08:33:20 +01002569 ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get();
2570 ScopedStackedShadowFramePusher
2571 frame_pusher(self, shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction);
2572 BuildQuickShadowFrameVisitor shadow_frame_builder(sp,
2573 kMethodIsStatic,
2574 shorty,
2575 shorty_len,
2576 shadow_frame,
2577 first_arg);
2578 shadow_frame_builder.VisitArguments();
2579
2580 // Push a transition back into managed code onto the linked list in thread.
2581 ManagedStack fragment;
2582 self->PushManagedStackFragment(&fragment);
2583 self->EndAssertNoThreadSuspension(old_cause);
2584
2585 // Perform the invoke-custom operation.
2586 RangeInstructionOperands operands(first_arg, num_vregs);
2587 JValue result;
2588 bool success =
2589 interpreter::DoInvokeCustom(self, *shadow_frame, call_site_idx, &operands, &result);
2590 DCHECK(success || self->IsExceptionPending());
2591
2592 // Pop transition record.
2593 self->PopManagedStackFragment(fragment);
2594
2595 return result.GetJ();
2596}
2597
Mythri Alle5097f832021-11-02 14:52:30 +00002598extern "C" void artMethodEntryHook(ArtMethod* method, Thread* self, ArtMethod** sp ATTRIBUTE_UNUSED)
2599 REQUIRES_SHARED(Locks::mutator_lock_) {
2600 instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation();
2601 instr->MethodEnterEvent(self, method);
2602 if (instr->IsDeoptimized(method)) {
2603 // Instrumentation can request deoptimizing only a particular method (for
2604 // ex: when there are break points on the method). In such cases deoptimize
2605 // only this method. FullFrame deoptimizations are handled on method exits.
2606 artDeoptimizeFromCompiledCode(DeoptimizationKind::kDebugging, self);
2607 }
2608}
2609
2610extern "C" int artMethodExitHook(Thread* self,
2611 ArtMethod* method,
2612 uint64_t* gpr_result,
2613 uint64_t* fpr_result)
2614 REQUIRES_SHARED(Locks::mutator_lock_) {
2615 DCHECK_EQ(reinterpret_cast<uintptr_t>(self), reinterpret_cast<uintptr_t>(Thread::Current()));
2616 CHECK(gpr_result != nullptr);
2617 CHECK(fpr_result != nullptr);
2618 // Instrumentation exit stub must not be entered with a pending exception.
2619 CHECK(!self->IsExceptionPending())
2620 << "Enter instrumentation exit stub with pending exception " << self->GetException()->Dump();
2621
2622 instrumentation::Instrumentation* instr = Runtime::Current()->GetInstrumentation();
Mythri Alle9575c122021-11-12 12:04:41 +00002623 DCHECK(instr->AreExitStubsInstalled());
Mythri Alle5097f832021-11-02 14:52:30 +00002624 bool is_ref;
2625 JValue return_value = instr->GetReturnValue(self, method, &is_ref, gpr_result, fpr_result);
2626 bool deoptimize = false;
2627 {
2628 StackHandleScope<1> hs(self);
2629 MutableHandle<mirror::Object> res(hs.NewHandle<mirror::Object>(nullptr));
2630 if (is_ref) {
2631 // Take a handle to the return value so we won't lose it if we suspend.
2632 res.Assign(return_value.GetL());
2633 }
2634 DCHECK(!method->IsRuntimeMethod());
Mythri Alle5097f832021-11-02 14:52:30 +00002635
2636 // Deoptimize if the caller needs to continue execution in the interpreter. Do nothing if we get
2637 // back to an upcall.
2638 NthCallerVisitor visitor(self, 1, true);
2639 visitor.WalkStack(true);
2640 deoptimize = instr->ShouldDeoptimizeMethod(self, visitor);
2641
Mythri Alle2a0ad752021-12-02 17:45:50 +00002642 // If we need a deoptimization MethodExitEvent will be called by the interpreter when it
2643 // re-executes the return instruction.
2644 if (!deoptimize) {
2645 instr->MethodExitEvent(self,
2646 method,
2647 /* frame= */ {},
2648 return_value);
2649 }
2650
Mythri Alle5097f832021-11-02 14:52:30 +00002651 if (is_ref) {
2652 // Restore the return value if it's a reference since it might have moved.
2653 *reinterpret_cast<mirror::Object**>(gpr_result) = res.Get();
2654 }
2655 }
2656
2657 if (self->IsExceptionPending() || self->ObserveAsyncException()) {
2658 return 1;
2659 }
2660
2661 if (deoptimize) {
2662 DeoptimizationMethodType deopt_method_type = instr->GetDeoptimizationMethodType(method);
2663 self->PushDeoptimizationContext(return_value, is_ref, nullptr, false, deopt_method_type);
2664 artDeoptimize(self);
2665 UNREACHABLE();
2666 }
2667
2668 return 0;
2669}
2670
Ian Rogers848871b2013-08-05 10:56:33 -07002671} // namespace art