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