1 /* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2016 SAP SE. 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/abstractInterpreter.hpp" 29 #include "interpreter/bytecodeHistogram.hpp" 30 #include "interpreter/interpreter.hpp" 31 #include "interpreter/interpreterRuntime.hpp" 32 #include "interpreter/interp_masm.hpp" 33 #include "interpreter/templateInterpreterGenerator.hpp" 34 #include "interpreter/templateTable.hpp" 35 #include "oops/arrayOop.hpp" 36 #include "oops/oop.inline.hpp" 37 #include "prims/jvmtiExport.hpp" 38 #include "prims/jvmtiThreadState.hpp" 39 #include "runtime/arguments.hpp" 40 #include "runtime/deoptimization.hpp" 41 #include "runtime/frame.inline.hpp" 42 #include "runtime/sharedRuntime.hpp" 43 #include "runtime/stubRoutines.hpp" 44 #include "runtime/synchronizer.hpp" 45 #include "runtime/timer.hpp" 46 #include "runtime/vframeArray.hpp" 47 #include "utilities/debug.hpp" 48 49 50 // Size of interpreter code. Increase if too small. Interpreter will 51 // fail with a guarantee ("not enough space for interpreter generation"); 52 // if too small. 53 // Run with +PrintInterpreter to get the VM to print out the size. 54 // Max size with JVMTI 55 int TemplateInterpreter::InterpreterCodeSize = 320*K; 56 57 #undef __ 58 #ifdef PRODUCT 59 #define __ _masm-> 60 #else 61 #define __ _masm-> 62 // #define __ (Verbose ? (_masm->block_comment(FILE_AND_LINE),_masm):_masm)-> 63 #endif 64 65 #define BLOCK_COMMENT(str) __ block_comment(str) 66 #define BIND(label) __ bind(label); BLOCK_COMMENT(#label ":") 67 68 #define oop_tmp_offset _z_ijava_state_neg(oop_tmp) 69 70 //----------------------------------------------------------------------------- 71 72 address TemplateInterpreterGenerator::generate_slow_signature_handler() { 73 // 74 // New slow_signature handler that respects the z/Architecture 75 // C calling conventions. 76 // 77 // We get called by the native entry code with our output register 78 // area == 8. First we call InterpreterRuntime::get_result_handler 79 // to copy the pointer to the signature string temporarily to the 80 // first C-argument and to return the result_handler in 81 // Z_RET. Since native_entry will copy the jni-pointer to the 82 // first C-argument slot later on, it's OK to occupy this slot 83 // temporarily. Then we copy the argument list on the java 84 // expression stack into native varargs format on the native stack 85 // and load arguments into argument registers. Integer arguments in 86 // the varargs vector will be sign-extended to 8 bytes. 87 // 88 // On entry: 89 // Z_ARG1 - intptr_t* Address of java argument list in memory. 90 // Z_state - cppInterpreter* Address of interpreter state for 91 // this method 92 // Z_method 93 // 94 // On exit (just before return instruction): 95 // Z_RET contains the address of the result_handler. 96 // Z_ARG2 is not updated for static methods and contains "this" otherwise. 97 // Z_ARG3-Z_ARG5 contain the first 3 arguments of types other than float and double. 98 // Z_FARG1-Z_FARG4 contain the first 4 arguments of type float or double. 99 100 const int LogSizeOfCase = 3; 101 102 const int max_fp_register_arguments = Argument::n_float_register_parameters; 103 const int max_int_register_arguments = Argument::n_register_parameters - 2; // First 2 are reserved. 104 105 const Register arg_java = Z_tmp_2; 106 const Register arg_c = Z_tmp_3; 107 const Register signature = Z_R1_scratch; // Is a string. 108 const Register fpcnt = Z_R0_scratch; 109 const Register argcnt = Z_tmp_4; 110 const Register intSlot = Z_tmp_1; 111 const Register sig_end = Z_tmp_1; // Assumed end of signature (only used in do_object). 112 const Register target_sp = Z_tmp_1; 113 const FloatRegister floatSlot = Z_F1; 114 115 const int d_signature = _z_abi(gpr6); // Only spill space, register contents not affected. 116 const int d_fpcnt = _z_abi(gpr7); // Only spill space, register contents not affected. 117 118 unsigned int entry_offset = __ offset(); 119 120 BLOCK_COMMENT("slow_signature_handler {"); 121 122 // We use target_sp for storing arguments in the C frame. 123 __ save_return_pc(); 124 125 __ z_stmg(Z_R10,Z_R13,-32,Z_SP); 126 __ push_frame_abi160(32); 127 128 __ z_lgr(arg_java, Z_ARG1); 129 130 Register method = Z_ARG2; // Directly load into correct argument register. 131 132 __ get_method(method); 133 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_signature), Z_thread, method); 134 135 // Move signature to callee saved register. 136 // Don't directly write to stack. Frame is used by VM call. 137 __ z_lgr(Z_tmp_1, Z_RET); 138 139 // Reload method. Register may have been altered by VM call. 140 __ get_method(method); 141 142 // Get address of result handler. 143 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_result_handler), Z_thread, method); 144 145 // Save signature address to stack. 146 __ z_stg(Z_tmp_1, d_signature, Z_SP); 147 148 // Don't overwrite return value (Z_RET, Z_ARG1) in rest of the method ! 149 150 { 151 Label isStatic; 152 153 // Test if static. 154 // We can test the bit directly. 155 // Path is Z_method->_access_flags._flags. 156 // We only support flag bits in the least significant byte (assert !). 157 // Therefore add 3 to address that byte within "_flags". 158 // Reload method. VM call above may have destroyed register contents 159 __ get_method(method); 160 __ testbit(method2_(method, access_flags), JVM_ACC_STATIC_BIT); 161 method = noreg; // end of life 162 __ z_btrue(isStatic); 163 164 // For non-static functions, pass "this" in Z_ARG2 and copy it to 2nd C-arg slot. 165 // Need to box the Java object here, so we use arg_java 166 // (address of current Java stack slot) as argument and 167 // don't dereference it as in case of ints, floats, etc.. 168 __ z_lgr(Z_ARG2, arg_java); 169 __ add2reg(arg_java, -BytesPerWord); 170 __ bind(isStatic); 171 } 172 173 // argcnt == 0 corresponds to 3rd C argument. 174 // arg #1 (result handler) and 175 // arg #2 (this, for non-statics), unused else 176 // are reserved and pre-filled above. 177 // arg_java points to the corresponding Java argument here. It 178 // has been decremented by one argument (this) in case of non-static. 179 __ clear_reg(argcnt, true, false); // Don't set CC. 180 __ z_lg(target_sp, 0, Z_SP); 181 __ add2reg(arg_c, _z_abi(remaining_cargs), target_sp); 182 // No floating-point args parsed so far. 183 __ clear_mem(Address(Z_SP, d_fpcnt), 8); 184 185 NearLabel move_intSlot_to_ARG, move_floatSlot_to_FARG; 186 NearLabel loop_start, loop_start_restore, loop_end; 187 NearLabel do_int, do_long, do_float, do_double; 188 NearLabel do_dontreachhere, do_object, do_array, do_boxed; 189 190 #ifdef ASSERT 191 // Signature needs to point to '(' (== 0x28) at entry. 192 __ z_lg(signature, d_signature, Z_SP); 193 __ z_cli(0, signature, (int) '('); 194 __ z_brne(do_dontreachhere); 195 #endif 196 197 __ bind(loop_start_restore); 198 __ z_lg(signature, d_signature, Z_SP); // Restore signature ptr, destroyed by move_XX_to_ARG. 199 200 BIND(loop_start); 201 // Advance to next argument type token from the signature. 202 __ add2reg(signature, 1); 203 204 // Use CLI, works well on all CPU versions. 205 __ z_cli(0, signature, (int) ')'); 206 __ z_bre(loop_end); // end of signature 207 __ z_cli(0, signature, (int) 'L'); 208 __ z_bre(do_object); // object #9 209 __ z_cli(0, signature, (int) 'F'); 210 __ z_bre(do_float); // float #7 211 __ z_cli(0, signature, (int) 'J'); 212 __ z_bre(do_long); // long #6 213 __ z_cli(0, signature, (int) 'B'); 214 __ z_bre(do_int); // byte #1 215 __ z_cli(0, signature, (int) 'Z'); 216 __ z_bre(do_int); // boolean #2 217 __ z_cli(0, signature, (int) 'C'); 218 __ z_bre(do_int); // char #3 219 __ z_cli(0, signature, (int) 'S'); 220 __ z_bre(do_int); // short #4 221 __ z_cli(0, signature, (int) 'I'); 222 __ z_bre(do_int); // int #5 223 __ z_cli(0, signature, (int) 'D'); 224 __ z_bre(do_double); // double #8 225 __ z_cli(0, signature, (int) '['); 226 __ z_bre(do_array); // array #10 227 228 __ bind(do_dontreachhere); 229 230 __ unimplemented("ShouldNotReachHere in slow_signature_handler", 120); 231 232 // Array argument 233 BIND(do_array); 234 235 { 236 Label start_skip, end_skip; 237 238 __ bind(start_skip); 239 240 // Advance to next type tag from signature. 241 __ add2reg(signature, 1); 242 243 // Use CLI, works well on all CPU versions. 244 __ z_cli(0, signature, (int) '['); 245 __ z_bre(start_skip); // Skip further brackets. 246 247 __ z_cli(0, signature, (int) '9'); 248 __ z_brh(end_skip); // no optional size 249 250 __ z_cli(0, signature, (int) '0'); 251 __ z_brnl(start_skip); // Skip optional size. 252 253 __ bind(end_skip); 254 255 __ z_cli(0, signature, (int) 'L'); 256 __ z_brne(do_boxed); // If not array of objects: go directly to do_boxed. 257 } 258 259 // OOP argument 260 BIND(do_object); 261 // Pass by an object's type name. 262 { 263 Label L; 264 265 __ add2reg(sig_end, 4095, signature); // Assume object type name is shorter than 4k. 266 __ load_const_optimized(Z_R0, (int) ';'); // Type name terminator (must be in Z_R0!). 267 __ MacroAssembler::search_string(sig_end, signature); 268 __ z_brl(L); 269 __ z_illtrap(); // No semicolon found: internal error or object name too long. 270 __ bind(L); 271 __ z_lgr(signature, sig_end); 272 // fallthru to do_boxed 273 } 274 275 // Need to box the Java object here, so we use arg_java 276 // (address of current Java stack slot) as argument and 277 // don't dereference it as in case of ints, floats, etc.. 278 279 // UNBOX argument 280 // Load reference and check for NULL. 281 Label do_int_Entry4Boxed; 282 __ bind(do_boxed); 283 { 284 __ load_and_test_long(intSlot, Address(arg_java)); 285 __ z_bre(do_int_Entry4Boxed); 286 __ z_lgr(intSlot, arg_java); 287 __ z_bru(do_int_Entry4Boxed); 288 } 289 290 // INT argument 291 292 // (also for byte, boolean, char, short) 293 // Use lgf for load (sign-extend) and stg for store. 294 BIND(do_int); 295 __ z_lgf(intSlot, 0, arg_java); 296 297 __ bind(do_int_Entry4Boxed); 298 __ add2reg(arg_java, -BytesPerWord); 299 // If argument fits into argument register, go and handle it, otherwise continue. 300 __ compare32_and_branch(argcnt, max_int_register_arguments, 301 Assembler::bcondLow, move_intSlot_to_ARG); 302 __ z_stg(intSlot, 0, arg_c); 303 __ add2reg(arg_c, BytesPerWord); 304 __ z_bru(loop_start); 305 306 // LONG argument 307 308 BIND(do_long); 309 __ add2reg(arg_java, -2*BytesPerWord); // Decrement first to have positive displacement for lg. 310 __ z_lg(intSlot, BytesPerWord, arg_java); 311 // If argument fits into argument register, go and handle it, otherwise continue. 312 __ compare32_and_branch(argcnt, max_int_register_arguments, 313 Assembler::bcondLow, move_intSlot_to_ARG); 314 __ z_stg(intSlot, 0, arg_c); 315 __ add2reg(arg_c, BytesPerWord); 316 __ z_bru(loop_start); 317 318 // FLOAT argumen 319 320 BIND(do_float); 321 __ z_le(floatSlot, 0, arg_java); 322 __ add2reg(arg_java, -BytesPerWord); 323 assert(max_fp_register_arguments <= 255, "always true"); // safety net 324 __ z_cli(d_fpcnt+7, Z_SP, max_fp_register_arguments); 325 __ z_brl(move_floatSlot_to_FARG); 326 __ z_ste(floatSlot, 4, arg_c); 327 __ add2reg(arg_c, BytesPerWord); 328 __ z_bru(loop_start); 329 330 // DOUBLE argument 331 332 BIND(do_double); 333 __ add2reg(arg_java, -2*BytesPerWord); // Decrement first to have positive displacement for lg. 334 __ z_ld(floatSlot, BytesPerWord, arg_java); 335 assert(max_fp_register_arguments <= 255, "always true"); // safety net 336 __ z_cli(d_fpcnt+7, Z_SP, max_fp_register_arguments); 337 __ z_brl(move_floatSlot_to_FARG); 338 __ z_std(floatSlot, 0, arg_c); 339 __ add2reg(arg_c, BytesPerWord); 340 __ z_bru(loop_start); 341 342 // Method exit, all arguments proocessed. 343 __ bind(loop_end); 344 __ pop_frame(); 345 __ restore_return_pc(); 346 __ z_lmg(Z_R10,Z_R13,-32,Z_SP); 347 __ z_br(Z_R14); 348 349 // Copy int arguments. 350 351 Label iarg_caselist; // Distance between each case has to be a power of 2 352 // (= 1 << LogSizeOfCase). 353 __ align(16); 354 BIND(iarg_caselist); 355 __ z_lgr(Z_ARG3, intSlot); // 4 bytes 356 __ z_bru(loop_start_restore); // 4 bytes 357 358 __ z_lgr(Z_ARG4, intSlot); 359 __ z_bru(loop_start_restore); 360 361 __ z_lgr(Z_ARG5, intSlot); 362 __ z_bru(loop_start_restore); 363 364 __ align(16); 365 __ bind(move_intSlot_to_ARG); 366 __ z_stg(signature, d_signature, Z_SP); // Spill since signature == Z_R1_scratch. 367 __ z_larl(Z_R1_scratch, iarg_caselist); 368 __ z_sllg(Z_R0_scratch, argcnt, LogSizeOfCase); 369 __ add2reg(argcnt, 1); 370 __ z_agr(Z_R1_scratch, Z_R0_scratch); 371 __ z_bcr(Assembler::bcondAlways, Z_R1_scratch); 372 373 // Copy float arguments. 374 375 Label farg_caselist; // Distance between each case has to be a power of 2 376 // (= 1 << logSizeOfCase, padded with nop. 377 __ align(16); 378 BIND(farg_caselist); 379 __ z_ldr(Z_FARG1, floatSlot); // 2 bytes 380 __ z_bru(loop_start_restore); // 4 bytes 381 __ z_nop(); // 2 bytes 382 383 __ z_ldr(Z_FARG2, floatSlot); 384 __ z_bru(loop_start_restore); 385 __ z_nop(); 386 387 __ z_ldr(Z_FARG3, floatSlot); 388 __ z_bru(loop_start_restore); 389 __ z_nop(); 390 391 __ z_ldr(Z_FARG4, floatSlot); 392 __ z_bru(loop_start_restore); 393 __ z_nop(); 394 395 __ align(16); 396 __ bind(move_floatSlot_to_FARG); 397 __ z_stg(signature, d_signature, Z_SP); // Spill since signature == Z_R1_scratch. 398 __ z_lg(Z_R0_scratch, d_fpcnt, Z_SP); // Need old value for indexing. 399 __ add2mem_64(Address(Z_SP, d_fpcnt), 1, Z_R1_scratch); // Increment index. 400 __ z_larl(Z_R1_scratch, farg_caselist); 401 __ z_sllg(Z_R0_scratch, Z_R0_scratch, LogSizeOfCase); 402 __ z_agr(Z_R1_scratch, Z_R0_scratch); 403 __ z_bcr(Assembler::bcondAlways, Z_R1_scratch); 404 405 BLOCK_COMMENT("} slow_signature_handler"); 406 407 return __ addr_at(entry_offset); 408 } 409 410 address TemplateInterpreterGenerator::generate_result_handler_for (BasicType type) { 411 address entry = __ pc(); 412 413 assert(Z_tos == Z_RET, "Result handler: must move result!"); 414 assert(Z_ftos == Z_FRET, "Result handler: must move float result!"); 415 416 switch (type) { 417 case T_BOOLEAN: 418 __ c2bool(Z_tos); 419 break; 420 case T_CHAR: 421 __ and_imm(Z_tos, 0xffff); 422 break; 423 case T_BYTE: 424 __ z_lbr(Z_tos, Z_tos); 425 break; 426 case T_SHORT: 427 __ z_lhr(Z_tos, Z_tos); 428 break; 429 case T_INT: 430 case T_LONG: 431 case T_VOID: 432 case T_FLOAT: 433 case T_DOUBLE: 434 break; 435 case T_OBJECT: 436 // Retrieve result from frame... 437 __ mem2reg_opt(Z_tos, Address(Z_fp, oop_tmp_offset)); 438 // and verify it. 439 __ verify_oop(Z_tos); 440 break; 441 default: 442 ShouldNotReachHere(); 443 } 444 __ z_br(Z_R14); // Return from result handler. 445 return entry; 446 } 447 448 // Abstract method entry. 449 // Attempt to execute abstract method. Throw exception. 450 address TemplateInterpreterGenerator::generate_abstract_entry(void) { 451 unsigned int entry_offset = __ offset(); 452 453 // Caller could be the call_stub or a compiled method (x86 version is wrong!). 454 455 BLOCK_COMMENT("abstract_entry {"); 456 457 // Implement call of InterpreterRuntime::throw_AbstractMethodError. 458 __ set_top_ijava_frame_at_SP_as_last_Java_frame(Z_SP, Z_R1); 459 __ save_return_pc(); // Save Z_R14. 460 __ push_frame_abi160(0); // Without new frame the RT call could overwrite the saved Z_R14. 461 462 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError), Z_thread); 463 464 __ pop_frame(); 465 __ restore_return_pc(); // Restore Z_R14. 466 __ reset_last_Java_frame(); 467 468 // Restore caller sp for c2i case. 469 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. 470 471 // branch to SharedRuntime::generate_forward_exception() which handles all possible callers, 472 // i.e. call stub, compiled method, interpreted method. 473 __ load_absolute_address(Z_tmp_1, StubRoutines::forward_exception_entry()); 474 __ z_br(Z_tmp_1); 475 476 BLOCK_COMMENT("} abstract_entry"); 477 478 return __ addr_at(entry_offset); 479 } 480 481 address TemplateInterpreterGenerator::generate_Reference_get_entry(void) { 482 #if INCLUDE_ALL_GCS 483 if (UseG1GC) { 484 // Inputs: 485 // Z_ARG1 - receiver 486 // 487 // What we do: 488 // - Load the referent field address. 489 // - Load the value in the referent field. 490 // - Pass that value to the pre-barrier. 491 // 492 // In the case of G1 this will record the value of the 493 // referent in an SATB buffer if marking is active. 494 // This will cause concurrent marking to mark the referent 495 // field as live. 496 497 Register scratch1 = Z_tmp_2; 498 Register scratch2 = Z_tmp_3; 499 Register pre_val = Z_RET; // return value 500 // Z_esp is callers operand stack pointer, i.e. it points to the parameters. 501 Register Rargp = Z_esp; 502 503 Label slow_path; 504 address entry = __ pc(); 505 506 const int referent_offset = java_lang_ref_Reference::referent_offset; 507 guarantee(referent_offset > 0, "referent offset not initialized"); 508 509 BLOCK_COMMENT("Reference_get {"); 510 511 // If the receiver is null then it is OK to jump to the slow path. 512 __ load_and_test_long(pre_val, Address(Rargp, Interpreter::stackElementSize)); // Get receiver. 513 __ z_bre(slow_path); 514 515 // Load the value of the referent field. 516 __ load_heap_oop(pre_val, referent_offset, pre_val); 517 518 // Restore caller sp for c2i case. 519 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. 520 521 // Generate the G1 pre-barrier code to log the value of 522 // the referent field in an SATB buffer. 523 // Note: 524 // With these parameters the write_barrier_pre does not 525 // generate instructions to load the previous value. 526 __ g1_write_barrier_pre(noreg, // obj 527 noreg, // offset 528 pre_val, // pre_val 529 noreg, // no new val to preserve 530 scratch1, // tmp 531 scratch2, // tmp 532 true); // pre_val_needed 533 534 __ z_br(Z_R14); 535 536 // Branch to previously generated regular method entry. 537 __ bind(slow_path); 538 539 address meth_entry = Interpreter::entry_for_kind(Interpreter::zerolocals); 540 __ jump_to_entry(meth_entry, Z_R1); 541 542 BLOCK_COMMENT("} Reference_get"); 543 544 return entry; 545 } 546 #endif // INCLUDE_ALL_GCS 547 548 return NULL; 549 } 550 551 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() { 552 address entry = __ pc(); 553 554 DEBUG_ONLY(__ verify_esp(Z_esp, Z_ARG5)); 555 556 // Restore bcp under the assumption that the current frame is still 557 // interpreted. 558 __ restore_bcp(); 559 560 // Expression stack must be empty before entering the VM if an 561 // exception happened. 562 __ empty_expression_stack(); 563 // Throw exception. 564 __ call_VM(noreg, 565 CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError)); 566 return entry; 567 } 568 569 // 570 // Args: 571 // Z_ARG3: aberrant index 572 // 573 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char * name) { 574 address entry = __ pc(); 575 address excp = CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException); 576 577 // Expression stack must be empty before entering the VM if an 578 // exception happened. 579 __ empty_expression_stack(); 580 581 // Setup parameters. 582 // Leave out the name and use register for array to create more detailed exceptions. 583 __ load_absolute_address(Z_ARG2, (address) name); 584 __ call_VM(noreg, excp, Z_ARG2, Z_ARG3); 585 return entry; 586 } 587 588 address TemplateInterpreterGenerator::generate_ClassCastException_handler() { 589 address entry = __ pc(); 590 591 // Object is at TOS. 592 __ pop_ptr(Z_ARG2); 593 594 // Expression stack must be empty before entering the VM if an 595 // exception happened. 596 __ empty_expression_stack(); 597 598 __ call_VM(Z_ARG1, 599 CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ClassCastException), 600 Z_ARG2); 601 602 DEBUG_ONLY(__ should_not_reach_here();) 603 604 return entry; 605 } 606 607 address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) { 608 assert(!pass_oop || message == NULL, "either oop or message but not both"); 609 address entry = __ pc(); 610 611 BLOCK_COMMENT("exception_handler_common {"); 612 613 // Expression stack must be empty before entering the VM if an 614 // exception happened. 615 __ empty_expression_stack(); 616 if (name != NULL) { 617 __ load_absolute_address(Z_ARG2, (address)name); 618 } else { 619 __ clear_reg(Z_ARG2, true, false); 620 } 621 622 if (pass_oop) { 623 __ call_VM(Z_tos, 624 CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), 625 Z_ARG2, Z_tos /*object (see TT::aastore())*/); 626 } else { 627 if (message != NULL) { 628 __ load_absolute_address(Z_ARG3, (address)message); 629 } else { 630 __ clear_reg(Z_ARG3, true, false); 631 } 632 __ call_VM(Z_tos, 633 CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), 634 Z_ARG2, Z_ARG3); 635 } 636 // Throw exception. 637 __ load_absolute_address(Z_R1_scratch, Interpreter::throw_exception_entry()); 638 __ z_br(Z_R1_scratch); 639 640 BLOCK_COMMENT("} exception_handler_common"); 641 642 return entry; 643 } 644 645 address TemplateInterpreterGenerator::generate_return_entry_for (TosState state, int step, size_t index_size) { 646 address entry = __ pc(); 647 648 BLOCK_COMMENT("return_entry {"); 649 650 // Pop i2c extension or revert top-2-parent-resize done by interpreted callees. 651 Register sp_before_i2c_extension = Z_bcp; 652 __ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Restore frame pointer. 653 __ z_lg(sp_before_i2c_extension, Address(Z_fp, _z_ijava_state_neg(top_frame_sp))); 654 __ resize_frame_absolute(sp_before_i2c_extension, Z_locals/*tmp*/, true/*load_fp*/); 655 656 // TODO(ZASM): necessary?? 657 // // and NULL it as marker that esp is now tos until next java call 658 // __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 659 660 __ restore_bcp(); 661 __ restore_locals(); 662 __ restore_esp(); 663 664 if (state == atos) { 665 __ profile_return_type(Z_tmp_1, Z_tos, Z_tmp_2); 666 } 667 668 Register cache = Z_tmp_1; 669 Register size = Z_tmp_1; 670 Register offset = Z_tmp_2; 671 const int flags_offset = in_bytes(ConstantPoolCache::base_offset() + 672 ConstantPoolCacheEntry::flags_offset()); 673 __ get_cache_and_index_at_bcp(cache, offset, 1, index_size); 674 675 // #args is in rightmost byte of the _flags field. 676 __ z_llgc(size, Address(cache, offset, flags_offset+(sizeof(size_t)-1))); 677 __ z_sllg(size, size, Interpreter::logStackElementSize); // Each argument size in bytes. 678 __ z_agr(Z_esp, size); // Pop arguments. 679 __ dispatch_next(state, step); 680 681 BLOCK_COMMENT("} return_entry"); 682 683 return entry; 684 } 685 686 address TemplateInterpreterGenerator::generate_deopt_entry_for (TosState state, 687 int step) { 688 address entry = __ pc(); 689 690 BLOCK_COMMENT("deopt_entry {"); 691 692 // TODO(ZASM): necessary? NULL last_sp until next java call 693 // __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); 694 __ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Restore frame pointer. 695 __ restore_bcp(); 696 __ restore_locals(); 697 __ restore_esp(); 698 699 // Handle exceptions. 700 { 701 Label L; 702 __ load_and_test_long(Z_R0/*pending_exception*/, thread_(pending_exception)); 703 __ z_bre(L); 704 __ call_VM(noreg, 705 CAST_FROM_FN_PTR(address, 706 InterpreterRuntime::throw_pending_exception)); 707 __ should_not_reach_here(); 708 __ bind(L); 709 } 710 __ dispatch_next(state, step); 711 712 BLOCK_COMMENT("} deopt_entry"); 713 714 return entry; 715 } 716 717 address TemplateInterpreterGenerator::generate_safept_entry_for (TosState state, 718 address runtime_entry) { 719 address entry = __ pc(); 720 __ push(state); 721 __ call_VM(noreg, runtime_entry); 722 __ dispatch_via(vtos, Interpreter::_normal_table.table_for (vtos)); 723 return entry; 724 } 725 726 // 727 // Helpers for commoning out cases in the various type of method entries. 728 // 729 730 // Increment invocation count & check for overflow. 731 // 732 // Note: checking for negative value instead of overflow 733 // so we have a 'sticky' overflow test. 734 // 735 // Z_ARG2: method (see generate_fixed_frame()) 736 // 737 void TemplateInterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) { 738 Label done; 739 Register method = Z_ARG2; // Generate_fixed_frame() copies Z_method into Z_ARG2. 740 Register m_counters = Z_ARG4; 741 742 BLOCK_COMMENT("counter_incr {"); 743 744 // Note: In tiered we increment either counters in method or in MDO depending 745 // if we are profiling or not. 746 if (TieredCompilation) { 747 int increment = InvocationCounter::count_increment; 748 if (ProfileInterpreter) { 749 NearLabel no_mdo; 750 Register mdo = m_counters; 751 // Are we profiling? 752 __ load_and_test_long(mdo, method2_(method, method_data)); 753 __ branch_optimized(Assembler::bcondZero, no_mdo); 754 // Increment counter in the MDO. 755 const Address mdo_invocation_counter(mdo, MethodData::invocation_counter_offset() + 756 InvocationCounter::counter_offset()); 757 const Address mask(mdo, MethodData::invoke_mask_offset()); 758 __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, 759 Z_R1_scratch, false, Assembler::bcondZero, 760 overflow); 761 __ z_bru(done); 762 __ bind(no_mdo); 763 } 764 765 // Increment counter in MethodCounters. 766 const Address invocation_counter(m_counters, 767 MethodCounters::invocation_counter_offset() + 768 InvocationCounter::counter_offset()); 769 // Get address of MethodCounters object. 770 __ get_method_counters(method, m_counters, done); 771 const Address mask(m_counters, MethodCounters::invoke_mask_offset()); 772 __ increment_mask_and_jump(invocation_counter, 773 increment, mask, 774 Z_R1_scratch, false, Assembler::bcondZero, 775 overflow); 776 } else { 777 Register counter_sum = Z_ARG3; // The result of this piece of code. 778 Register tmp = Z_R1_scratch; 779 #ifdef ASSERT 780 { 781 NearLabel ok; 782 __ get_method(tmp); 783 __ compare64_and_branch(method, tmp, Assembler::bcondEqual, ok); 784 __ z_illtrap(0x66); 785 __ bind(ok); 786 } 787 #endif 788 789 // Get address of MethodCounters object. 790 __ get_method_counters(method, m_counters, done); 791 // Update standard invocation counters. 792 __ increment_invocation_counter(m_counters, counter_sum); 793 if (ProfileInterpreter) { 794 __ add2mem_32(Address(m_counters, MethodCounters::interpreter_invocation_counter_offset()), 1, tmp); 795 if (profile_method != NULL) { 796 const Address profile_limit(m_counters, MethodCounters::interpreter_profile_limit_offset()); 797 __ z_cl(counter_sum, profile_limit); 798 __ branch_optimized(Assembler::bcondLow, *profile_method_continue); 799 // If no method data exists, go to profile_method. 800 __ test_method_data_pointer(tmp, *profile_method); 801 } 802 } 803 804 const Address invocation_limit(m_counters, MethodCounters::interpreter_invocation_limit_offset()); 805 __ z_cl(counter_sum, invocation_limit); 806 __ branch_optimized(Assembler::bcondNotLow, *overflow); 807 } 808 809 __ bind(done); 810 811 BLOCK_COMMENT("} counter_incr"); 812 } 813 814 void TemplateInterpreterGenerator::generate_counter_overflow(Label& do_continue) { 815 // InterpreterRuntime::frequency_counter_overflow takes two 816 // arguments, the first (thread) is passed by call_VM, the second 817 // indicates if the counter overflow occurs at a backwards branch 818 // (NULL bcp). We pass zero for it. The call returns the address 819 // of the verified entry point for the method or NULL if the 820 // compilation did not complete (either went background or bailed 821 // out). 822 __ clear_reg(Z_ARG2); 823 __ call_VM(noreg, 824 CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), 825 Z_ARG2); 826 __ z_bru(do_continue); 827 } 828 829 void TemplateInterpreterGenerator::generate_stack_overflow_check(Register frame_size, Register tmp1) { 830 Register tmp2 = Z_R1_scratch; 831 const int page_size = os::vm_page_size(); 832 NearLabel after_frame_check; 833 834 BLOCK_COMMENT("counter_overflow {"); 835 836 assert_different_registers(frame_size, tmp1); 837 838 // Stack banging is sufficient overflow check if frame_size < page_size. 839 if (Immediate::is_uimm(page_size, 15)) { 840 __ z_chi(frame_size, page_size); 841 __ z_brl(after_frame_check); 842 } else { 843 __ load_const_optimized(tmp1, page_size); 844 __ compareU32_and_branch(frame_size, tmp1, Assembler::bcondLow, after_frame_check); 845 } 846 847 // Get the stack base, and in debug, verify it is non-zero. 848 __ z_lg(tmp1, thread_(stack_base)); 849 #ifdef ASSERT 850 address reentry = NULL; 851 NearLabel base_not_zero; 852 __ compareU64_and_branch(tmp1, (intptr_t)0L, Assembler::bcondNotEqual, base_not_zero); 853 reentry = __ stop_chain_static(reentry, "stack base is zero in generate_stack_overflow_check"); 854 __ bind(base_not_zero); 855 #endif 856 857 // Get the stack size, and in debug, verify it is non-zero. 858 assert(sizeof(size_t) == sizeof(intptr_t), "wrong load size"); 859 __ z_lg(tmp2, thread_(stack_size)); 860 #ifdef ASSERT 861 NearLabel size_not_zero; 862 __ compareU64_and_branch(tmp2, (intptr_t)0L, Assembler::bcondNotEqual, size_not_zero); 863 reentry = __ stop_chain_static(reentry, "stack size is zero in generate_stack_overflow_check"); 864 __ bind(size_not_zero); 865 #endif 866 867 // Compute the beginning of the protected zone minus the requested frame size. 868 __ z_sgr(tmp1, tmp2); 869 __ add2reg(tmp1, JavaThread::stack_guard_zone_size()); 870 871 // Add in the size of the frame (which is the same as subtracting it from the 872 // SP, which would take another register. 873 __ z_agr(tmp1, frame_size); 874 875 // The frame is greater than one page in size, so check against 876 // the bottom of the stack. 877 __ compareU64_and_branch(Z_SP, tmp1, Assembler::bcondHigh, after_frame_check); 878 879 // The stack will overflow, throw an exception. 880 881 // Restore SP to sender's sp. This is necessary if the sender's frame is an 882 // extended compiled frame (see gen_c2i_adapter()) and safer anyway in case of 883 // JSR292 adaptations. 884 __ resize_frame_absolute(Z_R10, tmp1, true/*load_fp*/); 885 886 // Note also that the restored frame is not necessarily interpreted. 887 // Use the shared runtime version of the StackOverflowError. 888 assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated"); 889 AddressLiteral stub(StubRoutines::throw_StackOverflowError_entry()); 890 __ load_absolute_address(tmp1, StubRoutines::throw_StackOverflowError_entry()); 891 __ z_br(tmp1); 892 893 // If you get to here, then there is enough stack space. 894 __ bind(after_frame_check); 895 896 BLOCK_COMMENT("} counter_overflow"); 897 } 898 899 // Allocate monitor and lock method (asm interpreter). 900 // 901 // Args: 902 // Z_locals: locals 903 904 void TemplateInterpreterGenerator::lock_method(void) { 905 906 BLOCK_COMMENT("lock_method {"); 907 908 // Synchronize method. 909 const Register method = Z_tmp_2; 910 __ get_method(method); 911 912 #ifdef ASSERT 913 address reentry = NULL; 914 { 915 Label L; 916 __ testbit(method2_(method, access_flags), JVM_ACC_SYNCHRONIZED_BIT); 917 __ z_btrue(L); 918 reentry = __ stop_chain_static(reentry, "method doesn't need synchronization"); 919 __ bind(L); 920 } 921 #endif // ASSERT 922 923 // Get synchronization object. 924 const Register object = Z_tmp_2; 925 926 { 927 Label done; 928 Label static_method; 929 930 __ testbit(method2_(method, access_flags), JVM_ACC_STATIC_BIT); 931 __ z_btrue(static_method); 932 933 // non-static method: Load receiver obj from stack. 934 __ mem2reg_opt(object, Address(Z_locals, Interpreter::local_offset_in_bytes(0))); 935 __ z_bru(done); 936 937 __ bind(static_method); 938 939 // Lock the java mirror. 940 __ load_mirror(object, method); 941 #ifdef ASSERT 942 { 943 NearLabel L; 944 __ compare64_and_branch(object, (intptr_t) 0, Assembler::bcondNotEqual, L); 945 reentry = __ stop_chain_static(reentry, "synchronization object is NULL"); 946 __ bind(L); 947 } 948 #endif // ASSERT 949 950 __ bind(done); 951 } 952 953 __ add_monitor_to_stack(true, Z_ARG3, Z_ARG4, Z_ARG5); // Allocate monitor elem. 954 // Store object and lock it. 955 __ get_monitors(Z_tmp_1); 956 __ reg2mem_opt(object, Address(Z_tmp_1, BasicObjectLock::obj_offset_in_bytes())); 957 __ lock_object(Z_tmp_1, object); 958 959 BLOCK_COMMENT("} lock_method"); 960 } 961 962 // Generate a fixed interpreter frame. This is identical setup for 963 // interpreted methods and for native methods hence the shared code. 964 // 965 // Registers alive 966 // Z_thread - JavaThread* 967 // Z_SP - old stack pointer 968 // Z_method - callee's method 969 // Z_esp - parameter list (slot 'above' last param) 970 // Z_R14 - return pc, to be stored in caller's frame 971 // Z_R10 - sender sp, note: Z_tmp_1 is Z_R10! 972 // 973 // Registers updated 974 // Z_SP - new stack pointer 975 // Z_esp - callee's operand stack pointer 976 // points to the slot above the value on top 977 // Z_locals - used to access locals: locals[i] := *(Z_locals - i*BytesPerWord) 978 // Z_bcp - the bytecode pointer 979 // Z_fp - the frame pointer, thereby killing Z_method 980 // Z_ARG2 - copy of Z_method 981 // 982 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { 983 984 // stack layout 985 // 986 // F1 [TOP_IJAVA_FRAME_ABI] <-- Z_SP, Z_R10 (see note below) 987 // [F1's operand stack (unused)] 988 // [F1's outgoing Java arguments] <-- Z_esp 989 // [F1's operand stack (non args)] 990 // [monitors] (optional) 991 // [IJAVA_STATE] 992 // 993 // F2 [PARENT_IJAVA_FRAME_ABI] 994 // ... 995 // 996 // 0x000 997 // 998 // Note: Z_R10, the sender sp, will be below Z_SP if F1 was extended by a c2i adapter. 999 1000 //============================================================================= 1001 // Allocate space for locals other than the parameters, the 1002 // interpreter state, monitors, and the expression stack. 1003 1004 const Register local_count = Z_ARG5; 1005 const Register fp = Z_tmp_2; 1006 1007 BLOCK_COMMENT("generate_fixed_frame {"); 1008 1009 { 1010 // local registers 1011 const Register top_frame_size = Z_ARG2; 1012 const Register sp_after_resize = Z_ARG3; 1013 const Register max_stack = Z_ARG4; 1014 1015 // local_count = method->constMethod->max_locals(); 1016 __ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); 1017 __ z_llgh(local_count, Address(Z_R1_scratch, ConstMethod::size_of_locals_offset())); 1018 1019 if (native_call) { 1020 // If we're calling a native method, we replace max_stack (which is 1021 // zero) with space for the worst-case signature handler varargs 1022 // vector, which is: 1023 // max_stack = max(Argument::n_register_parameters, parameter_count+2); 1024 // 1025 // We add two slots to the parameter_count, one for the jni 1026 // environment and one for a possible native mirror. We allocate 1027 // space for at least the number of ABI registers, even though 1028 // InterpreterRuntime::slow_signature_handler won't write more than 1029 // parameter_count+2 words when it creates the varargs vector at the 1030 // top of the stack. The generated slow signature handler will just 1031 // load trash into registers beyond the necessary number. We're 1032 // still going to cut the stack back by the ABI register parameter 1033 // count so as to get SP+16 pointing at the ABI outgoing parameter 1034 // area, so we need to allocate at least that much even though we're 1035 // going to throw it away. 1036 // 1037 1038 __ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); 1039 __ z_llgh(max_stack, Address(Z_R1_scratch, ConstMethod::size_of_parameters_offset())); 1040 __ add2reg(max_stack, 2); 1041 1042 NearLabel passing_args_on_stack; 1043 1044 // max_stack in bytes 1045 __ z_sllg(max_stack, max_stack, LogBytesPerWord); 1046 1047 int argument_registers_in_bytes = Argument::n_register_parameters << LogBytesPerWord; 1048 __ compare64_and_branch(max_stack, argument_registers_in_bytes, Assembler::bcondNotLow, passing_args_on_stack); 1049 1050 __ load_const_optimized(max_stack, argument_registers_in_bytes); 1051 1052 __ bind(passing_args_on_stack); 1053 } else { 1054 // !native_call 1055 __ z_lg(max_stack, method_(const)); 1056 1057 // Calculate number of non-parameter locals (in slots): 1058 __ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); 1059 __ z_sh(local_count, Address(Z_R1_scratch, ConstMethod::size_of_parameters_offset())); 1060 1061 // max_stack = method->max_stack(); 1062 __ z_llgh(max_stack, Address(max_stack, ConstMethod::max_stack_offset())); 1063 // max_stack in bytes 1064 __ z_sllg(max_stack, max_stack, LogBytesPerWord); 1065 } 1066 1067 // Resize (i.e. normally shrink) the top frame F1 ... 1068 // F1 [TOP_IJAVA_FRAME_ABI] <-- Z_SP, Z_R10 1069 // F1's operand stack (free) 1070 // ... 1071 // F1's operand stack (free) <-- Z_esp 1072 // F1's outgoing Java arg m 1073 // ... 1074 // F1's outgoing Java arg 0 1075 // ... 1076 // 1077 // ... into a parent frame (Z_R10 holds F1's SP before any modification, see also above) 1078 // 1079 // +......................+ 1080 // : : <-- Z_R10, saved below as F0's z_ijava_state.sender_sp 1081 // : : 1082 // F1 [PARENT_IJAVA_FRAME_ABI] <-- Z_SP \ 1083 // F0's non arg local | = delta 1084 // ... | 1085 // F0's non arg local <-- Z_esp / 1086 // F1's outgoing Java arg m 1087 // ... 1088 // F1's outgoing Java arg 0 1089 // ... 1090 // 1091 // then push the new top frame F0. 1092 // 1093 // F0 [TOP_IJAVA_FRAME_ABI] = frame::z_top_ijava_frame_abi_size \ 1094 // [operand stack] = max_stack | = top_frame_size 1095 // [IJAVA_STATE] = frame::z_ijava_state_size / 1096 1097 // sp_after_resize = Z_esp - delta 1098 // 1099 // delta = PARENT_IJAVA_FRAME_ABI + (locals_count - params_count) 1100 1101 __ add2reg(sp_after_resize, (Interpreter::stackElementSize) - (frame::z_parent_ijava_frame_abi_size), Z_esp); 1102 __ z_sllg(Z_R0_scratch, local_count, LogBytesPerWord); // Params have already been subtracted from local_count. 1103 __ z_slgr(sp_after_resize, Z_R0_scratch); 1104 1105 // top_frame_size = TOP_IJAVA_FRAME_ABI + max_stack + size of interpreter state 1106 __ add2reg(top_frame_size, 1107 frame::z_top_ijava_frame_abi_size + 1108 frame::z_ijava_state_size + 1109 frame::interpreter_frame_monitor_size() * wordSize, 1110 max_stack); 1111 1112 // Check if there's room for the new frame... 1113 Register frame_size = max_stack; // Reuse the regiser for max_stack. 1114 __ z_lgr(frame_size, Z_SP); 1115 __ z_sgr(frame_size, sp_after_resize); 1116 __ z_agr(frame_size, top_frame_size); 1117 generate_stack_overflow_check(frame_size, fp/*tmp1*/); 1118 1119 DEBUG_ONLY(__ z_cg(Z_R14, _z_abi16(return_pc), Z_SP)); 1120 __ asm_assert_eq("killed Z_R14", 0); 1121 __ resize_frame_absolute(sp_after_resize, fp, true); 1122 __ save_return_pc(Z_R14); 1123 1124 // ... and push the new frame F0. 1125 __ push_frame(top_frame_size, fp, true /*copy_sp*/, false); 1126 } 1127 1128 //============================================================================= 1129 // Initialize the new frame F0: initialize interpreter state. 1130 1131 { 1132 // locals 1133 const Register local_addr = Z_ARG4; 1134 1135 BLOCK_COMMENT("generate_fixed_frame: initialize interpreter state {"); 1136 1137 #ifdef ASSERT 1138 // Set the magic number (using local_addr as tmp register). 1139 __ load_const_optimized(local_addr, frame::z_istate_magic_number); 1140 __ z_stg(local_addr, _z_ijava_state_neg(magic), fp); 1141 #endif 1142 1143 // Save sender SP from F1 (i.e. before it was potentially modified by an 1144 // adapter) into F0's interpreter state. We us it as well to revert 1145 // resizing the frame above. 1146 __ z_stg(Z_R10, _z_ijava_state_neg(sender_sp), fp); 1147 1148 // Load cp cache and save it at the and of this block. 1149 __ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); 1150 __ z_lg(Z_R1_scratch, Address(Z_R1_scratch, ConstMethod::constants_offset())); 1151 __ z_lg(Z_R1_scratch, Address(Z_R1_scratch, ConstantPool::cache_offset_in_bytes())); 1152 1153 // z_ijava_state->method = method; 1154 __ z_stg(Z_method, _z_ijava_state_neg(method), fp); 1155 1156 // Point locals at the first argument. Method's locals are the 1157 // parameters on top of caller's expression stack. 1158 // Tos points past last Java argument. 1159 1160 __ z_lg(Z_locals, Address(Z_method, Method::const_offset())); 1161 __ z_llgh(Z_locals /*parameter_count words*/, 1162 Address(Z_locals, ConstMethod::size_of_parameters_offset())); 1163 __ z_sllg(Z_locals /*parameter_count bytes*/, Z_locals /*parameter_count*/, LogBytesPerWord); 1164 __ z_agr(Z_locals, Z_esp); 1165 // z_ijava_state->locals - i*BytesPerWord points to i-th Java local (i starts at 0) 1166 // z_ijava_state->locals = Z_esp + parameter_count bytes 1167 __ z_stg(Z_locals, _z_ijava_state_neg(locals), fp); 1168 1169 // z_ijava_state->oop_temp = NULL; 1170 __ store_const(Address(fp, oop_tmp_offset), 0); 1171 1172 // Initialize z_ijava_state->mdx. 1173 Register Rmdp = Z_bcp; 1174 // native_call: assert that mdo == NULL 1175 const bool check_for_mdo = !native_call DEBUG_ONLY(|| native_call); 1176 if (ProfileInterpreter && check_for_mdo) { 1177 #ifdef FAST_DISPATCH 1178 // FAST_DISPATCH and ProfileInterpreter are mutually exclusive since 1179 // they both use I2. 1180 assert(0, "FAST_DISPATCH and +ProfileInterpreter are mutually exclusive"); 1181 #endif // FAST_DISPATCH 1182 Label get_continue; 1183 1184 __ load_and_test_long(Rmdp, method_(method_data)); 1185 __ z_brz(get_continue); 1186 DEBUG_ONLY(if (native_call) __ stop("native methods don't have a mdo")); 1187 __ add2reg(Rmdp, in_bytes(MethodData::data_offset())); 1188 __ bind(get_continue); 1189 } 1190 __ z_stg(Rmdp, _z_ijava_state_neg(mdx), fp); 1191 1192 // Initialize z_ijava_state->bcp and Z_bcp. 1193 if (native_call) { 1194 __ clear_reg(Z_bcp); // Must initialize. Will get written into frame where GC reads it. 1195 } else { 1196 __ z_lg(Z_bcp, method_(const)); 1197 __ add2reg(Z_bcp, in_bytes(ConstMethod::codes_offset())); 1198 } 1199 __ z_stg(Z_bcp, _z_ijava_state_neg(bcp), fp); 1200 1201 // no monitors and empty operand stack 1202 // => z_ijava_state->monitors points to the top slot in IJAVA_STATE. 1203 // => Z_ijava_state->esp points one slot above into the operand stack. 1204 // z_ijava_state->monitors = fp - frame::z_ijava_state_size - Interpreter::stackElementSize; 1205 // z_ijava_state->esp = Z_esp = z_ijava_state->monitors; 1206 __ add2reg(Z_esp, -frame::z_ijava_state_size, fp); 1207 __ z_stg(Z_esp, _z_ijava_state_neg(monitors), fp); 1208 __ add2reg(Z_esp, -Interpreter::stackElementSize); 1209 __ z_stg(Z_esp, _z_ijava_state_neg(esp), fp); 1210 1211 // z_ijava_state->cpoolCache = Z_R1_scratch (see load above); 1212 __ z_stg(Z_R1_scratch, _z_ijava_state_neg(cpoolCache), fp); 1213 1214 // Get mirror and store it in the frame as GC root for this Method*. 1215 __ load_mirror(Z_R1_scratch, Z_method); 1216 __ z_stg(Z_R1_scratch, _z_ijava_state_neg(mirror), fp); 1217 1218 BLOCK_COMMENT("} generate_fixed_frame: initialize interpreter state"); 1219 1220 //============================================================================= 1221 if (!native_call) { 1222 // Fill locals with 0x0s. 1223 NearLabel locals_zeroed; 1224 NearLabel doXC; 1225 1226 // Local_count is already num_locals_slots - num_param_slots. 1227 __ compare64_and_branch(local_count, (intptr_t)0L, Assembler::bcondNotHigh, locals_zeroed); 1228 1229 // Advance local_addr to point behind locals (creates positive incr. in loop). 1230 __ z_lg(Z_R1_scratch, Address(Z_method, Method::const_offset())); 1231 __ z_llgh(Z_R0_scratch, 1232 Address(Z_R1_scratch, ConstMethod::size_of_locals_offset())); 1233 if (Z_R0_scratch == Z_R0) { 1234 __ z_aghi(Z_R0_scratch, -1); 1235 } else { 1236 __ add2reg(Z_R0_scratch, -1); 1237 } 1238 __ z_lgr(local_addr/*locals*/, Z_locals); 1239 __ z_sllg(Z_R0_scratch, Z_R0_scratch, LogBytesPerWord); 1240 __ z_sllg(local_count, local_count, LogBytesPerWord); // Local_count are non param locals. 1241 __ z_sgr(local_addr, Z_R0_scratch); 1242 1243 if (VM_Version::has_Prefetch()) { 1244 __ z_pfd(0x02, 0, Z_R0, local_addr); 1245 __ z_pfd(0x02, 256, Z_R0, local_addr); 1246 } 1247 1248 // Can't optimise for Z10 using "compare and branch" (immediate value is too big). 1249 __ z_cghi(local_count, 256); 1250 __ z_brnh(doXC); 1251 1252 // MVCLE: Initialize if quite a lot locals. 1253 // __ bind(doMVCLE); 1254 __ z_lgr(Z_R0_scratch, local_addr); 1255 __ z_lgr(Z_R1_scratch, local_count); 1256 __ clear_reg(Z_ARG2); // Src len of MVCLE is zero. 1257 1258 __ MacroAssembler::move_long_ext(Z_R0_scratch, Z_ARG1, 0); 1259 __ z_bru(locals_zeroed); 1260 1261 Label XC_template; 1262 __ bind(XC_template); 1263 __ z_xc(0, 0, local_addr, 0, local_addr); 1264 1265 __ bind(doXC); 1266 __ z_bctgr(local_count, Z_R0); // Get #bytes-1 for EXECUTE. 1267 if (VM_Version::has_ExecuteExtensions()) { 1268 __ z_exrl(local_count, XC_template); // Execute XC with variable length. 1269 } else { 1270 __ z_larl(Z_R1_scratch, XC_template); 1271 __ z_ex(local_count, 0, Z_R0, Z_R1_scratch); // Execute XC with variable length. 1272 } 1273 1274 __ bind(locals_zeroed); 1275 } 1276 1277 } 1278 // Finally set the frame pointer, destroying Z_method. 1279 assert(Z_fp == Z_method, "maybe set Z_fp earlier if other register than Z_method"); 1280 // Oprofile analysis suggests to keep a copy in a register to be used by 1281 // generate_counter_incr(). 1282 __ z_lgr(Z_ARG2, Z_method); 1283 __ z_lgr(Z_fp, fp); 1284 1285 BLOCK_COMMENT("} generate_fixed_frame"); 1286 } 1287 1288 // Various method entries 1289 1290 // Math function, frame manager must set up an interpreter state, etc. 1291 address TemplateInterpreterGenerator::generate_math_entry(AbstractInterpreter::MethodKind kind) { 1292 1293 // Decide what to do: Use same platform specific instructions and runtime calls as compilers. 1294 bool use_instruction = false; 1295 address runtime_entry = NULL; 1296 int num_args = 1; 1297 bool double_precision = true; 1298 1299 // s390 specific: 1300 switch (kind) { 1301 case Interpreter::java_lang_math_sqrt: 1302 case Interpreter::java_lang_math_abs: use_instruction = true; break; 1303 case Interpreter::java_lang_math_fmaF: 1304 case Interpreter::java_lang_math_fmaD: use_instruction = UseFMA; break; 1305 default: break; // Fall back to runtime call. 1306 } 1307 1308 switch (kind) { 1309 case Interpreter::java_lang_math_sin : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsin); break; 1310 case Interpreter::java_lang_math_cos : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dcos); break; 1311 case Interpreter::java_lang_math_tan : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dtan); break; 1312 case Interpreter::java_lang_math_abs : /* run interpreted */ break; 1313 case Interpreter::java_lang_math_sqrt : /* runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dsqrt); not available */ break; 1314 case Interpreter::java_lang_math_log : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog); break; 1315 case Interpreter::java_lang_math_log10: runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dlog10); break; 1316 case Interpreter::java_lang_math_pow : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dpow); num_args = 2; break; 1317 case Interpreter::java_lang_math_exp : runtime_entry = CAST_FROM_FN_PTR(address, SharedRuntime::dexp); break; 1318 case Interpreter::java_lang_math_fmaF : /* run interpreted */ num_args = 3; double_precision = false; break; 1319 case Interpreter::java_lang_math_fmaD : /* run interpreted */ num_args = 3; break; 1320 default: ShouldNotReachHere(); 1321 } 1322 1323 // Use normal entry if neither instruction nor runtime call is used. 1324 if (!use_instruction && runtime_entry == NULL) return NULL; 1325 1326 address entry = __ pc(); 1327 1328 if (use_instruction) { 1329 switch (kind) { 1330 case Interpreter::java_lang_math_sqrt: 1331 // Can use memory operand directly. 1332 __ z_sqdb(Z_FRET, Interpreter::stackElementSize, Z_esp); 1333 break; 1334 case Interpreter::java_lang_math_abs: 1335 // Load operand from stack. 1336 __ mem2freg_opt(Z_FRET, Address(Z_esp, Interpreter::stackElementSize)); 1337 __ z_lpdbr(Z_FRET); 1338 break; 1339 case Interpreter::java_lang_math_fmaF: 1340 __ mem2freg_opt(Z_FRET, Address(Z_esp, Interpreter::stackElementSize)); // result reg = arg3 1341 __ mem2freg_opt(Z_FARG2, Address(Z_esp, 3 * Interpreter::stackElementSize)); // arg1 1342 __ z_maeb(Z_FRET, Z_FARG2, Address(Z_esp, 2 * Interpreter::stackElementSize)); 1343 break; 1344 case Interpreter::java_lang_math_fmaD: 1345 __ mem2freg_opt(Z_FRET, Address(Z_esp, Interpreter::stackElementSize)); // result reg = arg3 1346 __ mem2freg_opt(Z_FARG2, Address(Z_esp, 5 * Interpreter::stackElementSize)); // arg1 1347 __ z_madb(Z_FRET, Z_FARG2, Address(Z_esp, 3 * Interpreter::stackElementSize)); 1348 break; 1349 default: ShouldNotReachHere(); 1350 } 1351 } else { 1352 // Load arguments 1353 assert(num_args <= 4, "passed in registers"); 1354 if (double_precision) { 1355 int offset = (2 * num_args - 1) * Interpreter::stackElementSize; 1356 for (int i = 0; i < num_args; ++i) { 1357 __ mem2freg_opt(as_FloatRegister(Z_FARG1->encoding() + 2 * i), Address(Z_esp, offset)); 1358 offset -= 2 * Interpreter::stackElementSize; 1359 } 1360 } else { 1361 int offset = num_args * Interpreter::stackElementSize; 1362 for (int i = 0; i < num_args; ++i) { 1363 __ mem2freg_opt(as_FloatRegister(Z_FARG1->encoding() + 2 * i), Address(Z_esp, offset)); 1364 offset -= Interpreter::stackElementSize; 1365 } 1366 } 1367 // Call runtime 1368 __ save_return_pc(); // Save Z_R14. 1369 __ push_frame_abi160(0); // Without new frame the RT call could overwrite the saved Z_R14. 1370 1371 __ call_VM_leaf(runtime_entry); 1372 1373 __ pop_frame(); 1374 __ restore_return_pc(); // Restore Z_R14. 1375 } 1376 1377 // Pop c2i arguments (if any) off when we return. 1378 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. 1379 1380 __ z_br(Z_R14); 1381 1382 return entry; 1383 } 1384 1385 // Interpreter stub for calling a native method. (asm interpreter). 1386 // This sets up a somewhat different looking stack for calling the 1387 // native method than the typical interpreter frame setup. 1388 address TemplateInterpreterGenerator::generate_native_entry(bool synchronized) { 1389 // Determine code generation flags. 1390 bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods; 1391 1392 // Interpreter entry for ordinary Java methods. 1393 // 1394 // Registers alive 1395 // Z_SP - stack pointer 1396 // Z_thread - JavaThread* 1397 // Z_method - callee's method (method to be invoked) 1398 // Z_esp - operand (or expression) stack pointer of caller. one slot above last arg. 1399 // Z_R10 - sender sp (before modifications, e.g. by c2i adapter 1400 // and as well by generate_fixed_frame below) 1401 // Z_R14 - return address to caller (call_stub or c2i_adapter) 1402 // 1403 // Registers updated 1404 // Z_SP - stack pointer 1405 // Z_fp - callee's framepointer 1406 // Z_esp - callee's operand stack pointer 1407 // points to the slot above the value on top 1408 // Z_locals - used to access locals: locals[i] := *(Z_locals - i*BytesPerWord) 1409 // Z_tos - integer result, if any 1410 // z_ftos - floating point result, if any 1411 // 1412 // Stack layout at this point: 1413 // 1414 // F1 [TOP_IJAVA_FRAME_ABI] <-- Z_SP, Z_R10 (Z_R10 will be below Z_SP if 1415 // frame was extended by c2i adapter) 1416 // [outgoing Java arguments] <-- Z_esp 1417 // ... 1418 // PARENT [PARENT_IJAVA_FRAME_ABI] 1419 // ... 1420 // 1421 1422 address entry_point = __ pc(); 1423 1424 // Make sure registers are different! 1425 assert_different_registers(Z_thread, Z_method, Z_esp); 1426 1427 BLOCK_COMMENT("native_entry {"); 1428 1429 // Make sure method is native and not abstract. 1430 #ifdef ASSERT 1431 address reentry = NULL; 1432 { Label L; 1433 __ testbit(method_(access_flags), JVM_ACC_NATIVE_BIT); 1434 __ z_btrue(L); 1435 reentry = __ stop_chain_static(reentry, "tried to execute non-native method as native"); 1436 __ bind(L); 1437 } 1438 { Label L; 1439 __ testbit(method_(access_flags), JVM_ACC_ABSTRACT_BIT); 1440 __ z_bfalse(L); 1441 reentry = __ stop_chain_static(reentry, "tried to execute abstract method as non-abstract"); 1442 __ bind(L); 1443 } 1444 #endif // ASSERT 1445 1446 #ifdef ASSERT 1447 // Save the return PC into the callers frame for assertion in generate_fixed_frame. 1448 __ save_return_pc(Z_R14); 1449 #endif 1450 1451 // Generate the code to allocate the interpreter stack frame. 1452 generate_fixed_frame(true); 1453 1454 const Address do_not_unlock_if_synchronized(Z_thread, JavaThread::do_not_unlock_if_synchronized_offset()); 1455 // Since at this point in the method invocation the exception handler 1456 // would try to exit the monitor of synchronized methods which hasn't 1457 // been entered yet, we set the thread local variable 1458 // _do_not_unlock_if_synchronized to true. If any exception was thrown by 1459 // runtime, exception handling i.e. unlock_if_synchronized_method will 1460 // check this thread local flag. 1461 __ z_mvi(do_not_unlock_if_synchronized, true); 1462 1463 // Increment invocation count and check for overflow. 1464 NearLabel invocation_counter_overflow; 1465 if (inc_counter) { 1466 generate_counter_incr(&invocation_counter_overflow, NULL, NULL); 1467 } 1468 1469 Label continue_after_compile; 1470 __ bind(continue_after_compile); 1471 1472 bang_stack_shadow_pages(true); 1473 1474 // Reset the _do_not_unlock_if_synchronized flag. 1475 __ z_mvi(do_not_unlock_if_synchronized, false); 1476 1477 // Check for synchronized methods. 1478 // This mst happen AFTER invocation_counter check and stack overflow check, 1479 // so method is not locked if overflows. 1480 if (synchronized) { 1481 lock_method(); 1482 } else { 1483 // No synchronization necessary. 1484 #ifdef ASSERT 1485 { Label L; 1486 __ get_method(Z_R1_scratch); 1487 __ testbit(method2_(Z_R1_scratch, access_flags), JVM_ACC_SYNCHRONIZED_BIT); 1488 __ z_bfalse(L); 1489 reentry = __ stop_chain_static(reentry, "method needs synchronization"); 1490 __ bind(L); 1491 } 1492 #endif // ASSERT 1493 } 1494 1495 // start execution 1496 1497 // jvmti support 1498 __ notify_method_entry(); 1499 1500 //============================================================================= 1501 // Get and call the signature handler. 1502 const Register Rmethod = Z_tmp_2; 1503 const Register signature_handler_entry = Z_tmp_1; 1504 const Register Rresult_handler = Z_tmp_3; 1505 Label call_signature_handler; 1506 1507 assert_different_registers(Z_fp, Rmethod, signature_handler_entry, Rresult_handler); 1508 assert(Rresult_handler->is_nonvolatile(), "Rresult_handler must be in a non-volatile register"); 1509 1510 // Reload method. 1511 __ get_method(Rmethod); 1512 1513 // Check for signature handler. 1514 __ load_and_test_long(signature_handler_entry, method2_(Rmethod, signature_handler)); 1515 __ z_brne(call_signature_handler); 1516 1517 // Method has never been called. Either generate a specialized 1518 // handler or point to the slow one. 1519 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), 1520 Rmethod); 1521 1522 // Reload method. 1523 __ get_method(Rmethod); 1524 1525 // Reload signature handler, it must have been created/assigned in the meantime. 1526 __ z_lg(signature_handler_entry, method2_(Rmethod, signature_handler)); 1527 1528 __ bind(call_signature_handler); 1529 1530 // We have a TOP_IJAVA_FRAME here, which belongs to us. 1531 __ set_top_ijava_frame_at_SP_as_last_Java_frame(Z_SP, Z_R1/*tmp*/); 1532 1533 // Call signature handler and pass locals address in Z_ARG1. 1534 __ z_lgr(Z_ARG1, Z_locals); 1535 __ call_stub(signature_handler_entry); 1536 // Save result handler returned by signature handler. 1537 __ z_lgr(Rresult_handler, Z_RET); 1538 1539 // Reload method (the slow signature handler may block for GC). 1540 __ get_method(Rmethod); 1541 1542 // Pass mirror handle if static call. 1543 { 1544 Label method_is_not_static; 1545 __ testbit(method2_(Rmethod, access_flags), JVM_ACC_STATIC_BIT); 1546 __ z_bfalse(method_is_not_static); 1547 // Get mirror. 1548 __ load_mirror(Z_R1, Rmethod); 1549 // z_ijava_state.oop_temp = pool_holder->klass_part()->java_mirror(); 1550 __ z_stg(Z_R1, oop_tmp_offset, Z_fp); 1551 // Pass handle to mirror as 2nd argument to JNI method. 1552 __ add2reg(Z_ARG2, oop_tmp_offset, Z_fp); 1553 __ bind(method_is_not_static); 1554 } 1555 1556 // Pass JNIEnv address as first parameter. 1557 __ add2reg(Z_ARG1, in_bytes(JavaThread::jni_environment_offset()), Z_thread); 1558 1559 // Note: last java frame has been set above already. The pc from there 1560 // is precise enough. 1561 1562 // Get native function entry point before we change the thread state. 1563 __ z_lg(Z_R1/*native_method_entry*/, method2_(Rmethod, native_function)); 1564 1565 //============================================================================= 1566 // Transition from _thread_in_Java to _thread_in_native. As soon as 1567 // we make this change the safepoint code needs to be certain that 1568 // the last Java frame we established is good. The pc in that frame 1569 // just need to be near here not an actual return address. 1570 #ifdef ASSERT 1571 { 1572 NearLabel L; 1573 __ mem2reg_opt(Z_R14, Address(Z_thread, JavaThread::thread_state_offset()), false /*32 bits*/); 1574 __ compareU32_and_branch(Z_R14, _thread_in_Java, Assembler::bcondEqual, L); 1575 reentry = __ stop_chain_static(reentry, "Wrong thread state in native stub"); 1576 __ bind(L); 1577 } 1578 #endif 1579 1580 // Memory ordering: Z does not reorder store/load with subsequent load. That's strong enough. 1581 __ set_thread_state(_thread_in_native); 1582 1583 //============================================================================= 1584 // Call the native method. Argument registers must not have been 1585 // overwritten since "__ call_stub(signature_handler);" (except for 1586 // ARG1 and ARG2 for static methods). 1587 1588 __ call_c(Z_R1/*native_method_entry*/); 1589 1590 // NOTE: frame::interpreter_frame_result() depends on these stores. 1591 __ z_stg(Z_RET, _z_ijava_state_neg(lresult), Z_fp); 1592 __ freg2mem_opt(Z_FRET, Address(Z_fp, _z_ijava_state_neg(fresult))); 1593 const Register Rlresult = signature_handler_entry; 1594 assert(Rlresult->is_nonvolatile(), "Rlresult must be in a non-volatile register"); 1595 __ z_lgr(Rlresult, Z_RET); 1596 1597 // Z_method may no longer be valid, because of GC. 1598 1599 // Block, if necessary, before resuming in _thread_in_Java state. 1600 // In order for GC to work, don't clear the last_Java_sp until after 1601 // blocking. 1602 1603 //============================================================================= 1604 // Switch thread to "native transition" state before reading the 1605 // synchronization state. This additional state is necessary 1606 // because reading and testing the synchronization state is not 1607 // atomic w.r.t. GC, as this scenario demonstrates: Java thread A, 1608 // in _thread_in_native state, loads _not_synchronized and is 1609 // preempted. VM thread changes sync state to synchronizing and 1610 // suspends threads for GC. Thread A is resumed to finish this 1611 // native method, but doesn't block here since it didn't see any 1612 // synchronization is progress, and escapes. 1613 1614 __ set_thread_state(_thread_in_native_trans); 1615 if (UseMembar) { 1616 __ z_fence(); 1617 } else { 1618 // Write serialization page so VM thread can do a pseudo remote 1619 // membar. We use the current thread pointer to calculate a thread 1620 // specific offset to write to within the page. This minimizes bus 1621 // traffic due to cache line collision. 1622 __ serialize_memory(Z_thread, Z_R1, Z_R0); 1623 } 1624 // Now before we return to java we must look for a current safepoint 1625 // (a new safepoint can not start since we entered native_trans). 1626 // We must check here because a current safepoint could be modifying 1627 // the callers registers right this moment. 1628 1629 // Check for safepoint operation in progress and/or pending suspend requests. 1630 { 1631 Label Continue, do_safepoint; 1632 __ generate_safepoint_check(do_safepoint, Z_R1, true); 1633 // Check for suspend. 1634 __ load_and_test_int(Z_R0/*suspend_flags*/, thread_(suspend_flags)); 1635 __ z_bre(Continue); // 0 -> no flag set -> not suspended 1636 __ bind(do_safepoint); 1637 __ z_lgr(Z_ARG1, Z_thread); 1638 __ call_c(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)); 1639 __ bind(Continue); 1640 } 1641 1642 //============================================================================= 1643 // Back in Interpreter Frame. 1644 1645 // We are in thread_in_native_trans here and back in the normal 1646 // interpreter frame. We don't have to do anything special about 1647 // safepoints and we can switch to Java mode anytime we are ready. 1648 1649 // Note: frame::interpreter_frame_result has a dependency on how the 1650 // method result is saved across the call to post_method_exit. For 1651 // native methods it assumes that the non-FPU/non-void result is 1652 // saved in z_ijava_state.lresult and a FPU result in z_ijava_state.fresult. If 1653 // this changes then the interpreter_frame_result implementation 1654 // will need to be updated too. 1655 1656 //============================================================================= 1657 // Back in Java. 1658 1659 // Memory ordering: Z does not reorder store/load with subsequent 1660 // load. That's strong enough. 1661 __ set_thread_state(_thread_in_Java); 1662 1663 __ reset_last_Java_frame(); 1664 1665 // We reset the JNI handle block only after unboxing the result; see below. 1666 1667 // The method register is junk from after the thread_in_native transition 1668 // until here. Also can't call_VM until the bcp has been 1669 // restored. Need bcp for throwing exception below so get it now. 1670 __ get_method(Rmethod); 1671 1672 // Restore Z_bcp to have legal interpreter frame, 1673 // i.e., bci == 0 <=> Z_bcp == code_base(). 1674 __ z_lg(Z_bcp, Address(Rmethod, Method::const_offset())); // get constMethod 1675 __ add2reg(Z_bcp, in_bytes(ConstMethod::codes_offset())); // get codebase 1676 1677 if (CheckJNICalls) { 1678 // clear_pending_jni_exception_check 1679 __ clear_mem(Address(Z_thread, JavaThread::pending_jni_exception_check_fn_offset()), sizeof(oop)); 1680 } 1681 1682 // Check if the native method returns an oop, and if so, move it 1683 // from the jni handle to z_ijava_state.oop_temp. This is 1684 // necessary, because we reset the jni handle block below. 1685 // NOTE: frame::interpreter_frame_result() depends on this, too. 1686 { NearLabel no_oop_result, store_oop_result; 1687 __ load_absolute_address(Z_R1, AbstractInterpreter::result_handler(T_OBJECT)); 1688 __ compareU64_and_branch(Z_R1, Rresult_handler, Assembler::bcondNotEqual, no_oop_result); 1689 __ compareU64_and_branch(Rlresult, (intptr_t)0L, Assembler::bcondEqual, store_oop_result); 1690 __ z_lg(Rlresult, 0, Rlresult); // unbox 1691 __ bind(store_oop_result); 1692 __ z_stg(Rlresult, oop_tmp_offset, Z_fp); 1693 __ verify_oop(Rlresult); 1694 __ bind(no_oop_result); 1695 } 1696 1697 // Reset handle block. 1698 __ z_lg(Z_R1/*active_handles*/, thread_(active_handles)); 1699 __ clear_mem(Address(Z_R1, JNIHandleBlock::top_offset_in_bytes()), 4); 1700 1701 // Bandle exceptions (exception handling will handle unlocking!). 1702 { 1703 Label L; 1704 __ load_and_test_long(Z_R0/*pending_exception*/, thread_(pending_exception)); 1705 __ z_bre(L); 1706 __ MacroAssembler::call_VM(noreg, 1707 CAST_FROM_FN_PTR(address, 1708 InterpreterRuntime::throw_pending_exception)); 1709 __ should_not_reach_here(); 1710 __ bind(L); 1711 } 1712 1713 if (synchronized) { 1714 Register Rfirst_monitor = Z_ARG2; 1715 __ add2reg(Rfirst_monitor, -(frame::z_ijava_state_size + (int)sizeof(BasicObjectLock)), Z_fp); 1716 #ifdef ASSERT 1717 NearLabel ok; 1718 __ z_lg(Z_R1, _z_ijava_state_neg(monitors), Z_fp); 1719 __ compareU64_and_branch(Rfirst_monitor, Z_R1, Assembler::bcondEqual, ok); 1720 reentry = __ stop_chain_static(reentry, "native_entry:unlock: inconsistent z_ijava_state.monitors"); 1721 __ bind(ok); 1722 #endif 1723 __ unlock_object(Rfirst_monitor); 1724 } 1725 1726 // JVMTI support. Result has already been saved above to the frame. 1727 __ notify_method_exit(true/*native_method*/, ilgl, InterpreterMacroAssembler::NotifyJVMTI); 1728 1729 // Move native method result back into proper registers and return. 1730 // C++ interpreter does not use result handler. So do we need to here? TODO(ZASM): check if correct. 1731 { NearLabel no_oop_or_null; 1732 __ mem2freg_opt(Z_FRET, Address(Z_fp, _z_ijava_state_neg(fresult))); 1733 __ load_and_test_long(Z_RET, Address(Z_fp, _z_ijava_state_neg(lresult))); 1734 __ z_bre(no_oop_or_null); // No unboxing if the result is NULL. 1735 __ load_absolute_address(Z_R1, AbstractInterpreter::result_handler(T_OBJECT)); 1736 __ compareU64_and_branch(Z_R1, Rresult_handler, Assembler::bcondNotEqual, no_oop_or_null); 1737 __ z_lg(Z_RET, oop_tmp_offset, Z_fp); 1738 __ verify_oop(Z_RET); 1739 __ bind(no_oop_or_null); 1740 } 1741 1742 // Pop the native method's interpreter frame. 1743 __ pop_interpreter_frame(Z_R14 /*return_pc*/, Z_ARG2/*tmp1*/, Z_ARG3/*tmp2*/); 1744 1745 // Return to caller. 1746 __ z_br(Z_R14); 1747 1748 if (inc_counter) { 1749 // Handle overflow of counter and compile method. 1750 __ bind(invocation_counter_overflow); 1751 generate_counter_overflow(continue_after_compile); 1752 } 1753 1754 BLOCK_COMMENT("} native_entry"); 1755 1756 return entry_point; 1757 } 1758 1759 // 1760 // Generic interpreted method entry to template interpreter. 1761 // 1762 address TemplateInterpreterGenerator::generate_normal_entry(bool synchronized) { 1763 address entry_point = __ pc(); 1764 1765 bool inc_counter = UseCompiler || CountCompiledCalls || LogTouchedMethods; 1766 1767 // Interpreter entry for ordinary Java methods. 1768 // 1769 // Registers alive 1770 // Z_SP - stack pointer 1771 // Z_thread - JavaThread* 1772 // Z_method - callee's method (method to be invoked) 1773 // Z_esp - operand (or expression) stack pointer of caller. one slot above last arg. 1774 // Z_R10 - sender sp (before modifications, e.g. by c2i adapter 1775 // and as well by generate_fixed_frame below) 1776 // Z_R14 - return address to caller (call_stub or c2i_adapter) 1777 // 1778 // Registers updated 1779 // Z_SP - stack pointer 1780 // Z_fp - callee's framepointer 1781 // Z_esp - callee's operand stack pointer 1782 // points to the slot above the value on top 1783 // Z_locals - used to access locals: locals[i] := *(Z_locals - i*BytesPerWord) 1784 // Z_tos - integer result, if any 1785 // z_ftos - floating point result, if any 1786 // 1787 // 1788 // stack layout at this point: 1789 // 1790 // F1 [TOP_IJAVA_FRAME_ABI] <-- Z_SP, Z_R10 (Z_R10 will be below Z_SP if 1791 // frame was extended by c2i adapter) 1792 // [outgoing Java arguments] <-- Z_esp 1793 // ... 1794 // PARENT [PARENT_IJAVA_FRAME_ABI] 1795 // ... 1796 // 1797 // stack layout before dispatching the first bytecode: 1798 // 1799 // F0 [TOP_IJAVA_FRAME_ABI] <-- Z_SP 1800 // [operand stack] <-- Z_esp 1801 // monitor (optional, can grow) 1802 // [IJAVA_STATE] 1803 // F1 [PARENT_IJAVA_FRAME_ABI] <-- Z_fp (== *Z_SP) 1804 // [F0's locals] <-- Z_locals 1805 // [F1's operand stack] 1806 // [F1's monitors] (optional) 1807 // [IJAVA_STATE] 1808 1809 // Make sure registers are different! 1810 assert_different_registers(Z_thread, Z_method, Z_esp); 1811 1812 BLOCK_COMMENT("normal_entry {"); 1813 1814 // Make sure method is not native and not abstract. 1815 // Rethink these assertions - they can be simplified and shared. 1816 #ifdef ASSERT 1817 address reentry = NULL; 1818 { Label L; 1819 __ testbit(method_(access_flags), JVM_ACC_NATIVE_BIT); 1820 __ z_bfalse(L); 1821 reentry = __ stop_chain_static(reentry, "tried to execute native method as non-native"); 1822 __ bind(L); 1823 } 1824 { Label L; 1825 __ testbit(method_(access_flags), JVM_ACC_ABSTRACT_BIT); 1826 __ z_bfalse(L); 1827 reentry = __ stop_chain_static(reentry, "tried to execute abstract method as non-abstract"); 1828 __ bind(L); 1829 } 1830 #endif // ASSERT 1831 1832 #ifdef ASSERT 1833 // Save the return PC into the callers frame for assertion in generate_fixed_frame. 1834 __ save_return_pc(Z_R14); 1835 #endif 1836 1837 // Generate the code to allocate the interpreter stack frame. 1838 generate_fixed_frame(false); 1839 1840 const Address do_not_unlock_if_synchronized(Z_thread, JavaThread::do_not_unlock_if_synchronized_offset()); 1841 // Since at this point in the method invocation the exception handler 1842 // would try to exit the monitor of synchronized methods which hasn't 1843 // been entered yet, we set the thread local variable 1844 // _do_not_unlock_if_synchronized to true. If any exception was thrown by 1845 // runtime, exception handling i.e. unlock_if_synchronized_method will 1846 // check this thread local flag. 1847 __ z_mvi(do_not_unlock_if_synchronized, true); 1848 1849 __ profile_parameters_type(Z_tmp_2, Z_ARG3, Z_ARG4); 1850 1851 // Increment invocation counter and check for overflow. 1852 // 1853 // Note: checking for negative value instead of overflow so we have a 'sticky' 1854 // overflow test (may be of importance as soon as we have true MT/MP). 1855 NearLabel invocation_counter_overflow; 1856 NearLabel profile_method; 1857 NearLabel profile_method_continue; 1858 NearLabel Lcontinue; 1859 if (inc_counter) { 1860 generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue); 1861 if (ProfileInterpreter) { 1862 __ bind(profile_method_continue); 1863 } 1864 } 1865 __ bind(Lcontinue); 1866 1867 bang_stack_shadow_pages(false); 1868 1869 // Reset the _do_not_unlock_if_synchronized flag. 1870 __ z_mvi(do_not_unlock_if_synchronized, false); 1871 1872 // Check for synchronized methods. 1873 // Must happen AFTER invocation_counter check and stack overflow check, 1874 // so method is not locked if overflows. 1875 if (synchronized) { 1876 // Allocate monitor and lock method. 1877 lock_method(); 1878 } else { 1879 #ifdef ASSERT 1880 { Label L; 1881 __ get_method(Z_R1_scratch); 1882 __ testbit(method2_(Z_R1_scratch, access_flags), JVM_ACC_SYNCHRONIZED_BIT); 1883 __ z_bfalse(L); 1884 reentry = __ stop_chain_static(reentry, "method needs synchronization"); 1885 __ bind(L); 1886 } 1887 #endif // ASSERT 1888 } 1889 1890 // start execution 1891 1892 #ifdef ASSERT 1893 __ verify_esp(Z_esp, Z_R1_scratch); 1894 1895 __ verify_thread(); 1896 #endif 1897 1898 // jvmti support 1899 __ notify_method_entry(); 1900 1901 // Start executing instructions. 1902 __ dispatch_next(vtos); 1903 // Dispatch_next does not return. 1904 DEBUG_ONLY(__ should_not_reach_here()); 1905 1906 // Invocation counter overflow. 1907 if (inc_counter) { 1908 if (ProfileInterpreter) { 1909 // We have decided to profile this method in the interpreter. 1910 __ bind(profile_method); 1911 1912 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); 1913 __ set_method_data_pointer_for_bcp(); 1914 __ z_bru(profile_method_continue); 1915 } 1916 1917 // Handle invocation counter overflow. 1918 __ bind(invocation_counter_overflow); 1919 generate_counter_overflow(Lcontinue); 1920 } 1921 1922 BLOCK_COMMENT("} normal_entry"); 1923 1924 return entry_point; 1925 } 1926 1927 // Method entry for static native methods: 1928 // int java.util.zip.CRC32.update(int crc, int b) 1929 address TemplateInterpreterGenerator::generate_CRC32_update_entry() { 1930 1931 if (UseCRC32Intrinsics) { 1932 uint64_t entry_off = __ offset(); 1933 Label slow_path; 1934 1935 // If we need a safepoint check, generate full interpreter entry. 1936 __ generate_safepoint_check(slow_path, Z_R1, false); 1937 1938 BLOCK_COMMENT("CRC32_update {"); 1939 1940 // We don't generate local frame and don't align stack because 1941 // we not even call stub code (we generate the code inline) 1942 // and there is no safepoint on this path. 1943 1944 // Load java parameters. 1945 // Z_esp is callers operand stack pointer, i.e. it points to the parameters. 1946 const Register argP = Z_esp; 1947 const Register crc = Z_ARG1; // crc value 1948 const Register data = Z_ARG2; // address of java byte value (kernel_crc32 needs address) 1949 const Register dataLen = Z_ARG3; // source data len (1 byte). Not used because calling the single-byte emitter. 1950 const Register table = Z_ARG4; // address of crc32 table 1951 1952 // Arguments are reversed on java expression stack. 1953 __ z_la(data, 3+1*wordSize, argP); // byte value (stack address). 1954 // Being passed as an int, the single byte is at offset +3. 1955 __ z_llgf(crc, 2 * wordSize, argP); // Current crc state, zero extend to 64 bit to have a clean register. 1956 1957 StubRoutines::zarch::generate_load_crc_table_addr(_masm, table); 1958 __ kernel_crc32_singleByte(crc, data, dataLen, table, Z_R1); 1959 1960 // Restore caller sp for c2i case. 1961 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. 1962 1963 __ z_br(Z_R14); 1964 1965 BLOCK_COMMENT("} CRC32_update"); 1966 1967 // Use a previously generated vanilla native entry as the slow path. 1968 BIND(slow_path); 1969 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), Z_R1); 1970 return __ addr_at(entry_off); 1971 } 1972 1973 return NULL; 1974 } 1975 1976 1977 // Method entry for static native methods: 1978 // int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len) 1979 // int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) 1980 address TemplateInterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) { 1981 1982 if (UseCRC32Intrinsics) { 1983 uint64_t entry_off = __ offset(); 1984 Label slow_path; 1985 1986 // If we need a safepoint check, generate full interpreter entry. 1987 __ generate_safepoint_check(slow_path, Z_R1, false); 1988 1989 // We don't generate local frame and don't align stack because 1990 // we call stub code and there is no safepoint on this path. 1991 1992 // Load parameters. 1993 // Z_esp is callers operand stack pointer, i.e. it points to the parameters. 1994 const Register argP = Z_esp; 1995 const Register crc = Z_ARG1; // crc value 1996 const Register data = Z_ARG2; // address of java byte array 1997 const Register dataLen = Z_ARG3; // source data len 1998 const Register table = Z_ARG4; // address of crc32 table 1999 const Register t0 = Z_R10; // work reg for kernel* emitters 2000 const Register t1 = Z_R11; // work reg for kernel* emitters 2001 const Register t2 = Z_R12; // work reg for kernel* emitters 2002 const Register t3 = Z_R13; // work reg for kernel* emitters 2003 2004 // Arguments are reversed on java expression stack. 2005 // Calculate address of start element. 2006 if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) { // Used for "updateByteBuffer direct". 2007 // crc @ (SP + 5W) (32bit) 2008 // buf @ (SP + 3W) (64bit ptr to long array) 2009 // off @ (SP + 2W) (32bit) 2010 // dataLen @ (SP + 1W) (32bit) 2011 // data = buf + off 2012 BLOCK_COMMENT("CRC32_updateByteBuffer {"); 2013 __ z_llgf(crc, 5*wordSize, argP); // current crc state 2014 __ z_lg(data, 3*wordSize, argP); // start of byte buffer 2015 __ z_agf(data, 2*wordSize, argP); // Add byte buffer offset. 2016 __ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process 2017 } else { // Used for "updateBytes update". 2018 // crc @ (SP + 4W) (32bit) 2019 // buf @ (SP + 3W) (64bit ptr to byte array) 2020 // off @ (SP + 2W) (32bit) 2021 // dataLen @ (SP + 1W) (32bit) 2022 // data = buf + off + base_offset 2023 BLOCK_COMMENT("CRC32_updateBytes {"); 2024 __ z_llgf(crc, 4*wordSize, argP); // current crc state 2025 __ z_lg(data, 3*wordSize, argP); // start of byte buffer 2026 __ z_agf(data, 2*wordSize, argP); // Add byte buffer offset. 2027 __ z_lgf(dataLen, 1*wordSize, argP); // #bytes to process 2028 __ z_aghi(data, arrayOopDesc::base_offset_in_bytes(T_BYTE)); 2029 } 2030 2031 StubRoutines::zarch::generate_load_crc_table_addr(_masm, table); 2032 2033 __ resize_frame(-(6*8), Z_R0, true); // Resize frame to provide add'l space to spill 5 registers. 2034 __ z_stmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 to make them available as work registers. 2035 __ kernel_crc32_1word(crc, data, dataLen, table, t0, t1, t2, t3); 2036 __ z_lmg(t0, t3, 1*8, Z_SP); // Spill regs 10..13 back from stack. 2037 2038 // Restore caller sp for c2i case. 2039 __ resize_frame_absolute(Z_R10, Z_R0, true); // Cut the stack back to where the caller started. 2040 2041 __ z_br(Z_R14); 2042 2043 BLOCK_COMMENT("} CRC32_update{Bytes|ByteBuffer}"); 2044 2045 // Use a previously generated vanilla native entry as the slow path. 2046 BIND(slow_path); 2047 __ jump_to_entry(Interpreter::entry_for_kind(Interpreter::native), Z_R1); 2048 return __ addr_at(entry_off); 2049 } 2050 2051 return NULL; 2052 } 2053 2054 // Not supported 2055 address TemplateInterpreterGenerator::generate_CRC32C_updateBytes_entry(AbstractInterpreter::MethodKind kind) { 2056 return NULL; 2057 } 2058 2059 void TemplateInterpreterGenerator::bang_stack_shadow_pages(bool native_call) { 2060 // Quick & dirty stack overflow checking: bang the stack & handle trap. 2061 // Note that we do the banging after the frame is setup, since the exception 2062 // handling code expects to find a valid interpreter frame on the stack. 2063 // Doing the banging earlier fails if the caller frame is not an interpreter 2064 // frame. 2065 // (Also, the exception throwing code expects to unlock any synchronized 2066 // method receiver, so do the banging after locking the receiver.) 2067 2068 // Bang each page in the shadow zone. We can't assume it's been done for 2069 // an interpreter frame with greater than a page of locals, so each page 2070 // needs to be checked. Only true for non-native. For native, we only bang the last page. 2071 if (UseStackBanging) { 2072 const int page_size = os::vm_page_size(); 2073 const int n_shadow_pages = (int)(JavaThread::stack_shadow_zone_size()/page_size); 2074 const int start_page_num = native_call ? n_shadow_pages : 1; 2075 for (int pages = start_page_num; pages <= n_shadow_pages; pages++) { 2076 __ bang_stack_with_offset(pages*page_size); 2077 } 2078 } 2079 } 2080 2081 //----------------------------------------------------------------------------- 2082 // Exceptions 2083 2084 void TemplateInterpreterGenerator::generate_throw_exception() { 2085 2086 BLOCK_COMMENT("throw_exception {"); 2087 2088 // Entry point in previous activation (i.e., if the caller was interpreted). 2089 Interpreter::_rethrow_exception_entry = __ pc(); 2090 __ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Frame accessors use Z_fp. 2091 // Z_ARG1 (==Z_tos): exception 2092 // Z_ARG2 : Return address/pc that threw exception. 2093 __ restore_bcp(); // R13 points to call/send. 2094 __ restore_locals(); 2095 2096 // Fallthrough, no need to restore Z_esp. 2097 2098 // Entry point for exceptions thrown within interpreter code. 2099 Interpreter::_throw_exception_entry = __ pc(); 2100 // Expression stack is undefined here. 2101 // Z_ARG1 (==Z_tos): exception 2102 // Z_bcp: exception bcp 2103 __ verify_oop(Z_ARG1); 2104 __ z_lgr(Z_ARG2, Z_ARG1); 2105 2106 // Expression stack must be empty before entering the VM in case of 2107 // an exception. 2108 __ empty_expression_stack(); 2109 // Find exception handler address and preserve exception oop. 2110 const Register Rpreserved_exc_oop = Z_tmp_1; 2111 __ call_VM(Rpreserved_exc_oop, 2112 CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), 2113 Z_ARG2); 2114 // Z_RET: exception handler entry point 2115 // Z_bcp: bcp for exception handler 2116 __ push_ptr(Rpreserved_exc_oop); // Push exception which is now the only value on the stack. 2117 __ z_br(Z_RET); // Jump to exception handler (may be _remove_activation_entry!). 2118 2119 // If the exception is not handled in the current frame the frame is 2120 // removed and the exception is rethrown (i.e. exception 2121 // continuation is _rethrow_exception). 2122 // 2123 // Note: At this point the bci is still the bci for the instruction 2124 // which caused the exception and the expression stack is 2125 // empty. Thus, for any VM calls at this point, GC will find a legal 2126 // oop map (with empty expression stack). 2127 2128 // 2129 // JVMTI PopFrame support 2130 // 2131 2132 Interpreter::_remove_activation_preserving_args_entry = __ pc(); 2133 __ z_lg(Z_fp, _z_parent_ijava_frame_abi(callers_sp), Z_SP); 2134 __ empty_expression_stack(); 2135 // Set the popframe_processing bit in pending_popframe_condition 2136 // indicating that we are currently handling popframe, so that 2137 // call_VMs that may happen later do not trigger new popframe 2138 // handling cycles. 2139 __ load_sized_value(Z_tmp_1, Address(Z_thread, JavaThread::popframe_condition_offset()), 4, false /*signed*/); 2140 __ z_oill(Z_tmp_1, JavaThread::popframe_processing_bit); 2141 __ z_sty(Z_tmp_1, thread_(popframe_condition)); 2142 2143 { 2144 // Check to see whether we are returning to a deoptimized frame. 2145 // (The PopFrame call ensures that the caller of the popped frame is 2146 // either interpreted or compiled and deoptimizes it if compiled.) 2147 // In this case, we can't call dispatch_next() after the frame is 2148 // popped, but instead must save the incoming arguments and restore 2149 // them after deoptimization has occurred. 2150 // 2151 // Note that we don't compare the return PC against the 2152 // deoptimization blob's unpack entry because of the presence of 2153 // adapter frames in C2. 2154 NearLabel caller_not_deoptimized; 2155 __ z_lg(Z_ARG1, _z_parent_ijava_frame_abi(return_pc), Z_fp); 2156 __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), Z_ARG1); 2157 __ compareU64_and_branch(Z_RET, (intptr_t)0, Assembler::bcondNotEqual, caller_not_deoptimized); 2158 2159 // Compute size of arguments for saving when returning to 2160 // deoptimized caller. 2161 __ get_method(Z_ARG2); 2162 __ z_lg(Z_ARG2, Address(Z_ARG2, Method::const_offset())); 2163 __ z_llgh(Z_ARG2, Address(Z_ARG2, ConstMethod::size_of_parameters_offset())); 2164 __ z_sllg(Z_ARG2, Z_ARG2, Interpreter::logStackElementSize); // slots 2 bytes 2165 __ restore_locals(); 2166 // Compute address of args to be saved. 2167 __ z_lgr(Z_ARG3, Z_locals); 2168 __ z_slgr(Z_ARG3, Z_ARG2); 2169 __ add2reg(Z_ARG3, wordSize); 2170 // Save these arguments. 2171 __ call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), 2172 Z_thread, Z_ARG2, Z_ARG3); 2173 2174 __ remove_activation(vtos, Z_R14, 2175 /* throw_monitor_exception */ false, 2176 /* install_monitor_exception */ false, 2177 /* notify_jvmdi */ false); 2178 2179 // Inform deoptimization that it is responsible for restoring 2180 // these arguments. 2181 __ store_const(thread_(popframe_condition), 2182 JavaThread::popframe_force_deopt_reexecution_bit, 2183 Z_tmp_1, false); 2184 2185 // Continue in deoptimization handler. 2186 __ z_br(Z_R14); 2187 2188 __ bind(caller_not_deoptimized); 2189 } 2190 2191 // Clear the popframe condition flag. 2192 __ clear_mem(thread_(popframe_condition), sizeof(int)); 2193 2194 __ remove_activation(vtos, 2195 noreg, // Retaddr is not used. 2196 false, // throw_monitor_exception 2197 false, // install_monitor_exception 2198 false); // notify_jvmdi 2199 __ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Restore frame pointer. 2200 __ restore_bcp(); 2201 __ restore_locals(); 2202 __ restore_esp(); 2203 // The method data pointer was incremented already during 2204 // call profiling. We have to restore the mdp for the current bcp. 2205 if (ProfileInterpreter) { 2206 __ set_method_data_pointer_for_bcp(); 2207 } 2208 #if INCLUDE_JVMTI 2209 { 2210 Label L_done; 2211 2212 __ z_cli(0, Z_bcp, Bytecodes::_invokestatic); 2213 __ z_brc(Assembler::bcondNotEqual, L_done); 2214 2215 // The member name argument must be restored if _invokestatic is 2216 // re-executed after a PopFrame call. Detect such a case in the 2217 // InterpreterRuntime function and return the member name 2218 // argument, or NULL. 2219 __ z_lg(Z_ARG2, Address(Z_locals)); 2220 __ get_method(Z_ARG3); 2221 __ call_VM(Z_tmp_1, 2222 CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), 2223 Z_ARG2, Z_ARG3, Z_bcp); 2224 2225 __ z_ltgr(Z_tmp_1, Z_tmp_1); 2226 __ z_brc(Assembler::bcondEqual, L_done); 2227 2228 __ z_stg(Z_tmp_1, Address(Z_esp, wordSize)); 2229 __ bind(L_done); 2230 } 2231 #endif // INCLUDE_JVMTI 2232 __ dispatch_next(vtos); 2233 // End of PopFrame support. 2234 Interpreter::_remove_activation_entry = __ pc(); 2235 2236 // In between activations - previous activation type unknown yet 2237 // compute continuation point - the continuation point expects the 2238 // following registers set up: 2239 // 2240 // Z_ARG1 (==Z_tos): exception 2241 // Z_ARG2 : return address/pc that threw exception 2242 2243 Register return_pc = Z_tmp_1; 2244 Register handler = Z_tmp_2; 2245 assert(return_pc->is_nonvolatile(), "use non-volatile reg. to preserve exception pc"); 2246 assert(handler->is_nonvolatile(), "use non-volatile reg. to handler pc"); 2247 __ asm_assert_ijava_state_magic(return_pc/*tmp*/); // The top frame should be an interpreter frame. 2248 __ z_lg(return_pc, _z_parent_ijava_frame_abi(return_pc), Z_fp); 2249 2250 // Moved removing the activation after VM call, because the new top 2251 // frame does not necessarily have the z_abi_160 required for a VM 2252 // call (e.g. if it is compiled). 2253 2254 __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, 2255 SharedRuntime::exception_handler_for_return_address), 2256 Z_thread, return_pc); 2257 __ z_lgr(handler, Z_RET); // Save exception handler. 2258 2259 // Preserve exception over this code sequence. 2260 __ pop_ptr(Z_ARG1); 2261 __ set_vm_result(Z_ARG1); 2262 // Remove the activation (without doing throws on illegalMonitorExceptions). 2263 __ remove_activation(vtos, noreg/*ret.pc already loaded*/, false/*throw exc*/, true/*install exc*/, false/*notify jvmti*/); 2264 __ z_lg(Z_fp, _z_abi(callers_sp), Z_SP); // Restore frame pointer. 2265 2266 __ get_vm_result(Z_ARG1); // Restore exception. 2267 __ verify_oop(Z_ARG1); 2268 __ z_lgr(Z_ARG2, return_pc); // Restore return address. 2269 2270 #ifdef ASSERT 2271 // The return_pc in the new top frame is dead... at least that's my 2272 // current understanding. To assert this I overwrite it. 2273 // Note: for compiled frames the handler is the deopt blob 2274 // which writes Z_ARG2 into the return_pc slot. 2275 __ load_const_optimized(return_pc, 0xb00b1); 2276 __ z_stg(return_pc, _z_parent_ijava_frame_abi(return_pc), Z_SP); 2277 #endif 2278 2279 // Z_ARG1 (==Z_tos): exception 2280 // Z_ARG2 : return address/pc that threw exception 2281 2282 // Note that an "issuing PC" is actually the next PC after the call. 2283 __ z_br(handler); // Jump to exception handler of caller. 2284 2285 BLOCK_COMMENT("} throw_exception"); 2286 } 2287 2288 // 2289 // JVMTI ForceEarlyReturn support 2290 // 2291 address TemplateInterpreterGenerator::generate_earlyret_entry_for (TosState state) { 2292 address entry = __ pc(); 2293 2294 BLOCK_COMMENT("earlyret_entry {"); 2295 2296 __ z_lg(Z_fp, _z_parent_ijava_frame_abi(callers_sp), Z_SP); 2297 __ restore_bcp(); 2298 __ restore_locals(); 2299 __ restore_esp(); 2300 __ empty_expression_stack(); 2301 __ load_earlyret_value(state); 2302 2303 Register RjvmtiState = Z_tmp_1; 2304 __ z_lg(RjvmtiState, thread_(jvmti_thread_state)); 2305 __ store_const(Address(RjvmtiState, JvmtiThreadState::earlyret_state_offset()), 2306 JvmtiThreadState::earlyret_inactive, 4, 4, Z_R0_scratch); 2307 2308 __ remove_activation(state, 2309 Z_tmp_1, // retaddr 2310 false, // throw_monitor_exception 2311 false, // install_monitor_exception 2312 true); // notify_jvmdi 2313 __ z_br(Z_tmp_1); 2314 2315 BLOCK_COMMENT("} earlyret_entry"); 2316 2317 return entry; 2318 } 2319 2320 //----------------------------------------------------------------------------- 2321 // Helper for vtos entry point generation. 2322 2323 void TemplateInterpreterGenerator::set_vtos_entry_points(Template* t, 2324 address& bep, 2325 address& cep, 2326 address& sep, 2327 address& aep, 2328 address& iep, 2329 address& lep, 2330 address& fep, 2331 address& dep, 2332 address& vep) { 2333 assert(t->is_valid() && t->tos_in() == vtos, "illegal template"); 2334 Label L; 2335 aep = __ pc(); __ push_ptr(); __ z_bru(L); 2336 fep = __ pc(); __ push_f(); __ z_bru(L); 2337 dep = __ pc(); __ push_d(); __ z_bru(L); 2338 lep = __ pc(); __ push_l(); __ z_bru(L); 2339 bep = cep = sep = 2340 iep = __ pc(); __ push_i(); 2341 vep = __ pc(); 2342 __ bind(L); 2343 generate_and_dispatch(t); 2344 } 2345 2346 //----------------------------------------------------------------------------- 2347 2348 #ifndef PRODUCT 2349 address TemplateInterpreterGenerator::generate_trace_code(TosState state) { 2350 address entry = __ pc(); 2351 NearLabel counter_below_trace_threshold; 2352 2353 if (TraceBytecodesAt > 0) { 2354 // Skip runtime call, if the trace threshold is not yet reached. 2355 __ load_absolute_address(Z_tmp_1, (address)&BytecodeCounter::_counter_value); 2356 __ load_absolute_address(Z_tmp_2, (address)&TraceBytecodesAt); 2357 __ load_sized_value(Z_tmp_1, Address(Z_tmp_1), 4, false /*signed*/); 2358 __ load_sized_value(Z_tmp_2, Address(Z_tmp_2), 8, false /*signed*/); 2359 __ compareU64_and_branch(Z_tmp_1, Z_tmp_2, Assembler::bcondLow, counter_below_trace_threshold); 2360 } 2361 2362 int offset2 = state == ltos || state == dtos ? 2 : 1; 2363 2364 __ push(state); 2365 // Preserved return pointer is in Z_R14. 2366 // InterpreterRuntime::trace_bytecode() preserved and returns the value passed as second argument. 2367 __ z_lgr(Z_ARG2, Z_R14); 2368 __ z_lg(Z_ARG3, Address(Z_esp, Interpreter::expr_offset_in_bytes(0))); 2369 if (WizardMode) { 2370 __ z_lgr(Z_ARG4, Z_esp); // Trace Z_esp in WizardMode. 2371 } else { 2372 __ z_lg(Z_ARG4, Address(Z_esp, Interpreter::expr_offset_in_bytes(offset2))); 2373 } 2374 __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::trace_bytecode), Z_ARG2, Z_ARG3, Z_ARG4); 2375 __ z_lgr(Z_R14, Z_RET); // Estore return address (see above). 2376 __ pop(state); 2377 2378 __ bind(counter_below_trace_threshold); 2379 __ z_br(Z_R14); // return 2380 2381 return entry; 2382 } 2383 2384 // Make feasible for old CPUs. 2385 void TemplateInterpreterGenerator::count_bytecode() { 2386 __ load_absolute_address(Z_R1_scratch, (address) &BytecodeCounter::_counter_value); 2387 __ add2mem_32(Address(Z_R1_scratch), 1, Z_R0_scratch); 2388 } 2389 2390 void TemplateInterpreterGenerator::histogram_bytecode(Template * t) { 2391 __ load_absolute_address(Z_R1_scratch, (address)&BytecodeHistogram::_counters[ t->bytecode() ]); 2392 __ add2mem_32(Address(Z_R1_scratch), 1, Z_tmp_1); 2393 } 2394 2395 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template * t) { 2396 Address index_addr(Z_tmp_1, (intptr_t) 0); 2397 Register index = Z_tmp_2; 2398 2399 // Load previous index. 2400 __ load_absolute_address(Z_tmp_1, (address) &BytecodePairHistogram::_index); 2401 __ mem2reg_opt(index, index_addr, false); 2402 2403 // Mask with current bytecode and store as new previous index. 2404 __ z_srl(index, BytecodePairHistogram::log2_number_of_codes); 2405 __ load_const_optimized(Z_R0_scratch, 2406 (int)t->bytecode() << BytecodePairHistogram::log2_number_of_codes); 2407 __ z_or(index, Z_R0_scratch); 2408 __ reg2mem_opt(index, index_addr, false); 2409 2410 // Load counter array's address. 2411 __ z_lgfr(index, index); // Sign extend for addressing. 2412 __ z_sllg(index, index, LogBytesPerInt); // index2bytes 2413 __ load_absolute_address(Z_R1_scratch, 2414 (address) &BytecodePairHistogram::_counters); 2415 // Add index and increment counter. 2416 __ z_agr(Z_R1_scratch, index); 2417 __ add2mem_32(Address(Z_R1_scratch), 1, Z_tmp_1); 2418 } 2419 2420 void TemplateInterpreterGenerator::trace_bytecode(Template* t) { 2421 // Call a little run-time stub to avoid blow-up for each bytecode. 2422 // The run-time runtime saves the right registers, depending on 2423 // the tosca in-state for the given template. 2424 address entry = Interpreter::trace_code(t->tos_in()); 2425 guarantee(entry != NULL, "entry must have been generated"); 2426 __ call_stub(entry); 2427 } 2428 2429 void TemplateInterpreterGenerator::stop_interpreter_at() { 2430 NearLabel L; 2431 2432 __ load_absolute_address(Z_tmp_1, (address)&BytecodeCounter::_counter_value); 2433 __ load_absolute_address(Z_tmp_2, (address)&StopInterpreterAt); 2434 __ load_sized_value(Z_tmp_1, Address(Z_tmp_1), 4, false /*signed*/); 2435 __ load_sized_value(Z_tmp_2, Address(Z_tmp_2), 8, false /*signed*/); 2436 __ compareU64_and_branch(Z_tmp_1, Z_tmp_2, Assembler::bcondLow, L); 2437 assert(Z_tmp_1->is_nonvolatile(), "must be nonvolatile to preserve Z_tos"); 2438 assert(Z_F8->is_nonvolatile(), "must be nonvolatile to preserve Z_ftos"); 2439 __ z_lgr(Z_tmp_1, Z_tos); // Save tos. 2440 __ z_lgr(Z_tmp_2, Z_bytecode); // Save Z_bytecode. 2441 __ z_ldr(Z_F8, Z_ftos); // Save ftos. 2442 // Use -XX:StopInterpreterAt=<num> to set the limit 2443 // and break at breakpoint(). 2444 __ call_VM(noreg, CAST_FROM_FN_PTR(address, breakpoint), false); 2445 __ z_lgr(Z_tos, Z_tmp_1); // Restore tos. 2446 __ z_lgr(Z_bytecode, Z_tmp_2); // Save Z_bytecode. 2447 __ z_ldr(Z_ftos, Z_F8); // Restore ftos. 2448 __ bind(L); 2449 } 2450 2451 #endif // !PRODUCT