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