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