1 /* 2 * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2012, 2017 SAP AG. All rights reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #include "precompiled.hpp" 27 #include "asm/macroAssembler.inline.hpp" 28 #include "interpreter/bytecodeHistogram.hpp" 29 #include "interpreter/interpreter.hpp" 30 #include "interpreter/interpreterGenerator.hpp" 31 #include "interpreter/interpreterRuntime.hpp" 32 #include "interpreter/templateTable.hpp" 33 #include "oops/arrayOop.hpp" 34 #include "oops/methodData.hpp" 35 #include "oops/method.hpp" 36 #include "oops/oop.inline.hpp" 37 #include "prims/jvmtiExport.hpp" 38 #include "prims/jvmtiThreadState.hpp" 39 #include "prims/methodHandles.hpp" 40 #include "runtime/arguments.hpp" 41 #include "runtime/deoptimization.hpp" 42 #include "runtime/frame.inline.hpp" 43 #include "runtime/sharedRuntime.hpp" 44 #include "runtime/stubRoutines.hpp" 45 #include "runtime/synchronizer.hpp" 46 #include "runtime/timer.hpp" 47 #include "runtime/vframeArray.hpp" 48 #include "utilities/debug.hpp" 49 #ifdef COMPILER1 50 #include "c1/c1_Runtime1.hpp" 51 #endif 52 53 #define __ _masm-> 54 55 #ifdef PRODUCT 56 #define BLOCK_COMMENT(str) // nothing 57 #else 58 #define BLOCK_COMMENT(str) __ block_comment(str) 59 #endif 60 61 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") 62 63 int AbstractInterpreter::BasicType_as_index(BasicType type) { 64 int i = 0; 65 switch (type) { 66 case T_BOOLEAN: i = 0; break; 67 case T_CHAR : i = 1; break; 68 case T_BYTE : i = 2; break; 69 case T_SHORT : i = 3; break; 70 case T_INT : i = 4; break; 71 case T_LONG : i = 5; break; 72 case T_VOID : i = 6; break; 73 case T_FLOAT : i = 7; break; 74 case T_DOUBLE : i = 8; break; 75 case T_OBJECT : i = 9; break; 76 case T_ARRAY : i = 9; break; 77 default : ShouldNotReachHere(); 78 } 79 assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds"); 80 return i; 81 } 82 83 address AbstractInterpreterGenerator::generate_slow_signature_handler() { 84 // Slow_signature handler that respects the PPC C calling conventions. 85 // 86 // We get called by the native entry code with our output register 87 // area == 8. First we call InterpreterRuntime::get_result_handler 88 // to copy the pointer to the signature string temporarily to the 89 // first C-argument and to return the result_handler in 90 // R3_RET. Since native_entry will copy the jni-pointer to the 91 // first C-argument slot later on, it is OK to occupy this slot 92 // temporarilly. Then we copy the argument list on the java 93 // expression stack into native varargs format on the native stack 94 // and load arguments into argument registers. Integer arguments in 95 // the varargs vector will be sign-extended to 8 bytes. 96 // 97 // On entry: 98 // R3_ARG1 - intptr_t* Address of java argument list in memory. 99 // R15_prev_state - BytecodeInterpreter* Address of interpreter state for 100 // this method 101 // R19_method 102 // 103 // On exit (just before return instruction): 104 // R3_RET - contains the address of the result_handler. 105 // R4_ARG2 - is not updated for static methods and contains "this" otherwise. 106 // R5_ARG3-R10_ARG8: - When the (i-2)th Java argument is not of type float or double, 107 // ARGi contains this argument. Otherwise, ARGi is not updated. 108 // F1_ARG1-F13_ARG13 - contain the first 13 arguments of type float or double. 109 110 const int LogSizeOfTwoInstructions = 3; 111 112 // FIXME: use Argument:: GL: Argument names different numbers! 113 const int max_fp_register_arguments = 13; 114 const int max_int_register_arguments = 6; // first 2 are reserved 115 116 const Register arg_java = R21_tmp1; 117 const Register arg_c = R22_tmp2; 118 const Register signature = R23_tmp3; // is string 119 const Register sig_byte = R24_tmp4; 120 const Register fpcnt = R25_tmp5; 121 const Register argcnt = R26_tmp6; 122 const Register intSlot = R27_tmp7; 123 const Register target_sp = R28_tmp8; 124 const FloatRegister floatSlot = F0; 125 126 address entry = __ function_entry(); 127 128 __ save_LR_CR(R0); 129 __ save_nonvolatile_gprs(R1_SP, _spill_nonvolatiles_neg(r14)); 130 // We use target_sp for storing arguments in the C frame. 131 __ mr(target_sp, R1_SP); 132 __ push_frame_reg_args_nonvolatiles(0, R11_scratch1); 133 134 __ mr(arg_java, R3_ARG1); 135 136 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_signature), R16_thread, R19_method); 137 138 // Signature is in R3_RET. Signature is callee saved. 139 __ mr(signature, R3_RET); 140 141 // Get the result handler. 142 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_result_handler), R16_thread, R19_method); 143 144 { 145 Label L; 146 // test if static 147 // _access_flags._flags must be at offset 0. 148 // TODO PPC port: requires change in shared code. 149 //assert(in_bytes(AccessFlags::flags_offset()) == 0, 150 // "MethodDesc._access_flags == MethodDesc._access_flags._flags"); 151 // _access_flags must be a 32 bit value. 152 assert(sizeof(AccessFlags) == 4, "wrong size"); 153 __ lwa(R11_scratch1/*access_flags*/, method_(access_flags)); 154 // testbit with condition register. 155 __ testbitdi(CCR0, R0, R11_scratch1/*access_flags*/, JVM_ACC_STATIC_BIT); 156 __ btrue(CCR0, L); 157 // For non-static functions, pass "this" in R4_ARG2 and copy it 158 // to 2nd C-arg slot. 159 // We need to box the Java object here, so we use arg_java 160 // (address of current Java stack slot) as argument and don't 161 // dereference it as in case of ints, floats, etc. 162 __ mr(R4_ARG2, arg_java); 163 __ addi(arg_java, arg_java, -BytesPerWord); 164 __ std(R4_ARG2, _abi(carg_2), target_sp); 165 __ bind(L); 166 } 167 168 // Will be incremented directly after loop_start. argcnt=0 169 // corresponds to 3rd C argument. 170 __ li(argcnt, -1); 171 // arg_c points to 3rd C argument 172 __ addi(arg_c, target_sp, _abi(carg_3)); 173 // no floating-point args parsed so far 174 __ li(fpcnt, 0); 175 176 Label move_intSlot_to_ARG, move_floatSlot_to_FARG; 177 Label loop_start, loop_end; 178 Label do_int, do_long, do_float, do_double, do_dontreachhere, do_object, do_array, do_boxed; 179 180 // signature points to '(' at entry 181 #ifdef ASSERT 182 __ lbz(sig_byte, 0, signature); 183 __ cmplwi(CCR0, sig_byte, '('); 184 __ bne(CCR0, do_dontreachhere); 185 #endif 186 187 __ bind(loop_start); 188 189 __ addi(argcnt, argcnt, 1); 190 __ lbzu(sig_byte, 1, signature); 191 192 __ cmplwi(CCR0, sig_byte, ')'); // end of signature 193 __ beq(CCR0, loop_end); 194 195 __ cmplwi(CCR0, sig_byte, 'B'); // byte 196 __ beq(CCR0, do_int); 197 198 __ cmplwi(CCR0, sig_byte, 'C'); // char 199 __ beq(CCR0, do_int); 200 201 __ cmplwi(CCR0, sig_byte, 'D'); // double 202 __ beq(CCR0, do_double); 203 204 __ cmplwi(CCR0, sig_byte, 'F'); // float 205 __ beq(CCR0, do_float); 206 207 __ cmplwi(CCR0, sig_byte, 'I'); // int 208 __ beq(CCR0, do_int); 209 210 __ cmplwi(CCR0, sig_byte, 'J'); // long 211 __ beq(CCR0, do_long); 212 213 __ cmplwi(CCR0, sig_byte, 'S'); // short 214 __ beq(CCR0, do_int); 215 216 __ cmplwi(CCR0, sig_byte, 'Z'); // boolean 217 __ beq(CCR0, do_int); 218 219 __ cmplwi(CCR0, sig_byte, 'L'); // object 220 __ beq(CCR0, do_object); 221 222 __ cmplwi(CCR0, sig_byte, '['); // array 223 __ beq(CCR0, do_array); 224 225 // __ cmplwi(CCR0, sig_byte, 'V'); // void cannot appear since we do not parse the return type 226 // __ beq(CCR0, do_void); 227 228 __ bind(do_dontreachhere); 229 230 __ unimplemented("ShouldNotReachHere in slow_signature_handler", 120); 231 232 __ bind(do_array); 233 234 { 235 Label start_skip, end_skip; 236 237 __ bind(start_skip); 238 __ lbzu(sig_byte, 1, signature); 239 __ cmplwi(CCR0, sig_byte, '['); 240 __ beq(CCR0, start_skip); // skip further brackets 241 __ cmplwi(CCR0, sig_byte, '9'); 242 __ bgt(CCR0, end_skip); // no optional size 243 __ cmplwi(CCR0, sig_byte, '0'); 244 __ bge(CCR0, start_skip); // skip optional size 245 __ bind(end_skip); 246 247 __ cmplwi(CCR0, sig_byte, 'L'); 248 __ beq(CCR0, do_object); // for arrays of objects, the name of the object must be skipped 249 __ b(do_boxed); // otherwise, go directly to do_boxed 250 } 251 252 __ bind(do_object); 253 { 254 Label L; 255 __ bind(L); 256 __ lbzu(sig_byte, 1, signature); 257 __ cmplwi(CCR0, sig_byte, ';'); 258 __ bne(CCR0, L); 259 } 260 // Need to box the Java object here, so we use arg_java (address of 261 // current Java stack slot) as argument and don't dereference it as 262 // in case of ints, floats, etc. 263 Label do_null; 264 __ bind(do_boxed); 265 __ ld(R0,0, arg_java); 266 __ cmpdi(CCR0, R0, 0); 267 __ li(intSlot,0); 268 __ beq(CCR0, do_null); 269 __ mr(intSlot, arg_java); 270 __ bind(do_null); 271 __ std(intSlot, 0, arg_c); 272 __ addi(arg_java, arg_java, -BytesPerWord); 273 __ addi(arg_c, arg_c, BytesPerWord); 274 __ cmplwi(CCR0, argcnt, max_int_register_arguments); 275 __ blt(CCR0, move_intSlot_to_ARG); 276 __ b(loop_start); 277 278 __ bind(do_int); 279 __ lwa(intSlot, 0, arg_java); 280 __ std(intSlot, 0, arg_c); 281 __ addi(arg_java, arg_java, -BytesPerWord); 282 __ addi(arg_c, arg_c, BytesPerWord); 283 __ cmplwi(CCR0, argcnt, max_int_register_arguments); 284 __ blt(CCR0, move_intSlot_to_ARG); 285 __ b(loop_start); 286 287 __ bind(do_long); 288 __ ld(intSlot, -BytesPerWord, arg_java); 289 __ std(intSlot, 0, arg_c); 290 __ addi(arg_java, arg_java, - 2 * BytesPerWord); 291 __ addi(arg_c, arg_c, BytesPerWord); 292 __ cmplwi(CCR0, argcnt, max_int_register_arguments); 293 __ blt(CCR0, move_intSlot_to_ARG); 294 __ b(loop_start); 295 296 __ bind(do_float); 297 __ lfs(floatSlot, 0, arg_java); 298 #if defined(LINUX) 299 // Linux uses ELF ABI. Both original ELF and ELFv2 ABIs have float 300 // in the least significant word of an argument slot. 301 #if defined(VM_LITTLE_ENDIAN) 302 __ stfs(floatSlot, 0, arg_c); 303 #else 304 __ stfs(floatSlot, 4, arg_c); 305 #endif 306 #elif defined(AIX) 307 // Although AIX runs on big endian CPU, float is in most significant 308 // word of an argument slot. 309 __ stfs(floatSlot, 0, arg_c); 310 #else 311 #error "unknown OS" 312 #endif 313 __ addi(arg_java, arg_java, -BytesPerWord); 314 __ addi(arg_c, arg_c, BytesPerWord); 315 __ cmplwi(CCR0, fpcnt, max_fp_register_arguments); 316 __ blt(CCR0, move_floatSlot_to_FARG); 317 __ b(loop_start); 318 319 __ bind(do_double); 320 __ lfd(floatSlot, - BytesPerWord, arg_java); 321 __ stfd(floatSlot, 0, arg_c); 322 __ addi(arg_java, arg_java, - 2 * BytesPerWord); 323 __ addi(arg_c, arg_c, BytesPerWord); 324 __ cmplwi(CCR0, fpcnt, max_fp_register_arguments); 325 __ blt(CCR0, move_floatSlot_to_FARG); 326 __ b(loop_start); 327 328 __ bind(loop_end); 329 330 __ pop_frame(); 331 __ restore_nonvolatile_gprs(R1_SP, _spill_nonvolatiles_neg(r14)); 332 __ restore_LR_CR(R0); 333 334 __ blr(); 335 336 Label move_int_arg, move_float_arg; 337 __ bind(move_int_arg); // each case must consist of 2 instructions (otherwise adapt LogSizeOfTwoInstructions) 338 __ mr(R5_ARG3, intSlot); __ b(loop_start); 339 __ mr(R6_ARG4, intSlot); __ b(loop_start); 340 __ mr(R7_ARG5, intSlot); __ b(loop_start); 341 __ mr(R8_ARG6, intSlot); __ b(loop_start); 342 __ mr(R9_ARG7, intSlot); __ b(loop_start); 343 __ mr(R10_ARG8, intSlot); __ b(loop_start); 344 345 __ bind(move_float_arg); // each case must consist of 2 instructions (otherwise adapt LogSizeOfTwoInstructions) 346 __ fmr(F1_ARG1, floatSlot); __ b(loop_start); 347 __ fmr(F2_ARG2, floatSlot); __ b(loop_start); 348 __ fmr(F3_ARG3, floatSlot); __ b(loop_start); 349 __ fmr(F4_ARG4, floatSlot); __ b(loop_start); 350 __ fmr(F5_ARG5, floatSlot); __ b(loop_start); 351 __ fmr(F6_ARG6, floatSlot); __ b(loop_start); 352 __ fmr(F7_ARG7, floatSlot); __ b(loop_start); 353 __ fmr(F8_ARG8, floatSlot); __ b(loop_start); 354 __ fmr(F9_ARG9, floatSlot); __ b(loop_start); 355 __ fmr(F10_ARG10, floatSlot); __ b(loop_start); 356 __ fmr(F11_ARG11, floatSlot); __ b(loop_start); 357 __ fmr(F12_ARG12, floatSlot); __ b(loop_start); 358 __ fmr(F13_ARG13, floatSlot); __ b(loop_start); 359 360 __ bind(move_intSlot_to_ARG); 361 __ sldi(R0, argcnt, LogSizeOfTwoInstructions); 362 __ load_const(R11_scratch1, move_int_arg); // Label must be bound here. 363 __ add(R11_scratch1, R0, R11_scratch1); 364 __ mtctr(R11_scratch1/*branch_target*/); 365 __ bctr(); 366 __ bind(move_floatSlot_to_FARG); 367 __ sldi(R0, fpcnt, LogSizeOfTwoInstructions); 368 __ addi(fpcnt, fpcnt, 1); 369 __ load_const(R11_scratch1, move_float_arg); // Label must be bound here. 370 __ add(R11_scratch1, R0, R11_scratch1); 371 __ mtctr(R11_scratch1/*branch_target*/); 372 __ bctr(); 373 374 return entry; 375 } 376 377 address AbstractInterpreterGenerator::generate_result_handler_for(BasicType type) { 378 // 379 // Registers alive 380 // R3_RET 381 // LR 382 // 383 // Registers updated 384 // R3_RET 385 // 386 387 Label done; 388 address entry = __ pc(); 389 390 switch (type) { 391 case T_BOOLEAN: 392 // convert !=0 to 1 393 __ neg(R0, R3_RET); 394 __ orr(R0, R3_RET, R0); 395 __ srwi(R3_RET, R0, 31); 396 break; 397 case T_BYTE: 398 // sign extend 8 bits 399 __ extsb(R3_RET, R3_RET); 400 break; 401 case T_CHAR: 402 // zero extend 16 bits 403 __ clrldi(R3_RET, R3_RET, 48); 404 break; 405 case T_SHORT: 406 // sign extend 16 bits 407 __ extsh(R3_RET, R3_RET); 408 break; 409 case T_INT: 410 // sign extend 32 bits 411 __ extsw(R3_RET, R3_RET); 412 break; 413 case T_LONG: 414 break; 415 case T_OBJECT: 416 // JNIHandles::resolve result. 417 __ resolve_jobject(R3_RET, R11_scratch1, R12_scratch2, /* needs_frame */ true); // kills R31 418 break; 419 case T_FLOAT: 420 break; 421 case T_DOUBLE: 422 break; 423 case T_VOID: 424 break; 425 default: ShouldNotReachHere(); 426 } 427 428 __ BIND(done); 429 __ blr(); 430 431 return entry; 432 } 433 434 // Abstract method entry. 435 // 436 address InterpreterGenerator::generate_abstract_entry(void) { 437 address entry = __ pc(); 438 439 // 440 // Registers alive 441 // R16_thread - JavaThread* 442 // R19_method - callee's method (method to be invoked) 443 // R1_SP - SP prepared such that caller's outgoing args are near top 444 // LR - return address to caller 445 // 446 // Stack layout at this point: 447 // 448 // 0 [TOP_IJAVA_FRAME_ABI] <-- R1_SP 449 // alignment (optional) 450 // [outgoing Java arguments] 451 // ... 452 // PARENT [PARENT_IJAVA_FRAME_ABI] 453 // ... 454 // 455 456 // Can't use call_VM here because we have not set up a new 457 // interpreter state. Make the call to the vm and make it look like 458 // our caller set up the JavaFrameAnchor. 459 __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/); 460 461 // Push a new C frame and save LR. 462 __ save_LR_CR(R0); 463 __ push_frame_reg_args(0, R11_scratch1); 464 465 // This is not a leaf but we have a JavaFrameAnchor now and we will 466 // check (create) exceptions afterward so this is ok. 467 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError), 468 R16_thread); 469 470 // Pop the C frame and restore LR. 471 __ pop_frame(); 472 __ restore_LR_CR(R0); 473 474 // Reset JavaFrameAnchor from call_VM_leaf above. 475 __ reset_last_Java_frame(); 476 477 #ifdef CC_INTERP 478 // Return to frame manager, it will handle the pending exception. 479 __ blr(); 480 #else 481 // We don't know our caller, so jump to the general forward exception stub, 482 // which will also pop our full frame off. Satisfy the interface of 483 // SharedRuntime::generate_forward_exception() 484 __ load_const_optimized(R11_scratch1, StubRoutines::forward_exception_entry(), R0); 485 __ mtctr(R11_scratch1); 486 __ bctr(); 487 #endif 488 489 return entry; 490 } 491 492 // Call an accessor method (assuming it is resolved, otherwise drop into 493 // vanilla (slow path) entry. 494 address InterpreterGenerator::generate_accessor_entry(void) { 495 if (!UseFastAccessorMethods && (!FLAG_IS_ERGO(UseFastAccessorMethods))) { 496 return NULL; 497 } 498 499 Label Lslow_path, Lacquire; 500 501 const Register 502 Rclass_or_obj = R3_ARG1, 503 Rconst_method = R4_ARG2, 504 Rcodes = Rconst_method, 505 Rcpool_cache = R5_ARG3, 506 Rscratch = R11_scratch1, 507 Rjvmti_mode = Rscratch, 508 Roffset = R12_scratch2, 509 Rflags = R6_ARG4, 510 Rbtable = R7_ARG5; 511 512 static address branch_table[number_of_states]; 513 514 address entry = __ pc(); 515 516 // Check for safepoint: 517 // Ditch this, real man don't need safepoint checks. 518 519 // Also check for JVMTI mode 520 // Check for null obj, take slow path if so. 521 __ ld(Rclass_or_obj, Interpreter::stackElementSize, CC_INTERP_ONLY(R17_tos) NOT_CC_INTERP(R15_esp)); 522 __ lwz(Rjvmti_mode, thread_(interp_only_mode)); 523 __ cmpdi(CCR1, Rclass_or_obj, 0); 524 __ cmpwi(CCR0, Rjvmti_mode, 0); 525 __ crorc(/*CCR0 eq*/2, /*CCR1 eq*/4+2, /*CCR0 eq*/2); 526 __ beq(CCR0, Lslow_path); // this==null or jvmti_mode!=0 527 528 // Do 2 things in parallel: 529 // 1. Load the index out of the first instruction word, which looks like this: 530 // <0x2a><0xb4><index (2 byte, native endianess)>. 531 // 2. Load constant pool cache base. 532 __ ld(Rconst_method, in_bytes(Method::const_offset()), R19_method); 533 __ ld(Rcpool_cache, in_bytes(ConstMethod::constants_offset()), Rconst_method); 534 535 __ lhz(Rcodes, in_bytes(ConstMethod::codes_offset()) + 2, Rconst_method); // Lower half of 32 bit field. 536 __ ld(Rcpool_cache, ConstantPool::cache_offset_in_bytes(), Rcpool_cache); 537 538 // Get the const pool entry by means of <index>. 539 const int codes_shift = exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord); 540 __ slwi(Rscratch, Rcodes, codes_shift); // (codes&0xFFFF)<<codes_shift 541 __ add(Rcpool_cache, Rscratch, Rcpool_cache); 542 543 // Check if cpool cache entry is resolved. 544 // We are resolved if the indices offset contains the current bytecode. 545 ByteSize cp_base_offset = ConstantPoolCache::base_offset(); 546 // Big Endian: 547 __ lbz(Rscratch, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::indices_offset()) + 7 - 2, Rcpool_cache); 548 __ cmpwi(CCR0, Rscratch, Bytecodes::_getfield); 549 __ bne(CCR0, Lslow_path); 550 __ isync(); // Order succeeding loads wrt. load of _indices field from cpool_cache. 551 552 // Finally, start loading the value: Get cp cache entry into regs. 553 __ ld(Rflags, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::flags_offset()), Rcpool_cache); 554 __ ld(Roffset, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::f2_offset()), Rcpool_cache); 555 556 // Following code is from templateTable::getfield_or_static 557 // Load pointer to branch table 558 __ load_const_optimized(Rbtable, (address)branch_table, Rscratch); 559 560 // Get volatile flag 561 __ rldicl(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // extract volatile bit 562 // note: sync is needed before volatile load on PPC64 563 564 // Check field type 565 __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits); 566 567 #ifdef ASSERT 568 Label LFlagInvalid; 569 __ cmpldi(CCR0, Rflags, number_of_states); 570 __ bge(CCR0, LFlagInvalid); 571 572 __ ld(R9_ARG7, 0, R1_SP); 573 __ ld(R10_ARG8, 0, R21_sender_SP); 574 __ cmpd(CCR0, R9_ARG7, R10_ARG8); 575 __ asm_assert_eq("backlink", 0x543); 576 #endif // ASSERT 577 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started. 578 579 // Load from branch table and dispatch (volatile case: one instruction ahead) 580 __ sldi(Rflags, Rflags, LogBytesPerWord); 581 __ cmpwi(CCR6, Rscratch, 1); // volatile? 582 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { 583 __ sldi(Rscratch, Rscratch, exact_log2(BytesPerInstWord)); // volatile ? size of 1 instruction : 0 584 } 585 __ ldx(Rbtable, Rbtable, Rflags); 586 587 if (support_IRIW_for_not_multiple_copy_atomic_cpu) { 588 __ subf(Rbtable, Rscratch, Rbtable); // point to volatile/non-volatile entry point 589 } 590 __ mtctr(Rbtable); 591 __ bctr(); 592 593 #ifdef ASSERT 594 __ bind(LFlagInvalid); 595 __ stop("got invalid flag", 0x6541); 596 597 bool all_uninitialized = true, 598 all_initialized = true; 599 for (int i = 0; i<number_of_states; ++i) { 600 all_uninitialized = all_uninitialized && (branch_table[i] == NULL); 601 all_initialized = all_initialized && (branch_table[i] != NULL); 602 } 603 assert(all_uninitialized != all_initialized, "consistency"); // either or 604 605 __ fence(); // volatile entry point (one instruction before non-volatile_entry point) 606 if (branch_table[vtos] == 0) branch_table[vtos] = __ pc(); // non-volatile_entry point 607 if (branch_table[dtos] == 0) branch_table[dtos] = __ pc(); // non-volatile_entry point 608 if (branch_table[ftos] == 0) branch_table[ftos] = __ pc(); // non-volatile_entry point 609 __ stop("unexpected type", 0x6551); 610 #endif 611 612 if (branch_table[itos] == 0) { // generate only once 613 __ align(32, 28, 28); // align load 614 __ fence(); // volatile entry point (one instruction before non-volatile_entry point) 615 branch_table[itos] = __ pc(); // non-volatile_entry point 616 __ lwax(R3_RET, Rclass_or_obj, Roffset); 617 __ beq(CCR6, Lacquire); 618 __ blr(); 619 } 620 621 if (branch_table[ltos] == 0) { // generate only once 622 __ align(32, 28, 28); // align load 623 __ fence(); // volatile entry point (one instruction before non-volatile_entry point) 624 branch_table[ltos] = __ pc(); // non-volatile_entry point 625 __ ldx(R3_RET, Rclass_or_obj, Roffset); 626 __ beq(CCR6, Lacquire); 627 __ blr(); 628 } 629 630 if (branch_table[btos] == 0) { // generate only once 631 __ align(32, 28, 28); // align load 632 __ fence(); // volatile entry point (one instruction before non-volatile_entry point) 633 branch_table[btos] = __ pc(); // non-volatile_entry point 634 __ lbzx(R3_RET, Rclass_or_obj, Roffset); 635 __ extsb(R3_RET, R3_RET); 636 __ beq(CCR6, Lacquire); 637 __ blr(); 638 } 639 640 if (branch_table[ztos] == 0) { // generate only once 641 __ align(32, 28, 28); // align load 642 __ fence(); // volatile entry point (one instruction before non-volatile_entry point) 643 branch_table[ztos] = __ pc(); // non-volatile_entry point 644 __ lbzx(R3_RET, Rclass_or_obj, Roffset); 645 __ extsb(R3_RET, R3_RET); 646 __ beq(CCR6, Lacquire); 647 __ blr(); 648 } 649 650 if (branch_table[ctos] == 0) { // generate only once 651 __ align(32, 28, 28); // align load 652 __ fence(); // volatile entry point (one instruction before non-volatile_entry point) 653 branch_table[ctos] = __ pc(); // non-volatile_entry point 654 __ lhzx(R3_RET, Rclass_or_obj, Roffset); 655 __ beq(CCR6, Lacquire); 656 __ blr(); 657 } 658 659 if (branch_table[stos] == 0) { // generate only once 660 __ align(32, 28, 28); // align load 661 __ fence(); // volatile entry point (one instruction before non-volatile_entry point) 662 branch_table[stos] = __ pc(); // non-volatile_entry point 663 __ lhax(R3_RET, Rclass_or_obj, Roffset); 664 __ beq(CCR6, Lacquire); 665 __ blr(); 666 } 667 668 if (branch_table[atos] == 0) { // generate only once 669 __ align(32, 28, 28); // align load 670 __ fence(); // volatile entry point (one instruction before non-volatile_entry point) 671 branch_table[atos] = __ pc(); // non-volatile_entry point 672 __ load_heap_oop(R3_RET, (RegisterOrConstant)Roffset, Rclass_or_obj); 673 __ verify_oop(R3_RET); 674 //__ dcbt(R3_RET); // prefetch 675 __ beq(CCR6, Lacquire); 676 __ blr(); 677 } 678 679 __ align(32, 12); 680 __ bind(Lacquire); 681 __ twi_0(R3_RET); 682 __ isync(); // acquire 683 __ blr(); 684 685 #ifdef ASSERT 686 for (int i = 0; i<number_of_states; ++i) { 687 assert(branch_table[i], "accessor_entry initialization"); 688 //tty->print_cr("accessor_entry: branch_table[%d] = 0x%llx (opcode 0x%llx)", i, branch_table[i], *((unsigned int*)branch_table[i])); 689 } 690 #endif 691 692 __ bind(Lslow_path); 693 __ branch_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals), Rscratch); 694 __ flush(); 695 696 return entry; 697 } 698 699 // Interpreter intrinsic for WeakReference.get(). 700 // 1. Don't push a full blown frame and go on dispatching, but fetch the value 701 // into R8 and return quickly 702 // 2. If G1 is active we *must* execute this intrinsic for corrrectness: 703 // It contains a GC barrier which puts the reference into the satb buffer 704 // to indicate that someone holds a strong reference to the object the 705 // weak ref points to! 706 address InterpreterGenerator::generate_Reference_get_entry(void) { 707 // Code: _aload_0, _getfield, _areturn 708 // parameter size = 1 709 // 710 // The code that gets generated by this routine is split into 2 parts: 711 // 1. the "intrinsified" code for G1 (or any SATB based GC), 712 // 2. the slow path - which is an expansion of the regular method entry. 713 // 714 // Notes: 715 // * In the G1 code we do not check whether we need to block for 716 // a safepoint. If G1 is enabled then we must execute the specialized 717 // code for Reference.get (except when the Reference object is null) 718 // so that we can log the value in the referent field with an SATB 719 // update buffer. 720 // If the code for the getfield template is modified so that the 721 // G1 pre-barrier code is executed when the current method is 722 // Reference.get() then going through the normal method entry 723 // will be fine. 724 // * The G1 code can, however, check the receiver object (the instance 725 // of java.lang.Reference) and jump to the slow path if null. If the 726 // Reference object is null then we obviously cannot fetch the referent 727 // and so we don't need to call the G1 pre-barrier. Thus we can use the 728 // regular method entry code to generate the NPE. 729 // 730 // This code is based on generate_accessor_enty. 731 732 address entry = __ pc(); 733 734 const int referent_offset = java_lang_ref_Reference::referent_offset; 735 guarantee(referent_offset > 0, "referent offset not initialized"); 736 737 if (UseG1GC) { 738 Label slow_path; 739 740 // Debugging not possible, so can't use __ skip_if_jvmti_mode(slow_path, GR31_SCRATCH); 741 742 // In the G1 code we don't check if we need to reach a safepoint. We 743 // continue and the thread will safepoint at the next bytecode dispatch. 744 745 // If the receiver is null then it is OK to jump to the slow path. 746 __ ld(R3_RET, Interpreter::stackElementSize, CC_INTERP_ONLY(R17_tos) NOT_CC_INTERP(R15_esp)); // get receiver 747 748 // Check if receiver == NULL and go the slow path. 749 __ cmpdi(CCR0, R3_RET, 0); 750 __ beq(CCR0, slow_path); 751 752 // Load the value of the referent field. 753 __ load_heap_oop(R3_RET, referent_offset, R3_RET); 754 755 // Generate the G1 pre-barrier code to log the value of 756 // the referent field in an SATB buffer. Note with 757 // these parameters the pre-barrier does not generate 758 // the load of the previous value. 759 760 // Restore caller sp for c2i case. 761 #ifdef ASSERT 762 __ ld(R9_ARG7, 0, R1_SP); 763 __ ld(R10_ARG8, 0, R21_sender_SP); 764 __ cmpd(CCR0, R9_ARG7, R10_ARG8); 765 __ asm_assert_eq("backlink", 0x544); 766 #endif // ASSERT 767 __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started. 768 769 __ g1_write_barrier_pre(noreg, // obj 770 noreg, // offset 771 R3_RET, // pre_val 772 R11_scratch1, // tmp 773 R12_scratch2, // tmp 774 true); // needs_frame 775 776 __ blr(); 777 778 // Generate regular method entry. 779 __ bind(slow_path); 780 __ branch_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals), R11_scratch1); 781 __ flush(); 782 783 return entry; 784 } else { 785 return generate_accessor_entry(); 786 } 787 } 788 789 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) { 790 // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in 791 // the days we had adapter frames. When we deoptimize a situation where a 792 // compiled caller calls a compiled caller will have registers it expects 793 // to survive the call to the callee. If we deoptimize the callee the only 794 // way we can restore these registers is to have the oldest interpreter 795 // frame that we create restore these values. That is what this routine 796 // will accomplish. 797 798 // At the moment we have modified c2 to not have any callee save registers 799 // so this problem does not exist and this routine is just a place holder. 800 801 assert(f->is_interpreted_frame(), "must be interpreted"); 802 }