1 /* 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 25 #include "precompiled.hpp" 26 #include "c1/c1_Defs.hpp" 27 #include "c1/c1_MacroAssembler.hpp" 28 #include "c1/c1_Runtime1.hpp" 29 #include "interpreter/interpreter.hpp" 30 #include "nativeInst_sparc.hpp" 31 #include "oops/compiledICHolderOop.hpp" 32 #include "oops/oop.inline.hpp" 33 #include "prims/jvmtiExport.hpp" 34 #include "register_sparc.hpp" 35 #include "runtime/sharedRuntime.hpp" 36 #include "runtime/signature.hpp" 37 #include "runtime/vframeArray.hpp" 38 #include "vmreg_sparc.inline.hpp" 39 40 // Implementation of StubAssembler 41 42 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry_point, int number_of_arguments) { 43 // for sparc changing the number of arguments doesn't change 44 // anything about the frame size so we'll always lie and claim that 45 // we are only passing 1 argument. 46 set_num_rt_args(1); 47 48 assert_not_delayed(); 49 // bang stack before going to runtime 50 set(-os::vm_page_size() + STACK_BIAS, G3_scratch); 51 st(G0, SP, G3_scratch); 52 53 // debugging support 54 assert(number_of_arguments >= 0 , "cannot have negative number of arguments"); 55 56 set_last_Java_frame(SP, noreg); 57 if (VerifyThread) mov(G2_thread, O0); // about to be smashed; pass early 58 save_thread(L7_thread_cache); 59 // do the call 60 call(entry_point, relocInfo::runtime_call_type); 61 if (!VerifyThread) { 62 delayed()->mov(G2_thread, O0); // pass thread as first argument 63 } else { 64 delayed()->nop(); // (thread already passed) 65 } 66 int call_offset = offset(); // offset of return address 67 restore_thread(L7_thread_cache); 68 reset_last_Java_frame(); 69 70 // check for pending exceptions 71 { Label L; 72 Address exception_addr(G2_thread, Thread::pending_exception_offset()); 73 ld_ptr(exception_addr, Gtemp); 74 br_null_short(Gtemp, pt, L); 75 Address vm_result_addr(G2_thread, JavaThread::vm_result_offset()); 76 st_ptr(G0, vm_result_addr); 77 Address vm_result_addr_2(G2_thread, JavaThread::vm_result_2_offset()); 78 st_ptr(G0, vm_result_addr_2); 79 80 if (frame_size() == no_frame_size) { 81 // we use O7 linkage so that forward_exception_entry has the issuing PC 82 call(StubRoutines::forward_exception_entry(), relocInfo::runtime_call_type); 83 delayed()->restore(); 84 } else if (_stub_id == Runtime1::forward_exception_id) { 85 should_not_reach_here(); 86 } else { 87 AddressLiteral exc(Runtime1::entry_for(Runtime1::forward_exception_id)); 88 jump_to(exc, G4); 89 delayed()->nop(); 90 } 91 bind(L); 92 } 93 94 // get oop result if there is one and reset the value in the thread 95 if (oop_result1->is_valid()) { // get oop result if there is one and reset it in the thread 96 get_vm_result (oop_result1); 97 } else { 98 // be a little paranoid and clear the result 99 Address vm_result_addr(G2_thread, JavaThread::vm_result_offset()); 100 st_ptr(G0, vm_result_addr); 101 } 102 103 if (oop_result2->is_valid()) { 104 get_vm_result_2(oop_result2); 105 } else { 106 // be a little paranoid and clear the result 107 Address vm_result_addr_2(G2_thread, JavaThread::vm_result_2_offset()); 108 st_ptr(G0, vm_result_addr_2); 109 } 110 111 return call_offset; 112 } 113 114 115 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1) { 116 // O0 is reserved for the thread 117 mov(arg1, O1); 118 return call_RT(oop_result1, oop_result2, entry, 1); 119 } 120 121 122 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1, Register arg2) { 123 // O0 is reserved for the thread 124 mov(arg1, O1); 125 mov(arg2, O2); assert(arg2 != O1, "smashed argument"); 126 return call_RT(oop_result1, oop_result2, entry, 2); 127 } 128 129 130 int StubAssembler::call_RT(Register oop_result1, Register oop_result2, address entry, Register arg1, Register arg2, Register arg3) { 131 // O0 is reserved for the thread 132 mov(arg1, O1); 133 mov(arg2, O2); assert(arg2 != O1, "smashed argument"); 134 mov(arg3, O3); assert(arg3 != O1 && arg3 != O2, "smashed argument"); 135 return call_RT(oop_result1, oop_result2, entry, 3); 136 } 137 138 139 // Implementation of Runtime1 140 141 #define __ sasm-> 142 143 static int cpu_reg_save_offsets[FrameMap::nof_cpu_regs]; 144 static int fpu_reg_save_offsets[FrameMap::nof_fpu_regs]; 145 static int reg_save_size_in_words; 146 static int frame_size_in_bytes = -1; 147 148 static OopMap* generate_oop_map(StubAssembler* sasm, bool save_fpu_registers) { 149 assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words), 150 "mismatch in calculation"); 151 sasm->set_frame_size(frame_size_in_bytes / BytesPerWord); 152 int frame_size_in_slots = frame_size_in_bytes / sizeof(jint); 153 OopMap* oop_map = new OopMap(frame_size_in_slots, 0); 154 155 int i; 156 for (i = 0; i < FrameMap::nof_cpu_regs; i++) { 157 Register r = as_Register(i); 158 if (r == G1 || r == G3 || r == G4 || r == G5) { 159 int sp_offset = cpu_reg_save_offsets[i]; 160 oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset), 161 r->as_VMReg()); 162 } 163 } 164 165 if (save_fpu_registers) { 166 for (i = 0; i < FrameMap::nof_fpu_regs; i++) { 167 FloatRegister r = as_FloatRegister(i); 168 int sp_offset = fpu_reg_save_offsets[i]; 169 oop_map->set_callee_saved(VMRegImpl::stack2reg(sp_offset), 170 r->as_VMReg()); 171 } 172 } 173 return oop_map; 174 } 175 176 static OopMap* save_live_registers(StubAssembler* sasm, bool save_fpu_registers = true) { 177 assert(frame_size_in_bytes == __ total_frame_size_in_bytes(reg_save_size_in_words), 178 "mismatch in calculation"); 179 __ save_frame_c1(frame_size_in_bytes); 180 181 // Record volatile registers as callee-save values in an OopMap so their save locations will be 182 // propagated to the caller frame's RegisterMap during StackFrameStream construction (needed for 183 // deoptimization; see compiledVFrame::create_stack_value). The caller's I, L and O registers 184 // are saved in register windows - I's and L's in the caller's frame and O's in the stub frame 185 // (as the stub's I's) when the runtime routine called by the stub creates its frame. 186 // OopMap frame sizes are in c2 stack slot sizes (sizeof(jint)) 187 188 int i; 189 for (i = 0; i < FrameMap::nof_cpu_regs; i++) { 190 Register r = as_Register(i); 191 if (r == G1 || r == G3 || r == G4 || r == G5) { 192 int sp_offset = cpu_reg_save_offsets[i]; 193 __ st_ptr(r, SP, (sp_offset * BytesPerWord) + STACK_BIAS); 194 } 195 } 196 197 if (save_fpu_registers) { 198 for (i = 0; i < FrameMap::nof_fpu_regs; i++) { 199 FloatRegister r = as_FloatRegister(i); 200 int sp_offset = fpu_reg_save_offsets[i]; 201 __ stf(FloatRegisterImpl::S, r, SP, (sp_offset * BytesPerWord) + STACK_BIAS); 202 } 203 } 204 205 return generate_oop_map(sasm, save_fpu_registers); 206 } 207 208 static void restore_live_registers(StubAssembler* sasm, bool restore_fpu_registers = true) { 209 for (int i = 0; i < FrameMap::nof_cpu_regs; i++) { 210 Register r = as_Register(i); 211 if (r == G1 || r == G3 || r == G4 || r == G5) { 212 __ ld_ptr(SP, (cpu_reg_save_offsets[i] * BytesPerWord) + STACK_BIAS, r); 213 } 214 } 215 216 if (restore_fpu_registers) { 217 for (int i = 0; i < FrameMap::nof_fpu_regs; i++) { 218 FloatRegister r = as_FloatRegister(i); 219 __ ldf(FloatRegisterImpl::S, SP, (fpu_reg_save_offsets[i] * BytesPerWord) + STACK_BIAS, r); 220 } 221 } 222 } 223 224 225 void Runtime1::initialize_pd() { 226 // compute word offsets from SP at which live (non-windowed) registers are captured by stub routines 227 // 228 // A stub routine will have a frame that is at least large enough to hold 229 // a register window save area (obviously) and the volatile g registers 230 // and floating registers. A user of save_live_registers can have a frame 231 // that has more scratch area in it (although typically they will use L-regs). 232 // in that case the frame will look like this (stack growing down) 233 // 234 // FP -> | | 235 // | scratch mem | 236 // | " " | 237 // -------------- 238 // | float regs | 239 // | " " | 240 // --------------- 241 // | G regs | 242 // | " " | 243 // --------------- 244 // | abi reg. | 245 // | window save | 246 // | area | 247 // SP -> --------------- 248 // 249 int i; 250 int sp_offset = round_to(frame::register_save_words, 2); // start doubleword aligned 251 252 // only G int registers are saved explicitly; others are found in register windows 253 for (i = 0; i < FrameMap::nof_cpu_regs; i++) { 254 Register r = as_Register(i); 255 if (r == G1 || r == G3 || r == G4 || r == G5) { 256 cpu_reg_save_offsets[i] = sp_offset; 257 sp_offset++; 258 } 259 } 260 261 // all float registers are saved explicitly 262 assert(FrameMap::nof_fpu_regs == 32, "double registers not handled here"); 263 for (i = 0; i < FrameMap::nof_fpu_regs; i++) { 264 fpu_reg_save_offsets[i] = sp_offset; 265 sp_offset++; 266 } 267 reg_save_size_in_words = sp_offset - frame::memory_parameter_word_sp_offset; 268 // this should match assembler::total_frame_size_in_bytes, which 269 // isn't callable from this context. It's checked by an assert when 270 // it's used though. 271 frame_size_in_bytes = align_size_up(sp_offset * wordSize, 8); 272 } 273 274 275 OopMapSet* Runtime1::generate_exception_throw(StubAssembler* sasm, address target, bool has_argument) { 276 // make a frame and preserve the caller's caller-save registers 277 OopMap* oop_map = save_live_registers(sasm); 278 int call_offset; 279 if (!has_argument) { 280 call_offset = __ call_RT(noreg, noreg, target); 281 } else { 282 call_offset = __ call_RT(noreg, noreg, target, G4); 283 } 284 OopMapSet* oop_maps = new OopMapSet(); 285 oop_maps->add_gc_map(call_offset, oop_map); 286 287 __ should_not_reach_here(); 288 return oop_maps; 289 } 290 291 292 OopMapSet* Runtime1::generate_stub_call(StubAssembler* sasm, Register result, address target, 293 Register arg1, Register arg2, Register arg3) { 294 // make a frame and preserve the caller's caller-save registers 295 OopMap* oop_map = save_live_registers(sasm); 296 297 int call_offset; 298 if (arg1 == noreg) { 299 call_offset = __ call_RT(result, noreg, target); 300 } else if (arg2 == noreg) { 301 call_offset = __ call_RT(result, noreg, target, arg1); 302 } else if (arg3 == noreg) { 303 call_offset = __ call_RT(result, noreg, target, arg1, arg2); 304 } else { 305 call_offset = __ call_RT(result, noreg, target, arg1, arg2, arg3); 306 } 307 OopMapSet* oop_maps = NULL; 308 309 oop_maps = new OopMapSet(); 310 oop_maps->add_gc_map(call_offset, oop_map); 311 restore_live_registers(sasm); 312 313 __ ret(); 314 __ delayed()->restore(); 315 316 return oop_maps; 317 } 318 319 320 OopMapSet* Runtime1::generate_patching(StubAssembler* sasm, address target) { 321 // make a frame and preserve the caller's caller-save registers 322 OopMap* oop_map = save_live_registers(sasm); 323 324 // call the runtime patching routine, returns non-zero if nmethod got deopted. 325 int call_offset = __ call_RT(noreg, noreg, target); 326 OopMapSet* oop_maps = new OopMapSet(); 327 oop_maps->add_gc_map(call_offset, oop_map); 328 329 // re-execute the patched instruction or, if the nmethod was deoptmized, return to the 330 // deoptimization handler entry that will cause re-execution of the current bytecode 331 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob(); 332 assert(deopt_blob != NULL, "deoptimization blob must have been created"); 333 334 Label no_deopt; 335 __ br_null_short(O0, Assembler::pt, no_deopt); 336 337 // return to the deoptimization handler entry for unpacking and rexecute 338 // if we simply returned the we'd deopt as if any call we patched had just 339 // returned. 340 341 restore_live_registers(sasm); 342 343 AddressLiteral dest(deopt_blob->unpack_with_reexecution()); 344 __ jump_to(dest, O0); 345 __ delayed()->restore(); 346 347 __ bind(no_deopt); 348 restore_live_registers(sasm); 349 __ ret(); 350 __ delayed()->restore(); 351 352 return oop_maps; 353 } 354 355 OopMapSet* Runtime1::generate_code_for(StubID id, StubAssembler* sasm) { 356 357 OopMapSet* oop_maps = NULL; 358 // for better readability 359 const bool must_gc_arguments = true; 360 const bool dont_gc_arguments = false; 361 362 // stub code & info for the different stubs 363 switch (id) { 364 case forward_exception_id: 365 { 366 oop_maps = generate_handle_exception(id, sasm); 367 } 368 break; 369 370 case new_instance_id: 371 case fast_new_instance_id: 372 case fast_new_instance_init_check_id: 373 { 374 Register G5_klass = G5; // Incoming 375 Register O0_obj = O0; // Outgoing 376 377 if (id == new_instance_id) { 378 __ set_info("new_instance", dont_gc_arguments); 379 } else if (id == fast_new_instance_id) { 380 __ set_info("fast new_instance", dont_gc_arguments); 381 } else { 382 assert(id == fast_new_instance_init_check_id, "bad StubID"); 383 __ set_info("fast new_instance init check", dont_gc_arguments); 384 } 385 386 if ((id == fast_new_instance_id || id == fast_new_instance_init_check_id) && 387 UseTLAB && FastTLABRefill) { 388 Label slow_path; 389 Register G1_obj_size = G1; 390 Register G3_t1 = G3; 391 Register G4_t2 = G4; 392 assert_different_registers(G5_klass, G1_obj_size, G3_t1, G4_t2); 393 394 // Push a frame since we may do dtrace notification for the 395 // allocation which requires calling out and we don't want 396 // to stomp the real return address. 397 __ save_frame(0); 398 399 if (id == fast_new_instance_init_check_id) { 400 // make sure the klass is initialized 401 __ ld(G5_klass, in_bytes(instanceKlass::init_state_offset()), G3_t1); 402 __ cmp_and_br_short(G3_t1, instanceKlass::fully_initialized, Assembler::notEqual, Assembler::pn, slow_path); 403 } 404 #ifdef ASSERT 405 // assert object can be fast path allocated 406 { 407 Label ok, not_ok; 408 __ ld(G5_klass, in_bytes(Klass::layout_helper_offset()), G1_obj_size); 409 // make sure it's an instance (LH > 0) 410 __ cmp_and_br_short(G1_obj_size, 0, Assembler::lessEqual, Assembler::pn, not_ok); 411 __ btst(Klass::_lh_instance_slow_path_bit, G1_obj_size); 412 __ br(Assembler::zero, false, Assembler::pn, ok); 413 __ delayed()->nop(); 414 __ bind(not_ok); 415 __ stop("assert(can be fast path allocated)"); 416 __ should_not_reach_here(); 417 __ bind(ok); 418 } 419 #endif // ASSERT 420 // if we got here then the TLAB allocation failed, so try 421 // refilling the TLAB or allocating directly from eden. 422 Label retry_tlab, try_eden; 423 __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves G5_klass 424 425 __ bind(retry_tlab); 426 427 // get the instance size 428 __ ld(G5_klass, in_bytes(Klass::layout_helper_offset()), G1_obj_size); 429 430 __ tlab_allocate(O0_obj, G1_obj_size, 0, G3_t1, slow_path); 431 432 __ initialize_object(O0_obj, G5_klass, G1_obj_size, 0, G3_t1, G4_t2); 433 __ verify_oop(O0_obj); 434 __ mov(O0, I0); 435 __ ret(); 436 __ delayed()->restore(); 437 438 __ bind(try_eden); 439 // get the instance size 440 __ ld(G5_klass, in_bytes(Klass::layout_helper_offset()), G1_obj_size); 441 __ eden_allocate(O0_obj, G1_obj_size, 0, G3_t1, G4_t2, slow_path); 442 __ incr_allocated_bytes(G1_obj_size, G3_t1, G4_t2); 443 444 __ initialize_object(O0_obj, G5_klass, G1_obj_size, 0, G3_t1, G4_t2); 445 __ verify_oop(O0_obj); 446 __ mov(O0, I0); 447 __ ret(); 448 __ delayed()->restore(); 449 450 __ bind(slow_path); 451 452 // pop this frame so generate_stub_call can push it's own 453 __ restore(); 454 } 455 456 oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_instance), G5_klass); 457 // I0->O0: new instance 458 } 459 460 break; 461 462 case counter_overflow_id: 463 // G4 contains bci, G5 contains method 464 oop_maps = generate_stub_call(sasm, noreg, CAST_FROM_FN_PTR(address, counter_overflow), G4, G5); 465 break; 466 467 case new_type_array_id: 468 case new_object_array_id: 469 { 470 Register G5_klass = G5; // Incoming 471 Register G4_length = G4; // Incoming 472 Register O0_obj = O0; // Outgoing 473 474 Address klass_lh(G5_klass, Klass::layout_helper_offset()); 475 assert(Klass::_lh_header_size_shift % BitsPerByte == 0, "bytewise"); 476 assert(Klass::_lh_header_size_mask == 0xFF, "bytewise"); 477 // Use this offset to pick out an individual byte of the layout_helper: 478 const int klass_lh_header_size_offset = ((BytesPerInt - 1) // 3 - 2 selects byte {0,1,0,0} 479 - Klass::_lh_header_size_shift / BitsPerByte); 480 481 if (id == new_type_array_id) { 482 __ set_info("new_type_array", dont_gc_arguments); 483 } else { 484 __ set_info("new_object_array", dont_gc_arguments); 485 } 486 487 #ifdef ASSERT 488 // assert object type is really an array of the proper kind 489 { 490 Label ok; 491 Register G3_t1 = G3; 492 __ ld(klass_lh, G3_t1); 493 __ sra(G3_t1, Klass::_lh_array_tag_shift, G3_t1); 494 int tag = ((id == new_type_array_id) 495 ? Klass::_lh_array_tag_type_value 496 : Klass::_lh_array_tag_obj_value); 497 __ cmp_and_brx_short(G3_t1, tag, Assembler::equal, Assembler::pt, ok); 498 __ stop("assert(is an array klass)"); 499 __ should_not_reach_here(); 500 __ bind(ok); 501 } 502 #endif // ASSERT 503 504 if (UseTLAB && FastTLABRefill) { 505 Label slow_path; 506 Register G1_arr_size = G1; 507 Register G3_t1 = G3; 508 Register O1_t2 = O1; 509 assert_different_registers(G5_klass, G4_length, G1_arr_size, G3_t1, O1_t2); 510 511 // check that array length is small enough for fast path 512 __ set(C1_MacroAssembler::max_array_allocation_length, G3_t1); 513 __ cmp_and_br_short(G4_length, G3_t1, Assembler::greaterUnsigned, Assembler::pn, slow_path); 514 515 // if we got here then the TLAB allocation failed, so try 516 // refilling the TLAB or allocating directly from eden. 517 Label retry_tlab, try_eden; 518 __ tlab_refill(retry_tlab, try_eden, slow_path); // preserves G4_length and G5_klass 519 520 __ bind(retry_tlab); 521 522 // get the allocation size: (length << (layout_helper & 0x1F)) + header_size 523 __ ld(klass_lh, G3_t1); 524 __ sll(G4_length, G3_t1, G1_arr_size); 525 __ srl(G3_t1, Klass::_lh_header_size_shift, G3_t1); 526 __ and3(G3_t1, Klass::_lh_header_size_mask, G3_t1); 527 __ add(G1_arr_size, G3_t1, G1_arr_size); 528 __ add(G1_arr_size, MinObjAlignmentInBytesMask, G1_arr_size); // align up 529 __ and3(G1_arr_size, ~MinObjAlignmentInBytesMask, G1_arr_size); 530 531 __ tlab_allocate(O0_obj, G1_arr_size, 0, G3_t1, slow_path); // preserves G1_arr_size 532 533 __ initialize_header(O0_obj, G5_klass, G4_length, G3_t1, O1_t2); 534 __ ldub(klass_lh, G3_t1, klass_lh_header_size_offset); 535 __ sub(G1_arr_size, G3_t1, O1_t2); // body length 536 __ add(O0_obj, G3_t1, G3_t1); // body start 537 __ initialize_body(G3_t1, O1_t2); 538 __ verify_oop(O0_obj); 539 __ retl(); 540 __ delayed()->nop(); 541 542 __ bind(try_eden); 543 // get the allocation size: (length << (layout_helper & 0x1F)) + header_size 544 __ ld(klass_lh, G3_t1); 545 __ sll(G4_length, G3_t1, G1_arr_size); 546 __ srl(G3_t1, Klass::_lh_header_size_shift, G3_t1); 547 __ and3(G3_t1, Klass::_lh_header_size_mask, G3_t1); 548 __ add(G1_arr_size, G3_t1, G1_arr_size); 549 __ add(G1_arr_size, MinObjAlignmentInBytesMask, G1_arr_size); 550 __ and3(G1_arr_size, ~MinObjAlignmentInBytesMask, G1_arr_size); 551 552 __ eden_allocate(O0_obj, G1_arr_size, 0, G3_t1, O1_t2, slow_path); // preserves G1_arr_size 553 __ incr_allocated_bytes(G1_arr_size, G3_t1, O1_t2); 554 555 __ initialize_header(O0_obj, G5_klass, G4_length, G3_t1, O1_t2); 556 __ ldub(klass_lh, G3_t1, klass_lh_header_size_offset); 557 __ sub(G1_arr_size, G3_t1, O1_t2); // body length 558 __ add(O0_obj, G3_t1, G3_t1); // body start 559 __ initialize_body(G3_t1, O1_t2); 560 __ verify_oop(O0_obj); 561 __ retl(); 562 __ delayed()->nop(); 563 564 __ bind(slow_path); 565 } 566 567 if (id == new_type_array_id) { 568 oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_type_array), G5_klass, G4_length); 569 } else { 570 oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_object_array), G5_klass, G4_length); 571 } 572 // I0 -> O0: new array 573 } 574 break; 575 576 case new_multi_array_id: 577 { // O0: klass 578 // O1: rank 579 // O2: address of 1st dimension 580 __ set_info("new_multi_array", dont_gc_arguments); 581 oop_maps = generate_stub_call(sasm, I0, CAST_FROM_FN_PTR(address, new_multi_array), I0, I1, I2); 582 // I0 -> O0: new multi array 583 } 584 break; 585 586 case register_finalizer_id: 587 { 588 __ set_info("register_finalizer", dont_gc_arguments); 589 590 // load the klass and check the has finalizer flag 591 Label register_finalizer; 592 Register t = O1; 593 __ load_klass(O0, t); 594 __ ld(t, in_bytes(Klass::access_flags_offset()), t); 595 __ set(JVM_ACC_HAS_FINALIZER, G3); 596 __ andcc(G3, t, G0); 597 __ br(Assembler::notZero, false, Assembler::pt, register_finalizer); 598 __ delayed()->nop(); 599 600 // do a leaf return 601 __ retl(); 602 __ delayed()->nop(); 603 604 __ bind(register_finalizer); 605 OopMap* oop_map = save_live_registers(sasm); 606 int call_offset = __ call_RT(noreg, noreg, 607 CAST_FROM_FN_PTR(address, SharedRuntime::register_finalizer), I0); 608 oop_maps = new OopMapSet(); 609 oop_maps->add_gc_map(call_offset, oop_map); 610 611 // Now restore all the live registers 612 restore_live_registers(sasm); 613 614 __ ret(); 615 __ delayed()->restore(); 616 } 617 break; 618 619 case throw_range_check_failed_id: 620 { __ set_info("range_check_failed", dont_gc_arguments); // arguments will be discarded 621 // G4: index 622 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_range_check_exception), true); 623 } 624 break; 625 626 case throw_index_exception_id: 627 { __ set_info("index_range_check_failed", dont_gc_arguments); // arguments will be discarded 628 // G4: index 629 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_index_exception), true); 630 } 631 break; 632 633 case throw_div0_exception_id: 634 { __ set_info("throw_div0_exception", dont_gc_arguments); 635 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_div0_exception), false); 636 } 637 break; 638 639 case throw_null_pointer_exception_id: 640 { __ set_info("throw_null_pointer_exception", dont_gc_arguments); 641 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_null_pointer_exception), false); 642 } 643 break; 644 645 case handle_exception_id: 646 { __ set_info("handle_exception", dont_gc_arguments); 647 oop_maps = generate_handle_exception(id, sasm); 648 } 649 break; 650 651 case handle_exception_from_callee_id: 652 { __ set_info("handle_exception_from_callee", dont_gc_arguments); 653 oop_maps = generate_handle_exception(id, sasm); 654 } 655 break; 656 657 case unwind_exception_id: 658 { 659 // O0: exception 660 // I7: address of call to this method 661 662 __ set_info("unwind_exception", dont_gc_arguments); 663 __ mov(Oexception, Oexception->after_save()); 664 __ add(I7, frame::pc_return_offset, Oissuing_pc->after_save()); 665 666 __ call_VM_leaf(L7_thread_cache, CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), 667 G2_thread, Oissuing_pc->after_save()); 668 __ verify_not_null_oop(Oexception->after_save()); 669 670 // Restore SP from L7 if the exception PC is a method handle call site. 671 __ mov(O0, G5); // Save the target address. 672 __ lduw(Address(G2_thread, JavaThread::is_method_handle_return_offset()), L0); 673 __ tst(L0); // Condition codes are preserved over the restore. 674 __ restore(); 675 676 __ jmp(G5, 0); 677 __ delayed()->movcc(Assembler::notZero, false, Assembler::icc, L7_mh_SP_save, SP); // Restore SP if required. 678 } 679 break; 680 681 case throw_array_store_exception_id: 682 { 683 __ set_info("throw_array_store_exception", dont_gc_arguments); 684 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_array_store_exception), true); 685 } 686 break; 687 688 case throw_class_cast_exception_id: 689 { 690 // G4: object 691 __ set_info("throw_class_cast_exception", dont_gc_arguments); 692 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_class_cast_exception), true); 693 } 694 break; 695 696 case throw_incompatible_class_change_error_id: 697 { 698 __ set_info("throw_incompatible_class_cast_exception", dont_gc_arguments); 699 oop_maps = generate_exception_throw(sasm, CAST_FROM_FN_PTR(address, throw_incompatible_class_change_error), false); 700 } 701 break; 702 703 case slow_subtype_check_id: 704 { // Support for uint StubRoutine::partial_subtype_check( Klass sub, Klass super ); 705 // Arguments : 706 // 707 // ret : G3 708 // sub : G3, argument, destroyed 709 // super: G1, argument, not changed 710 // raddr: O7, blown by call 711 Label miss; 712 713 __ save_frame(0); // Blow no registers! 714 715 __ check_klass_subtype_slow_path(G3, G1, L0, L1, L2, L4, NULL, &miss); 716 717 __ mov(1, G3); 718 __ ret(); // Result in G5 is 'true' 719 __ delayed()->restore(); // free copy or add can go here 720 721 __ bind(miss); 722 __ mov(0, G3); 723 __ ret(); // Result in G5 is 'false' 724 __ delayed()->restore(); // free copy or add can go here 725 } 726 727 case monitorenter_nofpu_id: 728 case monitorenter_id: 729 { // G4: object 730 // G5: lock address 731 __ set_info("monitorenter", dont_gc_arguments); 732 733 int save_fpu_registers = (id == monitorenter_id); 734 // make a frame and preserve the caller's caller-save registers 735 OopMap* oop_map = save_live_registers(sasm, save_fpu_registers); 736 737 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorenter), G4, G5); 738 739 oop_maps = new OopMapSet(); 740 oop_maps->add_gc_map(call_offset, oop_map); 741 restore_live_registers(sasm, save_fpu_registers); 742 743 __ ret(); 744 __ delayed()->restore(); 745 } 746 break; 747 748 case monitorexit_nofpu_id: 749 case monitorexit_id: 750 { // G4: lock address 751 // note: really a leaf routine but must setup last java sp 752 // => use call_RT for now (speed can be improved by 753 // doing last java sp setup manually) 754 __ set_info("monitorexit", dont_gc_arguments); 755 756 int save_fpu_registers = (id == monitorexit_id); 757 // make a frame and preserve the caller's caller-save registers 758 OopMap* oop_map = save_live_registers(sasm, save_fpu_registers); 759 760 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, monitorexit), G4); 761 762 oop_maps = new OopMapSet(); 763 oop_maps->add_gc_map(call_offset, oop_map); 764 restore_live_registers(sasm, save_fpu_registers); 765 766 __ ret(); 767 __ delayed()->restore(); 768 } 769 break; 770 771 case deoptimize_id: 772 { 773 __ set_info("deoptimize", dont_gc_arguments); 774 OopMap* oop_map = save_live_registers(sasm); 775 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, deoptimize)); 776 oop_maps = new OopMapSet(); 777 oop_maps->add_gc_map(call_offset, oop_map); 778 restore_live_registers(sasm); 779 DeoptimizationBlob* deopt_blob = SharedRuntime::deopt_blob(); 780 assert(deopt_blob != NULL, "deoptimization blob must have been created"); 781 AddressLiteral dest(deopt_blob->unpack_with_reexecution()); 782 __ jump_to(dest, O0); 783 __ delayed()->restore(); 784 } 785 break; 786 787 case access_field_patching_id: 788 { __ set_info("access_field_patching", dont_gc_arguments); 789 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, access_field_patching)); 790 } 791 break; 792 793 case load_klass_patching_id: 794 { __ set_info("load_klass_patching", dont_gc_arguments); 795 oop_maps = generate_patching(sasm, CAST_FROM_FN_PTR(address, move_klass_patching)); 796 } 797 break; 798 799 case dtrace_object_alloc_id: 800 { // O0: object 801 __ set_info("dtrace_object_alloc", dont_gc_arguments); 802 // we can't gc here so skip the oopmap but make sure that all 803 // the live registers get saved. 804 save_live_registers(sasm); 805 806 __ save_thread(L7_thread_cache); 807 __ call(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_object_alloc), 808 relocInfo::runtime_call_type); 809 __ delayed()->mov(I0, O0); 810 __ restore_thread(L7_thread_cache); 811 812 restore_live_registers(sasm); 813 __ ret(); 814 __ delayed()->restore(); 815 } 816 break; 817 818 #ifndef SERIALGC 819 case g1_pre_barrier_slow_id: 820 { // G4: previous value of memory 821 BarrierSet* bs = Universe::heap()->barrier_set(); 822 if (bs->kind() != BarrierSet::G1SATBCTLogging) { 823 __ save_frame(0); 824 __ set((int)id, O1); 825 __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), I0); 826 __ should_not_reach_here(); 827 break; 828 } 829 830 __ set_info("g1_pre_barrier_slow_id", dont_gc_arguments); 831 832 Register pre_val = G4; 833 Register tmp = G1_scratch; 834 Register tmp2 = G3_scratch; 835 836 Label refill, restart; 837 bool with_frame = false; // I don't know if we can do with-frame. 838 int satb_q_index_byte_offset = 839 in_bytes(JavaThread::satb_mark_queue_offset() + 840 PtrQueue::byte_offset_of_index()); 841 int satb_q_buf_byte_offset = 842 in_bytes(JavaThread::satb_mark_queue_offset() + 843 PtrQueue::byte_offset_of_buf()); 844 845 __ bind(restart); 846 // Load the index into the SATB buffer. PtrQueue::_index is a 847 // size_t so ld_ptr is appropriate 848 __ ld_ptr(G2_thread, satb_q_index_byte_offset, tmp); 849 850 // index == 0? 851 __ cmp_and_brx_short(tmp, G0, Assembler::equal, Assembler::pn, refill); 852 853 __ ld_ptr(G2_thread, satb_q_buf_byte_offset, tmp2); 854 __ sub(tmp, oopSize, tmp); 855 856 __ st_ptr(pre_val, tmp2, tmp); // [_buf + index] := <address_of_card> 857 // Use return-from-leaf 858 __ retl(); 859 __ delayed()->st_ptr(tmp, G2_thread, satb_q_index_byte_offset); 860 861 __ bind(refill); 862 __ save_frame(0); 863 864 __ mov(pre_val, L0); 865 __ mov(tmp, L1); 866 __ mov(tmp2, L2); 867 868 __ call_VM_leaf(L7_thread_cache, 869 CAST_FROM_FN_PTR(address, 870 SATBMarkQueueSet::handle_zero_index_for_thread), 871 G2_thread); 872 873 __ mov(L0, pre_val); 874 __ mov(L1, tmp); 875 __ mov(L2, tmp2); 876 877 __ br(Assembler::always, /*annul*/false, Assembler::pt, restart); 878 __ delayed()->restore(); 879 } 880 break; 881 882 case g1_post_barrier_slow_id: 883 { 884 BarrierSet* bs = Universe::heap()->barrier_set(); 885 if (bs->kind() != BarrierSet::G1SATBCTLogging) { 886 __ save_frame(0); 887 __ set((int)id, O1); 888 __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), I0); 889 __ should_not_reach_here(); 890 break; 891 } 892 893 __ set_info("g1_post_barrier_slow_id", dont_gc_arguments); 894 895 Register addr = G4; 896 Register cardtable = G5; 897 Register tmp = G1_scratch; 898 Register tmp2 = G3_scratch; 899 jbyte* byte_map_base = ((CardTableModRefBS*)bs)->byte_map_base; 900 901 Label not_already_dirty, restart, refill; 902 903 #ifdef _LP64 904 __ srlx(addr, CardTableModRefBS::card_shift, addr); 905 #else 906 __ srl(addr, CardTableModRefBS::card_shift, addr); 907 #endif 908 909 AddressLiteral rs(byte_map_base); 910 __ set(rs, cardtable); // cardtable := <card table base> 911 __ ldub(addr, cardtable, tmp); // tmp := [addr + cardtable] 912 913 assert(CardTableModRefBS::dirty_card_val() == 0, "otherwise check this code"); 914 __ cmp_and_br_short(tmp, G0, Assembler::notEqual, Assembler::pt, not_already_dirty); 915 916 // We didn't take the branch, so we're already dirty: return. 917 // Use return-from-leaf 918 __ retl(); 919 __ delayed()->nop(); 920 921 // Not dirty. 922 __ bind(not_already_dirty); 923 924 // Get cardtable + tmp into a reg by itself 925 __ add(addr, cardtable, tmp2); 926 927 // First, dirty it. 928 __ stb(G0, tmp2, 0); // [cardPtr] := 0 (i.e., dirty). 929 930 Register tmp3 = cardtable; 931 Register tmp4 = tmp; 932 933 // these registers are now dead 934 addr = cardtable = tmp = noreg; 935 936 int dirty_card_q_index_byte_offset = 937 in_bytes(JavaThread::dirty_card_queue_offset() + 938 PtrQueue::byte_offset_of_index()); 939 int dirty_card_q_buf_byte_offset = 940 in_bytes(JavaThread::dirty_card_queue_offset() + 941 PtrQueue::byte_offset_of_buf()); 942 943 __ bind(restart); 944 945 // Get the index into the update buffer. PtrQueue::_index is 946 // a size_t so ld_ptr is appropriate here. 947 __ ld_ptr(G2_thread, dirty_card_q_index_byte_offset, tmp3); 948 949 // index == 0? 950 __ cmp_and_brx_short(tmp3, G0, Assembler::equal, Assembler::pn, refill); 951 952 __ ld_ptr(G2_thread, dirty_card_q_buf_byte_offset, tmp4); 953 __ sub(tmp3, oopSize, tmp3); 954 955 __ st_ptr(tmp2, tmp4, tmp3); // [_buf + index] := <address_of_card> 956 // Use return-from-leaf 957 __ retl(); 958 __ delayed()->st_ptr(tmp3, G2_thread, dirty_card_q_index_byte_offset); 959 960 __ bind(refill); 961 __ save_frame(0); 962 963 __ mov(tmp2, L0); 964 __ mov(tmp3, L1); 965 __ mov(tmp4, L2); 966 967 __ call_VM_leaf(L7_thread_cache, 968 CAST_FROM_FN_PTR(address, 969 DirtyCardQueueSet::handle_zero_index_for_thread), 970 G2_thread); 971 972 __ mov(L0, tmp2); 973 __ mov(L1, tmp3); 974 __ mov(L2, tmp4); 975 976 __ br(Assembler::always, /*annul*/false, Assembler::pt, restart); 977 __ delayed()->restore(); 978 } 979 break; 980 #endif // !SERIALGC 981 982 default: 983 { __ set_info("unimplemented entry", dont_gc_arguments); 984 __ save_frame(0); 985 __ set((int)id, O1); 986 __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, unimplemented_entry), O1); 987 __ should_not_reach_here(); 988 } 989 break; 990 } 991 return oop_maps; 992 } 993 994 995 OopMapSet* Runtime1::generate_handle_exception(StubID id, StubAssembler* sasm) { 996 __ block_comment("generate_handle_exception"); 997 998 // Save registers, if required. 999 OopMapSet* oop_maps = new OopMapSet(); 1000 OopMap* oop_map = NULL; 1001 switch (id) { 1002 case forward_exception_id: 1003 // We're handling an exception in the context of a compiled frame. 1004 // The registers have been saved in the standard places. Perform 1005 // an exception lookup in the caller and dispatch to the handler 1006 // if found. Otherwise unwind and dispatch to the callers 1007 // exception handler. 1008 oop_map = generate_oop_map(sasm, true); 1009 1010 // transfer the pending exception to the exception_oop 1011 __ ld_ptr(G2_thread, in_bytes(JavaThread::pending_exception_offset()), Oexception); 1012 __ ld_ptr(Oexception, 0, G0); 1013 __ st_ptr(G0, G2_thread, in_bytes(JavaThread::pending_exception_offset())); 1014 __ add(I7, frame::pc_return_offset, Oissuing_pc); 1015 break; 1016 case handle_exception_id: 1017 // At this point all registers MAY be live. 1018 oop_map = save_live_registers(sasm); 1019 __ mov(Oexception->after_save(), Oexception); 1020 __ mov(Oissuing_pc->after_save(), Oissuing_pc); 1021 break; 1022 case handle_exception_from_callee_id: 1023 // At this point all registers except exception oop (Oexception) 1024 // and exception pc (Oissuing_pc) are dead. 1025 oop_map = new OopMap(frame_size_in_bytes / sizeof(jint), 0); 1026 sasm->set_frame_size(frame_size_in_bytes / BytesPerWord); 1027 __ save_frame_c1(frame_size_in_bytes); 1028 __ mov(Oexception->after_save(), Oexception); 1029 __ mov(Oissuing_pc->after_save(), Oissuing_pc); 1030 break; 1031 default: ShouldNotReachHere(); 1032 } 1033 1034 __ verify_not_null_oop(Oexception); 1035 1036 // save the exception and issuing pc in the thread 1037 __ st_ptr(Oexception, G2_thread, in_bytes(JavaThread::exception_oop_offset())); 1038 __ st_ptr(Oissuing_pc, G2_thread, in_bytes(JavaThread::exception_pc_offset())); 1039 1040 // use the throwing pc as the return address to lookup (has bci & oop map) 1041 __ mov(Oissuing_pc, I7); 1042 __ sub(I7, frame::pc_return_offset, I7); 1043 int call_offset = __ call_RT(noreg, noreg, CAST_FROM_FN_PTR(address, exception_handler_for_pc)); 1044 oop_maps->add_gc_map(call_offset, oop_map); 1045 1046 // Note: if nmethod has been deoptimized then regardless of 1047 // whether it had a handler or not we will deoptimize 1048 // by entering the deopt blob with a pending exception. 1049 1050 // Restore the registers that were saved at the beginning, remove 1051 // the frame and jump to the exception handler. 1052 switch (id) { 1053 case forward_exception_id: 1054 case handle_exception_id: 1055 restore_live_registers(sasm); 1056 __ jmp(O0, 0); 1057 __ delayed()->restore(); 1058 break; 1059 case handle_exception_from_callee_id: 1060 // Restore SP from L7 if the exception PC is a method handle call site. 1061 __ mov(O0, G5); // Save the target address. 1062 __ lduw(Address(G2_thread, JavaThread::is_method_handle_return_offset()), L0); 1063 __ tst(L0); // Condition codes are preserved over the restore. 1064 __ restore(); 1065 1066 __ jmp(G5, 0); // jump to the exception handler 1067 __ delayed()->movcc(Assembler::notZero, false, Assembler::icc, L7_mh_SP_save, SP); // Restore SP if required. 1068 break; 1069 default: ShouldNotReachHere(); 1070 } 1071 1072 return oop_maps; 1073 } 1074 1075 1076 #undef __ 1077 1078 const char *Runtime1::pd_name_for_address(address entry) { 1079 return "<unknown function>"; 1080 }