Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1 | /* |
| 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 Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 17 | #include "art_method-inl.h" |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 18 | #include "base/callee_save_type.h" |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 19 | #include "base/enums.h" |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 20 | #include "callee_save_frame.h" |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 21 | #include "common_throws.h" |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame^] | 22 | #include "class_root.h" |
Vladimir Marko | 606adb3 | 2018-04-05 14:49:24 +0100 | [diff] [blame] | 23 | #include "debug_print.h" |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 24 | #include "debugger.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 25 | #include "dex/dex_file-inl.h" |
| 26 | #include "dex/dex_file_types.h" |
| 27 | #include "dex/dex_instruction-inl.h" |
David Sehr | 312f3b2 | 2018-03-19 08:39:26 -0700 | [diff] [blame] | 28 | #include "dex/method_reference.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 29 | #include "entrypoints/entrypoint_utils-inl.h" |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 30 | #include "entrypoints/quick/callee_save_frame.h" |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 31 | #include "entrypoints/runtime_asm_entrypoints.h" |
Ian Rogers | 83883d7 | 2013-10-21 21:07:24 -0700 | [diff] [blame] | 32 | #include "gc/accounting/card_table-inl.h" |
Andreas Gampe | 75a7db6 | 2016-09-26 12:04:26 -0700 | [diff] [blame] | 33 | #include "imt_conflict_table.h" |
| 34 | #include "imtable-inl.h" |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 35 | #include "index_bss_mapping.h" |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 36 | #include "instrumentation.h" |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 37 | #include "interpreter/interpreter.h" |
Vladimir Marko | 6ec2a1b | 2018-05-22 15:33:48 +0100 | [diff] [blame] | 38 | #include "interpreter/shadow_frame-inl.h" |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 39 | #include "jit/jit.h" |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 40 | #include "linear_alloc.h" |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 41 | #include "method_handles.h" |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 42 | #include "mirror/class-inl.h" |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 43 | #include "mirror/dex_cache-inl.h" |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 44 | #include "mirror/method.h" |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 45 | #include "mirror/method_handle_impl.h" |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 46 | #include "mirror/object-inl.h" |
| 47 | #include "mirror/object_array-inl.h" |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 48 | #include "mirror/var_handle.h" |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 49 | #include "oat_file.h" |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 50 | #include "oat_quick_method_header.h" |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 51 | #include "quick_exception_handler.h" |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 52 | #include "runtime.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 53 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 54 | #include "stack.h" |
Andreas Gampe | 513061a | 2017-06-01 09:17:34 -0700 | [diff] [blame] | 55 | #include "thread-inl.h" |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 56 | #include "var_handles.h" |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 57 | #include "well_known_classes.h" |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 58 | |
| 59 | namespace art { |
| 60 | |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 61 | // Visits the arguments as saved to the stack by a CalleeSaveType::kRefAndArgs callee save frame. |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 62 | class QuickArgumentVisitor { |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 63 | // Number of bytes for each out register in the caller method's frame. |
| 64 | static constexpr size_t kBytesStackArgLocation = 4; |
Alexei Zavjalov | 41c507a | 2014-05-15 16:02:46 +0700 | [diff] [blame] | 65 | // Frame size in bytes of a callee-save frame for RefsAndArgs. |
| 66 | static constexpr size_t kQuickCalleeSaveFrame_RefAndArgs_FrameSize = |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 67 | RuntimeCalleeSaveFrame::GetFrameSize(CalleeSaveType::kSaveRefsAndArgs); |
| 68 | // Offset of first GPR arg. |
| 69 | static constexpr size_t kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset = |
| 70 | RuntimeCalleeSaveFrame::GetGpr1Offset(CalleeSaveType::kSaveRefsAndArgs); |
| 71 | // Offset of first FPR arg. |
| 72 | static constexpr size_t kQuickCalleeSaveFrame_RefAndArgs_Fpr1Offset = |
| 73 | RuntimeCalleeSaveFrame::GetFpr1Offset(CalleeSaveType::kSaveRefsAndArgs); |
| 74 | // Offset of return address. |
| 75 | static constexpr size_t kQuickCalleeSaveFrame_RefAndArgs_ReturnPcOffset = |
| 76 | RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveRefsAndArgs); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 77 | #if defined(__arm__) |
| 78 | // The callee save frame is pointed to by SP. |
| 79 | // | argN | | |
| 80 | // | ... | | |
| 81 | // | arg4 | | |
| 82 | // | arg3 spill | | Caller's frame |
| 83 | // | arg2 spill | | |
| 84 | // | arg1 spill | | |
| 85 | // | Method* | --- |
| 86 | // | LR | |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 87 | // | ... | 4x6 bytes callee saves |
| 88 | // | R3 | |
| 89 | // | R2 | |
| 90 | // | R1 | |
| 91 | // | S15 | |
| 92 | // | : | |
| 93 | // | S0 | |
| 94 | // | | 4x2 bytes padding |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 95 | // | Method* | <- sp |
Andreas Gampe | 217d6d3 | 2017-09-18 12:48:20 -0700 | [diff] [blame] | 96 | static constexpr bool kSplitPairAcrossRegisterAndStack = false; |
| 97 | static constexpr bool kAlignPairRegister = true; |
| 98 | static constexpr bool kQuickSoftFloatAbi = false; |
| 99 | static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = true; |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 100 | static constexpr bool kQuickSkipOddFpRegisters = false; |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 101 | static constexpr size_t kNumQuickGprArgs = 3; |
Andreas Gampe | 217d6d3 | 2017-09-18 12:48:20 -0700 | [diff] [blame] | 102 | static constexpr size_t kNumQuickFprArgs = 16; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 103 | static constexpr bool kGprFprLockstep = false; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 104 | static size_t GprIndexToGprOffset(uint32_t gpr_index) { |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 105 | return gpr_index * GetBytesPerGprSpillLocation(kRuntimeISA); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 106 | } |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 107 | #elif defined(__aarch64__) |
| 108 | // The callee save frame is pointed to by SP. |
| 109 | // | argN | | |
| 110 | // | ... | | |
| 111 | // | arg4 | | |
| 112 | // | arg3 spill | | Caller's frame |
| 113 | // | arg2 spill | | |
| 114 | // | arg1 spill | | |
| 115 | // | Method* | --- |
| 116 | // | LR | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 117 | // | X29 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 118 | // | : | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 119 | // | X20 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 120 | // | X7 | |
| 121 | // | : | |
| 122 | // | X1 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 123 | // | D7 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 124 | // | : | |
| 125 | // | D0 | |
| 126 | // | | padding |
| 127 | // | Method* | <- sp |
Mark Mendell | 3e6a3bf | 2015-01-19 14:09:22 -0500 | [diff] [blame] | 128 | static constexpr bool kSplitPairAcrossRegisterAndStack = false; |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 129 | static constexpr bool kAlignPairRegister = false; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 130 | static constexpr bool kQuickSoftFloatAbi = false; // This is a hard float ABI. |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 131 | static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = false; |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 132 | static constexpr bool kQuickSkipOddFpRegisters = false; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 133 | static constexpr size_t kNumQuickGprArgs = 7; // 7 arguments passed in GPRs. |
| 134 | static constexpr size_t kNumQuickFprArgs = 8; // 8 arguments passed in FPRs. |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 135 | static constexpr bool kGprFprLockstep = false; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 136 | static size_t GprIndexToGprOffset(uint32_t gpr_index) { |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 137 | return gpr_index * GetBytesPerGprSpillLocation(kRuntimeISA); |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 138 | } |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 139 | #elif defined(__mips__) && !defined(__LP64__) |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 140 | // The callee save frame is pointed to by SP. |
| 141 | // | argN | | |
| 142 | // | ... | | |
| 143 | // | arg4 | | |
| 144 | // | arg3 spill | | Caller's frame |
| 145 | // | arg2 spill | | |
| 146 | // | arg1 spill | | |
| 147 | // | Method* | --- |
| 148 | // | RA | |
| 149 | // | ... | callee saves |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 150 | // | T1 | arg5 |
| 151 | // | T0 | arg4 |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 152 | // | A3 | arg3 |
| 153 | // | A2 | arg2 |
| 154 | // | A1 | arg1 |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 155 | // | F19 | |
| 156 | // | F18 | f_arg5 |
| 157 | // | F17 | |
| 158 | // | F16 | f_arg4 |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 159 | // | F15 | |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 160 | // | F14 | f_arg3 |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 161 | // | F13 | |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 162 | // | F12 | f_arg2 |
| 163 | // | F11 | |
| 164 | // | F10 | f_arg1 |
| 165 | // | F9 | |
| 166 | // | F8 | f_arg0 |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 167 | // | | padding |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 168 | // | A0/Method* | <- sp |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 169 | static constexpr bool kSplitPairAcrossRegisterAndStack = false; |
| 170 | static constexpr bool kAlignPairRegister = true; |
| 171 | static constexpr bool kQuickSoftFloatAbi = false; |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 172 | static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = false; |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 173 | static constexpr bool kQuickSkipOddFpRegisters = true; |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 174 | static constexpr size_t kNumQuickGprArgs = 5; // 5 arguments passed in GPRs. |
| 175 | static constexpr size_t kNumQuickFprArgs = 12; // 6 arguments passed in FPRs. Floats can be |
| 176 | // passed only in even numbered registers and each |
| 177 | // double occupies two registers. |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 178 | static constexpr bool kGprFprLockstep = false; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 179 | static size_t GprIndexToGprOffset(uint32_t gpr_index) { |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 180 | return gpr_index * GetBytesPerGprSpillLocation(kRuntimeISA); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 181 | } |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 182 | #elif defined(__mips__) && defined(__LP64__) |
| 183 | // The callee save frame is pointed to by SP. |
| 184 | // | argN | | |
| 185 | // | ... | | |
| 186 | // | arg4 | | |
| 187 | // | arg3 spill | | Caller's frame |
| 188 | // | arg2 spill | | |
| 189 | // | arg1 spill | | |
| 190 | // | Method* | --- |
| 191 | // | RA | |
| 192 | // | ... | callee saves |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 193 | // | A7 | arg7 |
| 194 | // | A6 | arg6 |
| 195 | // | A5 | arg5 |
| 196 | // | A4 | arg4 |
| 197 | // | A3 | arg3 |
| 198 | // | A2 | arg2 |
| 199 | // | A1 | arg1 |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 200 | // | F19 | f_arg7 |
| 201 | // | F18 | f_arg6 |
| 202 | // | F17 | f_arg5 |
| 203 | // | F16 | f_arg4 |
| 204 | // | F15 | f_arg3 |
| 205 | // | F14 | f_arg2 |
| 206 | // | F13 | f_arg1 |
| 207 | // | F12 | f_arg0 |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 208 | // | | padding |
| 209 | // | A0/Method* | <- sp |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 210 | // NOTE: for Mip64, when A0 is skipped, F12 is also skipped. |
Douglas Leung | d18e083 | 2015-02-09 15:22:26 -0800 | [diff] [blame] | 211 | static constexpr bool kSplitPairAcrossRegisterAndStack = false; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 212 | static constexpr bool kAlignPairRegister = false; |
| 213 | static constexpr bool kQuickSoftFloatAbi = false; |
| 214 | static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = false; |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 215 | static constexpr bool kQuickSkipOddFpRegisters = false; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 216 | static constexpr size_t kNumQuickGprArgs = 7; // 7 arguments passed in GPRs. |
| 217 | static constexpr size_t kNumQuickFprArgs = 7; // 7 arguments passed in FPRs. |
| 218 | static constexpr bool kGprFprLockstep = true; |
| 219 | |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 220 | static size_t GprIndexToGprOffset(uint32_t gpr_index) { |
| 221 | return gpr_index * GetBytesPerGprSpillLocation(kRuntimeISA); |
| 222 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 223 | #elif defined(__i386__) |
| 224 | // The callee save frame is pointed to by SP. |
| 225 | // | argN | | |
| 226 | // | ... | | |
| 227 | // | arg4 | | |
| 228 | // | arg3 spill | | Caller's frame |
| 229 | // | arg2 spill | | |
| 230 | // | arg1 spill | | |
| 231 | // | Method* | --- |
| 232 | // | Return | |
| 233 | // | EBP,ESI,EDI | callee saves |
| 234 | // | EBX | arg3 |
| 235 | // | EDX | arg2 |
| 236 | // | ECX | arg1 |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 237 | // | XMM3 | float arg 4 |
| 238 | // | XMM2 | float arg 3 |
| 239 | // | XMM1 | float arg 2 |
| 240 | // | XMM0 | float arg 1 |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 241 | // | EAX/Method* | <- sp |
Mark Mendell | 3e6a3bf | 2015-01-19 14:09:22 -0500 | [diff] [blame] | 242 | static constexpr bool kSplitPairAcrossRegisterAndStack = false; |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 243 | static constexpr bool kAlignPairRegister = false; |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 244 | static constexpr bool kQuickSoftFloatAbi = false; // This is a hard float ABI. |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 245 | static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = false; |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 246 | static constexpr bool kQuickSkipOddFpRegisters = false; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 247 | static constexpr size_t kNumQuickGprArgs = 3; // 3 arguments passed in GPRs. |
Mark P Mendell | 966c3ae | 2015-01-27 15:45:27 +0000 | [diff] [blame] | 248 | static constexpr size_t kNumQuickFprArgs = 4; // 4 arguments passed in FPRs. |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 249 | static constexpr bool kGprFprLockstep = false; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 250 | static size_t GprIndexToGprOffset(uint32_t gpr_index) { |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 251 | return gpr_index * GetBytesPerGprSpillLocation(kRuntimeISA); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 252 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 253 | #elif defined(__x86_64__) |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 254 | // The callee save frame is pointed to by SP. |
| 255 | // | argN | | |
| 256 | // | ... | | |
| 257 | // | reg. arg spills | | Caller's frame |
| 258 | // | Method* | --- |
| 259 | // | Return | |
| 260 | // | R15 | callee save |
| 261 | // | R14 | callee save |
| 262 | // | R13 | callee save |
| 263 | // | R12 | callee save |
| 264 | // | R9 | arg5 |
| 265 | // | R8 | arg4 |
| 266 | // | RSI/R6 | arg1 |
| 267 | // | RBP/R5 | callee save |
| 268 | // | RBX/R3 | callee save |
| 269 | // | RDX/R2 | arg2 |
| 270 | // | RCX/R1 | arg3 |
| 271 | // | XMM7 | float arg 8 |
| 272 | // | XMM6 | float arg 7 |
| 273 | // | XMM5 | float arg 6 |
| 274 | // | XMM4 | float arg 5 |
| 275 | // | XMM3 | float arg 4 |
| 276 | // | XMM2 | float arg 3 |
| 277 | // | XMM1 | float arg 2 |
| 278 | // | XMM0 | float arg 1 |
| 279 | // | Padding | |
| 280 | // | RDI/Method* | <- sp |
Mark Mendell | 3e6a3bf | 2015-01-19 14:09:22 -0500 | [diff] [blame] | 281 | static constexpr bool kSplitPairAcrossRegisterAndStack = false; |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 282 | static constexpr bool kAlignPairRegister = false; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 283 | static constexpr bool kQuickSoftFloatAbi = false; // This is a hard float ABI. |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 284 | static constexpr bool kQuickDoubleRegAlignedFloatBackFilled = false; |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 285 | static constexpr bool kQuickSkipOddFpRegisters = false; |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 286 | static constexpr size_t kNumQuickGprArgs = 5; // 5 arguments passed in GPRs. |
Dmitry Petrochenko | 58994cd | 2014-05-17 01:02:18 +0700 | [diff] [blame] | 287 | static constexpr size_t kNumQuickFprArgs = 8; // 8 arguments passed in FPRs. |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 288 | static constexpr bool kGprFprLockstep = false; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 289 | static size_t GprIndexToGprOffset(uint32_t gpr_index) { |
| 290 | switch (gpr_index) { |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 291 | case 0: return (4 * GetBytesPerGprSpillLocation(kRuntimeISA)); |
| 292 | case 1: return (1 * GetBytesPerGprSpillLocation(kRuntimeISA)); |
| 293 | case 2: return (0 * GetBytesPerGprSpillLocation(kRuntimeISA)); |
| 294 | case 3: return (5 * GetBytesPerGprSpillLocation(kRuntimeISA)); |
| 295 | case 4: return (6 * GetBytesPerGprSpillLocation(kRuntimeISA)); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 296 | default: |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 297 | LOG(FATAL) << "Unexpected GPR index: " << gpr_index; |
| 298 | return 0; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 299 | } |
| 300 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 301 | #else |
| 302 | #error "Unsupported architecture" |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 303 | #endif |
| 304 | |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 305 | public: |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 306 | // Special handling for proxy methods. Proxy methods are instance methods so the |
| 307 | // 'this' object is the 1st argument. They also have the same frame layout as the |
| 308 | // kRefAndArgs runtime method. Since 'this' is a reference, it is located in the |
| 309 | // 1st GPR. |
Roland Levillain | fa854e4 | 2018-02-07 13:09:55 +0000 | [diff] [blame] | 310 | static StackReference<mirror::Object>* GetProxyThisObjectReference(ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 311 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 312 | CHECK((*sp)->IsProxyMethod()); |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 313 | CHECK_GT(kNumQuickGprArgs, 0u); |
| 314 | constexpr uint32_t kThisGprIndex = 0u; // 'this' is in the 1st GPR. |
| 315 | size_t this_arg_offset = kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset + |
| 316 | GprIndexToGprOffset(kThisGprIndex); |
| 317 | uint8_t* this_arg_address = reinterpret_cast<uint8_t*>(sp) + this_arg_offset; |
Roland Levillain | fa854e4 | 2018-02-07 13:09:55 +0000 | [diff] [blame] | 318 | return reinterpret_cast<StackReference<mirror::Object>*>(this_arg_address); |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 319 | } |
| 320 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 321 | static ArtMethod* GetCallingMethod(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 322 | DCHECK((*sp)->IsCalleeSaveMethod()); |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 323 | return GetCalleeSaveMethodCaller(sp, CalleeSaveType::kSaveRefsAndArgs); |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 324 | } |
| 325 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 326 | static ArtMethod* GetOuterMethod(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 327 | DCHECK((*sp)->IsCalleeSaveMethod()); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 328 | uint8_t* previous_sp = |
| 329 | reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_FrameSize; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 330 | return *reinterpret_cast<ArtMethod**>(previous_sp); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 331 | } |
| 332 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 333 | static uint32_t GetCallingDexPc(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 334 | DCHECK((*sp)->IsCalleeSaveMethod()); |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 335 | constexpr size_t callee_frame_size = |
| 336 | RuntimeCalleeSaveFrame::GetFrameSize(CalleeSaveType::kSaveRefsAndArgs); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 337 | ArtMethod** caller_sp = reinterpret_cast<ArtMethod**>( |
| 338 | reinterpret_cast<uintptr_t>(sp) + callee_frame_size); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 339 | uintptr_t outer_pc = QuickArgumentVisitor::GetCallingPc(sp); |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 340 | const OatQuickMethodHeader* current_code = (*caller_sp)->GetOatQuickMethodHeader(outer_pc); |
| 341 | uintptr_t outer_pc_offset = current_code->NativeQuickPcOffset(outer_pc); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 342 | |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 343 | if (current_code->IsOptimized()) { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 344 | CodeInfo code_info(current_code); |
| 345 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(outer_pc_offset); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 346 | DCHECK(stack_map.IsValid()); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 347 | if (stack_map.HasInlineInfo()) { |
| 348 | InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map); |
| 349 | return inline_info.GetDexPcAtDepth(inline_info.GetDepth()-1); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 350 | } else { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 351 | return stack_map.GetDexPc(); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 352 | } |
| 353 | } else { |
Nicolas Geoffray | 524e7ea | 2015-10-16 17:13:34 +0100 | [diff] [blame] | 354 | return current_code->ToDexPc(*caller_sp, outer_pc); |
Nicolas Geoffray | d23eeef | 2015-05-18 22:31:29 +0100 | [diff] [blame] | 355 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 358 | static bool GetInvokeType(ArtMethod** sp, InvokeType* invoke_type, uint32_t* dex_method_index) |
| 359 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 360 | DCHECK((*sp)->IsCalleeSaveMethod()); |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 361 | constexpr size_t callee_frame_size = |
| 362 | RuntimeCalleeSaveFrame::GetFrameSize(CalleeSaveType::kSaveRefsAndArgs); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 363 | ArtMethod** caller_sp = reinterpret_cast<ArtMethod**>( |
| 364 | reinterpret_cast<uintptr_t>(sp) + callee_frame_size); |
| 365 | uintptr_t outer_pc = QuickArgumentVisitor::GetCallingPc(sp); |
| 366 | const OatQuickMethodHeader* current_code = (*caller_sp)->GetOatQuickMethodHeader(outer_pc); |
| 367 | if (!current_code->IsOptimized()) { |
| 368 | return false; |
| 369 | } |
| 370 | uintptr_t outer_pc_offset = current_code->NativeQuickPcOffset(outer_pc); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 371 | CodeInfo code_info(current_code); |
Mathieu Chartier | cbcedbf | 2017-03-12 22:24:50 -0700 | [diff] [blame] | 372 | MethodInfo method_info = current_code->GetOptimizedMethodInfo(); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 373 | InvokeInfo invoke(code_info.GetInvokeInfoForNativePcOffset(outer_pc_offset)); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 374 | if (invoke.IsValid()) { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 375 | *invoke_type = static_cast<InvokeType>(invoke.GetInvokeType()); |
| 376 | *dex_method_index = invoke.GetMethodIndex(method_info); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 377 | return true; |
| 378 | } |
| 379 | return false; |
| 380 | } |
| 381 | |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 382 | // For the given quick ref and args quick frame, return the caller's PC. |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 383 | static uintptr_t GetCallingPc(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 384 | DCHECK((*sp)->IsCalleeSaveMethod()); |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 385 | uint8_t* return_adress_spill = |
| 386 | reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_ReturnPcOffset; |
| 387 | return *reinterpret_cast<uintptr_t*>(return_adress_spill); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 390 | QuickArgumentVisitor(ArtMethod** sp, bool is_static, const char* shorty, |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 391 | uint32_t shorty_len) REQUIRES_SHARED(Locks::mutator_lock_) : |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 392 | is_static_(is_static), shorty_(shorty), shorty_len_(shorty_len), |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 393 | gpr_args_(reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_Gpr1Offset), |
| 394 | fpr_args_(reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_Fpr1Offset), |
| 395 | stack_args_(reinterpret_cast<uint8_t*>(sp) + kQuickCalleeSaveFrame_RefAndArgs_FrameSize |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 396 | + sizeof(ArtMethod*)), // Skip ArtMethod*. |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 397 | gpr_index_(0), fpr_index_(0), fpr_double_index_(0), stack_index_(0), |
| 398 | cur_type_(Primitive::kPrimVoid), is_split_long_or_double_(false) { |
Andreas Gampe | 575e78c | 2014-11-03 23:41:03 -0800 | [diff] [blame] | 399 | static_assert(kQuickSoftFloatAbi == (kNumQuickFprArgs == 0), |
| 400 | "Number of Quick FPR arguments unexpected"); |
| 401 | static_assert(!(kQuickSoftFloatAbi && kQuickDoubleRegAlignedFloatBackFilled), |
| 402 | "Double alignment unexpected"); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 403 | // For register alignment, we want to assume that counters(fpr_double_index_) are even if the |
| 404 | // next register is even. |
Andreas Gampe | 575e78c | 2014-11-03 23:41:03 -0800 | [diff] [blame] | 405 | static_assert(!kQuickDoubleRegAlignedFloatBackFilled || kNumQuickFprArgs % 2 == 0, |
| 406 | "Number of Quick FPR arguments not even"); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 407 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 408 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 409 | |
| 410 | virtual ~QuickArgumentVisitor() {} |
| 411 | |
| 412 | virtual void Visit() = 0; |
| 413 | |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 414 | Primitive::Type GetParamPrimitiveType() const { |
| 415 | return cur_type_; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 418 | uint8_t* GetParamAddress() const { |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 419 | if (!kQuickSoftFloatAbi) { |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 420 | Primitive::Type type = GetParamPrimitiveType(); |
| 421 | if (UNLIKELY((type == Primitive::kPrimDouble) || (type == Primitive::kPrimFloat))) { |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 422 | if (type == Primitive::kPrimDouble && kQuickDoubleRegAlignedFloatBackFilled) { |
| 423 | if (fpr_double_index_ + 2 < kNumQuickFprArgs + 1) { |
| 424 | return fpr_args_ + (fpr_double_index_ * GetBytesPerFprSpillLocation(kRuntimeISA)); |
| 425 | } |
| 426 | } else if (fpr_index_ + 1 < kNumQuickFprArgs + 1) { |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 427 | return fpr_args_ + (fpr_index_ * GetBytesPerFprSpillLocation(kRuntimeISA)); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 428 | } |
Vladimir Kostyukov | 1dd61ba | 2014-04-02 18:42:20 +0700 | [diff] [blame] | 429 | return stack_args_ + (stack_index_ * kBytesStackArgLocation); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 430 | } |
| 431 | } |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 432 | if (gpr_index_ < kNumQuickGprArgs) { |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 433 | return gpr_args_ + GprIndexToGprOffset(gpr_index_); |
| 434 | } |
| 435 | return stack_args_ + (stack_index_ * kBytesStackArgLocation); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 436 | } |
| 437 | |
| 438 | bool IsSplitLongOrDouble() const { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 439 | if ((GetBytesPerGprSpillLocation(kRuntimeISA) == 4) || |
| 440 | (GetBytesPerFprSpillLocation(kRuntimeISA) == 4)) { |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 441 | return is_split_long_or_double_; |
| 442 | } else { |
| 443 | return false; // An optimization for when GPR and FPRs are 64bit. |
| 444 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 447 | bool IsParamAReference() const { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 448 | return GetParamPrimitiveType() == Primitive::kPrimNot; |
| 449 | } |
| 450 | |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 451 | bool IsParamALongOrDouble() const { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 452 | Primitive::Type type = GetParamPrimitiveType(); |
| 453 | return type == Primitive::kPrimLong || type == Primitive::kPrimDouble; |
| 454 | } |
| 455 | |
| 456 | uint64_t ReadSplitLongParam() const { |
Nicolas Geoffray | 425f239 | 2015-01-08 14:52:29 +0000 | [diff] [blame] | 457 | // The splitted long is always available through the stack. |
| 458 | return *reinterpret_cast<uint64_t*>(stack_args_ |
| 459 | + stack_index_ * kBytesStackArgLocation); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 462 | void IncGprIndex() { |
| 463 | gpr_index_++; |
| 464 | if (kGprFprLockstep) { |
| 465 | fpr_index_++; |
| 466 | } |
| 467 | } |
| 468 | |
| 469 | void IncFprIndex() { |
| 470 | fpr_index_++; |
| 471 | if (kGprFprLockstep) { |
| 472 | gpr_index_++; |
| 473 | } |
| 474 | } |
| 475 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 476 | void VisitArguments() REQUIRES_SHARED(Locks::mutator_lock_) { |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 477 | // (a) 'stack_args_' should point to the first method's argument |
| 478 | // (b) whatever the argument type it is, the 'stack_index_' should |
| 479 | // be moved forward along with every visiting. |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 480 | gpr_index_ = 0; |
| 481 | fpr_index_ = 0; |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 482 | if (kQuickDoubleRegAlignedFloatBackFilled) { |
| 483 | fpr_double_index_ = 0; |
| 484 | } |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 485 | stack_index_ = 0; |
| 486 | if (!is_static_) { // Handle this. |
| 487 | cur_type_ = Primitive::kPrimNot; |
| 488 | is_split_long_or_double_ = false; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 489 | Visit(); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 490 | stack_index_++; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 491 | if (kNumQuickGprArgs > 0) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 492 | IncGprIndex(); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 493 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 494 | } |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 495 | for (uint32_t shorty_index = 1; shorty_index < shorty_len_; ++shorty_index) { |
| 496 | cur_type_ = Primitive::GetType(shorty_[shorty_index]); |
| 497 | switch (cur_type_) { |
| 498 | case Primitive::kPrimNot: |
| 499 | case Primitive::kPrimBoolean: |
| 500 | case Primitive::kPrimByte: |
| 501 | case Primitive::kPrimChar: |
| 502 | case Primitive::kPrimShort: |
| 503 | case Primitive::kPrimInt: |
| 504 | is_split_long_or_double_ = false; |
| 505 | Visit(); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 506 | stack_index_++; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 507 | if (gpr_index_ < kNumQuickGprArgs) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 508 | IncGprIndex(); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 509 | } |
| 510 | break; |
| 511 | case Primitive::kPrimFloat: |
| 512 | is_split_long_or_double_ = false; |
| 513 | Visit(); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 514 | stack_index_++; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 515 | if (kQuickSoftFloatAbi) { |
| 516 | if (gpr_index_ < kNumQuickGprArgs) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 517 | IncGprIndex(); |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 518 | } |
| 519 | } else { |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 520 | if (fpr_index_ + 1 < kNumQuickFprArgs + 1) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 521 | IncFprIndex(); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 522 | if (kQuickDoubleRegAlignedFloatBackFilled) { |
| 523 | // Double should not overlap with float. |
| 524 | // For example, if fpr_index_ = 3, fpr_double_index_ should be at least 4. |
| 525 | fpr_double_index_ = std::max(fpr_double_index_, RoundUp(fpr_index_, 2)); |
| 526 | // Float should not overlap with double. |
| 527 | if (fpr_index_ % 2 == 0) { |
| 528 | fpr_index_ = std::max(fpr_double_index_, fpr_index_); |
| 529 | } |
Goran Jakovljevic | ff73498 | 2015-08-24 12:58:55 +0000 | [diff] [blame] | 530 | } else if (kQuickSkipOddFpRegisters) { |
| 531 | IncFprIndex(); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 532 | } |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 533 | } |
| 534 | } |
| 535 | break; |
| 536 | case Primitive::kPrimDouble: |
| 537 | case Primitive::kPrimLong: |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 538 | if (kQuickSoftFloatAbi || (cur_type_ == Primitive::kPrimLong)) { |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 539 | if (cur_type_ == Primitive::kPrimLong && |
| 540 | #if defined(__mips__) && !defined(__LP64__) |
| 541 | (gpr_index_ == 0 || gpr_index_ == 2) && |
| 542 | #else |
| 543 | gpr_index_ == 0 && |
| 544 | #endif |
| 545 | kAlignPairRegister) { |
| 546 | // Currently, this is only for ARM and MIPS, where we align long parameters with |
| 547 | // even-numbered registers by skipping R1 (on ARM) or A1(A3) (on MIPS) and using |
| 548 | // R2 (on ARM) or A2(T0) (on MIPS) instead. |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 549 | IncGprIndex(); |
Nicolas Geoffray | 69c15d3 | 2015-01-13 11:42:13 +0000 | [diff] [blame] | 550 | } |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 551 | is_split_long_or_double_ = (GetBytesPerGprSpillLocation(kRuntimeISA) == 4) && |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 552 | ((gpr_index_ + 1) == kNumQuickGprArgs); |
Mark Mendell | 3e6a3bf | 2015-01-19 14:09:22 -0500 | [diff] [blame] | 553 | if (!kSplitPairAcrossRegisterAndStack && is_split_long_or_double_) { |
| 554 | // We don't want to split this. Pass over this register. |
| 555 | gpr_index_++; |
| 556 | is_split_long_or_double_ = false; |
| 557 | } |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 558 | Visit(); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 559 | if (kBytesStackArgLocation == 4) { |
| 560 | stack_index_+= 2; |
| 561 | } else { |
| 562 | CHECK_EQ(kBytesStackArgLocation, 8U); |
| 563 | stack_index_++; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 564 | } |
Vladimir Kostyukov | 1dd61ba | 2014-04-02 18:42:20 +0700 | [diff] [blame] | 565 | if (gpr_index_ < kNumQuickGprArgs) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 566 | IncGprIndex(); |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 567 | if (GetBytesPerGprSpillLocation(kRuntimeISA) == 4) { |
Vladimir Kostyukov | 1dd61ba | 2014-04-02 18:42:20 +0700 | [diff] [blame] | 568 | if (gpr_index_ < kNumQuickGprArgs) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 569 | IncGprIndex(); |
Vladimir Kostyukov | 1dd61ba | 2014-04-02 18:42:20 +0700 | [diff] [blame] | 570 | } |
| 571 | } |
| 572 | } |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 573 | } else { |
Nicolas Geoffray | 42fcd98 | 2014-04-22 11:03:52 +0000 | [diff] [blame] | 574 | is_split_long_or_double_ = (GetBytesPerFprSpillLocation(kRuntimeISA) == 4) && |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 575 | ((fpr_index_ + 1) == kNumQuickFprArgs) && !kQuickDoubleRegAlignedFloatBackFilled; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 576 | Visit(); |
Vladimir Kostyukov | 1dd61ba | 2014-04-02 18:42:20 +0700 | [diff] [blame] | 577 | if (kBytesStackArgLocation == 4) { |
| 578 | stack_index_+= 2; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 579 | } else { |
Vladimir Kostyukov | 1dd61ba | 2014-04-02 18:42:20 +0700 | [diff] [blame] | 580 | CHECK_EQ(kBytesStackArgLocation, 8U); |
| 581 | stack_index_++; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 582 | } |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 583 | if (kQuickDoubleRegAlignedFloatBackFilled) { |
| 584 | if (fpr_double_index_ + 2 < kNumQuickFprArgs + 1) { |
| 585 | fpr_double_index_ += 2; |
| 586 | // Float should not overlap with double. |
| 587 | if (fpr_index_ % 2 == 0) { |
| 588 | fpr_index_ = std::max(fpr_double_index_, fpr_index_); |
| 589 | } |
| 590 | } |
| 591 | } else if (fpr_index_ + 1 < kNumQuickFprArgs + 1) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 592 | IncFprIndex(); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 593 | if (GetBytesPerFprSpillLocation(kRuntimeISA) == 4) { |
| 594 | if (fpr_index_ + 1 < kNumQuickFprArgs + 1) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 595 | IncFprIndex(); |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 596 | } |
| 597 | } |
| 598 | } |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 599 | } |
| 600 | break; |
| 601 | default: |
| 602 | LOG(FATAL) << "Unexpected type: " << cur_type_ << " in " << shorty_; |
| 603 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 604 | } |
| 605 | } |
| 606 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 607 | protected: |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 608 | const bool is_static_; |
| 609 | const char* const shorty_; |
| 610 | const uint32_t shorty_len_; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 611 | |
| 612 | private: |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 613 | uint8_t* const gpr_args_; // Address of GPR arguments in callee save frame. |
| 614 | uint8_t* const fpr_args_; // Address of FPR arguments in callee save frame. |
| 615 | uint8_t* const stack_args_; // Address of stack arguments in caller's frame. |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 616 | uint32_t gpr_index_; // Index into spilled GPRs. |
Zheng Xu | 5667fdb | 2014-10-23 18:29:55 +0800 | [diff] [blame] | 617 | // Index into spilled FPRs. |
| 618 | // In case kQuickDoubleRegAlignedFloatBackFilled, it may index a hole while fpr_double_index_ |
| 619 | // holds a higher register number. |
| 620 | uint32_t fpr_index_; |
| 621 | // Index into spilled FPRs for aligned double. |
| 622 | // Only used when kQuickDoubleRegAlignedFloatBackFilled. Next available double register indexed in |
| 623 | // terms of singles, may be behind fpr_index. |
| 624 | uint32_t fpr_double_index_; |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 625 | uint32_t stack_index_; // Index into arguments on the stack. |
| 626 | // The current type of argument during VisitArguments. |
| 627 | Primitive::Type cur_type_; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 628 | // Does a 64bit parameter straddle the register and stack arguments? |
| 629 | bool is_split_long_or_double_; |
| 630 | }; |
| 631 | |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 632 | // Returns the 'this' object of a proxy method. This function is only used by StackVisitor. It |
| 633 | // allows to use the QuickArgumentVisitor constants without moving all the code in its own module. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 634 | extern "C" mirror::Object* artQuickGetProxyThisObject(ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 635 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Roland Levillain | fa854e4 | 2018-02-07 13:09:55 +0000 | [diff] [blame] | 636 | return QuickArgumentVisitor::GetProxyThisObjectReference(sp)->AsMirrorPtr(); |
| 637 | } |
Sebastien Hertz | a836bc9 | 2014-11-25 16:30:53 +0100 | [diff] [blame] | 638 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 639 | // Visits arguments on the stack placing them into the shadow frame. |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 640 | class BuildQuickShadowFrameVisitor FINAL : public QuickArgumentVisitor { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 641 | public: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 642 | BuildQuickShadowFrameVisitor(ArtMethod** sp, bool is_static, const char* shorty, |
| 643 | uint32_t shorty_len, ShadowFrame* sf, size_t first_arg_reg) : |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 644 | QuickArgumentVisitor(sp, is_static, shorty, shorty_len), sf_(sf), cur_reg_(first_arg_reg) {} |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 645 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 646 | void Visit() REQUIRES_SHARED(Locks::mutator_lock_) OVERRIDE; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 647 | |
| 648 | private: |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 649 | ShadowFrame* const sf_; |
| 650 | uint32_t cur_reg_; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 651 | |
Dragos Sbirlea | bd136a2 | 2013-08-13 18:07:04 -0700 | [diff] [blame] | 652 | DISALLOW_COPY_AND_ASSIGN(BuildQuickShadowFrameVisitor); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 653 | }; |
| 654 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 655 | void BuildQuickShadowFrameVisitor::Visit() { |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 656 | Primitive::Type type = GetParamPrimitiveType(); |
| 657 | switch (type) { |
| 658 | case Primitive::kPrimLong: // Fall-through. |
| 659 | case Primitive::kPrimDouble: |
| 660 | if (IsSplitLongOrDouble()) { |
| 661 | sf_->SetVRegLong(cur_reg_, ReadSplitLongParam()); |
| 662 | } else { |
| 663 | sf_->SetVRegLong(cur_reg_, *reinterpret_cast<jlong*>(GetParamAddress())); |
| 664 | } |
| 665 | ++cur_reg_; |
| 666 | break; |
| 667 | case Primitive::kPrimNot: { |
| 668 | StackReference<mirror::Object>* stack_ref = |
| 669 | reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress()); |
| 670 | sf_->SetVRegReference(cur_reg_, stack_ref->AsMirrorPtr()); |
| 671 | } |
| 672 | break; |
| 673 | case Primitive::kPrimBoolean: // Fall-through. |
| 674 | case Primitive::kPrimByte: // Fall-through. |
| 675 | case Primitive::kPrimChar: // Fall-through. |
| 676 | case Primitive::kPrimShort: // Fall-through. |
| 677 | case Primitive::kPrimInt: // Fall-through. |
| 678 | case Primitive::kPrimFloat: |
| 679 | sf_->SetVReg(cur_reg_, *reinterpret_cast<jint*>(GetParamAddress())); |
| 680 | break; |
| 681 | case Primitive::kPrimVoid: |
| 682 | LOG(FATAL) << "UNREACHABLE"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 683 | UNREACHABLE(); |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 684 | } |
| 685 | ++cur_reg_; |
| 686 | } |
| 687 | |
Mingyao Yang | 417528d | 2017-09-13 12:10:40 -0700 | [diff] [blame] | 688 | // Don't inline. See b/65159206. |
| 689 | NO_INLINE |
| 690 | static void HandleDeoptimization(JValue* result, |
| 691 | ArtMethod* method, |
| 692 | ShadowFrame* deopt_frame, |
| 693 | ManagedStack* fragment) |
| 694 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 695 | // Coming from partial-fragment deopt. |
| 696 | Thread* self = Thread::Current(); |
| 697 | if (kIsDebugBuild) { |
| 698 | // Sanity-check: are the methods as expected? We check that the last shadow frame (the bottom |
| 699 | // of the call-stack) corresponds to the called method. |
| 700 | ShadowFrame* linked = deopt_frame; |
| 701 | while (linked->GetLink() != nullptr) { |
| 702 | linked = linked->GetLink(); |
| 703 | } |
| 704 | CHECK_EQ(method, linked->GetMethod()) << method->PrettyMethod() << " " |
| 705 | << ArtMethod::PrettyMethod(linked->GetMethod()); |
| 706 | } |
| 707 | |
| 708 | if (VLOG_IS_ON(deopt)) { |
| 709 | // Print out the stack to verify that it was a partial-fragment deopt. |
| 710 | LOG(INFO) << "Continue-ing from deopt. Stack is:"; |
| 711 | QuickExceptionHandler::DumpFramesWithType(self, true); |
| 712 | } |
| 713 | |
| 714 | ObjPtr<mirror::Throwable> pending_exception; |
| 715 | bool from_code = false; |
| 716 | DeoptimizationMethodType method_type; |
| 717 | self->PopDeoptimizationContext(/* out */ result, |
| 718 | /* out */ &pending_exception, |
| 719 | /* out */ &from_code, |
| 720 | /* out */ &method_type); |
| 721 | |
| 722 | // Push a transition back into managed code onto the linked list in thread. |
| 723 | self->PushManagedStackFragment(fragment); |
| 724 | |
| 725 | // Ensure that the stack is still in order. |
| 726 | if (kIsDebugBuild) { |
| 727 | class DummyStackVisitor : public StackVisitor { |
| 728 | public: |
| 729 | explicit DummyStackVisitor(Thread* self_in) REQUIRES_SHARED(Locks::mutator_lock_) |
| 730 | : StackVisitor(self_in, nullptr, StackVisitor::StackWalkKind::kIncludeInlinedFrames) {} |
| 731 | |
| 732 | bool VisitFrame() OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_) { |
| 733 | // Nothing to do here. In a debug build, SanityCheckFrame will do the work in the walking |
| 734 | // logic. Just always say we want to continue. |
| 735 | return true; |
| 736 | } |
| 737 | }; |
| 738 | DummyStackVisitor dsv(self); |
| 739 | dsv.WalkStack(); |
| 740 | } |
| 741 | |
| 742 | // Restore the exception that was pending before deoptimization then interpret the |
| 743 | // deoptimized frames. |
| 744 | if (pending_exception != nullptr) { |
| 745 | self->SetException(pending_exception); |
| 746 | } |
| 747 | interpreter::EnterInterpreterFromDeoptimize(self, |
| 748 | deopt_frame, |
| 749 | result, |
| 750 | from_code, |
| 751 | DeoptimizationMethodType::kDefault); |
| 752 | } |
| 753 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 754 | extern "C" uint64_t artQuickToInterpreterBridge(ArtMethod* method, Thread* self, ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 755 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 756 | // Ensure we don't get thread suspension until the object arguments are safely in the shadow |
| 757 | // frame. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 758 | ScopedQuickEntrypointChecks sqec(self); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 759 | |
Alex Light | 9139e00 | 2015-10-09 15:59:48 -0700 | [diff] [blame] | 760 | if (UNLIKELY(!method->IsInvokable())) { |
| 761 | method->ThrowInvocationTimeError(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 762 | return 0; |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | JValue tmp_value; |
| 766 | ShadowFrame* deopt_frame = self->PopStackedShadowFrame( |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 767 | StackedShadowFrameType::kDeoptimizationShadowFrame, false); |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 768 | ManagedStack fragment; |
| 769 | |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 770 | DCHECK(!method->IsNative()) << method->PrettyMethod(); |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 771 | uint32_t shorty_len = 0; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 772 | ArtMethod* non_proxy_method = method->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 773 | DCHECK(non_proxy_method->GetCodeItem() != nullptr) << method->PrettyMethod(); |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 774 | CodeItemDataAccessor accessor(non_proxy_method->DexInstructionData()); |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 775 | const char* shorty = non_proxy_method->GetShorty(&shorty_len); |
| 776 | |
| 777 | JValue result; |
| 778 | |
Mingyao Yang | 417528d | 2017-09-13 12:10:40 -0700 | [diff] [blame] | 779 | if (UNLIKELY(deopt_frame != nullptr)) { |
| 780 | HandleDeoptimization(&result, method, deopt_frame, &fragment); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 781 | } else { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 782 | const char* old_cause = self->StartAssertNoThreadSuspension( |
| 783 | "Building interpreter shadow frame"); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 784 | uint16_t num_regs = accessor.RegistersSize(); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 785 | // No last shadow coming from quick. |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 786 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
Andreas Gampe | 03ec930 | 2015-08-27 17:41:47 -0700 | [diff] [blame] | 787 | CREATE_SHADOW_FRAME(num_regs, /* link */ nullptr, method, /* dex pc */ 0); |
Andreas Gampe | b302592 | 2015-09-01 14:45:00 -0700 | [diff] [blame] | 788 | ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get(); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 789 | size_t first_arg_reg = accessor.RegistersSize() - accessor.InsSize(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 790 | BuildQuickShadowFrameVisitor shadow_frame_builder(sp, method->IsStatic(), shorty, shorty_len, |
Ian Rogers | 936b37f | 2014-02-14 00:52:24 -0800 | [diff] [blame] | 791 | shadow_frame, first_arg_reg); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 792 | shadow_frame_builder.VisitArguments(); |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 793 | const bool needs_initialization = |
| 794 | method->IsStatic() && !method->GetDeclaringClass()->IsInitialized(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 795 | // Push a transition back into managed code onto the linked list in thread. |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 796 | self->PushManagedStackFragment(&fragment); |
| 797 | self->PushShadowFrame(shadow_frame); |
| 798 | self->EndAssertNoThreadSuspension(old_cause); |
| 799 | |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 800 | if (needs_initialization) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 801 | // Ensure static method's class is initialized. |
Ian Rogers | e94652f | 2014-12-02 11:13:19 -0800 | [diff] [blame] | 802 | StackHandleScope<1> hs(self); |
| 803 | Handle<mirror::Class> h_class(hs.NewHandle(shadow_frame->GetMethod()->GetDeclaringClass())); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 804 | if (!Runtime::Current()->GetClassLinker()->EnsureInitialized(self, h_class, true, true)) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 805 | DCHECK(Thread::Current()->IsExceptionPending()) |
| 806 | << shadow_frame->GetMethod()->PrettyMethod(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 807 | self->PopManagedStackFragment(fragment); |
| 808 | return 0; |
| 809 | } |
| 810 | } |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 811 | |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 812 | result = interpreter::EnterInterpreterFromEntryPoint(self, accessor, shadow_frame); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 813 | } |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 814 | |
| 815 | // Pop transition. |
| 816 | self->PopManagedStackFragment(fragment); |
| 817 | |
| 818 | // Request a stack deoptimization if needed |
| 819 | ArtMethod* caller = QuickArgumentVisitor::GetCallingMethod(sp); |
Mingyao Yang | f711f2c | 2016-05-23 12:29:39 -0700 | [diff] [blame] | 820 | uintptr_t caller_pc = QuickArgumentVisitor::GetCallingPc(sp); |
Mingyao Yang | a3549d2 | 2016-06-02 17:01:02 -0700 | [diff] [blame] | 821 | // If caller_pc is the instrumentation exit stub, the stub will check to see if deoptimization |
| 822 | // should be done and it knows the real return pc. |
| 823 | if (UNLIKELY(caller_pc != reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()) && |
Nicolas Geoffray | 433b79a | 2017-01-30 20:54:45 +0000 | [diff] [blame] | 824 | Dbg::IsForcedInterpreterNeededForUpcall(self, caller))) { |
| 825 | if (!Runtime::Current()->IsAsyncDeoptimizeable(caller_pc)) { |
| 826 | LOG(WARNING) << "Got a deoptimization request on un-deoptimizable method " |
| 827 | << caller->PrettyMethod(); |
| 828 | } else { |
| 829 | // Push the context of the deoptimization stack so we can restore the return value and the |
| 830 | // exception before executing the deoptimized frames. |
| 831 | self->PushDeoptimizationContext( |
Mingyao Yang | 2ee1790 | 2017-08-30 11:37:08 -0700 | [diff] [blame] | 832 | result, |
| 833 | shorty[0] == 'L' || shorty[0] == '[', /* class or array */ |
| 834 | self->GetException(), |
| 835 | false /* from_code */, |
| 836 | DeoptimizationMethodType::kDefault); |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 837 | |
Nicolas Geoffray | 433b79a | 2017-01-30 20:54:45 +0000 | [diff] [blame] | 838 | // Set special exception to cause deoptimization. |
| 839 | self->SetException(Thread::GetDeoptimizationException()); |
| 840 | } |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | // No need to restore the args since the method has already been run by the interpreter. |
| 844 | return result.GetJ(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 845 | } |
| 846 | |
| 847 | // Visits arguments on the stack placing them into the args vector, Object* arguments are converted |
| 848 | // to jobjects. |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 849 | class BuildQuickArgumentVisitor FINAL : public QuickArgumentVisitor { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 850 | public: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 851 | BuildQuickArgumentVisitor(ArtMethod** sp, bool is_static, const char* shorty, uint32_t shorty_len, |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 852 | ScopedObjectAccessUnchecked* soa, std::vector<jvalue>* args) : |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 853 | QuickArgumentVisitor(sp, is_static, shorty, shorty_len), soa_(soa), args_(args) {} |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 854 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 855 | void Visit() REQUIRES_SHARED(Locks::mutator_lock_) OVERRIDE; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 856 | |
| 857 | private: |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 858 | ScopedObjectAccessUnchecked* const soa_; |
| 859 | std::vector<jvalue>* const args_; |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 860 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 861 | DISALLOW_COPY_AND_ASSIGN(BuildQuickArgumentVisitor); |
| 862 | }; |
| 863 | |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 864 | void BuildQuickArgumentVisitor::Visit() { |
| 865 | jvalue val; |
| 866 | Primitive::Type type = GetParamPrimitiveType(); |
| 867 | switch (type) { |
| 868 | case Primitive::kPrimNot: { |
| 869 | StackReference<mirror::Object>* stack_ref = |
| 870 | reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress()); |
| 871 | val.l = soa_->AddLocalReference<jobject>(stack_ref->AsMirrorPtr()); |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 872 | break; |
| 873 | } |
| 874 | case Primitive::kPrimLong: // Fall-through. |
| 875 | case Primitive::kPrimDouble: |
| 876 | if (IsSplitLongOrDouble()) { |
| 877 | val.j = ReadSplitLongParam(); |
| 878 | } else { |
| 879 | val.j = *reinterpret_cast<jlong*>(GetParamAddress()); |
| 880 | } |
| 881 | break; |
| 882 | case Primitive::kPrimBoolean: // Fall-through. |
| 883 | case Primitive::kPrimByte: // Fall-through. |
| 884 | case Primitive::kPrimChar: // Fall-through. |
| 885 | case Primitive::kPrimShort: // Fall-through. |
| 886 | case Primitive::kPrimInt: // Fall-through. |
| 887 | case Primitive::kPrimFloat: |
| 888 | val.i = *reinterpret_cast<jint*>(GetParamAddress()); |
| 889 | break; |
| 890 | case Primitive::kPrimVoid: |
| 891 | LOG(FATAL) << "UNREACHABLE"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 892 | UNREACHABLE(); |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 893 | } |
| 894 | args_->push_back(val); |
| 895 | } |
| 896 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 897 | // Handler for invocation on proxy methods. On entry a frame will exist for the proxy object method |
| 898 | // which is responsible for recording callee save registers. We explicitly place into jobjects the |
| 899 | // incoming reference arguments (so they survive GC). We invoke the invocation handler, which is a |
| 900 | // field within the proxy object, which will box the primitive arguments and deal with error cases. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 901 | extern "C" uint64_t artQuickProxyInvokeHandler( |
| 902 | ArtMethod* proxy_method, mirror::Object* receiver, Thread* self, ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 903 | REQUIRES_SHARED(Locks::mutator_lock_) { |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 904 | DCHECK(proxy_method->IsProxyMethod()) << proxy_method->PrettyMethod(); |
| 905 | DCHECK(receiver->GetClass()->IsProxyClass()) << proxy_method->PrettyMethod(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 906 | // Ensure we don't get thread suspension until the object arguments are safely in jobjects. |
| 907 | const char* old_cause = |
| 908 | self->StartAssertNoThreadSuspension("Adding to IRT proxy object arguments"); |
| 909 | // Register the top of the managed stack, making stack crawlable. |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 910 | DCHECK_EQ((*sp), proxy_method) << proxy_method->PrettyMethod(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 911 | self->VerifyStack(); |
| 912 | // Start new JNI local reference state. |
| 913 | JNIEnvExt* env = self->GetJniEnv(); |
| 914 | ScopedObjectAccessUnchecked soa(env); |
| 915 | ScopedJniEnvLocalRefState env_state(env); |
| 916 | // Create local ref. copies of proxy method and the receiver. |
| 917 | jobject rcvr_jobj = soa.AddLocalReference<jobject>(receiver); |
| 918 | |
| 919 | // Placing arguments into args vector and remove the receiver. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 920 | ArtMethod* non_proxy_method = proxy_method->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 921 | CHECK(!non_proxy_method->IsStatic()) << proxy_method->PrettyMethod() << " " |
| 922 | << non_proxy_method->PrettyMethod(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 923 | std::vector<jvalue> args; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 924 | uint32_t shorty_len = 0; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 925 | const char* shorty = non_proxy_method->GetShorty(&shorty_len); |
Roland Levillain | ad0777d | 2018-02-12 20:00:18 +0000 | [diff] [blame] | 926 | BuildQuickArgumentVisitor local_ref_visitor( |
| 927 | sp, /* is_static */ false, shorty, shorty_len, &soa, &args); |
Brian Carlstrom | d3633d5 | 2013-08-20 21:06:26 -0700 | [diff] [blame] | 928 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 929 | local_ref_visitor.VisitArguments(); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 930 | DCHECK_GT(args.size(), 0U) << proxy_method->PrettyMethod(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 931 | args.erase(args.begin()); |
| 932 | |
| 933 | // Convert proxy method into expected interface method. |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 934 | ArtMethod* interface_method = proxy_method->FindOverriddenMethod(kRuntimePointerSize); |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 935 | DCHECK(interface_method != nullptr) << proxy_method->PrettyMethod(); |
| 936 | DCHECK(!interface_method->IsProxyMethod()) << interface_method->PrettyMethod(); |
Mathieu Chartier | fc58af4 | 2015-04-16 18:00:39 -0700 | [diff] [blame] | 937 | self->EndAssertNoThreadSuspension(old_cause); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 938 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Andreas Gampe | e01e364 | 2016-07-25 13:06:04 -0700 | [diff] [blame] | 939 | DCHECK(!Runtime::Current()->IsActiveTransaction()); |
Andreas Gampe | ee29a07 | 2017-11-02 15:28:09 -0700 | [diff] [blame] | 940 | ObjPtr<mirror::Method> interface_reflect_method = |
| 941 | mirror::Method::CreateFromArtMethod<kRuntimePointerSize, false>(soa.Self(), interface_method); |
| 942 | if (interface_reflect_method == nullptr) { |
| 943 | soa.Self()->AssertPendingOOMException(); |
| 944 | return 0; |
| 945 | } |
| 946 | jobject interface_method_jobj = soa.AddLocalReference<jobject>(interface_reflect_method); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 947 | |
| 948 | // All naked Object*s should now be in jobjects, so its safe to go into the main invoke code |
| 949 | // that performs allocations. |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 950 | JValue result = InvokeProxyInvocationHandler(soa, shorty, rcvr_jobj, interface_method_jobj, args); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 951 | return result.GetJ(); |
| 952 | } |
| 953 | |
Roland Levillain | ad0777d | 2018-02-12 20:00:18 +0000 | [diff] [blame] | 954 | // Visitor returning a reference argument at a given position in a Quick stack frame. |
| 955 | // NOTE: Only used for testing purposes. |
| 956 | class GetQuickReferenceArgumentAtVisitor FINAL : public QuickArgumentVisitor { |
| 957 | public: |
| 958 | GetQuickReferenceArgumentAtVisitor(ArtMethod** sp, |
| 959 | const char* shorty, |
| 960 | uint32_t shorty_len, |
| 961 | size_t arg_pos) |
| 962 | : QuickArgumentVisitor(sp, /* is_static */ false, shorty, shorty_len), |
| 963 | cur_pos_(0u), |
| 964 | arg_pos_(arg_pos), |
| 965 | ref_arg_(nullptr) { |
| 966 | CHECK_LT(arg_pos, shorty_len) << "Argument position greater than the number arguments"; |
| 967 | } |
| 968 | |
| 969 | void Visit() REQUIRES_SHARED(Locks::mutator_lock_) OVERRIDE { |
| 970 | if (cur_pos_ == arg_pos_) { |
| 971 | Primitive::Type type = GetParamPrimitiveType(); |
| 972 | CHECK_EQ(type, Primitive::kPrimNot) << "Argument at searched position is not a reference"; |
| 973 | ref_arg_ = reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress()); |
| 974 | } |
| 975 | ++cur_pos_; |
| 976 | } |
| 977 | |
| 978 | StackReference<mirror::Object>* GetReferenceArgument() { |
| 979 | return ref_arg_; |
| 980 | } |
| 981 | |
| 982 | private: |
| 983 | // The position of the currently visited argument. |
| 984 | size_t cur_pos_; |
| 985 | // The position of the searched argument. |
| 986 | const size_t arg_pos_; |
| 987 | // The reference argument, if found. |
| 988 | StackReference<mirror::Object>* ref_arg_; |
| 989 | |
| 990 | DISALLOW_COPY_AND_ASSIGN(GetQuickReferenceArgumentAtVisitor); |
| 991 | }; |
| 992 | |
| 993 | // Returning reference argument at position `arg_pos` in Quick stack frame at address `sp`. |
| 994 | // NOTE: Only used for testing purposes. |
| 995 | extern "C" StackReference<mirror::Object>* artQuickGetProxyReferenceArgumentAt(size_t arg_pos, |
| 996 | ArtMethod** sp) |
| 997 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 998 | ArtMethod* proxy_method = *sp; |
| 999 | ArtMethod* non_proxy_method = proxy_method->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
| 1000 | CHECK(!non_proxy_method->IsStatic()) |
| 1001 | << proxy_method->PrettyMethod() << " " << non_proxy_method->PrettyMethod(); |
| 1002 | uint32_t shorty_len = 0; |
| 1003 | const char* shorty = non_proxy_method->GetShorty(&shorty_len); |
| 1004 | GetQuickReferenceArgumentAtVisitor ref_arg_visitor(sp, shorty, shorty_len, arg_pos); |
| 1005 | ref_arg_visitor.VisitArguments(); |
| 1006 | StackReference<mirror::Object>* ref_arg = ref_arg_visitor.GetReferenceArgument(); |
| 1007 | return ref_arg; |
| 1008 | } |
| 1009 | |
| 1010 | // Visitor returning all the reference arguments in a Quick stack frame. |
| 1011 | class GetQuickReferenceArgumentsVisitor FINAL : public QuickArgumentVisitor { |
| 1012 | public: |
| 1013 | GetQuickReferenceArgumentsVisitor(ArtMethod** sp, |
| 1014 | bool is_static, |
| 1015 | const char* shorty, |
| 1016 | uint32_t shorty_len) |
| 1017 | : QuickArgumentVisitor(sp, is_static, shorty, shorty_len) {} |
| 1018 | |
| 1019 | void Visit() REQUIRES_SHARED(Locks::mutator_lock_) OVERRIDE { |
| 1020 | Primitive::Type type = GetParamPrimitiveType(); |
| 1021 | if (type == Primitive::kPrimNot) { |
| 1022 | StackReference<mirror::Object>* ref_arg = |
| 1023 | reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress()); |
| 1024 | ref_args_.push_back(ref_arg); |
| 1025 | } |
| 1026 | } |
| 1027 | |
| 1028 | std::vector<StackReference<mirror::Object>*> GetReferenceArguments() { |
| 1029 | return ref_args_; |
| 1030 | } |
| 1031 | |
| 1032 | private: |
| 1033 | // The reference arguments. |
| 1034 | std::vector<StackReference<mirror::Object>*> ref_args_; |
| 1035 | |
| 1036 | DISALLOW_COPY_AND_ASSIGN(GetQuickReferenceArgumentsVisitor); |
| 1037 | }; |
| 1038 | |
| 1039 | // Returning all reference arguments in Quick stack frame at address `sp`. |
| 1040 | std::vector<StackReference<mirror::Object>*> GetProxyReferenceArguments(ArtMethod** sp) |
| 1041 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1042 | ArtMethod* proxy_method = *sp; |
| 1043 | ArtMethod* non_proxy_method = proxy_method->GetInterfaceMethodIfProxy(kRuntimePointerSize); |
| 1044 | CHECK(!non_proxy_method->IsStatic()) |
| 1045 | << proxy_method->PrettyMethod() << " " << non_proxy_method->PrettyMethod(); |
| 1046 | uint32_t shorty_len = 0; |
| 1047 | const char* shorty = non_proxy_method->GetShorty(&shorty_len); |
| 1048 | GetQuickReferenceArgumentsVisitor ref_args_visitor(sp, /* is_static */ false, shorty, shorty_len); |
| 1049 | ref_args_visitor.VisitArguments(); |
| 1050 | std::vector<StackReference<mirror::Object>*> ref_args = ref_args_visitor.GetReferenceArguments(); |
| 1051 | return ref_args; |
| 1052 | } |
| 1053 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1054 | // Read object references held in arguments from quick frames and place in a JNI local references, |
| 1055 | // so they don't get garbage collected. |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1056 | class RememberForGcArgumentVisitor FINAL : public QuickArgumentVisitor { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1057 | public: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1058 | RememberForGcArgumentVisitor(ArtMethod** sp, bool is_static, const char* shorty, |
| 1059 | uint32_t shorty_len, ScopedObjectAccessUnchecked* soa) : |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1060 | QuickArgumentVisitor(sp, is_static, shorty, shorty_len), soa_(soa) {} |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1061 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1062 | void Visit() REQUIRES_SHARED(Locks::mutator_lock_) OVERRIDE; |
Mathieu Chartier | 07d447b | 2013-09-26 11:57:43 -0700 | [diff] [blame] | 1063 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1064 | void FixupReferences() REQUIRES_SHARED(Locks::mutator_lock_); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1065 | |
| 1066 | private: |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 1067 | ScopedObjectAccessUnchecked* const soa_; |
Mathieu Chartier | 5275bcb | 2014-02-20 17:16:42 -0800 | [diff] [blame] | 1068 | // References which we must update when exiting in case the GC moved the objects. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1069 | std::vector<std::pair<jobject, StackReference<mirror::Object>*> > references_; |
| 1070 | |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1071 | DISALLOW_COPY_AND_ASSIGN(RememberForGcArgumentVisitor); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1072 | }; |
| 1073 | |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 1074 | void RememberForGcArgumentVisitor::Visit() { |
| 1075 | if (IsParamAReference()) { |
| 1076 | StackReference<mirror::Object>* stack_ref = |
| 1077 | reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress()); |
| 1078 | jobject reference = |
| 1079 | soa_->AddLocalReference<jobject>(stack_ref->AsMirrorPtr()); |
| 1080 | references_.push_back(std::make_pair(reference, stack_ref)); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | void RememberForGcArgumentVisitor::FixupReferences() { |
| 1085 | // Fixup any references which may have changed. |
| 1086 | for (const auto& pair : references_) { |
Mathieu Chartier | 1a5337f | 2016-10-13 13:48:23 -0700 | [diff] [blame] | 1087 | pair.second->Assign(soa_->Decode<mirror::Object>(pair.first)); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 1088 | soa_->Env()->DeleteLocalRef(pair.first); |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 1089 | } |
| 1090 | } |
| 1091 | |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1092 | extern "C" const void* artInstrumentationMethodEntryFromCode(ArtMethod* method, |
| 1093 | mirror::Object* this_object, |
| 1094 | Thread* self, |
| 1095 | ArtMethod** sp) |
| 1096 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1097 | const void* result; |
| 1098 | // Instrumentation changes the stack. Thus, when exiting, the stack cannot be verified, so skip |
| 1099 | // that part. |
| 1100 | ScopedQuickEntrypointChecks sqec(self, kIsDebugBuild, false); |
| 1101 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 1102 | if (instrumentation->IsDeoptimized(method)) { |
| 1103 | result = GetQuickToInterpreterBridge(); |
| 1104 | } else { |
| 1105 | result = instrumentation->GetQuickCodeFor(method, kRuntimePointerSize); |
| 1106 | DCHECK(!Runtime::Current()->GetClassLinker()->IsQuickToInterpreterBridge(result)); |
| 1107 | } |
| 1108 | |
| 1109 | bool interpreter_entry = (result == GetQuickToInterpreterBridge()); |
| 1110 | bool is_static = method->IsStatic(); |
| 1111 | uint32_t shorty_len; |
| 1112 | const char* shorty = |
| 1113 | method->GetInterfaceMethodIfProxy(kRuntimePointerSize)->GetShorty(&shorty_len); |
| 1114 | |
| 1115 | ScopedObjectAccessUnchecked soa(self); |
| 1116 | RememberForGcArgumentVisitor visitor(sp, is_static, shorty, shorty_len, &soa); |
| 1117 | visitor.VisitArguments(); |
| 1118 | |
| 1119 | instrumentation->PushInstrumentationStackFrame(self, |
| 1120 | is_static ? nullptr : this_object, |
| 1121 | method, |
| 1122 | QuickArgumentVisitor::GetCallingPc(sp), |
| 1123 | interpreter_entry); |
| 1124 | |
| 1125 | visitor.FixupReferences(); |
| 1126 | if (UNLIKELY(self->IsExceptionPending())) { |
| 1127 | return nullptr; |
| 1128 | } |
| 1129 | CHECK(result != nullptr) << method->PrettyMethod(); |
| 1130 | return result; |
| 1131 | } |
| 1132 | |
| 1133 | extern "C" TwoWordReturn artInstrumentationMethodExitFromCode(Thread* self, |
| 1134 | ArtMethod** sp, |
| 1135 | uint64_t* gpr_result, |
| 1136 | uint64_t* fpr_result) |
| 1137 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1138 | DCHECK_EQ(reinterpret_cast<uintptr_t>(self), reinterpret_cast<uintptr_t>(Thread::Current())); |
| 1139 | CHECK(gpr_result != nullptr); |
| 1140 | CHECK(fpr_result != nullptr); |
| 1141 | // Instrumentation exit stub must not be entered with a pending exception. |
| 1142 | CHECK(!self->IsExceptionPending()) << "Enter instrumentation exit stub with pending exception " |
| 1143 | << self->GetException()->Dump(); |
| 1144 | // Compute address of return PC and sanity check that it currently holds 0. |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 1145 | constexpr size_t return_pc_offset = |
| 1146 | RuntimeCalleeSaveFrame::GetReturnPcOffset(CalleeSaveType::kSaveEverything); |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1147 | uintptr_t* return_pc = reinterpret_cast<uintptr_t*>(reinterpret_cast<uint8_t*>(sp) + |
| 1148 | return_pc_offset); |
| 1149 | CHECK_EQ(*return_pc, 0U); |
| 1150 | |
| 1151 | // Pop the frame filling in the return pc. The low half of the return value is 0 when |
| 1152 | // deoptimization shouldn't be performed with the high-half having the return address. When |
| 1153 | // deoptimization should be performed the low half is zero and the high-half the address of the |
| 1154 | // deoptimization entry point. |
| 1155 | instrumentation::Instrumentation* instrumentation = Runtime::Current()->GetInstrumentation(); |
| 1156 | TwoWordReturn return_or_deoptimize_pc = instrumentation->PopInstrumentationStackFrame( |
| 1157 | self, return_pc, gpr_result, fpr_result); |
Vladimir Marko | fac2178 | 2018-03-13 17:01:09 +0000 | [diff] [blame] | 1158 | if (self->IsExceptionPending() || self->ObserveAsyncException()) { |
Alex Light | b7edcda | 2017-04-27 13:20:31 -0700 | [diff] [blame] | 1159 | return GetTwoWordFailureValue(); |
| 1160 | } |
| 1161 | return return_or_deoptimize_pc; |
| 1162 | } |
| 1163 | |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1164 | static std::string DumpInstruction(ArtMethod* method, uint32_t dex_pc) |
| 1165 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1166 | if (dex_pc == static_cast<uint32_t>(-1)) { |
| 1167 | CHECK(method == jni::DecodeArtMethod(WellKnownClasses::java_lang_String_charAt)); |
| 1168 | return "<native>"; |
| 1169 | } else { |
| 1170 | CodeItemInstructionAccessor accessor = method->DexInstructions(); |
| 1171 | CHECK_LT(dex_pc, accessor.InsnsSizeInCodeUnits()); |
| 1172 | return accessor.InstructionAt(dex_pc).DumpString(method->GetDexFile()); |
| 1173 | } |
| 1174 | } |
| 1175 | |
Vladimir Marko | 606adb3 | 2018-04-05 14:49:24 +0100 | [diff] [blame] | 1176 | static void DumpB74410240ClassData(ObjPtr<mirror::Class> klass) |
| 1177 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1178 | std::string storage; |
| 1179 | const char* descriptor = klass->GetDescriptor(&storage); |
| 1180 | LOG(FATAL_WITHOUT_ABORT) << " " << DescribeLoaders(klass->GetClassLoader(), descriptor); |
| 1181 | const OatDexFile* oat_dex_file = klass->GetDexFile().GetOatDexFile(); |
| 1182 | if (oat_dex_file != nullptr) { |
| 1183 | const OatFile* oat_file = oat_dex_file->GetOatFile(); |
| 1184 | const char* dex2oat_cmdline = |
| 1185 | oat_file->GetOatHeader().GetStoreValueByKey(OatHeader::kDex2OatCmdLineKey); |
| 1186 | LOG(FATAL_WITHOUT_ABORT) << " OatFile: " << oat_file->GetLocation() |
| 1187 | << "; " << (dex2oat_cmdline != nullptr ? dex2oat_cmdline : "<not recorded>"); |
| 1188 | } |
| 1189 | } |
| 1190 | |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1191 | static void DumpB74410240DebugData(ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 1192 | // Mimick the search for the caller and dump some data while doing so. |
Vladimir Marko | 606adb3 | 2018-04-05 14:49:24 +0100 | [diff] [blame] | 1193 | LOG(FATAL_WITHOUT_ABORT) << "Dumping debugging data, please attach a bugreport to b/74410240."; |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1194 | |
| 1195 | constexpr CalleeSaveType type = CalleeSaveType::kSaveRefsAndArgs; |
| 1196 | CHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(type)); |
| 1197 | |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 1198 | constexpr size_t callee_frame_size = RuntimeCalleeSaveFrame::GetFrameSize(type); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1199 | auto** caller_sp = reinterpret_cast<ArtMethod**>( |
| 1200 | reinterpret_cast<uintptr_t>(sp) + callee_frame_size); |
Vladimir Marko | d3083dd | 2018-05-17 08:43:47 +0100 | [diff] [blame] | 1201 | constexpr size_t callee_return_pc_offset = RuntimeCalleeSaveFrame::GetReturnPcOffset(type); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1202 | uintptr_t caller_pc = *reinterpret_cast<uintptr_t*>( |
| 1203 | (reinterpret_cast<uint8_t*>(sp) + callee_return_pc_offset)); |
| 1204 | ArtMethod* outer_method = *caller_sp; |
| 1205 | |
| 1206 | if (UNLIKELY(caller_pc == reinterpret_cast<uintptr_t>(GetQuickInstrumentationExitPc()))) { |
| 1207 | LOG(FATAL_WITHOUT_ABORT) << "Method: " << outer_method->PrettyMethod() |
| 1208 | << " native pc: " << caller_pc << " Instrumented!"; |
| 1209 | return; |
| 1210 | } |
| 1211 | |
| 1212 | const OatQuickMethodHeader* current_code = outer_method->GetOatQuickMethodHeader(caller_pc); |
| 1213 | CHECK(current_code != nullptr); |
| 1214 | CHECK(current_code->IsOptimized()); |
| 1215 | uintptr_t native_pc_offset = current_code->NativeQuickPcOffset(caller_pc); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 1216 | CodeInfo code_info(current_code); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1217 | MethodInfo method_info = current_code->GetOptimizedMethodInfo(); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 1218 | StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1219 | CHECK(stack_map.IsValid()); |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 1220 | uint32_t dex_pc = stack_map.GetDexPc(); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1221 | |
| 1222 | // Log the outer method and its associated dex file and class table pointer which can be used |
| 1223 | // to find out if the inlined methods were defined by other dex file(s) or class loader(s). |
| 1224 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 1225 | LOG(FATAL_WITHOUT_ABORT) << "Outer: " << outer_method->PrettyMethod() |
| 1226 | << " native pc: " << caller_pc |
| 1227 | << " dex pc: " << dex_pc |
| 1228 | << " dex file: " << outer_method->GetDexFile()->GetLocation() |
| 1229 | << " class table: " << class_linker->ClassTableForClassLoader(outer_method->GetClassLoader()); |
Vladimir Marko | 606adb3 | 2018-04-05 14:49:24 +0100 | [diff] [blame] | 1230 | DumpB74410240ClassData(outer_method->GetDeclaringClass()); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1231 | LOG(FATAL_WITHOUT_ABORT) << " instruction: " << DumpInstruction(outer_method, dex_pc); |
| 1232 | |
| 1233 | ArtMethod* caller = outer_method; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 1234 | if (stack_map.HasInlineInfo()) { |
| 1235 | InlineInfo inline_info = code_info.GetInlineInfoOf(stack_map); |
| 1236 | size_t depth = inline_info.GetDepth(); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1237 | for (size_t d = 0; d < depth; ++d) { |
| 1238 | const char* tag = ""; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 1239 | dex_pc = inline_info.GetDexPcAtDepth(d); |
| 1240 | if (inline_info.EncodesArtMethodAtDepth(d)) { |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1241 | tag = "encoded "; |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 1242 | caller = inline_info.GetArtMethodAtDepth(d); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1243 | } else { |
David Srbecky | 052f8ca | 2018-04-26 15:42:54 +0100 | [diff] [blame] | 1244 | uint32_t method_index = inline_info.GetMethodIndexAtDepth(method_info, d); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1245 | if (dex_pc == static_cast<uint32_t>(-1)) { |
| 1246 | tag = "special "; |
| 1247 | CHECK_EQ(d + 1u, depth); |
| 1248 | caller = jni::DecodeArtMethod(WellKnownClasses::java_lang_String_charAt); |
| 1249 | CHECK_EQ(caller->GetDexMethodIndex(), method_index); |
| 1250 | } else { |
| 1251 | ObjPtr<mirror::DexCache> dex_cache = caller->GetDexCache(); |
| 1252 | ObjPtr<mirror::ClassLoader> class_loader = caller->GetClassLoader(); |
| 1253 | caller = class_linker->LookupResolvedMethod(method_index, dex_cache, class_loader); |
| 1254 | CHECK(caller != nullptr); |
| 1255 | } |
| 1256 | } |
| 1257 | LOG(FATAL_WITHOUT_ABORT) << "Inlined method #" << d << ": " << tag << caller->PrettyMethod() |
| 1258 | << " dex pc: " << dex_pc |
| 1259 | << " dex file: " << caller->GetDexFile()->GetLocation() |
| 1260 | << " class table: " |
Vladimir Marko | 606adb3 | 2018-04-05 14:49:24 +0100 | [diff] [blame] | 1261 | << class_linker->ClassTableForClassLoader(caller->GetClassLoader()); |
| 1262 | DumpB74410240ClassData(caller->GetDeclaringClass()); |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1263 | LOG(FATAL_WITHOUT_ABORT) << " instruction: " << DumpInstruction(caller, dex_pc); |
| 1264 | } |
| 1265 | } |
| 1266 | } |
| 1267 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1268 | // Lazily resolve a method for quick. Called by stub code. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1269 | extern "C" const void* artQuickResolutionTrampoline( |
| 1270 | ArtMethod* called, mirror::Object* receiver, Thread* self, ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1271 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | 3b45ef2 | 2015-05-26 21:34:09 -0700 | [diff] [blame] | 1272 | // The resolution trampoline stashes the resolved method into the callee-save frame to transport |
| 1273 | // it. Thus, when exiting, the stack cannot be verified (as the resolved method most likely |
| 1274 | // does not have the same stack layout as the callee-save method). |
| 1275 | ScopedQuickEntrypointChecks sqec(self, kIsDebugBuild, false); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1276 | // Start new JNI local reference state |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1277 | JNIEnvExt* env = self->GetJniEnv(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1278 | ScopedObjectAccessUnchecked soa(env); |
| 1279 | ScopedJniEnvLocalRefState env_state(env); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1280 | const char* old_cause = self->StartAssertNoThreadSuspension("Quick method resolution set up"); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1281 | |
| 1282 | // Compute details about the called method (avoid GCs) |
| 1283 | ClassLinker* linker = Runtime::Current()->GetClassLinker(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1284 | InvokeType invoke_type; |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1285 | MethodReference called_method(nullptr, 0); |
| 1286 | const bool called_method_known_on_entry = !called->IsRuntimeMethod(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1287 | ArtMethod* caller = nullptr; |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1288 | if (!called_method_known_on_entry) { |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 1289 | caller = QuickArgumentVisitor::GetCallingMethod(sp); |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1290 | called_method.dex_file = caller->GetDexFile(); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1291 | |
| 1292 | InvokeType stack_map_invoke_type; |
| 1293 | uint32_t stack_map_dex_method_idx; |
| 1294 | const bool found_stack_map = QuickArgumentVisitor::GetInvokeType(sp, |
| 1295 | &stack_map_invoke_type, |
| 1296 | &stack_map_dex_method_idx); |
| 1297 | // For debug builds, we make sure both of the paths are consistent by also looking at the dex |
| 1298 | // code. |
| 1299 | if (!found_stack_map || kIsDebugBuild) { |
| 1300 | uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp); |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 1301 | CodeItemInstructionAccessor accessor(caller->DexInstructions()); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 1302 | CHECK_LT(dex_pc, accessor.InsnsSizeInCodeUnits()); |
| 1303 | const Instruction& instr = accessor.InstructionAt(dex_pc); |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 1304 | Instruction::Code instr_code = instr.Opcode(); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1305 | bool is_range; |
| 1306 | switch (instr_code) { |
| 1307 | case Instruction::INVOKE_DIRECT: |
| 1308 | invoke_type = kDirect; |
| 1309 | is_range = false; |
| 1310 | break; |
| 1311 | case Instruction::INVOKE_DIRECT_RANGE: |
| 1312 | invoke_type = kDirect; |
| 1313 | is_range = true; |
| 1314 | break; |
| 1315 | case Instruction::INVOKE_STATIC: |
| 1316 | invoke_type = kStatic; |
| 1317 | is_range = false; |
| 1318 | break; |
| 1319 | case Instruction::INVOKE_STATIC_RANGE: |
| 1320 | invoke_type = kStatic; |
| 1321 | is_range = true; |
| 1322 | break; |
| 1323 | case Instruction::INVOKE_SUPER: |
| 1324 | invoke_type = kSuper; |
| 1325 | is_range = false; |
| 1326 | break; |
| 1327 | case Instruction::INVOKE_SUPER_RANGE: |
| 1328 | invoke_type = kSuper; |
| 1329 | is_range = true; |
| 1330 | break; |
| 1331 | case Instruction::INVOKE_VIRTUAL: |
| 1332 | invoke_type = kVirtual; |
| 1333 | is_range = false; |
| 1334 | break; |
| 1335 | case Instruction::INVOKE_VIRTUAL_RANGE: |
| 1336 | invoke_type = kVirtual; |
| 1337 | is_range = true; |
| 1338 | break; |
| 1339 | case Instruction::INVOKE_INTERFACE: |
| 1340 | invoke_type = kInterface; |
| 1341 | is_range = false; |
| 1342 | break; |
| 1343 | case Instruction::INVOKE_INTERFACE_RANGE: |
| 1344 | invoke_type = kInterface; |
| 1345 | is_range = true; |
| 1346 | break; |
| 1347 | default: |
Vladimir Marko | 5b4b9a0 | 2018-03-16 09:42:09 +0000 | [diff] [blame] | 1348 | DumpB74410240DebugData(sp); |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 1349 | LOG(FATAL) << "Unexpected call into trampoline: " << instr.DumpString(nullptr); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1350 | UNREACHABLE(); |
| 1351 | } |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 1352 | called_method.index = (is_range) ? instr.VRegB_3rc() : instr.VRegB_35c(); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1353 | // Check that the invoke matches what we expected, note that this path only happens for debug |
| 1354 | // builds. |
| 1355 | if (found_stack_map) { |
| 1356 | DCHECK_EQ(stack_map_invoke_type, invoke_type); |
| 1357 | if (invoke_type != kSuper) { |
| 1358 | // Super may be sharpened. |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1359 | DCHECK_EQ(stack_map_dex_method_idx, called_method.index) |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1360 | << called_method.dex_file->PrettyMethod(stack_map_dex_method_idx) << " " |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1361 | << called_method.PrettyMethod(); |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1362 | } |
| 1363 | } else { |
Andreas Gampe | 9e6dee2 | 2017-04-11 13:50:23 -0700 | [diff] [blame] | 1364 | VLOG(dex) << "Accessed dex file for invoke " << invoke_type << " " |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1365 | << called_method.index; |
Mathieu Chartier | d776ff0 | 2017-01-17 09:32:18 -0800 | [diff] [blame] | 1366 | } |
| 1367 | } else { |
| 1368 | invoke_type = stack_map_invoke_type; |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1369 | called_method.index = stack_map_dex_method_idx; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1370 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1371 | } else { |
| 1372 | invoke_type = kStatic; |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1373 | called_method.dex_file = called->GetDexFile(); |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1374 | called_method.index = called->GetDexMethodIndex(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1375 | } |
| 1376 | uint32_t shorty_len; |
| 1377 | const char* shorty = |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1378 | called_method.dex_file->GetMethodShorty(called_method.GetMethodId(), &shorty_len); |
Mathieu Chartier | 590fee9 | 2013-09-13 13:46:47 -0700 | [diff] [blame] | 1379 | RememberForGcArgumentVisitor visitor(sp, invoke_type == kStatic, shorty, shorty_len, &soa); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1380 | visitor.VisitArguments(); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1381 | self->EndAssertNoThreadSuspension(old_cause); |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1382 | const bool virtual_or_interface = invoke_type == kVirtual || invoke_type == kInterface; |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1383 | // Resolve method filling in dex cache. |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1384 | if (!called_method_known_on_entry) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1385 | StackHandleScope<1> hs(self); |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 1386 | mirror::Object* dummy = nullptr; |
| 1387 | HandleWrapper<mirror::Object> h_receiver( |
| 1388 | hs.NewHandleWrapper(virtual_or_interface ? &receiver : &dummy)); |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1389 | DCHECK_EQ(caller->GetDexFile(), called_method.dex_file); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1390 | called = linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( |
Mathieu Chartier | fc8b422 | 2017-09-17 13:44:24 -0700 | [diff] [blame] | 1391 | self, called_method.index, caller, invoke_type); |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1392 | |
| 1393 | // Update .bss entry in oat file if any. |
| 1394 | if (called != nullptr && called_method.dex_file->GetOatDexFile() != nullptr) { |
Vladimir Marko | f3c52b4 | 2017-11-17 17:32:12 +0000 | [diff] [blame] | 1395 | size_t bss_offset = IndexBssMappingLookup::GetBssOffset( |
| 1396 | called_method.dex_file->GetOatDexFile()->GetMethodBssMapping(), |
| 1397 | called_method.index, |
| 1398 | called_method.dex_file->NumMethodIds(), |
| 1399 | static_cast<size_t>(kRuntimePointerSize)); |
| 1400 | if (bss_offset != IndexBssMappingLookup::npos) { |
| 1401 | DCHECK_ALIGNED(bss_offset, static_cast<size_t>(kRuntimePointerSize)); |
| 1402 | const OatFile* oat_file = called_method.dex_file->GetOatDexFile()->GetOatFile(); |
| 1403 | ArtMethod** method_entry = reinterpret_cast<ArtMethod**>(const_cast<uint8_t*>( |
| 1404 | oat_file->BssBegin() + bss_offset)); |
| 1405 | DCHECK_GE(method_entry, oat_file->GetBssMethods().data()); |
| 1406 | DCHECK_LT(method_entry, |
| 1407 | oat_file->GetBssMethods().data() + oat_file->GetBssMethods().size()); |
| 1408 | *method_entry = called; |
Vladimir Marko | 0eb882b | 2017-05-15 13:39:18 +0100 | [diff] [blame] | 1409 | } |
| 1410 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1411 | } |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1412 | const void* code = nullptr; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1413 | if (LIKELY(!self->IsExceptionPending())) { |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1414 | // Incompatible class change should have been handled in resolve method. |
Brian Carlstrom | 2ec6520 | 2014-03-03 15:16:37 -0800 | [diff] [blame] | 1415 | CHECK(!called->CheckIncompatibleClassChange(invoke_type)) |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1416 | << called->PrettyMethod() << " " << invoke_type; |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1417 | if (virtual_or_interface || invoke_type == kSuper) { |
| 1418 | // Refine called method based on receiver for kVirtual/kInterface, and |
| 1419 | // caller for kSuper. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1420 | ArtMethod* orig_called = called; |
Mathieu Chartier | 55871bf | 2014-02-27 10:24:50 -0800 | [diff] [blame] | 1421 | if (invoke_type == kVirtual) { |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1422 | CHECK(receiver != nullptr) << invoke_type; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1423 | called = receiver->GetClass()->FindVirtualMethodForVirtual(called, kRuntimePointerSize); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1424 | } else if (invoke_type == kInterface) { |
| 1425 | CHECK(receiver != nullptr) << invoke_type; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1426 | called = receiver->GetClass()->FindVirtualMethodForInterface(called, kRuntimePointerSize); |
Nicolas Geoffray | e523423 | 2015-12-02 09:06:11 +0000 | [diff] [blame] | 1427 | } else { |
| 1428 | DCHECK_EQ(invoke_type, kSuper); |
| 1429 | CHECK(caller != nullptr) << invoke_type; |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 1430 | ObjPtr<mirror::Class> ref_class = linker->LookupResolvedType( |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 1431 | caller->GetDexFile()->GetMethodId(called_method.index).class_idx_, caller); |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 1432 | if (ref_class->IsInterface()) { |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1433 | called = ref_class->FindVirtualMethodForInterfaceSuper(called, kRuntimePointerSize); |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 1434 | } else { |
| 1435 | called = caller->GetDeclaringClass()->GetSuperClass()->GetVTableEntry( |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1436 | called->GetMethodIndex(), kRuntimePointerSize); |
Alex Light | fedd91d | 2016-01-07 14:49:16 -0800 | [diff] [blame] | 1437 | } |
Mathieu Chartier | 55871bf | 2014-02-27 10:24:50 -0800 | [diff] [blame] | 1438 | } |
Mingyao Yang | f486778 | 2014-05-05 11:55:02 -0700 | [diff] [blame] | 1439 | |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 1440 | CHECK(called != nullptr) << orig_called->PrettyMethod() << " " |
| 1441 | << mirror::Object::PrettyTypeOf(receiver) << " " |
Mingyao Yang | f486778 | 2014-05-05 11:55:02 -0700 | [diff] [blame] | 1442 | << invoke_type << " " << orig_called->GetVtableIndex(); |
Ian Rogers | 83883d7 | 2013-10-21 21:07:24 -0700 | [diff] [blame] | 1443 | } |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 1444 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1445 | // Ensure that the called method's class is initialized. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1446 | StackHandleScope<1> hs(soa.Self()); |
| 1447 | Handle<mirror::Class> called_class(hs.NewHandle(called->GetDeclaringClass())); |
Ian Rogers | 7b078e8 | 2014-09-10 14:44:24 -0700 | [diff] [blame] | 1448 | linker->EnsureInitialized(soa.Self(), called_class, true, true); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1449 | if (LIKELY(called_class->IsInitialized())) { |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 1450 | if (UNLIKELY(Dbg::IsForcedInterpreterNeededForResolution(self, called))) { |
| 1451 | // If we are single-stepping or the called method is deoptimized (by a |
| 1452 | // breakpoint, for example), then we have to execute the called method |
| 1453 | // with the interpreter. |
| 1454 | code = GetQuickToInterpreterBridge(); |
| 1455 | } else if (UNLIKELY(Dbg::IsForcedInstrumentationNeededForResolution(self, caller))) { |
| 1456 | // If the caller is deoptimized (by a breakpoint, for example), we have to |
| 1457 | // continue its execution with interpreter when returning from the called |
| 1458 | // method. Because we do not want to execute the called method with the |
| 1459 | // interpreter, we wrap its execution into the instrumentation stubs. |
| 1460 | // When the called method returns, it will execute the instrumentation |
| 1461 | // exit hook that will determine the need of the interpreter with a call |
| 1462 | // to Dbg::IsForcedInterpreterNeededForUpcall and deoptimize the stack if |
| 1463 | // it is needed. |
| 1464 | code = GetQuickInstrumentationEntryPoint(); |
| 1465 | } else { |
| 1466 | code = called->GetEntryPointFromQuickCompiledCode(); |
| 1467 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1468 | } else if (called_class->IsInitializing()) { |
Daniel Mihalyi | eb07669 | 2014-08-22 17:33:31 +0200 | [diff] [blame] | 1469 | if (UNLIKELY(Dbg::IsForcedInterpreterNeededForResolution(self, called))) { |
| 1470 | // If we are single-stepping or the called method is deoptimized (by a |
| 1471 | // breakpoint, for example), then we have to execute the called method |
| 1472 | // with the interpreter. |
| 1473 | code = GetQuickToInterpreterBridge(); |
| 1474 | } else if (invoke_type == kStatic) { |
Alex Light | fc49fec | 2018-01-16 22:28:36 +0000 | [diff] [blame] | 1475 | // Class is still initializing, go to oat and grab code (trampoline must be left in place |
| 1476 | // until class is initialized to stop races between threads). |
| 1477 | code = linker->GetQuickOatCodeFor(called); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1478 | } else { |
| 1479 | // No trampoline for non-static methods. |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 1480 | code = called->GetEntryPointFromQuickCompiledCode(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1481 | } |
| 1482 | } else { |
| 1483 | DCHECK(called_class->IsErroneous()); |
| 1484 | } |
| 1485 | } |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1486 | CHECK_EQ(code == nullptr, self->IsExceptionPending()); |
Mathieu Chartier | 07d447b | 2013-09-26 11:57:43 -0700 | [diff] [blame] | 1487 | // Fixup any locally saved objects may have moved during a GC. |
| 1488 | visitor.FixupReferences(); |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1489 | // Place called method in callee-save frame to be placed as first argument to quick method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1490 | *sp = called; |
| 1491 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 1492 | return code; |
| 1493 | } |
| 1494 | |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1495 | /* |
| 1496 | * This class uses a couple of observations to unite the different calling conventions through |
| 1497 | * a few constants. |
| 1498 | * |
| 1499 | * 1) Number of registers used for passing is normally even, so counting down has no penalty for |
| 1500 | * possible alignment. |
| 1501 | * 2) Known 64b architectures store 8B units on the stack, both for integral and floating point |
| 1502 | * types, so using uintptr_t is OK. Also means that we can use kRegistersNeededX to denote |
| 1503 | * when we have to split things |
| 1504 | * 3) The only soft-float, Arm, is 32b, so no widening needs to be taken into account for floats |
| 1505 | * and we can use Int handling directly. |
| 1506 | * 4) Only 64b architectures widen, and their stack is aligned 8B anyways, so no padding code |
| 1507 | * necessary when widening. Also, widening of Ints will take place implicitly, and the |
| 1508 | * extension should be compatible with Aarch64, which mandates copying the available bits |
| 1509 | * into LSB and leaving the rest unspecified. |
| 1510 | * 5) Aligning longs and doubles is necessary on arm only, and it's the same in registers and on |
| 1511 | * the stack. |
| 1512 | * 6) There is only little endian. |
| 1513 | * |
| 1514 | * |
| 1515 | * Actual work is supposed to be done in a delegate of the template type. The interface is as |
| 1516 | * follows: |
| 1517 | * |
| 1518 | * void PushGpr(uintptr_t): Add a value for the next GPR |
| 1519 | * |
| 1520 | * void PushFpr4(float): Add a value for the next FPR of size 32b. Is only called if we need |
| 1521 | * padding, that is, think the architecture is 32b and aligns 64b. |
| 1522 | * |
| 1523 | * void PushFpr8(uint64_t): Push a double. We _will_ call this on 32b, it's the callee's job to |
| 1524 | * split this if necessary. The current state will have aligned, if |
| 1525 | * necessary. |
| 1526 | * |
| 1527 | * void PushStack(uintptr_t): Push a value to the stack. |
| 1528 | * |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1529 | * uintptr_t PushHandleScope(mirror::Object* ref): Add a reference to the HandleScope. This _will_ have nullptr, |
Andreas Gampe | 36fea8d | 2014-03-10 13:37:40 -0700 | [diff] [blame] | 1530 | * as this might be important for null initialization. |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1531 | * Must return the jobject, that is, the reference to the |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1532 | * entry in the HandleScope (nullptr if necessary). |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1533 | * |
| 1534 | */ |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1535 | template<class T> class BuildNativeCallFrameStateMachine { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1536 | public: |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1537 | #if defined(__arm__) |
| 1538 | // TODO: These are all dummy values! |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1539 | static constexpr bool kNativeSoftFloatAbi = true; |
| 1540 | static constexpr size_t kNumNativeGprArgs = 4; // 4 arguments passed in GPRs, r0-r3 |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1541 | static constexpr size_t kNumNativeFprArgs = 0; // 0 arguments passed in FPRs. |
| 1542 | |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1543 | static constexpr size_t kRegistersNeededForLong = 2; |
| 1544 | static constexpr size_t kRegistersNeededForDouble = 2; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1545 | static constexpr bool kMultiRegistersAligned = true; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1546 | static constexpr bool kMultiFPRegistersWidened = false; |
| 1547 | static constexpr bool kMultiGPRegistersWidened = false; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1548 | static constexpr bool kAlignLongOnStack = true; |
| 1549 | static constexpr bool kAlignDoubleOnStack = true; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1550 | #elif defined(__aarch64__) |
| 1551 | static constexpr bool kNativeSoftFloatAbi = false; // This is a hard float ABI. |
| 1552 | static constexpr size_t kNumNativeGprArgs = 8; // 6 arguments passed in GPRs. |
| 1553 | static constexpr size_t kNumNativeFprArgs = 8; // 8 arguments passed in FPRs. |
| 1554 | |
| 1555 | static constexpr size_t kRegistersNeededForLong = 1; |
| 1556 | static constexpr size_t kRegistersNeededForDouble = 1; |
| 1557 | static constexpr bool kMultiRegistersAligned = false; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1558 | static constexpr bool kMultiFPRegistersWidened = false; |
| 1559 | static constexpr bool kMultiGPRegistersWidened = false; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1560 | static constexpr bool kAlignLongOnStack = false; |
| 1561 | static constexpr bool kAlignDoubleOnStack = false; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1562 | #elif defined(__mips__) && !defined(__LP64__) |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1563 | static constexpr bool kNativeSoftFloatAbi = true; // This is a hard float ABI. |
Douglas Leung | 735b855 | 2014-10-31 12:21:40 -0700 | [diff] [blame] | 1564 | static constexpr size_t kNumNativeGprArgs = 4; // 4 arguments passed in GPRs. |
| 1565 | static constexpr size_t kNumNativeFprArgs = 0; // 0 arguments passed in FPRs. |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1566 | |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1567 | static constexpr size_t kRegistersNeededForLong = 2; |
| 1568 | static constexpr size_t kRegistersNeededForDouble = 2; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1569 | static constexpr bool kMultiRegistersAligned = true; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1570 | static constexpr bool kMultiFPRegistersWidened = true; |
| 1571 | static constexpr bool kMultiGPRegistersWidened = false; |
Douglas Leung | 735b855 | 2014-10-31 12:21:40 -0700 | [diff] [blame] | 1572 | static constexpr bool kAlignLongOnStack = true; |
| 1573 | static constexpr bool kAlignDoubleOnStack = true; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1574 | #elif defined(__mips__) && defined(__LP64__) |
| 1575 | // Let the code prepare GPRs only and we will load the FPRs with same data. |
| 1576 | static constexpr bool kNativeSoftFloatAbi = true; |
| 1577 | static constexpr size_t kNumNativeGprArgs = 8; |
| 1578 | static constexpr size_t kNumNativeFprArgs = 0; |
| 1579 | |
| 1580 | static constexpr size_t kRegistersNeededForLong = 1; |
| 1581 | static constexpr size_t kRegistersNeededForDouble = 1; |
| 1582 | static constexpr bool kMultiRegistersAligned = false; |
| 1583 | static constexpr bool kMultiFPRegistersWidened = false; |
| 1584 | static constexpr bool kMultiGPRegistersWidened = true; |
| 1585 | static constexpr bool kAlignLongOnStack = false; |
| 1586 | static constexpr bool kAlignDoubleOnStack = false; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1587 | #elif defined(__i386__) |
| 1588 | // TODO: Check these! |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1589 | static constexpr bool kNativeSoftFloatAbi = false; // Not using int registers for fp |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1590 | static constexpr size_t kNumNativeGprArgs = 0; // 6 arguments passed in GPRs. |
| 1591 | static constexpr size_t kNumNativeFprArgs = 0; // 8 arguments passed in FPRs. |
| 1592 | |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1593 | static constexpr size_t kRegistersNeededForLong = 2; |
| 1594 | static constexpr size_t kRegistersNeededForDouble = 2; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1595 | static constexpr bool kMultiRegistersAligned = false; // x86 not using regs, anyways |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1596 | static constexpr bool kMultiFPRegistersWidened = false; |
| 1597 | static constexpr bool kMultiGPRegistersWidened = false; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1598 | static constexpr bool kAlignLongOnStack = false; |
| 1599 | static constexpr bool kAlignDoubleOnStack = false; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1600 | #elif defined(__x86_64__) |
| 1601 | static constexpr bool kNativeSoftFloatAbi = false; // This is a hard float ABI. |
| 1602 | static constexpr size_t kNumNativeGprArgs = 6; // 6 arguments passed in GPRs. |
| 1603 | static constexpr size_t kNumNativeFprArgs = 8; // 8 arguments passed in FPRs. |
| 1604 | |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1605 | static constexpr size_t kRegistersNeededForLong = 1; |
| 1606 | static constexpr size_t kRegistersNeededForDouble = 1; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1607 | static constexpr bool kMultiRegistersAligned = false; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1608 | static constexpr bool kMultiFPRegistersWidened = false; |
| 1609 | static constexpr bool kMultiGPRegistersWidened = false; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1610 | static constexpr bool kAlignLongOnStack = false; |
| 1611 | static constexpr bool kAlignDoubleOnStack = false; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1612 | #else |
| 1613 | #error "Unsupported architecture" |
| 1614 | #endif |
| 1615 | |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1616 | public: |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1617 | explicit BuildNativeCallFrameStateMachine(T* delegate) |
| 1618 | : gpr_index_(kNumNativeGprArgs), |
| 1619 | fpr_index_(kNumNativeFprArgs), |
| 1620 | stack_entries_(0), |
| 1621 | delegate_(delegate) { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1622 | // For register alignment, we want to assume that counters (gpr_index_, fpr_index_) are even iff |
| 1623 | // the next register is even; counting down is just to make the compiler happy... |
Andreas Gampe | 575e78c | 2014-11-03 23:41:03 -0800 | [diff] [blame] | 1624 | static_assert(kNumNativeGprArgs % 2 == 0U, "Number of native GPR arguments not even"); |
| 1625 | static_assert(kNumNativeFprArgs % 2 == 0U, "Number of native FPR arguments not even"); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1626 | } |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1627 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1628 | virtual ~BuildNativeCallFrameStateMachine() {} |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1629 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1630 | bool HavePointerGpr() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1631 | return gpr_index_ > 0; |
| 1632 | } |
| 1633 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1634 | void AdvancePointer(const void* val) { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1635 | if (HavePointerGpr()) { |
| 1636 | gpr_index_--; |
| 1637 | PushGpr(reinterpret_cast<uintptr_t>(val)); |
| 1638 | } else { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1639 | stack_entries_++; // TODO: have a field for pointer length as multiple of 32b |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1640 | PushStack(reinterpret_cast<uintptr_t>(val)); |
| 1641 | gpr_index_ = 0; |
| 1642 | } |
| 1643 | } |
| 1644 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1645 | bool HaveHandleScopeGpr() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1646 | return gpr_index_ > 0; |
| 1647 | } |
| 1648 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1649 | void AdvanceHandleScope(mirror::Object* ptr) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1650 | uintptr_t handle = PushHandle(ptr); |
| 1651 | if (HaveHandleScopeGpr()) { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1652 | gpr_index_--; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1653 | PushGpr(handle); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1654 | } else { |
| 1655 | stack_entries_++; |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1656 | PushStack(handle); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1657 | gpr_index_ = 0; |
| 1658 | } |
| 1659 | } |
| 1660 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1661 | bool HaveIntGpr() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1662 | return gpr_index_ > 0; |
| 1663 | } |
| 1664 | |
| 1665 | void AdvanceInt(uint32_t val) { |
| 1666 | if (HaveIntGpr()) { |
| 1667 | gpr_index_--; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1668 | if (kMultiGPRegistersWidened) { |
| 1669 | DCHECK_EQ(sizeof(uintptr_t), sizeof(int64_t)); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1670 | PushGpr(static_cast<int64_t>(bit_cast<int32_t, uint32_t>(val))); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1671 | } else { |
| 1672 | PushGpr(val); |
| 1673 | } |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1674 | } else { |
| 1675 | stack_entries_++; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1676 | if (kMultiGPRegistersWidened) { |
| 1677 | DCHECK_EQ(sizeof(uintptr_t), sizeof(int64_t)); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1678 | PushStack(static_cast<int64_t>(bit_cast<int32_t, uint32_t>(val))); |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1679 | } else { |
| 1680 | PushStack(val); |
| 1681 | } |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1682 | gpr_index_ = 0; |
| 1683 | } |
| 1684 | } |
| 1685 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1686 | bool HaveLongGpr() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1687 | return gpr_index_ >= kRegistersNeededForLong + (LongGprNeedsPadding() ? 1 : 0); |
| 1688 | } |
| 1689 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1690 | bool LongGprNeedsPadding() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1691 | return kRegistersNeededForLong > 1 && // only pad when using multiple registers |
| 1692 | kAlignLongOnStack && // and when it needs alignment |
| 1693 | (gpr_index_ & 1) == 1; // counter is odd, see constructor |
| 1694 | } |
| 1695 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1696 | bool LongStackNeedsPadding() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1697 | return kRegistersNeededForLong > 1 && // only pad when using multiple registers |
| 1698 | kAlignLongOnStack && // and when it needs 8B alignment |
| 1699 | (stack_entries_ & 1) == 1; // counter is odd |
| 1700 | } |
| 1701 | |
| 1702 | void AdvanceLong(uint64_t val) { |
| 1703 | if (HaveLongGpr()) { |
| 1704 | if (LongGprNeedsPadding()) { |
| 1705 | PushGpr(0); |
| 1706 | gpr_index_--; |
| 1707 | } |
| 1708 | if (kRegistersNeededForLong == 1) { |
| 1709 | PushGpr(static_cast<uintptr_t>(val)); |
| 1710 | } else { |
| 1711 | PushGpr(static_cast<uintptr_t>(val & 0xFFFFFFFF)); |
| 1712 | PushGpr(static_cast<uintptr_t>((val >> 32) & 0xFFFFFFFF)); |
| 1713 | } |
| 1714 | gpr_index_ -= kRegistersNeededForLong; |
| 1715 | } else { |
| 1716 | if (LongStackNeedsPadding()) { |
| 1717 | PushStack(0); |
| 1718 | stack_entries_++; |
| 1719 | } |
| 1720 | if (kRegistersNeededForLong == 1) { |
| 1721 | PushStack(static_cast<uintptr_t>(val)); |
| 1722 | stack_entries_++; |
| 1723 | } else { |
| 1724 | PushStack(static_cast<uintptr_t>(val & 0xFFFFFFFF)); |
| 1725 | PushStack(static_cast<uintptr_t>((val >> 32) & 0xFFFFFFFF)); |
| 1726 | stack_entries_ += 2; |
| 1727 | } |
| 1728 | gpr_index_ = 0; |
| 1729 | } |
| 1730 | } |
| 1731 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1732 | bool HaveFloatFpr() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1733 | return fpr_index_ > 0; |
| 1734 | } |
| 1735 | |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1736 | void AdvanceFloat(float val) { |
| 1737 | if (kNativeSoftFloatAbi) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1738 | AdvanceInt(bit_cast<uint32_t, float>(val)); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1739 | } else { |
| 1740 | if (HaveFloatFpr()) { |
| 1741 | fpr_index_--; |
| 1742 | if (kRegistersNeededForDouble == 1) { |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1743 | if (kMultiFPRegistersWidened) { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1744 | PushFpr8(bit_cast<uint64_t, double>(val)); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1745 | } else { |
| 1746 | // No widening, just use the bits. |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1747 | PushFpr8(static_cast<uint64_t>(bit_cast<uint32_t, float>(val))); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1748 | } |
| 1749 | } else { |
| 1750 | PushFpr4(val); |
| 1751 | } |
| 1752 | } else { |
| 1753 | stack_entries_++; |
Andreas Gampe | 1a5c406 | 2015-01-15 12:10:47 -0800 | [diff] [blame] | 1754 | if (kRegistersNeededForDouble == 1 && kMultiFPRegistersWidened) { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1755 | // Need to widen before storing: Note the "double" in the template instantiation. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1756 | // Note: We need to jump through those hoops to make the compiler happy. |
| 1757 | DCHECK_EQ(sizeof(uintptr_t), sizeof(uint64_t)); |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1758 | PushStack(static_cast<uintptr_t>(bit_cast<uint64_t, double>(val))); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1759 | } else { |
Roland Levillain | da4d79b | 2015-03-24 14:36:11 +0000 | [diff] [blame] | 1760 | PushStack(static_cast<uintptr_t>(bit_cast<uint32_t, float>(val))); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1761 | } |
| 1762 | fpr_index_ = 0; |
| 1763 | } |
| 1764 | } |
| 1765 | } |
| 1766 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1767 | bool HaveDoubleFpr() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1768 | return fpr_index_ >= kRegistersNeededForDouble + (DoubleFprNeedsPadding() ? 1 : 0); |
| 1769 | } |
| 1770 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1771 | bool DoubleFprNeedsPadding() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1772 | return kRegistersNeededForDouble > 1 && // only pad when using multiple registers |
| 1773 | kAlignDoubleOnStack && // and when it needs alignment |
| 1774 | (fpr_index_ & 1) == 1; // counter is odd, see constructor |
| 1775 | } |
| 1776 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1777 | bool DoubleStackNeedsPadding() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1778 | return kRegistersNeededForDouble > 1 && // only pad when using multiple registers |
| 1779 | kAlignDoubleOnStack && // and when it needs 8B alignment |
| 1780 | (stack_entries_ & 1) == 1; // counter is odd |
| 1781 | } |
| 1782 | |
| 1783 | void AdvanceDouble(uint64_t val) { |
| 1784 | if (kNativeSoftFloatAbi) { |
| 1785 | AdvanceLong(val); |
| 1786 | } else { |
| 1787 | if (HaveDoubleFpr()) { |
| 1788 | if (DoubleFprNeedsPadding()) { |
| 1789 | PushFpr4(0); |
| 1790 | fpr_index_--; |
| 1791 | } |
| 1792 | PushFpr8(val); |
| 1793 | fpr_index_ -= kRegistersNeededForDouble; |
| 1794 | } else { |
| 1795 | if (DoubleStackNeedsPadding()) { |
| 1796 | PushStack(0); |
| 1797 | stack_entries_++; |
| 1798 | } |
| 1799 | if (kRegistersNeededForDouble == 1) { |
| 1800 | PushStack(static_cast<uintptr_t>(val)); |
| 1801 | stack_entries_++; |
| 1802 | } else { |
| 1803 | PushStack(static_cast<uintptr_t>(val & 0xFFFFFFFF)); |
| 1804 | PushStack(static_cast<uintptr_t>((val >> 32) & 0xFFFFFFFF)); |
| 1805 | stack_entries_ += 2; |
| 1806 | } |
| 1807 | fpr_index_ = 0; |
| 1808 | } |
| 1809 | } |
| 1810 | } |
| 1811 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1812 | uint32_t GetStackEntries() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1813 | return stack_entries_; |
| 1814 | } |
| 1815 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1816 | uint32_t GetNumberOfUsedGprs() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1817 | return kNumNativeGprArgs - gpr_index_; |
| 1818 | } |
| 1819 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1820 | uint32_t GetNumberOfUsedFprs() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1821 | return kNumNativeFprArgs - fpr_index_; |
| 1822 | } |
| 1823 | |
| 1824 | private: |
| 1825 | void PushGpr(uintptr_t val) { |
| 1826 | delegate_->PushGpr(val); |
| 1827 | } |
| 1828 | void PushFpr4(float val) { |
| 1829 | delegate_->PushFpr4(val); |
| 1830 | } |
| 1831 | void PushFpr8(uint64_t val) { |
| 1832 | delegate_->PushFpr8(val); |
| 1833 | } |
| 1834 | void PushStack(uintptr_t val) { |
| 1835 | delegate_->PushStack(val); |
| 1836 | } |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1837 | uintptr_t PushHandle(mirror::Object* ref) REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 1838 | return delegate_->PushHandle(ref); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1839 | } |
| 1840 | |
| 1841 | uint32_t gpr_index_; // Number of free GPRs |
| 1842 | uint32_t fpr_index_; // Number of free FPRs |
| 1843 | uint32_t stack_entries_; // Stack entries are in multiples of 32b, as floats are usually not |
| 1844 | // extended |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1845 | T* const delegate_; // What Push implementation gets called |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1846 | }; |
| 1847 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1848 | // Computes the sizes of register stacks and call stack area. Handling of references can be extended |
| 1849 | // in subclasses. |
| 1850 | // |
| 1851 | // To handle native pointers, use "L" in the shorty for an object reference, which simulates |
| 1852 | // them with handles. |
| 1853 | class ComputeNativeCallFrameSize { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1854 | public: |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1855 | ComputeNativeCallFrameSize() : num_stack_entries_(0) {} |
| 1856 | |
| 1857 | virtual ~ComputeNativeCallFrameSize() {} |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1858 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1859 | uint32_t GetStackSize() const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1860 | return num_stack_entries_ * sizeof(uintptr_t); |
| 1861 | } |
| 1862 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1863 | uint8_t* LayoutCallStack(uint8_t* sp8) const { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1864 | sp8 -= GetStackSize(); |
Andreas Gampe | 779f8c9 | 2014-06-09 18:29:38 -0700 | [diff] [blame] | 1865 | // Align by kStackAlignment. |
| 1866 | sp8 = reinterpret_cast<uint8_t*>(RoundDown(reinterpret_cast<uintptr_t>(sp8), kStackAlignment)); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1867 | return sp8; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1868 | } |
| 1869 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1870 | uint8_t* LayoutCallRegisterStacks(uint8_t* sp8, uintptr_t** start_gpr, uint32_t** start_fpr) |
| 1871 | const { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1872 | // Assumption is OK right now, as we have soft-float arm |
| 1873 | size_t fregs = BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>::kNumNativeFprArgs; |
| 1874 | sp8 -= fregs * sizeof(uintptr_t); |
| 1875 | *start_fpr = reinterpret_cast<uint32_t*>(sp8); |
| 1876 | size_t iregs = BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>::kNumNativeGprArgs; |
| 1877 | sp8 -= iregs * sizeof(uintptr_t); |
| 1878 | *start_gpr = reinterpret_cast<uintptr_t*>(sp8); |
| 1879 | return sp8; |
| 1880 | } |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1881 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1882 | uint8_t* LayoutNativeCall(uint8_t* sp8, uintptr_t** start_stack, uintptr_t** start_gpr, |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1883 | uint32_t** start_fpr) const { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1884 | // Native call stack. |
| 1885 | sp8 = LayoutCallStack(sp8); |
| 1886 | *start_stack = reinterpret_cast<uintptr_t*>(sp8); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1887 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1888 | // Put fprs and gprs below. |
| 1889 | sp8 = LayoutCallRegisterStacks(sp8, start_gpr, start_fpr); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1890 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1891 | // Return the new bottom. |
| 1892 | return sp8; |
| 1893 | } |
| 1894 | |
Roland Levillain | 4b8f1ec | 2015-08-26 18:34:03 +0100 | [diff] [blame] | 1895 | virtual void WalkHeader( |
| 1896 | BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>* sm ATTRIBUTE_UNUSED) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1897 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 1898 | } |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1899 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1900 | void Walk(const char* shorty, uint32_t shorty_len) REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1901 | BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize> sm(this); |
| 1902 | |
| 1903 | WalkHeader(&sm); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1904 | |
| 1905 | for (uint32_t i = 1; i < shorty_len; ++i) { |
| 1906 | Primitive::Type cur_type_ = Primitive::GetType(shorty[i]); |
| 1907 | switch (cur_type_) { |
| 1908 | case Primitive::kPrimNot: |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1909 | // TODO: fix abuse of mirror types. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1910 | sm.AdvanceHandleScope( |
| 1911 | reinterpret_cast<mirror::Object*>(0x12345678)); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1912 | break; |
| 1913 | |
| 1914 | case Primitive::kPrimBoolean: |
| 1915 | case Primitive::kPrimByte: |
| 1916 | case Primitive::kPrimChar: |
| 1917 | case Primitive::kPrimShort: |
| 1918 | case Primitive::kPrimInt: |
| 1919 | sm.AdvanceInt(0); |
| 1920 | break; |
| 1921 | case Primitive::kPrimFloat: |
| 1922 | sm.AdvanceFloat(0); |
| 1923 | break; |
| 1924 | case Primitive::kPrimDouble: |
| 1925 | sm.AdvanceDouble(0); |
| 1926 | break; |
| 1927 | case Primitive::kPrimLong: |
| 1928 | sm.AdvanceLong(0); |
| 1929 | break; |
| 1930 | default: |
| 1931 | LOG(FATAL) << "Unexpected type: " << cur_type_ << " in " << shorty; |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 1932 | UNREACHABLE(); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1933 | } |
| 1934 | } |
| 1935 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 1936 | num_stack_entries_ = sm.GetStackEntries(); |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | void PushGpr(uintptr_t /* val */) { |
| 1940 | // not optimizing registers, yet |
| 1941 | } |
| 1942 | |
| 1943 | void PushFpr4(float /* val */) { |
| 1944 | // not optimizing registers, yet |
| 1945 | } |
| 1946 | |
| 1947 | void PushFpr8(uint64_t /* val */) { |
| 1948 | // not optimizing registers, yet |
| 1949 | } |
| 1950 | |
| 1951 | void PushStack(uintptr_t /* val */) { |
| 1952 | // counting is already done in the superclass |
| 1953 | } |
| 1954 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1955 | virtual uintptr_t PushHandle(mirror::Object* /* ptr */) { |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1956 | return reinterpret_cast<uintptr_t>(nullptr); |
| 1957 | } |
| 1958 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1959 | protected: |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 1960 | uint32_t num_stack_entries_; |
| 1961 | }; |
| 1962 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1963 | class ComputeGenericJniFrameSize FINAL : public ComputeNativeCallFrameSize { |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1964 | public: |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 1965 | explicit ComputeGenericJniFrameSize(bool critical_native) |
| 1966 | : num_handle_scope_references_(0), critical_native_(critical_native) {} |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1967 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1968 | // Lays out the callee-save frame. Assumes that the incorrect frame corresponding to RefsAndArgs |
| 1969 | // is at *m = sp. Will update to point to the bottom of the save frame. |
| 1970 | // |
| 1971 | // Note: assumes ComputeAll() has been run before. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1972 | void LayoutCalleeSaveFrame(Thread* self, ArtMethod*** m, void* sp, HandleScope** handle_scope) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 1973 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1974 | ArtMethod* method = **m; |
| 1975 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 1976 | DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), kRuntimePointerSize); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 1977 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1978 | uint8_t* sp8 = reinterpret_cast<uint8_t*>(sp); |
| 1979 | |
| 1980 | // First, fix up the layout of the callee-save frame. |
| 1981 | // We have to squeeze in the HandleScope, and relocate the method pointer. |
| 1982 | |
| 1983 | // "Free" the slot for the method. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 1984 | sp8 += sizeof(void*); // In the callee-save frame we use a full pointer. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1985 | |
| 1986 | // Under the callee saves put handle scope and new method stack reference. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1987 | size_t handle_scope_size = HandleScope::SizeOf(num_handle_scope_references_); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1988 | size_t scope_and_method = handle_scope_size + sizeof(ArtMethod*); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1989 | |
| 1990 | sp8 -= scope_and_method; |
| 1991 | // Align by kStackAlignment. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1992 | sp8 = reinterpret_cast<uint8_t*>(RoundDown(reinterpret_cast<uintptr_t>(sp8), kStackAlignment)); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1993 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 1994 | uint8_t* sp8_table = sp8 + sizeof(ArtMethod*); |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 1995 | *handle_scope = HandleScope::Create(sp8_table, self->GetTopHandleScope(), |
| 1996 | num_handle_scope_references_); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 1997 | |
| 1998 | // Add a slot for the method pointer, and fill it. Fix the pointer-pointer given to us. |
| 1999 | uint8_t* method_pointer = sp8; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2000 | auto** new_method_ref = reinterpret_cast<ArtMethod**>(method_pointer); |
| 2001 | *new_method_ref = method; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2002 | *m = new_method_ref; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2003 | } |
| 2004 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2005 | // Adds space for the cookie. Note: may leave stack unaligned. |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 2006 | void LayoutCookie(uint8_t** sp) const { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2007 | // Reference cookie and padding |
| 2008 | *sp -= 8; |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2011 | // Re-layout the callee-save frame (insert a handle-scope). Then add space for the cookie. |
| 2012 | // Returns the new bottom. Note: this may be unaligned. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2013 | uint8_t* LayoutJNISaveFrame(Thread* self, ArtMethod*** m, void* sp, HandleScope** handle_scope) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2014 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2015 | // First, fix up the layout of the callee-save frame. |
| 2016 | // We have to squeeze in the HandleScope, and relocate the method pointer. |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 2017 | LayoutCalleeSaveFrame(self, m, sp, handle_scope); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2018 | |
| 2019 | // The bottom of the callee-save frame is now where the method is, *m. |
| 2020 | uint8_t* sp8 = reinterpret_cast<uint8_t*>(*m); |
| 2021 | |
| 2022 | // Add space for cookie. |
| 2023 | LayoutCookie(&sp8); |
| 2024 | |
| 2025 | return sp8; |
| 2026 | } |
| 2027 | |
| 2028 | // WARNING: After this, *sp won't be pointing to the method anymore! |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2029 | uint8_t* ComputeLayout(Thread* self, ArtMethod*** m, const char* shorty, uint32_t shorty_len, |
| 2030 | HandleScope** handle_scope, uintptr_t** start_stack, uintptr_t** start_gpr, |
| 2031 | uint32_t** start_fpr) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2032 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2033 | Walk(shorty, shorty_len); |
| 2034 | |
| 2035 | // JNI part. |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 2036 | uint8_t* sp8 = LayoutJNISaveFrame(self, m, reinterpret_cast<void*>(*m), handle_scope); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2037 | |
| 2038 | sp8 = LayoutNativeCall(sp8, start_stack, start_gpr, start_fpr); |
| 2039 | |
| 2040 | // Return the new bottom. |
| 2041 | return sp8; |
| 2042 | } |
| 2043 | |
| 2044 | uintptr_t PushHandle(mirror::Object* /* ptr */) OVERRIDE; |
| 2045 | |
| 2046 | // Add JNIEnv* and jobj/jclass before the shorty-derived elements. |
| 2047 | void WalkHeader(BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>* sm) OVERRIDE |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2048 | REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2049 | |
| 2050 | private: |
| 2051 | uint32_t num_handle_scope_references_; |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2052 | const bool critical_native_; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2053 | }; |
| 2054 | |
| 2055 | uintptr_t ComputeGenericJniFrameSize::PushHandle(mirror::Object* /* ptr */) { |
| 2056 | num_handle_scope_references_++; |
| 2057 | return reinterpret_cast<uintptr_t>(nullptr); |
| 2058 | } |
| 2059 | |
| 2060 | void ComputeGenericJniFrameSize::WalkHeader( |
| 2061 | BuildNativeCallFrameStateMachine<ComputeNativeCallFrameSize>* sm) { |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2062 | // First 2 parameters are always excluded for @CriticalNative. |
| 2063 | if (UNLIKELY(critical_native_)) { |
| 2064 | return; |
| 2065 | } |
| 2066 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2067 | // JNIEnv |
| 2068 | sm->AdvancePointer(nullptr); |
| 2069 | |
| 2070 | // Class object or this as first argument |
| 2071 | sm->AdvanceHandleScope(reinterpret_cast<mirror::Object*>(0x12345678)); |
| 2072 | } |
| 2073 | |
| 2074 | // Class to push values to three separate regions. Used to fill the native call part. Adheres to |
| 2075 | // the template requirements of BuildGenericJniFrameStateMachine. |
| 2076 | class FillNativeCall { |
| 2077 | public: |
| 2078 | FillNativeCall(uintptr_t* gpr_regs, uint32_t* fpr_regs, uintptr_t* stack_args) : |
| 2079 | cur_gpr_reg_(gpr_regs), cur_fpr_reg_(fpr_regs), cur_stack_arg_(stack_args) {} |
| 2080 | |
| 2081 | virtual ~FillNativeCall() {} |
| 2082 | |
| 2083 | void Reset(uintptr_t* gpr_regs, uint32_t* fpr_regs, uintptr_t* stack_args) { |
| 2084 | cur_gpr_reg_ = gpr_regs; |
| 2085 | cur_fpr_reg_ = fpr_regs; |
| 2086 | cur_stack_arg_ = stack_args; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 2087 | } |
| 2088 | |
| 2089 | void PushGpr(uintptr_t val) { |
| 2090 | *cur_gpr_reg_ = val; |
| 2091 | cur_gpr_reg_++; |
| 2092 | } |
| 2093 | |
| 2094 | void PushFpr4(float val) { |
| 2095 | *cur_fpr_reg_ = val; |
| 2096 | cur_fpr_reg_++; |
| 2097 | } |
| 2098 | |
| 2099 | void PushFpr8(uint64_t val) { |
| 2100 | uint64_t* tmp = reinterpret_cast<uint64_t*>(cur_fpr_reg_); |
| 2101 | *tmp = val; |
| 2102 | cur_fpr_reg_ += 2; |
| 2103 | } |
| 2104 | |
| 2105 | void PushStack(uintptr_t val) { |
| 2106 | *cur_stack_arg_ = val; |
| 2107 | cur_stack_arg_++; |
| 2108 | } |
| 2109 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2110 | virtual uintptr_t PushHandle(mirror::Object*) REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2111 | LOG(FATAL) << "(Non-JNI) Native call does not use handles."; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2112 | UNREACHABLE(); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2113 | } |
| 2114 | |
| 2115 | private: |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2116 | uintptr_t* cur_gpr_reg_; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2117 | uint32_t* cur_fpr_reg_; |
| 2118 | uintptr_t* cur_stack_arg_; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2119 | }; |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 2120 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2121 | // Visits arguments on the stack placing them into a region lower down the stack for the benefit |
| 2122 | // of transitioning into native code. |
| 2123 | class BuildGenericJniFrameVisitor FINAL : public QuickArgumentVisitor { |
| 2124 | public: |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2125 | BuildGenericJniFrameVisitor(Thread* self, |
| 2126 | bool is_static, |
| 2127 | bool critical_native, |
| 2128 | const char* shorty, |
| 2129 | uint32_t shorty_len, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2130 | ArtMethod*** sp) |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2131 | : QuickArgumentVisitor(*sp, is_static, shorty, shorty_len), |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2132 | jni_call_(nullptr, nullptr, nullptr, nullptr, critical_native), |
| 2133 | sm_(&jni_call_) { |
| 2134 | ComputeGenericJniFrameSize fsc(critical_native); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2135 | uintptr_t* start_gpr_reg; |
| 2136 | uint32_t* start_fpr_reg; |
| 2137 | uintptr_t* start_stack_arg; |
Ian Rogers | 6a3c1fc | 2014-10-31 00:33:20 -0700 | [diff] [blame] | 2138 | bottom_of_used_area_ = fsc.ComputeLayout(self, sp, shorty, shorty_len, |
Ian Rogers | 59c0706 | 2014-10-10 13:03:39 -0700 | [diff] [blame] | 2139 | &handle_scope_, |
| 2140 | &start_stack_arg, |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2141 | &start_gpr_reg, &start_fpr_reg); |
| 2142 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2143 | jni_call_.Reset(start_gpr_reg, start_fpr_reg, start_stack_arg, handle_scope_); |
| 2144 | |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2145 | // First 2 parameters are always excluded for CriticalNative methods. |
| 2146 | if (LIKELY(!critical_native)) { |
| 2147 | // jni environment is always first argument |
| 2148 | sm_.AdvancePointer(self->GetJniEnv()); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2149 | |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2150 | if (is_static) { |
| 2151 | sm_.AdvanceHandleScope((**sp)->GetDeclaringClass()); |
| 2152 | } // else "this" reference is already handled by QuickArgumentVisitor. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2156 | void Visit() REQUIRES_SHARED(Locks::mutator_lock_) OVERRIDE; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2157 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2158 | void FinalizeHandleScope(Thread* self) REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2159 | |
Vladimir Marko | f39745e | 2016-01-26 12:16:55 +0000 | [diff] [blame] | 2160 | StackReference<mirror::Object>* GetFirstHandleScopeEntry() { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2161 | return handle_scope_->GetHandle(0).GetReference(); |
| 2162 | } |
| 2163 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2164 | jobject GetFirstHandleScopeJObject() const REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2165 | return handle_scope_->GetHandle(0).ToJObject(); |
| 2166 | } |
| 2167 | |
Ian Rogers | 1428dce | 2014-10-21 15:02:15 -0700 | [diff] [blame] | 2168 | void* GetBottomOfUsedArea() const { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2169 | return bottom_of_used_area_; |
| 2170 | } |
| 2171 | |
| 2172 | private: |
| 2173 | // A class to fill a JNI call. Adds reference/handle-scope management to FillNativeCall. |
| 2174 | class FillJniCall FINAL : public FillNativeCall { |
| 2175 | public: |
| 2176 | FillJniCall(uintptr_t* gpr_regs, uint32_t* fpr_regs, uintptr_t* stack_args, |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2177 | HandleScope* handle_scope, bool critical_native) |
| 2178 | : FillNativeCall(gpr_regs, fpr_regs, stack_args), |
| 2179 | handle_scope_(handle_scope), |
| 2180 | cur_entry_(0), |
| 2181 | critical_native_(critical_native) {} |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2182 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2183 | uintptr_t PushHandle(mirror::Object* ref) OVERRIDE REQUIRES_SHARED(Locks::mutator_lock_); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2184 | |
| 2185 | void Reset(uintptr_t* gpr_regs, uint32_t* fpr_regs, uintptr_t* stack_args, HandleScope* scope) { |
| 2186 | FillNativeCall::Reset(gpr_regs, fpr_regs, stack_args); |
| 2187 | handle_scope_ = scope; |
| 2188 | cur_entry_ = 0U; |
| 2189 | } |
| 2190 | |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2191 | void ResetRemainingScopeSlots() REQUIRES_SHARED(Locks::mutator_lock_) { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2192 | // Initialize padding entries. |
| 2193 | size_t expected_slots = handle_scope_->NumberOfReferences(); |
| 2194 | while (cur_entry_ < expected_slots) { |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 2195 | handle_scope_->GetMutableHandle(cur_entry_++).Assign(nullptr); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2196 | } |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2197 | |
| 2198 | if (!critical_native_) { |
| 2199 | // Non-critical natives have at least the self class (jclass) or this (jobject). |
| 2200 | DCHECK_NE(cur_entry_, 0U); |
| 2201 | } |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2202 | } |
| 2203 | |
Mathieu Chartier | 1432a5b | 2016-10-04 15:41:42 -0700 | [diff] [blame] | 2204 | bool CriticalNative() const { |
| 2205 | return critical_native_; |
| 2206 | } |
| 2207 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2208 | private: |
| 2209 | HandleScope* handle_scope_; |
| 2210 | size_t cur_entry_; |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2211 | const bool critical_native_; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2212 | }; |
| 2213 | |
| 2214 | HandleScope* handle_scope_; |
| 2215 | FillJniCall jni_call_; |
| 2216 | void* bottom_of_used_area_; |
| 2217 | |
| 2218 | BuildNativeCallFrameStateMachine<FillJniCall> sm_; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2219 | |
| 2220 | DISALLOW_COPY_AND_ASSIGN(BuildGenericJniFrameVisitor); |
| 2221 | }; |
| 2222 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2223 | uintptr_t BuildGenericJniFrameVisitor::FillJniCall::PushHandle(mirror::Object* ref) { |
| 2224 | uintptr_t tmp; |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 2225 | MutableHandle<mirror::Object> h = handle_scope_->GetMutableHandle(cur_entry_); |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2226 | h.Assign(ref); |
| 2227 | tmp = reinterpret_cast<uintptr_t>(h.ToJObject()); |
| 2228 | cur_entry_++; |
| 2229 | return tmp; |
| 2230 | } |
| 2231 | |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 2232 | void BuildGenericJniFrameVisitor::Visit() { |
| 2233 | Primitive::Type type = GetParamPrimitiveType(); |
| 2234 | switch (type) { |
| 2235 | case Primitive::kPrimLong: { |
| 2236 | jlong long_arg; |
| 2237 | if (IsSplitLongOrDouble()) { |
| 2238 | long_arg = ReadSplitLongParam(); |
| 2239 | } else { |
| 2240 | long_arg = *reinterpret_cast<jlong*>(GetParamAddress()); |
| 2241 | } |
| 2242 | sm_.AdvanceLong(long_arg); |
| 2243 | break; |
| 2244 | } |
| 2245 | case Primitive::kPrimDouble: { |
| 2246 | uint64_t double_arg; |
| 2247 | if (IsSplitLongOrDouble()) { |
| 2248 | // Read into union so that we don't case to a double. |
| 2249 | double_arg = ReadSplitLongParam(); |
| 2250 | } else { |
| 2251 | double_arg = *reinterpret_cast<uint64_t*>(GetParamAddress()); |
| 2252 | } |
| 2253 | sm_.AdvanceDouble(double_arg); |
| 2254 | break; |
| 2255 | } |
| 2256 | case Primitive::kPrimNot: { |
| 2257 | StackReference<mirror::Object>* stack_ref = |
| 2258 | reinterpret_cast<StackReference<mirror::Object>*>(GetParamAddress()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2259 | sm_.AdvanceHandleScope(stack_ref->AsMirrorPtr()); |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 2260 | break; |
| 2261 | } |
| 2262 | case Primitive::kPrimFloat: |
| 2263 | sm_.AdvanceFloat(*reinterpret_cast<float*>(GetParamAddress())); |
| 2264 | break; |
| 2265 | case Primitive::kPrimBoolean: // Fall-through. |
| 2266 | case Primitive::kPrimByte: // Fall-through. |
| 2267 | case Primitive::kPrimChar: // Fall-through. |
| 2268 | case Primitive::kPrimShort: // Fall-through. |
| 2269 | case Primitive::kPrimInt: // Fall-through. |
| 2270 | sm_.AdvanceInt(*reinterpret_cast<jint*>(GetParamAddress())); |
| 2271 | break; |
| 2272 | case Primitive::kPrimVoid: |
| 2273 | LOG(FATAL) << "UNREACHABLE"; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 2274 | UNREACHABLE(); |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 2275 | } |
| 2276 | } |
| 2277 | |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2278 | void BuildGenericJniFrameVisitor::FinalizeHandleScope(Thread* self) { |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2279 | // Clear out rest of the scope. |
| 2280 | jni_call_.ResetRemainingScopeSlots(); |
Mathieu Chartier | 1432a5b | 2016-10-04 15:41:42 -0700 | [diff] [blame] | 2281 | if (!jni_call_.CriticalNative()) { |
| 2282 | // Install HandleScope. |
| 2283 | self->PushHandleScope(handle_scope_); |
| 2284 | } |
Ian Rogers | 9758f79 | 2014-03-13 09:02:55 -0700 | [diff] [blame] | 2285 | } |
| 2286 | |
Ian Rogers | 04c31d2 | 2014-07-07 21:44:06 -0700 | [diff] [blame] | 2287 | #if defined(__arm__) || defined(__aarch64__) |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 2288 | extern "C" const void* artFindNativeMethod(); |
Ian Rogers | 04c31d2 | 2014-07-07 21:44:06 -0700 | [diff] [blame] | 2289 | #else |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 2290 | extern "C" const void* artFindNativeMethod(Thread* self); |
Ian Rogers | 04c31d2 | 2014-07-07 21:44:06 -0700 | [diff] [blame] | 2291 | #endif |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 2292 | |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2293 | static uint64_t artQuickGenericJniEndJNIRef(Thread* self, |
| 2294 | uint32_t cookie, |
| 2295 | bool fast_native ATTRIBUTE_UNUSED, |
| 2296 | jobject l, |
| 2297 | jobject lock) { |
| 2298 | // TODO: add entrypoints for @FastNative returning objects. |
Andreas Gampe | ad61517 | 2014-04-04 16:20:13 -0700 | [diff] [blame] | 2299 | if (lock != nullptr) { |
| 2300 | return reinterpret_cast<uint64_t>(JniMethodEndWithReferenceSynchronized(l, cookie, lock, self)); |
| 2301 | } else { |
| 2302 | return reinterpret_cast<uint64_t>(JniMethodEndWithReference(l, cookie, self)); |
| 2303 | } |
| 2304 | } |
| 2305 | |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2306 | static void artQuickGenericJniEndJNINonRef(Thread* self, |
| 2307 | uint32_t cookie, |
| 2308 | bool fast_native, |
| 2309 | jobject lock) { |
Andreas Gampe | ad61517 | 2014-04-04 16:20:13 -0700 | [diff] [blame] | 2310 | if (lock != nullptr) { |
| 2311 | JniMethodEndSynchronized(cookie, lock, self); |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2312 | // Ignore "fast_native" here because synchronized functions aren't very fast. |
Andreas Gampe | ad61517 | 2014-04-04 16:20:13 -0700 | [diff] [blame] | 2313 | } else { |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2314 | if (UNLIKELY(fast_native)) { |
| 2315 | JniMethodFastEnd(cookie, self); |
| 2316 | } else { |
| 2317 | JniMethodEnd(cookie, self); |
| 2318 | } |
Andreas Gampe | ad61517 | 2014-04-04 16:20:13 -0700 | [diff] [blame] | 2319 | } |
| 2320 | } |
| 2321 | |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 2322 | /* |
| 2323 | * Initializes an alloca region assumed to be directly below sp for a native call: |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2324 | * Create a HandleScope and call stack and fill a mini stack with values to be pushed to registers. |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 2325 | * The final element on the stack is a pointer to the native code. |
| 2326 | * |
Andreas Gampe | 36fea8d | 2014-03-10 13:37:40 -0700 | [diff] [blame] | 2327 | * On entry, the stack has a standard callee-save frame above sp, and an alloca below it. |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2328 | * We need to fix this, as the handle scope needs to go into the callee-save frame. |
Andreas Gampe | 36fea8d | 2014-03-10 13:37:40 -0700 | [diff] [blame] | 2329 | * |
Andreas Gampe | c147b00 | 2014-03-06 18:11:06 -0800 | [diff] [blame] | 2330 | * The return of this function denotes: |
| 2331 | * 1) How many bytes of the alloca can be released, if the value is non-negative. |
| 2332 | * 2) An error, if the value is negative. |
| 2333 | */ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2334 | extern "C" TwoWordReturn artQuickGenericJniTrampoline(Thread* self, ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2335 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 2336 | // Note: We cannot walk the stack properly until fixed up below. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2337 | ArtMethod* called = *sp; |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2338 | DCHECK(called->IsNative()) << called->PrettyMethod(true); |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 2339 | Runtime* runtime = Runtime::Current(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 2340 | uint32_t shorty_len = 0; |
| 2341 | const char* shorty = called->GetShorty(&shorty_len); |
Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 2342 | bool critical_native = called->IsCriticalNative(); |
| 2343 | bool fast_native = called->IsFastNative(); |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2344 | bool normal_native = !critical_native && !fast_native; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2345 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2346 | // Run the visitor and update sp. |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2347 | BuildGenericJniFrameVisitor visitor(self, |
| 2348 | called->IsStatic(), |
| 2349 | critical_native, |
| 2350 | shorty, |
| 2351 | shorty_len, |
| 2352 | &sp); |
Mathieu Chartier | be08cf5 | 2016-09-13 13:41:24 -0700 | [diff] [blame] | 2353 | { |
| 2354 | ScopedAssertNoThreadSuspension sants(__FUNCTION__); |
| 2355 | visitor.VisitArguments(); |
| 2356 | // FinalizeHandleScope pushes the handle scope on the thread. |
| 2357 | visitor.FinalizeHandleScope(self); |
| 2358 | } |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2359 | |
Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 2360 | // Fix up managed-stack things in Thread. After this we can walk the stack. |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 2361 | self->SetTopOfStackTagged(sp); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2362 | |
Ian Rogers | e0dcd46 | 2014-03-08 15:21:04 -0800 | [diff] [blame] | 2363 | self->VerifyStack(); |
| 2364 | |
Vladimir Marko | f8655b3 | 2018-03-21 17:53:56 +0000 | [diff] [blame] | 2365 | // We can now walk the stack if needed by JIT GC from MethodEntered() for JIT-on-first-use. |
| 2366 | jit::Jit* jit = runtime->GetJit(); |
| 2367 | if (jit != nullptr) { |
| 2368 | jit->MethodEntered(self, called); |
| 2369 | } |
| 2370 | |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2371 | uint32_t cookie; |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2372 | uint32_t* sp32; |
| 2373 | // Skip calling JniMethodStart for @CriticalNative. |
| 2374 | if (LIKELY(!critical_native)) { |
| 2375 | // Start JNI, save the cookie. |
| 2376 | if (called->IsSynchronized()) { |
| 2377 | DCHECK(normal_native) << " @FastNative and synchronize is not supported"; |
| 2378 | cookie = JniMethodStartSynchronized(visitor.GetFirstHandleScopeJObject(), self); |
| 2379 | if (self->IsExceptionPending()) { |
| 2380 | self->PopHandleScope(); |
| 2381 | // A negative value denotes an error. |
| 2382 | return GetTwoWordFailureValue(); |
| 2383 | } |
| 2384 | } else { |
| 2385 | if (fast_native) { |
| 2386 | cookie = JniMethodFastStart(self); |
| 2387 | } else { |
| 2388 | DCHECK(normal_native); |
| 2389 | cookie = JniMethodStart(self); |
| 2390 | } |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2391 | } |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2392 | sp32 = reinterpret_cast<uint32_t*>(sp); |
| 2393 | *(sp32 - 1) = cookie; |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2394 | } |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2395 | |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 2396 | // Retrieve the stored native code. |
Alex Light | d78ddec | 2017-04-18 15:20:38 -0700 | [diff] [blame] | 2397 | void const* nativeCode = called->GetEntryPointFromJni(); |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 2398 | |
Andreas Gampe | 9a6a99a | 2014-03-14 07:52:20 -0700 | [diff] [blame] | 2399 | // There are two cases for the content of nativeCode: |
| 2400 | // 1) Pointer to the native function. |
| 2401 | // 2) Pointer to the trampoline for native code binding. |
| 2402 | // In the second case, we need to execute the binding and continue with the actual native function |
| 2403 | // pointer. |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 2404 | DCHECK(nativeCode != nullptr); |
| 2405 | if (nativeCode == GetJniDlsymLookupStub()) { |
Ian Rogers | 04c31d2 | 2014-07-07 21:44:06 -0700 | [diff] [blame] | 2406 | #if defined(__arm__) || defined(__aarch64__) |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 2407 | nativeCode = artFindNativeMethod(); |
Ian Rogers | 04c31d2 | 2014-07-07 21:44:06 -0700 | [diff] [blame] | 2408 | #else |
| 2409 | nativeCode = artFindNativeMethod(self); |
| 2410 | #endif |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 2411 | |
| 2412 | if (nativeCode == nullptr) { |
| 2413 | DCHECK(self->IsExceptionPending()); // There should be an exception pending now. |
Andreas Gampe | ad61517 | 2014-04-04 16:20:13 -0700 | [diff] [blame] | 2414 | |
Igor Murashkin | 06a04e0 | 2016-09-13 15:57:37 -0700 | [diff] [blame] | 2415 | // @CriticalNative calls do not need to call back into JniMethodEnd. |
| 2416 | if (LIKELY(!critical_native)) { |
| 2417 | // End JNI, as the assembly will move to deliver the exception. |
| 2418 | jobject lock = called->IsSynchronized() ? visitor.GetFirstHandleScopeJObject() : nullptr; |
| 2419 | if (shorty[0] == 'L') { |
| 2420 | artQuickGenericJniEndJNIRef(self, cookie, fast_native, nullptr, lock); |
| 2421 | } else { |
| 2422 | artQuickGenericJniEndJNINonRef(self, cookie, fast_native, lock); |
| 2423 | } |
Andreas Gampe | ad61517 | 2014-04-04 16:20:13 -0700 | [diff] [blame] | 2424 | } |
| 2425 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2426 | return GetTwoWordFailureValue(); |
Andreas Gampe | 9054683 | 2014-03-12 18:07:19 -0700 | [diff] [blame] | 2427 | } |
| 2428 | // Note that the native code pointer will be automatically set by artFindNativeMethod(). |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2429 | } |
| 2430 | |
Alexey Frunze | 1b8464d | 2016-11-12 17:22:05 -0800 | [diff] [blame] | 2431 | #if defined(__mips__) && !defined(__LP64__) |
| 2432 | // On MIPS32 if the first two arguments are floating-point, we need to know their types |
| 2433 | // so that art_quick_generic_jni_trampoline can correctly extract them from the stack |
| 2434 | // and load into floating-point registers. |
| 2435 | // Possible arrangements of first two floating-point arguments on the stack (32-bit FPU |
| 2436 | // view): |
| 2437 | // (1) |
| 2438 | // | DOUBLE | DOUBLE | other args, if any |
| 2439 | // | F12 | F13 | F14 | F15 | |
| 2440 | // | SP+0 | SP+4 | SP+8 | SP+12 | SP+16 |
| 2441 | // (2) |
| 2442 | // | DOUBLE | FLOAT | (PAD) | other args, if any |
| 2443 | // | F12 | F13 | F14 | | |
| 2444 | // | SP+0 | SP+4 | SP+8 | SP+12 | SP+16 |
| 2445 | // (3) |
| 2446 | // | FLOAT | (PAD) | DOUBLE | other args, if any |
| 2447 | // | F12 | | F14 | F15 | |
| 2448 | // | SP+0 | SP+4 | SP+8 | SP+12 | SP+16 |
| 2449 | // (4) |
| 2450 | // | FLOAT | FLOAT | other args, if any |
| 2451 | // | F12 | F14 | |
| 2452 | // | SP+0 | SP+4 | SP+8 |
| 2453 | // As you can see, only the last case (4) is special. In all others we can just |
| 2454 | // load F12/F13 and F14/F15 in the same manner. |
| 2455 | // Set bit 0 of the native code address to 1 in this case (valid code addresses |
| 2456 | // are always a multiple of 4 on MIPS32, so we have 2 spare bits available). |
| 2457 | if (nativeCode != nullptr && |
| 2458 | shorty != nullptr && |
| 2459 | shorty_len >= 3 && |
| 2460 | shorty[1] == 'F' && |
| 2461 | shorty[2] == 'F') { |
| 2462 | nativeCode = reinterpret_cast<void*>(reinterpret_cast<uintptr_t>(nativeCode) | 1); |
| 2463 | } |
| 2464 | #endif |
| 2465 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2466 | // Return native code addr(lo) and bottom of alloca address(hi). |
| 2467 | return GetTwoWordSuccessValue(reinterpret_cast<uintptr_t>(visitor.GetBottomOfUsedArea()), |
| 2468 | reinterpret_cast<uintptr_t>(nativeCode)); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2469 | } |
| 2470 | |
Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 2471 | // Defined in quick_jni_entrypoints.cc. |
| 2472 | extern uint64_t GenericJniMethodEnd(Thread* self, uint32_t saved_local_ref_cookie, |
| 2473 | jvalue result, uint64_t result_f, ArtMethod* called, |
| 2474 | HandleScope* handle_scope); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2475 | /* |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2476 | * Is called after the native JNI code. Responsible for cleanup (handle scope, saved state) and |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2477 | * unlocking. |
| 2478 | */ |
Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 2479 | extern "C" uint64_t artQuickGenericJniEndTrampoline(Thread* self, |
| 2480 | jvalue result, |
| 2481 | uint64_t result_f) { |
| 2482 | // We're here just back from a native call. We don't have the shared mutator lock at this point |
| 2483 | // yet until we call GoToRunnable() later in GenericJniMethodEnd(). Accessing objects or doing |
| 2484 | // anything that requires a mutator lock before that would cause problems as GC may have the |
| 2485 | // exclusive mutator lock and may be moving objects, etc. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2486 | ArtMethod** sp = self->GetManagedStack()->GetTopQuickFrame(); |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 2487 | DCHECK(self->GetManagedStack()->GetTopQuickFrameTag()); |
Andreas Gampe | bf6b92a | 2014-03-05 16:11:04 -0800 | [diff] [blame] | 2488 | uint32_t* sp32 = reinterpret_cast<uint32_t*>(sp); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2489 | ArtMethod* called = *sp; |
Ian Rogers | e0dcd46 | 2014-03-08 15:21:04 -0800 | [diff] [blame] | 2490 | uint32_t cookie = *(sp32 - 1); |
Hiroshi Yamauchi | a23b468 | 2015-09-28 17:47:32 -0700 | [diff] [blame] | 2491 | HandleScope* table = reinterpret_cast<HandleScope*>(reinterpret_cast<uint8_t*>(sp) + sizeof(*sp)); |
| 2492 | return GenericJniMethodEnd(self, cookie, result, result_f, called, table); |
Andreas Gampe | 2da8823 | 2014-02-27 12:26:20 -0800 | [diff] [blame] | 2493 | } |
| 2494 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2495 | // We use TwoWordReturn to optimize scalar returns. We use the hi value for code, and the lo value |
| 2496 | // for the method pointer. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2497 | // |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2498 | // It is valid to use this, as at the usage points here (returns from C functions) we are assuming |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2499 | // to hold the mutator lock (see REQUIRES_SHARED(Locks::mutator_lock_) annotations). |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2500 | |
Vladimir Marko | f79aa7f | 2017-07-04 16:58:55 +0100 | [diff] [blame] | 2501 | template <InvokeType type, bool access_check> |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 2502 | static TwoWordReturn artInvokeCommon(uint32_t method_idx, |
| 2503 | ObjPtr<mirror::Object> this_object, |
| 2504 | Thread* self, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2505 | ArtMethod** sp) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2506 | ScopedQuickEntrypointChecks sqec(self); |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 2507 | DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2508 | ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp); |
Vladimir Marko | f79aa7f | 2017-07-04 16:58:55 +0100 | [diff] [blame] | 2509 | ArtMethod* method = FindMethodFast<type, access_check>(method_idx, this_object, caller_method); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2510 | if (UNLIKELY(method == nullptr)) { |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2511 | const DexFile* dex_file = caller_method->GetDeclaringClass()->GetDexCache()->GetDexFile(); |
| 2512 | uint32_t shorty_len; |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2513 | const char* shorty = dex_file->GetMethodShorty(dex_file->GetMethodId(method_idx), &shorty_len); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2514 | { |
| 2515 | // Remember the args in case a GC happens in FindMethodFromCode. |
| 2516 | ScopedObjectAccessUnchecked soa(self->GetJniEnv()); |
| 2517 | RememberForGcArgumentVisitor visitor(sp, type == kStatic, shorty, shorty_len, &soa); |
| 2518 | visitor.VisitArguments(); |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 2519 | method = FindMethodFromCode<type, access_check>(method_idx, |
| 2520 | &this_object, |
| 2521 | caller_method, |
Mathieu Chartier | 0cd8135 | 2014-05-22 16:48:55 -0700 | [diff] [blame] | 2522 | self); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2523 | visitor.FixupReferences(); |
| 2524 | } |
| 2525 | |
Ian Rogers | e0a02da | 2014-12-02 14:10:53 -0800 | [diff] [blame] | 2526 | if (UNLIKELY(method == nullptr)) { |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2527 | CHECK(self->IsExceptionPending()); |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2528 | return GetTwoWordFailureValue(); // Failure. |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2529 | } |
| 2530 | } |
| 2531 | DCHECK(!self->IsExceptionPending()); |
| 2532 | const void* code = method->GetEntryPointFromQuickCompiledCode(); |
| 2533 | |
| 2534 | // When we return, the caller will branch to this address, so it had better not be 0! |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2535 | DCHECK(code != nullptr) << "Code was null in method: " << method->PrettyMethod() |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2536 | << " location: " |
| 2537 | << method->GetDexFile()->GetLocation(); |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2538 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2539 | return GetTwoWordSuccessValue(reinterpret_cast<uintptr_t>(code), |
| 2540 | reinterpret_cast<uintptr_t>(method)); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2541 | } |
| 2542 | |
Nicolas Geoffray | 8689a0a | 2014-04-04 09:26:24 +0100 | [diff] [blame] | 2543 | // Explicit artInvokeCommon template function declarations to please analysis tool. |
| 2544 | #define EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(type, access_check) \ |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2545 | template REQUIRES_SHARED(Locks::mutator_lock_) \ |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2546 | TwoWordReturn artInvokeCommon<type, access_check>( \ |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 2547 | uint32_t method_idx, ObjPtr<mirror::Object> his_object, Thread* self, ArtMethod** sp) |
Nicolas Geoffray | 8689a0a | 2014-04-04 09:26:24 +0100 | [diff] [blame] | 2548 | |
| 2549 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kVirtual, false); |
| 2550 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kVirtual, true); |
| 2551 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kInterface, false); |
| 2552 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kInterface, true); |
| 2553 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kDirect, false); |
| 2554 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kDirect, true); |
| 2555 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kStatic, false); |
| 2556 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kStatic, true); |
| 2557 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kSuper, false); |
| 2558 | EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL(kSuper, true); |
| 2559 | #undef EXPLICIT_INVOKE_COMMON_TEMPLATE_DECL |
| 2560 | |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2561 | // See comments in runtime_support_asm.S |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2562 | extern "C" TwoWordReturn artInvokeInterfaceTrampolineWithAccessCheck( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2563 | uint32_t method_idx, mirror::Object* this_object, Thread* self, ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2564 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 2565 | return artInvokeCommon<kInterface, true>(method_idx, this_object, self, sp); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2566 | } |
| 2567 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2568 | extern "C" TwoWordReturn artInvokeDirectTrampolineWithAccessCheck( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2569 | uint32_t method_idx, mirror::Object* this_object, Thread* self, ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2570 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 2571 | return artInvokeCommon<kDirect, true>(method_idx, this_object, self, sp); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2572 | } |
| 2573 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2574 | extern "C" TwoWordReturn artInvokeStaticTrampolineWithAccessCheck( |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 2575 | uint32_t method_idx, |
| 2576 | mirror::Object* this_object ATTRIBUTE_UNUSED, |
| 2577 | Thread* self, |
| 2578 | ArtMethod** sp) REQUIRES_SHARED(Locks::mutator_lock_) { |
| 2579 | // For static, this_object is not required and may be random garbage. Don't pass it down so that |
| 2580 | // it doesn't cause ObjPtr alignment failure check. |
| 2581 | return artInvokeCommon<kStatic, true>(method_idx, nullptr, self, sp); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2584 | extern "C" TwoWordReturn artInvokeSuperTrampolineWithAccessCheck( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2585 | uint32_t method_idx, mirror::Object* this_object, Thread* self, ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2586 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 2587 | return artInvokeCommon<kSuper, true>(method_idx, this_object, self, sp); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2588 | } |
| 2589 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2590 | extern "C" TwoWordReturn artInvokeVirtualTrampolineWithAccessCheck( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2591 | uint32_t method_idx, mirror::Object* this_object, Thread* self, ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2592 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 2593 | return artInvokeCommon<kVirtual, true>(method_idx, this_object, self, sp); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
Vladimir Marko | 07bfbac | 2017-07-06 14:55:02 +0100 | [diff] [blame] | 2596 | // Helper function for art_quick_imt_conflict_trampoline to look up the interface method. |
| 2597 | extern "C" ArtMethod* artLookupResolvedMethod(uint32_t method_index, ArtMethod* referrer) |
| 2598 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 2599 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
| 2600 | DCHECK(!referrer->IsProxyMethod()); |
| 2601 | ArtMethod* result = Runtime::Current()->GetClassLinker()->LookupResolvedMethod( |
| 2602 | method_index, referrer->GetDexCache(), referrer->GetClassLoader()); |
| 2603 | DCHECK(result == nullptr || |
| 2604 | result->GetDeclaringClass()->IsInterface() || |
| 2605 | result->GetDeclaringClass() == |
| 2606 | WellKnownClasses::ToClass(WellKnownClasses::java_lang_Object)) |
| 2607 | << result->PrettyMethod(); |
| 2608 | return result; |
| 2609 | } |
| 2610 | |
Jeff Hao | 5667f56 | 2017-02-27 19:32:01 -0800 | [diff] [blame] | 2611 | // Determine target of interface dispatch. The interface method and this object are known non-null. |
| 2612 | // The interface method is the method returned by the dex cache in the conflict trampoline. |
| 2613 | extern "C" TwoWordReturn artInvokeInterfaceTrampoline(ArtMethod* interface_method, |
Mathieu Chartier | ef41db7 | 2016-10-25 15:08:01 -0700 | [diff] [blame] | 2614 | mirror::Object* raw_this_object, |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2615 | Thread* self, |
| 2616 | ArtMethod** sp) |
Andreas Gampe | bdf7f1c | 2016-08-30 16:38:47 -0700 | [diff] [blame] | 2617 | REQUIRES_SHARED(Locks::mutator_lock_) { |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2618 | ScopedQuickEntrypointChecks sqec(self); |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2619 | StackHandleScope<2> hs(self); |
| 2620 | Handle<mirror::Object> this_object = hs.NewHandle(raw_this_object); |
| 2621 | Handle<mirror::Class> cls = hs.NewHandle(this_object->GetClass()); |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2622 | |
Nicolas Geoffray | 5bf7bac | 2016-07-06 14:18:23 +0000 | [diff] [blame] | 2623 | ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp); |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2624 | ArtMethod* method = nullptr; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 2625 | ImTable* imt = cls->GetImt(kRuntimePointerSize); |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2626 | |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2627 | if (UNLIKELY(interface_method == nullptr)) { |
Vladimir Marko | 07bfbac | 2017-07-06 14:55:02 +0100 | [diff] [blame] | 2628 | // The interface method is unresolved, so resolve it in the dex file of the caller. |
Jeff Hao | 5667f56 | 2017-02-27 19:32:01 -0800 | [diff] [blame] | 2629 | // Fetch the dex_method_idx of the target interface method from the caller. |
| 2630 | uint32_t dex_method_idx; |
| 2631 | uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp); |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 2632 | const Instruction& instr = caller_method->DexInstructions().InstructionAt(dex_pc); |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 2633 | Instruction::Code instr_code = instr.Opcode(); |
Jeff Hao | 5667f56 | 2017-02-27 19:32:01 -0800 | [diff] [blame] | 2634 | DCHECK(instr_code == Instruction::INVOKE_INTERFACE || |
| 2635 | instr_code == Instruction::INVOKE_INTERFACE_RANGE) |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 2636 | << "Unexpected call into interface trampoline: " << instr.DumpString(nullptr); |
Jeff Hao | 5667f56 | 2017-02-27 19:32:01 -0800 | [diff] [blame] | 2637 | if (instr_code == Instruction::INVOKE_INTERFACE) { |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 2638 | dex_method_idx = instr.VRegB_35c(); |
Jeff Hao | 5667f56 | 2017-02-27 19:32:01 -0800 | [diff] [blame] | 2639 | } else { |
| 2640 | DCHECK_EQ(instr_code, Instruction::INVOKE_INTERFACE_RANGE); |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 2641 | dex_method_idx = instr.VRegB_3rc(); |
Jeff Hao | 5667f56 | 2017-02-27 19:32:01 -0800 | [diff] [blame] | 2642 | } |
| 2643 | |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2644 | const DexFile& dex_file = caller_method->GetDeclaringClass()->GetDexFile(); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2645 | uint32_t shorty_len; |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2646 | const char* shorty = dex_file.GetMethodShorty(dex_file.GetMethodId(dex_method_idx), |
| 2647 | &shorty_len); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2648 | { |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2649 | // Remember the args in case a GC happens in ClassLinker::ResolveMethod(). |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2650 | ScopedObjectAccessUnchecked soa(self->GetJniEnv()); |
| 2651 | RememberForGcArgumentVisitor visitor(sp, false, shorty, shorty_len, &soa); |
| 2652 | visitor.VisitArguments(); |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2653 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 2654 | interface_method = class_linker->ResolveMethod<ClassLinker::ResolveMode::kNoChecks>( |
| 2655 | self, dex_method_idx, caller_method, kInterface); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2656 | visitor.FixupReferences(); |
| 2657 | } |
| 2658 | |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2659 | if (UNLIKELY(interface_method == nullptr)) { |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2660 | CHECK(self->IsExceptionPending()); |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2661 | return GetTwoWordFailureValue(); // Failure. |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2662 | } |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2663 | } |
| 2664 | |
| 2665 | DCHECK(!interface_method->IsRuntimeMethod()); |
| 2666 | // Look whether we have a match in the ImtConflictTable. |
| 2667 | uint32_t imt_index = ImTable::GetImtIndex(interface_method); |
| 2668 | ArtMethod* conflict_method = imt->Get(imt_index, kRuntimePointerSize); |
| 2669 | if (LIKELY(conflict_method->IsRuntimeMethod())) { |
| 2670 | ImtConflictTable* current_table = conflict_method->GetImtConflictTable(kRuntimePointerSize); |
| 2671 | DCHECK(current_table != nullptr); |
| 2672 | method = current_table->Lookup(interface_method, kRuntimePointerSize); |
| 2673 | } else { |
| 2674 | // It seems we aren't really a conflict method! |
| 2675 | if (kIsDebugBuild) { |
| 2676 | ArtMethod* m = cls->FindVirtualMethodForInterface(interface_method, kRuntimePointerSize); |
| 2677 | CHECK_EQ(conflict_method, m) |
| 2678 | << interface_method->PrettyMethod() << " / " << conflict_method->PrettyMethod() << " / " |
| 2679 | << " / " << ArtMethod::PrettyMethod(m) << " / " << cls->PrettyClass(); |
| 2680 | } |
| 2681 | method = conflict_method; |
| 2682 | } |
| 2683 | if (method != nullptr) { |
| 2684 | return GetTwoWordSuccessValue( |
| 2685 | reinterpret_cast<uintptr_t>(method->GetEntryPointFromQuickCompiledCode()), |
| 2686 | reinterpret_cast<uintptr_t>(method)); |
| 2687 | } |
| 2688 | |
| 2689 | // No match, use the IfTable. |
| 2690 | method = cls->FindVirtualMethodForInterface(interface_method, kRuntimePointerSize); |
| 2691 | if (UNLIKELY(method == nullptr)) { |
| 2692 | ThrowIncompatibleClassChangeErrorClassForInterfaceDispatch( |
| 2693 | interface_method, this_object.Get(), caller_method); |
| 2694 | return GetTwoWordFailureValue(); // Failure. |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2695 | } |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2696 | |
| 2697 | // We arrive here if we have found an implementation, and it is not in the ImtConflictTable. |
| 2698 | // We create a new table with the new pair { interface_method, method }. |
Vladimir Marko | 302f69c | 2017-07-25 15:27:15 +0100 | [diff] [blame] | 2699 | DCHECK(conflict_method->IsRuntimeMethod()); |
| 2700 | ArtMethod* new_conflict_method = Runtime::Current()->GetClassLinker()->AddMethodToConflictTable( |
| 2701 | cls.Get(), |
| 2702 | conflict_method, |
| 2703 | interface_method, |
| 2704 | method, |
| 2705 | /*force_new_conflict_method*/false); |
| 2706 | if (new_conflict_method != conflict_method) { |
| 2707 | // Update the IMT if we create a new conflict method. No fence needed here, as the |
| 2708 | // data is consistent. |
| 2709 | imt->Set(imt_index, |
| 2710 | new_conflict_method, |
| 2711 | kRuntimePointerSize); |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2712 | } |
| 2713 | |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2714 | const void* code = method->GetEntryPointFromQuickCompiledCode(); |
| 2715 | |
| 2716 | // When we return, the caller will branch to this address, so it had better not be 0! |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 2717 | DCHECK(code != nullptr) << "Code was null in method: " << method->PrettyMethod() |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2718 | << " location: " << method->GetDexFile()->GetLocation(); |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2719 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2720 | return GetTwoWordSuccessValue(reinterpret_cast<uintptr_t>(code), |
| 2721 | reinterpret_cast<uintptr_t>(method)); |
Mathieu Chartier | 5f3ded4 | 2014-04-03 15:25:30 -0700 | [diff] [blame] | 2722 | } |
| 2723 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2724 | // Returns shorty type so the caller can determine how to put |result| |
| 2725 | // into expected registers. The shorty type is static so the compiler |
| 2726 | // could call different flavors of this code path depending on the |
| 2727 | // shorty type though this would require different entry points for |
| 2728 | // each type. |
| 2729 | extern "C" uintptr_t artInvokePolymorphic( |
| 2730 | JValue* result, |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 2731 | mirror::Object* raw_receiver, |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2732 | Thread* self, |
| 2733 | ArtMethod** sp) |
| 2734 | REQUIRES_SHARED(Locks::mutator_lock_) { |
| 2735 | ScopedQuickEntrypointChecks sqec(self); |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 2736 | DCHECK_EQ(*sp, Runtime::Current()->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs)); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2737 | |
| 2738 | // Start new JNI local reference state |
| 2739 | JNIEnvExt* env = self->GetJniEnv(); |
| 2740 | ScopedObjectAccessUnchecked soa(env); |
| 2741 | ScopedJniEnvLocalRefState env_state(env); |
| 2742 | const char* old_cause = self->StartAssertNoThreadSuspension("Making stack arguments safe."); |
| 2743 | |
| 2744 | // From the instruction, get the |callsite_shorty| and expose arguments on the stack to the GC. |
| 2745 | ArtMethod* caller_method = QuickArgumentVisitor::GetCallingMethod(sp); |
| 2746 | uint32_t dex_pc = QuickArgumentVisitor::GetCallingDexPc(sp); |
Mathieu Chartier | 73f21d4 | 2018-01-02 14:26:50 -0800 | [diff] [blame] | 2747 | const Instruction& inst = caller_method->DexInstructions().InstructionAt(dex_pc); |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 2748 | DCHECK(inst.Opcode() == Instruction::INVOKE_POLYMORPHIC || |
| 2749 | inst.Opcode() == Instruction::INVOKE_POLYMORPHIC_RANGE); |
Orion Hodson | 06d10a7 | 2018-05-14 08:53:38 +0100 | [diff] [blame] | 2750 | const dex::ProtoIndex proto_idx(inst.VRegH()); |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 2751 | const char* shorty = caller_method->GetDexFile()->GetShorty(proto_idx); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2752 | const size_t shorty_length = strlen(shorty); |
| 2753 | static const bool kMethodIsStatic = false; // invoke() and invokeExact() are not static. |
| 2754 | RememberForGcArgumentVisitor gc_visitor(sp, kMethodIsStatic, shorty, shorty_length, &soa); |
Orion Hodson | fea84dd | 2017-01-16 13:52:20 +0000 | [diff] [blame] | 2755 | gc_visitor.VisitArguments(); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2756 | |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 2757 | // Wrap raw_receiver in a Handle for safety. |
| 2758 | StackHandleScope<3> hs(self); |
| 2759 | Handle<mirror::Object> receiver_handle(hs.NewHandle(raw_receiver)); |
| 2760 | raw_receiver = nullptr; |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2761 | self->EndAssertNoThreadSuspension(old_cause); |
| 2762 | |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 2763 | // Resolve method. |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2764 | ClassLinker* linker = Runtime::Current()->GetClassLinker(); |
Vladimir Marko | ba11882 | 2017-06-12 15:41:56 +0100 | [diff] [blame] | 2765 | ArtMethod* resolved_method = linker->ResolveMethod<ClassLinker::ResolveMode::kCheckICCEAndIAE>( |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 2766 | self, inst.VRegB(), caller_method, kVirtual); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 2767 | |
| 2768 | if (UNLIKELY(receiver_handle.IsNull())) { |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2769 | ThrowNullPointerExceptionForMethodAccess(resolved_method, InvokeType::kVirtual); |
| 2770 | return static_cast<uintptr_t>('V'); |
| 2771 | } |
| 2772 | |
Orion Hodson | e7732be | 2017-10-11 14:35:20 +0100 | [diff] [blame] | 2773 | Handle<mirror::MethodType> method_type( |
| 2774 | hs.NewHandle(linker->ResolveMethodType(self, proto_idx, caller_method))); |
| 2775 | |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2776 | // This implies we couldn't resolve one or more types in this method handle. |
| 2777 | if (UNLIKELY(method_type.IsNull())) { |
| 2778 | CHECK(self->IsExceptionPending()); |
| 2779 | return static_cast<uintptr_t>('V'); |
| 2780 | } |
| 2781 | |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 2782 | DCHECK_EQ(ArtMethod::NumArgRegisters(shorty) + 1u, (uint32_t)inst.VRegA()); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2783 | DCHECK_EQ(resolved_method->IsStatic(), kMethodIsStatic); |
| 2784 | |
| 2785 | // Fix references before constructing the shadow frame. |
| 2786 | gc_visitor.FixupReferences(); |
| 2787 | |
| 2788 | // Construct shadow frame placing arguments consecutively from |first_arg|. |
Vladimir Marko | d7559b7 | 2017-09-28 13:50:37 +0100 | [diff] [blame] | 2789 | const bool is_range = (inst.Opcode() == Instruction::INVOKE_POLYMORPHIC_RANGE); |
| 2790 | const size_t num_vregs = is_range ? inst.VRegA_4rcc() : inst.VRegA_45cc(); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2791 | const size_t first_arg = 0; |
| 2792 | ShadowFrameAllocaUniquePtr shadow_frame_unique_ptr = |
| 2793 | CREATE_SHADOW_FRAME(num_vregs, /* link */ nullptr, resolved_method, dex_pc); |
| 2794 | ShadowFrame* shadow_frame = shadow_frame_unique_ptr.get(); |
| 2795 | ScopedStackedShadowFramePusher |
| 2796 | frame_pusher(self, shadow_frame, StackedShadowFrameType::kShadowFrameUnderConstruction); |
| 2797 | BuildQuickShadowFrameVisitor shadow_frame_builder(sp, |
| 2798 | kMethodIsStatic, |
| 2799 | shorty, |
| 2800 | strlen(shorty), |
| 2801 | shadow_frame, |
| 2802 | first_arg); |
| 2803 | shadow_frame_builder.VisitArguments(); |
| 2804 | |
| 2805 | // Push a transition back into managed code onto the linked list in thread. |
| 2806 | ManagedStack fragment; |
| 2807 | self->PushManagedStackFragment(&fragment); |
| 2808 | |
| 2809 | // Call DoInvokePolymorphic with |is_range| = true, as shadow frame has argument registers in |
| 2810 | // consecutive order. |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 2811 | RangeInstructionOperands operands(first_arg + 1, num_vregs - 1); |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 2812 | Intrinsics intrinsic = static_cast<Intrinsics>(resolved_method->GetIntrinsic()); |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 2813 | bool success = false; |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame^] | 2814 | if (resolved_method->GetDeclaringClass() == GetClassRoot<mirror::MethodHandle>(linker)) { |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 2815 | Handle<mirror::MethodHandle> method_handle(hs.NewHandle( |
| 2816 | ObjPtr<mirror::MethodHandle>::DownCast(MakeObjPtr(receiver_handle.Get())))); |
| 2817 | if (intrinsic == Intrinsics::kMethodHandleInvokeExact) { |
| 2818 | success = MethodHandleInvokeExact(self, |
| 2819 | *shadow_frame, |
| 2820 | method_handle, |
| 2821 | method_type, |
| 2822 | &operands, |
| 2823 | result); |
| 2824 | } else { |
| 2825 | DCHECK_EQ(static_cast<uint32_t>(intrinsic), |
| 2826 | static_cast<uint32_t>(Intrinsics::kMethodHandleInvoke)); |
| 2827 | success = MethodHandleInvoke(self, |
| 2828 | *shadow_frame, |
| 2829 | method_handle, |
| 2830 | method_type, |
| 2831 | &operands, |
| 2832 | result); |
| 2833 | } |
| 2834 | } else { |
Vladimir Marko | c7aa87e | 2018-05-24 15:19:52 +0100 | [diff] [blame^] | 2835 | DCHECK_EQ(GetClassRoot<mirror::VarHandle>(linker), resolved_method->GetDeclaringClass()); |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 2836 | Handle<mirror::VarHandle> var_handle(hs.NewHandle( |
| 2837 | ObjPtr<mirror::VarHandle>::DownCast(MakeObjPtr(receiver_handle.Get())))); |
| 2838 | mirror::VarHandle::AccessMode access_mode = |
| 2839 | mirror::VarHandle::GetAccessModeByIntrinsic(intrinsic); |
| 2840 | success = VarHandleInvokeAccessor(self, |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 2841 | *shadow_frame, |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 2842 | var_handle, |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 2843 | method_type, |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 2844 | access_mode, |
Orion Hodson | 960d4f7 | 2017-11-10 15:32:38 +0000 | [diff] [blame] | 2845 | &operands, |
| 2846 | result); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2847 | } |
Orion Hodson | 537a4fe | 2018-05-15 13:57:58 +0100 | [diff] [blame] | 2848 | |
Orion Hodson | 43f0cdb | 2017-10-10 14:47:32 +0100 | [diff] [blame] | 2849 | DCHECK(success || self->IsExceptionPending()); |
Orion Hodson | ac14139 | 2017-01-13 11:53:47 +0000 | [diff] [blame] | 2850 | |
| 2851 | // Pop transition record. |
| 2852 | self->PopManagedStackFragment(fragment); |
| 2853 | |
| 2854 | return static_cast<uintptr_t>(shorty[0]); |
| 2855 | } |
| 2856 | |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 2857 | } // namespace art |