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