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