Wed, 27 Nov 2013 16:16:21 -0800
8029015: PPC64 (part 216): opto: trap based null and range checks
Summary: On PPC64 use tdi instruction that does a compare and raises SIGTRAP for NULL and range checks.
Reviewed-by: kvn
goetz@6458 | 1 | /* |
goetz@6458 | 2 | * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
goetz@6458 | 3 | * Copyright 2012, 2013 SAP AG. All rights reserved. |
goetz@6458 | 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
goetz@6458 | 5 | * |
goetz@6458 | 6 | * This code is free software; you can redistribute it and/or modify it |
goetz@6458 | 7 | * under the terms of the GNU General Public License version 2 only, as |
goetz@6458 | 8 | * published by the Free Software Foundation. |
goetz@6458 | 9 | * |
goetz@6458 | 10 | * This code is distributed in the hope that it will be useful, but WITHOUT |
goetz@6458 | 11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
goetz@6458 | 12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
goetz@6458 | 13 | * version 2 for more details (a copy is included in the LICENSE file that |
goetz@6458 | 14 | * accompanied this code). |
goetz@6458 | 15 | * |
goetz@6458 | 16 | * You should have received a copy of the GNU General Public License version |
goetz@6458 | 17 | * 2 along with this work; if not, write to the Free Software Foundation, |
goetz@6458 | 18 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
goetz@6458 | 19 | * |
goetz@6458 | 20 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
goetz@6458 | 21 | * or visit www.oracle.com if you need additional information or have any |
goetz@6458 | 22 | * questions. |
goetz@6458 | 23 | * |
goetz@6458 | 24 | */ |
goetz@6458 | 25 | |
goetz@6458 | 26 | #include "precompiled.hpp" |
goetz@6458 | 27 | #include "asm/assembler.hpp" |
goetz@6458 | 28 | #include "asm/macroAssembler.inline.hpp" |
goetz@6458 | 29 | #include "interpreter/interpreter.hpp" |
goetz@6458 | 30 | #include "nativeInst_ppc.hpp" |
goetz@6458 | 31 | #include "oops/instanceOop.hpp" |
goetz@6458 | 32 | #include "oops/method.hpp" |
goetz@6458 | 33 | #include "oops/objArrayKlass.hpp" |
goetz@6458 | 34 | #include "oops/oop.inline.hpp" |
goetz@6458 | 35 | #include "prims/methodHandles.hpp" |
goetz@6458 | 36 | #include "runtime/frame.inline.hpp" |
goetz@6458 | 37 | #include "runtime/handles.inline.hpp" |
goetz@6458 | 38 | #include "runtime/sharedRuntime.hpp" |
goetz@6458 | 39 | #include "runtime/stubCodeGenerator.hpp" |
goetz@6458 | 40 | #include "runtime/stubRoutines.hpp" |
goetz@6458 | 41 | #include "utilities/top.hpp" |
goetz@6458 | 42 | #ifdef TARGET_OS_FAMILY_aix |
goetz@6458 | 43 | # include "thread_aix.inline.hpp" |
goetz@6458 | 44 | #endif |
goetz@6458 | 45 | #ifdef TARGET_OS_FAMILY_linux |
goetz@6458 | 46 | # include "thread_linux.inline.hpp" |
goetz@6458 | 47 | #endif |
goetz@6458 | 48 | #ifdef COMPILER2 |
goetz@6458 | 49 | #include "opto/runtime.hpp" |
goetz@6458 | 50 | #endif |
goetz@6458 | 51 | |
goetz@6458 | 52 | #define __ _masm-> |
goetz@6458 | 53 | |
goetz@6458 | 54 | #ifdef PRODUCT |
goetz@6458 | 55 | #define BLOCK_COMMENT(str) // nothing |
goetz@6458 | 56 | #else |
goetz@6458 | 57 | #define BLOCK_COMMENT(str) __ block_comment(str) |
goetz@6458 | 58 | #endif |
goetz@6458 | 59 | |
goetz@6458 | 60 | class StubGenerator: public StubCodeGenerator { |
goetz@6458 | 61 | private: |
goetz@6458 | 62 | |
goetz@6458 | 63 | // Call stubs are used to call Java from C |
goetz@6458 | 64 | // |
goetz@6458 | 65 | // Arguments: |
goetz@6458 | 66 | // |
goetz@6458 | 67 | // R3 - call wrapper address : address |
goetz@6458 | 68 | // R4 - result : intptr_t* |
goetz@6458 | 69 | // R5 - result type : BasicType |
goetz@6458 | 70 | // R6 - method : Method |
goetz@6458 | 71 | // R7 - frame mgr entry point : address |
goetz@6458 | 72 | // R8 - parameter block : intptr_t* |
goetz@6458 | 73 | // R9 - parameter count in words : int |
goetz@6458 | 74 | // R10 - thread : Thread* |
goetz@6458 | 75 | // |
goetz@6458 | 76 | address generate_call_stub(address& return_address) { |
goetz@6458 | 77 | // Setup a new c frame, copy java arguments, call frame manager or |
goetz@6458 | 78 | // native_entry, and process result. |
goetz@6458 | 79 | |
goetz@6458 | 80 | StubCodeMark mark(this, "StubRoutines", "call_stub"); |
goetz@6458 | 81 | |
goetz@6458 | 82 | address start = __ emit_fd(); |
goetz@6458 | 83 | |
goetz@6458 | 84 | // some sanity checks |
goetz@6458 | 85 | assert((sizeof(frame::abi_48) % 16) == 0, "unaligned"); |
goetz@6458 | 86 | assert((sizeof(frame::abi_112) % 16) == 0, "unaligned"); |
goetz@6458 | 87 | assert((sizeof(frame::spill_nonvolatiles) % 16) == 0, "unaligned"); |
goetz@6458 | 88 | assert((sizeof(frame::parent_ijava_frame_abi) % 16) == 0, "unaligned"); |
goetz@6458 | 89 | assert((sizeof(frame::entry_frame_locals) % 16) == 0, "unaligned"); |
goetz@6458 | 90 | |
goetz@6458 | 91 | Register r_arg_call_wrapper_addr = R3; |
goetz@6458 | 92 | Register r_arg_result_addr = R4; |
goetz@6458 | 93 | Register r_arg_result_type = R5; |
goetz@6458 | 94 | Register r_arg_method = R6; |
goetz@6458 | 95 | Register r_arg_entry = R7; |
goetz@6458 | 96 | Register r_arg_thread = R10; |
goetz@6458 | 97 | |
goetz@6458 | 98 | Register r_temp = R24; |
goetz@6458 | 99 | Register r_top_of_arguments_addr = R25; |
goetz@6458 | 100 | Register r_entryframe_fp = R26; |
goetz@6458 | 101 | |
goetz@6458 | 102 | { |
goetz@6458 | 103 | // Stack on entry to call_stub: |
goetz@6458 | 104 | // |
goetz@6458 | 105 | // F1 [C_FRAME] |
goetz@6458 | 106 | // ... |
goetz@6458 | 107 | |
goetz@6458 | 108 | Register r_arg_argument_addr = R8; |
goetz@6458 | 109 | Register r_arg_argument_count = R9; |
goetz@6458 | 110 | Register r_frame_alignment_in_bytes = R27; |
goetz@6458 | 111 | Register r_argument_addr = R28; |
goetz@6458 | 112 | Register r_argumentcopy_addr = R29; |
goetz@6458 | 113 | Register r_argument_size_in_bytes = R30; |
goetz@6458 | 114 | Register r_frame_size = R23; |
goetz@6458 | 115 | |
goetz@6458 | 116 | Label arguments_copied; |
goetz@6458 | 117 | |
goetz@6458 | 118 | // Save LR/CR to caller's C_FRAME. |
goetz@6458 | 119 | __ save_LR_CR(R0); |
goetz@6458 | 120 | |
goetz@6458 | 121 | // Zero extend arg_argument_count. |
goetz@6458 | 122 | __ clrldi(r_arg_argument_count, r_arg_argument_count, 32); |
goetz@6458 | 123 | |
goetz@6458 | 124 | // Save non-volatiles GPRs to ENTRY_FRAME (not yet pushed, but it's safe). |
goetz@6458 | 125 | __ save_nonvolatile_gprs(R1_SP, _spill_nonvolatiles_neg(r14)); |
goetz@6458 | 126 | |
goetz@6458 | 127 | // Keep copy of our frame pointer (caller's SP). |
goetz@6458 | 128 | __ mr(r_entryframe_fp, R1_SP); |
goetz@6458 | 129 | |
goetz@6458 | 130 | BLOCK_COMMENT("Push ENTRY_FRAME including arguments"); |
goetz@6458 | 131 | // Push ENTRY_FRAME including arguments: |
goetz@6458 | 132 | // |
goetz@6458 | 133 | // F0 [TOP_IJAVA_FRAME_ABI] |
goetz@6458 | 134 | // alignment (optional) |
goetz@6458 | 135 | // [outgoing Java arguments] |
goetz@6458 | 136 | // [ENTRY_FRAME_LOCALS] |
goetz@6458 | 137 | // F1 [C_FRAME] |
goetz@6458 | 138 | // ... |
goetz@6458 | 139 | |
goetz@6458 | 140 | // calculate frame size |
goetz@6458 | 141 | |
goetz@6458 | 142 | // unaligned size of arguments |
goetz@6458 | 143 | __ sldi(r_argument_size_in_bytes, |
goetz@6458 | 144 | r_arg_argument_count, Interpreter::logStackElementSize); |
goetz@6458 | 145 | // arguments alignment (max 1 slot) |
goetz@6458 | 146 | // FIXME: use round_to() here |
goetz@6458 | 147 | __ andi_(r_frame_alignment_in_bytes, r_arg_argument_count, 1); |
goetz@6458 | 148 | __ sldi(r_frame_alignment_in_bytes, |
goetz@6458 | 149 | r_frame_alignment_in_bytes, Interpreter::logStackElementSize); |
goetz@6458 | 150 | |
goetz@6458 | 151 | // size = unaligned size of arguments + top abi's size |
goetz@6458 | 152 | __ addi(r_frame_size, r_argument_size_in_bytes, |
goetz@6458 | 153 | frame::top_ijava_frame_abi_size); |
goetz@6458 | 154 | // size += arguments alignment |
goetz@6458 | 155 | __ add(r_frame_size, |
goetz@6458 | 156 | r_frame_size, r_frame_alignment_in_bytes); |
goetz@6458 | 157 | // size += size of call_stub locals |
goetz@6458 | 158 | __ addi(r_frame_size, |
goetz@6458 | 159 | r_frame_size, frame::entry_frame_locals_size); |
goetz@6458 | 160 | |
goetz@6458 | 161 | // push ENTRY_FRAME |
goetz@6458 | 162 | __ push_frame(r_frame_size, r_temp); |
goetz@6458 | 163 | |
goetz@6458 | 164 | // initialize call_stub locals (step 1) |
goetz@6458 | 165 | __ std(r_arg_call_wrapper_addr, |
goetz@6458 | 166 | _entry_frame_locals_neg(call_wrapper_address), r_entryframe_fp); |
goetz@6458 | 167 | __ std(r_arg_result_addr, |
goetz@6458 | 168 | _entry_frame_locals_neg(result_address), r_entryframe_fp); |
goetz@6458 | 169 | __ std(r_arg_result_type, |
goetz@6458 | 170 | _entry_frame_locals_neg(result_type), r_entryframe_fp); |
goetz@6458 | 171 | // we will save arguments_tos_address later |
goetz@6458 | 172 | |
goetz@6458 | 173 | |
goetz@6458 | 174 | BLOCK_COMMENT("Copy Java arguments"); |
goetz@6458 | 175 | // copy Java arguments |
goetz@6458 | 176 | |
goetz@6458 | 177 | // Calculate top_of_arguments_addr which will be R17_tos (not prepushed) later. |
goetz@6458 | 178 | // FIXME: why not simply use SP+frame::top_ijava_frame_size? |
goetz@6458 | 179 | __ addi(r_top_of_arguments_addr, |
goetz@6458 | 180 | R1_SP, frame::top_ijava_frame_abi_size); |
goetz@6458 | 181 | __ add(r_top_of_arguments_addr, |
goetz@6458 | 182 | r_top_of_arguments_addr, r_frame_alignment_in_bytes); |
goetz@6458 | 183 | |
goetz@6458 | 184 | // any arguments to copy? |
goetz@6458 | 185 | __ cmpdi(CCR0, r_arg_argument_count, 0); |
goetz@6458 | 186 | __ beq(CCR0, arguments_copied); |
goetz@6458 | 187 | |
goetz@6458 | 188 | // prepare loop and copy arguments in reverse order |
goetz@6458 | 189 | { |
goetz@6458 | 190 | // init CTR with arg_argument_count |
goetz@6458 | 191 | __ mtctr(r_arg_argument_count); |
goetz@6458 | 192 | |
goetz@6458 | 193 | // let r_argumentcopy_addr point to last outgoing Java arguments P |
goetz@6458 | 194 | __ mr(r_argumentcopy_addr, r_top_of_arguments_addr); |
goetz@6458 | 195 | |
goetz@6458 | 196 | // let r_argument_addr point to last incoming java argument |
goetz@6458 | 197 | __ add(r_argument_addr, |
goetz@6458 | 198 | r_arg_argument_addr, r_argument_size_in_bytes); |
goetz@6458 | 199 | __ addi(r_argument_addr, r_argument_addr, -BytesPerWord); |
goetz@6458 | 200 | |
goetz@6458 | 201 | // now loop while CTR > 0 and copy arguments |
goetz@6458 | 202 | { |
goetz@6458 | 203 | Label next_argument; |
goetz@6458 | 204 | __ bind(next_argument); |
goetz@6458 | 205 | |
goetz@6458 | 206 | __ ld(r_temp, 0, r_argument_addr); |
goetz@6458 | 207 | // argument_addr--; |
goetz@6458 | 208 | __ addi(r_argument_addr, r_argument_addr, -BytesPerWord); |
goetz@6458 | 209 | __ std(r_temp, 0, r_argumentcopy_addr); |
goetz@6458 | 210 | // argumentcopy_addr++; |
goetz@6458 | 211 | __ addi(r_argumentcopy_addr, r_argumentcopy_addr, BytesPerWord); |
goetz@6458 | 212 | |
goetz@6458 | 213 | __ bdnz(next_argument); |
goetz@6458 | 214 | } |
goetz@6458 | 215 | } |
goetz@6458 | 216 | |
goetz@6458 | 217 | // Arguments copied, continue. |
goetz@6458 | 218 | __ bind(arguments_copied); |
goetz@6458 | 219 | } |
goetz@6458 | 220 | |
goetz@6458 | 221 | { |
goetz@6458 | 222 | BLOCK_COMMENT("Call frame manager or native entry."); |
goetz@6458 | 223 | // Call frame manager or native entry. |
goetz@6458 | 224 | Register r_new_arg_entry = R14_state; |
goetz@6458 | 225 | assert_different_registers(r_new_arg_entry, r_top_of_arguments_addr, |
goetz@6458 | 226 | r_arg_method, r_arg_thread); |
goetz@6458 | 227 | |
goetz@6458 | 228 | __ mr(r_new_arg_entry, r_arg_entry); |
goetz@6458 | 229 | |
goetz@6458 | 230 | // Register state on entry to frame manager / native entry: |
goetz@6458 | 231 | // |
goetz@6458 | 232 | // R17_tos - intptr_t* sender tos (prepushed) Lesp = (SP) + copied_arguments_offset - 8 |
goetz@6458 | 233 | // R19_method - Method |
goetz@6458 | 234 | // R16_thread - JavaThread* |
goetz@6458 | 235 | |
goetz@6458 | 236 | // R17_tos must point to last argument - element_size. |
goetz@6458 | 237 | __ addi(R17_tos, r_top_of_arguments_addr, -Interpreter::stackElementSize); |
goetz@6458 | 238 | |
goetz@6458 | 239 | // initialize call_stub locals (step 2) |
goetz@6458 | 240 | // now save R17_tos as arguments_tos_address |
goetz@6458 | 241 | __ std(R17_tos, _entry_frame_locals_neg(arguments_tos_address), r_entryframe_fp); |
goetz@6458 | 242 | |
goetz@6458 | 243 | // load argument registers for call |
goetz@6458 | 244 | __ mr(R19_method, r_arg_method); |
goetz@6458 | 245 | __ mr(R16_thread, r_arg_thread); |
goetz@6458 | 246 | assert(R17_tos != r_arg_method, "trashed r_arg_method"); |
goetz@6458 | 247 | assert(R17_tos != r_arg_thread && R19_method != r_arg_thread, "trashed r_arg_thread"); |
goetz@6458 | 248 | |
goetz@6458 | 249 | // Set R15_prev_state to 0 for simplifying checks in callee. |
goetz@6458 | 250 | __ li(R15_prev_state, 0); |
goetz@6458 | 251 | |
goetz@6458 | 252 | // Stack on entry to frame manager / native entry: |
goetz@6458 | 253 | // |
goetz@6458 | 254 | // F0 [TOP_IJAVA_FRAME_ABI] |
goetz@6458 | 255 | // alignment (optional) |
goetz@6458 | 256 | // [outgoing Java arguments] |
goetz@6458 | 257 | // [ENTRY_FRAME_LOCALS] |
goetz@6458 | 258 | // F1 [C_FRAME] |
goetz@6458 | 259 | // ... |
goetz@6458 | 260 | // |
goetz@6458 | 261 | |
goetz@6458 | 262 | // global toc register |
goetz@6458 | 263 | __ load_const(R29, MacroAssembler::global_toc(), R11_scratch1); |
goetz@6458 | 264 | |
goetz@6458 | 265 | // Load narrow oop base. |
goetz@6458 | 266 | __ reinit_heapbase(R30, R11_scratch1); |
goetz@6458 | 267 | |
goetz@6458 | 268 | // Remember the senderSP so we interpreter can pop c2i arguments off of the stack |
goetz@6458 | 269 | // when called via a c2i. |
goetz@6458 | 270 | |
goetz@6458 | 271 | // Pass initial_caller_sp to framemanager. |
goetz@6458 | 272 | __ mr(R21_tmp1, R1_SP); |
goetz@6458 | 273 | |
goetz@6458 | 274 | // Do a light-weight C-call here, r_new_arg_entry holds the address |
goetz@6458 | 275 | // of the interpreter entry point (frame manager or native entry) |
goetz@6458 | 276 | // and save runtime-value of LR in return_address. |
goetz@6458 | 277 | assert(r_new_arg_entry != R17_tos && r_new_arg_entry != R19_method && r_new_arg_entry != R16_thread, |
goetz@6458 | 278 | "trashed r_new_arg_entry"); |
goetz@6458 | 279 | return_address = __ call_stub(r_new_arg_entry); |
goetz@6458 | 280 | } |
goetz@6458 | 281 | |
goetz@6458 | 282 | { |
goetz@6458 | 283 | BLOCK_COMMENT("Returned from frame manager or native entry."); |
goetz@6458 | 284 | // Returned from frame manager or native entry. |
goetz@6458 | 285 | // Now pop frame, process result, and return to caller. |
goetz@6458 | 286 | |
goetz@6458 | 287 | // Stack on exit from frame manager / native entry: |
goetz@6458 | 288 | // |
goetz@6458 | 289 | // F0 [ABI] |
goetz@6458 | 290 | // ... |
goetz@6458 | 291 | // [ENTRY_FRAME_LOCALS] |
goetz@6458 | 292 | // F1 [C_FRAME] |
goetz@6458 | 293 | // ... |
goetz@6458 | 294 | // |
goetz@6458 | 295 | // Just pop the topmost frame ... |
goetz@6458 | 296 | // |
goetz@6458 | 297 | |
goetz@6458 | 298 | Label ret_is_object; |
goetz@6458 | 299 | Label ret_is_long; |
goetz@6458 | 300 | Label ret_is_float; |
goetz@6458 | 301 | Label ret_is_double; |
goetz@6458 | 302 | |
goetz@6458 | 303 | Register r_entryframe_fp = R30; |
goetz@6458 | 304 | Register r_lr = R7_ARG5; |
goetz@6458 | 305 | Register r_cr = R8_ARG6; |
goetz@6458 | 306 | |
goetz@6458 | 307 | // Reload some volatile registers which we've spilled before the call |
goetz@6458 | 308 | // to frame manager / native entry. |
goetz@6458 | 309 | // Access all locals via frame pointer, because we know nothing about |
goetz@6458 | 310 | // the topmost frame's size. |
goetz@6458 | 311 | __ ld(r_entryframe_fp, _abi(callers_sp), R1_SP); |
goetz@6458 | 312 | assert_different_registers(r_entryframe_fp, R3_RET, r_arg_result_addr, r_arg_result_type, r_cr, r_lr); |
goetz@6458 | 313 | __ ld(r_arg_result_addr, |
goetz@6458 | 314 | _entry_frame_locals_neg(result_address), r_entryframe_fp); |
goetz@6458 | 315 | __ ld(r_arg_result_type, |
goetz@6458 | 316 | _entry_frame_locals_neg(result_type), r_entryframe_fp); |
goetz@6458 | 317 | __ ld(r_cr, _abi(cr), r_entryframe_fp); |
goetz@6458 | 318 | __ ld(r_lr, _abi(lr), r_entryframe_fp); |
goetz@6458 | 319 | |
goetz@6458 | 320 | // pop frame and restore non-volatiles, LR and CR |
goetz@6458 | 321 | __ mr(R1_SP, r_entryframe_fp); |
goetz@6458 | 322 | __ mtcr(r_cr); |
goetz@6458 | 323 | __ mtlr(r_lr); |
goetz@6458 | 324 | |
goetz@6458 | 325 | // Store result depending on type. Everything that is not |
goetz@6458 | 326 | // T_OBJECT, T_LONG, T_FLOAT, or T_DOUBLE is treated as T_INT. |
goetz@6458 | 327 | __ cmpwi(CCR0, r_arg_result_type, T_OBJECT); |
goetz@6458 | 328 | __ cmpwi(CCR1, r_arg_result_type, T_LONG); |
goetz@6458 | 329 | __ cmpwi(CCR5, r_arg_result_type, T_FLOAT); |
goetz@6458 | 330 | __ cmpwi(CCR6, r_arg_result_type, T_DOUBLE); |
goetz@6458 | 331 | |
goetz@6458 | 332 | // restore non-volatile registers |
goetz@6458 | 333 | __ restore_nonvolatile_gprs(R1_SP, _spill_nonvolatiles_neg(r14)); |
goetz@6458 | 334 | |
goetz@6458 | 335 | |
goetz@6458 | 336 | // Stack on exit from call_stub: |
goetz@6458 | 337 | // |
goetz@6458 | 338 | // 0 [C_FRAME] |
goetz@6458 | 339 | // ... |
goetz@6458 | 340 | // |
goetz@6458 | 341 | // no call_stub frames left. |
goetz@6458 | 342 | |
goetz@6458 | 343 | // All non-volatiles have been restored at this point!! |
goetz@6458 | 344 | assert(R3_RET == R3, "R3_RET should be R3"); |
goetz@6458 | 345 | |
goetz@6458 | 346 | __ beq(CCR0, ret_is_object); |
goetz@6458 | 347 | __ beq(CCR1, ret_is_long); |
goetz@6458 | 348 | __ beq(CCR5, ret_is_float); |
goetz@6458 | 349 | __ beq(CCR6, ret_is_double); |
goetz@6458 | 350 | |
goetz@6458 | 351 | // default: |
goetz@6458 | 352 | __ stw(R3_RET, 0, r_arg_result_addr); |
goetz@6458 | 353 | __ blr(); // return to caller |
goetz@6458 | 354 | |
goetz@6458 | 355 | // case T_OBJECT: |
goetz@6458 | 356 | __ bind(ret_is_object); |
goetz@6458 | 357 | __ std(R3_RET, 0, r_arg_result_addr); |
goetz@6458 | 358 | __ blr(); // return to caller |
goetz@6458 | 359 | |
goetz@6458 | 360 | // case T_LONG: |
goetz@6458 | 361 | __ bind(ret_is_long); |
goetz@6458 | 362 | __ std(R3_RET, 0, r_arg_result_addr); |
goetz@6458 | 363 | __ blr(); // return to caller |
goetz@6458 | 364 | |
goetz@6458 | 365 | // case T_FLOAT: |
goetz@6458 | 366 | __ bind(ret_is_float); |
goetz@6458 | 367 | __ stfs(F1_RET, 0, r_arg_result_addr); |
goetz@6458 | 368 | __ blr(); // return to caller |
goetz@6458 | 369 | |
goetz@6458 | 370 | // case T_DOUBLE: |
goetz@6458 | 371 | __ bind(ret_is_double); |
goetz@6458 | 372 | __ stfd(F1_RET, 0, r_arg_result_addr); |
goetz@6458 | 373 | __ blr(); // return to caller |
goetz@6458 | 374 | } |
goetz@6458 | 375 | |
goetz@6458 | 376 | return start; |
goetz@6458 | 377 | } |
goetz@6458 | 378 | |
goetz@6458 | 379 | // Return point for a Java call if there's an exception thrown in |
goetz@6458 | 380 | // Java code. The exception is caught and transformed into a |
goetz@6458 | 381 | // pending exception stored in JavaThread that can be tested from |
goetz@6458 | 382 | // within the VM. |
goetz@6458 | 383 | // |
goetz@6458 | 384 | address generate_catch_exception() { |
goetz@6458 | 385 | StubCodeMark mark(this, "StubRoutines", "catch_exception"); |
goetz@6458 | 386 | |
goetz@6458 | 387 | address start = __ pc(); |
goetz@6458 | 388 | |
goetz@6458 | 389 | // Registers alive |
goetz@6458 | 390 | // |
goetz@6458 | 391 | // R16_thread |
goetz@6458 | 392 | // R3_ARG1 - address of pending exception |
goetz@6458 | 393 | // R4_ARG2 - return address in call stub |
goetz@6458 | 394 | |
goetz@6458 | 395 | const Register exception_file = R21_tmp1; |
goetz@6458 | 396 | const Register exception_line = R22_tmp2; |
goetz@6458 | 397 | |
goetz@6458 | 398 | __ load_const(exception_file, (void*)__FILE__); |
goetz@6458 | 399 | __ load_const(exception_line, (void*)__LINE__); |
goetz@6458 | 400 | |
goetz@6458 | 401 | __ std(R3_ARG1, thread_(pending_exception)); |
goetz@6458 | 402 | // store into `char *' |
goetz@6458 | 403 | __ std(exception_file, thread_(exception_file)); |
goetz@6458 | 404 | // store into `int' |
goetz@6458 | 405 | __ stw(exception_line, thread_(exception_line)); |
goetz@6458 | 406 | |
goetz@6458 | 407 | // complete return to VM |
goetz@6458 | 408 | assert(StubRoutines::_call_stub_return_address != NULL, "must have been generated before"); |
goetz@6458 | 409 | |
goetz@6458 | 410 | __ mtlr(R4_ARG2); |
goetz@6458 | 411 | // continue in call stub |
goetz@6458 | 412 | __ blr(); |
goetz@6458 | 413 | |
goetz@6458 | 414 | return start; |
goetz@6458 | 415 | } |
goetz@6458 | 416 | |
goetz@6458 | 417 | // Continuation point for runtime calls returning with a pending |
goetz@6458 | 418 | // exception. The pending exception check happened in the runtime |
goetz@6458 | 419 | // or native call stub. The pending exception in Thread is |
goetz@6458 | 420 | // converted into a Java-level exception. |
goetz@6458 | 421 | // |
goetz@6458 | 422 | address generate_forward_exception() { |
goetz@6458 | 423 | StubCodeMark mark(this, "StubRoutines", "forward_exception"); |
goetz@6458 | 424 | address start = __ pc(); |
goetz@6458 | 425 | |
goetz@6458 | 426 | #if !defined(PRODUCT) |
goetz@6458 | 427 | if (VerifyOops) { |
goetz@6458 | 428 | // Get pending exception oop. |
goetz@6458 | 429 | __ ld(R3_ARG1, |
goetz@6458 | 430 | in_bytes(Thread::pending_exception_offset()), |
goetz@6458 | 431 | R16_thread); |
goetz@6458 | 432 | // Make sure that this code is only executed if there is a pending exception. |
goetz@6458 | 433 | { |
goetz@6458 | 434 | Label L; |
goetz@6458 | 435 | __ cmpdi(CCR0, R3_ARG1, 0); |
goetz@6458 | 436 | __ bne(CCR0, L); |
goetz@6458 | 437 | __ stop("StubRoutines::forward exception: no pending exception (1)"); |
goetz@6458 | 438 | __ bind(L); |
goetz@6458 | 439 | } |
goetz@6458 | 440 | __ verify_oop(R3_ARG1, "StubRoutines::forward exception: not an oop"); |
goetz@6458 | 441 | } |
goetz@6458 | 442 | #endif |
goetz@6458 | 443 | |
goetz@6458 | 444 | // Save LR/CR and copy exception pc (LR) into R4_ARG2. |
goetz@6458 | 445 | __ save_LR_CR(R4_ARG2); |
goetz@6458 | 446 | __ push_frame_abi112(0, R0); |
goetz@6458 | 447 | // Find exception handler. |
goetz@6458 | 448 | __ call_VM_leaf(CAST_FROM_FN_PTR(address, |
goetz@6458 | 449 | SharedRuntime::exception_handler_for_return_address), |
goetz@6458 | 450 | R16_thread, |
goetz@6458 | 451 | R4_ARG2); |
goetz@6458 | 452 | // Copy handler's address. |
goetz@6458 | 453 | __ mtctr(R3_RET); |
goetz@6458 | 454 | __ pop_frame(); |
goetz@6458 | 455 | __ restore_LR_CR(R0); |
goetz@6458 | 456 | |
goetz@6458 | 457 | // Set up the arguments for the exception handler: |
goetz@6458 | 458 | // - R3_ARG1: exception oop |
goetz@6458 | 459 | // - R4_ARG2: exception pc. |
goetz@6458 | 460 | |
goetz@6458 | 461 | // Load pending exception oop. |
goetz@6458 | 462 | __ ld(R3_ARG1, |
goetz@6458 | 463 | in_bytes(Thread::pending_exception_offset()), |
goetz@6458 | 464 | R16_thread); |
goetz@6458 | 465 | |
goetz@6458 | 466 | // The exception pc is the return address in the caller. |
goetz@6458 | 467 | // Must load it into R4_ARG2. |
goetz@6458 | 468 | __ mflr(R4_ARG2); |
goetz@6458 | 469 | |
goetz@6458 | 470 | #ifdef ASSERT |
goetz@6458 | 471 | // Make sure exception is set. |
goetz@6458 | 472 | { |
goetz@6458 | 473 | Label L; |
goetz@6458 | 474 | __ cmpdi(CCR0, R3_ARG1, 0); |
goetz@6458 | 475 | __ bne(CCR0, L); |
goetz@6458 | 476 | __ stop("StubRoutines::forward exception: no pending exception (2)"); |
goetz@6458 | 477 | __ bind(L); |
goetz@6458 | 478 | } |
goetz@6458 | 479 | #endif |
goetz@6458 | 480 | |
goetz@6458 | 481 | // Clear the pending exception. |
goetz@6458 | 482 | __ li(R0, 0); |
goetz@6458 | 483 | __ std(R0, |
goetz@6458 | 484 | in_bytes(Thread::pending_exception_offset()), |
goetz@6458 | 485 | R16_thread); |
goetz@6458 | 486 | // Jump to exception handler. |
goetz@6458 | 487 | __ bctr(); |
goetz@6458 | 488 | |
goetz@6458 | 489 | return start; |
goetz@6458 | 490 | } |
goetz@6458 | 491 | |
goetz@6458 | 492 | #undef __ |
goetz@6458 | 493 | #define __ masm-> |
goetz@6458 | 494 | // Continuation point for throwing of implicit exceptions that are |
goetz@6458 | 495 | // not handled in the current activation. Fabricates an exception |
goetz@6458 | 496 | // oop and initiates normal exception dispatching in this |
goetz@6458 | 497 | // frame. Only callee-saved registers are preserved (through the |
goetz@6458 | 498 | // normal register window / RegisterMap handling). If the compiler |
goetz@6458 | 499 | // needs all registers to be preserved between the fault point and |
goetz@6458 | 500 | // the exception handler then it must assume responsibility for that |
goetz@6458 | 501 | // in AbstractCompiler::continuation_for_implicit_null_exception or |
goetz@6458 | 502 | // continuation_for_implicit_division_by_zero_exception. All other |
goetz@6458 | 503 | // implicit exceptions (e.g., NullPointerException or |
goetz@6458 | 504 | // AbstractMethodError on entry) are either at call sites or |
goetz@6458 | 505 | // otherwise assume that stack unwinding will be initiated, so |
goetz@6458 | 506 | // caller saved registers were assumed volatile in the compiler. |
goetz@6458 | 507 | // |
goetz@6458 | 508 | // Note that we generate only this stub into a RuntimeStub, because |
goetz@6458 | 509 | // it needs to be properly traversed and ignored during GC, so we |
goetz@6458 | 510 | // change the meaning of the "__" macro within this method. |
goetz@6458 | 511 | // |
goetz@6458 | 512 | // Note: the routine set_pc_not_at_call_for_caller in |
goetz@6458 | 513 | // SharedRuntime.cpp requires that this code be generated into a |
goetz@6458 | 514 | // RuntimeStub. |
goetz@6458 | 515 | address generate_throw_exception(const char* name, address runtime_entry, bool restore_saved_exception_pc, |
goetz@6458 | 516 | Register arg1 = noreg, Register arg2 = noreg) { |
goetz@6458 | 517 | CodeBuffer code(name, 1024 DEBUG_ONLY(+ 512), 0); |
goetz@6458 | 518 | MacroAssembler* masm = new MacroAssembler(&code); |
goetz@6458 | 519 | |
goetz@6458 | 520 | OopMapSet* oop_maps = new OopMapSet(); |
goetz@6458 | 521 | int frame_size_in_bytes = frame::abi_112_size; |
goetz@6458 | 522 | OopMap* map = new OopMap(frame_size_in_bytes / sizeof(jint), 0); |
goetz@6458 | 523 | |
goetz@6458 | 524 | StubCodeMark mark(this, "StubRoutines", "throw_exception"); |
goetz@6458 | 525 | |
goetz@6458 | 526 | address start = __ pc(); |
goetz@6458 | 527 | |
goetz@6458 | 528 | __ save_LR_CR(R11_scratch1); |
goetz@6458 | 529 | |
goetz@6458 | 530 | // Push a frame. |
goetz@6458 | 531 | __ push_frame_abi112(0, R11_scratch1); |
goetz@6458 | 532 | |
goetz@6458 | 533 | address frame_complete_pc = __ pc(); |
goetz@6458 | 534 | |
goetz@6458 | 535 | if (restore_saved_exception_pc) { |
goetz@6458 | 536 | __ unimplemented("StubGenerator::throw_exception with restore_saved_exception_pc", 74); |
goetz@6458 | 537 | } |
goetz@6458 | 538 | |
goetz@6458 | 539 | // Note that we always have a runtime stub frame on the top of |
goetz@6458 | 540 | // stack by this point. Remember the offset of the instruction |
goetz@6458 | 541 | // whose address will be moved to R11_scratch1. |
goetz@6458 | 542 | address gc_map_pc = __ get_PC_trash_LR(R11_scratch1); |
goetz@6458 | 543 | |
goetz@6458 | 544 | __ set_last_Java_frame(/*sp*/R1_SP, /*pc*/R11_scratch1); |
goetz@6458 | 545 | |
goetz@6458 | 546 | __ mr(R3_ARG1, R16_thread); |
goetz@6458 | 547 | if (arg1 != noreg) { |
goetz@6458 | 548 | __ mr(R4_ARG2, arg1); |
goetz@6458 | 549 | } |
goetz@6458 | 550 | if (arg2 != noreg) { |
goetz@6458 | 551 | __ mr(R5_ARG3, arg2); |
goetz@6458 | 552 | } |
goetz@6458 | 553 | __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, runtime_entry), |
goetz@6458 | 554 | relocInfo::none); |
goetz@6458 | 555 | |
goetz@6458 | 556 | // Set an oopmap for the call site. |
goetz@6458 | 557 | oop_maps->add_gc_map((int)(gc_map_pc - start), map); |
goetz@6458 | 558 | |
goetz@6458 | 559 | __ reset_last_Java_frame(); |
goetz@6458 | 560 | |
goetz@6458 | 561 | #ifdef ASSERT |
goetz@6458 | 562 | // Make sure that this code is only executed if there is a pending |
goetz@6458 | 563 | // exception. |
goetz@6458 | 564 | { |
goetz@6458 | 565 | Label L; |
goetz@6458 | 566 | __ ld(R0, |
goetz@6458 | 567 | in_bytes(Thread::pending_exception_offset()), |
goetz@6458 | 568 | R16_thread); |
goetz@6458 | 569 | __ cmpdi(CCR0, R0, 0); |
goetz@6458 | 570 | __ bne(CCR0, L); |
goetz@6458 | 571 | __ stop("StubRoutines::throw_exception: no pending exception"); |
goetz@6458 | 572 | __ bind(L); |
goetz@6458 | 573 | } |
goetz@6458 | 574 | #endif |
goetz@6458 | 575 | |
goetz@6458 | 576 | // Pop frame. |
goetz@6458 | 577 | __ pop_frame(); |
goetz@6458 | 578 | |
goetz@6458 | 579 | __ restore_LR_CR(R11_scratch1); |
goetz@6458 | 580 | |
goetz@6458 | 581 | __ load_const(R11_scratch1, StubRoutines::forward_exception_entry()); |
goetz@6458 | 582 | __ mtctr(R11_scratch1); |
goetz@6458 | 583 | __ bctr(); |
goetz@6458 | 584 | |
goetz@6458 | 585 | // Create runtime stub with OopMap. |
goetz@6458 | 586 | RuntimeStub* stub = |
goetz@6458 | 587 | RuntimeStub::new_runtime_stub(name, &code, |
goetz@6458 | 588 | /*frame_complete=*/ (int)(frame_complete_pc - start), |
goetz@6458 | 589 | frame_size_in_bytes/wordSize, |
goetz@6458 | 590 | oop_maps, |
goetz@6458 | 591 | false); |
goetz@6458 | 592 | return stub->entry_point(); |
goetz@6458 | 593 | } |
goetz@6458 | 594 | #undef __ |
goetz@6458 | 595 | #define __ _masm-> |
goetz@6458 | 596 | |
goetz@6458 | 597 | // Generate G1 pre-write barrier for array. |
goetz@6458 | 598 | // |
goetz@6458 | 599 | // Input: |
goetz@6458 | 600 | // from - register containing src address (only needed for spilling) |
goetz@6458 | 601 | // to - register containing starting address |
goetz@6458 | 602 | // count - register containing element count |
goetz@6458 | 603 | // tmp - scratch register |
goetz@6458 | 604 | // |
goetz@6458 | 605 | // Kills: |
goetz@6458 | 606 | // nothing |
goetz@6458 | 607 | // |
goetz@6458 | 608 | void gen_write_ref_array_pre_barrier(Register from, Register to, Register count, bool dest_uninitialized, Register Rtmp1) { |
goetz@6458 | 609 | BarrierSet* const bs = Universe::heap()->barrier_set(); |
goetz@6458 | 610 | switch (bs->kind()) { |
goetz@6458 | 611 | case BarrierSet::G1SATBCT: |
goetz@6458 | 612 | case BarrierSet::G1SATBCTLogging: |
goetz@6458 | 613 | // With G1, don't generate the call if we statically know that the target in uninitialized |
goetz@6458 | 614 | if (!dest_uninitialized) { |
goetz@6458 | 615 | const int spill_slots = 4 * wordSize; |
goetz@6458 | 616 | const int frame_size = frame::abi_112_size + spill_slots; |
goetz@6458 | 617 | |
goetz@6458 | 618 | __ save_LR_CR(R0); |
goetz@6458 | 619 | __ push_frame_abi112(spill_slots, R0); |
goetz@6458 | 620 | __ std(from, frame_size - 1 * wordSize, R1_SP); |
goetz@6458 | 621 | __ std(to, frame_size - 2 * wordSize, R1_SP); |
goetz@6458 | 622 | __ std(count, frame_size - 3 * wordSize, R1_SP); |
goetz@6458 | 623 | |
goetz@6458 | 624 | __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_pre), to, count); |
goetz@6458 | 625 | |
goetz@6458 | 626 | __ ld(from, frame_size - 1 * wordSize, R1_SP); |
goetz@6458 | 627 | __ ld(to, frame_size - 2 * wordSize, R1_SP); |
goetz@6458 | 628 | __ ld(count, frame_size - 3 * wordSize, R1_SP); |
goetz@6458 | 629 | __ pop_frame(); |
goetz@6458 | 630 | __ restore_LR_CR(R0); |
goetz@6458 | 631 | } |
goetz@6458 | 632 | break; |
goetz@6458 | 633 | case BarrierSet::CardTableModRef: |
goetz@6458 | 634 | case BarrierSet::CardTableExtension: |
goetz@6458 | 635 | case BarrierSet::ModRef: |
goetz@6458 | 636 | break; |
goetz@6458 | 637 | default: |
goetz@6458 | 638 | ShouldNotReachHere(); |
goetz@6458 | 639 | } |
goetz@6458 | 640 | } |
goetz@6458 | 641 | |
goetz@6458 | 642 | // Generate CMS/G1 post-write barrier for array. |
goetz@6458 | 643 | // |
goetz@6458 | 644 | // Input: |
goetz@6458 | 645 | // addr - register containing starting address |
goetz@6458 | 646 | // count - register containing element count |
goetz@6458 | 647 | // tmp - scratch register |
goetz@6458 | 648 | // |
goetz@6458 | 649 | // The input registers and R0 are overwritten. |
goetz@6458 | 650 | // |
goetz@6458 | 651 | void gen_write_ref_array_post_barrier(Register addr, Register count, Register tmp) { |
goetz@6458 | 652 | BarrierSet* const bs = Universe::heap()->barrier_set(); |
goetz@6458 | 653 | |
goetz@6458 | 654 | switch (bs->kind()) { |
goetz@6458 | 655 | case BarrierSet::G1SATBCT: |
goetz@6458 | 656 | case BarrierSet::G1SATBCTLogging: |
goetz@6458 | 657 | { |
goetz@6458 | 658 | __ save_LR_CR(R0); |
goetz@6458 | 659 | // We need this frame only that the callee can spill LR/CR. |
goetz@6458 | 660 | __ push_frame_abi112(0, R0); |
goetz@6458 | 661 | |
goetz@6458 | 662 | __ call_VM_leaf(CAST_FROM_FN_PTR(address, BarrierSet::static_write_ref_array_post), addr, count); |
goetz@6458 | 663 | |
goetz@6458 | 664 | __ pop_frame(); |
goetz@6458 | 665 | __ restore_LR_CR(R0); |
goetz@6458 | 666 | } |
goetz@6458 | 667 | break; |
goetz@6458 | 668 | case BarrierSet::CardTableModRef: |
goetz@6458 | 669 | case BarrierSet::CardTableExtension: |
goetz@6458 | 670 | { |
goetz@6458 | 671 | Label Lskip_loop, Lstore_loop; |
goetz@6458 | 672 | if (UseConcMarkSweepGC) { |
goetz@6458 | 673 | // TODO PPC port: contribute optimization / requires shared changes |
goetz@6458 | 674 | __ release(); |
goetz@6458 | 675 | } |
goetz@6458 | 676 | |
goetz@6458 | 677 | CardTableModRefBS* const ct = (CardTableModRefBS*)bs; |
goetz@6458 | 678 | assert(sizeof(*ct->byte_map_base) == sizeof(jbyte), "adjust this code"); |
goetz@6458 | 679 | assert_different_registers(addr, count, tmp); |
goetz@6458 | 680 | |
goetz@6458 | 681 | __ sldi(count, count, LogBytesPerHeapOop); |
goetz@6458 | 682 | __ addi(count, count, -BytesPerHeapOop); |
goetz@6458 | 683 | __ add(count, addr, count); |
goetz@6458 | 684 | // Use two shifts to clear out those low order two bits! (Cannot opt. into 1.) |
goetz@6458 | 685 | __ srdi(addr, addr, CardTableModRefBS::card_shift); |
goetz@6458 | 686 | __ srdi(count, count, CardTableModRefBS::card_shift); |
goetz@6458 | 687 | __ subf(count, addr, count); |
goetz@6458 | 688 | assert_different_registers(R0, addr, count, tmp); |
goetz@6458 | 689 | __ load_const(tmp, (address)ct->byte_map_base); |
goetz@6458 | 690 | __ addic_(count, count, 1); |
goetz@6458 | 691 | __ beq(CCR0, Lskip_loop); |
goetz@6458 | 692 | __ li(R0, 0); |
goetz@6458 | 693 | __ mtctr(count); |
goetz@6458 | 694 | // Byte store loop |
goetz@6458 | 695 | __ bind(Lstore_loop); |
goetz@6458 | 696 | __ stbx(R0, tmp, addr); |
goetz@6458 | 697 | __ addi(addr, addr, 1); |
goetz@6458 | 698 | __ bdnz(Lstore_loop); |
goetz@6458 | 699 | __ bind(Lskip_loop); |
goetz@6458 | 700 | } |
goetz@6458 | 701 | break; |
goetz@6458 | 702 | case BarrierSet::ModRef: |
goetz@6458 | 703 | break; |
goetz@6458 | 704 | default: |
goetz@6458 | 705 | ShouldNotReachHere(); |
goetz@6458 | 706 | } |
goetz@6458 | 707 | } |
goetz@6458 | 708 | |
goetz@6458 | 709 | // Support for void zero_words_aligned8(HeapWord* to, size_t count) |
goetz@6458 | 710 | // |
goetz@6458 | 711 | // Arguments: |
goetz@6458 | 712 | // to: |
goetz@6458 | 713 | // count: |
goetz@6458 | 714 | // |
goetz@6458 | 715 | // Destroys: |
goetz@6458 | 716 | // |
goetz@6458 | 717 | address generate_zero_words_aligned8() { |
goetz@6458 | 718 | StubCodeMark mark(this, "StubRoutines", "zero_words_aligned8"); |
goetz@6458 | 719 | |
goetz@6458 | 720 | // Implemented as in ClearArray. |
goetz@6458 | 721 | address start = __ emit_fd(); |
goetz@6458 | 722 | |
goetz@6458 | 723 | Register base_ptr_reg = R3_ARG1; // tohw (needs to be 8b aligned) |
goetz@6458 | 724 | Register cnt_dwords_reg = R4_ARG2; // count (in dwords) |
goetz@6458 | 725 | Register tmp1_reg = R5_ARG3; |
goetz@6458 | 726 | Register tmp2_reg = R6_ARG4; |
goetz@6458 | 727 | Register zero_reg = R7_ARG5; |
goetz@6458 | 728 | |
goetz@6458 | 729 | // Procedure for large arrays (uses data cache block zero instruction). |
goetz@6458 | 730 | Label dwloop, fast, fastloop, restloop, lastdword, done; |
goetz@6458 | 731 | int cl_size=VM_Version::get_cache_line_size(), cl_dwords=cl_size>>3, cl_dwordaddr_bits=exact_log2(cl_dwords); |
goetz@6458 | 732 | int min_dcbz=2; // Needs to be positive, apply dcbz only to at least min_dcbz cache lines. |
goetz@6458 | 733 | |
goetz@6458 | 734 | // Clear up to 128byte boundary if long enough, dword_cnt=(16-(base>>3))%16. |
goetz@6458 | 735 | __ dcbtst(base_ptr_reg); // Indicate write access to first cache line ... |
goetz@6458 | 736 | __ andi(tmp2_reg, cnt_dwords_reg, 1); // to check if number of dwords is even. |
goetz@6458 | 737 | __ srdi_(tmp1_reg, cnt_dwords_reg, 1); // number of double dwords |
goetz@6458 | 738 | __ load_const_optimized(zero_reg, 0L); // Use as zero register. |
goetz@6458 | 739 | |
goetz@6458 | 740 | __ cmpdi(CCR1, tmp2_reg, 0); // cnt_dwords even? |
goetz@6458 | 741 | __ beq(CCR0, lastdword); // size <= 1 |
goetz@6458 | 742 | __ mtctr(tmp1_reg); // Speculatively preload counter for rest loop (>0). |
goetz@6458 | 743 | __ cmpdi(CCR0, cnt_dwords_reg, (min_dcbz+1)*cl_dwords-1); // Big enough to ensure >=min_dcbz cache lines are included? |
goetz@6458 | 744 | __ neg(tmp1_reg, base_ptr_reg); // bit 0..58: bogus, bit 57..60: (16-(base>>3))%16, bit 61..63: 000 |
goetz@6458 | 745 | |
goetz@6458 | 746 | __ blt(CCR0, restloop); // Too small. (<31=(2*cl_dwords)-1 is sufficient, but bigger performs better.) |
goetz@6458 | 747 | __ rldicl_(tmp1_reg, tmp1_reg, 64-3, 64-cl_dwordaddr_bits); // Extract number of dwords to 128byte boundary=(16-(base>>3))%16. |
goetz@6458 | 748 | |
goetz@6458 | 749 | __ beq(CCR0, fast); // already 128byte aligned |
goetz@6458 | 750 | __ mtctr(tmp1_reg); // Set ctr to hit 128byte boundary (0<ctr<cnt). |
goetz@6458 | 751 | __ subf(cnt_dwords_reg, tmp1_reg, cnt_dwords_reg); // rest (>0 since size>=256-8) |
goetz@6458 | 752 | |
goetz@6458 | 753 | // Clear in first cache line dword-by-dword if not already 128byte aligned. |
goetz@6458 | 754 | __ bind(dwloop); |
goetz@6458 | 755 | __ std(zero_reg, 0, base_ptr_reg); // Clear 8byte aligned block. |
goetz@6458 | 756 | __ addi(base_ptr_reg, base_ptr_reg, 8); |
goetz@6458 | 757 | __ bdnz(dwloop); |
goetz@6458 | 758 | |
goetz@6458 | 759 | // clear 128byte blocks |
goetz@6458 | 760 | __ bind(fast); |
goetz@6458 | 761 | __ srdi(tmp1_reg, cnt_dwords_reg, cl_dwordaddr_bits); // loop count for 128byte loop (>0 since size>=256-8) |
goetz@6458 | 762 | __ andi(tmp2_reg, cnt_dwords_reg, 1); // to check if rest even |
goetz@6458 | 763 | |
goetz@6458 | 764 | __ mtctr(tmp1_reg); // load counter |
goetz@6458 | 765 | __ cmpdi(CCR1, tmp2_reg, 0); // rest even? |
goetz@6458 | 766 | __ rldicl_(tmp1_reg, cnt_dwords_reg, 63, 65-cl_dwordaddr_bits); // rest in double dwords |
goetz@6458 | 767 | |
goetz@6458 | 768 | __ bind(fastloop); |
goetz@6458 | 769 | __ dcbz(base_ptr_reg); // Clear 128byte aligned block. |
goetz@6458 | 770 | __ addi(base_ptr_reg, base_ptr_reg, cl_size); |
goetz@6458 | 771 | __ bdnz(fastloop); |
goetz@6458 | 772 | |
goetz@6458 | 773 | //__ dcbtst(base_ptr_reg); // Indicate write access to last cache line. |
goetz@6458 | 774 | __ beq(CCR0, lastdword); // rest<=1 |
goetz@6458 | 775 | __ mtctr(tmp1_reg); // load counter |
goetz@6458 | 776 | |
goetz@6458 | 777 | // Clear rest. |
goetz@6458 | 778 | __ bind(restloop); |
goetz@6458 | 779 | __ std(zero_reg, 0, base_ptr_reg); // Clear 8byte aligned block. |
goetz@6458 | 780 | __ std(zero_reg, 8, base_ptr_reg); // Clear 8byte aligned block. |
goetz@6458 | 781 | __ addi(base_ptr_reg, base_ptr_reg, 16); |
goetz@6458 | 782 | __ bdnz(restloop); |
goetz@6458 | 783 | |
goetz@6458 | 784 | __ bind(lastdword); |
goetz@6458 | 785 | __ beq(CCR1, done); |
goetz@6458 | 786 | __ std(zero_reg, 0, base_ptr_reg); |
goetz@6458 | 787 | __ bind(done); |
goetz@6458 | 788 | __ blr(); // return |
goetz@6458 | 789 | |
goetz@6458 | 790 | return start; |
goetz@6458 | 791 | } |
goetz@6458 | 792 | |
goetz@6458 | 793 | // The following routine generates a subroutine to throw an asynchronous |
goetz@6458 | 794 | // UnknownError when an unsafe access gets a fault that could not be |
goetz@6458 | 795 | // reasonably prevented by the programmer. (Example: SIGBUS/OBJERR.) |
goetz@6458 | 796 | // |
goetz@6458 | 797 | address generate_handler_for_unsafe_access() { |
goetz@6458 | 798 | StubCodeMark mark(this, "StubRoutines", "handler_for_unsafe_access"); |
goetz@6458 | 799 | address start = __ emit_fd(); |
goetz@6458 | 800 | __ unimplemented("StubRoutines::handler_for_unsafe_access", 93); |
goetz@6458 | 801 | return start; |
goetz@6458 | 802 | } |
goetz@6458 | 803 | |
goetz@6458 | 804 | #if !defined(PRODUCT) |
goetz@6458 | 805 | // Wrapper which calls oopDesc::is_oop_or_null() |
goetz@6458 | 806 | // Only called by MacroAssembler::verify_oop |
goetz@6458 | 807 | static void verify_oop_helper(const char* message, oop o) { |
goetz@6458 | 808 | if (!o->is_oop_or_null()) { |
goetz@6458 | 809 | fatal(message); |
goetz@6458 | 810 | } |
goetz@6458 | 811 | ++ StubRoutines::_verify_oop_count; |
goetz@6458 | 812 | } |
goetz@6458 | 813 | #endif |
goetz@6458 | 814 | |
goetz@6458 | 815 | // Return address of code to be called from code generated by |
goetz@6458 | 816 | // MacroAssembler::verify_oop. |
goetz@6458 | 817 | // |
goetz@6458 | 818 | // Don't generate, rather use C++ code. |
goetz@6458 | 819 | address generate_verify_oop() { |
goetz@6458 | 820 | StubCodeMark mark(this, "StubRoutines", "verify_oop"); |
goetz@6458 | 821 | |
goetz@6458 | 822 | // this is actually a `FunctionDescriptor*'. |
goetz@6458 | 823 | address start = 0; |
goetz@6458 | 824 | |
goetz@6458 | 825 | #if !defined(PRODUCT) |
goetz@6458 | 826 | start = CAST_FROM_FN_PTR(address, verify_oop_helper); |
goetz@6458 | 827 | #endif |
goetz@6458 | 828 | |
goetz@6458 | 829 | return start; |
goetz@6458 | 830 | } |
goetz@6458 | 831 | |
goetz@6458 | 832 | // Fairer handling of safepoints for native methods. |
goetz@6458 | 833 | // |
goetz@6458 | 834 | // Generate code which reads from the polling page. This special handling is needed as the |
goetz@6458 | 835 | // linux-ppc64 kernel before 2.6.6 doesn't set si_addr on some segfaults in 64bit mode |
goetz@6458 | 836 | // (cf. http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.6), especially when we try |
goetz@6458 | 837 | // to read from the safepoint polling page. |
goetz@6458 | 838 | address generate_load_from_poll() { |
goetz@6458 | 839 | StubCodeMark mark(this, "StubRoutines", "generate_load_from_poll"); |
goetz@6458 | 840 | address start = __ emit_fd(); |
goetz@6458 | 841 | __ unimplemented("StubRoutines::verify_oop", 95); // TODO PPC port |
goetz@6458 | 842 | return start; |
goetz@6458 | 843 | } |
goetz@6458 | 844 | |
goetz@6458 | 845 | // -XX:+OptimizeFill : convert fill/copy loops into intrinsic |
goetz@6458 | 846 | // |
goetz@6458 | 847 | // The code is implemented(ported from sparc) as we believe it benefits JVM98, however |
goetz@6458 | 848 | // tracing(-XX:+TraceOptimizeFill) shows the intrinsic replacement doesn't happen at all! |
goetz@6458 | 849 | // |
goetz@6458 | 850 | // Source code in function is_range_check_if() shows OptimizeFill relaxed the condition |
goetz@6458 | 851 | // for turning on loop predication optimization, and hence the behavior of "array range check" |
goetz@6458 | 852 | // and "loop invariant check" could be influenced, which potentially boosted JVM98. |
goetz@6458 | 853 | // |
goetz@6458 | 854 | // We leave the code here and see if Oracle has updates in later releases(later than HS20). |
goetz@6458 | 855 | // |
goetz@6458 | 856 | // Generate stub for disjoint short fill. If "aligned" is true, the |
goetz@6458 | 857 | // "to" address is assumed to be heapword aligned. |
goetz@6458 | 858 | // |
goetz@6458 | 859 | // Arguments for generated stub: |
goetz@6458 | 860 | // to: R3_ARG1 |
goetz@6458 | 861 | // value: R4_ARG2 |
goetz@6458 | 862 | // count: R5_ARG3 treated as signed |
goetz@6458 | 863 | // |
goetz@6458 | 864 | address generate_fill(BasicType t, bool aligned, const char* name) { |
goetz@6458 | 865 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 866 | address start = __ emit_fd(); |
goetz@6458 | 867 | |
goetz@6458 | 868 | const Register to = R3_ARG1; // source array address |
goetz@6458 | 869 | const Register value = R4_ARG2; // fill value |
goetz@6458 | 870 | const Register count = R5_ARG3; // elements count |
goetz@6458 | 871 | const Register temp = R6_ARG4; // temp register |
goetz@6458 | 872 | |
goetz@6458 | 873 | //assert_clean_int(count, O3); // Make sure 'count' is clean int. |
goetz@6458 | 874 | |
goetz@6458 | 875 | Label L_exit, L_skip_align1, L_skip_align2, L_fill_byte; |
goetz@6458 | 876 | Label L_fill_2_bytes, L_fill_4_bytes, L_fill_elements, L_fill_32_bytes; |
goetz@6458 | 877 | |
goetz@6458 | 878 | int shift = -1; |
goetz@6458 | 879 | switch (t) { |
goetz@6458 | 880 | case T_BYTE: |
goetz@6458 | 881 | shift = 2; |
goetz@6458 | 882 | // clone bytes (zero extend not needed because store instructions below ignore high order bytes) |
goetz@6458 | 883 | __ rldimi(value, value, 8, 48); // 8 bit -> 16 bit |
goetz@6458 | 884 | __ cmpdi(CCR0, count, 2<<shift); // Short arrays (< 8 bytes) fill by element |
goetz@6458 | 885 | __ blt(CCR0, L_fill_elements); |
goetz@6458 | 886 | __ rldimi(value, value, 16, 32); // 16 bit -> 32 bit |
goetz@6458 | 887 | break; |
goetz@6458 | 888 | case T_SHORT: |
goetz@6458 | 889 | shift = 1; |
goetz@6458 | 890 | // clone bytes (zero extend not needed because store instructions below ignore high order bytes) |
goetz@6458 | 891 | __ rldimi(value, value, 16, 32); // 16 bit -> 32 bit |
goetz@6458 | 892 | __ cmpdi(CCR0, count, 2<<shift); // Short arrays (< 8 bytes) fill by element |
goetz@6458 | 893 | __ blt(CCR0, L_fill_elements); |
goetz@6458 | 894 | break; |
goetz@6458 | 895 | case T_INT: |
goetz@6458 | 896 | shift = 0; |
goetz@6458 | 897 | __ cmpdi(CCR0, count, 2<<shift); // Short arrays (< 8 bytes) fill by element |
goetz@6458 | 898 | __ blt(CCR0, L_fill_4_bytes); |
goetz@6458 | 899 | break; |
goetz@6458 | 900 | default: ShouldNotReachHere(); |
goetz@6458 | 901 | } |
goetz@6458 | 902 | |
goetz@6458 | 903 | if (!aligned && (t == T_BYTE || t == T_SHORT)) { |
goetz@6458 | 904 | // align source address at 4 bytes address boundary |
goetz@6458 | 905 | if (t == T_BYTE) { |
goetz@6458 | 906 | // One byte misalignment happens only for byte arrays |
goetz@6458 | 907 | __ andi_(temp, to, 1); |
goetz@6458 | 908 | __ beq(CCR0, L_skip_align1); |
goetz@6458 | 909 | __ stb(value, 0, to); |
goetz@6458 | 910 | __ addi(to, to, 1); |
goetz@6458 | 911 | __ addi(count, count, -1); |
goetz@6458 | 912 | __ bind(L_skip_align1); |
goetz@6458 | 913 | } |
goetz@6458 | 914 | // Two bytes misalignment happens only for byte and short (char) arrays. |
goetz@6458 | 915 | __ andi_(temp, to, 2); |
goetz@6458 | 916 | __ beq(CCR0, L_skip_align2); |
goetz@6458 | 917 | __ sth(value, 0, to); |
goetz@6458 | 918 | __ addi(to, to, 2); |
goetz@6458 | 919 | __ addi(count, count, -(1 << (shift - 1))); |
goetz@6458 | 920 | __ bind(L_skip_align2); |
goetz@6458 | 921 | } |
goetz@6458 | 922 | |
goetz@6458 | 923 | if (!aligned) { |
goetz@6458 | 924 | // Align to 8 bytes, we know we are 4 byte aligned to start. |
goetz@6458 | 925 | __ andi_(temp, to, 7); |
goetz@6458 | 926 | __ beq(CCR0, L_fill_32_bytes); |
goetz@6458 | 927 | __ stw(value, 0, to); |
goetz@6458 | 928 | __ addi(to, to, 4); |
goetz@6458 | 929 | __ addi(count, count, -(1 << shift)); |
goetz@6458 | 930 | __ bind(L_fill_32_bytes); |
goetz@6458 | 931 | } |
goetz@6458 | 932 | |
goetz@6458 | 933 | __ li(temp, 8<<shift); // prepare for 32 byte loop |
goetz@6458 | 934 | // clone bytes int->long as above |
goetz@6458 | 935 | __ rldimi(value, value, 32, 0); // 32 bit -> 64 bit |
goetz@6458 | 936 | |
goetz@6458 | 937 | Label L_check_fill_8_bytes; |
goetz@6458 | 938 | // Fill 32-byte chunks |
goetz@6458 | 939 | __ subf_(count, temp, count); |
goetz@6458 | 940 | __ blt(CCR0, L_check_fill_8_bytes); |
goetz@6458 | 941 | |
goetz@6458 | 942 | Label L_fill_32_bytes_loop; |
goetz@6458 | 943 | __ align(32); |
goetz@6458 | 944 | __ bind(L_fill_32_bytes_loop); |
goetz@6458 | 945 | |
goetz@6458 | 946 | __ std(value, 0, to); |
goetz@6458 | 947 | __ std(value, 8, to); |
goetz@6458 | 948 | __ subf_(count, temp, count); // update count |
goetz@6458 | 949 | __ std(value, 16, to); |
goetz@6458 | 950 | __ std(value, 24, to); |
goetz@6458 | 951 | |
goetz@6458 | 952 | __ addi(to, to, 32); |
goetz@6458 | 953 | __ bge(CCR0, L_fill_32_bytes_loop); |
goetz@6458 | 954 | |
goetz@6458 | 955 | __ bind(L_check_fill_8_bytes); |
goetz@6458 | 956 | __ add_(count, temp, count); |
goetz@6458 | 957 | __ beq(CCR0, L_exit); |
goetz@6458 | 958 | __ addic_(count, count, -(2 << shift)); |
goetz@6458 | 959 | __ blt(CCR0, L_fill_4_bytes); |
goetz@6458 | 960 | |
goetz@6458 | 961 | // |
goetz@6458 | 962 | // Length is too short, just fill 8 bytes at a time. |
goetz@6458 | 963 | // |
goetz@6458 | 964 | Label L_fill_8_bytes_loop; |
goetz@6458 | 965 | __ bind(L_fill_8_bytes_loop); |
goetz@6458 | 966 | __ std(value, 0, to); |
goetz@6458 | 967 | __ addic_(count, count, -(2 << shift)); |
goetz@6458 | 968 | __ addi(to, to, 8); |
goetz@6458 | 969 | __ bge(CCR0, L_fill_8_bytes_loop); |
goetz@6458 | 970 | |
goetz@6458 | 971 | // fill trailing 4 bytes |
goetz@6458 | 972 | __ bind(L_fill_4_bytes); |
goetz@6458 | 973 | __ andi_(temp, count, 1<<shift); |
goetz@6458 | 974 | __ beq(CCR0, L_fill_2_bytes); |
goetz@6458 | 975 | |
goetz@6458 | 976 | __ stw(value, 0, to); |
goetz@6458 | 977 | if (t == T_BYTE || t == T_SHORT) { |
goetz@6458 | 978 | __ addi(to, to, 4); |
goetz@6458 | 979 | // fill trailing 2 bytes |
goetz@6458 | 980 | __ bind(L_fill_2_bytes); |
goetz@6458 | 981 | __ andi_(temp, count, 1<<(shift-1)); |
goetz@6458 | 982 | __ beq(CCR0, L_fill_byte); |
goetz@6458 | 983 | __ sth(value, 0, to); |
goetz@6458 | 984 | if (t == T_BYTE) { |
goetz@6458 | 985 | __ addi(to, to, 2); |
goetz@6458 | 986 | // fill trailing byte |
goetz@6458 | 987 | __ bind(L_fill_byte); |
goetz@6458 | 988 | __ andi_(count, count, 1); |
goetz@6458 | 989 | __ beq(CCR0, L_exit); |
goetz@6458 | 990 | __ stb(value, 0, to); |
goetz@6458 | 991 | } else { |
goetz@6458 | 992 | __ bind(L_fill_byte); |
goetz@6458 | 993 | } |
goetz@6458 | 994 | } else { |
goetz@6458 | 995 | __ bind(L_fill_2_bytes); |
goetz@6458 | 996 | } |
goetz@6458 | 997 | __ bind(L_exit); |
goetz@6458 | 998 | __ blr(); |
goetz@6458 | 999 | |
goetz@6458 | 1000 | // Handle copies less than 8 bytes. Int is handled elsewhere. |
goetz@6458 | 1001 | if (t == T_BYTE) { |
goetz@6458 | 1002 | __ bind(L_fill_elements); |
goetz@6458 | 1003 | Label L_fill_2, L_fill_4; |
goetz@6458 | 1004 | __ andi_(temp, count, 1); |
goetz@6458 | 1005 | __ beq(CCR0, L_fill_2); |
goetz@6458 | 1006 | __ stb(value, 0, to); |
goetz@6458 | 1007 | __ addi(to, to, 1); |
goetz@6458 | 1008 | __ bind(L_fill_2); |
goetz@6458 | 1009 | __ andi_(temp, count, 2); |
goetz@6458 | 1010 | __ beq(CCR0, L_fill_4); |
goetz@6458 | 1011 | __ stb(value, 0, to); |
goetz@6458 | 1012 | __ stb(value, 0, to); |
goetz@6458 | 1013 | __ addi(to, to, 2); |
goetz@6458 | 1014 | __ bind(L_fill_4); |
goetz@6458 | 1015 | __ andi_(temp, count, 4); |
goetz@6458 | 1016 | __ beq(CCR0, L_exit); |
goetz@6458 | 1017 | __ stb(value, 0, to); |
goetz@6458 | 1018 | __ stb(value, 1, to); |
goetz@6458 | 1019 | __ stb(value, 2, to); |
goetz@6458 | 1020 | __ stb(value, 3, to); |
goetz@6458 | 1021 | __ blr(); |
goetz@6458 | 1022 | } |
goetz@6458 | 1023 | |
goetz@6458 | 1024 | if (t == T_SHORT) { |
goetz@6458 | 1025 | Label L_fill_2; |
goetz@6458 | 1026 | __ bind(L_fill_elements); |
goetz@6458 | 1027 | __ andi_(temp, count, 1); |
goetz@6458 | 1028 | __ beq(CCR0, L_fill_2); |
goetz@6458 | 1029 | __ sth(value, 0, to); |
goetz@6458 | 1030 | __ addi(to, to, 2); |
goetz@6458 | 1031 | __ bind(L_fill_2); |
goetz@6458 | 1032 | __ andi_(temp, count, 2); |
goetz@6458 | 1033 | __ beq(CCR0, L_exit); |
goetz@6458 | 1034 | __ sth(value, 0, to); |
goetz@6458 | 1035 | __ sth(value, 2, to); |
goetz@6458 | 1036 | __ blr(); |
goetz@6458 | 1037 | } |
goetz@6458 | 1038 | return start; |
goetz@6458 | 1039 | } |
goetz@6458 | 1040 | |
goetz@6458 | 1041 | |
goetz@6458 | 1042 | // Generate overlap test for array copy stubs |
goetz@6458 | 1043 | // |
goetz@6458 | 1044 | // Input: |
goetz@6458 | 1045 | // R3_ARG1 - from |
goetz@6458 | 1046 | // R4_ARG2 - to |
goetz@6458 | 1047 | // R5_ARG3 - element count |
goetz@6458 | 1048 | // |
goetz@6458 | 1049 | void array_overlap_test(address no_overlap_target, int log2_elem_size) { |
goetz@6458 | 1050 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1051 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1052 | |
goetz@6458 | 1053 | Label l_overlap; |
goetz@6458 | 1054 | #ifdef ASSERT |
goetz@6458 | 1055 | __ srdi_(tmp2, R5_ARG3, 31); |
goetz@6458 | 1056 | __ asm_assert_eq("missing zero extend", 0xAFFE); |
goetz@6458 | 1057 | #endif |
goetz@6458 | 1058 | |
goetz@6458 | 1059 | __ subf(tmp1, R3_ARG1, R4_ARG2); // distance in bytes |
goetz@6458 | 1060 | __ sldi(tmp2, R5_ARG3, log2_elem_size); // size in bytes |
goetz@6458 | 1061 | __ cmpld(CCR0, R3_ARG1, R4_ARG2); // Use unsigned comparison! |
goetz@6458 | 1062 | __ cmpld(CCR1, tmp1, tmp2); |
goetz@6458 | 1063 | __ crand(/*CCR0 lt*/0, /*CCR1 lt*/4+0, /*CCR0 lt*/0); |
goetz@6458 | 1064 | __ blt(CCR0, l_overlap); // Src before dst and distance smaller than size. |
goetz@6458 | 1065 | |
goetz@6458 | 1066 | // need to copy forwards |
goetz@6458 | 1067 | if (__ is_within_range_of_b(no_overlap_target, __ pc())) { |
goetz@6458 | 1068 | __ b(no_overlap_target); |
goetz@6458 | 1069 | } else { |
goetz@6458 | 1070 | __ load_const(tmp1, no_overlap_target, tmp2); |
goetz@6458 | 1071 | __ mtctr(tmp1); |
goetz@6458 | 1072 | __ bctr(); |
goetz@6458 | 1073 | } |
goetz@6458 | 1074 | |
goetz@6458 | 1075 | __ bind(l_overlap); |
goetz@6458 | 1076 | // need to copy backwards |
goetz@6458 | 1077 | } |
goetz@6458 | 1078 | |
goetz@6458 | 1079 | // The guideline in the implementations of generate_disjoint_xxx_copy |
goetz@6458 | 1080 | // (xxx=byte,short,int,long,oop) is to copy as many elements as possible with |
goetz@6458 | 1081 | // single instructions, but to avoid alignment interrupts (see subsequent |
goetz@6458 | 1082 | // comment). Furthermore, we try to minimize misaligned access, even |
goetz@6458 | 1083 | // though they cause no alignment interrupt. |
goetz@6458 | 1084 | // |
goetz@6458 | 1085 | // In Big-Endian mode, the PowerPC architecture requires implementations to |
goetz@6458 | 1086 | // handle automatically misaligned integer halfword and word accesses, |
goetz@6458 | 1087 | // word-aligned integer doubleword accesses, and word-aligned floating-point |
goetz@6458 | 1088 | // accesses. Other accesses may or may not generate an Alignment interrupt |
goetz@6458 | 1089 | // depending on the implementation. |
goetz@6458 | 1090 | // Alignment interrupt handling may require on the order of hundreds of cycles, |
goetz@6458 | 1091 | // so every effort should be made to avoid misaligned memory values. |
goetz@6458 | 1092 | // |
goetz@6458 | 1093 | // |
goetz@6458 | 1094 | // Generate stub for disjoint byte copy. If "aligned" is true, the |
goetz@6458 | 1095 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1096 | // |
goetz@6458 | 1097 | // Arguments for generated stub: |
goetz@6458 | 1098 | // from: R3_ARG1 |
goetz@6458 | 1099 | // to: R4_ARG2 |
goetz@6458 | 1100 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1101 | // |
goetz@6458 | 1102 | address generate_disjoint_byte_copy(bool aligned, const char * name) { |
goetz@6458 | 1103 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1104 | address start = __ emit_fd(); |
goetz@6458 | 1105 | |
goetz@6458 | 1106 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1107 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1108 | Register tmp3 = R8_ARG6; |
goetz@6458 | 1109 | Register tmp4 = R9_ARG7; |
goetz@6458 | 1110 | |
goetz@6458 | 1111 | |
goetz@6458 | 1112 | Label l_1, l_2, l_3, l_4, l_5, l_6, l_7, l_8, l_9; |
goetz@6458 | 1113 | // Don't try anything fancy if arrays don't have many elements. |
goetz@6458 | 1114 | __ li(tmp3, 0); |
goetz@6458 | 1115 | __ cmpwi(CCR0, R5_ARG3, 17); |
goetz@6458 | 1116 | __ ble(CCR0, l_6); // copy 4 at a time |
goetz@6458 | 1117 | |
goetz@6458 | 1118 | if (!aligned) { |
goetz@6458 | 1119 | __ xorr(tmp1, R3_ARG1, R4_ARG2); |
goetz@6458 | 1120 | __ andi_(tmp1, tmp1, 3); |
goetz@6458 | 1121 | __ bne(CCR0, l_6); // If arrays don't have the same alignment mod 4, do 4 element copy. |
goetz@6458 | 1122 | |
goetz@6458 | 1123 | // Copy elements if necessary to align to 4 bytes. |
goetz@6458 | 1124 | __ neg(tmp1, R3_ARG1); // Compute distance to alignment boundary. |
goetz@6458 | 1125 | __ andi_(tmp1, tmp1, 3); |
goetz@6458 | 1126 | __ beq(CCR0, l_2); |
goetz@6458 | 1127 | |
goetz@6458 | 1128 | __ subf(R5_ARG3, tmp1, R5_ARG3); |
goetz@6458 | 1129 | __ bind(l_9); |
goetz@6458 | 1130 | __ lbz(tmp2, 0, R3_ARG1); |
goetz@6458 | 1131 | __ addic_(tmp1, tmp1, -1); |
goetz@6458 | 1132 | __ stb(tmp2, 0, R4_ARG2); |
goetz@6458 | 1133 | __ addi(R3_ARG1, R3_ARG1, 1); |
goetz@6458 | 1134 | __ addi(R4_ARG2, R4_ARG2, 1); |
goetz@6458 | 1135 | __ bne(CCR0, l_9); |
goetz@6458 | 1136 | |
goetz@6458 | 1137 | __ bind(l_2); |
goetz@6458 | 1138 | } |
goetz@6458 | 1139 | |
goetz@6458 | 1140 | // copy 8 elements at a time |
goetz@6458 | 1141 | __ xorr(tmp2, R3_ARG1, R4_ARG2); // skip if src & dest have differing alignment mod 8 |
goetz@6458 | 1142 | __ andi_(tmp1, tmp2, 7); |
goetz@6458 | 1143 | __ bne(CCR0, l_7); // not same alignment -> to or from is aligned -> copy 8 |
goetz@6458 | 1144 | |
goetz@6458 | 1145 | // copy a 2-element word if necessary to align to 8 bytes |
goetz@6458 | 1146 | __ andi_(R0, R3_ARG1, 7); |
goetz@6458 | 1147 | __ beq(CCR0, l_7); |
goetz@6458 | 1148 | |
goetz@6458 | 1149 | __ lwzx(tmp2, R3_ARG1, tmp3); |
goetz@6458 | 1150 | __ addi(R5_ARG3, R5_ARG3, -4); |
goetz@6458 | 1151 | __ stwx(tmp2, R4_ARG2, tmp3); |
goetz@6458 | 1152 | { // FasterArrayCopy |
goetz@6458 | 1153 | __ addi(R3_ARG1, R3_ARG1, 4); |
goetz@6458 | 1154 | __ addi(R4_ARG2, R4_ARG2, 4); |
goetz@6458 | 1155 | } |
goetz@6458 | 1156 | __ bind(l_7); |
goetz@6458 | 1157 | |
goetz@6458 | 1158 | { // FasterArrayCopy |
goetz@6458 | 1159 | __ cmpwi(CCR0, R5_ARG3, 31); |
goetz@6458 | 1160 | __ ble(CCR0, l_6); // copy 2 at a time if less than 32 elements remain |
goetz@6458 | 1161 | |
goetz@6458 | 1162 | __ srdi(tmp1, R5_ARG3, 5); |
goetz@6458 | 1163 | __ andi_(R5_ARG3, R5_ARG3, 31); |
goetz@6458 | 1164 | __ mtctr(tmp1); |
goetz@6458 | 1165 | |
goetz@6458 | 1166 | __ bind(l_8); |
goetz@6458 | 1167 | // Use unrolled version for mass copying (copy 32 elements a time) |
goetz@6458 | 1168 | // Load feeding store gets zero latency on Power6, however not on Power5. |
goetz@6458 | 1169 | // Therefore, the following sequence is made for the good of both. |
goetz@6458 | 1170 | __ ld(tmp1, 0, R3_ARG1); |
goetz@6458 | 1171 | __ ld(tmp2, 8, R3_ARG1); |
goetz@6458 | 1172 | __ ld(tmp3, 16, R3_ARG1); |
goetz@6458 | 1173 | __ ld(tmp4, 24, R3_ARG1); |
goetz@6458 | 1174 | __ std(tmp1, 0, R4_ARG2); |
goetz@6458 | 1175 | __ std(tmp2, 8, R4_ARG2); |
goetz@6458 | 1176 | __ std(tmp3, 16, R4_ARG2); |
goetz@6458 | 1177 | __ std(tmp4, 24, R4_ARG2); |
goetz@6458 | 1178 | __ addi(R3_ARG1, R3_ARG1, 32); |
goetz@6458 | 1179 | __ addi(R4_ARG2, R4_ARG2, 32); |
goetz@6458 | 1180 | __ bdnz(l_8); |
goetz@6458 | 1181 | } |
goetz@6458 | 1182 | |
goetz@6458 | 1183 | __ bind(l_6); |
goetz@6458 | 1184 | |
goetz@6458 | 1185 | // copy 4 elements at a time |
goetz@6458 | 1186 | __ cmpwi(CCR0, R5_ARG3, 4); |
goetz@6458 | 1187 | __ blt(CCR0, l_1); |
goetz@6458 | 1188 | __ srdi(tmp1, R5_ARG3, 2); |
goetz@6458 | 1189 | __ mtctr(tmp1); // is > 0 |
goetz@6458 | 1190 | __ andi_(R5_ARG3, R5_ARG3, 3); |
goetz@6458 | 1191 | |
goetz@6458 | 1192 | { // FasterArrayCopy |
goetz@6458 | 1193 | __ addi(R3_ARG1, R3_ARG1, -4); |
goetz@6458 | 1194 | __ addi(R4_ARG2, R4_ARG2, -4); |
goetz@6458 | 1195 | __ bind(l_3); |
goetz@6458 | 1196 | __ lwzu(tmp2, 4, R3_ARG1); |
goetz@6458 | 1197 | __ stwu(tmp2, 4, R4_ARG2); |
goetz@6458 | 1198 | __ bdnz(l_3); |
goetz@6458 | 1199 | __ addi(R3_ARG1, R3_ARG1, 4); |
goetz@6458 | 1200 | __ addi(R4_ARG2, R4_ARG2, 4); |
goetz@6458 | 1201 | } |
goetz@6458 | 1202 | |
goetz@6458 | 1203 | // do single element copy |
goetz@6458 | 1204 | __ bind(l_1); |
goetz@6458 | 1205 | __ cmpwi(CCR0, R5_ARG3, 0); |
goetz@6458 | 1206 | __ beq(CCR0, l_4); |
goetz@6458 | 1207 | |
goetz@6458 | 1208 | { // FasterArrayCopy |
goetz@6458 | 1209 | __ mtctr(R5_ARG3); |
goetz@6458 | 1210 | __ addi(R3_ARG1, R3_ARG1, -1); |
goetz@6458 | 1211 | __ addi(R4_ARG2, R4_ARG2, -1); |
goetz@6458 | 1212 | |
goetz@6458 | 1213 | __ bind(l_5); |
goetz@6458 | 1214 | __ lbzu(tmp2, 1, R3_ARG1); |
goetz@6458 | 1215 | __ stbu(tmp2, 1, R4_ARG2); |
goetz@6458 | 1216 | __ bdnz(l_5); |
goetz@6458 | 1217 | } |
goetz@6458 | 1218 | |
goetz@6458 | 1219 | __ bind(l_4); |
goetz@6458 | 1220 | __ blr(); |
goetz@6458 | 1221 | |
goetz@6458 | 1222 | return start; |
goetz@6458 | 1223 | } |
goetz@6458 | 1224 | |
goetz@6458 | 1225 | // Generate stub for conjoint byte copy. If "aligned" is true, the |
goetz@6458 | 1226 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1227 | // |
goetz@6458 | 1228 | // Arguments for generated stub: |
goetz@6458 | 1229 | // from: R3_ARG1 |
goetz@6458 | 1230 | // to: R4_ARG2 |
goetz@6458 | 1231 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1232 | // |
goetz@6458 | 1233 | address generate_conjoint_byte_copy(bool aligned, const char * name) { |
goetz@6458 | 1234 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1235 | address start = __ emit_fd(); |
goetz@6458 | 1236 | |
goetz@6458 | 1237 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1238 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1239 | Register tmp3 = R8_ARG6; |
goetz@6458 | 1240 | |
goetz@6458 | 1241 | address nooverlap_target = aligned ? |
goetz@6458 | 1242 | ((FunctionDescriptor*)StubRoutines::arrayof_jbyte_disjoint_arraycopy())->entry() : |
goetz@6458 | 1243 | ((FunctionDescriptor*)StubRoutines::jbyte_disjoint_arraycopy())->entry(); |
goetz@6458 | 1244 | |
goetz@6458 | 1245 | array_overlap_test(nooverlap_target, 0); |
goetz@6458 | 1246 | // Do reverse copy. We assume the case of actual overlap is rare enough |
goetz@6458 | 1247 | // that we don't have to optimize it. |
goetz@6458 | 1248 | Label l_1, l_2; |
goetz@6458 | 1249 | |
goetz@6458 | 1250 | __ b(l_2); |
goetz@6458 | 1251 | __ bind(l_1); |
goetz@6458 | 1252 | __ stbx(tmp1, R4_ARG2, R5_ARG3); |
goetz@6458 | 1253 | __ bind(l_2); |
goetz@6458 | 1254 | __ addic_(R5_ARG3, R5_ARG3, -1); |
goetz@6458 | 1255 | __ lbzx(tmp1, R3_ARG1, R5_ARG3); |
goetz@6458 | 1256 | __ bge(CCR0, l_1); |
goetz@6458 | 1257 | |
goetz@6458 | 1258 | __ blr(); |
goetz@6458 | 1259 | |
goetz@6458 | 1260 | return start; |
goetz@6458 | 1261 | } |
goetz@6458 | 1262 | |
goetz@6458 | 1263 | // Generate stub for disjoint short copy. If "aligned" is true, the |
goetz@6458 | 1264 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1265 | // |
goetz@6458 | 1266 | // Arguments for generated stub: |
goetz@6458 | 1267 | // from: R3_ARG1 |
goetz@6458 | 1268 | // to: R4_ARG2 |
goetz@6458 | 1269 | // elm.count: R5_ARG3 treated as signed |
goetz@6458 | 1270 | // |
goetz@6458 | 1271 | // Strategy for aligned==true: |
goetz@6458 | 1272 | // |
goetz@6458 | 1273 | // If length <= 9: |
goetz@6458 | 1274 | // 1. copy 2 elements at a time (l_6) |
goetz@6458 | 1275 | // 2. copy last element if original element count was odd (l_1) |
goetz@6458 | 1276 | // |
goetz@6458 | 1277 | // If length > 9: |
goetz@6458 | 1278 | // 1. copy 4 elements at a time until less than 4 elements are left (l_7) |
goetz@6458 | 1279 | // 2. copy 2 elements at a time until less than 2 elements are left (l_6) |
goetz@6458 | 1280 | // 3. copy last element if one was left in step 2. (l_1) |
goetz@6458 | 1281 | // |
goetz@6458 | 1282 | // |
goetz@6458 | 1283 | // Strategy for aligned==false: |
goetz@6458 | 1284 | // |
goetz@6458 | 1285 | // If length <= 9: same as aligned==true case, but NOTE: load/stores |
goetz@6458 | 1286 | // can be unaligned (see comment below) |
goetz@6458 | 1287 | // |
goetz@6458 | 1288 | // If length > 9: |
goetz@6458 | 1289 | // 1. continue with step 6. if the alignment of from and to mod 4 |
goetz@6458 | 1290 | // is different. |
goetz@6458 | 1291 | // 2. align from and to to 4 bytes by copying 1 element if necessary |
goetz@6458 | 1292 | // 3. at l_2 from and to are 4 byte aligned; continue with |
goetz@6458 | 1293 | // 5. if they cannot be aligned to 8 bytes because they have |
goetz@6458 | 1294 | // got different alignment mod 8. |
goetz@6458 | 1295 | // 4. at this point we know that both, from and to, have the same |
goetz@6458 | 1296 | // alignment mod 8, now copy one element if necessary to get |
goetz@6458 | 1297 | // 8 byte alignment of from and to. |
goetz@6458 | 1298 | // 5. copy 4 elements at a time until less than 4 elements are |
goetz@6458 | 1299 | // left; depending on step 3. all load/stores are aligned or |
goetz@6458 | 1300 | // either all loads or all stores are unaligned. |
goetz@6458 | 1301 | // 6. copy 2 elements at a time until less than 2 elements are |
goetz@6458 | 1302 | // left (l_6); arriving here from step 1., there is a chance |
goetz@6458 | 1303 | // that all accesses are unaligned. |
goetz@6458 | 1304 | // 7. copy last element if one was left in step 6. (l_1) |
goetz@6458 | 1305 | // |
goetz@6458 | 1306 | // There are unaligned data accesses using integer load/store |
goetz@6458 | 1307 | // instructions in this stub. POWER allows such accesses. |
goetz@6458 | 1308 | // |
goetz@6458 | 1309 | // According to the manuals (PowerISA_V2.06_PUBLIC, Book II, |
goetz@6458 | 1310 | // Chapter 2: Effect of Operand Placement on Performance) unaligned |
goetz@6458 | 1311 | // integer load/stores have good performance. Only unaligned |
goetz@6458 | 1312 | // floating point load/stores can have poor performance. |
goetz@6458 | 1313 | // |
goetz@6458 | 1314 | // TODO: |
goetz@6458 | 1315 | // |
goetz@6458 | 1316 | // 1. check if aligning the backbranch target of loops is beneficial |
goetz@6458 | 1317 | // |
goetz@6458 | 1318 | address generate_disjoint_short_copy(bool aligned, const char * name) { |
goetz@6458 | 1319 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1320 | |
goetz@6458 | 1321 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1322 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1323 | Register tmp3 = R8_ARG6; |
goetz@6458 | 1324 | Register tmp4 = R9_ARG7; |
goetz@6458 | 1325 | |
goetz@6458 | 1326 | address start = __ emit_fd(); |
goetz@6458 | 1327 | |
goetz@6458 | 1328 | Label l_1, l_2, l_3, l_4, l_5, l_6, l_7, l_8; |
goetz@6458 | 1329 | // don't try anything fancy if arrays don't have many elements |
goetz@6458 | 1330 | __ li(tmp3, 0); |
goetz@6458 | 1331 | __ cmpwi(CCR0, R5_ARG3, 9); |
goetz@6458 | 1332 | __ ble(CCR0, l_6); // copy 2 at a time |
goetz@6458 | 1333 | |
goetz@6458 | 1334 | if (!aligned) { |
goetz@6458 | 1335 | __ xorr(tmp1, R3_ARG1, R4_ARG2); |
goetz@6458 | 1336 | __ andi_(tmp1, tmp1, 3); |
goetz@6458 | 1337 | __ bne(CCR0, l_6); // if arrays don't have the same alignment mod 4, do 2 element copy |
goetz@6458 | 1338 | |
goetz@6458 | 1339 | // At this point it is guaranteed that both, from and to have the same alignment mod 4. |
goetz@6458 | 1340 | |
goetz@6458 | 1341 | // Copy 1 element if necessary to align to 4 bytes. |
goetz@6458 | 1342 | __ andi_(tmp1, R3_ARG1, 3); |
goetz@6458 | 1343 | __ beq(CCR0, l_2); |
goetz@6458 | 1344 | |
goetz@6458 | 1345 | __ lhz(tmp2, 0, R3_ARG1); |
goetz@6458 | 1346 | __ addi(R3_ARG1, R3_ARG1, 2); |
goetz@6458 | 1347 | __ sth(tmp2, 0, R4_ARG2); |
goetz@6458 | 1348 | __ addi(R4_ARG2, R4_ARG2, 2); |
goetz@6458 | 1349 | __ addi(R5_ARG3, R5_ARG3, -1); |
goetz@6458 | 1350 | __ bind(l_2); |
goetz@6458 | 1351 | |
goetz@6458 | 1352 | // At this point the positions of both, from and to, are at least 4 byte aligned. |
goetz@6458 | 1353 | |
goetz@6458 | 1354 | // Copy 4 elements at a time. |
goetz@6458 | 1355 | // Align to 8 bytes, but only if both, from and to, have same alignment mod 8. |
goetz@6458 | 1356 | __ xorr(tmp2, R3_ARG1, R4_ARG2); |
goetz@6458 | 1357 | __ andi_(tmp1, tmp2, 7); |
goetz@6458 | 1358 | __ bne(CCR0, l_7); // not same alignment mod 8 -> copy 4, either from or to will be unaligned |
goetz@6458 | 1359 | |
goetz@6458 | 1360 | // Copy a 2-element word if necessary to align to 8 bytes. |
goetz@6458 | 1361 | __ andi_(R0, R3_ARG1, 7); |
goetz@6458 | 1362 | __ beq(CCR0, l_7); |
goetz@6458 | 1363 | |
goetz@6458 | 1364 | __ lwzx(tmp2, R3_ARG1, tmp3); |
goetz@6458 | 1365 | __ addi(R5_ARG3, R5_ARG3, -2); |
goetz@6458 | 1366 | __ stwx(tmp2, R4_ARG2, tmp3); |
goetz@6458 | 1367 | { // FasterArrayCopy |
goetz@6458 | 1368 | __ addi(R3_ARG1, R3_ARG1, 4); |
goetz@6458 | 1369 | __ addi(R4_ARG2, R4_ARG2, 4); |
goetz@6458 | 1370 | } |
goetz@6458 | 1371 | } |
goetz@6458 | 1372 | |
goetz@6458 | 1373 | __ bind(l_7); |
goetz@6458 | 1374 | |
goetz@6458 | 1375 | // Copy 4 elements at a time; either the loads or the stores can |
goetz@6458 | 1376 | // be unaligned if aligned == false. |
goetz@6458 | 1377 | |
goetz@6458 | 1378 | { // FasterArrayCopy |
goetz@6458 | 1379 | __ cmpwi(CCR0, R5_ARG3, 15); |
goetz@6458 | 1380 | __ ble(CCR0, l_6); // copy 2 at a time if less than 16 elements remain |
goetz@6458 | 1381 | |
goetz@6458 | 1382 | __ srdi(tmp1, R5_ARG3, 4); |
goetz@6458 | 1383 | __ andi_(R5_ARG3, R5_ARG3, 15); |
goetz@6458 | 1384 | __ mtctr(tmp1); |
goetz@6458 | 1385 | |
goetz@6458 | 1386 | __ bind(l_8); |
goetz@6458 | 1387 | // Use unrolled version for mass copying (copy 16 elements a time). |
goetz@6458 | 1388 | // Load feeding store gets zero latency on Power6, however not on Power5. |
goetz@6458 | 1389 | // Therefore, the following sequence is made for the good of both. |
goetz@6458 | 1390 | __ ld(tmp1, 0, R3_ARG1); |
goetz@6458 | 1391 | __ ld(tmp2, 8, R3_ARG1); |
goetz@6458 | 1392 | __ ld(tmp3, 16, R3_ARG1); |
goetz@6458 | 1393 | __ ld(tmp4, 24, R3_ARG1); |
goetz@6458 | 1394 | __ std(tmp1, 0, R4_ARG2); |
goetz@6458 | 1395 | __ std(tmp2, 8, R4_ARG2); |
goetz@6458 | 1396 | __ std(tmp3, 16, R4_ARG2); |
goetz@6458 | 1397 | __ std(tmp4, 24, R4_ARG2); |
goetz@6458 | 1398 | __ addi(R3_ARG1, R3_ARG1, 32); |
goetz@6458 | 1399 | __ addi(R4_ARG2, R4_ARG2, 32); |
goetz@6458 | 1400 | __ bdnz(l_8); |
goetz@6458 | 1401 | } |
goetz@6458 | 1402 | __ bind(l_6); |
goetz@6458 | 1403 | |
goetz@6458 | 1404 | // copy 2 elements at a time |
goetz@6458 | 1405 | { // FasterArrayCopy |
goetz@6458 | 1406 | __ cmpwi(CCR0, R5_ARG3, 2); |
goetz@6458 | 1407 | __ blt(CCR0, l_1); |
goetz@6458 | 1408 | __ srdi(tmp1, R5_ARG3, 1); |
goetz@6458 | 1409 | __ andi_(R5_ARG3, R5_ARG3, 1); |
goetz@6458 | 1410 | |
goetz@6458 | 1411 | __ addi(R3_ARG1, R3_ARG1, -4); |
goetz@6458 | 1412 | __ addi(R4_ARG2, R4_ARG2, -4); |
goetz@6458 | 1413 | __ mtctr(tmp1); |
goetz@6458 | 1414 | |
goetz@6458 | 1415 | __ bind(l_3); |
goetz@6458 | 1416 | __ lwzu(tmp2, 4, R3_ARG1); |
goetz@6458 | 1417 | __ stwu(tmp2, 4, R4_ARG2); |
goetz@6458 | 1418 | __ bdnz(l_3); |
goetz@6458 | 1419 | |
goetz@6458 | 1420 | __ addi(R3_ARG1, R3_ARG1, 4); |
goetz@6458 | 1421 | __ addi(R4_ARG2, R4_ARG2, 4); |
goetz@6458 | 1422 | } |
goetz@6458 | 1423 | |
goetz@6458 | 1424 | // do single element copy |
goetz@6458 | 1425 | __ bind(l_1); |
goetz@6458 | 1426 | __ cmpwi(CCR0, R5_ARG3, 0); |
goetz@6458 | 1427 | __ beq(CCR0, l_4); |
goetz@6458 | 1428 | |
goetz@6458 | 1429 | { // FasterArrayCopy |
goetz@6458 | 1430 | __ mtctr(R5_ARG3); |
goetz@6458 | 1431 | __ addi(R3_ARG1, R3_ARG1, -2); |
goetz@6458 | 1432 | __ addi(R4_ARG2, R4_ARG2, -2); |
goetz@6458 | 1433 | |
goetz@6458 | 1434 | __ bind(l_5); |
goetz@6458 | 1435 | __ lhzu(tmp2, 2, R3_ARG1); |
goetz@6458 | 1436 | __ sthu(tmp2, 2, R4_ARG2); |
goetz@6458 | 1437 | __ bdnz(l_5); |
goetz@6458 | 1438 | } |
goetz@6458 | 1439 | __ bind(l_4); |
goetz@6458 | 1440 | __ blr(); |
goetz@6458 | 1441 | |
goetz@6458 | 1442 | return start; |
goetz@6458 | 1443 | } |
goetz@6458 | 1444 | |
goetz@6458 | 1445 | // Generate stub for conjoint short copy. If "aligned" is true, the |
goetz@6458 | 1446 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1447 | // |
goetz@6458 | 1448 | // Arguments for generated stub: |
goetz@6458 | 1449 | // from: R3_ARG1 |
goetz@6458 | 1450 | // to: R4_ARG2 |
goetz@6458 | 1451 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1452 | // |
goetz@6458 | 1453 | address generate_conjoint_short_copy(bool aligned, const char * name) { |
goetz@6458 | 1454 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1455 | address start = __ emit_fd(); |
goetz@6458 | 1456 | |
goetz@6458 | 1457 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1458 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1459 | Register tmp3 = R8_ARG6; |
goetz@6458 | 1460 | |
goetz@6458 | 1461 | address nooverlap_target = aligned ? |
goetz@6458 | 1462 | ((FunctionDescriptor*)StubRoutines::arrayof_jshort_disjoint_arraycopy())->entry() : |
goetz@6458 | 1463 | ((FunctionDescriptor*)StubRoutines::jshort_disjoint_arraycopy())->entry(); |
goetz@6458 | 1464 | |
goetz@6458 | 1465 | array_overlap_test(nooverlap_target, 1); |
goetz@6458 | 1466 | |
goetz@6458 | 1467 | Label l_1, l_2; |
goetz@6458 | 1468 | __ sldi(tmp1, R5_ARG3, 1); |
goetz@6458 | 1469 | __ b(l_2); |
goetz@6458 | 1470 | __ bind(l_1); |
goetz@6458 | 1471 | __ sthx(tmp2, R4_ARG2, tmp1); |
goetz@6458 | 1472 | __ bind(l_2); |
goetz@6458 | 1473 | __ addic_(tmp1, tmp1, -2); |
goetz@6458 | 1474 | __ lhzx(tmp2, R3_ARG1, tmp1); |
goetz@6458 | 1475 | __ bge(CCR0, l_1); |
goetz@6458 | 1476 | |
goetz@6458 | 1477 | __ blr(); |
goetz@6458 | 1478 | |
goetz@6458 | 1479 | return start; |
goetz@6458 | 1480 | } |
goetz@6458 | 1481 | |
goetz@6458 | 1482 | // Generate core code for disjoint int copy (and oop copy on 32-bit). If "aligned" |
goetz@6458 | 1483 | // is true, the "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1484 | // |
goetz@6458 | 1485 | // Arguments: |
goetz@6458 | 1486 | // from: R3_ARG1 |
goetz@6458 | 1487 | // to: R4_ARG2 |
goetz@6458 | 1488 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1489 | // |
goetz@6458 | 1490 | void generate_disjoint_int_copy_core(bool aligned) { |
goetz@6458 | 1491 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1492 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1493 | Register tmp3 = R8_ARG6; |
goetz@6458 | 1494 | Register tmp4 = R0; |
goetz@6458 | 1495 | |
goetz@6458 | 1496 | Label l_1, l_2, l_3, l_4, l_5, l_6; |
goetz@6458 | 1497 | // for short arrays, just do single element copy |
goetz@6458 | 1498 | __ li(tmp3, 0); |
goetz@6458 | 1499 | __ cmpwi(CCR0, R5_ARG3, 5); |
goetz@6458 | 1500 | __ ble(CCR0, l_2); |
goetz@6458 | 1501 | |
goetz@6458 | 1502 | if (!aligned) { |
goetz@6458 | 1503 | // check if arrays have same alignment mod 8. |
goetz@6458 | 1504 | __ xorr(tmp1, R3_ARG1, R4_ARG2); |
goetz@6458 | 1505 | __ andi_(R0, tmp1, 7); |
goetz@6458 | 1506 | // Not the same alignment, but ld and std just need to be 4 byte aligned. |
goetz@6458 | 1507 | __ bne(CCR0, l_4); // to OR from is 8 byte aligned -> copy 2 at a time |
goetz@6458 | 1508 | |
goetz@6458 | 1509 | // copy 1 element to align to and from on an 8 byte boundary |
goetz@6458 | 1510 | __ andi_(R0, R3_ARG1, 7); |
goetz@6458 | 1511 | __ beq(CCR0, l_4); |
goetz@6458 | 1512 | |
goetz@6458 | 1513 | __ lwzx(tmp2, R3_ARG1, tmp3); |
goetz@6458 | 1514 | __ addi(R5_ARG3, R5_ARG3, -1); |
goetz@6458 | 1515 | __ stwx(tmp2, R4_ARG2, tmp3); |
goetz@6458 | 1516 | { // FasterArrayCopy |
goetz@6458 | 1517 | __ addi(R3_ARG1, R3_ARG1, 4); |
goetz@6458 | 1518 | __ addi(R4_ARG2, R4_ARG2, 4); |
goetz@6458 | 1519 | } |
goetz@6458 | 1520 | __ bind(l_4); |
goetz@6458 | 1521 | } |
goetz@6458 | 1522 | |
goetz@6458 | 1523 | { // FasterArrayCopy |
goetz@6458 | 1524 | __ cmpwi(CCR0, R5_ARG3, 7); |
goetz@6458 | 1525 | __ ble(CCR0, l_2); // copy 1 at a time if less than 8 elements remain |
goetz@6458 | 1526 | |
goetz@6458 | 1527 | __ srdi(tmp1, R5_ARG3, 3); |
goetz@6458 | 1528 | __ andi_(R5_ARG3, R5_ARG3, 7); |
goetz@6458 | 1529 | __ mtctr(tmp1); |
goetz@6458 | 1530 | |
goetz@6458 | 1531 | __ bind(l_6); |
goetz@6458 | 1532 | // Use unrolled version for mass copying (copy 8 elements a time). |
goetz@6458 | 1533 | // Load feeding store gets zero latency on power6, however not on power 5. |
goetz@6458 | 1534 | // Therefore, the following sequence is made for the good of both. |
goetz@6458 | 1535 | __ ld(tmp1, 0, R3_ARG1); |
goetz@6458 | 1536 | __ ld(tmp2, 8, R3_ARG1); |
goetz@6458 | 1537 | __ ld(tmp3, 16, R3_ARG1); |
goetz@6458 | 1538 | __ ld(tmp4, 24, R3_ARG1); |
goetz@6458 | 1539 | __ std(tmp1, 0, R4_ARG2); |
goetz@6458 | 1540 | __ std(tmp2, 8, R4_ARG2); |
goetz@6458 | 1541 | __ std(tmp3, 16, R4_ARG2); |
goetz@6458 | 1542 | __ std(tmp4, 24, R4_ARG2); |
goetz@6458 | 1543 | __ addi(R3_ARG1, R3_ARG1, 32); |
goetz@6458 | 1544 | __ addi(R4_ARG2, R4_ARG2, 32); |
goetz@6458 | 1545 | __ bdnz(l_6); |
goetz@6458 | 1546 | } |
goetz@6458 | 1547 | |
goetz@6458 | 1548 | // copy 1 element at a time |
goetz@6458 | 1549 | __ bind(l_2); |
goetz@6458 | 1550 | __ cmpwi(CCR0, R5_ARG3, 0); |
goetz@6458 | 1551 | __ beq(CCR0, l_1); |
goetz@6458 | 1552 | |
goetz@6458 | 1553 | { // FasterArrayCopy |
goetz@6458 | 1554 | __ mtctr(R5_ARG3); |
goetz@6458 | 1555 | __ addi(R3_ARG1, R3_ARG1, -4); |
goetz@6458 | 1556 | __ addi(R4_ARG2, R4_ARG2, -4); |
goetz@6458 | 1557 | |
goetz@6458 | 1558 | __ bind(l_3); |
goetz@6458 | 1559 | __ lwzu(tmp2, 4, R3_ARG1); |
goetz@6458 | 1560 | __ stwu(tmp2, 4, R4_ARG2); |
goetz@6458 | 1561 | __ bdnz(l_3); |
goetz@6458 | 1562 | } |
goetz@6458 | 1563 | |
goetz@6458 | 1564 | __ bind(l_1); |
goetz@6458 | 1565 | return; |
goetz@6458 | 1566 | } |
goetz@6458 | 1567 | |
goetz@6458 | 1568 | // Generate stub for disjoint int copy. If "aligned" is true, the |
goetz@6458 | 1569 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1570 | // |
goetz@6458 | 1571 | // Arguments for generated stub: |
goetz@6458 | 1572 | // from: R3_ARG1 |
goetz@6458 | 1573 | // to: R4_ARG2 |
goetz@6458 | 1574 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1575 | // |
goetz@6458 | 1576 | address generate_disjoint_int_copy(bool aligned, const char * name) { |
goetz@6458 | 1577 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1578 | address start = __ emit_fd(); |
goetz@6458 | 1579 | generate_disjoint_int_copy_core(aligned); |
goetz@6458 | 1580 | __ blr(); |
goetz@6458 | 1581 | return start; |
goetz@6458 | 1582 | } |
goetz@6458 | 1583 | |
goetz@6458 | 1584 | // Generate core code for conjoint int copy (and oop copy on |
goetz@6458 | 1585 | // 32-bit). If "aligned" is true, the "from" and "to" addresses |
goetz@6458 | 1586 | // are assumed to be heapword aligned. |
goetz@6458 | 1587 | // |
goetz@6458 | 1588 | // Arguments: |
goetz@6458 | 1589 | // from: R3_ARG1 |
goetz@6458 | 1590 | // to: R4_ARG2 |
goetz@6458 | 1591 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1592 | // |
goetz@6458 | 1593 | void generate_conjoint_int_copy_core(bool aligned) { |
goetz@6458 | 1594 | // Do reverse copy. We assume the case of actual overlap is rare enough |
goetz@6458 | 1595 | // that we don't have to optimize it. |
goetz@6458 | 1596 | |
goetz@6458 | 1597 | Label l_1, l_2, l_3, l_4, l_5, l_6; |
goetz@6458 | 1598 | |
goetz@6458 | 1599 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1600 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1601 | Register tmp3 = R8_ARG6; |
goetz@6458 | 1602 | Register tmp4 = R0; |
goetz@6458 | 1603 | |
goetz@6458 | 1604 | { // FasterArrayCopy |
goetz@6458 | 1605 | __ cmpwi(CCR0, R5_ARG3, 0); |
goetz@6458 | 1606 | __ beq(CCR0, l_6); |
goetz@6458 | 1607 | |
goetz@6458 | 1608 | __ sldi(R5_ARG3, R5_ARG3, 2); |
goetz@6458 | 1609 | __ add(R3_ARG1, R3_ARG1, R5_ARG3); |
goetz@6458 | 1610 | __ add(R4_ARG2, R4_ARG2, R5_ARG3); |
goetz@6458 | 1611 | __ srdi(R5_ARG3, R5_ARG3, 2); |
goetz@6458 | 1612 | |
goetz@6458 | 1613 | __ cmpwi(CCR0, R5_ARG3, 7); |
goetz@6458 | 1614 | __ ble(CCR0, l_5); // copy 1 at a time if less than 8 elements remain |
goetz@6458 | 1615 | |
goetz@6458 | 1616 | __ srdi(tmp1, R5_ARG3, 3); |
goetz@6458 | 1617 | __ andi(R5_ARG3, R5_ARG3, 7); |
goetz@6458 | 1618 | __ mtctr(tmp1); |
goetz@6458 | 1619 | |
goetz@6458 | 1620 | __ bind(l_4); |
goetz@6458 | 1621 | // Use unrolled version for mass copying (copy 4 elements a time). |
goetz@6458 | 1622 | // Load feeding store gets zero latency on Power6, however not on Power5. |
goetz@6458 | 1623 | // Therefore, the following sequence is made for the good of both. |
goetz@6458 | 1624 | __ addi(R3_ARG1, R3_ARG1, -32); |
goetz@6458 | 1625 | __ addi(R4_ARG2, R4_ARG2, -32); |
goetz@6458 | 1626 | __ ld(tmp4, 24, R3_ARG1); |
goetz@6458 | 1627 | __ ld(tmp3, 16, R3_ARG1); |
goetz@6458 | 1628 | __ ld(tmp2, 8, R3_ARG1); |
goetz@6458 | 1629 | __ ld(tmp1, 0, R3_ARG1); |
goetz@6458 | 1630 | __ std(tmp4, 24, R4_ARG2); |
goetz@6458 | 1631 | __ std(tmp3, 16, R4_ARG2); |
goetz@6458 | 1632 | __ std(tmp2, 8, R4_ARG2); |
goetz@6458 | 1633 | __ std(tmp1, 0, R4_ARG2); |
goetz@6458 | 1634 | __ bdnz(l_4); |
goetz@6458 | 1635 | |
goetz@6458 | 1636 | __ cmpwi(CCR0, R5_ARG3, 0); |
goetz@6458 | 1637 | __ beq(CCR0, l_6); |
goetz@6458 | 1638 | |
goetz@6458 | 1639 | __ bind(l_5); |
goetz@6458 | 1640 | __ mtctr(R5_ARG3); |
goetz@6458 | 1641 | __ bind(l_3); |
goetz@6458 | 1642 | __ lwz(R0, -4, R3_ARG1); |
goetz@6458 | 1643 | __ stw(R0, -4, R4_ARG2); |
goetz@6458 | 1644 | __ addi(R3_ARG1, R3_ARG1, -4); |
goetz@6458 | 1645 | __ addi(R4_ARG2, R4_ARG2, -4); |
goetz@6458 | 1646 | __ bdnz(l_3); |
goetz@6458 | 1647 | |
goetz@6458 | 1648 | __ bind(l_6); |
goetz@6458 | 1649 | } |
goetz@6458 | 1650 | } |
goetz@6458 | 1651 | |
goetz@6458 | 1652 | // Generate stub for conjoint int copy. If "aligned" is true, the |
goetz@6458 | 1653 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1654 | // |
goetz@6458 | 1655 | // Arguments for generated stub: |
goetz@6458 | 1656 | // from: R3_ARG1 |
goetz@6458 | 1657 | // to: R4_ARG2 |
goetz@6458 | 1658 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1659 | // |
goetz@6458 | 1660 | address generate_conjoint_int_copy(bool aligned, const char * name) { |
goetz@6458 | 1661 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1662 | address start = __ emit_fd(); |
goetz@6458 | 1663 | |
goetz@6458 | 1664 | address nooverlap_target = aligned ? |
goetz@6458 | 1665 | ((FunctionDescriptor*)StubRoutines::arrayof_jint_disjoint_arraycopy())->entry() : |
goetz@6458 | 1666 | ((FunctionDescriptor*)StubRoutines::jint_disjoint_arraycopy())->entry(); |
goetz@6458 | 1667 | |
goetz@6458 | 1668 | array_overlap_test(nooverlap_target, 2); |
goetz@6458 | 1669 | |
goetz@6458 | 1670 | generate_conjoint_int_copy_core(aligned); |
goetz@6458 | 1671 | |
goetz@6458 | 1672 | __ blr(); |
goetz@6458 | 1673 | |
goetz@6458 | 1674 | return start; |
goetz@6458 | 1675 | } |
goetz@6458 | 1676 | |
goetz@6458 | 1677 | // Generate core code for disjoint long copy (and oop copy on |
goetz@6458 | 1678 | // 64-bit). If "aligned" is true, the "from" and "to" addresses |
goetz@6458 | 1679 | // are assumed to be heapword aligned. |
goetz@6458 | 1680 | // |
goetz@6458 | 1681 | // Arguments: |
goetz@6458 | 1682 | // from: R3_ARG1 |
goetz@6458 | 1683 | // to: R4_ARG2 |
goetz@6458 | 1684 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1685 | // |
goetz@6458 | 1686 | void generate_disjoint_long_copy_core(bool aligned) { |
goetz@6458 | 1687 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1688 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1689 | Register tmp3 = R8_ARG6; |
goetz@6458 | 1690 | Register tmp4 = R0; |
goetz@6458 | 1691 | |
goetz@6458 | 1692 | Label l_1, l_2, l_3, l_4; |
goetz@6458 | 1693 | |
goetz@6458 | 1694 | { // FasterArrayCopy |
goetz@6458 | 1695 | __ cmpwi(CCR0, R5_ARG3, 3); |
goetz@6458 | 1696 | __ ble(CCR0, l_3); // copy 1 at a time if less than 4 elements remain |
goetz@6458 | 1697 | |
goetz@6458 | 1698 | __ srdi(tmp1, R5_ARG3, 2); |
goetz@6458 | 1699 | __ andi_(R5_ARG3, R5_ARG3, 3); |
goetz@6458 | 1700 | __ mtctr(tmp1); |
goetz@6458 | 1701 | |
goetz@6458 | 1702 | __ bind(l_4); |
goetz@6458 | 1703 | // Use unrolled version for mass copying (copy 4 elements a time). |
goetz@6458 | 1704 | // Load feeding store gets zero latency on Power6, however not on Power5. |
goetz@6458 | 1705 | // Therefore, the following sequence is made for the good of both. |
goetz@6458 | 1706 | __ ld(tmp1, 0, R3_ARG1); |
goetz@6458 | 1707 | __ ld(tmp2, 8, R3_ARG1); |
goetz@6458 | 1708 | __ ld(tmp3, 16, R3_ARG1); |
goetz@6458 | 1709 | __ ld(tmp4, 24, R3_ARG1); |
goetz@6458 | 1710 | __ std(tmp1, 0, R4_ARG2); |
goetz@6458 | 1711 | __ std(tmp2, 8, R4_ARG2); |
goetz@6458 | 1712 | __ std(tmp3, 16, R4_ARG2); |
goetz@6458 | 1713 | __ std(tmp4, 24, R4_ARG2); |
goetz@6458 | 1714 | __ addi(R3_ARG1, R3_ARG1, 32); |
goetz@6458 | 1715 | __ addi(R4_ARG2, R4_ARG2, 32); |
goetz@6458 | 1716 | __ bdnz(l_4); |
goetz@6458 | 1717 | } |
goetz@6458 | 1718 | |
goetz@6458 | 1719 | // copy 1 element at a time |
goetz@6458 | 1720 | __ bind(l_3); |
goetz@6458 | 1721 | __ cmpwi(CCR0, R5_ARG3, 0); |
goetz@6458 | 1722 | __ beq(CCR0, l_1); |
goetz@6458 | 1723 | |
goetz@6458 | 1724 | { // FasterArrayCopy |
goetz@6458 | 1725 | __ mtctr(R5_ARG3); |
goetz@6458 | 1726 | __ addi(R3_ARG1, R3_ARG1, -8); |
goetz@6458 | 1727 | __ addi(R4_ARG2, R4_ARG2, -8); |
goetz@6458 | 1728 | |
goetz@6458 | 1729 | __ bind(l_2); |
goetz@6458 | 1730 | __ ldu(R0, 8, R3_ARG1); |
goetz@6458 | 1731 | __ stdu(R0, 8, R4_ARG2); |
goetz@6458 | 1732 | __ bdnz(l_2); |
goetz@6458 | 1733 | |
goetz@6458 | 1734 | } |
goetz@6458 | 1735 | __ bind(l_1); |
goetz@6458 | 1736 | } |
goetz@6458 | 1737 | |
goetz@6458 | 1738 | // Generate stub for disjoint long copy. If "aligned" is true, the |
goetz@6458 | 1739 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1740 | // |
goetz@6458 | 1741 | // Arguments for generated stub: |
goetz@6458 | 1742 | // from: R3_ARG1 |
goetz@6458 | 1743 | // to: R4_ARG2 |
goetz@6458 | 1744 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1745 | // |
goetz@6458 | 1746 | address generate_disjoint_long_copy(bool aligned, const char * name) { |
goetz@6458 | 1747 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1748 | address start = __ emit_fd(); |
goetz@6458 | 1749 | generate_disjoint_long_copy_core(aligned); |
goetz@6458 | 1750 | __ blr(); |
goetz@6458 | 1751 | |
goetz@6458 | 1752 | return start; |
goetz@6458 | 1753 | } |
goetz@6458 | 1754 | |
goetz@6458 | 1755 | // Generate core code for conjoint long copy (and oop copy on |
goetz@6458 | 1756 | // 64-bit). If "aligned" is true, the "from" and "to" addresses |
goetz@6458 | 1757 | // are assumed to be heapword aligned. |
goetz@6458 | 1758 | // |
goetz@6458 | 1759 | // Arguments: |
goetz@6458 | 1760 | // from: R3_ARG1 |
goetz@6458 | 1761 | // to: R4_ARG2 |
goetz@6458 | 1762 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1763 | // |
goetz@6458 | 1764 | void generate_conjoint_long_copy_core(bool aligned) { |
goetz@6458 | 1765 | Register tmp1 = R6_ARG4; |
goetz@6458 | 1766 | Register tmp2 = R7_ARG5; |
goetz@6458 | 1767 | Register tmp3 = R8_ARG6; |
goetz@6458 | 1768 | Register tmp4 = R0; |
goetz@6458 | 1769 | |
goetz@6458 | 1770 | Label l_1, l_2, l_3, l_4, l_5; |
goetz@6458 | 1771 | |
goetz@6458 | 1772 | __ cmpwi(CCR0, R5_ARG3, 0); |
goetz@6458 | 1773 | __ beq(CCR0, l_1); |
goetz@6458 | 1774 | |
goetz@6458 | 1775 | { // FasterArrayCopy |
goetz@6458 | 1776 | __ sldi(R5_ARG3, R5_ARG3, 3); |
goetz@6458 | 1777 | __ add(R3_ARG1, R3_ARG1, R5_ARG3); |
goetz@6458 | 1778 | __ add(R4_ARG2, R4_ARG2, R5_ARG3); |
goetz@6458 | 1779 | __ srdi(R5_ARG3, R5_ARG3, 3); |
goetz@6458 | 1780 | |
goetz@6458 | 1781 | __ cmpwi(CCR0, R5_ARG3, 3); |
goetz@6458 | 1782 | __ ble(CCR0, l_5); // copy 1 at a time if less than 4 elements remain |
goetz@6458 | 1783 | |
goetz@6458 | 1784 | __ srdi(tmp1, R5_ARG3, 2); |
goetz@6458 | 1785 | __ andi(R5_ARG3, R5_ARG3, 3); |
goetz@6458 | 1786 | __ mtctr(tmp1); |
goetz@6458 | 1787 | |
goetz@6458 | 1788 | __ bind(l_4); |
goetz@6458 | 1789 | // Use unrolled version for mass copying (copy 4 elements a time). |
goetz@6458 | 1790 | // Load feeding store gets zero latency on Power6, however not on Power5. |
goetz@6458 | 1791 | // Therefore, the following sequence is made for the good of both. |
goetz@6458 | 1792 | __ addi(R3_ARG1, R3_ARG1, -32); |
goetz@6458 | 1793 | __ addi(R4_ARG2, R4_ARG2, -32); |
goetz@6458 | 1794 | __ ld(tmp4, 24, R3_ARG1); |
goetz@6458 | 1795 | __ ld(tmp3, 16, R3_ARG1); |
goetz@6458 | 1796 | __ ld(tmp2, 8, R3_ARG1); |
goetz@6458 | 1797 | __ ld(tmp1, 0, R3_ARG1); |
goetz@6458 | 1798 | __ std(tmp4, 24, R4_ARG2); |
goetz@6458 | 1799 | __ std(tmp3, 16, R4_ARG2); |
goetz@6458 | 1800 | __ std(tmp2, 8, R4_ARG2); |
goetz@6458 | 1801 | __ std(tmp1, 0, R4_ARG2); |
goetz@6458 | 1802 | __ bdnz(l_4); |
goetz@6458 | 1803 | |
goetz@6458 | 1804 | __ cmpwi(CCR0, R5_ARG3, 0); |
goetz@6458 | 1805 | __ beq(CCR0, l_1); |
goetz@6458 | 1806 | |
goetz@6458 | 1807 | __ bind(l_5); |
goetz@6458 | 1808 | __ mtctr(R5_ARG3); |
goetz@6458 | 1809 | __ bind(l_3); |
goetz@6458 | 1810 | __ ld(R0, -8, R3_ARG1); |
goetz@6458 | 1811 | __ std(R0, -8, R4_ARG2); |
goetz@6458 | 1812 | __ addi(R3_ARG1, R3_ARG1, -8); |
goetz@6458 | 1813 | __ addi(R4_ARG2, R4_ARG2, -8); |
goetz@6458 | 1814 | __ bdnz(l_3); |
goetz@6458 | 1815 | |
goetz@6458 | 1816 | } |
goetz@6458 | 1817 | __ bind(l_1); |
goetz@6458 | 1818 | } |
goetz@6458 | 1819 | |
goetz@6458 | 1820 | // Generate stub for conjoint long copy. If "aligned" is true, the |
goetz@6458 | 1821 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1822 | // |
goetz@6458 | 1823 | // Arguments for generated stub: |
goetz@6458 | 1824 | // from: R3_ARG1 |
goetz@6458 | 1825 | // to: R4_ARG2 |
goetz@6458 | 1826 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1827 | // |
goetz@6458 | 1828 | address generate_conjoint_long_copy(bool aligned, const char * name) { |
goetz@6458 | 1829 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1830 | address start = __ emit_fd(); |
goetz@6458 | 1831 | |
goetz@6458 | 1832 | address nooverlap_target = aligned ? |
goetz@6458 | 1833 | ((FunctionDescriptor*)StubRoutines::arrayof_jlong_disjoint_arraycopy())->entry() : |
goetz@6458 | 1834 | ((FunctionDescriptor*)StubRoutines::jlong_disjoint_arraycopy())->entry(); |
goetz@6458 | 1835 | |
goetz@6458 | 1836 | array_overlap_test(nooverlap_target, 3); |
goetz@6458 | 1837 | generate_conjoint_long_copy_core(aligned); |
goetz@6458 | 1838 | |
goetz@6458 | 1839 | __ blr(); |
goetz@6458 | 1840 | |
goetz@6458 | 1841 | return start; |
goetz@6458 | 1842 | } |
goetz@6458 | 1843 | |
goetz@6458 | 1844 | // Generate stub for conjoint oop copy. If "aligned" is true, the |
goetz@6458 | 1845 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1846 | // |
goetz@6458 | 1847 | // Arguments for generated stub: |
goetz@6458 | 1848 | // from: R3_ARG1 |
goetz@6458 | 1849 | // to: R4_ARG2 |
goetz@6458 | 1850 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1851 | // dest_uninitialized: G1 support |
goetz@6458 | 1852 | // |
goetz@6458 | 1853 | address generate_conjoint_oop_copy(bool aligned, const char * name, bool dest_uninitialized) { |
goetz@6458 | 1854 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1855 | |
goetz@6458 | 1856 | address start = __ emit_fd(); |
goetz@6458 | 1857 | |
goetz@6458 | 1858 | address nooverlap_target = aligned ? |
goetz@6458 | 1859 | ((FunctionDescriptor*)StubRoutines::arrayof_oop_disjoint_arraycopy())->entry() : |
goetz@6458 | 1860 | ((FunctionDescriptor*)StubRoutines::oop_disjoint_arraycopy())->entry(); |
goetz@6458 | 1861 | |
goetz@6458 | 1862 | gen_write_ref_array_pre_barrier(R3_ARG1, R4_ARG2, R5_ARG3, dest_uninitialized, R9_ARG7); |
goetz@6458 | 1863 | |
goetz@6458 | 1864 | // Save arguments. |
goetz@6458 | 1865 | __ mr(R9_ARG7, R4_ARG2); |
goetz@6458 | 1866 | __ mr(R10_ARG8, R5_ARG3); |
goetz@6458 | 1867 | |
goetz@6458 | 1868 | if (UseCompressedOops) { |
goetz@6458 | 1869 | array_overlap_test(nooverlap_target, 2); |
goetz@6458 | 1870 | generate_conjoint_int_copy_core(aligned); |
goetz@6458 | 1871 | } else { |
goetz@6458 | 1872 | array_overlap_test(nooverlap_target, 3); |
goetz@6458 | 1873 | generate_conjoint_long_copy_core(aligned); |
goetz@6458 | 1874 | } |
goetz@6458 | 1875 | |
goetz@6458 | 1876 | gen_write_ref_array_post_barrier(R9_ARG7, R10_ARG8, R11_scratch1); |
goetz@6458 | 1877 | |
goetz@6458 | 1878 | __ blr(); |
goetz@6458 | 1879 | |
goetz@6458 | 1880 | return start; |
goetz@6458 | 1881 | } |
goetz@6458 | 1882 | |
goetz@6458 | 1883 | // Generate stub for disjoint oop copy. If "aligned" is true, the |
goetz@6458 | 1884 | // "from" and "to" addresses are assumed to be heapword aligned. |
goetz@6458 | 1885 | // |
goetz@6458 | 1886 | // Arguments for generated stub: |
goetz@6458 | 1887 | // from: R3_ARG1 |
goetz@6458 | 1888 | // to: R4_ARG2 |
goetz@6458 | 1889 | // count: R5_ARG3 treated as signed |
goetz@6458 | 1890 | // dest_uninitialized: G1 support |
goetz@6458 | 1891 | // |
goetz@6458 | 1892 | address generate_disjoint_oop_copy(bool aligned, const char * name, bool dest_uninitialized) { |
goetz@6458 | 1893 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1894 | address start = __ emit_fd(); |
goetz@6458 | 1895 | |
goetz@6458 | 1896 | gen_write_ref_array_pre_barrier(R3_ARG1, R4_ARG2, R5_ARG3, dest_uninitialized, R9_ARG7); |
goetz@6458 | 1897 | |
goetz@6458 | 1898 | // save some arguments, disjoint_long_copy_core destroys them. |
goetz@6458 | 1899 | // needed for post barrier |
goetz@6458 | 1900 | __ mr(R9_ARG7, R4_ARG2); |
goetz@6458 | 1901 | __ mr(R10_ARG8, R5_ARG3); |
goetz@6458 | 1902 | |
goetz@6458 | 1903 | if (UseCompressedOops) { |
goetz@6458 | 1904 | generate_disjoint_int_copy_core(aligned); |
goetz@6458 | 1905 | } else { |
goetz@6458 | 1906 | generate_disjoint_long_copy_core(aligned); |
goetz@6458 | 1907 | } |
goetz@6458 | 1908 | |
goetz@6458 | 1909 | gen_write_ref_array_post_barrier(R9_ARG7, R10_ARG8, R11_scratch1); |
goetz@6458 | 1910 | |
goetz@6458 | 1911 | __ blr(); |
goetz@6458 | 1912 | |
goetz@6458 | 1913 | return start; |
goetz@6458 | 1914 | } |
goetz@6458 | 1915 | |
goetz@6458 | 1916 | void generate_arraycopy_stubs() { |
goetz@6458 | 1917 | // Note: the disjoint stubs must be generated first, some of |
goetz@6458 | 1918 | // the conjoint stubs use them. |
goetz@6458 | 1919 | |
goetz@6458 | 1920 | // non-aligned disjoint versions |
goetz@6458 | 1921 | StubRoutines::_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(false, "jbyte_disjoint_arraycopy"); |
goetz@6458 | 1922 | StubRoutines::_jshort_disjoint_arraycopy = generate_disjoint_short_copy(false, "jshort_disjoint_arraycopy"); |
goetz@6458 | 1923 | StubRoutines::_jint_disjoint_arraycopy = generate_disjoint_int_copy(false, "jint_disjoint_arraycopy"); |
goetz@6458 | 1924 | StubRoutines::_jlong_disjoint_arraycopy = generate_disjoint_long_copy(false, "jlong_disjoint_arraycopy"); |
goetz@6458 | 1925 | StubRoutines::_oop_disjoint_arraycopy = generate_disjoint_oop_copy(false, "oop_disjoint_arraycopy", false); |
goetz@6458 | 1926 | StubRoutines::_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy(false, "oop_disjoint_arraycopy_uninit", true); |
goetz@6458 | 1927 | |
goetz@6458 | 1928 | // aligned disjoint versions |
goetz@6458 | 1929 | StubRoutines::_arrayof_jbyte_disjoint_arraycopy = generate_disjoint_byte_copy(true, "arrayof_jbyte_disjoint_arraycopy"); |
goetz@6458 | 1930 | StubRoutines::_arrayof_jshort_disjoint_arraycopy = generate_disjoint_short_copy(true, "arrayof_jshort_disjoint_arraycopy"); |
goetz@6458 | 1931 | StubRoutines::_arrayof_jint_disjoint_arraycopy = generate_disjoint_int_copy(true, "arrayof_jint_disjoint_arraycopy"); |
goetz@6458 | 1932 | StubRoutines::_arrayof_jlong_disjoint_arraycopy = generate_disjoint_long_copy(true, "arrayof_jlong_disjoint_arraycopy"); |
goetz@6458 | 1933 | StubRoutines::_arrayof_oop_disjoint_arraycopy = generate_disjoint_oop_copy(true, "arrayof_oop_disjoint_arraycopy", false); |
goetz@6458 | 1934 | StubRoutines::_arrayof_oop_disjoint_arraycopy_uninit = generate_disjoint_oop_copy(true, "oop_disjoint_arraycopy_uninit", true); |
goetz@6458 | 1935 | |
goetz@6458 | 1936 | // non-aligned conjoint versions |
goetz@6458 | 1937 | StubRoutines::_jbyte_arraycopy = generate_conjoint_byte_copy(false, "jbyte_arraycopy"); |
goetz@6458 | 1938 | StubRoutines::_jshort_arraycopy = generate_conjoint_short_copy(false, "jshort_arraycopy"); |
goetz@6458 | 1939 | StubRoutines::_jint_arraycopy = generate_conjoint_int_copy(false, "jint_arraycopy"); |
goetz@6458 | 1940 | StubRoutines::_jlong_arraycopy = generate_conjoint_long_copy(false, "jlong_arraycopy"); |
goetz@6458 | 1941 | StubRoutines::_oop_arraycopy = generate_conjoint_oop_copy(false, "oop_arraycopy", false); |
goetz@6458 | 1942 | StubRoutines::_oop_arraycopy_uninit = generate_conjoint_oop_copy(false, "oop_arraycopy_uninit", true); |
goetz@6458 | 1943 | |
goetz@6458 | 1944 | // aligned conjoint versions |
goetz@6458 | 1945 | StubRoutines::_arrayof_jbyte_arraycopy = generate_conjoint_byte_copy(true, "arrayof_jbyte_arraycopy"); |
goetz@6458 | 1946 | StubRoutines::_arrayof_jshort_arraycopy = generate_conjoint_short_copy(true, "arrayof_jshort_arraycopy"); |
goetz@6458 | 1947 | StubRoutines::_arrayof_jint_arraycopy = generate_conjoint_int_copy(true, "arrayof_jint_arraycopy"); |
goetz@6458 | 1948 | StubRoutines::_arrayof_jlong_arraycopy = generate_conjoint_long_copy(true, "arrayof_jlong_arraycopy"); |
goetz@6458 | 1949 | StubRoutines::_arrayof_oop_arraycopy = generate_conjoint_oop_copy(true, "arrayof_oop_arraycopy", false); |
goetz@6458 | 1950 | StubRoutines::_arrayof_oop_arraycopy_uninit = generate_conjoint_oop_copy(true, "arrayof_oop_arraycopy", true); |
goetz@6458 | 1951 | |
goetz@6458 | 1952 | // fill routines |
goetz@6458 | 1953 | StubRoutines::_jbyte_fill = generate_fill(T_BYTE, false, "jbyte_fill"); |
goetz@6458 | 1954 | StubRoutines::_jshort_fill = generate_fill(T_SHORT, false, "jshort_fill"); |
goetz@6458 | 1955 | StubRoutines::_jint_fill = generate_fill(T_INT, false, "jint_fill"); |
goetz@6458 | 1956 | StubRoutines::_arrayof_jbyte_fill = generate_fill(T_BYTE, true, "arrayof_jbyte_fill"); |
goetz@6458 | 1957 | StubRoutines::_arrayof_jshort_fill = generate_fill(T_SHORT, true, "arrayof_jshort_fill"); |
goetz@6458 | 1958 | StubRoutines::_arrayof_jint_fill = generate_fill(T_INT, true, "arrayof_jint_fill"); |
goetz@6458 | 1959 | } |
goetz@6458 | 1960 | |
goetz@6458 | 1961 | // Safefetch stubs. |
goetz@6458 | 1962 | void generate_safefetch(const char* name, int size, address* entry, address* fault_pc, address* continuation_pc) { |
goetz@6458 | 1963 | // safefetch signatures: |
goetz@6458 | 1964 | // int SafeFetch32(int* adr, int errValue); |
goetz@6458 | 1965 | // intptr_t SafeFetchN (intptr_t* adr, intptr_t errValue); |
goetz@6458 | 1966 | // |
goetz@6458 | 1967 | // arguments: |
goetz@6458 | 1968 | // R3_ARG1 = adr |
goetz@6458 | 1969 | // R4_ARG2 = errValue |
goetz@6458 | 1970 | // |
goetz@6458 | 1971 | // result: |
goetz@6458 | 1972 | // R3_RET = *adr or errValue |
goetz@6458 | 1973 | |
goetz@6458 | 1974 | StubCodeMark mark(this, "StubRoutines", name); |
goetz@6458 | 1975 | |
goetz@6458 | 1976 | // Entry point, pc or function descriptor. |
goetz@6458 | 1977 | *entry = __ emit_fd(); |
goetz@6458 | 1978 | |
goetz@6458 | 1979 | // Load *adr into R4_ARG2, may fault. |
goetz@6458 | 1980 | *fault_pc = __ pc(); |
goetz@6458 | 1981 | switch (size) { |
goetz@6458 | 1982 | case 4: |
goetz@6458 | 1983 | // int32_t, signed extended |
goetz@6458 | 1984 | __ lwa(R4_ARG2, 0, R3_ARG1); |
goetz@6458 | 1985 | break; |
goetz@6458 | 1986 | case 8: |
goetz@6458 | 1987 | // int64_t |
goetz@6458 | 1988 | __ ld(R4_ARG2, 0, R3_ARG1); |
goetz@6458 | 1989 | break; |
goetz@6458 | 1990 | default: |
goetz@6458 | 1991 | ShouldNotReachHere(); |
goetz@6458 | 1992 | } |
goetz@6458 | 1993 | |
goetz@6458 | 1994 | // return errValue or *adr |
goetz@6458 | 1995 | *continuation_pc = __ pc(); |
goetz@6458 | 1996 | __ mr(R3_RET, R4_ARG2); |
goetz@6458 | 1997 | __ blr(); |
goetz@6458 | 1998 | } |
goetz@6458 | 1999 | |
goetz@6458 | 2000 | // Initialization |
goetz@6458 | 2001 | void generate_initial() { |
goetz@6458 | 2002 | // Generates all stubs and initializes the entry points |
goetz@6458 | 2003 | |
goetz@6458 | 2004 | // Entry points that exist in all platforms. |
goetz@6458 | 2005 | // Note: This is code that could be shared among different platforms - however the |
goetz@6458 | 2006 | // benefit seems to be smaller than the disadvantage of having a |
goetz@6458 | 2007 | // much more complicated generator structure. See also comment in |
goetz@6458 | 2008 | // stubRoutines.hpp. |
goetz@6458 | 2009 | |
goetz@6458 | 2010 | StubRoutines::_forward_exception_entry = generate_forward_exception(); |
goetz@6458 | 2011 | StubRoutines::_call_stub_entry = generate_call_stub(StubRoutines::_call_stub_return_address); |
goetz@6458 | 2012 | StubRoutines::_catch_exception_entry = generate_catch_exception(); |
goetz@6458 | 2013 | } |
goetz@6458 | 2014 | |
goetz@6458 | 2015 | void generate_all() { |
goetz@6458 | 2016 | // Generates all stubs and initializes the entry points |
goetz@6458 | 2017 | |
goetz@6458 | 2018 | // These entry points require SharedInfo::stack0 to be set up in |
goetz@6458 | 2019 | // non-core builds |
goetz@6458 | 2020 | StubRoutines::_throw_AbstractMethodError_entry = generate_throw_exception("AbstractMethodError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_AbstractMethodError), false); |
goetz@6458 | 2021 | // Handle IncompatibleClassChangeError in itable stubs. |
goetz@6458 | 2022 | StubRoutines::_throw_IncompatibleClassChangeError_entry= generate_throw_exception("IncompatibleClassChangeError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_IncompatibleClassChangeError), false); |
goetz@6458 | 2023 | StubRoutines::_throw_NullPointerException_at_call_entry= generate_throw_exception("NullPointerException at call throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_NullPointerException_at_call), false); |
goetz@6458 | 2024 | StubRoutines::_throw_StackOverflowError_entry = generate_throw_exception("StackOverflowError throw_exception", CAST_FROM_FN_PTR(address, SharedRuntime::throw_StackOverflowError), false); |
goetz@6458 | 2025 | |
goetz@6458 | 2026 | StubRoutines::_handler_for_unsafe_access_entry = generate_handler_for_unsafe_access(); |
goetz@6458 | 2027 | |
goetz@6458 | 2028 | // support for verify_oop (must happen after universe_init) |
goetz@6458 | 2029 | StubRoutines::_verify_oop_subroutine_entry = generate_verify_oop(); |
goetz@6458 | 2030 | |
goetz@6458 | 2031 | // arraycopy stubs used by compilers |
goetz@6458 | 2032 | generate_arraycopy_stubs(); |
goetz@6458 | 2033 | |
goetz@6458 | 2034 | // PPC uses stubs for safefetch. |
goetz@6458 | 2035 | generate_safefetch("SafeFetch32", sizeof(int), &StubRoutines::_safefetch32_entry, |
goetz@6458 | 2036 | &StubRoutines::_safefetch32_fault_pc, |
goetz@6458 | 2037 | &StubRoutines::_safefetch32_continuation_pc); |
goetz@6458 | 2038 | generate_safefetch("SafeFetchN", sizeof(intptr_t), &StubRoutines::_safefetchN_entry, |
goetz@6458 | 2039 | &StubRoutines::_safefetchN_fault_pc, |
goetz@6458 | 2040 | &StubRoutines::_safefetchN_continuation_pc); |
goetz@6458 | 2041 | } |
goetz@6458 | 2042 | |
goetz@6458 | 2043 | public: |
goetz@6458 | 2044 | StubGenerator(CodeBuffer* code, bool all) : StubCodeGenerator(code) { |
goetz@6458 | 2045 | // replace the standard masm with a special one: |
goetz@6458 | 2046 | _masm = new MacroAssembler(code); |
goetz@6458 | 2047 | if (all) { |
goetz@6458 | 2048 | generate_all(); |
goetz@6458 | 2049 | } else { |
goetz@6458 | 2050 | generate_initial(); |
goetz@6458 | 2051 | } |
goetz@6458 | 2052 | } |
goetz@6458 | 2053 | }; |
goetz@6458 | 2054 | |
goetz@6458 | 2055 | void StubGenerator_generate(CodeBuffer* code, bool all) { |
goetz@6458 | 2056 | StubGenerator g(code, all); |
goetz@6458 | 2057 | } |