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