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