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