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