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