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