Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #include "asm_support_arm64.S" |
| 18 | |
| 19 | #include "arch/quick_alloc_entrypoints.S" |
| 20 | |
| 21 | |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 22 | .macro INCREASE_FRAME frame_adjustment |
| 23 | sub sp, sp, #(\frame_adjustment) |
| 24 | .cfi_adjust_cfa_offset (\frame_adjustment) |
| 25 | .endm |
| 26 | |
| 27 | .macro DECREASE_FRAME frame_adjustment |
| 28 | add sp, sp, #(\frame_adjustment) |
| 29 | .cfi_adjust_cfa_offset -(\frame_adjustment) |
| 30 | .endm |
| 31 | |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 32 | .macro SAVE_REG reg, offset |
| 33 | str \reg, [sp, #(\offset)] |
| 34 | .cfi_rel_offset \reg, (\offset) |
| 35 | .endm |
| 36 | |
| 37 | .macro RESTORE_REG reg, offset |
| 38 | ldr \reg, [sp, #(\offset)] |
| 39 | .cfi_restore \reg |
| 40 | .endm |
| 41 | |
| 42 | .macro SAVE_TWO_REGS reg1, reg2, offset |
| 43 | stp \reg1, \reg2, [sp, #(\offset)] |
| 44 | .cfi_rel_offset \reg1, (\offset) |
| 45 | .cfi_rel_offset \reg2, (\offset) + 8 |
| 46 | .endm |
| 47 | |
| 48 | .macro RESTORE_TWO_REGS reg1, reg2, offset |
| 49 | ldp \reg1, \reg2, [sp, #(\offset)] |
| 50 | .cfi_restore \reg1 |
| 51 | .cfi_restore \reg2 |
| 52 | .endm |
| 53 | |
| 54 | .macro SAVE_TWO_REGS_INCREASE_FRAME reg1, reg2, frame_adjustment |
| 55 | stp \reg1, \reg2, [sp, #-(\frame_adjustment)]! |
| 56 | .cfi_adjust_cfa_offset (\frame_adjustment) |
| 57 | .cfi_rel_offset \reg1, 0 |
| 58 | .cfi_rel_offset \reg2, 8 |
| 59 | .endm |
| 60 | |
| 61 | .macro RESTORE_TWO_REGS_DECREASE_FRAME reg1, reg2, frame_adjustment |
| 62 | ldp \reg1, \reg2, [sp], #(\frame_adjustment) |
| 63 | .cfi_restore \reg1 |
| 64 | .cfi_restore \reg2 |
| 65 | .cfi_adjust_cfa_offset -(\frame_adjustment) |
| 66 | .endm |
| 67 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 68 | /* |
| 69 | * Macro that sets up the callee save frame to conform with |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 70 | * Runtime::CreateCalleeSaveMethod(kSaveAllCalleeSaves) |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 71 | */ |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 72 | .macro SETUP_SAVE_ALL_CALLEE_SAVES_FRAME |
| 73 | // art::Runtime** xIP0 = &art::Runtime::instance_ |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 74 | adrp xIP0, :got:_ZN3art7Runtime9instance_E |
| 75 | ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 76 | |
| 77 | // Our registers aren't intermixed - just spill in order. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 78 | ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 79 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 80 | // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveAllCalleeSaves]; |
| 81 | ldr xIP0, [xIP0, RUNTIME_SAVE_ALL_CALLEE_SAVES_METHOD_OFFSET] |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 82 | |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 83 | INCREASE_FRAME 176 |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 84 | |
| 85 | // Ugly compile-time check, but we only have the preprocessor. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 86 | #if (FRAME_SIZE_SAVE_ALL_CALLEE_SAVES != 176) |
| 87 | #error "FRAME_SIZE_SAVE_ALL_CALLEE_SAVES(ARM64) size not as expected." |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 88 | #endif |
| 89 | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 90 | // Stack alignment filler [sp, #8]. |
| 91 | // FP callee-saves. |
| 92 | stp d8, d9, [sp, #16] |
| 93 | stp d10, d11, [sp, #32] |
| 94 | stp d12, d13, [sp, #48] |
| 95 | stp d14, d15, [sp, #64] |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 96 | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 97 | // GP callee-saves |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 98 | SAVE_TWO_REGS x19, x20, 80 |
| 99 | SAVE_TWO_REGS x21, x22, 96 |
| 100 | SAVE_TWO_REGS x23, x24, 112 |
| 101 | SAVE_TWO_REGS x25, x26, 128 |
| 102 | SAVE_TWO_REGS x27, x28, 144 |
| 103 | SAVE_TWO_REGS x29, xLR, 160 |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 104 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 105 | // Store ArtMethod* Runtime::callee_save_methods_[kSaveAllCalleeSaves]. |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 106 | str xIP0, [sp] |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 107 | // Place sp in Thread::Current()->top_quick_frame. |
| 108 | mov xIP0, sp |
| 109 | str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 110 | .endm |
| 111 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 112 | /* |
| 113 | * Macro that sets up the callee save frame to conform with |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 114 | * Runtime::CreateCalleeSaveMethod(kSaveRefsOnly). |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 115 | */ |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 116 | .macro SETUP_SAVE_REFS_ONLY_FRAME |
| 117 | // art::Runtime** xIP0 = &art::Runtime::instance_ |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 118 | adrp xIP0, :got:_ZN3art7Runtime9instance_E |
| 119 | ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] |
| 120 | |
| 121 | // Our registers aren't intermixed - just spill in order. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 122 | ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_; |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 123 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 124 | // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefOnly]; |
| 125 | ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_ONLY_METHOD_OFFSET] |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 126 | |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 127 | INCREASE_FRAME 96 |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 128 | |
| 129 | // Ugly compile-time check, but we only have the preprocessor. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 130 | #if (FRAME_SIZE_SAVE_REFS_ONLY != 96) |
| 131 | #error "FRAME_SIZE_SAVE_REFS_ONLY(ARM64) size not as expected." |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 132 | #endif |
| 133 | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 134 | // GP callee-saves. |
| 135 | // x20 paired with ArtMethod* - see below. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 136 | SAVE_TWO_REGS x21, x22, 16 |
| 137 | SAVE_TWO_REGS x23, x24, 32 |
| 138 | SAVE_TWO_REGS x25, x26, 48 |
| 139 | SAVE_TWO_REGS x27, x28, 64 |
| 140 | SAVE_TWO_REGS x29, xLR, 80 |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 141 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 142 | // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsOnly]. |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 143 | stp xIP0, x20, [sp] |
| 144 | .cfi_rel_offset x20, 8 |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 145 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 146 | // Place sp in Thread::Current()->top_quick_frame. |
| 147 | mov xIP0, sp |
| 148 | str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 149 | .endm |
| 150 | |
| 151 | // TODO: Probably no need to restore registers preserved by aapcs64. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 152 | .macro RESTORE_SAVE_REFS_ONLY_FRAME |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 153 | // Callee-saves. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 154 | RESTORE_REG x20, 8 |
| 155 | RESTORE_TWO_REGS x21, x22, 16 |
| 156 | RESTORE_TWO_REGS x23, x24, 32 |
| 157 | RESTORE_TWO_REGS x25, x26, 48 |
| 158 | RESTORE_TWO_REGS x27, x28, 64 |
| 159 | RESTORE_TWO_REGS x29, xLR, 80 |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 160 | |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 161 | DECREASE_FRAME 96 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 162 | .endm |
| 163 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 164 | .macro POP_SAVE_REFS_ONLY_FRAME |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 165 | DECREASE_FRAME 96 |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 166 | .endm |
| 167 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 168 | .macro RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN |
| 169 | RESTORE_SAVE_REFS_ONLY_FRAME |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 170 | ret |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 171 | .endm |
| 172 | |
| 173 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 174 | .macro SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 175 | INCREASE_FRAME 224 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 176 | |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 177 | // Ugly compile-time check, but we only have the preprocessor. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 178 | #if (FRAME_SIZE_SAVE_REFS_AND_ARGS != 224) |
| 179 | #error "FRAME_SIZE_SAVE_REFS_AND_ARGS(ARM64) size not as expected." |
Andreas Gampe | 5c1e435 | 2014-04-21 19:28:24 -0700 | [diff] [blame] | 180 | #endif |
| 181 | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 182 | // Stack alignment filler [sp, #8]. |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 183 | // FP args. |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 184 | stp d0, d1, [sp, #16] |
| 185 | stp d2, d3, [sp, #32] |
| 186 | stp d4, d5, [sp, #48] |
| 187 | stp d6, d7, [sp, #64] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 188 | |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 189 | // Core args. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 190 | SAVE_TWO_REGS x1, x2, 80 |
| 191 | SAVE_TWO_REGS x3, x4, 96 |
| 192 | SAVE_TWO_REGS x5, x6, 112 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 193 | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 194 | // x7, Callee-saves. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 195 | SAVE_TWO_REGS x7, x20, 128 |
| 196 | SAVE_TWO_REGS x21, x22, 144 |
| 197 | SAVE_TWO_REGS x23, x24, 160 |
| 198 | SAVE_TWO_REGS x25, x26, 176 |
| 199 | SAVE_TWO_REGS x27, x28, 192 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 200 | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 201 | // x29(callee-save) and LR. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 202 | SAVE_TWO_REGS x29, xLR, 208 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 203 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 204 | .endm |
| 205 | |
| 206 | /* |
| 207 | * Macro that sets up the callee save frame to conform with |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 208 | * Runtime::CreateCalleeSaveMethod(kSaveRefsAndArgs). |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 209 | * |
| 210 | * TODO This is probably too conservative - saving FP & LR. |
| 211 | */ |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 212 | .macro SETUP_SAVE_REFS_AND_ARGS_FRAME |
| 213 | // art::Runtime** xIP0 = &art::Runtime::instance_ |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 214 | adrp xIP0, :got:_ZN3art7Runtime9instance_E |
| 215 | ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 216 | |
| 217 | // Our registers aren't intermixed - just spill in order. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 218 | ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_; |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 219 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 220 | // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveRefAndArgs]; |
| 221 | ldr xIP0, [xIP0, RUNTIME_SAVE_REFS_AND_ARGS_METHOD_OFFSET] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 222 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 223 | SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 224 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 225 | str xIP0, [sp] // Store ArtMethod* Runtime::callee_save_methods_[kSaveRefsAndArgs]. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 226 | // Place sp in Thread::Current()->top_quick_frame. |
| 227 | mov xIP0, sp |
| 228 | str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] |
| 229 | .endm |
| 230 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 231 | .macro SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0 |
| 232 | SETUP_SAVE_REFS_AND_ARGS_FRAME_INTERNAL |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 233 | str x0, [sp, #0] // Store ArtMethod* to bottom of stack. |
| 234 | // Place sp in Thread::Current()->top_quick_frame. |
| 235 | mov xIP0, sp |
| 236 | str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 237 | .endm |
| 238 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 239 | // TODO: Probably no need to restore registers preserved by aapcs64. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 240 | .macro RESTORE_SAVE_REFS_AND_ARGS_FRAME |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 241 | // FP args. |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 242 | ldp d0, d1, [sp, #16] |
| 243 | ldp d2, d3, [sp, #32] |
| 244 | ldp d4, d5, [sp, #48] |
| 245 | ldp d6, d7, [sp, #64] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 246 | |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 247 | // Core args. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 248 | RESTORE_TWO_REGS x1, x2, 80 |
| 249 | RESTORE_TWO_REGS x3, x4, 96 |
| 250 | RESTORE_TWO_REGS x5, x6, 112 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 251 | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 252 | // x7, Callee-saves. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 253 | RESTORE_TWO_REGS x7, x20, 128 |
| 254 | RESTORE_TWO_REGS x21, x22, 144 |
| 255 | RESTORE_TWO_REGS x23, x24, 160 |
| 256 | RESTORE_TWO_REGS x25, x26, 176 |
| 257 | RESTORE_TWO_REGS x27, x28, 192 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 258 | |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 259 | // x29(callee-save) and LR. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 260 | RESTORE_TWO_REGS x29, xLR, 208 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 261 | |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 262 | DECREASE_FRAME 224 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 263 | .endm |
| 264 | |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 265 | /* |
| 266 | * Macro that sets up the callee save frame to conform with |
| 267 | * Runtime::CreateCalleeSaveMethod(kSaveEverything) |
Vladimir Marko | 3b7537b | 2016-09-13 11:56:01 +0000 | [diff] [blame] | 268 | * when the SP has already been decremented by FRAME_SIZE_SAVE_EVERYTHING |
| 269 | * and saving registers x29 and LR is handled elsewhere. |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 270 | */ |
Vladimir Marko | 3b7537b | 2016-09-13 11:56:01 +0000 | [diff] [blame] | 271 | .macro SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 272 | // Ugly compile-time check, but we only have the preprocessor. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 273 | #if (FRAME_SIZE_SAVE_EVERYTHING != 512) |
| 274 | #error "FRAME_SIZE_SAVE_EVERYTHING(ARM64) size not as expected." |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 275 | #endif |
| 276 | |
| 277 | // Save FP registers. |
Vladimir Marko | 40df7c1 | 2016-08-22 16:02:12 +0100 | [diff] [blame] | 278 | // For better performance, store d0 and d31 separately, so that all STPs are 16-byte aligned. |
Vladimir Marko | de5f194 | 2016-08-10 12:30:05 +0100 | [diff] [blame] | 279 | str d0, [sp, #8] |
| 280 | stp d1, d2, [sp, #16] |
| 281 | stp d3, d4, [sp, #32] |
| 282 | stp d5, d6, [sp, #48] |
| 283 | stp d7, d8, [sp, #64] |
| 284 | stp d9, d10, [sp, #80] |
| 285 | stp d11, d12, [sp, #96] |
| 286 | stp d13, d14, [sp, #112] |
| 287 | stp d15, d16, [sp, #128] |
| 288 | stp d17, d18, [sp, #144] |
| 289 | stp d19, d20, [sp, #160] |
| 290 | stp d21, d22, [sp, #176] |
| 291 | stp d23, d24, [sp, #192] |
| 292 | stp d25, d26, [sp, #208] |
| 293 | stp d27, d28, [sp, #224] |
| 294 | stp d29, d30, [sp, #240] |
| 295 | str d31, [sp, #256] |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 296 | |
| 297 | // Save core registers. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 298 | SAVE_REG x0, 264 |
| 299 | SAVE_TWO_REGS x1, x2, 272 |
| 300 | SAVE_TWO_REGS x3, x4, 288 |
| 301 | SAVE_TWO_REGS x5, x6, 304 |
| 302 | SAVE_TWO_REGS x7, x8, 320 |
| 303 | SAVE_TWO_REGS x9, x10, 336 |
| 304 | SAVE_TWO_REGS x11, x12, 352 |
| 305 | SAVE_TWO_REGS x13, x14, 368 |
| 306 | SAVE_TWO_REGS x15, x16, 384 |
| 307 | SAVE_TWO_REGS x17, x18, 400 |
| 308 | SAVE_TWO_REGS x19, x20, 416 |
| 309 | SAVE_TWO_REGS x21, x22, 432 |
| 310 | SAVE_TWO_REGS x23, x24, 448 |
| 311 | SAVE_TWO_REGS x25, x26, 464 |
| 312 | SAVE_TWO_REGS x27, x28, 480 |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 313 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 314 | // art::Runtime** xIP0 = &art::Runtime::instance_ |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 315 | adrp xIP0, :got:_ZN3art7Runtime9instance_E |
| 316 | ldr xIP0, [xIP0, #:got_lo12:_ZN3art7Runtime9instance_E] |
| 317 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 318 | ldr xIP0, [xIP0] // art::Runtime* xIP0 = art::Runtime::instance_; |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 319 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 320 | // ArtMethod* xIP0 = Runtime::instance_->callee_save_methods_[kSaveEverything]; |
| 321 | ldr xIP0, [xIP0, RUNTIME_SAVE_EVERYTHING_METHOD_OFFSET] |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 322 | |
| 323 | // Store ArtMethod* Runtime::callee_save_methods_[kSaveEverything]. |
| 324 | str xIP0, [sp] |
| 325 | // Place sp in Thread::Current()->top_quick_frame. |
| 326 | mov xIP0, sp |
| 327 | str xIP0, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] |
| 328 | .endm |
| 329 | |
Vladimir Marko | 3b7537b | 2016-09-13 11:56:01 +0000 | [diff] [blame] | 330 | /* |
| 331 | * Macro that sets up the callee save frame to conform with |
| 332 | * Runtime::CreateCalleeSaveMethod(kSaveEverything) |
| 333 | */ |
| 334 | .macro SETUP_SAVE_EVERYTHING_FRAME |
| 335 | INCREASE_FRAME 512 |
| 336 | SAVE_TWO_REGS x29, xLR, 496 |
| 337 | SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR |
| 338 | .endm |
| 339 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 340 | .macro RESTORE_SAVE_EVERYTHING_FRAME |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 341 | // Restore FP registers. |
Vladimir Marko | 40df7c1 | 2016-08-22 16:02:12 +0100 | [diff] [blame] | 342 | // For better performance, load d0 and d31 separately, so that all LDPs are 16-byte aligned. |
Vladimir Marko | de5f194 | 2016-08-10 12:30:05 +0100 | [diff] [blame] | 343 | ldr d0, [sp, #8] |
| 344 | ldp d1, d2, [sp, #16] |
| 345 | ldp d3, d4, [sp, #32] |
| 346 | ldp d5, d6, [sp, #48] |
| 347 | ldp d7, d8, [sp, #64] |
| 348 | ldp d9, d10, [sp, #80] |
| 349 | ldp d11, d12, [sp, #96] |
| 350 | ldp d13, d14, [sp, #112] |
| 351 | ldp d15, d16, [sp, #128] |
| 352 | ldp d17, d18, [sp, #144] |
| 353 | ldp d19, d20, [sp, #160] |
| 354 | ldp d21, d22, [sp, #176] |
| 355 | ldp d23, d24, [sp, #192] |
| 356 | ldp d25, d26, [sp, #208] |
| 357 | ldp d27, d28, [sp, #224] |
| 358 | ldp d29, d30, [sp, #240] |
| 359 | ldr d31, [sp, #256] |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 360 | |
| 361 | // Restore core registers. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 362 | RESTORE_REG x0, 264 |
| 363 | RESTORE_TWO_REGS x1, x2, 272 |
| 364 | RESTORE_TWO_REGS x3, x4, 288 |
| 365 | RESTORE_TWO_REGS x5, x6, 304 |
| 366 | RESTORE_TWO_REGS x7, x8, 320 |
| 367 | RESTORE_TWO_REGS x9, x10, 336 |
| 368 | RESTORE_TWO_REGS x11, x12, 352 |
| 369 | RESTORE_TWO_REGS x13, x14, 368 |
| 370 | RESTORE_TWO_REGS x15, x16, 384 |
| 371 | RESTORE_TWO_REGS x17, x18, 400 |
| 372 | RESTORE_TWO_REGS x19, x20, 416 |
| 373 | RESTORE_TWO_REGS x21, x22, 432 |
| 374 | RESTORE_TWO_REGS x23, x24, 448 |
| 375 | RESTORE_TWO_REGS x25, x26, 464 |
| 376 | RESTORE_TWO_REGS x27, x28, 480 |
| 377 | RESTORE_TWO_REGS x29, xLR, 496 |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 378 | |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 379 | DECREASE_FRAME 512 |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 380 | .endm |
| 381 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 382 | .macro RETURN_IF_RESULT_IS_ZERO |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 383 | cbnz x0, 1f // result non-zero branch over |
| 384 | ret // return |
| 385 | 1: |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 386 | .endm |
| 387 | |
| 388 | .macro RETURN_IF_RESULT_IS_NON_ZERO |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 389 | cbz x0, 1f // result zero branch over |
| 390 | ret // return |
| 391 | 1: |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 392 | .endm |
| 393 | |
| 394 | /* |
| 395 | * Macro that set calls through to artDeliverPendingExceptionFromCode, where the pending |
| 396 | * exception is Thread::Current()->exception_ |
| 397 | */ |
| 398 | .macro DELIVER_PENDING_EXCEPTION |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 399 | SETUP_SAVE_ALL_CALLEE_SAVES_FRAME |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 400 | mov x0, xSELF |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 401 | |
| 402 | // Point of no return. |
Vladimir Marko | 908eb22 | 2016-09-14 10:29:18 +0100 | [diff] [blame^] | 403 | bl artDeliverPendingExceptionFromCode // artDeliverPendingExceptionFromCode(Thread*) |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 404 | brk 0 // Unreached |
| 405 | .endm |
| 406 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 407 | .macro RETURN_OR_DELIVER_PENDING_EXCEPTION_REG reg |
| 408 | ldr \reg, [xSELF, # THREAD_EXCEPTION_OFFSET] // Get exception field. |
| 409 | cbnz \reg, 1f |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 410 | ret |
| 411 | 1: |
| 412 | DELIVER_PENDING_EXCEPTION |
| 413 | .endm |
| 414 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 415 | .macro RETURN_OR_DELIVER_PENDING_EXCEPTION |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 416 | RETURN_OR_DELIVER_PENDING_EXCEPTION_REG xIP0 |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 417 | .endm |
| 418 | |
| 419 | // Same as above with x1. This is helpful in stubs that want to avoid clobbering another register. |
| 420 | .macro RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 421 | RETURN_OR_DELIVER_PENDING_EXCEPTION_REG x1 |
| 422 | .endm |
| 423 | |
| 424 | .macro RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 425 | cbnz w0, 1f // result non-zero branch over |
| 426 | ret // return |
| 427 | 1: |
| 428 | DELIVER_PENDING_EXCEPTION |
| 429 | .endm |
| 430 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 431 | .macro NO_ARG_RUNTIME_EXCEPTION c_name, cxx_name |
| 432 | .extern \cxx_name |
| 433 | ENTRY \c_name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 434 | SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 435 | mov x0, xSELF // pass Thread::Current |
Vladimir Marko | 908eb22 | 2016-09-14 10:29:18 +0100 | [diff] [blame^] | 436 | bl \cxx_name // \cxx_name(Thread*) |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 437 | END \c_name |
| 438 | .endm |
| 439 | |
| 440 | .macro ONE_ARG_RUNTIME_EXCEPTION c_name, cxx_name |
| 441 | .extern \cxx_name |
| 442 | ENTRY \c_name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 443 | SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context. |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 444 | mov x1, xSELF // pass Thread::Current. |
Vladimir Marko | 908eb22 | 2016-09-14 10:29:18 +0100 | [diff] [blame^] | 445 | bl \cxx_name // \cxx_name(arg, Thread*). |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 446 | brk 0 |
| 447 | END \c_name |
| 448 | .endm |
| 449 | |
| 450 | .macro TWO_ARG_RUNTIME_EXCEPTION c_name, cxx_name |
| 451 | .extern \cxx_name |
| 452 | ENTRY \c_name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 453 | SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 454 | mov x2, xSELF // pass Thread::Current |
Vladimir Marko | 908eb22 | 2016-09-14 10:29:18 +0100 | [diff] [blame^] | 455 | bl \cxx_name // \cxx_name(arg1, arg2, Thread*) |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 456 | brk 0 |
| 457 | END \c_name |
| 458 | .endm |
| 459 | |
| 460 | /* |
| 461 | * Called by managed code, saves callee saves and then calls artThrowException |
| 462 | * that will place a mock Method* at the bottom of the stack. Arg1 holds the exception. |
| 463 | */ |
| 464 | ONE_ARG_RUNTIME_EXCEPTION art_quick_deliver_exception, artDeliverExceptionFromCode |
| 465 | |
| 466 | /* |
| 467 | * Called by managed code to create and deliver a NullPointerException. |
| 468 | */ |
| 469 | NO_ARG_RUNTIME_EXCEPTION art_quick_throw_null_pointer_exception, artThrowNullPointerExceptionFromCode |
| 470 | |
| 471 | /* |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 472 | * Call installed by a signal handler to create and deliver a NullPointerException. |
| 473 | */ |
Vladimir Marko | 3b7537b | 2016-09-13 11:56:01 +0000 | [diff] [blame] | 474 | .extern art_quick_throw_null_pointer_exception_from_signal |
| 475 | ENTRY art_quick_throw_null_pointer_exception_from_signal |
| 476 | // The fault handler pushes the gc map address, i.e. "return address", to stack |
| 477 | // and passes the fault address in LR. So we need to set up the CFI info accordingly. |
| 478 | .cfi_def_cfa_offset __SIZEOF_POINTER__ |
| 479 | .cfi_rel_offset lr, 0 |
| 480 | // Save all registers as basis for long jump context. |
| 481 | INCREASE_FRAME (FRAME_SIZE_SAVE_EVERYTHING - __SIZEOF_POINTER__) |
| 482 | SAVE_REG x29, (FRAME_SIZE_SAVE_EVERYTHING - 2 * __SIZEOF_POINTER__) // LR already saved. |
| 483 | SETUP_SAVE_EVERYTHING_FRAME_DECREMENTED_SP_SKIP_X29_LR |
| 484 | mov x0, lr // pass the fault address stored in LR by the fault handler. |
| 485 | mov x1, xSELF // pass Thread::Current. |
Vladimir Marko | 908eb22 | 2016-09-14 10:29:18 +0100 | [diff] [blame^] | 486 | bl artThrowNullPointerExceptionFromSignal // (arg, Thread*). |
Vladimir Marko | 3b7537b | 2016-09-13 11:56:01 +0000 | [diff] [blame] | 487 | brk 0 |
| 488 | END art_quick_throw_null_pointer_exception_from_signal |
Nicolas Geoffray | e8e1127 | 2016-06-28 18:08:46 +0100 | [diff] [blame] | 489 | |
| 490 | /* |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 491 | * Called by managed code to create and deliver an ArithmeticException. |
| 492 | */ |
| 493 | NO_ARG_RUNTIME_EXCEPTION art_quick_throw_div_zero, artThrowDivZeroFromCode |
| 494 | |
| 495 | /* |
| 496 | * Called by managed code to create and deliver an ArrayIndexOutOfBoundsException. Arg1 holds |
| 497 | * index, arg2 holds limit. |
| 498 | */ |
| 499 | TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_array_bounds, artThrowArrayBoundsFromCode |
| 500 | |
| 501 | /* |
Vladimir Marko | 87f3fcb | 2016-04-28 15:52:11 +0100 | [diff] [blame] | 502 | * Called by managed code to create and deliver a StringIndexOutOfBoundsException |
| 503 | * as if thrown from a call to String.charAt(). Arg1 holds index, arg2 holds limit. |
| 504 | */ |
| 505 | TWO_ARG_RUNTIME_EXCEPTION art_quick_throw_string_bounds, artThrowStringBoundsFromCode |
| 506 | |
| 507 | /* |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 508 | * Called by managed code to create and deliver a StackOverflowError. |
| 509 | */ |
| 510 | NO_ARG_RUNTIME_EXCEPTION art_quick_throw_stack_overflow, artThrowStackOverflowFromCode |
| 511 | |
| 512 | /* |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 513 | * All generated callsites for interface invokes and invocation slow paths will load arguments |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 514 | * as usual - except instead of loading arg0/x0 with the target Method*, arg0/x0 will contain |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 515 | * the method_idx. This wrapper will save arg1-arg3, and call the appropriate C helper. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 516 | * NOTE: "this" is first visible argument of the target, and so can be found in arg1/x1. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 517 | * |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 518 | * The helper will attempt to locate the target and return a 128-bit result in x0/x1 consisting |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 519 | * of the target Method* in x0 and method->code_ in x1. |
| 520 | * |
Mathieu Chartier | 2cebb24 | 2015-04-21 16:50:40 -0700 | [diff] [blame] | 521 | * If unsuccessful, the helper will return null/????. There will be a pending exception in the |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 522 | * thread and we branch to another stub to deliver it. |
| 523 | * |
| 524 | * On success this wrapper will restore arguments and *jump* to the target, leaving the lr |
| 525 | * pointing back to the original caller. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 526 | * |
| 527 | * Adapted from ARM32 code. |
| 528 | * |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 529 | * Clobbers xIP0. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 530 | */ |
Andreas Gampe | 3031c8d | 2015-07-13 20:11:06 -0700 | [diff] [blame] | 531 | .macro INVOKE_TRAMPOLINE_BODY cxx_name |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 532 | .extern \cxx_name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 533 | SETUP_SAVE_REFS_AND_ARGS_FRAME // save callee saves in case allocation triggers GC |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 534 | // Helper signature is always |
| 535 | // (method_idx, *this_object, *caller_method, *self, sp) |
| 536 | |
Nicolas Geoffray | 7ea6a17 | 2015-05-19 18:58:54 +0100 | [diff] [blame] | 537 | mov x2, xSELF // pass Thread::Current |
| 538 | mov x3, sp |
| 539 | bl \cxx_name // (method_idx, this, Thread*, SP) |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 540 | mov xIP0, x1 // save Method*->code_ |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 541 | RESTORE_SAVE_REFS_AND_ARGS_FRAME |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 542 | cbz x0, 1f // did we find the target? if not go to exception delivery |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 543 | br xIP0 // tail call to target |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 544 | 1: |
| 545 | DELIVER_PENDING_EXCEPTION |
Andreas Gampe | 3031c8d | 2015-07-13 20:11:06 -0700 | [diff] [blame] | 546 | .endm |
| 547 | .macro INVOKE_TRAMPOLINE c_name, cxx_name |
| 548 | ENTRY \c_name |
| 549 | INVOKE_TRAMPOLINE_BODY \cxx_name |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 550 | END \c_name |
| 551 | .endm |
| 552 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 553 | INVOKE_TRAMPOLINE art_quick_invoke_interface_trampoline_with_access_check, artInvokeInterfaceTrampolineWithAccessCheck |
| 554 | |
| 555 | INVOKE_TRAMPOLINE art_quick_invoke_static_trampoline_with_access_check, artInvokeStaticTrampolineWithAccessCheck |
| 556 | INVOKE_TRAMPOLINE art_quick_invoke_direct_trampoline_with_access_check, artInvokeDirectTrampolineWithAccessCheck |
| 557 | INVOKE_TRAMPOLINE art_quick_invoke_super_trampoline_with_access_check, artInvokeSuperTrampolineWithAccessCheck |
| 558 | INVOKE_TRAMPOLINE art_quick_invoke_virtual_trampoline_with_access_check, artInvokeVirtualTrampolineWithAccessCheck |
| 559 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 560 | |
| 561 | .macro INVOKE_STUB_CREATE_FRAME |
| 562 | |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 563 | SAVE_SIZE=15*8 // x4, x5, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 564 | SAVE_SIZE_AND_METHOD=SAVE_SIZE+8 |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 565 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 566 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 567 | mov x9, sp // Save stack pointer. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 568 | .cfi_register sp,x9 |
| 569 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 570 | add x10, x2, # SAVE_SIZE_AND_METHOD // calculate size of frame. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 571 | sub x10, sp, x10 // Calculate SP position - saves + ArtMethod* + args |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 572 | and x10, x10, # ~0xf // Enforce 16 byte stack alignment. |
| 573 | mov sp, x10 // Set new SP. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 574 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 575 | sub x10, x9, #SAVE_SIZE // Calculate new FP (later). Done here as we must move SP |
| 576 | .cfi_def_cfa_register x10 // before this. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 577 | .cfi_adjust_cfa_offset SAVE_SIZE |
| 578 | |
Nicolas Geoffray | 4808846 | 2014-12-12 10:29:38 +0000 | [diff] [blame] | 579 | str x28, [x10, #112] |
| 580 | .cfi_rel_offset x28, 112 |
| 581 | |
| 582 | stp x26, x27, [x10, #96] |
| 583 | .cfi_rel_offset x26, 96 |
| 584 | .cfi_rel_offset x27, 104 |
| 585 | |
| 586 | stp x24, x25, [x10, #80] |
| 587 | .cfi_rel_offset x24, 80 |
| 588 | .cfi_rel_offset x25, 88 |
| 589 | |
| 590 | stp x22, x23, [x10, #64] |
| 591 | .cfi_rel_offset x22, 64 |
| 592 | .cfi_rel_offset x23, 72 |
| 593 | |
| 594 | stp x20, x21, [x10, #48] |
| 595 | .cfi_rel_offset x20, 48 |
| 596 | .cfi_rel_offset x21, 56 |
| 597 | |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 598 | stp x9, x19, [x10, #32] // Save old stack pointer and x19. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 599 | .cfi_rel_offset sp, 32 |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 600 | .cfi_rel_offset x19, 40 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 601 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 602 | stp x4, x5, [x10, #16] // Save result and shorty addresses. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 603 | .cfi_rel_offset x4, 16 |
| 604 | .cfi_rel_offset x5, 24 |
| 605 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 606 | stp xFP, xLR, [x10] // Store LR & FP. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 607 | .cfi_rel_offset x29, 0 |
| 608 | .cfi_rel_offset x30, 8 |
| 609 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 610 | mov xFP, x10 // Use xFP now, as it's callee-saved. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 611 | .cfi_def_cfa_register x29 |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 612 | mov xSELF, x3 // Move thread pointer into SELF register. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 613 | |
| 614 | // Copy arguments into stack frame. |
| 615 | // Use simple copy routine for now. |
| 616 | // 4 bytes per slot. |
| 617 | // X1 - source address |
| 618 | // W2 - args length |
| 619 | // X9 - destination address. |
| 620 | // W10 - temporary |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 621 | add x9, sp, #8 // Destination address is bottom of stack + null. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 622 | |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 623 | // Copy parameters into the stack. Use numeric label as this is a macro and Clang's assembler |
| 624 | // does not have unique-id variables. |
| 625 | 1: |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 626 | cmp w2, #0 |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 627 | beq 2f |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 628 | sub w2, w2, #4 // Need 65536 bytes of range. |
| 629 | ldr w10, [x1, x2] |
| 630 | str w10, [x9, x2] |
| 631 | |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 632 | b 1b |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 633 | |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 634 | 2: |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 635 | // Store null into ArtMethod* at bottom of frame. |
| 636 | str xzr, [sp] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 637 | .endm |
| 638 | |
| 639 | .macro INVOKE_STUB_CALL_AND_RETURN |
| 640 | |
| 641 | // load method-> METHOD_QUICK_CODE_OFFSET |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 642 | ldr x9, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64] |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 643 | // Branch to method. |
| 644 | blr x9 |
| 645 | |
| 646 | // Restore return value address and shorty address. |
| 647 | ldp x4,x5, [xFP, #16] |
| 648 | .cfi_restore x4 |
| 649 | .cfi_restore x5 |
| 650 | |
Nicolas Geoffray | 4808846 | 2014-12-12 10:29:38 +0000 | [diff] [blame] | 651 | ldr x28, [xFP, #112] |
| 652 | .cfi_restore x28 |
| 653 | |
| 654 | ldp x26, x27, [xFP, #96] |
| 655 | .cfi_restore x26 |
| 656 | .cfi_restore x27 |
| 657 | |
| 658 | ldp x24, x25, [xFP, #80] |
| 659 | .cfi_restore x24 |
| 660 | .cfi_restore x25 |
| 661 | |
| 662 | ldp x22, x23, [xFP, #64] |
| 663 | .cfi_restore x22 |
| 664 | .cfi_restore x23 |
| 665 | |
| 666 | ldp x20, x21, [xFP, #48] |
| 667 | .cfi_restore x20 |
| 668 | .cfi_restore x21 |
| 669 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 670 | // Store result (w0/x0/s0/d0) appropriately, depending on resultType. |
| 671 | ldrb w10, [x5] |
| 672 | |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 673 | // Check the return type and store the correct register into the jvalue in memory. |
| 674 | // Use numeric label as this is a macro and Clang's assembler does not have unique-id variables. |
| 675 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 676 | // Don't set anything for a void type. |
| 677 | cmp w10, #'V' |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 678 | beq 3f |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 679 | |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 680 | // Is it a double? |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 681 | cmp w10, #'D' |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 682 | bne 1f |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 683 | str d0, [x4] |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 684 | b 3f |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 685 | |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 686 | 1: // Is it a float? |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 687 | cmp w10, #'F' |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 688 | bne 2f |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 689 | str s0, [x4] |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 690 | b 3f |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 691 | |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 692 | 2: // Just store x0. Doesn't matter if it is 64 or 32 bits. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 693 | str x0, [x4] |
| 694 | |
Chih-Hung Hsieh | c0da7ac | 2015-07-27 10:10:44 -0700 | [diff] [blame] | 695 | 3: // Finish up. |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 696 | ldp x2, x19, [xFP, #32] // Restore stack pointer and x19. |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 697 | .cfi_restore x19 |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 698 | mov sp, x2 |
| 699 | .cfi_restore sp |
| 700 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 701 | ldp xFP, xLR, [xFP] // Restore old frame pointer and link register. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 702 | .cfi_restore x29 |
| 703 | .cfi_restore x30 |
| 704 | |
| 705 | ret |
| 706 | |
| 707 | .endm |
| 708 | |
| 709 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 710 | /* |
| 711 | * extern"C" void art_quick_invoke_stub(ArtMethod *method, x0 |
| 712 | * uint32_t *args, x1 |
| 713 | * uint32_t argsize, w2 |
| 714 | * Thread *self, x3 |
| 715 | * JValue *result, x4 |
| 716 | * char *shorty); x5 |
| 717 | * +----------------------+ |
| 718 | * | | |
| 719 | * | C/C++ frame | |
| 720 | * | LR'' | |
| 721 | * | FP'' | <- SP' |
| 722 | * +----------------------+ |
| 723 | * +----------------------+ |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 724 | * | x28 | <- TODO: Remove callee-saves. |
| 725 | * | : | |
| 726 | * | x19 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 727 | * | SP' | |
| 728 | * | X5 | |
| 729 | * | X4 | Saved registers |
| 730 | * | LR' | |
| 731 | * | FP' | <- FP |
| 732 | * +----------------------+ |
| 733 | * | uint32_t out[n-1] | |
| 734 | * | : : | Outs |
| 735 | * | uint32_t out[0] | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 736 | * | ArtMethod* | <- SP value=null |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 737 | * +----------------------+ |
| 738 | * |
| 739 | * Outgoing registers: |
| 740 | * x0 - Method* |
| 741 | * x1-x7 - integer parameters. |
| 742 | * d0-d7 - Floating point parameters. |
| 743 | * xSELF = self |
| 744 | * SP = & of ArtMethod* |
| 745 | * x1 = "this" pointer. |
| 746 | * |
| 747 | */ |
| 748 | ENTRY art_quick_invoke_stub |
| 749 | // Spill registers as per AACPS64 calling convention. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 750 | INVOKE_STUB_CREATE_FRAME |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 751 | |
| 752 | // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. |
| 753 | // Parse the passed shorty to determine which register to load. |
| 754 | // Load addresses for routines that load WXSD registers. |
| 755 | adr x11, .LstoreW2 |
| 756 | adr x12, .LstoreX2 |
| 757 | adr x13, .LstoreS0 |
| 758 | adr x14, .LstoreD0 |
| 759 | |
| 760 | // Initialize routine offsets to 0 for integers and floats. |
| 761 | // x8 for integers, x15 for floating point. |
| 762 | mov x8, #0 |
| 763 | mov x15, #0 |
| 764 | |
| 765 | add x10, x5, #1 // Load shorty address, plus one to skip return value. |
| 766 | ldr w1, [x9],#4 // Load "this" parameter, and increment arg pointer. |
| 767 | |
| 768 | // Loop to fill registers. |
| 769 | .LfillRegisters: |
| 770 | ldrb w17, [x10], #1 // Load next character in signature, and increment. |
| 771 | cbz w17, .LcallFunction // Exit at end of signature. Shorty 0 terminated. |
| 772 | |
| 773 | cmp w17, #'F' // is this a float? |
| 774 | bne .LisDouble |
| 775 | |
| 776 | cmp x15, # 8*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 777 | beq .Ladvance4 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 778 | |
| 779 | add x17, x13, x15 // Calculate subroutine to jump to. |
| 780 | br x17 |
| 781 | |
| 782 | .LisDouble: |
| 783 | cmp w17, #'D' // is this a double? |
| 784 | bne .LisLong |
| 785 | |
| 786 | cmp x15, # 8*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 787 | beq .Ladvance8 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 788 | |
| 789 | add x17, x14, x15 // Calculate subroutine to jump to. |
| 790 | br x17 |
| 791 | |
| 792 | .LisLong: |
| 793 | cmp w17, #'J' // is this a long? |
| 794 | bne .LisOther |
| 795 | |
Andreas Gampe | 9de65ff | 2014-03-21 17:25:57 -0700 | [diff] [blame] | 796 | cmp x8, # 6*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 797 | beq .Ladvance8 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 798 | |
| 799 | add x17, x12, x8 // Calculate subroutine to jump to. |
| 800 | br x17 |
| 801 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 802 | .LisOther: // Everything else takes one vReg. |
Andreas Gampe | 9de65ff | 2014-03-21 17:25:57 -0700 | [diff] [blame] | 803 | cmp x8, # 6*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 804 | beq .Ladvance4 |
| 805 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 806 | add x17, x11, x8 // Calculate subroutine to jump to. |
| 807 | br x17 |
| 808 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 809 | .Ladvance4: |
| 810 | add x9, x9, #4 |
| 811 | b .LfillRegisters |
| 812 | |
| 813 | .Ladvance8: |
| 814 | add x9, x9, #8 |
| 815 | b .LfillRegisters |
| 816 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 817 | // Macro for loading a parameter into a register. |
| 818 | // counter - the register with offset into these tables |
| 819 | // size - the size of the register - 4 or 8 bytes. |
| 820 | // register - the name of the register to be loaded. |
| 821 | .macro LOADREG counter size register return |
| 822 | ldr \register , [x9], #\size |
| 823 | add \counter, \counter, 12 |
| 824 | b \return |
| 825 | .endm |
| 826 | |
| 827 | // Store ints. |
| 828 | .LstoreW2: |
| 829 | LOADREG x8 4 w2 .LfillRegisters |
| 830 | LOADREG x8 4 w3 .LfillRegisters |
| 831 | LOADREG x8 4 w4 .LfillRegisters |
| 832 | LOADREG x8 4 w5 .LfillRegisters |
| 833 | LOADREG x8 4 w6 .LfillRegisters |
| 834 | LOADREG x8 4 w7 .LfillRegisters |
| 835 | |
| 836 | // Store longs. |
| 837 | .LstoreX2: |
| 838 | LOADREG x8 8 x2 .LfillRegisters |
| 839 | LOADREG x8 8 x3 .LfillRegisters |
| 840 | LOADREG x8 8 x4 .LfillRegisters |
| 841 | LOADREG x8 8 x5 .LfillRegisters |
| 842 | LOADREG x8 8 x6 .LfillRegisters |
| 843 | LOADREG x8 8 x7 .LfillRegisters |
| 844 | |
| 845 | // Store singles. |
| 846 | .LstoreS0: |
| 847 | LOADREG x15 4 s0 .LfillRegisters |
| 848 | LOADREG x15 4 s1 .LfillRegisters |
| 849 | LOADREG x15 4 s2 .LfillRegisters |
| 850 | LOADREG x15 4 s3 .LfillRegisters |
| 851 | LOADREG x15 4 s4 .LfillRegisters |
| 852 | LOADREG x15 4 s5 .LfillRegisters |
| 853 | LOADREG x15 4 s6 .LfillRegisters |
| 854 | LOADREG x15 4 s7 .LfillRegisters |
| 855 | |
| 856 | // Store doubles. |
| 857 | .LstoreD0: |
| 858 | LOADREG x15 8 d0 .LfillRegisters |
| 859 | LOADREG x15 8 d1 .LfillRegisters |
| 860 | LOADREG x15 8 d2 .LfillRegisters |
| 861 | LOADREG x15 8 d3 .LfillRegisters |
| 862 | LOADREG x15 8 d4 .LfillRegisters |
| 863 | LOADREG x15 8 d5 .LfillRegisters |
| 864 | LOADREG x15 8 d6 .LfillRegisters |
| 865 | LOADREG x15 8 d7 .LfillRegisters |
| 866 | |
| 867 | |
| 868 | .LcallFunction: |
| 869 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 870 | INVOKE_STUB_CALL_AND_RETURN |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 871 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 872 | END art_quick_invoke_stub |
| 873 | |
| 874 | /* extern"C" |
| 875 | * void art_quick_invoke_static_stub(ArtMethod *method, x0 |
| 876 | * uint32_t *args, x1 |
| 877 | * uint32_t argsize, w2 |
| 878 | * Thread *self, x3 |
| 879 | * JValue *result, x4 |
| 880 | * char *shorty); x5 |
| 881 | */ |
| 882 | ENTRY art_quick_invoke_static_stub |
| 883 | // Spill registers as per AACPS64 calling convention. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 884 | INVOKE_STUB_CREATE_FRAME |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 885 | |
| 886 | // Fill registers x/w1 to x/w7 and s/d0 to s/d7 with parameters. |
| 887 | // Parse the passed shorty to determine which register to load. |
| 888 | // Load addresses for routines that load WXSD registers. |
| 889 | adr x11, .LstoreW1_2 |
| 890 | adr x12, .LstoreX1_2 |
| 891 | adr x13, .LstoreS0_2 |
| 892 | adr x14, .LstoreD0_2 |
| 893 | |
| 894 | // Initialize routine offsets to 0 for integers and floats. |
| 895 | // x8 for integers, x15 for floating point. |
| 896 | mov x8, #0 |
| 897 | mov x15, #0 |
| 898 | |
| 899 | add x10, x5, #1 // Load shorty address, plus one to skip return value. |
| 900 | |
| 901 | // Loop to fill registers. |
| 902 | .LfillRegisters2: |
| 903 | ldrb w17, [x10], #1 // Load next character in signature, and increment. |
| 904 | cbz w17, .LcallFunction2 // Exit at end of signature. Shorty 0 terminated. |
| 905 | |
| 906 | cmp w17, #'F' // is this a float? |
| 907 | bne .LisDouble2 |
| 908 | |
| 909 | cmp x15, # 8*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 910 | beq .Ladvance4_2 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 911 | |
| 912 | add x17, x13, x15 // Calculate subroutine to jump to. |
| 913 | br x17 |
| 914 | |
| 915 | .LisDouble2: |
| 916 | cmp w17, #'D' // is this a double? |
| 917 | bne .LisLong2 |
| 918 | |
| 919 | cmp x15, # 8*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 920 | beq .Ladvance8_2 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 921 | |
| 922 | add x17, x14, x15 // Calculate subroutine to jump to. |
| 923 | br x17 |
| 924 | |
| 925 | .LisLong2: |
| 926 | cmp w17, #'J' // is this a long? |
| 927 | bne .LisOther2 |
| 928 | |
| 929 | cmp x8, # 7*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 930 | beq .Ladvance8_2 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 931 | |
| 932 | add x17, x12, x8 // Calculate subroutine to jump to. |
| 933 | br x17 |
| 934 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 935 | .LisOther2: // Everything else takes one vReg. |
| 936 | cmp x8, # 7*12 // Skip this load if all registers full. |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 937 | beq .Ladvance4_2 |
| 938 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 939 | add x17, x11, x8 // Calculate subroutine to jump to. |
| 940 | br x17 |
| 941 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 942 | .Ladvance4_2: |
| 943 | add x9, x9, #4 |
| 944 | b .LfillRegisters2 |
| 945 | |
| 946 | .Ladvance8_2: |
| 947 | add x9, x9, #8 |
| 948 | b .LfillRegisters2 |
| 949 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 950 | // Store ints. |
| 951 | .LstoreW1_2: |
| 952 | LOADREG x8 4 w1 .LfillRegisters2 |
| 953 | LOADREG x8 4 w2 .LfillRegisters2 |
| 954 | LOADREG x8 4 w3 .LfillRegisters2 |
| 955 | LOADREG x8 4 w4 .LfillRegisters2 |
| 956 | LOADREG x8 4 w5 .LfillRegisters2 |
| 957 | LOADREG x8 4 w6 .LfillRegisters2 |
| 958 | LOADREG x8 4 w7 .LfillRegisters2 |
| 959 | |
| 960 | // Store longs. |
| 961 | .LstoreX1_2: |
| 962 | LOADREG x8 8 x1 .LfillRegisters2 |
| 963 | LOADREG x8 8 x2 .LfillRegisters2 |
| 964 | LOADREG x8 8 x3 .LfillRegisters2 |
| 965 | LOADREG x8 8 x4 .LfillRegisters2 |
| 966 | LOADREG x8 8 x5 .LfillRegisters2 |
| 967 | LOADREG x8 8 x6 .LfillRegisters2 |
| 968 | LOADREG x8 8 x7 .LfillRegisters2 |
| 969 | |
| 970 | // Store singles. |
| 971 | .LstoreS0_2: |
| 972 | LOADREG x15 4 s0 .LfillRegisters2 |
| 973 | LOADREG x15 4 s1 .LfillRegisters2 |
| 974 | LOADREG x15 4 s2 .LfillRegisters2 |
| 975 | LOADREG x15 4 s3 .LfillRegisters2 |
| 976 | LOADREG x15 4 s4 .LfillRegisters2 |
| 977 | LOADREG x15 4 s5 .LfillRegisters2 |
| 978 | LOADREG x15 4 s6 .LfillRegisters2 |
| 979 | LOADREG x15 4 s7 .LfillRegisters2 |
| 980 | |
| 981 | // Store doubles. |
| 982 | .LstoreD0_2: |
| 983 | LOADREG x15 8 d0 .LfillRegisters2 |
| 984 | LOADREG x15 8 d1 .LfillRegisters2 |
| 985 | LOADREG x15 8 d2 .LfillRegisters2 |
| 986 | LOADREG x15 8 d3 .LfillRegisters2 |
| 987 | LOADREG x15 8 d4 .LfillRegisters2 |
| 988 | LOADREG x15 8 d5 .LfillRegisters2 |
| 989 | LOADREG x15 8 d6 .LfillRegisters2 |
| 990 | LOADREG x15 8 d7 .LfillRegisters2 |
| 991 | |
| 992 | |
| 993 | .LcallFunction2: |
| 994 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 995 | INVOKE_STUB_CALL_AND_RETURN |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 996 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 997 | END art_quick_invoke_static_stub |
| 998 | |
Andreas Gampe | 03906cf | 2014-04-07 12:08:28 -0700 | [diff] [blame] | 999 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1000 | |
Nicolas Geoffray | b331feb | 2016-02-05 16:51:53 +0000 | [diff] [blame] | 1001 | /* extern"C" void art_quick_osr_stub(void** stack, x0 |
| 1002 | * size_t stack_size_in_bytes, x1 |
| 1003 | * const uin8_t* native_pc, x2 |
| 1004 | * JValue *result, x3 |
| 1005 | * char *shorty, x4 |
| 1006 | * Thread *self) x5 |
| 1007 | */ |
| 1008 | ENTRY art_quick_osr_stub |
| 1009 | SAVE_SIZE=15*8 // x3, x4, x19, x20, x21, x22, x23, x24, x25, x26, x27, x28, SP, LR, FP saved. |
| 1010 | mov x9, sp // Save stack pointer. |
| 1011 | .cfi_register sp,x9 |
| 1012 | |
| 1013 | sub x10, sp, # SAVE_SIZE |
| 1014 | and x10, x10, # ~0xf // Enforce 16 byte stack alignment. |
| 1015 | mov sp, x10 // Set new SP. |
| 1016 | |
| 1017 | str x28, [sp, #112] |
| 1018 | stp x26, x27, [sp, #96] |
| 1019 | stp x24, x25, [sp, #80] |
| 1020 | stp x22, x23, [sp, #64] |
| 1021 | stp x20, x21, [sp, #48] |
| 1022 | stp x9, x19, [sp, #32] // Save old stack pointer and x19. |
| 1023 | stp x3, x4, [sp, #16] // Save result and shorty addresses. |
| 1024 | stp xFP, xLR, [sp] // Store LR & FP. |
| 1025 | mov xSELF, x5 // Move thread pointer into SELF register. |
| 1026 | |
| 1027 | sub sp, sp, #16 |
| 1028 | str xzr, [sp] // Store null for ArtMethod* slot |
| 1029 | // Branch to stub. |
| 1030 | bl .Losr_entry |
| 1031 | add sp, sp, #16 |
| 1032 | |
| 1033 | // Restore return value address and shorty address. |
| 1034 | ldp x3,x4, [sp, #16] |
| 1035 | ldr x28, [sp, #112] |
| 1036 | ldp x26, x27, [sp, #96] |
| 1037 | ldp x24, x25, [sp, #80] |
| 1038 | ldp x22, x23, [sp, #64] |
| 1039 | ldp x20, x21, [sp, #48] |
| 1040 | |
| 1041 | // Store result (w0/x0/s0/d0) appropriately, depending on resultType. |
| 1042 | ldrb w10, [x4] |
| 1043 | |
| 1044 | // Check the return type and store the correct register into the jvalue in memory. |
| 1045 | |
| 1046 | // Don't set anything for a void type. |
| 1047 | cmp w10, #'V' |
| 1048 | beq .Losr_exit |
| 1049 | |
| 1050 | // Is it a double? |
| 1051 | cmp w10, #'D' |
| 1052 | bne .Lno_double |
| 1053 | str d0, [x3] |
| 1054 | b .Losr_exit |
| 1055 | |
| 1056 | .Lno_double: // Is it a float? |
| 1057 | cmp w10, #'F' |
| 1058 | bne .Lno_float |
| 1059 | str s0, [x3] |
| 1060 | b .Losr_exit |
| 1061 | |
| 1062 | .Lno_float: // Just store x0. Doesn't matter if it is 64 or 32 bits. |
| 1063 | str x0, [x3] |
| 1064 | |
| 1065 | .Losr_exit: // Finish up. |
| 1066 | ldp x2, x19, [sp, #32] // Restore stack pointer and x19. |
| 1067 | ldp xFP, xLR, [sp] // Restore old frame pointer and link register. |
| 1068 | mov sp, x2 |
| 1069 | ret |
| 1070 | |
| 1071 | .Losr_entry: |
| 1072 | // Update stack pointer for the callee |
| 1073 | sub sp, sp, x1 |
| 1074 | |
| 1075 | // Update link register slot expected by the callee. |
| 1076 | sub w1, w1, #8 |
| 1077 | str lr, [sp, x1] |
| 1078 | |
| 1079 | // Copy arguments into stack frame. |
| 1080 | // Use simple copy routine for now. |
| 1081 | // 4 bytes per slot. |
| 1082 | // X0 - source address |
| 1083 | // W1 - args length |
| 1084 | // SP - destination address. |
| 1085 | // W10 - temporary |
| 1086 | .Losr_loop_entry: |
| 1087 | cmp w1, #0 |
| 1088 | beq .Losr_loop_exit |
| 1089 | sub w1, w1, #4 |
| 1090 | ldr w10, [x0, x1] |
| 1091 | str w10, [sp, x1] |
| 1092 | b .Losr_loop_entry |
| 1093 | |
| 1094 | .Losr_loop_exit: |
| 1095 | // Branch to the OSR entry point. |
| 1096 | br x2 |
| 1097 | |
| 1098 | END art_quick_osr_stub |
| 1099 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1100 | /* |
| 1101 | * On entry x0 is uintptr_t* gprs_ and x1 is uint64_t* fprs_ |
| 1102 | */ |
| 1103 | |
| 1104 | ENTRY art_quick_do_long_jump |
| 1105 | // Load FPRs |
| 1106 | ldp d0, d1, [x1], #16 |
| 1107 | ldp d2, d3, [x1], #16 |
| 1108 | ldp d4, d5, [x1], #16 |
| 1109 | ldp d6, d7, [x1], #16 |
| 1110 | ldp d8, d9, [x1], #16 |
| 1111 | ldp d10, d11, [x1], #16 |
| 1112 | ldp d12, d13, [x1], #16 |
| 1113 | ldp d14, d15, [x1], #16 |
| 1114 | ldp d16, d17, [x1], #16 |
| 1115 | ldp d18, d19, [x1], #16 |
| 1116 | ldp d20, d21, [x1], #16 |
| 1117 | ldp d22, d23, [x1], #16 |
| 1118 | ldp d24, d25, [x1], #16 |
| 1119 | ldp d26, d27, [x1], #16 |
| 1120 | ldp d28, d29, [x1], #16 |
| 1121 | ldp d30, d31, [x1] |
| 1122 | |
| 1123 | // Load GPRs |
| 1124 | // TODO: lots of those are smashed, could optimize. |
| 1125 | add x0, x0, #30*8 |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 1126 | ldp x30, x1, [x0], #-16 // LR & SP |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1127 | ldp x28, x29, [x0], #-16 |
| 1128 | ldp x26, x27, [x0], #-16 |
| 1129 | ldp x24, x25, [x0], #-16 |
| 1130 | ldp x22, x23, [x0], #-16 |
| 1131 | ldp x20, x21, [x0], #-16 |
| 1132 | ldp x18, x19, [x0], #-16 |
| 1133 | ldp x16, x17, [x0], #-16 |
| 1134 | ldp x14, x15, [x0], #-16 |
| 1135 | ldp x12, x13, [x0], #-16 |
| 1136 | ldp x10, x11, [x0], #-16 |
| 1137 | ldp x8, x9, [x0], #-16 |
| 1138 | ldp x6, x7, [x0], #-16 |
| 1139 | ldp x4, x5, [x0], #-16 |
| 1140 | ldp x2, x3, [x0], #-16 |
| 1141 | mov sp, x1 |
| 1142 | |
Andreas Gampe | 639bdd1 | 2015-06-03 11:22:45 -0700 | [diff] [blame] | 1143 | // Need to load PC, it's at the end (after the space for the unused XZR). Use x1. |
| 1144 | ldr x1, [x0, #33*8] |
| 1145 | // And the value of x0. |
| 1146 | ldr x0, [x0] |
| 1147 | |
| 1148 | br x1 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1149 | END art_quick_do_long_jump |
| 1150 | |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1151 | /* |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1152 | * Entry from managed code that calls artLockObjectFromCode, may block for GC. x0 holds the |
| 1153 | * possibly null object to lock. |
| 1154 | * |
| 1155 | * Derived from arm32 code. |
| 1156 | */ |
| 1157 | .extern artLockObjectFromCode |
| 1158 | ENTRY art_quick_lock_object |
| 1159 | cbz w0, .Lslow_lock |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1160 | add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1161 | .Lretry_lock: |
| 1162 | ldr w2, [xSELF, #THREAD_ID_OFFSET] // TODO: Can the thread ID really change during the loop? |
| 1163 | ldxr w1, [x4] |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1164 | mov x3, x1 |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1165 | and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1166 | cbnz w3, .Lnot_unlocked // already thin locked |
| 1167 | // unlocked case - x1: original lock word that's zero except for the read barrier bits. |
| 1168 | orr x2, x1, x2 // x2 holds thread id with count of 0 with preserved read barrier bits |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1169 | stxr w3, w2, [x4] |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1170 | cbnz w3, .Llock_stxr_fail // store failed, retry |
Andreas Gampe | 675967d | 2014-05-14 16:28:34 -0700 | [diff] [blame] | 1171 | dmb ishld // full (LoadLoad|LoadStore) memory barrier |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1172 | ret |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1173 | .Lnot_unlocked: // x1: original lock word |
| 1174 | lsr w3, w1, LOCK_WORD_STATE_SHIFT |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1175 | cbnz w3, .Lslow_lock // if either of the top two bits are set, go slow path |
| 1176 | eor w2, w1, w2 // lock_word.ThreadId() ^ self->ThreadId() |
| 1177 | uxth w2, w2 // zero top 16 bits |
| 1178 | cbnz w2, .Lslow_lock // lock word and self thread id's match -> recursive lock |
| 1179 | // else contention, go to slow path |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1180 | mov x3, x1 // copy the lock word to check count overflow. |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1181 | and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits. |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1182 | add w2, w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count in lock word placing in w2 to check overflow |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1183 | lsr w3, w2, #LOCK_WORD_GC_STATE_SHIFT // if the first gc state bit is set, we overflowed. |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1184 | cbnz w3, .Lslow_lock // if we overflow the count go slow path |
| 1185 | add w2, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // increment count for real |
| 1186 | stxr w3, w2, [x4] |
| 1187 | cbnz w3, .Llock_stxr_fail // store failed, retry |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1188 | ret |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1189 | .Llock_stxr_fail: |
| 1190 | b .Lretry_lock // retry |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1191 | .Lslow_lock: |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1192 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1193 | mov x1, xSELF // pass Thread::Current |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1194 | bl artLockObjectFromCode // (Object* obj, Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1195 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1196 | RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1197 | END art_quick_lock_object |
| 1198 | |
Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 1199 | ENTRY art_quick_lock_object_no_inline |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1200 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case we block |
Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 1201 | mov x1, xSELF // pass Thread::Current |
| 1202 | bl artLockObjectFromCode // (Object* obj, Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1203 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 1204 | RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1205 | END art_quick_lock_object_no_inline |
| 1206 | |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1207 | /* |
| 1208 | * Entry from managed code that calls artUnlockObjectFromCode and delivers exception on failure. |
| 1209 | * x0 holds the possibly null object to lock. |
| 1210 | * |
| 1211 | * Derived from arm32 code. |
| 1212 | */ |
| 1213 | .extern artUnlockObjectFromCode |
| 1214 | ENTRY art_quick_unlock_object |
| 1215 | cbz x0, .Lslow_unlock |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1216 | add x4, x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET // exclusive load/store has no immediate anymore |
| 1217 | .Lretry_unlock: |
| 1218 | #ifndef USE_READ_BARRIER |
| 1219 | ldr w1, [x4] |
| 1220 | #else |
| 1221 | ldxr w1, [x4] // Need to use atomic instructions for read barrier |
| 1222 | #endif |
| 1223 | lsr w2, w1, LOCK_WORD_STATE_SHIFT |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1224 | cbnz w2, .Lslow_unlock // if either of the top two bits are set, go slow path |
| 1225 | ldr w2, [xSELF, #THREAD_ID_OFFSET] |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1226 | mov x3, x1 // copy lock word to check thread id equality |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1227 | and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1228 | eor w3, w3, w2 // lock_word.ThreadId() ^ self->ThreadId() |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1229 | uxth w3, w3 // zero top 16 bits |
| 1230 | cbnz w3, .Lslow_unlock // do lock word and self thread id's match? |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1231 | mov x3, x1 // copy lock word to detect transition to unlocked |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1232 | and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED_TOGGLED // zero the gc bits |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1233 | cmp w3, #LOCK_WORD_THIN_LOCK_COUNT_ONE |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1234 | bpl .Lrecursive_thin_unlock |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1235 | // transition to unlocked |
| 1236 | mov x3, x1 |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1237 | and w3, w3, #LOCK_WORD_GC_STATE_MASK_SHIFTED // w3: zero except for the preserved read barrier bits |
Andreas Gampe | 675967d | 2014-05-14 16:28:34 -0700 | [diff] [blame] | 1238 | dmb ish // full (LoadStore|StoreStore) memory barrier |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1239 | #ifndef USE_READ_BARRIER |
| 1240 | str w3, [x4] |
| 1241 | #else |
| 1242 | stxr w2, w3, [x4] // Need to use atomic instructions for read barrier |
| 1243 | cbnz w2, .Lunlock_stxr_fail // store failed, retry |
| 1244 | #endif |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1245 | ret |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1246 | .Lrecursive_thin_unlock: // w1: original lock word |
| 1247 | sub w1, w1, #LOCK_WORD_THIN_LOCK_COUNT_ONE // decrement count |
| 1248 | #ifndef USE_READ_BARRIER |
| 1249 | str w1, [x4] |
| 1250 | #else |
| 1251 | stxr w2, w1, [x4] // Need to use atomic instructions for read barrier |
| 1252 | cbnz w2, .Lunlock_stxr_fail // store failed, retry |
| 1253 | #endif |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1254 | ret |
Hiroshi Yamauchi | e15ea08 | 2015-02-09 17:11:42 -0800 | [diff] [blame] | 1255 | .Lunlock_stxr_fail: |
| 1256 | b .Lretry_unlock // retry |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1257 | .Lslow_unlock: |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1258 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1259 | mov x1, xSELF // pass Thread::Current |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1260 | bl artUnlockObjectFromCode // (Object* obj, Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1261 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | 4fc046e | 2014-05-06 16:56:39 -0700 | [diff] [blame] | 1262 | RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1263 | END art_quick_unlock_object |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1264 | |
Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 1265 | ENTRY art_quick_unlock_object_no_inline |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1266 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case exception allocation triggers GC |
Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 1267 | mov x1, xSELF // pass Thread::Current |
| 1268 | bl artUnlockObjectFromCode // (Object* obj, Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1269 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | c7ed09b | 2016-04-25 20:08:55 -0700 | [diff] [blame] | 1270 | RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1271 | END art_quick_unlock_object_no_inline |
| 1272 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1273 | /* |
| 1274 | * Entry from managed code that calls artIsAssignableFromCode and on failure calls |
| 1275 | * artThrowClassCastException. |
| 1276 | */ |
| 1277 | .extern artThrowClassCastException |
| 1278 | ENTRY art_quick_check_cast |
| 1279 | // Store arguments and link register |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 1280 | // Stack needs to be 16B aligned on calls. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1281 | SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32 |
| 1282 | SAVE_REG xLR, 24 |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1283 | |
| 1284 | // Call runtime code |
| 1285 | bl artIsAssignableFromCode |
| 1286 | |
| 1287 | // Check for exception |
| 1288 | cbz x0, .Lthrow_class_cast_exception |
| 1289 | |
| 1290 | // Restore and return |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 1291 | .cfi_remember_state |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1292 | RESTORE_REG xLR, 24 |
| 1293 | RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32 |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1294 | ret |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 1295 | .cfi_restore_state // Reset unwind info so following code unwinds. |
Andreas Gampe | 6b90d42 | 2015-06-26 19:49:24 -0700 | [diff] [blame] | 1296 | |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1297 | .Lthrow_class_cast_exception: |
| 1298 | // Restore |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1299 | RESTORE_REG xLR, 24 |
| 1300 | RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32 |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1301 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1302 | SETUP_SAVE_ALL_CALLEE_SAVES_FRAME // save all registers as basis for long jump context |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1303 | mov x2, xSELF // pass Thread::Current |
Vladimir Marko | 908eb22 | 2016-09-14 10:29:18 +0100 | [diff] [blame^] | 1304 | bl artThrowClassCastException // (Class*, Class*, Thread*) |
Andreas Gampe | 525cde2 | 2014-04-22 15:44:50 -0700 | [diff] [blame] | 1305 | brk 0 // We should not return here... |
| 1306 | END art_quick_check_cast |
| 1307 | |
Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 1308 | // Restore xReg's value from [sp, #offset] if xReg is not the same as xExclude. |
| 1309 | .macro POP_REG_NE xReg, offset, xExclude |
| 1310 | .ifnc \xReg, \xExclude |
| 1311 | ldr \xReg, [sp, #\offset] // restore xReg |
| 1312 | .cfi_restore \xReg |
| 1313 | .endif |
| 1314 | .endm |
| 1315 | |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 1316 | // Restore xReg1's value from [sp, #offset] if xReg1 is not the same as xExclude. |
| 1317 | // Restore xReg2's value from [sp, #(offset + 8)] if xReg2 is not the same as xExclude. |
| 1318 | .macro POP_REGS_NE xReg1, xReg2, offset, xExclude |
| 1319 | .ifc \xReg1, \xExclude |
| 1320 | ldr \xReg2, [sp, #(\offset + 8)] // restore xReg2 |
| 1321 | .else |
| 1322 | .ifc \xReg2, \xExclude |
| 1323 | ldr \xReg1, [sp, #\offset] // restore xReg1 |
| 1324 | .else |
| 1325 | ldp \xReg1, \xReg2, [sp, #\offset] // restore xReg1 and xReg2 |
| 1326 | .endif |
| 1327 | .endif |
| 1328 | .cfi_restore \xReg1 |
| 1329 | .cfi_restore \xReg2 |
| 1330 | .endm |
| 1331 | |
Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 1332 | /* |
| 1333 | * Macro to insert read barrier, only used in art_quick_aput_obj. |
| 1334 | * xDest, wDest and xObj are registers, offset is a defined literal such as |
| 1335 | * MIRROR_OBJECT_CLASS_OFFSET. Dest needs both x and w versions of the same register to handle |
| 1336 | * name mismatch between instructions. This macro uses the lower 32b of register when possible. |
| 1337 | * TODO: When read barrier has a fast path, add heap unpoisoning support for the fast path. |
| 1338 | */ |
Mathieu Chartier | 4b5f791 | 2016-07-21 14:59:04 -0700 | [diff] [blame] | 1339 | .macro READ_BARRIER xDest, wDest, xObj, xTemp, wTemp, offset, number |
Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 1340 | #ifdef USE_READ_BARRIER |
Mathieu Chartier | 4b5f791 | 2016-07-21 14:59:04 -0700 | [diff] [blame] | 1341 | #ifdef USE_BAKER_READ_BARRIER |
| 1342 | ldr \wTemp, [\xObj, #MIRROR_OBJECT_LOCK_WORD_OFFSET] |
| 1343 | tbnz \wTemp, #LOCK_WORD_READ_BARRIER_STATE_SHIFT, .Lrb_slowpath\number |
| 1344 | // False dependency to avoid needing load/load fence. |
| 1345 | add \xObj, \xObj, \xTemp, lsr #32 |
| 1346 | ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest. |
| 1347 | UNPOISON_HEAP_REF \wDest |
| 1348 | b .Lrb_exit\number |
| 1349 | #endif |
| 1350 | .Lrb_slowpath\number: |
Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 1351 | // Store registers used in art_quick_aput_obj (x0-x4, LR), stack is 16B aligned. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1352 | SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 48 |
| 1353 | SAVE_TWO_REGS x2, x3, 16 |
| 1354 | SAVE_TWO_REGS x4, xLR, 32 |
Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 1355 | |
Man Cao | 6306921 | 2015-08-21 15:51:39 -0700 | [diff] [blame] | 1356 | // mov x0, \xRef // pass ref in x0 (no-op for now since parameter ref is unused) |
Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 1357 | .ifnc \xObj, x1 |
| 1358 | mov x1, \xObj // pass xObj |
| 1359 | .endif |
| 1360 | mov w2, #\offset // pass offset |
| 1361 | bl artReadBarrierSlow // artReadBarrierSlow(ref, xObj, offset) |
| 1362 | // No need to unpoison return value in w0, artReadBarrierSlow() would do the unpoisoning. |
| 1363 | .ifnc \wDest, w0 |
| 1364 | mov \wDest, w0 // save return value in wDest |
| 1365 | .endif |
| 1366 | |
| 1367 | // Conditionally restore saved registers |
| 1368 | POP_REG_NE x0, 0, \xDest |
| 1369 | POP_REG_NE x1, 8, \xDest |
| 1370 | POP_REG_NE x2, 16, \xDest |
| 1371 | POP_REG_NE x3, 24, \xDest |
| 1372 | POP_REG_NE x4, 32, \xDest |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1373 | RESTORE_REG xLR, 40 |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 1374 | DECREASE_FRAME 48 |
Mathieu Chartier | 4b5f791 | 2016-07-21 14:59:04 -0700 | [diff] [blame] | 1375 | .Lrb_exit\number: |
Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 1376 | #else |
| 1377 | ldr \wDest, [\xObj, #\offset] // Heap reference = 32b. This also zero-extends to \xDest. |
| 1378 | UNPOISON_HEAP_REF \wDest |
| 1379 | #endif // USE_READ_BARRIER |
| 1380 | .endm |
| 1381 | |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1382 | /* |
| 1383 | * Entry from managed code for array put operations of objects where the value being stored |
| 1384 | * needs to be checked for compatibility. |
| 1385 | * x0 = array, x1 = index, x2 = value |
| 1386 | * |
| 1387 | * Currently all values should fit into w0/w1/w2, and w1 always will as indices are 32b. We |
| 1388 | * assume, though, that the upper 32b are zeroed out. At least for x1/w1 we can do better by |
| 1389 | * using index-zero-extension in load/stores. |
| 1390 | * |
| 1391 | * Temporaries: x3, x4 |
| 1392 | * TODO: x4 OK? ip seems wrong here. |
| 1393 | */ |
| 1394 | ENTRY art_quick_aput_obj_with_null_and_bound_check |
| 1395 | tst x0, x0 |
| 1396 | bne art_quick_aput_obj_with_bound_check |
| 1397 | b art_quick_throw_null_pointer_exception |
| 1398 | END art_quick_aput_obj_with_null_and_bound_check |
| 1399 | |
| 1400 | ENTRY art_quick_aput_obj_with_bound_check |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1401 | ldr w3, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1402 | cmp w3, w1 |
| 1403 | bhi art_quick_aput_obj |
| 1404 | mov x0, x1 |
| 1405 | mov x1, x3 |
| 1406 | b art_quick_throw_array_bounds |
| 1407 | END art_quick_aput_obj_with_bound_check |
| 1408 | |
Man Cao | 1aee900 | 2015-07-14 22:31:42 -0700 | [diff] [blame] | 1409 | #ifdef USE_READ_BARRIER |
| 1410 | .extern artReadBarrierSlow |
| 1411 | #endif |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1412 | ENTRY art_quick_aput_obj |
| 1413 | cbz x2, .Ldo_aput_null |
Mathieu Chartier | 4b5f791 | 2016-07-21 14:59:04 -0700 | [diff] [blame] | 1414 | READ_BARRIER x3, w3, x0, x3, w3, MIRROR_OBJECT_CLASS_OFFSET, 0 // Heap reference = 32b |
| 1415 | // This also zero-extends to x3 |
| 1416 | READ_BARRIER x3, w3, x3, x4, w4, MIRROR_CLASS_COMPONENT_TYPE_OFFSET, 1 // Heap reference = 32b |
| 1417 | // This also zero-extends to x3 |
| 1418 | READ_BARRIER x4, w4, x2, x4, w4, MIRROR_OBJECT_CLASS_OFFSET, 2 // Heap reference = 32b |
| 1419 | // This also zero-extends to x4 |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1420 | cmp w3, w4 // value's type == array's component type - trivial assignability |
| 1421 | bne .Lcheck_assignability |
| 1422 | .Ldo_aput: |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1423 | add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1424 | // "Compress" = do nothing |
Hiroshi Yamauchi | bfa5eb6 | 2015-05-29 15:04:41 -0700 | [diff] [blame] | 1425 | POISON_HEAP_REF w2 |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1426 | str w2, [x3, x1, lsl #2] // Heap reference = 32b |
| 1427 | ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] |
| 1428 | lsr x0, x0, #7 |
| 1429 | strb w3, [x3, x0] |
| 1430 | ret |
| 1431 | .Ldo_aput_null: |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1432 | add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1433 | // "Compress" = do nothing |
| 1434 | str w2, [x3, x1, lsl #2] // Heap reference = 32b |
| 1435 | ret |
| 1436 | .Lcheck_assignability: |
| 1437 | // Store arguments and link register |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1438 | SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32 |
| 1439 | SAVE_TWO_REGS x2, xLR, 16 |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1440 | |
| 1441 | // Call runtime code |
| 1442 | mov x0, x3 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended |
| 1443 | mov x1, x4 // Heap reference, 32b, "uncompress" = do nothing, already zero-extended |
| 1444 | bl artIsAssignableFromCode |
| 1445 | |
| 1446 | // Check for exception |
| 1447 | cbz x0, .Lthrow_array_store_exception |
| 1448 | |
| 1449 | // Restore |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 1450 | .cfi_remember_state |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1451 | RESTORE_TWO_REGS x2, xLR, 16 |
| 1452 | RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32 |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1453 | |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1454 | add x3, x0, #MIRROR_OBJECT_ARRAY_DATA_OFFSET |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1455 | // "Compress" = do nothing |
Hiroshi Yamauchi | bfa5eb6 | 2015-05-29 15:04:41 -0700 | [diff] [blame] | 1456 | POISON_HEAP_REF w2 |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1457 | str w2, [x3, x1, lsl #2] // Heap reference = 32b |
| 1458 | ldr x3, [xSELF, #THREAD_CARD_TABLE_OFFSET] |
| 1459 | lsr x0, x0, #7 |
| 1460 | strb w3, [x3, x0] |
| 1461 | ret |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 1462 | .cfi_restore_state // Reset unwind info so following code unwinds. |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1463 | .Lthrow_array_store_exception: |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1464 | RESTORE_TWO_REGS x2, xLR, 16 |
| 1465 | RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32 |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1466 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1467 | SETUP_SAVE_ALL_CALLEE_SAVES_FRAME |
Vladimir Marko | 908eb22 | 2016-09-14 10:29:18 +0100 | [diff] [blame^] | 1468 | mov x1, x2 // Pass value. |
| 1469 | mov x2, xSELF // Pass Thread::Current. |
| 1470 | bl artThrowArrayStoreException // (Object*, Object*, Thread*). |
| 1471 | brk 0 // Unreached. |
Andreas Gampe | f4e910b | 2014-04-29 16:55:52 -0700 | [diff] [blame] | 1472 | END art_quick_aput_obj |
| 1473 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1474 | // Macro to facilitate adding new allocation entrypoints. |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 1475 | .macro ONE_ARG_DOWNCALL name, entrypoint, return |
| 1476 | .extern \entrypoint |
| 1477 | ENTRY \name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1478 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 1479 | mov x1, xSELF // pass Thread::Current |
| 1480 | bl \entrypoint // (uint32_t type_idx, Method* method, Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1481 | RESTORE_SAVE_REFS_ONLY_FRAME |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 1482 | \return |
| 1483 | END \name |
| 1484 | .endm |
| 1485 | |
| 1486 | // Macro to facilitate adding new allocation entrypoints. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1487 | .macro TWO_ARG_DOWNCALL name, entrypoint, return |
| 1488 | .extern \entrypoint |
| 1489 | ENTRY \name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1490 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1491 | mov x2, xSELF // pass Thread::Current |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 1492 | bl \entrypoint // (uint32_t type_idx, Method* method, Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1493 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1494 | \return |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1495 | END \name |
| 1496 | .endm |
| 1497 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1498 | // Macro to facilitate adding new allocation entrypoints. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1499 | .macro THREE_ARG_DOWNCALL name, entrypoint, return |
| 1500 | .extern \entrypoint |
| 1501 | ENTRY \name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1502 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1503 | mov x3, xSELF // pass Thread::Current |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1504 | bl \entrypoint |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1505 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | 00c1e6d | 2014-04-25 15:47:13 -0700 | [diff] [blame] | 1506 | \return |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1507 | END \name |
| 1508 | .endm |
| 1509 | |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1510 | // Macro to facilitate adding new allocation entrypoints. |
| 1511 | .macro FOUR_ARG_DOWNCALL name, entrypoint, return |
| 1512 | .extern \entrypoint |
| 1513 | ENTRY \name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1514 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1515 | mov x4, xSELF // pass Thread::Current |
| 1516 | bl \entrypoint // |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1517 | RESTORE_SAVE_REFS_ONLY_FRAME |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 1518 | \return |
| 1519 | DELIVER_PENDING_EXCEPTION |
| 1520 | END \name |
| 1521 | .endm |
| 1522 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1523 | // Macros taking opportunity of code similarities for downcalls with referrer. |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1524 | .macro ONE_ARG_REF_DOWNCALL name, entrypoint, return |
| 1525 | .extern \entrypoint |
| 1526 | ENTRY \name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1527 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
| 1528 | ldr x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1529 | mov x2, xSELF // pass Thread::Current |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1530 | bl \entrypoint // (uint32_t type_idx, Method* method, Thread*, SP) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1531 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1532 | \return |
| 1533 | END \name |
| 1534 | .endm |
| 1535 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1536 | .macro TWO_ARG_REF_DOWNCALL name, entrypoint, return |
| 1537 | .extern \entrypoint |
| 1538 | ENTRY \name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1539 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
| 1540 | ldr x2, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1541 | mov x3, xSELF // pass Thread::Current |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1542 | bl \entrypoint |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1543 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1544 | \return |
| 1545 | END \name |
| 1546 | .endm |
| 1547 | |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1548 | .macro THREE_ARG_REF_DOWNCALL name, entrypoint, return |
| 1549 | .extern \entrypoint |
| 1550 | ENTRY \name |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1551 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
| 1552 | ldr x3, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1553 | mov x4, xSELF // pass Thread::Current |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1554 | bl \entrypoint |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1555 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1556 | \return |
| 1557 | END \name |
| 1558 | .endm |
| 1559 | |
Andreas Gampe | 1cc7dba | 2014-12-17 18:43:01 -0800 | [diff] [blame] | 1560 | .macro RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
| 1561 | cbz w0, 1f // result zero branch over |
| 1562 | ret // return |
| 1563 | 1: |
| 1564 | DELIVER_PENDING_EXCEPTION |
| 1565 | .endm |
| 1566 | |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1567 | /* |
Vladimir Marko | 3b37073 | 2014-10-09 18:34:28 +0100 | [diff] [blame] | 1568 | * Entry from managed code that calls artHandleFillArrayDataFromCode and delivers exception on |
| 1569 | * failure. |
| 1570 | */ |
| 1571 | TWO_ARG_REF_DOWNCALL art_quick_handle_fill_data, artHandleFillArrayDataFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1572 | |
| 1573 | /* |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1574 | * Entry from managed code when uninitialized static storage, this stub will run the class |
| 1575 | * initializer and deliver the exception on error. On success the static storage base is |
| 1576 | * returned. |
| 1577 | */ |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 1578 | ONE_ARG_DOWNCALL art_quick_initialize_static_storage, artInitializeStaticStorageFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1579 | |
Vladimir Marko | 5ea536a | 2015-04-20 20:11:30 +0100 | [diff] [blame] | 1580 | ONE_ARG_DOWNCALL art_quick_initialize_type, artInitializeTypeFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
| 1581 | ONE_ARG_DOWNCALL art_quick_initialize_type_and_verify_access, artInitializeTypeAndVerifyAccessFromCode, RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1582 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1583 | ONE_ARG_REF_DOWNCALL art_quick_get_boolean_static, artGetBooleanStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1584 | ONE_ARG_REF_DOWNCALL art_quick_get_byte_static, artGetByteStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1585 | ONE_ARG_REF_DOWNCALL art_quick_get_char_static, artGetCharStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1586 | ONE_ARG_REF_DOWNCALL art_quick_get_short_static, artGetShortStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1587 | ONE_ARG_REF_DOWNCALL art_quick_get32_static, artGet32StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1588 | ONE_ARG_REF_DOWNCALL art_quick_get64_static, artGet64StaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1589 | ONE_ARG_REF_DOWNCALL art_quick_get_obj_static, artGetObjStaticFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1590 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1591 | TWO_ARG_REF_DOWNCALL art_quick_get_boolean_instance, artGetBooleanInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1592 | TWO_ARG_REF_DOWNCALL art_quick_get_byte_instance, artGetByteInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1593 | TWO_ARG_REF_DOWNCALL art_quick_get_char_instance, artGetCharInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1594 | TWO_ARG_REF_DOWNCALL art_quick_get_short_instance, artGetShortInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1595 | TWO_ARG_REF_DOWNCALL art_quick_get32_instance, artGet32InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1596 | TWO_ARG_REF_DOWNCALL art_quick_get64_instance, artGet64InstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1597 | TWO_ARG_REF_DOWNCALL art_quick_get_obj_instance, artGetObjInstanceFromCode, RETURN_OR_DELIVER_PENDING_EXCEPTION_X1 |
| 1598 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1599 | TWO_ARG_REF_DOWNCALL art_quick_set8_static, artSet8StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1600 | TWO_ARG_REF_DOWNCALL art_quick_set16_static, artSet16StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1601 | TWO_ARG_REF_DOWNCALL art_quick_set32_static, artSet32StaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1602 | TWO_ARG_REF_DOWNCALL art_quick_set_obj_static, artSetObjStaticFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1603 | |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 1604 | THREE_ARG_REF_DOWNCALL art_quick_set8_instance, artSet8InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1605 | THREE_ARG_REF_DOWNCALL art_quick_set16_instance, artSet16InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1606 | THREE_ARG_REF_DOWNCALL art_quick_set32_instance, artSet32InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
Stephen Kyle | 0ff20d5 | 2014-10-22 15:23:46 +0100 | [diff] [blame] | 1607 | THREE_ARG_REF_DOWNCALL art_quick_set64_instance, artSet64InstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1608 | THREE_ARG_REF_DOWNCALL art_quick_set_obj_instance, artSetObjInstanceFromCode, RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1609 | |
| 1610 | // This is separated out as the argument order is different. |
| 1611 | .extern artSet64StaticFromCode |
| 1612 | ENTRY art_quick_set64_static |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1613 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
| 1614 | ldr x1, [sp, #FRAME_SIZE_SAVE_REFS_ONLY] // Load referrer |
Calin Juravle | e460d1d | 2015-09-29 04:52:17 +0100 | [diff] [blame] | 1615 | // x2 contains the parameter |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1616 | mov x3, xSELF // pass Thread::Current |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1617 | bl artSet64StaticFromCode |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1618 | RESTORE_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1619 | RETURN_IF_W0_IS_ZERO_OR_DELIVER |
| 1620 | END art_quick_set64_static |
| 1621 | |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1622 | /* |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1623 | * Entry from managed code to resolve a string, this stub will |
| 1624 | * check the dex cache for a matching string (the fast path), and if not found, |
| 1625 | * it will allocate a String and deliver an exception on error. |
| 1626 | * On success the String is returned. R0 holds the string index. |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 1627 | */ |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1628 | |
| 1629 | ENTRY art_quick_resolve_string |
| 1630 | ldr x1, [sp] // load referrer |
| 1631 | ldr w2, [x1, #ART_METHOD_DECLARING_CLASS_OFFSET] // load declaring class |
| 1632 | ldr x1, [x2, #DECLARING_CLASS_DEX_CACHE_STRINGS_OFFSET] // load string dex cache |
Mathieu Chartier | e3fbe38 | 2016-08-30 09:42:28 -0700 | [diff] [blame] | 1633 | ubfx x2, x0, #0, #STRING_DEX_CACHE_HASH_BITS // get masked string index into x2 |
Mathieu Chartier | 5f40433 | 2016-08-22 15:38:08 -0700 | [diff] [blame] | 1634 | ldr x2, [x1, x2, lsl #STRING_DEX_CACHE_ELEMENT_SIZE_SHIFT] // load dex cache pair into x2 |
| 1635 | cmp x0, x2, lsr #32 // compare against upper 32 bits |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1636 | bne .Lart_quick_resolve_string_slow_path |
Mathieu Chartier | 5f40433 | 2016-08-22 15:38:08 -0700 | [diff] [blame] | 1637 | ubfx x0, x2, #0, #32 // extract lower 32 bits into x0 |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1638 | #ifdef USE_READ_BARRIER |
Mathieu Chartier | 5f40433 | 2016-08-22 15:38:08 -0700 | [diff] [blame] | 1639 | // Most common case: GC is not marking. |
| 1640 | ldr w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET] |
| 1641 | cbnz x3, .Lart_quick_resolve_string_marking |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1642 | #endif |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1643 | ret |
| 1644 | |
Mathieu Chartier | 5f40433 | 2016-08-22 15:38:08 -0700 | [diff] [blame] | 1645 | // Slow path case, the index did not match. |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1646 | .Lart_quick_resolve_string_slow_path: |
| 1647 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
| 1648 | mov x1, xSELF // pass Thread::Current |
Mathieu Chartier | 5f40433 | 2016-08-22 15:38:08 -0700 | [diff] [blame] | 1649 | bl artResolveStringFromCode // (int32_t string_idx, Thread* self) |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1650 | RESTORE_SAVE_REFS_ONLY_FRAME |
| 1651 | RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
| 1652 | |
Mathieu Chartier | 5f40433 | 2016-08-22 15:38:08 -0700 | [diff] [blame] | 1653 | // GC is marking case, need to check the mark bit. |
| 1654 | .Lart_quick_resolve_string_marking: |
| 1655 | ldr x3, [x0, #MIRROR_OBJECT_LOCK_WORD_OFFSET] |
| 1656 | tbnz x3, #LOCK_WORD_MARK_BIT_SHIFT, .Lart_quick_resolve_string_no_rb |
| 1657 | // Save LR so that we can return, also x1 for alignment purposes. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1658 | SAVE_TWO_REGS_INCREASE_FRAME x1, xLR, 16 // Save x1, LR. |
Mathieu Chartier | 5f40433 | 2016-08-22 15:38:08 -0700 | [diff] [blame] | 1659 | bl artReadBarrierMark // Get the marked string back. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1660 | RESTORE_TWO_REGS_DECREASE_FRAME x1, xLR, 16 // Restore registers. |
Mathieu Chartier | 5f40433 | 2016-08-22 15:38:08 -0700 | [diff] [blame] | 1661 | .Lart_quick_resolve_string_no_rb: |
| 1662 | ret |
| 1663 | |
Christina Wadsworth | ead8ba3 | 2016-08-08 13:08:05 -0700 | [diff] [blame] | 1664 | END art_quick_resolve_string |
Andreas Gampe | 6e4e59c | 2014-05-05 20:11:02 -0700 | [diff] [blame] | 1665 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1666 | // Generate the allocation entrypoints for each allocator. |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1667 | GENERATE_ALLOC_ENTRYPOINTS_FOR_NON_REGION_TLAB_ALLOCATORS |
| 1668 | // Comment out allocators that have arm64 specific asm. |
| 1669 | // GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_region_tlab, RegionTLAB) implemented in asm |
| 1670 | // GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_RESOLVED(_region_tlab, RegionTLAB) |
| 1671 | // GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_INITIALIZED(_region_tlab, RegionTLAB) |
| 1672 | GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB) |
| 1673 | // GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY(_region_tlab, RegionTLAB) implemented in asm |
| 1674 | // GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_RESOLVED(_region_tlab, RegionTLAB) |
| 1675 | GENERATE_ALLOC_ENTRYPOINTS_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB) |
| 1676 | GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY(_region_tlab, RegionTLAB) |
| 1677 | GENERATE_ALLOC_ENTRYPOINTS_CHECK_AND_ALLOC_ARRAY_WITH_ACCESS_CHECK(_region_tlab, RegionTLAB) |
| 1678 | GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_BYTES(_region_tlab, RegionTLAB) |
| 1679 | GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_CHARS(_region_tlab, RegionTLAB) |
| 1680 | GENERATE_ALLOC_ENTRYPOINTS_ALLOC_STRING_FROM_STRING(_region_tlab, RegionTLAB) |
Hiroshi Yamauchi | 10d4c08 | 2016-02-24 12:51:18 -0800 | [diff] [blame] | 1681 | |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1682 | // A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_rosalloc, RosAlloc). |
| 1683 | ENTRY art_quick_alloc_object_rosalloc |
| 1684 | // Fast path rosalloc allocation. |
| 1685 | // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current |
| 1686 | // x2-x7: free. |
| 1687 | ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array |
| 1688 | // Load the class (x2) |
| 1689 | ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT] |
| 1690 | cbz x2, .Lart_quick_alloc_object_rosalloc_slow_path // Check null class |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1691 | ldr x3, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] // Check if the thread local |
| 1692 | // allocation stack has room. |
| 1693 | // ldp won't work due to large offset. |
| 1694 | ldr x4, [xSELF, #THREAD_LOCAL_ALLOC_STACK_END_OFFSET] |
| 1695 | cmp x3, x4 |
| 1696 | bhs .Lart_quick_alloc_object_rosalloc_slow_path |
Mathieu Chartier | 161db1d | 2016-09-01 14:06:54 -0700 | [diff] [blame] | 1697 | ldr w3, [x2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x3) |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1698 | cmp x3, #ROSALLOC_MAX_THREAD_LOCAL_BRACKET_SIZE // Check if the size is for a thread |
Mathieu Chartier | 161db1d | 2016-09-01 14:06:54 -0700 | [diff] [blame] | 1699 | // local allocation. Also does the |
| 1700 | // finalizable and initialization |
| 1701 | // checks. |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1702 | bhs .Lart_quick_alloc_object_rosalloc_slow_path |
| 1703 | // Compute the rosalloc bracket index |
Mathieu Chartier | 161db1d | 2016-09-01 14:06:54 -0700 | [diff] [blame] | 1704 | // from the size. Since the size is |
| 1705 | // already aligned we can combine the |
| 1706 | // two shifts together. |
| 1707 | add x4, xSELF, x3, lsr #(ROSALLOC_BRACKET_QUANTUM_SIZE_SHIFT - POINTER_SIZE_SHIFT) |
| 1708 | // Subtract pointer size since ther |
| 1709 | // are no runs for 0 byte allocations |
| 1710 | // and the size is already aligned. |
| 1711 | ldr x4, [x4, #(THREAD_ROSALLOC_RUNS_OFFSET - __SIZEOF_POINTER__)] |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1712 | // Load the free list head (x3). This |
| 1713 | // will be the return val. |
| 1714 | ldr x3, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)] |
| 1715 | cbz x3, .Lart_quick_alloc_object_rosalloc_slow_path |
| 1716 | // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1. |
| 1717 | ldr x1, [x3, #ROSALLOC_SLOT_NEXT_OFFSET] // Load the next pointer of the head |
| 1718 | // and update the list head with the |
| 1719 | // next pointer. |
| 1720 | str x1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_HEAD_OFFSET)] |
| 1721 | // Store the class pointer in the |
| 1722 | // header. This also overwrites the |
| 1723 | // next pointer. The offsets are |
| 1724 | // asserted to match. |
| 1725 | #if ROSALLOC_SLOT_NEXT_OFFSET != MIRROR_OBJECT_CLASS_OFFSET |
| 1726 | #error "Class pointer needs to overwrite next pointer." |
| 1727 | #endif |
| 1728 | POISON_HEAP_REF w2 |
| 1729 | str w2, [x3, #MIRROR_OBJECT_CLASS_OFFSET] |
Mathieu Chartier | 011dc2c | 2016-07-18 11:11:45 -0700 | [diff] [blame] | 1730 | // Fence. This is "ish" not "ishst" so |
| 1731 | // that it also ensures ordering of |
Mathieu Chartier | 161db1d | 2016-09-01 14:06:54 -0700 | [diff] [blame] | 1732 | // the object size load with respect |
Mathieu Chartier | 011dc2c | 2016-07-18 11:11:45 -0700 | [diff] [blame] | 1733 | // to later accesses to the class |
| 1734 | // object. Alternatively we could use |
| 1735 | // "ishst" if we use load-acquire for |
Mathieu Chartier | 161db1d | 2016-09-01 14:06:54 -0700 | [diff] [blame] | 1736 | // the class status load. |
Mathieu Chartier | 011dc2c | 2016-07-18 11:11:45 -0700 | [diff] [blame] | 1737 | // Needs to be done before pushing on |
| 1738 | // allocation since Heap::VisitObjects |
| 1739 | // relies on seeing the class pointer. |
| 1740 | // b/28790624 |
| 1741 | dmb ish |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1742 | // Push the new object onto the thread |
| 1743 | // local allocation stack and |
| 1744 | // increment the thread local |
| 1745 | // allocation stack top. |
| 1746 | ldr x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] |
| 1747 | str w3, [x1], #COMPRESSED_REFERENCE_SIZE // (Increment x1 as a side effect.) |
| 1748 | str x1, [xSELF, #THREAD_LOCAL_ALLOC_STACK_TOP_OFFSET] |
| 1749 | // Decrement the size of the free list |
| 1750 | ldr w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)] |
| 1751 | sub x1, x1, #1 |
| 1752 | // TODO: consider combining this store |
| 1753 | // and the list head store above using |
| 1754 | // strd. |
| 1755 | str w1, [x4, #(ROSALLOC_RUN_FREE_LIST_OFFSET + ROSALLOC_RUN_FREE_LIST_SIZE_OFFSET)] |
Mathieu Chartier | 011dc2c | 2016-07-18 11:11:45 -0700 | [diff] [blame] | 1756 | |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1757 | mov x0, x3 // Set the return value and return. |
| 1758 | ret |
| 1759 | .Lart_quick_alloc_object_rosalloc_slow_path: |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1760 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1761 | mov x2, xSELF // pass Thread::Current |
| 1762 | bl artAllocObjectFromCodeRosAlloc // (uint32_t type_idx, Method* method, Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1763 | RESTORE_SAVE_REFS_ONLY_FRAME |
Hiroshi Yamauchi | 6f6244a | 2015-10-22 12:08:12 -0700 | [diff] [blame] | 1764 | RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
| 1765 | END art_quick_alloc_object_rosalloc |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 1766 | |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1767 | |
| 1768 | // The common fast path code for art_quick_alloc_array_region_tlab. |
| 1769 | .macro ALLOC_ARRAY_TLAB_FAST_PATH slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2 |
| 1770 | // Check null class |
| 1771 | cbz \wClass, \slowPathLabel |
| 1772 | ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED \slowPathLabel, \xClass, \wClass, \xCount, \wCount, \xTemp0, \wTemp0, \xTemp1, \wTemp1, \xTemp2, \wTemp2 |
| 1773 | .endm |
| 1774 | |
| 1775 | // The common fast path code for art_quick_alloc_array_region_tlab. |
| 1776 | .macro ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED slowPathLabel, xClass, wClass, xCount, wCount, xTemp0, wTemp0, xTemp1, wTemp1, xTemp2, wTemp2 |
| 1777 | // Array classes are never finalizable or uninitialized, no need to check. |
| 1778 | ldr \wTemp0, [\xClass, #MIRROR_CLASS_COMPONENT_TYPE_OFFSET] // Load component type |
| 1779 | UNPOISON_HEAP_REF \wTemp0 |
| 1780 | ldr \wTemp0, [\xTemp0, #MIRROR_CLASS_OBJECT_PRIMITIVE_TYPE_OFFSET] |
| 1781 | lsr \xTemp0, \xTemp0, #PRIMITIVE_TYPE_SIZE_SHIFT_SHIFT // Component size shift is in high 16 |
| 1782 | // bits. |
| 1783 | // xCount is holding a 32 bit value, |
| 1784 | // it can not overflow. |
| 1785 | lsl \xTemp1, \xCount, \xTemp0 // Calculate data size |
| 1786 | // Add array data offset and alignment. |
| 1787 | add \xTemp1, \xTemp1, #(MIRROR_INT_ARRAY_DATA_OFFSET + OBJECT_ALIGNMENT_MASK) |
| 1788 | #if MIRROR_LONG_ARRAY_DATA_OFFSET != MIRROR_INT_ARRAY_DATA_OFFSET + 4 |
| 1789 | #error Long array data offset must be 4 greater than int array data offset. |
| 1790 | #endif |
| 1791 | |
| 1792 | add \xTemp0, \xTemp0, #1 // Add 4 to the length only if the |
| 1793 | // component size shift is 3 |
| 1794 | // (for 64 bit alignment). |
| 1795 | and \xTemp0, \xTemp0, #4 |
| 1796 | add \xTemp1, \xTemp1, \xTemp0 |
Mathieu Chartier | 2ee98f2 | 2016-08-10 10:08:58 -0700 | [diff] [blame] | 1797 | and \xTemp1, \xTemp1, #OBJECT_ALIGNMENT_MASK_TOGGLED64 // Apply alignemnt mask |
| 1798 | // (addr + 7) & ~7. The mask must |
| 1799 | // be 64 bits to keep high bits in |
| 1800 | // case of overflow. |
| 1801 | // Negative sized arrays are handled here since xCount holds a zero extended 32 bit value. |
| 1802 | // Negative ints become large 64 bit unsigned ints which will always be larger than max signed |
| 1803 | // 32 bit int. Since the max shift for arrays is 3, it can not become a negative 64 bit int. |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1804 | cmp \xTemp1, #MIN_LARGE_OBJECT_THRESHOLD // Possibly a large object, go slow |
| 1805 | bhs \slowPathLabel // path. |
| 1806 | |
| 1807 | ldr \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Check tlab for space, note that |
| 1808 | // we use (end - begin) to handle |
| 1809 | // negative size arrays. It is |
| 1810 | // assumed that a negative size will |
| 1811 | // always be greater unsigned than |
| 1812 | // region size. |
| 1813 | ldr \xTemp2, [xSELF, #THREAD_LOCAL_END_OFFSET] |
| 1814 | sub \xTemp2, \xTemp2, \xTemp0 |
| 1815 | cmp \xTemp1, \xTemp2 |
| 1816 | bhi \slowPathLabel |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1817 | // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1. |
| 1818 | // Move old thread_local_pos to x0 |
| 1819 | // for the return value. |
| 1820 | mov x0, \xTemp0 |
| 1821 | add \xTemp0, \xTemp0, \xTemp1 |
| 1822 | str \xTemp0, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos. |
| 1823 | ldr \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects. |
| 1824 | add \xTemp0, \xTemp0, #1 |
| 1825 | str \xTemp0, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] |
| 1826 | POISON_HEAP_REF \wClass |
| 1827 | str \wClass, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer. |
| 1828 | str \wCount, [x0, #MIRROR_ARRAY_LENGTH_OFFSET] // Store the array length. |
| 1829 | // Fence. |
| 1830 | dmb ishst |
| 1831 | ret |
| 1832 | .endm |
| 1833 | |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1834 | // The common fast path code for art_quick_alloc_object_tlab and art_quick_alloc_object_region_tlab. |
| 1835 | // |
| 1836 | // x0: type_idx/return value, x1: ArtMethod*, x2: Class*, xSELF(x19): Thread::Current |
| 1837 | // x3-x7: free. |
| 1838 | // Need to preserve x0 and x1 to the slow path. |
| 1839 | .macro ALLOC_OBJECT_TLAB_FAST_PATH slowPathLabel |
| 1840 | cbz x2, \slowPathLabel // Check null class |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1841 | ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED \slowPathLabel |
| 1842 | .endm |
| 1843 | |
Mathieu Chartier | 93bbee0 | 2016-08-31 09:38:40 -0700 | [diff] [blame] | 1844 | // TODO: delete ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED since it is the same as |
| 1845 | // ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED. |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1846 | .macro ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED slowPathLabel |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1847 | ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED \slowPathLabel |
| 1848 | .endm |
| 1849 | |
| 1850 | .macro ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED slowPathLabel |
Hiroshi Yamauchi | d72945c | 2016-03-16 11:23:10 -0700 | [diff] [blame] | 1851 | ldr x4, [xSELF, #THREAD_LOCAL_POS_OFFSET] |
| 1852 | ldr x5, [xSELF, #THREAD_LOCAL_END_OFFSET] |
Mathieu Chartier | 93bbee0 | 2016-08-31 09:38:40 -0700 | [diff] [blame] | 1853 | ldr w7, [x2, #MIRROR_CLASS_OBJECT_SIZE_ALLOC_FAST_PATH_OFFSET] // Load the object size (x7). |
| 1854 | add x6, x4, x7 // Add object size to tlab pos. |
| 1855 | cmp x6, x5 // Check if it fits, overflow works |
| 1856 | // since the tlab pos and end are 32 |
| 1857 | // bit values. |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1858 | bhi \slowPathLabel |
Hiroshi Yamauchi | d72945c | 2016-03-16 11:23:10 -0700 | [diff] [blame] | 1859 | // "Point of no slow path". Won't go to the slow path from here on. OK to clobber x0 and x1. |
Hiroshi Yamauchi | d72945c | 2016-03-16 11:23:10 -0700 | [diff] [blame] | 1860 | mov x0, x4 |
Mathieu Chartier | 93bbee0 | 2016-08-31 09:38:40 -0700 | [diff] [blame] | 1861 | str x6, [xSELF, #THREAD_LOCAL_POS_OFFSET] // Store new thread_local_pos. |
Hiroshi Yamauchi | d72945c | 2016-03-16 11:23:10 -0700 | [diff] [blame] | 1862 | ldr x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] // Increment thread_local_objects. |
| 1863 | add x5, x5, #1 |
| 1864 | str x5, [xSELF, #THREAD_LOCAL_OBJECTS_OFFSET] |
| 1865 | POISON_HEAP_REF w2 |
| 1866 | str w2, [x0, #MIRROR_OBJECT_CLASS_OFFSET] // Store the class pointer. |
| 1867 | // Fence. This is "ish" not "ishst" so |
| 1868 | // that the code after this allocation |
| 1869 | // site will see the right values in |
| 1870 | // the fields of the class. |
| 1871 | // Alternatively we could use "ishst" |
| 1872 | // if we use load-acquire for the |
Mathieu Chartier | 93bbee0 | 2016-08-31 09:38:40 -0700 | [diff] [blame] | 1873 | // object size load.) |
Hiroshi Yamauchi | d72945c | 2016-03-16 11:23:10 -0700 | [diff] [blame] | 1874 | dmb ish |
| 1875 | ret |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1876 | .endm |
| 1877 | |
| 1878 | // A hand-written override for GENERATE_ALLOC_ENTRYPOINTS_ALLOC_OBJECT(_tlab, TLAB). |
| 1879 | ENTRY art_quick_alloc_object_tlab |
| 1880 | // Fast path tlab allocation. |
| 1881 | // x0: type_idx/return value, x1: ArtMethod*, xSELF(x19): Thread::Current |
| 1882 | // x2-x7: free. |
| 1883 | #if defined(USE_READ_BARRIER) |
| 1884 | mvn x0, xzr // Read barrier not supported here. |
| 1885 | ret // Return -1. |
| 1886 | #endif |
| 1887 | ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array |
| 1888 | // Load the class (x2) |
| 1889 | ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT] |
| 1890 | ALLOC_OBJECT_TLAB_FAST_PATH .Lart_quick_alloc_object_tlab_slow_path |
Hiroshi Yamauchi | d72945c | 2016-03-16 11:23:10 -0700 | [diff] [blame] | 1891 | .Lart_quick_alloc_object_tlab_slow_path: |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1892 | SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC. |
Hiroshi Yamauchi | d72945c | 2016-03-16 11:23:10 -0700 | [diff] [blame] | 1893 | mov x2, xSELF // Pass Thread::Current. |
| 1894 | bl artAllocObjectFromCodeTLAB // (uint32_t type_idx, Method* method, Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1895 | RESTORE_SAVE_REFS_ONLY_FRAME |
Hiroshi Yamauchi | d72945c | 2016-03-16 11:23:10 -0700 | [diff] [blame] | 1896 | RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
| 1897 | END art_quick_alloc_object_tlab |
| 1898 | |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1899 | // The common code for art_quick_alloc_object_*region_tlab |
Mathieu Chartier | b6ec5d7 | 2016-08-30 15:06:54 -0700 | [diff] [blame] | 1900 | .macro GENERATE_ALLOC_OBJECT_REGION_TLAB name, entrypoint, fast_path, is_resolved, read_barrier |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1901 | ENTRY \name |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1902 | // Fast path region tlab allocation. |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1903 | // x0: type_idx/resolved class/return value, x1: ArtMethod*, xSELF(x19): Thread::Current |
| 1904 | // If is_resolved is 1 then x0 is the resolved type, otherwise it is the index. |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1905 | // x2-x7: free. |
| 1906 | #if !defined(USE_READ_BARRIER) |
| 1907 | mvn x0, xzr // Read barrier must be enabled here. |
| 1908 | ret // Return -1. |
| 1909 | #endif |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1910 | .if \is_resolved |
| 1911 | mov x2, x0 // class is actually stored in x0 already |
| 1912 | .else |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1913 | ldr x2, [x1, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array |
| 1914 | // Load the class (x2) |
| 1915 | ldr w2, [x2, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT] |
Mathieu Chartier | b6ec5d7 | 2016-08-30 15:06:54 -0700 | [diff] [blame] | 1916 | // If the class is null, go slow path. The check is required to read the lock word. |
| 1917 | cbz w2, .Lslow_path\name |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1918 | .endif |
Mathieu Chartier | b6ec5d7 | 2016-08-30 15:06:54 -0700 | [diff] [blame] | 1919 | .if \read_barrier |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1920 | // Most common case: GC is not marking. |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1921 | ldr w3, [xSELF, #THREAD_IS_GC_MARKING_OFFSET] |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1922 | cbnz x3, .Lmarking\name |
Mathieu Chartier | b6ec5d7 | 2016-08-30 15:06:54 -0700 | [diff] [blame] | 1923 | .endif |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1924 | .Ldo_allocation\name: |
| 1925 | \fast_path .Lslow_path\name |
| 1926 | .Lmarking\name: |
Mathieu Chartier | b6ec5d7 | 2016-08-30 15:06:54 -0700 | [diff] [blame] | 1927 | .if \read_barrier |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1928 | // GC is marking, check the lock word of the class for the mark bit. |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 1929 | // Class is not null, check mark bit in lock word. |
| 1930 | ldr w3, [x2, #MIRROR_OBJECT_LOCK_WORD_OFFSET] |
| 1931 | // If the bit is not zero, do the allocation. |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1932 | tbnz w3, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1933 | // The read barrier slow path. Mark |
| 1934 | // the class. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1935 | SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 32 // Save registers (x0, x1, lr). |
| 1936 | SAVE_REG xLR, 24 // Align sp by 16 bytes. |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1937 | mov x0, x2 // Pass the class as the first param. |
| 1938 | bl artReadBarrierMark |
| 1939 | mov x2, x0 // Get the (marked) class back. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 1940 | RESTORE_REG xLR, 24 |
| 1941 | RESTORE_TWO_REGS_DECREASE_FRAME x0, x1, 32 // Restore registers. |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1942 | b .Ldo_allocation\name |
Mathieu Chartier | b6ec5d7 | 2016-08-30 15:06:54 -0700 | [diff] [blame] | 1943 | .endif |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1944 | .Lslow_path\name: |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1945 | SETUP_SAVE_REFS_ONLY_FRAME // Save callee saves in case of GC. |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1946 | mov x2, xSELF // Pass Thread::Current. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 1947 | bl \entrypoint // (uint32_t type_idx, Method* method, Thread*) |
| 1948 | RESTORE_SAVE_REFS_ONLY_FRAME |
Hiroshi Yamauchi | cd77378 | 2016-04-07 17:18:24 -0700 | [diff] [blame] | 1949 | RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1950 | END \name |
| 1951 | .endm |
| 1952 | |
Mathieu Chartier | b6ec5d7 | 2016-08-30 15:06:54 -0700 | [diff] [blame] | 1953 | // Use ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED since the null check is already done in GENERATE_ALLOC_OBJECT_TLAB. |
| 1954 | GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_region_tlab, artAllocObjectFromCodeRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 0, 1 |
| 1955 | // No read barrier for the resolved or initialized cases since the caller is responsible for the |
| 1956 | // read barrier due to the to-space invariant. |
| 1957 | GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_resolved_region_tlab, artAllocObjectFromCodeResolvedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_RESOLVED, 1, 0 |
| 1958 | GENERATE_ALLOC_OBJECT_REGION_TLAB art_quick_alloc_object_initialized_region_tlab, artAllocObjectFromCodeInitializedRegionTLAB, ALLOC_OBJECT_TLAB_FAST_PATH_INITIALIZED, 1, 0 |
| 1959 | |
| 1960 | // TODO: We could use this macro for the normal tlab allocator too. |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 1961 | |
| 1962 | // The common code for art_quick_alloc_array_*region_tlab |
| 1963 | .macro GENERATE_ALLOC_ARRAY_REGION_TLAB name, entrypoint, fast_path, is_resolved |
| 1964 | ENTRY \name |
| 1965 | // Fast path array allocation for region tlab allocation. |
| 1966 | // x0: uint32_t type_idx |
| 1967 | // x1: int32_t component_count |
| 1968 | // x2: ArtMethod* method |
| 1969 | // x3-x7: free. |
| 1970 | #if !defined(USE_READ_BARRIER) |
| 1971 | mvn x0, xzr // Read barrier must be enabled here. |
| 1972 | ret // Return -1. |
| 1973 | #endif |
| 1974 | .if \is_resolved |
| 1975 | mov x3, x0 |
| 1976 | // If already resolved, class is stored in x0 |
| 1977 | .else |
| 1978 | ldr x3, [x2, #ART_METHOD_DEX_CACHE_TYPES_OFFSET_64] // Load dex cache resolved types array |
| 1979 | // Load the class (x2) |
| 1980 | ldr w3, [x3, x0, lsl #COMPRESSED_REFERENCE_SIZE_SHIFT] |
| 1981 | .endif |
| 1982 | // Most common case: GC is not marking. |
| 1983 | ldr w4, [xSELF, #THREAD_IS_GC_MARKING_OFFSET] |
| 1984 | cbnz x4, .Lmarking\name |
| 1985 | .Ldo_allocation\name: |
| 1986 | \fast_path .Lslow_path\name, x3, w3, x1, w1, x4, w4, x5, w5, x6, w6 |
| 1987 | .Lmarking\name: |
| 1988 | // GC is marking, check the lock word of the class for the mark bit. |
| 1989 | // If the class is null, go slow path. The check is required to read the lock word. |
| 1990 | cbz w3, .Lslow_path\name |
| 1991 | // Class is not null, check mark bit in lock word. |
| 1992 | ldr w4, [x3, #MIRROR_OBJECT_LOCK_WORD_OFFSET] |
| 1993 | // If the bit is not zero, do the allocation. |
| 1994 | tbnz w4, #LOCK_WORD_MARK_BIT_SHIFT, .Ldo_allocation\name |
| 1995 | // The read barrier slow path. Mark |
| 1996 | // the class. |
| 1997 | stp x0, x1, [sp, #-32]! // Save registers (x0, x1, x2, lr). |
| 1998 | stp x2, xLR, [sp, #16] |
| 1999 | mov x0, x3 // Pass the class as the first param. |
| 2000 | bl artReadBarrierMark |
| 2001 | mov x3, x0 // Get the (marked) class back. |
| 2002 | ldp x2, xLR, [sp, #16] |
| 2003 | ldp x0, x1, [sp], #32 // Restore registers. |
| 2004 | b .Ldo_allocation\name |
| 2005 | .Lslow_path\name: |
| 2006 | // x0: uint32_t type_idx / mirror::Class* klass (if resolved) |
| 2007 | // x1: int32_t component_count |
| 2008 | // x2: ArtMethod* method |
| 2009 | // x3: Thread* self |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2010 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves in case of GC |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 2011 | mov x3, xSELF // pass Thread::Current |
| 2012 | bl \entrypoint |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2013 | RESTORE_SAVE_REFS_ONLY_FRAME |
Mathieu Chartier | 8261d02 | 2016-08-08 09:41:04 -0700 | [diff] [blame] | 2014 | RETURN_IF_RESULT_IS_NON_ZERO_OR_DELIVER |
| 2015 | END \name |
| 2016 | .endm |
| 2017 | |
| 2018 | GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_region_tlab, artAllocArrayFromCodeRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH, 0 |
| 2019 | // TODO: art_quick_alloc_array_resolved_region_tlab seems to not get called. Investigate compiler. |
| 2020 | GENERATE_ALLOC_ARRAY_REGION_TLAB art_quick_alloc_array_resolved_region_tlab, artAllocArrayFromCodeResolvedRegionTLAB, ALLOC_ARRAY_TLAB_FAST_PATH_RESOLVED, 1 |
Hiroshi Yamauchi | 10d4c08 | 2016-02-24 12:51:18 -0800 | [diff] [blame] | 2021 | |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 2022 | /* |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 2023 | * Called by managed code when the thread has been asked to suspend. |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 2024 | */ |
| 2025 | .extern artTestSuspendFromCode |
| 2026 | ENTRY art_quick_test_suspend |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2027 | SETUP_SAVE_EVERYTHING_FRAME // save callee saves for stack crawl |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 2028 | mov x0, xSELF |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2029 | bl artTestSuspendFromCode // (Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2030 | RESTORE_SAVE_EVERYTHING_FRAME |
Vladimir Marko | 952dbb1 | 2016-07-28 12:01:51 +0100 | [diff] [blame] | 2031 | ret |
Zheng Xu | 48241e7 | 2014-05-23 11:52:42 +0800 | [diff] [blame] | 2032 | END art_quick_test_suspend |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2033 | |
Stuart Monteith | d5c78f4 | 2014-06-11 16:44:46 +0100 | [diff] [blame] | 2034 | ENTRY art_quick_implicit_suspend |
| 2035 | mov x0, xSELF |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2036 | SETUP_SAVE_REFS_ONLY_FRAME // save callee saves for stack crawl |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2037 | bl artTestSuspendFromCode // (Thread*) |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2038 | RESTORE_SAVE_REFS_ONLY_FRAME_AND_RETURN |
Stuart Monteith | d5c78f4 | 2014-06-11 16:44:46 +0100 | [diff] [blame] | 2039 | END art_quick_implicit_suspend |
| 2040 | |
Andreas Gampe | e62a07e | 2014-03-26 14:53:21 -0700 | [diff] [blame] | 2041 | /* |
| 2042 | * Called by managed code that is attempting to call a method on a proxy class. On entry |
| 2043 | * x0 holds the proxy method and x1 holds the receiver; The frame size of the invoked proxy |
| 2044 | * method agrees with a ref and args callee save frame. |
| 2045 | */ |
| 2046 | .extern artQuickProxyInvokeHandler |
| 2047 | ENTRY art_quick_proxy_invoke_handler |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2048 | SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0 |
Andreas Gampe | e62a07e | 2014-03-26 14:53:21 -0700 | [diff] [blame] | 2049 | mov x2, xSELF // pass Thread::Current |
| 2050 | mov x3, sp // pass SP |
| 2051 | bl artQuickProxyInvokeHandler // (Method* proxy method, receiver, Thread*, SP) |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 2052 | ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET] |
Andreas Gampe | e62a07e | 2014-03-26 14:53:21 -0700 | [diff] [blame] | 2053 | cbnz x2, .Lexception_in_proxy // success if no exception is pending |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2054 | RESTORE_SAVE_REFS_AND_ARGS_FRAME // Restore frame |
Andreas Gampe | d1e9167 | 2014-06-02 22:50:05 -0700 | [diff] [blame] | 2055 | fmov d0, x0 // Store result in d0 in case it was float or double |
Andreas Gampe | e62a07e | 2014-03-26 14:53:21 -0700 | [diff] [blame] | 2056 | ret // return on success |
| 2057 | .Lexception_in_proxy: |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2058 | RESTORE_SAVE_REFS_AND_ARGS_FRAME |
Andreas Gampe | e62a07e | 2014-03-26 14:53:21 -0700 | [diff] [blame] | 2059 | DELIVER_PENDING_EXCEPTION |
| 2060 | END art_quick_proxy_invoke_handler |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2061 | |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2062 | /* |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2063 | * Called to resolve an imt conflict. |
| 2064 | * x0 is the conflict ArtMethod. |
| 2065 | * xIP1 is a hidden argument that holds the target interface method's dex method index. |
| 2066 | * |
| 2067 | * Note that this stub writes to xIP0, xIP1, and x0. |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2068 | */ |
Andreas Gampe | 3031c8d | 2015-07-13 20:11:06 -0700 | [diff] [blame] | 2069 | .extern artInvokeInterfaceTrampoline |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2070 | ENTRY art_quick_imt_conflict_trampoline |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2071 | ldr xIP0, [sp, #0] // Load referrer |
| 2072 | ldr xIP0, [xIP0, #ART_METHOD_DEX_CACHE_METHODS_OFFSET_64] // Load dex cache methods array |
| 2073 | ldr xIP0, [xIP0, xIP1, lsl #POINTER_SIZE_SHIFT] // Load interface method |
| 2074 | ldr xIP1, [x0, #ART_METHOD_JNI_OFFSET_64] // Load ImtConflictTable |
| 2075 | ldr x0, [xIP1] // Load first entry in ImtConflictTable. |
| 2076 | .Limt_table_iterate: |
| 2077 | cmp x0, xIP0 |
| 2078 | // Branch if found. Benchmarks have shown doing a branch here is better. |
| 2079 | beq .Limt_table_found |
| 2080 | // If the entry is null, the interface method is not in the ImtConflictTable. |
| 2081 | cbz x0, .Lconflict_trampoline |
| 2082 | // Iterate over the entries of the ImtConflictTable. |
| 2083 | ldr x0, [xIP1, #(2 * __SIZEOF_POINTER__)]! |
| 2084 | b .Limt_table_iterate |
| 2085 | .Limt_table_found: |
Goran Jakovljevic | 59028d9 | 2016-03-29 18:05:03 +0200 | [diff] [blame] | 2086 | // We successfully hit an entry in the table. Load the target method |
Nicolas Geoffray | 796d630 | 2016-03-13 22:22:31 +0000 | [diff] [blame] | 2087 | // and jump to it. |
| 2088 | ldr x0, [xIP1, #__SIZEOF_POINTER__] |
| 2089 | ldr xIP0, [x0, #ART_METHOD_QUICK_CODE_OFFSET_64] |
| 2090 | br xIP0 |
| 2091 | .Lconflict_trampoline: |
| 2092 | // Call the runtime stub to populate the ImtConflictTable and jump to the |
| 2093 | // resolved method. |
Andreas Gampe | 3031c8d | 2015-07-13 20:11:06 -0700 | [diff] [blame] | 2094 | INVOKE_TRAMPOLINE_BODY artInvokeInterfaceTrampoline |
Andreas Gampe | 51f7635 | 2014-05-21 08:28:48 -0700 | [diff] [blame] | 2095 | END art_quick_imt_conflict_trampoline |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2096 | |
| 2097 | ENTRY art_quick_resolution_trampoline |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2098 | SETUP_SAVE_REFS_AND_ARGS_FRAME |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2099 | mov x2, xSELF |
| 2100 | mov x3, sp |
| 2101 | bl artQuickResolutionTrampoline // (called, receiver, Thread*, SP) |
Matteo Franchin | dfd891a | 2014-04-30 12:17:17 +0100 | [diff] [blame] | 2102 | cbz x0, 1f |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2103 | mov xIP0, x0 // Remember returned code pointer in xIP0. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 2104 | ldr x0, [sp, #0] // artQuickResolutionTrampoline puts called method in *SP. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2105 | RESTORE_SAVE_REFS_AND_ARGS_FRAME |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2106 | br xIP0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2107 | 1: |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2108 | RESTORE_SAVE_REFS_AND_ARGS_FRAME |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2109 | DELIVER_PENDING_EXCEPTION |
| 2110 | END art_quick_resolution_trampoline |
| 2111 | |
| 2112 | /* |
| 2113 | * Generic JNI frame layout: |
| 2114 | * |
| 2115 | * #-------------------# |
| 2116 | * | | |
| 2117 | * | caller method... | |
| 2118 | * #-------------------# <--- SP on entry |
| 2119 | * | Return X30/LR | |
| 2120 | * | X29/FP | callee save |
| 2121 | * | X28 | callee save |
| 2122 | * | X27 | callee save |
| 2123 | * | X26 | callee save |
| 2124 | * | X25 | callee save |
| 2125 | * | X24 | callee save |
| 2126 | * | X23 | callee save |
| 2127 | * | X22 | callee save |
| 2128 | * | X21 | callee save |
| 2129 | * | X20 | callee save |
Zheng Xu | 69a5030 | 2015-04-14 20:04:41 +0800 | [diff] [blame] | 2130 | * | X19 | callee save |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2131 | * | X7 | arg7 |
| 2132 | * | X6 | arg6 |
| 2133 | * | X5 | arg5 |
| 2134 | * | X4 | arg4 |
| 2135 | * | X3 | arg3 |
| 2136 | * | X2 | arg2 |
| 2137 | * | X1 | arg1 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2138 | * | D7 | float arg 8 |
| 2139 | * | D6 | float arg 7 |
| 2140 | * | D5 | float arg 6 |
| 2141 | * | D4 | float arg 5 |
| 2142 | * | D3 | float arg 4 |
| 2143 | * | D2 | float arg 3 |
| 2144 | * | D1 | float arg 2 |
| 2145 | * | D0 | float arg 1 |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 2146 | * | Method* | <- X0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2147 | * #-------------------# |
| 2148 | * | local ref cookie | // 4B |
Mathieu Chartier | 421c537 | 2014-05-14 14:11:40 -0700 | [diff] [blame] | 2149 | * | handle scope size | // 4B |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2150 | * #-------------------# |
| 2151 | * | JNI Call Stack | |
| 2152 | * #-------------------# <--- SP on native call |
| 2153 | * | | |
| 2154 | * | Stack for Regs | The trampoline assembly will pop these values |
| 2155 | * | | into registers for native call |
| 2156 | * #-------------------# |
| 2157 | * | Native code ptr | |
| 2158 | * #-------------------# |
| 2159 | * | Free scratch | |
| 2160 | * #-------------------# |
| 2161 | * | Ptr to (1) | <--- SP |
| 2162 | * #-------------------# |
| 2163 | */ |
| 2164 | /* |
| 2165 | * Called to do a generic JNI down-call |
| 2166 | */ |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 2167 | ENTRY art_quick_generic_jni_trampoline |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2168 | SETUP_SAVE_REFS_AND_ARGS_FRAME_WITH_METHOD_IN_X0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2169 | |
| 2170 | // Save SP , so we can have static CFI info. |
| 2171 | mov x28, sp |
| 2172 | .cfi_def_cfa_register x28 |
| 2173 | |
| 2174 | // This looks the same, but is different: this will be updated to point to the bottom |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 2175 | // of the frame when the handle scope is inserted. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2176 | mov xFP, sp |
| 2177 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2178 | mov xIP0, #5120 |
| 2179 | sub sp, sp, xIP0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2180 | |
| 2181 | // prepare for artQuickGenericJniTrampoline call |
| 2182 | // (Thread*, SP) |
| 2183 | // x0 x1 <= C calling convention |
| 2184 | // xSELF xFP <= where they are |
| 2185 | |
| 2186 | mov x0, xSELF // Thread* |
| 2187 | mov x1, xFP |
| 2188 | bl artQuickGenericJniTrampoline // (Thread*, sp) |
| 2189 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2190 | // The C call will have registered the complete save-frame on success. |
| 2191 | // The result of the call is: |
| 2192 | // x0: pointer to native code, 0 on error. |
| 2193 | // x1: pointer to the bottom of the used area of the alloca, can restore stack till there. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2194 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2195 | // Check for error = 0. |
Nicolas Geoffray | 126d659 | 2015-03-03 14:28:35 +0000 | [diff] [blame] | 2196 | cbz x0, .Lexception_in_native |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2197 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2198 | // Release part of the alloca. |
| 2199 | mov sp, x1 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2200 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2201 | // Save the code pointer |
| 2202 | mov xIP0, x0 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2203 | |
| 2204 | // Load parameters from frame into registers. |
| 2205 | // TODO Check with artQuickGenericJniTrampoline. |
| 2206 | // Also, check again APPCS64 - the stack arguments are interleaved. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2207 | ldp x0, x1, [sp] |
| 2208 | ldp x2, x3, [sp, #16] |
| 2209 | ldp x4, x5, [sp, #32] |
| 2210 | ldp x6, x7, [sp, #48] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2211 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2212 | ldp d0, d1, [sp, #64] |
| 2213 | ldp d2, d3, [sp, #80] |
| 2214 | ldp d4, d5, [sp, #96] |
| 2215 | ldp d6, d7, [sp, #112] |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2216 | |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2217 | add sp, sp, #128 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2218 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2219 | blr xIP0 // native call. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2220 | |
| 2221 | // result sign extension is handled in C code |
| 2222 | // prepare for artQuickGenericJniEndTrampoline call |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2223 | // (Thread*, result, result_f) |
| 2224 | // x0 x1 x2 <= C calling convention |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 2225 | mov x1, x0 // Result (from saved). |
| 2226 | mov x0, xSELF // Thread register. |
Andreas Gampe | c200a4a | 2014-06-16 18:39:09 -0700 | [diff] [blame] | 2227 | fmov x2, d0 // d0 will contain floating point result, but needs to go into x2 |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2228 | |
| 2229 | bl artQuickGenericJniEndTrampoline |
| 2230 | |
Nicolas Geoffray | 126d659 | 2015-03-03 14:28:35 +0000 | [diff] [blame] | 2231 | // Pending exceptions possible. |
Serban Constantinescu | 9bd88b0 | 2015-04-22 16:24:46 +0100 | [diff] [blame] | 2232 | ldr x2, [xSELF, THREAD_EXCEPTION_OFFSET] |
Nicolas Geoffray | 126d659 | 2015-03-03 14:28:35 +0000 | [diff] [blame] | 2233 | cbnz x2, .Lexception_in_native |
| 2234 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2235 | // Tear down the alloca. |
| 2236 | mov sp, x28 |
| 2237 | .cfi_def_cfa_register sp |
| 2238 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2239 | // Tear down the callee-save frame. |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2240 | RESTORE_SAVE_REFS_AND_ARGS_FRAME |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2241 | |
| 2242 | // store into fpr, for when it's a fpr return... |
| 2243 | fmov d0, x0 |
| 2244 | ret |
| 2245 | |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2246 | .Lexception_in_native: |
Nicolas Geoffray | 126d659 | 2015-03-03 14:28:35 +0000 | [diff] [blame] | 2247 | // Move to x1 then sp to please assembler. |
| 2248 | ldr x1, [xSELF, # THREAD_TOP_QUICK_FRAME_OFFSET] |
| 2249 | mov sp, x1 |
| 2250 | .cfi_def_cfa_register sp |
| 2251 | # This will create a new save-all frame, required by the runtime. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2252 | DELIVER_PENDING_EXCEPTION |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2253 | END art_quick_generic_jni_trampoline |
| 2254 | |
| 2255 | /* |
| 2256 | * Called to bridge from the quick to interpreter ABI. On entry the arguments match those |
| 2257 | * of a quick call: |
| 2258 | * x0 = method being called/to bridge to. |
| 2259 | * x1..x7, d0..d7 = arguments to that method. |
| 2260 | */ |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 2261 | ENTRY art_quick_to_interpreter_bridge |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2262 | SETUP_SAVE_REFS_AND_ARGS_FRAME // Set up frame and save arguments. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2263 | |
| 2264 | // x0 will contain mirror::ArtMethod* method. |
| 2265 | mov x1, xSELF // How to get Thread::Current() ??? |
| 2266 | mov x2, sp |
| 2267 | |
| 2268 | // uint64_t artQuickToInterpreterBridge(mirror::ArtMethod* method, Thread* self, |
| 2269 | // mirror::ArtMethod** sp) |
| 2270 | bl artQuickToInterpreterBridge |
| 2271 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2272 | RESTORE_SAVE_REFS_AND_ARGS_FRAME // TODO: no need to restore arguments in this case. |
Stuart Monteith | b95a534 | 2014-03-12 13:32:32 +0000 | [diff] [blame] | 2273 | |
| 2274 | fmov d0, x0 |
| 2275 | |
| 2276 | RETURN_OR_DELIVER_PENDING_EXCEPTION |
| 2277 | END art_quick_to_interpreter_bridge |
| 2278 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2279 | |
| 2280 | // |
| 2281 | // Instrumentation-related stubs |
| 2282 | // |
| 2283 | .extern artInstrumentationMethodEntryFromCode |
| 2284 | ENTRY art_quick_instrumentation_entry |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2285 | SETUP_SAVE_REFS_AND_ARGS_FRAME |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2286 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2287 | mov x20, x0 // Preserve method reference in a callee-save. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2288 | |
| 2289 | mov x2, xSELF |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2290 | mov x3, xLR |
| 2291 | bl artInstrumentationMethodEntryFromCode // (Method*, Object*, Thread*, LR) |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2292 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2293 | mov xIP0, x0 // x0 = result of call. |
| 2294 | mov x0, x20 // Reload method reference. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2295 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2296 | RESTORE_SAVE_REFS_AND_ARGS_FRAME // Note: will restore xSELF |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2297 | adr xLR, art_quick_instrumentation_exit |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2298 | br xIP0 // Tail-call method with lr set to art_quick_instrumentation_exit. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2299 | END art_quick_instrumentation_entry |
| 2300 | |
| 2301 | .extern artInstrumentationMethodExitFromCode |
| 2302 | ENTRY art_quick_instrumentation_exit |
| 2303 | mov xLR, #0 // Clobber LR for later checks. |
| 2304 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2305 | SETUP_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2306 | |
| 2307 | // We need to save x0 and d0. We could use a callee-save from SETUP_REF_ONLY, but then |
| 2308 | // we would need to fully restore it. As there are a lot of callee-save registers, it seems |
| 2309 | // easier to have an extra small stack area. |
| 2310 | |
Sebastien Hertz | 70f8d4b | 2014-06-19 11:51:41 +0200 | [diff] [blame] | 2311 | str x0, [sp, #-16]! // Save integer result. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2312 | .cfi_adjust_cfa_offset 16 |
| 2313 | str d0, [sp, #8] // Save floating-point result. |
| 2314 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2315 | add x1, sp, #16 // Pass SP. |
| 2316 | mov x2, x0 // Pass integer result. |
| 2317 | fmov x3, d0 // Pass floating-point result. |
Sebastien Hertz | 70f8d4b | 2014-06-19 11:51:41 +0200 | [diff] [blame] | 2318 | mov x0, xSELF // Pass Thread. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2319 | bl artInstrumentationMethodExitFromCode // (Thread*, SP, gpr_res, fpr_res) |
| 2320 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2321 | mov xIP0, x0 // Return address from instrumentation call. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2322 | mov xLR, x1 // r1 is holding link register if we're to bounce to deoptimize |
| 2323 | |
| 2324 | ldr d0, [sp, #8] // Restore floating-point result. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 2325 | ldr x0, [sp], #16 // Restore integer result, and drop stack area. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2326 | .cfi_adjust_cfa_offset 16 |
| 2327 | |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2328 | POP_SAVE_REFS_ONLY_FRAME |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2329 | |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2330 | br xIP0 // Tail-call out. |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2331 | END art_quick_instrumentation_exit |
| 2332 | |
| 2333 | /* |
| 2334 | * Instrumentation has requested that we deoptimize into the interpreter. The deoptimization |
| 2335 | * will long jump to the upcall with a special exception of -1. |
| 2336 | */ |
| 2337 | .extern artDeoptimize |
| 2338 | ENTRY art_quick_deoptimize |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 2339 | SETUP_SAVE_ALL_CALLEE_SAVES_FRAME |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2340 | mov x0, xSELF // Pass thread. |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2341 | bl artDeoptimize // artDeoptimize(Thread*) |
Serban Constantinescu | 86797a7 | 2014-06-19 16:17:56 +0100 | [diff] [blame] | 2342 | brk 0 |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2343 | END art_quick_deoptimize |
| 2344 | |
Sebastien Hertz | 0747466 | 2015-08-25 15:12:33 +0000 | [diff] [blame] | 2345 | /* |
| 2346 | * Compiled code has requested that we deoptimize into the interpreter. The deoptimization |
| 2347 | * will long jump to the upcall with a special exception of -1. |
| 2348 | */ |
| 2349 | .extern artDeoptimizeFromCompiledCode |
| 2350 | ENTRY art_quick_deoptimize_from_compiled_code |
Vladimir Marko | 239d6ea | 2016-09-05 10:44:04 +0100 | [diff] [blame] | 2351 | SETUP_SAVE_EVERYTHING_FRAME |
Sebastien Hertz | 0747466 | 2015-08-25 15:12:33 +0000 | [diff] [blame] | 2352 | mov x0, xSELF // Pass thread. |
| 2353 | bl artDeoptimizeFromCompiledCode // artDeoptimizeFromCompiledCode(Thread*) |
| 2354 | brk 0 |
| 2355 | END art_quick_deoptimize_from_compiled_code |
| 2356 | |
Andreas Gampe | d58342c | 2014-06-05 14:18:08 -0700 | [diff] [blame] | 2357 | |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 2358 | /* |
| 2359 | * String's indexOf. |
| 2360 | * |
| 2361 | * TODO: Not very optimized. |
| 2362 | * On entry: |
| 2363 | * x0: string object (known non-null) |
| 2364 | * w1: char to match (known <= 0xFFFF) |
| 2365 | * w2: Starting offset in string data |
| 2366 | */ |
| 2367 | ENTRY art_quick_indexof |
Ian Rogers | 1d8cdbc | 2014-09-22 22:51:09 -0700 | [diff] [blame] | 2368 | ldr w3, [x0, #MIRROR_STRING_COUNT_OFFSET] |
Jeff Hao | 848f70a | 2014-01-15 13:49:50 -0800 | [diff] [blame] | 2369 | add x0, x0, #MIRROR_STRING_VALUE_OFFSET |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 2370 | |
| 2371 | /* Clamp start to [0..count] */ |
| 2372 | cmp w2, #0 |
| 2373 | csel w2, wzr, w2, lt |
| 2374 | cmp w2, w3 |
| 2375 | csel w2, w3, w2, gt |
| 2376 | |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 2377 | /* Save a copy to compute result */ |
| 2378 | mov x5, x0 |
| 2379 | |
| 2380 | /* Build pointer to start of data to compare and pre-bias */ |
| 2381 | add x0, x0, x2, lsl #1 |
| 2382 | sub x0, x0, #2 |
| 2383 | |
| 2384 | /* Compute iteration count */ |
| 2385 | sub w2, w3, w2 |
| 2386 | |
| 2387 | /* |
| 2388 | * At this point we have: |
| 2389 | * x0: start of the data to test |
| 2390 | * w1: char to compare |
| 2391 | * w2: iteration count |
| 2392 | * x5: original start of string data |
| 2393 | */ |
| 2394 | |
| 2395 | subs w2, w2, #4 |
| 2396 | b.lt .Lindexof_remainder |
| 2397 | |
| 2398 | .Lindexof_loop4: |
| 2399 | ldrh w6, [x0, #2]! |
| 2400 | ldrh w7, [x0, #2]! |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2401 | ldrh wIP0, [x0, #2]! |
| 2402 | ldrh wIP1, [x0, #2]! |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 2403 | cmp w6, w1 |
| 2404 | b.eq .Lmatch_0 |
| 2405 | cmp w7, w1 |
| 2406 | b.eq .Lmatch_1 |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2407 | cmp wIP0, w1 |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 2408 | b.eq .Lmatch_2 |
Zheng Xu | b551fdc | 2014-07-25 11:49:42 +0800 | [diff] [blame] | 2409 | cmp wIP1, w1 |
Serban Constantinescu | 169489b | 2014-06-11 16:43:35 +0100 | [diff] [blame] | 2410 | b.eq .Lmatch_3 |
| 2411 | subs w2, w2, #4 |
| 2412 | b.ge .Lindexof_loop4 |
| 2413 | |
| 2414 | .Lindexof_remainder: |
| 2415 | adds w2, w2, #4 |
| 2416 | b.eq .Lindexof_nomatch |
| 2417 | |
| 2418 | .Lindexof_loop1: |
| 2419 | ldrh w6, [x0, #2]! |
| 2420 | cmp w6, w1 |
| 2421 | b.eq .Lmatch_3 |
| 2422 | subs w2, w2, #1 |
| 2423 | b.ne .Lindexof_loop1 |
| 2424 | |
| 2425 | .Lindexof_nomatch: |
| 2426 | mov x0, #-1 |
| 2427 | ret |
| 2428 | |
| 2429 | .Lmatch_0: |
| 2430 | sub x0, x0, #6 |
| 2431 | sub x0, x0, x5 |
| 2432 | asr x0, x0, #1 |
| 2433 | ret |
| 2434 | .Lmatch_1: |
| 2435 | sub x0, x0, #4 |
| 2436 | sub x0, x0, x5 |
| 2437 | asr x0, x0, #1 |
| 2438 | ret |
| 2439 | .Lmatch_2: |
| 2440 | sub x0, x0, #2 |
| 2441 | sub x0, x0, x5 |
| 2442 | asr x0, x0, #1 |
| 2443 | ret |
| 2444 | .Lmatch_3: |
| 2445 | sub x0, x0, x5 |
| 2446 | asr x0, x0, #1 |
| 2447 | ret |
| 2448 | END art_quick_indexof |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 2449 | |
| 2450 | /* |
| 2451 | * Create a function `name` calling the ReadBarrier::Mark routine, |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2452 | * getting its argument and returning its result through W register |
| 2453 | * `wreg` (corresponding to X register `xreg`), saving and restoring |
| 2454 | * all caller-save registers. |
| 2455 | * |
| 2456 | * If `wreg` is different from `w0`, the generated function follows a |
| 2457 | * non-standard runtime calling convention: |
| 2458 | * - register `wreg` is used to pass the (sole) argument of this |
| 2459 | * function (instead of W0); |
| 2460 | * - register `wreg` is used to return the result of this function |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 2461 | * (instead of W0); |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 2462 | * - W0 is treated like a normal (non-argument) caller-save register; |
| 2463 | * - everything else is the same as in the standard runtime calling |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2464 | * convention (e.g. standard callee-save registers are preserved). |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 2465 | */ |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2466 | .macro READ_BARRIER_MARK_REG name, wreg, xreg |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 2467 | ENTRY \name |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 2468 | // Reference is null, no work to do at all. |
| 2469 | cbz \wreg, .Lret_rb_\name |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2470 | /* |
| 2471 | * Allocate 46 stack slots * 8 = 368 bytes: |
| 2472 | * - 20 slots for core registers X0-X19 |
| 2473 | * - 24 slots for floating-point registers D0-D7 and D16-D31 |
| 2474 | * - 1 slot for return address register XLR |
| 2475 | * - 1 padding slot for 16-byte stack alignment |
| 2476 | */ |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 2477 | // Use wIP0 as temp and check the mark bit of the reference. wIP0 is not used by the compiler. |
| 2478 | ldr wIP0, [\xreg, #MIRROR_OBJECT_LOCK_WORD_OFFSET] |
| 2479 | tbz wIP0, #LOCK_WORD_MARK_BIT_SHIFT, .Lslow_path_rb_\name |
| 2480 | ret |
| 2481 | .Lslow_path_rb_\name: |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2482 | // Save all potentially live caller-save core registers. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 2483 | SAVE_TWO_REGS_INCREASE_FRAME x0, x1, 368 |
| 2484 | SAVE_TWO_REGS x2, x3, 16 |
| 2485 | SAVE_TWO_REGS x4, x5, 32 |
| 2486 | SAVE_TWO_REGS x6, x7, 48 |
| 2487 | SAVE_TWO_REGS x8, x9, 64 |
| 2488 | SAVE_TWO_REGS x10, x11, 80 |
| 2489 | SAVE_TWO_REGS x12, x13, 96 |
| 2490 | SAVE_TWO_REGS x14, x15, 112 |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 2491 | SAVE_TWO_REGS x16, x17, 128 |
| 2492 | SAVE_TWO_REGS x18, x19, 144 |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2493 | // Save all potentially live caller-save floating-point registers. |
| 2494 | stp d0, d1, [sp, #160] |
| 2495 | stp d2, d3, [sp, #176] |
| 2496 | stp d4, d5, [sp, #192] |
| 2497 | stp d6, d7, [sp, #208] |
| 2498 | stp d16, d17, [sp, #224] |
| 2499 | stp d18, d19, [sp, #240] |
| 2500 | stp d20, d21, [sp, #256] |
| 2501 | stp d22, d23, [sp, #272] |
| 2502 | stp d24, d25, [sp, #288] |
| 2503 | stp d26, d27, [sp, #304] |
| 2504 | stp d28, d29, [sp, #320] |
| 2505 | stp d30, d31, [sp, #336] |
| 2506 | // Save return address. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 2507 | // (sp + #352 is a padding slot) |
| 2508 | SAVE_REG xLR, 360 |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2509 | |
| 2510 | .ifnc \wreg, w0 |
| 2511 | mov w0, \wreg // Pass arg1 - obj from `wreg` |
| 2512 | .endif |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 2513 | bl artReadBarrierMark // artReadBarrierMark(obj) |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2514 | .ifnc \wreg, w0 |
| 2515 | mov \wreg, w0 // Return result into `wreg` |
| 2516 | .endif |
| 2517 | |
| 2518 | // Restore core regs, except `xreg`, as `wreg` is used to return the |
| 2519 | // result of this function (simply remove it from the stack instead). |
| 2520 | POP_REGS_NE x0, x1, 0, \xreg |
| 2521 | POP_REGS_NE x2, x3, 16, \xreg |
| 2522 | POP_REGS_NE x4, x5, 32, \xreg |
| 2523 | POP_REGS_NE x6, x7, 48, \xreg |
| 2524 | POP_REGS_NE x8, x9, 64, \xreg |
| 2525 | POP_REGS_NE x10, x11, 80, \xreg |
| 2526 | POP_REGS_NE x12, x13, 96, \xreg |
| 2527 | POP_REGS_NE x14, x15, 112, \xreg |
| 2528 | POP_REGS_NE x16, x17, 128, \xreg |
| 2529 | POP_REGS_NE x18, x19, 144, \xreg |
| 2530 | // Restore floating-point registers. |
| 2531 | ldp d0, d1, [sp, #160] |
| 2532 | ldp d2, d3, [sp, #176] |
| 2533 | ldp d4, d5, [sp, #192] |
| 2534 | ldp d6, d7, [sp, #208] |
| 2535 | ldp d16, d17, [sp, #224] |
| 2536 | ldp d18, d19, [sp, #240] |
| 2537 | ldp d20, d21, [sp, #256] |
| 2538 | ldp d22, d23, [sp, #272] |
| 2539 | ldp d24, d25, [sp, #288] |
| 2540 | ldp d26, d27, [sp, #304] |
| 2541 | ldp d28, d29, [sp, #320] |
| 2542 | ldp d30, d31, [sp, #336] |
| 2543 | // Restore return address and remove padding. |
Vladimir Marko | 215076b | 2016-09-07 18:05:55 +0100 | [diff] [blame] | 2544 | RESTORE_REG xLR, 360 |
Vladimir Marko | ae6ba1f | 2016-09-09 11:56:05 +0100 | [diff] [blame] | 2545 | DECREASE_FRAME 368 |
Mathieu Chartier | 36a270a | 2016-07-28 18:08:51 -0700 | [diff] [blame] | 2546 | .Lret_rb_\name: |
Roland Levillain | 02b7580 | 2016-07-13 11:54:35 +0100 | [diff] [blame] | 2547 | ret |
| 2548 | END \name |
| 2549 | .endm |
| 2550 | |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2551 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg00, w0, x0 |
| 2552 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg01, w1, x1 |
| 2553 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg02, w2, x2 |
| 2554 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg03, w3, x3 |
| 2555 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg04, w4, x4 |
| 2556 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg05, w5, x5 |
| 2557 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg06, w6, x6 |
| 2558 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg07, w7, x7 |
| 2559 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg08, w8, x8 |
| 2560 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg09, w9, x9 |
| 2561 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg10, w10, x10 |
| 2562 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg11, w11, x11 |
| 2563 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg12, w12, x12 |
| 2564 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg13, w13, x13 |
| 2565 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg14, w14, x14 |
| 2566 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg15, w15, x15 |
Mathieu Chartier | 36c2271 | 2016-08-12 13:19:44 -0700 | [diff] [blame] | 2567 | // READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg16, w16, x16 ip0 is blocked |
Roland Levillain | 4359e61 | 2016-07-20 11:32:19 +0100 | [diff] [blame] | 2568 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg17, w17, x17 |
| 2569 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg18, w18, x18 |
| 2570 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg19, w19, x19 |
| 2571 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg20, w20, x20 |
| 2572 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg21, w21, x21 |
| 2573 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg22, w22, x22 |
| 2574 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg23, w23, x23 |
| 2575 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg24, w24, x24 |
| 2576 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg25, w25, x25 |
| 2577 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg26, w26, x26 |
| 2578 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg27, w27, x27 |
| 2579 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg28, w28, x28 |
| 2580 | READ_BARRIER_MARK_REG art_quick_read_barrier_mark_reg29, w29, x29 |