1 /* 2 * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved. 3 * Copyright (c) 2016, 2024 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 // Major contributions by AHa, AS, JL, ML. 27 28 #include "precompiled.hpp" 29 #include "asm/macroAssembler.inline.hpp" 30 #include "gc/shared/barrierSet.hpp" 31 #include "gc/shared/barrierSetAssembler.hpp" 32 #include "interp_masm_s390.hpp" 33 #include "interpreter/interpreter.hpp" 34 #include "interpreter/interpreterRuntime.hpp" 35 #include "oops/arrayOop.hpp" 36 #include "oops/markWord.hpp" 37 #include "oops/methodCounters.hpp" 38 #include "oops/methodData.hpp" 39 #include "oops/resolvedFieldEntry.hpp" 40 #include "oops/resolvedIndyEntry.hpp" 41 #include "oops/resolvedMethodEntry.hpp" 42 #include "prims/jvmtiExport.hpp" 43 #include "prims/jvmtiThreadState.hpp" 44 #include "runtime/basicLock.hpp" 45 #include "runtime/frame.inline.hpp" 46 #include "runtime/javaThread.hpp" 47 #include "runtime/safepointMechanism.hpp" 48 #include "runtime/sharedRuntime.hpp" 49 #include "utilities/macros.hpp" 50 #include "utilities/powerOfTwo.hpp" 51 52 // Implementation of InterpreterMacroAssembler. 53 // This file specializes the assembler with interpreter-specific macros. 54 55 #ifdef PRODUCT 56 #define BLOCK_COMMENT(str) 57 #define BIND(label) bind(label); 58 #else 59 #define BLOCK_COMMENT(str) block_comment(str) 60 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":") 61 #endif 62 63 void InterpreterMacroAssembler::jump_to_entry(address entry, Register Rscratch) { 64 assert(entry != nullptr, "Entry must have been generated by now"); 65 assert(Rscratch != Z_R0, "Can't use R0 for addressing"); 66 branch_optimized(Assembler::bcondAlways, entry); 67 } 68 69 void InterpreterMacroAssembler::empty_expression_stack(void) { 70 get_monitors(Z_R1_scratch); 71 add2reg(Z_esp, -Interpreter::stackElementSize, Z_R1_scratch); 72 } 73 74 // Dispatch code executed in the prolog of a bytecode which does not do it's 75 // own dispatch. 76 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) { 77 // On z/Architecture we are short on registers, therefore we do not preload the 78 // dispatch address of the next bytecode. 79 } 80 81 // Dispatch code executed in the epilog of a bytecode which does not do it's 82 // own dispatch. 83 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) { 84 dispatch_next(state, step); 85 } 86 87 void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) { 88 z_llgc(Z_bytecode, bcp_incr, Z_R0, Z_bcp); // Load next bytecode. 89 add2reg(Z_bcp, bcp_incr); // Advance bcp. Add2reg produces optimal code. 90 dispatch_base(state, Interpreter::dispatch_table(state), generate_poll); 91 } 92 93 // Common code to dispatch and dispatch_only. 94 // Dispatch value in Lbyte_code and increment Lbcp. 95 96 void InterpreterMacroAssembler::dispatch_base(TosState state, address* table, bool generate_poll) { 97 verify_FPU(1, state); 98 99 #ifdef ASSERT 100 address reentry = nullptr; 101 { Label OK; 102 // Check if the frame pointer in Z_fp is correct. 103 z_cg(Z_fp, 0, Z_SP); 104 z_bre(OK); 105 reentry = stop_chain_static(reentry, "invalid frame pointer Z_fp: " FILE_AND_LINE); 106 bind(OK); 107 } 108 { Label OK; 109 // check if the locals pointer in Z_locals is correct 110 z_cg(Z_locals, _z_ijava_state_neg(locals), Z_fp); 111 z_bre(OK); 112 reentry = stop_chain_static(reentry, "invalid locals pointer Z_locals: " FILE_AND_LINE); 113 bind(OK); 114 } 115 #endif 116 117 // TODO: Maybe implement +VerifyActivationFrameSize here. 118 verify_oop(Z_tos, state); 119 120 // Dispatch table to use. 121 load_absolute_address(Z_tmp_1, (address)table); // Z_tmp_1 = table; 122 123 if (generate_poll) { 124 address *sfpt_tbl = Interpreter::safept_table(state); 125 if (table != sfpt_tbl) { 126 Label dispatch; 127 const Address poll_byte_addr(Z_thread, in_bytes(JavaThread::polling_word_offset()) + 7 /* Big Endian */); 128 // Armed page has poll_bit set, if poll bit is cleared just continue. 129 z_tm(poll_byte_addr, SafepointMechanism::poll_bit()); 130 z_braz(dispatch); 131 load_absolute_address(Z_tmp_1, (address)sfpt_tbl); // Z_tmp_1 = table; 132 bind(dispatch); 133 } 134 } 135 136 // 0 <= Z_bytecode < 256 => Use a 32 bit shift, because it is shorter than sllg. 137 // Z_bytecode must have been loaded zero-extended for this approach to be correct. 138 z_sll(Z_bytecode, LogBytesPerWord, Z_R0); // Multiply by wordSize. 139 z_lg(Z_tmp_1, 0, Z_bytecode, Z_tmp_1); // Get entry addr. 140 141 z_br(Z_tmp_1); 142 } 143 144 void InterpreterMacroAssembler::dispatch_only(TosState state, bool generate_poll) { 145 dispatch_base(state, Interpreter::dispatch_table(state), generate_poll); 146 } 147 148 void InterpreterMacroAssembler::dispatch_only_normal(TosState state) { 149 dispatch_base(state, Interpreter::normal_table(state)); 150 } 151 152 void InterpreterMacroAssembler::dispatch_via(TosState state, address *table) { 153 // Load current bytecode. 154 z_llgc(Z_bytecode, Address(Z_bcp, (intptr_t)0)); 155 dispatch_base(state, table); 156 } 157 158 // The following call_VM*_base() methods overload and mask the respective 159 // declarations/definitions in class MacroAssembler. They are meant as a "detour" 160 // to perform additional, template interpreter specific tasks before actually 161 // calling their MacroAssembler counterparts. 162 163 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point) { 164 bool allow_relocation = true; // Fenerally valid variant. Assume code is relocated. 165 // interpreter specific 166 // Note: No need to save/restore bcp (Z_R13) pointer since these are callee 167 // saved registers and no blocking/ GC can happen in leaf calls. 168 169 // super call 170 MacroAssembler::call_VM_leaf_base(entry_point, allow_relocation); 171 } 172 173 void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point, bool allow_relocation) { 174 // interpreter specific 175 // Note: No need to save/restore bcp (Z_R13) pointer since these are callee 176 // saved registers and no blocking/ GC can happen in leaf calls. 177 178 // super call 179 MacroAssembler::call_VM_leaf_base(entry_point, allow_relocation); 180 } 181 182 void InterpreterMacroAssembler::call_VM_base(Register oop_result, Register last_java_sp, 183 address entry_point, bool check_exceptions) { 184 bool allow_relocation = true; // Fenerally valid variant. Assume code is relocated. 185 // interpreter specific 186 187 save_bcp(); 188 save_esp(); 189 // super call 190 MacroAssembler::call_VM_base(oop_result, last_java_sp, 191 entry_point, allow_relocation, check_exceptions); 192 restore_bcp(); 193 } 194 195 void InterpreterMacroAssembler::call_VM_base(Register oop_result, Register last_java_sp, 196 address entry_point, bool allow_relocation, 197 bool check_exceptions) { 198 // interpreter specific 199 200 save_bcp(); 201 save_esp(); 202 // super call 203 MacroAssembler::call_VM_base(oop_result, last_java_sp, 204 entry_point, allow_relocation, check_exceptions); 205 restore_bcp(); 206 } 207 208 void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) { 209 if (JvmtiExport::can_pop_frame()) { 210 BLOCK_COMMENT("check_and_handle_popframe {"); 211 Label L; 212 // Initiate popframe handling only if it is not already being 213 // processed. If the flag has the popframe_processing bit set, it 214 // means that this code is called *during* popframe handling - we 215 // don't want to reenter. 216 // TODO: Check if all four state combinations could be visible. 217 // If (processing and !pending) is an invisible/impossible state, 218 // there is optimization potential by testing both bits at once. 219 // Then, All_Zeroes and All_Ones means skip, Mixed means doit. 220 testbit(Address(Z_thread, JavaThread::popframe_condition_offset()), 221 exact_log2(JavaThread::popframe_pending_bit)); 222 z_bfalse(L); 223 testbit(Address(Z_thread, JavaThread::popframe_condition_offset()), 224 exact_log2(JavaThread::popframe_processing_bit)); 225 z_btrue(L); 226 227 // Call Interpreter::remove_activation_preserving_args_entry() to get the 228 // address of the same-named entrypoint in the generated interpreter code. 229 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); 230 // The above call should (as its only effect) return the contents of the field 231 // _remove_activation_preserving_args_entry in Z_RET. 232 // We just jump there to have the work done. 233 z_br(Z_RET); 234 // There is no way for control to fall thru here. 235 236 bind(L); 237 BLOCK_COMMENT("} check_and_handle_popframe"); 238 } 239 } 240 241 242 void InterpreterMacroAssembler::load_earlyret_value(TosState state) { 243 Register RjvmtiState = Z_R1_scratch; 244 int tos_off = in_bytes(JvmtiThreadState::earlyret_tos_offset()); 245 int oop_off = in_bytes(JvmtiThreadState::earlyret_oop_offset()); 246 int val_off = in_bytes(JvmtiThreadState::earlyret_value_offset()); 247 int state_off = in_bytes(JavaThread::jvmti_thread_state_offset()); 248 249 z_lg(RjvmtiState, state_off, Z_thread); 250 251 switch (state) { 252 case atos: z_lg(Z_tos, oop_off, RjvmtiState); 253 store_const(Address(RjvmtiState, oop_off), 0L, 8, 8, Z_R0_scratch); 254 break; 255 case ltos: z_lg(Z_tos, val_off, RjvmtiState); break; 256 case btos: // fall through 257 case ztos: // fall through 258 case ctos: // fall through 259 case stos: // fall through 260 case itos: z_llgf(Z_tos, val_off, RjvmtiState); break; 261 case ftos: z_le(Z_ftos, val_off, RjvmtiState); break; 262 case dtos: z_ld(Z_ftos, val_off, RjvmtiState); break; 263 case vtos: /* nothing to do */ break; 264 default : ShouldNotReachHere(); 265 } 266 267 // Clean up tos value in the jvmti thread state. 268 store_const(Address(RjvmtiState, val_off), 0L, 8, 8, Z_R0_scratch); 269 // Set tos state field to illegal value. 270 store_const(Address(RjvmtiState, tos_off), ilgl, 4, 1, Z_R0_scratch); 271 } 272 273 void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) { 274 if (JvmtiExport::can_force_early_return()) { 275 BLOCK_COMMENT("check_and_handle_earlyret {"); 276 Label L; 277 // arg regs are save, because we are just behind the call in call_VM_base 278 Register jvmti_thread_state = Z_ARG2; 279 Register tmp = Z_ARG3; 280 load_and_test_long(jvmti_thread_state, Address(Z_thread, JavaThread::jvmti_thread_state_offset())); 281 z_bre(L); // if (thread->jvmti_thread_state() == nullptr) exit; 282 283 // Initiate earlyret handling only if it is not already being processed. 284 // If the flag has the earlyret_processing bit set, it means that this code 285 // is called *during* earlyret handling - we don't want to reenter. 286 287 assert((JvmtiThreadState::earlyret_pending != 0) && (JvmtiThreadState::earlyret_inactive == 0), 288 "must fix this check, when changing the values of the earlyret enum"); 289 assert(JvmtiThreadState::earlyret_pending == 1, "must fix this check, when changing the values of the earlyret enum"); 290 291 load_and_test_int(tmp, Address(jvmti_thread_state, JvmtiThreadState::earlyret_state_offset())); 292 z_brz(L); // if (thread->jvmti_thread_state()->_earlyret_state != JvmtiThreadState::earlyret_pending) exit; 293 294 // Call Interpreter::remove_activation_early_entry() to get the address of the 295 // same-named entrypoint in the generated interpreter code. 296 assert(sizeof(TosState) == 4, "unexpected size"); 297 z_l(Z_ARG1, Address(jvmti_thread_state, JvmtiThreadState::earlyret_tos_offset())); 298 call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), Z_ARG1); 299 // The above call should (as its only effect) return the contents of the field 300 // _remove_activation_preserving_args_entry in Z_RET. 301 // We just jump there to have the work done. 302 z_br(Z_RET); 303 // There is no way for control to fall thru here. 304 305 bind(L); 306 BLOCK_COMMENT("} check_and_handle_earlyret"); 307 } 308 } 309 310 void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, Register arg_1, Register arg_2) { 311 lgr_if_needed(Z_ARG1, arg_1); 312 assert(arg_2 != Z_ARG1, "smashed argument"); 313 lgr_if_needed(Z_ARG2, arg_2); 314 MacroAssembler::call_VM_leaf_base(entry_point, true); 315 } 316 317 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index, int bcp_offset, size_t index_size) { 318 Address param(Z_bcp, bcp_offset); 319 320 BLOCK_COMMENT("get_cache_index_at_bcp {"); 321 assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); 322 if (index_size == sizeof(u2)) { 323 load_sized_value(index, param, 2, false /*signed*/); 324 } else if (index_size == sizeof(u4)) { 325 326 load_sized_value(index, param, 4, false); 327 } else if (index_size == sizeof(u1)) { 328 z_llgc(index, param); 329 } else { 330 ShouldNotReachHere(); 331 } 332 BLOCK_COMMENT("}"); 333 } 334 335 void InterpreterMacroAssembler::load_resolved_indy_entry(Register cache, Register index) { 336 // Get index out of bytecode pointer. 337 get_cache_index_at_bcp(index, 1, sizeof(u4)); 338 339 // Get the address of the ResolvedIndyEntry array 340 get_constant_pool_cache(cache); 341 z_lg(cache, Address(cache, in_bytes(ConstantPoolCache::invokedynamic_entries_offset()))); 342 343 // Scale the index to form a byte offset into the ResolvedIndyEntry array 344 size_t entry_size = sizeof(ResolvedIndyEntry); 345 if (is_power_of_2(entry_size)) { 346 z_sllg(index, index, exact_log2(entry_size)); 347 } else { 348 z_mghi(index, entry_size); 349 } 350 351 // Calculate the final field address. 352 z_la(cache, Array<ResolvedIndyEntry>::base_offset_in_bytes(), index, cache); 353 } 354 355 void InterpreterMacroAssembler::load_field_entry(Register cache, Register index, int bcp_offset) { 356 // Get field index out of bytecode pointer. 357 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2)); 358 359 // Get the address of the ResolvedFieldEntry array. 360 get_constant_pool_cache(cache); 361 z_lg(cache, Address(cache, in_bytes(ConstantPoolCache::field_entries_offset()))); 362 363 // Scale the index to form a byte offset into the ResolvedFieldEntry array 364 size_t entry_size = sizeof(ResolvedFieldEntry); 365 if (is_power_of_2(entry_size)) { 366 z_sllg(index, index, exact_log2(entry_size)); 367 } else { 368 z_mghi(index, entry_size); 369 } 370 371 // Calculate the final field address. 372 z_la(cache, Array<ResolvedFieldEntry>::base_offset_in_bytes(), index, cache); 373 } 374 375 void InterpreterMacroAssembler::load_method_entry(Register cache, Register index, int bcp_offset) { 376 // Get field index out of bytecode pointer. 377 get_cache_index_at_bcp(index, bcp_offset, sizeof(u2)); 378 379 // Get the address of the ResolvedMethodEntry array. 380 get_constant_pool_cache(cache); 381 z_lg(cache, Address(cache, in_bytes(ConstantPoolCache::method_entries_offset()))); 382 383 // Scale the index to form a byte offset into the ResolvedMethodEntry array 384 size_t entry_size = sizeof(ResolvedMethodEntry); 385 if (is_power_of_2(entry_size)) { 386 z_sllg(index, index, exact_log2(entry_size)); 387 } else { 388 z_mghi(index, entry_size); 389 } 390 391 // Calculate the final field address. 392 z_la(cache, Array<ResolvedMethodEntry>::base_offset_in_bytes(), index, cache); 393 } 394 395 // Load object from cpool->resolved_references(index). 396 void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index) { 397 assert_different_registers(result, index); 398 get_constant_pool(result); 399 400 // Convert 401 // - from field index to resolved_references() index and 402 // - from word index to byte offset. 403 // Since this is a java object, it is potentially compressed. 404 Register tmp = index; // reuse 405 z_sllg(index, index, LogBytesPerHeapOop); // Offset into resolved references array. 406 // Load pointer for resolved_references[] objArray. 407 z_lg(result, in_bytes(ConstantPool::cache_offset()), result); 408 z_lg(result, in_bytes(ConstantPoolCache::resolved_references_offset()), result); 409 resolve_oop_handle(result); // Load resolved references array itself. 410 #ifdef ASSERT 411 NearLabel index_ok; 412 z_lgf(Z_R0, Address(result, arrayOopDesc::length_offset_in_bytes())); 413 z_sllg(Z_R0, Z_R0, LogBytesPerHeapOop); 414 compare64_and_branch(tmp, Z_R0, Assembler::bcondLow, index_ok); 415 stop("resolved reference index out of bounds", 0x09256); 416 bind(index_ok); 417 #endif 418 z_agr(result, index); // Address of indexed array element. 419 load_heap_oop(result, Address(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT)), tmp, noreg); 420 } 421 422 // load cpool->resolved_klass_at(index) 423 void InterpreterMacroAssembler::load_resolved_klass_at_offset(Register cpool, Register offset, Register iklass) { 424 // int value = *(Rcpool->int_at_addr(which)); 425 // int resolved_klass_index = extract_low_short_from_int(value); 426 z_llgh(offset, Address(cpool, offset, sizeof(ConstantPool) + 2)); // offset = resolved_klass_index (s390 is big-endian) 427 z_sllg(offset, offset, LogBytesPerWord); // Convert 'index' to 'offset' 428 z_lg(iklass, Address(cpool, ConstantPool::resolved_klasses_offset())); // iklass = cpool->_resolved_klasses 429 z_lg(iklass, Address(iklass, offset, Array<Klass*>::base_offset_in_bytes())); 430 } 431 432 // Generate a subtype check: branch to ok_is_subtype if sub_klass is 433 // a subtype of super_klass. Blows registers Rsuper_klass, Rsub_klass, tmp1, tmp2. 434 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, 435 Register Rsuper_klass, 436 Register Rtmp1, 437 Register Rtmp2, 438 Label &ok_is_subtype) { 439 // Profile the not-null value's klass. 440 profile_typecheck(Rtmp1, Rsub_klass, Rtmp2); 441 442 // Do the check. 443 check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype); 444 } 445 446 // Pop topmost element from stack. It just disappears. 447 // Useful if consumed previously by access via stackTop(). 448 void InterpreterMacroAssembler::popx(int len) { 449 add2reg(Z_esp, len*Interpreter::stackElementSize); 450 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 451 } 452 453 // Get Address object of stack top. No checks. No pop. 454 // Purpose: - Provide address of stack operand to exploit reg-mem operations. 455 // - Avoid RISC-like mem2reg - reg-reg-op sequence. 456 Address InterpreterMacroAssembler::stackTop() { 457 return Address(Z_esp, Interpreter::expr_offset_in_bytes(0)); 458 } 459 460 void InterpreterMacroAssembler::pop_i(Register r) { 461 z_l(r, Interpreter::expr_offset_in_bytes(0), Z_esp); 462 add2reg(Z_esp, Interpreter::stackElementSize); 463 assert_different_registers(r, Z_R1_scratch); 464 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 465 } 466 467 void InterpreterMacroAssembler::pop_ptr(Register r) { 468 z_lg(r, Interpreter::expr_offset_in_bytes(0), Z_esp); 469 add2reg(Z_esp, Interpreter::stackElementSize); 470 assert_different_registers(r, Z_R1_scratch); 471 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 472 } 473 474 void InterpreterMacroAssembler::pop_l(Register r) { 475 z_lg(r, Interpreter::expr_offset_in_bytes(0), Z_esp); 476 add2reg(Z_esp, 2*Interpreter::stackElementSize); 477 assert_different_registers(r, Z_R1_scratch); 478 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 479 } 480 481 void InterpreterMacroAssembler::pop_f(FloatRegister f) { 482 mem2freg_opt(f, Address(Z_esp, Interpreter::expr_offset_in_bytes(0)), false); 483 add2reg(Z_esp, Interpreter::stackElementSize); 484 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 485 } 486 487 void InterpreterMacroAssembler::pop_d(FloatRegister f) { 488 mem2freg_opt(f, Address(Z_esp, Interpreter::expr_offset_in_bytes(0)), true); 489 add2reg(Z_esp, 2*Interpreter::stackElementSize); 490 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 491 } 492 493 void InterpreterMacroAssembler::push_i(Register r) { 494 assert_different_registers(r, Z_R1_scratch); 495 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 496 z_st(r, Address(Z_esp)); 497 add2reg(Z_esp, -Interpreter::stackElementSize); 498 } 499 500 void InterpreterMacroAssembler::push_ptr(Register r) { 501 z_stg(r, Address(Z_esp)); 502 add2reg(Z_esp, -Interpreter::stackElementSize); 503 } 504 505 void InterpreterMacroAssembler::push_l(Register r) { 506 assert_different_registers(r, Z_R1_scratch); 507 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 508 int offset = -Interpreter::stackElementSize; 509 z_stg(r, Address(Z_esp, offset)); 510 clear_mem(Address(Z_esp), Interpreter::stackElementSize); 511 add2reg(Z_esp, 2 * offset); 512 } 513 514 void InterpreterMacroAssembler::push_f(FloatRegister f) { 515 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 516 freg2mem_opt(f, Address(Z_esp), false); 517 add2reg(Z_esp, -Interpreter::stackElementSize); 518 } 519 520 void InterpreterMacroAssembler::push_d(FloatRegister d) { 521 debug_only(verify_esp(Z_esp, Z_R1_scratch)); 522 int offset = -Interpreter::stackElementSize; 523 freg2mem_opt(d, Address(Z_esp, offset)); 524 add2reg(Z_esp, 2 * offset); 525 } 526 527 void InterpreterMacroAssembler::push(TosState state) { 528 verify_oop(Z_tos, state); 529 switch (state) { 530 case atos: push_ptr(); break; 531 case btos: push_i(); break; 532 case ztos: 533 case ctos: 534 case stos: push_i(); break; 535 case itos: push_i(); break; 536 case ltos: push_l(); break; 537 case ftos: push_f(); break; 538 case dtos: push_d(); break; 539 case vtos: /* nothing to do */ break; 540 default : ShouldNotReachHere(); 541 } 542 } 543 544 void InterpreterMacroAssembler::pop(TosState state) { 545 switch (state) { 546 case atos: pop_ptr(Z_tos); break; 547 case btos: pop_i(Z_tos); break; 548 case ztos: 549 case ctos: 550 case stos: pop_i(Z_tos); break; 551 case itos: pop_i(Z_tos); break; 552 case ltos: pop_l(Z_tos); break; 553 case ftos: pop_f(Z_ftos); break; 554 case dtos: pop_d(Z_ftos); break; 555 case vtos: /* nothing to do */ break; 556 default : ShouldNotReachHere(); 557 } 558 verify_oop(Z_tos, state); 559 } 560 561 // Helpers for swap and dup. 562 void InterpreterMacroAssembler::load_ptr(int n, Register val) { 563 z_lg(val, Address(Z_esp, Interpreter::expr_offset_in_bytes(n))); 564 } 565 566 void InterpreterMacroAssembler::store_ptr(int n, Register val) { 567 z_stg(val, Address(Z_esp, Interpreter::expr_offset_in_bytes(n))); 568 } 569 570 void InterpreterMacroAssembler::prepare_to_jump_from_interpreted(Register method) { 571 // Satisfy interpreter calling convention (see generate_normal_entry()). 572 z_lgr(Z_R10, Z_SP); // Set sender sp (aka initial caller sp, aka unextended sp). 573 // Record top_frame_sp, because the callee might modify it, if it's compiled. 574 z_stg(Z_SP, _z_ijava_state_neg(top_frame_sp), Z_fp); 575 save_bcp(); 576 save_esp(); 577 z_lgr(Z_method, method); // Set Z_method (kills Z_fp!). 578 } 579 580 // Jump to from_interpreted entry of a call unless single stepping is possible 581 // in this thread in which case we must call the i2i entry. 582 void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) { 583 assert_different_registers(method, Z_R10 /*used for initial_caller_sp*/, temp); 584 prepare_to_jump_from_interpreted(method); 585 586 if (JvmtiExport::can_post_interpreter_events()) { 587 // JVMTI events, such as single-stepping, are implemented partly by avoiding running 588 // compiled code in threads for which the event is enabled. Check here for 589 // interp_only_mode if these events CAN be enabled. 590 z_lg(Z_R1_scratch, Address(method, Method::from_interpreted_offset())); 591 MacroAssembler::load_and_test_int(Z_R0_scratch, Address(Z_thread, JavaThread::interp_only_mode_offset())); 592 z_bcr(bcondEqual, Z_R1_scratch); // Run compiled code if zero. 593 // Run interpreted. 594 z_lg(Z_R1_scratch, Address(method, Method::interpreter_entry_offset())); 595 z_br(Z_R1_scratch); 596 } else { 597 // Run compiled code. 598 z_lg(Z_R1_scratch, Address(method, Method::from_interpreted_offset())); 599 z_br(Z_R1_scratch); 600 } 601 } 602 603 #ifdef ASSERT 604 void InterpreterMacroAssembler::verify_esp(Register Resp, Register Rtemp) { 605 // About to read or write Resp[0]. 606 // Make sure it is not in the monitors or the TOP_IJAVA_FRAME_ABI. 607 address reentry = nullptr; 608 609 { 610 // Check if the frame pointer in Z_fp is correct. 611 NearLabel OK; 612 z_cg(Z_fp, 0, Z_SP); 613 z_bre(OK); 614 reentry = stop_chain_static(reentry, "invalid frame pointer Z_fp"); 615 bind(OK); 616 } 617 { 618 // Resp must not point into or below the operand stack, 619 // i.e. IJAVA_STATE.monitors > Resp. 620 NearLabel OK; 621 Register Rmonitors = Rtemp; 622 z_lg(Rmonitors, _z_ijava_state_neg(monitors), Z_fp); 623 compareU64_and_branch(Rmonitors, Resp, bcondHigh, OK); 624 reentry = stop_chain_static(reentry, "too many pops: Z_esp points into monitor area"); 625 bind(OK); 626 } 627 { 628 // Resp may point to the last word of TOP_IJAVA_FRAME_ABI, but not below 629 // i.e. !(Z_SP + frame::z_top_ijava_frame_abi_size - Interpreter::stackElementSize > Resp). 630 NearLabel OK; 631 Register Rabi_bottom = Rtemp; 632 add2reg(Rabi_bottom, frame::z_top_ijava_frame_abi_size - Interpreter::stackElementSize, Z_SP); 633 compareU64_and_branch(Rabi_bottom, Resp, bcondNotHigh, OK); 634 reentry = stop_chain_static(reentry, "too many pushes: Z_esp points into TOP_IJAVA_FRAME_ABI"); 635 bind(OK); 636 } 637 } 638 639 void InterpreterMacroAssembler::asm_assert_ijava_state_magic(Register tmp) { 640 Label magic_ok; 641 load_const_optimized(tmp, frame::z_istate_magic_number); 642 z_cg(tmp, Address(Z_fp, _z_ijava_state_neg(magic))); 643 z_bre(magic_ok); 644 stop_static("error: wrong magic number in ijava_state access"); 645 bind(magic_ok); 646 } 647 #endif // ASSERT 648 649 void InterpreterMacroAssembler::save_bcp() { 650 z_stg(Z_bcp, Address(Z_fp, _z_ijava_state_neg(bcp))); 651 asm_assert_ijava_state_magic(Z_bcp); 652 NOT_PRODUCT(z_lg(Z_bcp, Address(Z_fp, _z_ijava_state_neg(bcp)))); 653 } 654 655 void InterpreterMacroAssembler::restore_bcp() { 656 asm_assert_ijava_state_magic(Z_bcp); 657 z_lg(Z_bcp, Address(Z_fp, _z_ijava_state_neg(bcp))); 658 } 659 660 void InterpreterMacroAssembler::save_esp() { 661 z_stg(Z_esp, Address(Z_fp, _z_ijava_state_neg(esp))); 662 } 663 664 void InterpreterMacroAssembler::restore_esp() { 665 asm_assert_ijava_state_magic(Z_esp); 666 z_lg(Z_esp, Address(Z_fp, _z_ijava_state_neg(esp))); 667 } 668 669 void InterpreterMacroAssembler::get_monitors(Register reg) { 670 asm_assert_ijava_state_magic(reg); 671 mem2reg_opt(reg, Address(Z_fp, _z_ijava_state_neg(monitors))); 672 } 673 674 void InterpreterMacroAssembler::save_monitors(Register reg) { 675 reg2mem_opt(reg, Address(Z_fp, _z_ijava_state_neg(monitors))); 676 } 677 678 void InterpreterMacroAssembler::get_mdp(Register mdp) { 679 z_lg(mdp, _z_ijava_state_neg(mdx), Z_fp); 680 } 681 682 void InterpreterMacroAssembler::save_mdp(Register mdp) { 683 z_stg(mdp, _z_ijava_state_neg(mdx), Z_fp); 684 } 685 686 // Values that are only read (besides initialization). 687 void InterpreterMacroAssembler::restore_locals() { 688 asm_assert_ijava_state_magic(Z_locals); 689 z_lg(Z_locals, Address(Z_fp, _z_ijava_state_neg(locals))); 690 } 691 692 void InterpreterMacroAssembler::get_method(Register reg) { 693 asm_assert_ijava_state_magic(reg); 694 z_lg(reg, Address(Z_fp, _z_ijava_state_neg(method))); 695 } 696 697 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(Register Rdst, int bcp_offset, 698 signedOrNot is_signed) { 699 // Rdst is an 8-byte return value!!! 700 701 // Unaligned loads incur only a small penalty on z/Architecture. The penalty 702 // is a few (2..3) ticks, even when the load crosses a cache line 703 // boundary. In case of a cache miss, the stall could, of course, be 704 // much longer. 705 706 switch (is_signed) { 707 case Signed: 708 z_lgh(Rdst, bcp_offset, Z_R0, Z_bcp); 709 break; 710 case Unsigned: 711 z_llgh(Rdst, bcp_offset, Z_R0, Z_bcp); 712 break; 713 default: 714 ShouldNotReachHere(); 715 } 716 } 717 718 719 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(Register Rdst, int bcp_offset, 720 setCCOrNot set_cc) { 721 // Rdst is an 8-byte return value!!! 722 723 // Unaligned loads incur only a small penalty on z/Architecture. The penalty 724 // is a few (2..3) ticks, even when the load crosses a cache line 725 // boundary. In case of a cache miss, the stall could, of course, be 726 // much longer. 727 728 // Both variants implement a sign-extending int2long load. 729 if (set_cc == set_CC) { 730 load_and_test_int2long(Rdst, Address(Z_bcp, (intptr_t)bcp_offset)); 731 } else { 732 mem2reg_signed_opt( Rdst, Address(Z_bcp, (intptr_t)bcp_offset)); 733 } 734 } 735 736 void InterpreterMacroAssembler::get_constant_pool(Register Rdst) { 737 get_method(Rdst); 738 mem2reg_opt(Rdst, Address(Rdst, Method::const_offset())); 739 mem2reg_opt(Rdst, Address(Rdst, ConstMethod::constants_offset())); 740 } 741 742 void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) { 743 get_constant_pool(Rdst); 744 mem2reg_opt(Rdst, Address(Rdst, ConstantPool::cache_offset())); 745 } 746 747 void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) { 748 get_constant_pool(Rcpool); 749 mem2reg_opt(Rtags, Address(Rcpool, ConstantPool::tags_offset())); 750 } 751 752 // Unlock if synchronized method. 753 // 754 // Unlock the receiver if this is a synchronized method. 755 // Unlock any Java monitors from synchronized blocks. 756 // 757 // If there are locked Java monitors 758 // If throw_monitor_exception 759 // throws IllegalMonitorStateException 760 // Else if install_monitor_exception 761 // installs IllegalMonitorStateException 762 // Else 763 // no error processing 764 void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state, 765 bool throw_monitor_exception, 766 bool install_monitor_exception) { 767 NearLabel unlocked, unlock, no_unlock; 768 769 { 770 Register R_method = Z_ARG2; 771 Register R_do_not_unlock_if_synchronized = Z_ARG3; 772 773 // Get the value of _do_not_unlock_if_synchronized into G1_scratch. 774 const Address do_not_unlock_if_synchronized(Z_thread, 775 JavaThread::do_not_unlock_if_synchronized_offset()); 776 load_sized_value(R_do_not_unlock_if_synchronized, do_not_unlock_if_synchronized, 1, false /*unsigned*/); 777 z_mvi(do_not_unlock_if_synchronized, false); // Reset the flag. 778 779 // Check if synchronized method. 780 get_method(R_method); 781 verify_oop(Z_tos, state); 782 push(state); // Save tos/result. 783 testbit(method2_(R_method, access_flags), JVM_ACC_SYNCHRONIZED_BIT); 784 z_bfalse(unlocked); 785 786 // Don't unlock anything if the _do_not_unlock_if_synchronized flag 787 // is set. 788 compareU64_and_branch(R_do_not_unlock_if_synchronized, (intptr_t)0L, bcondNotEqual, no_unlock); 789 } 790 791 // unlock monitor 792 793 // BasicObjectLock will be first in list, since this is a 794 // synchronized method. However, need to check that the object has 795 // not been unlocked by an explicit monitorexit bytecode. 796 const Address monitor(Z_fp, -(frame::z_ijava_state_size + (int) sizeof(BasicObjectLock))); 797 // We use Z_ARG2 so that if we go slow path it will be the correct 798 // register for unlock_object to pass to VM directly. 799 load_address(Z_ARG2, monitor); // Address of first monitor. 800 z_lg(Z_ARG3, Address(Z_ARG2, BasicObjectLock::obj_offset())); 801 compareU64_and_branch(Z_ARG3, (intptr_t)0L, bcondNotEqual, unlock); 802 803 if (throw_monitor_exception) { 804 // Entry already unlocked need to throw an exception. 805 MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); 806 should_not_reach_here(); 807 } else { 808 // Monitor already unlocked during a stack unroll. 809 // If requested, install an illegal_monitor_state_exception. 810 // Continue with stack unrolling. 811 if (install_monitor_exception) { 812 MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception)); 813 } 814 z_bru(unlocked); 815 } 816 817 bind(unlock); 818 819 unlock_object(Z_ARG2); 820 821 bind(unlocked); 822 823 // I0, I1: Might contain return value 824 825 // Check that all monitors are unlocked. 826 { 827 NearLabel loop, exception, entry, restart; 828 const int entry_size = frame::interpreter_frame_monitor_size_in_bytes(); 829 // We use Z_ARG2 so that if we go slow path it will be the correct 830 // register for unlock_object to pass to VM directly. 831 Register R_current_monitor = Z_ARG2; 832 Register R_monitor_block_bot = Z_ARG1; 833 const Address monitor_block_top(Z_fp, _z_ijava_state_neg(monitors)); 834 const Address monitor_block_bot(Z_fp, -frame::z_ijava_state_size); 835 836 bind(restart); 837 // Starting with top-most entry. 838 z_lg(R_current_monitor, monitor_block_top); 839 // Points to word before bottom of monitor block. 840 load_address(R_monitor_block_bot, monitor_block_bot); 841 z_bru(entry); 842 843 // Entry already locked, need to throw exception. 844 bind(exception); 845 846 if (throw_monitor_exception) { 847 // Throw exception. 848 MacroAssembler::call_VM(noreg, 849 CAST_FROM_FN_PTR(address, InterpreterRuntime:: 850 throw_illegal_monitor_state_exception)); 851 should_not_reach_here(); 852 } else { 853 // Stack unrolling. Unlock object and install illegal_monitor_exception. 854 // Unlock does not block, so don't have to worry about the frame. 855 // We don't have to preserve c_rarg1 since we are going to throw an exception. 856 unlock_object(R_current_monitor); 857 if (install_monitor_exception) { 858 call_VM(noreg, CAST_FROM_FN_PTR(address, 859 InterpreterRuntime:: 860 new_illegal_monitor_state_exception)); 861 } 862 z_bru(restart); 863 } 864 865 bind(loop); 866 // Check if current entry is used. 867 load_and_test_long(Z_R0_scratch, Address(R_current_monitor, BasicObjectLock::obj_offset())); 868 z_brne(exception); 869 870 add2reg(R_current_monitor, entry_size); // Otherwise advance to next entry. 871 bind(entry); 872 compareU64_and_branch(R_current_monitor, R_monitor_block_bot, bcondNotEqual, loop); 873 } 874 875 bind(no_unlock); 876 pop(state); 877 verify_oop(Z_tos, state); 878 } 879 880 void InterpreterMacroAssembler::narrow(Register result, Register ret_type) { 881 get_method(ret_type); 882 z_lg(ret_type, Address(ret_type, in_bytes(Method::const_offset()))); 883 z_lb(ret_type, Address(ret_type, in_bytes(ConstMethod::result_type_offset()))); 884 885 Label notBool, notByte, notChar, done; 886 887 // common case first 888 compareU32_and_branch(ret_type, T_INT, bcondEqual, done); 889 890 compareU32_and_branch(ret_type, T_BOOLEAN, bcondNotEqual, notBool); 891 z_nilf(result, 0x1); 892 z_bru(done); 893 894 bind(notBool); 895 compareU32_and_branch(ret_type, T_BYTE, bcondNotEqual, notByte); 896 z_lbr(result, result); 897 z_bru(done); 898 899 bind(notByte); 900 compareU32_and_branch(ret_type, T_CHAR, bcondNotEqual, notChar); 901 z_nilf(result, 0xffff); 902 z_bru(done); 903 904 bind(notChar); 905 // compareU32_and_branch(ret_type, T_SHORT, bcondNotEqual, notShort); 906 z_lhr(result, result); 907 908 // Nothing to do for T_INT 909 bind(done); 910 } 911 912 // remove activation 913 // 914 // Unlock the receiver if this is a synchronized method. 915 // Unlock any Java monitors from synchronized blocks. 916 // Remove the activation from the stack. 917 // 918 // If there are locked Java monitors 919 // If throw_monitor_exception 920 // throws IllegalMonitorStateException 921 // Else if install_monitor_exception 922 // installs IllegalMonitorStateException 923 // Else 924 // no error processing 925 void InterpreterMacroAssembler::remove_activation(TosState state, 926 Register return_pc, 927 bool throw_monitor_exception, 928 bool install_monitor_exception, 929 bool notify_jvmti) { 930 BLOCK_COMMENT("remove_activation {"); 931 unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception); 932 933 // Save result (push state before jvmti call and pop it afterwards) and notify jvmti. 934 notify_method_exit(false, state, notify_jvmti ? NotifyJVMTI : SkipNotifyJVMTI); 935 936 if (StackReservedPages > 0) { 937 BLOCK_COMMENT("reserved_stack_check:"); 938 // Test if reserved zone needs to be enabled. 939 Label no_reserved_zone_enabling; 940 941 // check if already enabled - if so no re-enabling needed 942 assert(sizeof(StackOverflow::StackGuardState) == 4, "unexpected size"); 943 z_ly(Z_R0, Address(Z_thread, JavaThread::stack_guard_state_offset())); 944 compare32_and_branch(Z_R0, StackOverflow::stack_guard_enabled, bcondEqual, no_reserved_zone_enabling); 945 946 // Compare frame pointers. There is no good stack pointer, as with stack 947 // frame compression we can get different SPs when we do calls. A subsequent 948 // call could have a smaller SP, so that this compare succeeds for an 949 // inner call of the method annotated with ReservedStack. 950 z_lg(Z_R0, Address(Z_SP, (intptr_t)_z_abi(callers_sp))); 951 z_clg(Z_R0, Address(Z_thread, JavaThread::reserved_stack_activation_offset())); // Compare with frame pointer in memory. 952 z_brl(no_reserved_zone_enabling); 953 954 // Enable reserved zone again, throw stack overflow exception. 955 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), Z_thread); 956 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError)); 957 958 should_not_reach_here(); 959 960 bind(no_reserved_zone_enabling); 961 } 962 963 verify_oop(Z_tos, state); 964 965 pop_interpreter_frame(return_pc, Z_ARG2, Z_ARG3); 966 BLOCK_COMMENT("} remove_activation"); 967 } 968 969 // lock object 970 // 971 // Registers alive 972 // monitor (Z_R10) - Address of the BasicObjectLock to be used for locking, 973 // which must be initialized with the object to lock. 974 // object (Z_R11, Z_R2) - Address of the object to be locked. 975 // templateTable (monitorenter) is using Z_R2 for object 976 void InterpreterMacroAssembler::lock_object(Register monitor, Register object) { 977 978 if (LockingMode == LM_MONITOR) { 979 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor); 980 return; 981 } 982 983 // template code: (for LM_LEGACY) 984 // 985 // markWord displaced_header = obj->mark().set_unlocked(); 986 // monitor->lock()->set_displaced_header(displaced_header); 987 // if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) { 988 // // We stored the monitor address into the object's mark word. 989 // } else if (THREAD->is_lock_owned((address)displaced_header)) 990 // // Simple recursive case. 991 // monitor->lock()->set_displaced_header(nullptr); 992 // } else { 993 // // Slow path. 994 // InterpreterRuntime::monitorenter(THREAD, monitor); 995 // } 996 997 const int hdr_offset = oopDesc::mark_offset_in_bytes(); 998 999 const Register header = Z_ARG5; 1000 const Register object_mark_addr = Z_ARG4; 1001 const Register current_header = Z_ARG5; 1002 const Register tmp = Z_R1_scratch; 1003 1004 NearLabel done, slow_case; 1005 1006 // markWord header = obj->mark().set_unlocked(); 1007 1008 // Load markWord from object into header. 1009 z_lg(header, hdr_offset, object); 1010 1011 if (DiagnoseSyncOnValueBasedClasses != 0) { 1012 load_klass(tmp, object); 1013 testbit(Address(tmp, Klass::access_flags_offset()), exact_log2(JVM_ACC_IS_VALUE_BASED_CLASS)); 1014 z_btrue(slow_case); 1015 } 1016 1017 if (LockingMode == LM_LIGHTWEIGHT) { 1018 lightweight_lock(object, /* mark word */ header, tmp, slow_case); 1019 } else if (LockingMode == LM_LEGACY) { 1020 1021 // Set header to be (markWord of object | UNLOCK_VALUE). 1022 // This will not change anything if it was unlocked before. 1023 z_oill(header, markWord::unlocked_value); 1024 1025 // monitor->lock()->set_displaced_header(displaced_header); 1026 const int lock_offset = in_bytes(BasicObjectLock::lock_offset()); 1027 const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes(); 1028 1029 // Initialize the box (Must happen before we update the object mark!). 1030 z_stg(header, mark_offset, monitor); 1031 1032 // if (Atomic::cmpxchg(/*addr*/obj->mark_addr(), /*cmp*/displaced_header, /*ex=*/monitor) == displaced_header) { 1033 1034 // not necessary, use offset in instruction directly. 1035 // add2reg(object_mark_addr, hdr_offset, object); 1036 1037 // Store stack address of the BasicObjectLock (this is monitor) into object. 1038 z_csg(header, monitor, hdr_offset, object); 1039 assert(current_header == header, 1040 "must be same register"); // Identified two registers from z/Architecture. 1041 1042 z_bre(done); 1043 1044 // } else if (THREAD->is_lock_owned((address)displaced_header)) 1045 // // Simple recursive case. 1046 // monitor->lock()->set_displaced_header(nullptr); 1047 1048 // We did not see an unlocked object so try the fast recursive case. 1049 1050 // Check if owner is self by comparing the value in the markWord of object 1051 // (current_header) with the stack pointer. 1052 z_sgr(current_header, Z_SP); 1053 1054 assert(os::vm_page_size() > 0xfff, "page size too small - change the constant"); 1055 1056 // The prior sequence "LGR, NGR, LTGR" can be done better 1057 // (Z_R1 is temp and not used after here). 1058 load_const_optimized(Z_R0, (~(os::vm_page_size() - 1) | markWord::lock_mask_in_place)); 1059 z_ngr(Z_R0, current_header); // AND sets CC (result eq/ne 0) 1060 1061 // If condition is true we are done and hence we can store 0 in the displaced 1062 // header indicating it is a recursive lock and be done. 1063 z_brne(slow_case); 1064 z_release(); // Member unnecessary on zarch AND because the above csg does a sync before and after. 1065 z_stg(Z_R0/*==0!*/, mark_offset, monitor); 1066 } 1067 z_bru(done); 1068 // } else { 1069 // // Slow path. 1070 // InterpreterRuntime::monitorenter(THREAD, monitor); 1071 1072 // None of the above fast optimizations worked so we have to get into the 1073 // slow case of monitor enter. 1074 bind(slow_case); 1075 if (LockingMode == LM_LIGHTWEIGHT) { 1076 // for lightweight locking we need to use monitorenter_obj, see interpreterRuntime.cpp 1077 call_VM(noreg, 1078 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter_obj), 1079 object); 1080 } else { 1081 call_VM(noreg, 1082 CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), 1083 monitor); 1084 } 1085 // } 1086 1087 bind(done); 1088 } 1089 1090 // Unlocks an object. Used in monitorexit bytecode and remove_activation. 1091 // 1092 // Registers alive 1093 // monitor - address of the BasicObjectLock to be used for locking, 1094 // which must be initialized with the object to lock. 1095 // 1096 // Throw IllegalMonitorException if object is not locked by current thread. 1097 void InterpreterMacroAssembler::unlock_object(Register monitor, Register object) { 1098 1099 if (LockingMode == LM_MONITOR) { 1100 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor); 1101 return; 1102 } 1103 1104 // else { 1105 // template code: (for LM_LEGACY): 1106 // 1107 // if ((displaced_header = monitor->displaced_header()) == nullptr) { 1108 // // Recursive unlock. Mark the monitor unlocked by setting the object field to null. 1109 // monitor->set_obj(nullptr); 1110 // } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) { 1111 // // We swapped the unlocked mark in displaced_header into the object's mark word. 1112 // monitor->set_obj(nullptr); 1113 // } else { 1114 // // Slow path. 1115 // InterpreterRuntime::monitorexit(monitor); 1116 // } 1117 1118 const int hdr_offset = oopDesc::mark_offset_in_bytes(); 1119 1120 const Register header = Z_ARG4; 1121 const Register current_header = Z_R1_scratch; 1122 Address obj_entry(monitor, BasicObjectLock::obj_offset()); 1123 Label done, slow_case; 1124 1125 if (object == noreg) { 1126 // In the template interpreter, we must assure that the object 1127 // entry in the monitor is cleared on all paths. Thus we move 1128 // loading up to here, and clear the entry afterwards. 1129 object = Z_ARG3; // Use Z_ARG3 if caller didn't pass object. 1130 z_lg(object, obj_entry); 1131 } 1132 1133 assert_different_registers(monitor, object, header, current_header); 1134 1135 // if ((displaced_header = monitor->displaced_header()) == nullptr) { 1136 // // Recursive unlock. Mark the monitor unlocked by setting the object field to null. 1137 // monitor->set_obj(nullptr); 1138 1139 // monitor->lock()->set_displaced_header(displaced_header); 1140 const int lock_offset = in_bytes(BasicObjectLock::lock_offset()); 1141 const int mark_offset = lock_offset + BasicLock::displaced_header_offset_in_bytes(); 1142 1143 clear_mem(obj_entry, sizeof(oop)); 1144 if (LockingMode != LM_LIGHTWEIGHT) { 1145 // Test first if we are in the fast recursive case. 1146 MacroAssembler::load_and_test_long(header, Address(monitor, mark_offset)); 1147 z_bre(done); // header == 0 -> goto done 1148 } 1149 1150 // } else if (Atomic::cmpxchg(obj->mark_addr(), monitor, displaced_header) == monitor) { 1151 // // We swapped the unlocked mark in displaced_header into the object's mark word. 1152 // monitor->set_obj(nullptr); 1153 1154 // If we still have a lightweight lock, unlock the object and be done. 1155 if (LockingMode == LM_LIGHTWEIGHT) { 1156 // Check for non-symmetric locking. This is allowed by the spec and the interpreter 1157 // must handle it. 1158 1159 Register tmp = current_header; 1160 1161 // First check for lock-stack underflow. 1162 z_lgf(tmp, Address(Z_thread, JavaThread::lock_stack_top_offset())); 1163 compareU32_and_branch(tmp, (unsigned)LockStack::start_offset(), Assembler::bcondNotHigh, slow_case); 1164 1165 // Then check if the top of the lock-stack matches the unlocked object. 1166 z_aghi(tmp, -oopSize); 1167 z_lg(tmp, Address(Z_thread, tmp)); 1168 compare64_and_branch(tmp, object, Assembler::bcondNotEqual, slow_case); 1169 1170 z_lg(header, Address(object, hdr_offset)); 1171 z_lgr(tmp, header); 1172 z_nill(tmp, markWord::monitor_value); 1173 z_brne(slow_case); 1174 1175 lightweight_unlock(object, header, tmp, slow_case); 1176 1177 z_bru(done); 1178 } else { 1179 // The markword is expected to be at offset 0. 1180 // This is not required on s390, at least not here. 1181 assert(hdr_offset == 0, "unlock_object: review code below"); 1182 1183 // We have the displaced header in header. If the lock is still 1184 // lightweight, it will contain the monitor address and we'll store the 1185 // displaced header back into the object's mark word. 1186 z_lgr(current_header, monitor); 1187 z_csg(current_header, header, hdr_offset, object); 1188 z_bre(done); 1189 } 1190 1191 // } else { 1192 // // Slow path. 1193 // InterpreterRuntime::monitorexit(monitor); 1194 1195 // The lock has been converted into a heavy lock and hence 1196 // we need to get into the slow case. 1197 bind(slow_case); 1198 z_stg(object, obj_entry); // Restore object entry, has been cleared above. 1199 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor); 1200 1201 // } 1202 1203 bind(done); 1204 } 1205 1206 void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, Label& zero_continue) { 1207 assert(ProfileInterpreter, "must be profiling interpreter"); 1208 load_and_test_long(mdp, Address(Z_fp, _z_ijava_state_neg(mdx))); 1209 z_brz(zero_continue); 1210 } 1211 1212 // Set the method data pointer for the current bcp. 1213 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { 1214 assert(ProfileInterpreter, "must be profiling interpreter"); 1215 Label set_mdp; 1216 Register mdp = Z_ARG4; 1217 Register method = Z_ARG5; 1218 1219 get_method(method); 1220 // Test MDO to avoid the call if it is null. 1221 load_and_test_long(mdp, method2_(method, method_data)); 1222 z_brz(set_mdp); 1223 1224 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), method, Z_bcp); 1225 // Z_RET: mdi 1226 // Mdo is guaranteed to be non-zero here, we checked for it before the call. 1227 assert(method->is_nonvolatile(), "choose nonvolatile reg or reload from frame"); 1228 z_lg(mdp, method2_(method, method_data)); // Must reload, mdp is volatile reg. 1229 add2reg_with_index(mdp, in_bytes(MethodData::data_offset()), Z_RET, mdp); 1230 1231 bind(set_mdp); 1232 save_mdp(mdp); 1233 } 1234 1235 void InterpreterMacroAssembler::verify_method_data_pointer() { 1236 assert(ProfileInterpreter, "must be profiling interpreter"); 1237 #ifdef ASSERT 1238 NearLabel verify_continue; 1239 Register bcp_expected = Z_ARG3; 1240 Register mdp = Z_ARG4; 1241 Register method = Z_ARG5; 1242 1243 test_method_data_pointer(mdp, verify_continue); // If mdp is zero, continue 1244 get_method(method); 1245 1246 // If the mdp is valid, it will point to a DataLayout header which is 1247 // consistent with the bcp. The converse is highly probable also. 1248 load_sized_value(bcp_expected, Address(mdp, DataLayout::bci_offset()), 2, false /*signed*/); 1249 z_ag(bcp_expected, Address(method, Method::const_offset())); 1250 load_address(bcp_expected, Address(bcp_expected, ConstMethod::codes_offset())); 1251 compareU64_and_branch(bcp_expected, Z_bcp, bcondEqual, verify_continue); 1252 call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), method, Z_bcp, mdp); 1253 bind(verify_continue); 1254 #endif // ASSERT 1255 } 1256 1257 void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, int constant, Register value) { 1258 assert(ProfileInterpreter, "must be profiling interpreter"); 1259 z_stg(value, constant, mdp_in); 1260 } 1261 1262 void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, 1263 int constant, 1264 Register tmp, 1265 bool decrement) { 1266 assert_different_registers(mdp_in, tmp); 1267 // counter address 1268 Address data(mdp_in, constant); 1269 const int delta = decrement ? -DataLayout::counter_increment : DataLayout::counter_increment; 1270 add2mem_64(Address(mdp_in, constant), delta, tmp); 1271 } 1272 1273 void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, 1274 int flag_byte_constant) { 1275 assert(ProfileInterpreter, "must be profiling interpreter"); 1276 // Set the flag. 1277 z_oi(Address(mdp_in, DataLayout::flags_offset()), flag_byte_constant); 1278 } 1279 1280 void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in, 1281 int offset, 1282 Register value, 1283 Register test_value_out, 1284 Label& not_equal_continue) { 1285 assert(ProfileInterpreter, "must be profiling interpreter"); 1286 if (test_value_out == noreg) { 1287 z_cg(value, Address(mdp_in, offset)); 1288 z_brne(not_equal_continue); 1289 } else { 1290 // Put the test value into a register, so caller can use it: 1291 z_lg(test_value_out, Address(mdp_in, offset)); 1292 compareU64_and_branch(test_value_out, value, bcondNotEqual, not_equal_continue); 1293 } 1294 } 1295 1296 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, int offset_of_disp) { 1297 update_mdp_by_offset(mdp_in, noreg, offset_of_disp); 1298 } 1299 1300 void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, 1301 Register dataidx, 1302 int offset_of_disp) { 1303 assert(ProfileInterpreter, "must be profiling interpreter"); 1304 Address disp_address(mdp_in, dataidx, offset_of_disp); 1305 Assembler::z_ag(mdp_in, disp_address); 1306 save_mdp(mdp_in); 1307 } 1308 1309 void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, int constant) { 1310 assert(ProfileInterpreter, "must be profiling interpreter"); 1311 add2reg(mdp_in, constant); 1312 save_mdp(mdp_in); 1313 } 1314 1315 void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { 1316 assert(ProfileInterpreter, "must be profiling interpreter"); 1317 assert(return_bci->is_nonvolatile(), "choose nonvolatile reg or save/restore"); 1318 call_VM(noreg, 1319 CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), 1320 return_bci); 1321 } 1322 1323 void InterpreterMacroAssembler::profile_taken_branch(Register mdp, Register bumped_count) { 1324 if (ProfileInterpreter) { 1325 Label profile_continue; 1326 1327 // If no method data exists, go to profile_continue. 1328 // Otherwise, assign to mdp. 1329 test_method_data_pointer(mdp, profile_continue); 1330 1331 // We are taking a branch. Increment the taken count. 1332 // We inline increment_mdp_data_at to return bumped_count in a register 1333 //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); 1334 Address data(mdp, JumpData::taken_offset()); 1335 z_lg(bumped_count, data); 1336 // 64-bit overflow is very unlikely. Saturation to 32-bit values is 1337 // performed when reading the counts. 1338 add2reg(bumped_count, DataLayout::counter_increment); 1339 z_stg(bumped_count, data); // Store back out 1340 1341 // The method data pointer needs to be updated to reflect the new target. 1342 update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); 1343 bind(profile_continue); 1344 } 1345 } 1346 1347 // Kills Z_R1_scratch. 1348 void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { 1349 if (ProfileInterpreter) { 1350 Label profile_continue; 1351 1352 // If no method data exists, go to profile_continue. 1353 test_method_data_pointer(mdp, profile_continue); 1354 1355 // We are taking a branch. Increment the not taken count. 1356 increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset()), Z_R1_scratch); 1357 1358 // The method data pointer needs to be updated to correspond to 1359 // the next bytecode. 1360 update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size())); 1361 bind(profile_continue); 1362 } 1363 } 1364 1365 // Kills: Z_R1_scratch. 1366 void InterpreterMacroAssembler::profile_call(Register mdp) { 1367 if (ProfileInterpreter) { 1368 Label profile_continue; 1369 1370 // If no method data exists, go to profile_continue. 1371 test_method_data_pointer(mdp, profile_continue); 1372 1373 // We are making a call. Increment the count. 1374 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1375 1376 // The method data pointer needs to be updated to reflect the new target. 1377 update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size())); 1378 bind(profile_continue); 1379 } 1380 } 1381 1382 void InterpreterMacroAssembler::profile_final_call(Register mdp) { 1383 if (ProfileInterpreter) { 1384 Label profile_continue; 1385 1386 // If no method data exists, go to profile_continue. 1387 test_method_data_pointer(mdp, profile_continue); 1388 1389 // We are making a call. Increment the count. 1390 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1391 1392 // The method data pointer needs to be updated to reflect the new target. 1393 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size())); 1394 bind(profile_continue); 1395 } 1396 } 1397 1398 void InterpreterMacroAssembler::profile_virtual_call(Register receiver, 1399 Register mdp, 1400 Register reg2, 1401 bool receiver_can_be_null) { 1402 if (ProfileInterpreter) { 1403 NearLabel profile_continue; 1404 1405 // If no method data exists, go to profile_continue. 1406 test_method_data_pointer(mdp, profile_continue); 1407 1408 NearLabel skip_receiver_profile; 1409 if (receiver_can_be_null) { 1410 NearLabel not_null; 1411 compareU64_and_branch(receiver, (intptr_t)0L, bcondNotEqual, not_null); 1412 // We are making a call. Increment the count for null receiver. 1413 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1414 z_bru(skip_receiver_profile); 1415 bind(not_null); 1416 } 1417 1418 // Record the receiver type. 1419 record_klass_in_profile(receiver, mdp, reg2); 1420 bind(skip_receiver_profile); 1421 1422 // The method data pointer needs to be updated to reflect the new target. 1423 update_mdp_by_constant(mdp, in_bytes(VirtualCallData::virtual_call_data_size())); 1424 bind(profile_continue); 1425 } 1426 } 1427 1428 // This routine creates a state machine for updating the multi-row 1429 // type profile at a virtual call site (or other type-sensitive bytecode). 1430 // The machine visits each row (of receiver/count) until the receiver type 1431 // is found, or until it runs out of rows. At the same time, it remembers 1432 // the location of the first empty row. (An empty row records null for its 1433 // receiver, and can be allocated for a newly-observed receiver type.) 1434 // Because there are two degrees of freedom in the state, a simple linear 1435 // search will not work; it must be a decision tree. Hence this helper 1436 // function is recursive, to generate the required tree structured code. 1437 // It's the interpreter, so we are trading off code space for speed. 1438 // See below for example code. 1439 void InterpreterMacroAssembler::record_klass_in_profile_helper( 1440 Register receiver, Register mdp, 1441 Register reg2, int start_row, 1442 Label& done) { 1443 if (TypeProfileWidth == 0) { 1444 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1445 return; 1446 } 1447 1448 int last_row = VirtualCallData::row_limit() - 1; 1449 assert(start_row <= last_row, "must be work left to do"); 1450 // Test this row for both the receiver and for null. 1451 // Take any of three different outcomes: 1452 // 1. found receiver => increment count and goto done 1453 // 2. found null => keep looking for case 1, maybe allocate this cell 1454 // 3. found something else => keep looking for cases 1 and 2 1455 // Case 3 is handled by a recursive call. 1456 for (int row = start_row; row <= last_row; row++) { 1457 NearLabel next_test; 1458 bool test_for_null_also = (row == start_row); 1459 1460 // See if the receiver is receiver[n]. 1461 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row)); 1462 test_mdp_data_at(mdp, recvr_offset, receiver, 1463 (test_for_null_also ? reg2 : noreg), 1464 next_test); 1465 // (Reg2 now contains the receiver from the CallData.) 1466 1467 // The receiver is receiver[n]. Increment count[n]. 1468 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row)); 1469 increment_mdp_data_at(mdp, count_offset); 1470 z_bru(done); 1471 bind(next_test); 1472 1473 if (test_for_null_also) { 1474 Label found_null; 1475 // Failed the equality check on receiver[n]... Test for null. 1476 z_ltgr(reg2, reg2); 1477 if (start_row == last_row) { 1478 // The only thing left to do is handle the null case. 1479 z_brz(found_null); 1480 // Receiver did not match any saved receiver and there is no empty row for it. 1481 // Increment total counter to indicate polymorphic case. 1482 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1483 z_bru(done); 1484 bind(found_null); 1485 break; 1486 } 1487 // Since null is rare, make it be the branch-taken case. 1488 z_brz(found_null); 1489 1490 // Put all the "Case 3" tests here. 1491 record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done); 1492 1493 // Found a null. Keep searching for a matching receiver, 1494 // but remember that this is an empty (unused) slot. 1495 bind(found_null); 1496 } 1497 } 1498 1499 // In the fall-through case, we found no matching receiver, but we 1500 // observed the receiver[start_row] is null. 1501 1502 // Fill in the receiver field and increment the count. 1503 int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row)); 1504 set_mdp_data_at(mdp, recvr_offset, receiver); 1505 int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row)); 1506 load_const_optimized(reg2, DataLayout::counter_increment); 1507 set_mdp_data_at(mdp, count_offset, reg2); 1508 if (start_row > 0) { 1509 z_bru(done); 1510 } 1511 } 1512 1513 // Example state machine code for three profile rows: 1514 // // main copy of decision tree, rooted at row[1] 1515 // if (row[0].rec == rec) { row[0].incr(); goto done; } 1516 // if (row[0].rec != nullptr) { 1517 // // inner copy of decision tree, rooted at row[1] 1518 // if (row[1].rec == rec) { row[1].incr(); goto done; } 1519 // if (row[1].rec != nullptr) { 1520 // // degenerate decision tree, rooted at row[2] 1521 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1522 // if (row[2].rec != nullptr) { count.incr(); goto done; } // overflow 1523 // row[2].init(rec); goto done; 1524 // } else { 1525 // // remember row[1] is empty 1526 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1527 // row[1].init(rec); goto done; 1528 // } 1529 // } else { 1530 // // remember row[0] is empty 1531 // if (row[1].rec == rec) { row[1].incr(); goto done; } 1532 // if (row[2].rec == rec) { row[2].incr(); goto done; } 1533 // row[0].init(rec); goto done; 1534 // } 1535 // done: 1536 1537 void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, 1538 Register mdp, Register reg2) { 1539 assert(ProfileInterpreter, "must be profiling"); 1540 Label done; 1541 1542 record_klass_in_profile_helper(receiver, mdp, reg2, 0, done); 1543 1544 bind (done); 1545 } 1546 1547 void InterpreterMacroAssembler::profile_ret(Register return_bci, Register mdp) { 1548 if (ProfileInterpreter) { 1549 NearLabel profile_continue; 1550 uint row; 1551 1552 // If no method data exists, go to profile_continue. 1553 test_method_data_pointer(mdp, profile_continue); 1554 1555 // Update the total ret count. 1556 increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); 1557 1558 for (row = 0; row < RetData::row_limit(); row++) { 1559 NearLabel next_test; 1560 1561 // See if return_bci is equal to bci[n]: 1562 test_mdp_data_at(mdp, 1563 in_bytes(RetData::bci_offset(row)), 1564 return_bci, noreg, 1565 next_test); 1566 1567 // Return_bci is equal to bci[n]. Increment the count. 1568 increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row))); 1569 1570 // The method data pointer needs to be updated to reflect the new target. 1571 update_mdp_by_offset(mdp, in_bytes(RetData::bci_displacement_offset(row))); 1572 z_bru(profile_continue); 1573 bind(next_test); 1574 } 1575 1576 update_mdp_for_ret(return_bci); 1577 1578 bind(profile_continue); 1579 } 1580 } 1581 1582 void InterpreterMacroAssembler::profile_null_seen(Register mdp) { 1583 if (ProfileInterpreter) { 1584 Label profile_continue; 1585 1586 // If no method data exists, go to profile_continue. 1587 test_method_data_pointer(mdp, profile_continue); 1588 1589 set_mdp_flag_at(mdp, BitData::null_seen_byte_constant()); 1590 1591 // The method data pointer needs to be updated. 1592 int mdp_delta = in_bytes(BitData::bit_data_size()); 1593 if (TypeProfileCasts) { 1594 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1595 } 1596 update_mdp_by_constant(mdp, mdp_delta); 1597 1598 bind(profile_continue); 1599 } 1600 } 1601 1602 void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) { 1603 if (ProfileInterpreter) { 1604 Label profile_continue; 1605 1606 // If no method data exists, go to profile_continue. 1607 test_method_data_pointer(mdp, profile_continue); 1608 1609 // The method data pointer needs to be updated. 1610 int mdp_delta = in_bytes(BitData::bit_data_size()); 1611 if (TypeProfileCasts) { 1612 mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); 1613 1614 // Record the object type. 1615 record_klass_in_profile(klass, mdp, reg2); 1616 } 1617 update_mdp_by_constant(mdp, mdp_delta); 1618 1619 bind(profile_continue); 1620 } 1621 } 1622 1623 void InterpreterMacroAssembler::profile_switch_default(Register mdp) { 1624 if (ProfileInterpreter) { 1625 Label profile_continue; 1626 1627 // If no method data exists, go to profile_continue. 1628 test_method_data_pointer(mdp, profile_continue); 1629 1630 // Update the default case count. 1631 increment_mdp_data_at(mdp, in_bytes(MultiBranchData::default_count_offset())); 1632 1633 // The method data pointer needs to be updated. 1634 update_mdp_by_offset(mdp, in_bytes(MultiBranchData::default_displacement_offset())); 1635 1636 bind(profile_continue); 1637 } 1638 } 1639 1640 // Kills: index, scratch1, scratch2. 1641 void InterpreterMacroAssembler::profile_switch_case(Register index, 1642 Register mdp, 1643 Register scratch1, 1644 Register scratch2) { 1645 if (ProfileInterpreter) { 1646 Label profile_continue; 1647 assert_different_registers(index, mdp, scratch1, scratch2); 1648 1649 // If no method data exists, go to profile_continue. 1650 test_method_data_pointer(mdp, profile_continue); 1651 1652 // Build the base (index * per_case_size_in_bytes()) + 1653 // case_array_offset_in_bytes(). 1654 z_sllg(index, index, exact_log2(in_bytes(MultiBranchData::per_case_size()))); 1655 add2reg(index, in_bytes(MultiBranchData::case_array_offset())); 1656 1657 // Add the calculated base to the mdp -> address of the case' data. 1658 Address case_data_addr(mdp, index); 1659 Register case_data = scratch1; 1660 load_address(case_data, case_data_addr); 1661 1662 // Update the case count. 1663 increment_mdp_data_at(case_data, 1664 in_bytes(MultiBranchData::relative_count_offset()), 1665 scratch2); 1666 1667 // The method data pointer needs to be updated. 1668 update_mdp_by_offset(mdp, 1669 index, 1670 in_bytes(MultiBranchData::relative_displacement_offset())); 1671 1672 bind(profile_continue); 1673 } 1674 } 1675 1676 // kills: R0, R1, flags, loads klass from obj (if not null) 1677 void InterpreterMacroAssembler::profile_obj_type(Register obj, Address mdo_addr, Register klass, bool cmp_done) { 1678 NearLabel null_seen, init_klass, do_nothing, do_update; 1679 1680 // Klass = obj is allowed. 1681 const Register tmp = Z_R1; 1682 assert_different_registers(obj, mdo_addr.base(), tmp, Z_R0); 1683 assert_different_registers(klass, mdo_addr.base(), tmp, Z_R0); 1684 1685 z_lg(tmp, mdo_addr); 1686 if (cmp_done) { 1687 z_brz(null_seen); 1688 } else { 1689 compareU64_and_branch(obj, (intptr_t)0, Assembler::bcondEqual, null_seen); 1690 } 1691 1692 MacroAssembler::verify_oop(obj, FILE_AND_LINE); 1693 load_klass(klass, obj); 1694 1695 // Klass seen before, nothing to do (regardless of unknown bit). 1696 z_lgr(Z_R0, tmp); 1697 assert(Immediate::is_uimm(~TypeEntries::type_klass_mask, 16), "or change following instruction"); 1698 z_nill(Z_R0, TypeEntries::type_klass_mask & 0xFFFF); 1699 compareU64_and_branch(Z_R0, klass, Assembler::bcondEqual, do_nothing); 1700 1701 // Already unknown. Nothing to do anymore. 1702 z_tmll(tmp, TypeEntries::type_unknown); 1703 z_brc(Assembler::bcondAllOne, do_nothing); 1704 1705 z_lgr(Z_R0, tmp); 1706 assert(Immediate::is_uimm(~TypeEntries::type_mask, 16), "or change following instruction"); 1707 z_nill(Z_R0, TypeEntries::type_mask & 0xFFFF); 1708 compareU64_and_branch(Z_R0, (intptr_t)0, Assembler::bcondEqual, init_klass); 1709 1710 // Different than before. Cannot keep accurate profile. 1711 z_oill(tmp, TypeEntries::type_unknown); 1712 z_bru(do_update); 1713 1714 bind(init_klass); 1715 // Combine klass and null_seen bit (only used if (tmp & type_mask)==0). 1716 z_ogr(tmp, klass); 1717 z_bru(do_update); 1718 1719 bind(null_seen); 1720 // Set null_seen if obj is 0. 1721 z_oill(tmp, TypeEntries::null_seen); 1722 // fallthru: z_bru(do_update); 1723 1724 bind(do_update); 1725 z_stg(tmp, mdo_addr); 1726 1727 bind(do_nothing); 1728 } 1729 1730 void InterpreterMacroAssembler::profile_arguments_type(Register mdp, Register callee, Register tmp, bool is_virtual) { 1731 if (!ProfileInterpreter) { 1732 return; 1733 } 1734 1735 assert_different_registers(mdp, callee, tmp); 1736 1737 if (MethodData::profile_arguments() || MethodData::profile_return()) { 1738 Label profile_continue; 1739 1740 test_method_data_pointer(mdp, profile_continue); 1741 1742 int off_to_start = is_virtual ? in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size()); 1743 1744 z_cliy(in_bytes(DataLayout::tag_offset()) - off_to_start, mdp, 1745 is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag); 1746 z_brne(profile_continue); 1747 1748 if (MethodData::profile_arguments()) { 1749 NearLabel done; 1750 int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset()); 1751 add2reg(mdp, off_to_args); 1752 1753 for (int i = 0; i < TypeProfileArgsLimit; i++) { 1754 if (i > 0 || MethodData::profile_return()) { 1755 // If return value type is profiled we may have no argument to profile. 1756 z_lg(tmp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, mdp); 1757 add2reg(tmp, -i*TypeStackSlotEntries::per_arg_count()); 1758 compare64_and_branch(tmp, TypeStackSlotEntries::per_arg_count(), Assembler::bcondLow, done); 1759 } 1760 z_lg(tmp, Address(callee, Method::const_offset())); 1761 z_lgh(tmp, Address(tmp, ConstMethod::size_of_parameters_offset())); 1762 // Stack offset o (zero based) from the start of the argument 1763 // list. For n arguments translates into offset n - o - 1 from 1764 // the end of the argument list. But there is an extra slot at 1765 // the top of the stack. So the offset is n - o from Lesp. 1766 z_sg(tmp, Address(mdp, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args)); 1767 z_sllg(tmp, tmp, Interpreter::logStackElementSize); 1768 Address stack_slot_addr(tmp, Z_esp); 1769 z_ltg(tmp, stack_slot_addr); 1770 1771 Address mdo_arg_addr(mdp, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args); 1772 profile_obj_type(tmp, mdo_arg_addr, tmp, /*ltg did compare to 0*/ true); 1773 1774 int to_add = in_bytes(TypeStackSlotEntries::per_arg_size()); 1775 add2reg(mdp, to_add); 1776 off_to_args += to_add; 1777 } 1778 1779 if (MethodData::profile_return()) { 1780 z_lg(tmp, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, mdp); 1781 add2reg(tmp, -TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count()); 1782 } 1783 1784 bind(done); 1785 1786 if (MethodData::profile_return()) { 1787 // We're right after the type profile for the last 1788 // argument. Tmp is the number of cells left in the 1789 // CallTypeData/VirtualCallTypeData to reach its end. Non null 1790 // if there's a return to profile. 1791 assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(), "can't move past ret type"); 1792 z_sllg(tmp, tmp, exact_log2(DataLayout::cell_size)); 1793 z_agr(mdp, tmp); 1794 } 1795 z_stg(mdp, _z_ijava_state_neg(mdx), Z_fp); 1796 } else { 1797 assert(MethodData::profile_return(), "either profile call args or call ret"); 1798 update_mdp_by_constant(mdp, in_bytes(TypeEntriesAtCall::return_only_size())); 1799 } 1800 1801 // Mdp points right after the end of the 1802 // CallTypeData/VirtualCallTypeData, right after the cells for the 1803 // return value type if there's one. 1804 bind(profile_continue); 1805 } 1806 } 1807 1808 void InterpreterMacroAssembler::profile_return_type(Register mdp, Register ret, Register tmp) { 1809 assert_different_registers(mdp, ret, tmp); 1810 if (ProfileInterpreter && MethodData::profile_return()) { 1811 Label profile_continue; 1812 1813 test_method_data_pointer(mdp, profile_continue); 1814 1815 if (MethodData::profile_return_jsr292_only()) { 1816 // If we don't profile all invoke bytecodes we must make sure 1817 // it's a bytecode we indeed profile. We can't go back to the 1818 // beginning of the ProfileData we intend to update to check its 1819 // type because we're right after it and we don't known its 1820 // length. 1821 NearLabel do_profile; 1822 Address bc(Z_bcp); 1823 z_lb(tmp, bc); 1824 compare32_and_branch(tmp, Bytecodes::_invokedynamic, Assembler::bcondEqual, do_profile); 1825 compare32_and_branch(tmp, Bytecodes::_invokehandle, Assembler::bcondEqual, do_profile); 1826 get_method(tmp); 1827 // Supplement to 8139891: _intrinsic_id exceeded 1-byte size limit. 1828 if (Method::intrinsic_id_size_in_bytes() == 1) { 1829 z_cli(in_bytes(Method::intrinsic_id_offset()), tmp, static_cast<int>(vmIntrinsics::_compiledLambdaForm)); 1830 } else { 1831 assert(Method::intrinsic_id_size_in_bytes() == 2, "size error: check Method::_intrinsic_id"); 1832 z_lh(tmp, in_bytes(Method::intrinsic_id_offset()), Z_R0, tmp); 1833 z_chi(tmp, static_cast<int>(vmIntrinsics::_compiledLambdaForm)); 1834 } 1835 z_brne(profile_continue); 1836 1837 bind(do_profile); 1838 } 1839 1840 Address mdo_ret_addr(mdp, -in_bytes(ReturnTypeEntry::size())); 1841 profile_obj_type(ret, mdo_ret_addr, tmp); 1842 1843 bind(profile_continue); 1844 } 1845 } 1846 1847 void InterpreterMacroAssembler::profile_parameters_type(Register mdp, Register tmp1, Register tmp2) { 1848 if (ProfileInterpreter && MethodData::profile_parameters()) { 1849 Label profile_continue, done; 1850 1851 test_method_data_pointer(mdp, profile_continue); 1852 1853 // Load the offset of the area within the MDO used for 1854 // parameters. If it's negative we're not profiling any parameters. 1855 Address parm_di_addr(mdp, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset())); 1856 load_and_test_int2long(tmp1, parm_di_addr); 1857 z_brl(profile_continue); 1858 1859 // Compute a pointer to the area for parameters from the offset 1860 // and move the pointer to the slot for the last 1861 // parameters. Collect profiling from last parameter down. 1862 // mdo start + parameters offset + array length - 1 1863 1864 // Pointer to the parameter area in the MDO. 1865 z_agr(mdp, tmp1); 1866 1867 // Offset of the current profile entry to update. 1868 const Register entry_offset = tmp1; 1869 // entry_offset = array len in number of cells. 1870 z_lg(entry_offset, Address(mdp, ArrayData::array_len_offset())); 1871 // entry_offset (number of cells) = array len - size of 1 entry 1872 add2reg(entry_offset, -TypeStackSlotEntries::per_arg_count()); 1873 // entry_offset in bytes 1874 z_sllg(entry_offset, entry_offset, exact_log2(DataLayout::cell_size)); 1875 1876 Label loop; 1877 bind(loop); 1878 1879 Address arg_off(mdp, entry_offset, ParametersTypeData::stack_slot_offset(0)); 1880 Address arg_type(mdp, entry_offset, ParametersTypeData::type_offset(0)); 1881 1882 // Load offset on the stack from the slot for this parameter. 1883 z_lg(tmp2, arg_off); 1884 z_sllg(tmp2, tmp2, Interpreter::logStackElementSize); 1885 z_lcgr(tmp2); // Negate. 1886 1887 // Profile the parameter. 1888 z_ltg(tmp2, Address(Z_locals, tmp2)); 1889 profile_obj_type(tmp2, arg_type, tmp2, /*ltg did compare to 0*/ true); 1890 1891 // Go to next parameter. 1892 z_aghi(entry_offset, -TypeStackSlotEntries::per_arg_count() * DataLayout::cell_size); 1893 z_brnl(loop); 1894 1895 bind(profile_continue); 1896 } 1897 } 1898 1899 // Jump if ((*counter_addr += increment) & mask) satisfies the condition. 1900 void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, 1901 int increment, 1902 Address mask, 1903 Register scratch, 1904 bool preloaded, 1905 branch_condition cond, 1906 Label *where) { 1907 assert_different_registers(counter_addr.base(), scratch); 1908 if (preloaded) { 1909 add2reg(scratch, increment); 1910 reg2mem_opt(scratch, counter_addr, false); 1911 } else { 1912 if (VM_Version::has_MemWithImmALUOps() && Immediate::is_simm8(increment) && counter_addr.is_RSYform()) { 1913 z_alsi(counter_addr.disp20(), counter_addr.base(), increment); 1914 mem2reg_signed_opt(scratch, counter_addr); 1915 } else { 1916 mem2reg_signed_opt(scratch, counter_addr); 1917 add2reg(scratch, increment); 1918 reg2mem_opt(scratch, counter_addr, false); 1919 } 1920 } 1921 z_n(scratch, mask); 1922 if (where) { z_brc(cond, *where); } 1923 } 1924 1925 // Get MethodCounters object for given method. Lazily allocated if necessary. 1926 // method - Ptr to Method object. 1927 // Rcounters - Ptr to MethodCounters object associated with Method object. 1928 // skip - Exit point if MethodCounters object can't be created (OOM condition). 1929 void InterpreterMacroAssembler::get_method_counters(Register Rmethod, 1930 Register Rcounters, 1931 Label& skip) { 1932 assert_different_registers(Rmethod, Rcounters); 1933 1934 BLOCK_COMMENT("get MethodCounters object {"); 1935 1936 Label has_counters; 1937 load_and_test_long(Rcounters, Address(Rmethod, Method::method_counters_offset())); 1938 z_brnz(has_counters); 1939 1940 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::build_method_counters), Rmethod); 1941 z_ltgr(Rcounters, Z_RET); // Runtime call returns MethodCounters object. 1942 z_brz(skip); // No MethodCounters, out of memory. 1943 1944 bind(has_counters); 1945 1946 BLOCK_COMMENT("} get MethodCounters object"); 1947 } 1948 1949 // Increment invocation counter in MethodCounters object. 1950 // Return (invocation_counter+backedge_counter) as "result" in RctrSum. 1951 // Counter values are all unsigned. 1952 void InterpreterMacroAssembler::increment_invocation_counter(Register Rcounters, Register RctrSum) { 1953 assert(UseCompiler, "incrementing must be useful"); 1954 assert_different_registers(Rcounters, RctrSum); 1955 1956 int increment = InvocationCounter::count_increment; 1957 int inv_counter_offset = in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset()); 1958 int be_counter_offset = in_bytes(MethodCounters::backedge_counter_offset() + InvocationCounter::counter_offset()); 1959 1960 BLOCK_COMMENT("Increment invocation counter {"); 1961 1962 if (VM_Version::has_MemWithImmALUOps() && Immediate::is_simm8(increment)) { 1963 // Increment the invocation counter in place, 1964 // then add the incremented value to the backedge counter. 1965 z_l(RctrSum, be_counter_offset, Rcounters); 1966 z_alsi(inv_counter_offset, Rcounters, increment); // Atomic increment @no extra cost! 1967 z_nilf(RctrSum, InvocationCounter::count_mask_value); // Mask off state bits. 1968 z_al(RctrSum, inv_counter_offset, Z_R0, Rcounters); 1969 } else { 1970 // This path is optimized for low register consumption 1971 // at the cost of somewhat higher operand delays. 1972 // It does not need an extra temp register. 1973 1974 // Update the invocation counter. 1975 z_l(RctrSum, inv_counter_offset, Rcounters); 1976 if (RctrSum == Z_R0) { 1977 z_ahi(RctrSum, increment); 1978 } else { 1979 add2reg(RctrSum, increment); 1980 } 1981 z_st(RctrSum, inv_counter_offset, Rcounters); 1982 1983 // Mask off the state bits. 1984 z_nilf(RctrSum, InvocationCounter::count_mask_value); 1985 1986 // Add the backedge counter to the updated invocation counter to 1987 // form the result. 1988 z_al(RctrSum, be_counter_offset, Z_R0, Rcounters); 1989 } 1990 1991 BLOCK_COMMENT("} Increment invocation counter"); 1992 1993 // Note that this macro must leave the backedge_count + invocation_count in Rtmp! 1994 } 1995 1996 1997 // increment backedge counter in MethodCounters object. 1998 // return (invocation_counter+backedge_counter) as "result" in RctrSum 1999 // counter values are all unsigned! 2000 void InterpreterMacroAssembler::increment_backedge_counter(Register Rcounters, Register RctrSum) { 2001 assert(UseCompiler, "incrementing must be useful"); 2002 assert_different_registers(Rcounters, RctrSum); 2003 2004 int increment = InvocationCounter::count_increment; 2005 int inv_counter_offset = in_bytes(MethodCounters::invocation_counter_offset() + InvocationCounter::counter_offset()); 2006 int be_counter_offset = in_bytes(MethodCounters::backedge_counter_offset() + InvocationCounter::counter_offset()); 2007 2008 BLOCK_COMMENT("Increment backedge counter {"); 2009 2010 if (VM_Version::has_MemWithImmALUOps() && Immediate::is_simm8(increment)) { 2011 // Increment the invocation counter in place, 2012 // then add the incremented value to the backedge counter. 2013 z_l(RctrSum, inv_counter_offset, Rcounters); 2014 z_alsi(be_counter_offset, Rcounters, increment); // Atomic increment @no extra cost! 2015 z_nilf(RctrSum, InvocationCounter::count_mask_value); // Mask off state bits. 2016 z_al(RctrSum, be_counter_offset, Z_R0, Rcounters); 2017 } else { 2018 // This path is optimized for low register consumption 2019 // at the cost of somewhat higher operand delays. 2020 // It does not need an extra temp register. 2021 2022 // Update the invocation counter. 2023 z_l(RctrSum, be_counter_offset, Rcounters); 2024 if (RctrSum == Z_R0) { 2025 z_ahi(RctrSum, increment); 2026 } else { 2027 add2reg(RctrSum, increment); 2028 } 2029 z_st(RctrSum, be_counter_offset, Rcounters); 2030 2031 // Mask off the state bits. 2032 z_nilf(RctrSum, InvocationCounter::count_mask_value); 2033 2034 // Add the backedge counter to the updated invocation counter to 2035 // form the result. 2036 z_al(RctrSum, inv_counter_offset, Z_R0, Rcounters); 2037 } 2038 2039 BLOCK_COMMENT("} Increment backedge counter"); 2040 2041 // Note that this macro must leave the backedge_count + invocation_count in Rtmp! 2042 } 2043 2044 // Add an InterpMonitorElem to stack (see frame_s390.hpp). 2045 void InterpreterMacroAssembler::add_monitor_to_stack(bool stack_is_empty, 2046 Register Rtemp1, 2047 Register Rtemp2, 2048 Register Rtemp3) { 2049 2050 const Register Rcurr_slot = Rtemp1; 2051 const Register Rlimit = Rtemp2; 2052 const jint delta = -frame::interpreter_frame_monitor_size_in_bytes(); 2053 2054 assert((delta & LongAlignmentMask) == 0, 2055 "sizeof BasicObjectLock must be even number of doublewords"); 2056 assert(2 * wordSize == -delta, "this works only as long as delta == -2*wordSize"); 2057 assert(Rcurr_slot != Z_R0, "Register must be usable as base register"); 2058 assert_different_registers(Rlimit, Rcurr_slot, Rtemp3); 2059 2060 get_monitors(Rlimit); 2061 2062 // Adjust stack pointer for additional monitor entry. 2063 resize_frame(RegisterOrConstant((intptr_t) delta), Z_fp, false); 2064 2065 if (!stack_is_empty) { 2066 // Must copy stack contents down. 2067 NearLabel next, done; 2068 2069 // Rtemp := addr(Tos), Z_esp is pointing below it! 2070 add2reg(Rcurr_slot, wordSize, Z_esp); 2071 2072 // Nothing to do, if already at monitor area. 2073 compareU64_and_branch(Rcurr_slot, Rlimit, bcondNotLow, done); 2074 2075 bind(next); 2076 2077 // Move one stack slot. 2078 mem2reg_opt(Rtemp3, Address(Rcurr_slot)); 2079 reg2mem_opt(Rtemp3, Address(Rcurr_slot, delta)); 2080 add2reg(Rcurr_slot, wordSize); 2081 compareU64_and_branch(Rcurr_slot, Rlimit, bcondLow, next); // Are we done? 2082 2083 bind(done); 2084 // Done copying stack. 2085 } 2086 2087 // Adjust expression stack and monitor pointers. 2088 add2reg(Z_esp, delta); 2089 add2reg(Rlimit, delta); 2090 save_monitors(Rlimit); 2091 } 2092 2093 // Note: Index holds the offset in bytes afterwards. 2094 // You can use this to store a new value (with Llocals as the base). 2095 void InterpreterMacroAssembler::access_local_int(Register index, Register dst) { 2096 z_sllg(index, index, LogBytesPerWord); 2097 mem2reg_opt(dst, Address(Z_locals, index), false); 2098 } 2099 2100 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) { 2101 if (state == atos) { MacroAssembler::verify_oop(reg, FILE_AND_LINE); } 2102 } 2103 2104 // Inline assembly for: 2105 // 2106 // if (thread is in interp_only_mode) { 2107 // InterpreterRuntime::post_method_entry(); 2108 // } 2109 2110 void InterpreterMacroAssembler::notify_method_entry() { 2111 2112 // JVMTI 2113 // Whenever JVMTI puts a thread in interp_only_mode, method 2114 // entry/exit events are sent for that thread to track stack 2115 // depth. If it is possible to enter interp_only_mode we add 2116 // the code to check if the event should be sent. 2117 if (JvmtiExport::can_post_interpreter_events()) { 2118 Label jvmti_post_done; 2119 MacroAssembler::load_and_test_int(Z_R0, Address(Z_thread, JavaThread::interp_only_mode_offset())); 2120 z_bre(jvmti_post_done); 2121 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry)); 2122 bind(jvmti_post_done); 2123 } 2124 } 2125 2126 // Inline assembly for: 2127 // 2128 // if (thread is in interp_only_mode) { 2129 // if (!native_method) save result 2130 // InterpreterRuntime::post_method_exit(); 2131 // if (!native_method) restore result 2132 // } 2133 // if (DTraceMethodProbes) { 2134 // SharedRuntime::dtrace_method_exit(thread, method); 2135 // } 2136 // 2137 // For native methods their result is stored in z_ijava_state.lresult 2138 // and z_ijava_state.fresult before coming here. 2139 // Java methods have their result stored in the expression stack. 2140 // 2141 // Notice the dependency to frame::interpreter_frame_result(). 2142 void InterpreterMacroAssembler::notify_method_exit(bool native_method, 2143 TosState state, 2144 NotifyMethodExitMode mode) { 2145 // JVMTI 2146 // Whenever JVMTI puts a thread in interp_only_mode, method 2147 // entry/exit events are sent for that thread to track stack 2148 // depth. If it is possible to enter interp_only_mode we add 2149 // the code to check if the event should be sent. 2150 if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { 2151 Label jvmti_post_done; 2152 MacroAssembler::load_and_test_int(Z_R0, Address(Z_thread, JavaThread::interp_only_mode_offset())); 2153 z_bre(jvmti_post_done); 2154 if (!native_method) push(state); // see frame::interpreter_frame_result() 2155 call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); 2156 if (!native_method) pop(state); 2157 bind(jvmti_post_done); 2158 } 2159 2160 #if 0 2161 // Dtrace currently not supported on z/Architecture. 2162 { 2163 SkipIfEqual skip(this, &DTraceMethodProbes, false); 2164 push(state); 2165 get_method(c_rarg1); 2166 call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), 2167 r15_thread, c_rarg1); 2168 pop(state); 2169 } 2170 #endif 2171 } 2172 2173 void InterpreterMacroAssembler::skip_if_jvmti_mode(Label &Lskip, Register Rscratch) { 2174 if (!JvmtiExport::can_post_interpreter_events()) { 2175 return; 2176 } 2177 2178 load_and_test_int(Rscratch, Address(Z_thread, JavaThread::interp_only_mode_offset())); 2179 z_brnz(Lskip); 2180 2181 } 2182 2183 // Pop the topmost TOP_IJAVA_FRAME and set it's sender_sp as new Z_SP. 2184 // The return pc is loaded into the register return_pc. 2185 // 2186 // Registers updated: 2187 // return_pc - The return pc of the calling frame. 2188 // tmp1, tmp2 - scratch 2189 void InterpreterMacroAssembler::pop_interpreter_frame(Register return_pc, Register tmp1, Register tmp2) { 2190 // F0 Z_SP -> caller_sp (F1's) 2191 // ... 2192 // sender_sp (F1's) 2193 // ... 2194 // F1 Z_fp -> caller_sp (F2's) 2195 // return_pc (Continuation after return from F0.) 2196 // ... 2197 // F2 caller_sp 2198 2199 // Remove F0's activation. Restoring Z_SP to sender_sp reverts modifications 2200 // (a) by a c2i adapter and (b) by generate_fixed_frame(). 2201 // In case (a) the new top frame F1 is an unextended compiled frame. 2202 // In case (b) F1 is converted from PARENT_IJAVA_FRAME to TOP_IJAVA_FRAME. 2203 2204 // Case (b) seems to be redundant when returning to a interpreted caller, 2205 // because then the caller's top_frame_sp is installed as sp (see 2206 // TemplateInterpreterGenerator::generate_return_entry_for ()). But 2207 // pop_interpreter_frame() is also used in exception handling and there the 2208 // frame type of the caller is unknown, therefore top_frame_sp cannot be used, 2209 // so it is important that sender_sp is the caller's sp as TOP_IJAVA_FRAME. 2210 2211 Register R_f1_sender_sp = tmp1; 2212 Register R_f2_sp = tmp2; 2213 2214 // First check for the interpreter frame's magic. 2215 asm_assert_ijava_state_magic(R_f2_sp/*tmp*/); 2216 z_lg(R_f2_sp, _z_parent_ijava_frame_abi(callers_sp), Z_fp); 2217 z_lg(R_f1_sender_sp, _z_ijava_state_neg(sender_sp), Z_fp); 2218 if (return_pc->is_valid()) 2219 z_lg(return_pc, _z_parent_ijava_frame_abi(return_pc), Z_fp); 2220 // Pop F0 by resizing to R_f1_sender_sp and using R_f2_sp as fp. 2221 resize_frame_absolute(R_f1_sender_sp, R_f2_sp, false/*load fp*/); 2222 2223 #ifdef ASSERT 2224 // The return_pc in the new top frame is dead... at least that's my 2225 // current understanding; to assert this I overwrite it. 2226 load_const_optimized(Z_ARG3, 0xb00b1); 2227 z_stg(Z_ARG3, _z_parent_ijava_frame_abi(return_pc), Z_SP); 2228 #endif 2229 } 2230 2231 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { 2232 if (VerifyFPU) { 2233 unimplemented("verifyFPU"); 2234 } 2235 }