1 /*
   2  * Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright (c) 2012, 2021 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 
  27 #include "precompiled.hpp"
  28 #include "asm/macroAssembler.inline.hpp"
  29 #include "gc/shared/barrierSet.hpp"
  30 #include "gc/shared/barrierSetAssembler.hpp"
  31 #include "interp_masm_ppc.hpp"
  32 #include "interpreter/interpreterRuntime.hpp"
  33 #include "oops/methodData.hpp"
  34 #include "prims/jvmtiExport.hpp"
  35 #include "prims/jvmtiThreadState.hpp"
  36 #include "runtime/frame.inline.hpp"
  37 #include "runtime/safepointMechanism.hpp"
  38 #include "runtime/sharedRuntime.hpp"
  39 #include "runtime/vm_version.hpp"
  40 #include "utilities/macros.hpp"
  41 #include "utilities/powerOfTwo.hpp"
  42 
  43 // Implementation of InterpreterMacroAssembler.
  44 
  45 // This file specializes the assembler with interpreter-specific macros.
  46 
  47 #ifdef PRODUCT
  48 #define BLOCK_COMMENT(str) // nothing
  49 #else
  50 #define BLOCK_COMMENT(str) block_comment(str)
  51 #endif
  52 
  53 void InterpreterMacroAssembler::null_check_throw(Register a, int offset, Register temp_reg) {
  54   address exception_entry = Interpreter::throw_NullPointerException_entry();
  55   MacroAssembler::null_check_throw(a, offset, temp_reg, exception_entry);
  56 }
  57 
  58 void InterpreterMacroAssembler::jump_to_entry(address entry, Register Rscratch) {
  59   assert(entry, "Entry must have been generated by now");
  60   if (is_within_range_of_b(entry, pc())) {
  61     b(entry);
  62   } else {
  63     load_const_optimized(Rscratch, entry, R0);
  64     mtctr(Rscratch);
  65     bctr();
  66   }
  67 }
  68 
  69 void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr, bool generate_poll) {
  70   Register bytecode = R12_scratch2;
  71   if (bcp_incr != 0) {
  72     lbzu(bytecode, bcp_incr, R14_bcp);
  73   } else {
  74     lbz(bytecode, 0, R14_bcp);
  75   }
  76 
  77   dispatch_Lbyte_code(state, bytecode, Interpreter::dispatch_table(state), generate_poll);
  78 }
  79 
  80 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
  81   // Load current bytecode.
  82   Register bytecode = R12_scratch2;
  83   lbz(bytecode, 0, R14_bcp);
  84   dispatch_Lbyte_code(state, bytecode, table);
  85 }
  86 
  87 // Dispatch code executed in the prolog of a bytecode which does not do it's
  88 // own dispatch. The dispatch address is computed and placed in R24_dispatch_addr.
  89 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) {
  90   Register bytecode = R12_scratch2;
  91   lbz(bytecode, bcp_incr, R14_bcp);
  92 
  93   load_dispatch_table(R24_dispatch_addr, Interpreter::dispatch_table(state));
  94 
  95   sldi(bytecode, bytecode, LogBytesPerWord);
  96   ldx(R24_dispatch_addr, R24_dispatch_addr, bytecode);
  97 }
  98 
  99 // Dispatch code executed in the epilog of a bytecode which does not do it's
 100 // own dispatch. The dispatch address in R24_dispatch_addr is used for the
 101 // dispatch.
 102 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) {
 103   if (bcp_incr) { addi(R14_bcp, R14_bcp, bcp_incr); }
 104   mtctr(R24_dispatch_addr);
 105   bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable);
 106 }
 107 
 108 void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) {
 109   assert(scratch_reg != R0, "can't use R0 as scratch_reg here");
 110   if (JvmtiExport::can_pop_frame()) {
 111     Label L;
 112 
 113     // Check the "pending popframe condition" flag in the current thread.
 114     lwz(scratch_reg, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);
 115 
 116     // Initiate popframe handling only if it is not already being
 117     // processed. If the flag has the popframe_processing bit set, it
 118     // means that this code is called *during* popframe handling - we
 119     // don't want to reenter.
 120     andi_(R0, scratch_reg, JavaThread::popframe_pending_bit);
 121     beq(CCR0, L);
 122 
 123     andi_(R0, scratch_reg, JavaThread::popframe_processing_bit);
 124     bne(CCR0, L);
 125 
 126     // Call the Interpreter::remove_activation_preserving_args_entry()
 127     // func to get the address of the same-named entrypoint in the
 128     // generated interpreter code.
 129 #if defined(ABI_ELFv2)
 130     call_c(CAST_FROM_FN_PTR(address,
 131                             Interpreter::remove_activation_preserving_args_entry),
 132            relocInfo::none);
 133 #else
 134     call_c(CAST_FROM_FN_PTR(FunctionDescriptor*,
 135                             Interpreter::remove_activation_preserving_args_entry),
 136            relocInfo::none);
 137 #endif
 138 
 139     // Jump to Interpreter::_remove_activation_preserving_args_entry.
 140     mtctr(R3_RET);
 141     bctr();
 142 
 143     align(32, 12);
 144     bind(L);
 145   }
 146 }
 147 
 148 void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) {
 149   const Register Rthr_state_addr = scratch_reg;
 150   if (JvmtiExport::can_force_early_return()) {
 151     Label Lno_early_ret;
 152     ld(Rthr_state_addr, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
 153     cmpdi(CCR0, Rthr_state_addr, 0);
 154     beq(CCR0, Lno_early_ret);
 155 
 156     lwz(R0, in_bytes(JvmtiThreadState::earlyret_state_offset()), Rthr_state_addr);
 157     cmpwi(CCR0, R0, JvmtiThreadState::earlyret_pending);
 158     bne(CCR0, Lno_early_ret);
 159 
 160     // Jump to Interpreter::_earlyret_entry.
 161     lwz(R3_ARG1, in_bytes(JvmtiThreadState::earlyret_tos_offset()), Rthr_state_addr);
 162     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry));
 163     mtlr(R3_RET);
 164     blr();
 165 
 166     align(32, 12);
 167     bind(Lno_early_ret);
 168   }
 169 }
 170 
 171 void InterpreterMacroAssembler::load_earlyret_value(TosState state, Register Rscratch1) {
 172   const Register RjvmtiState = Rscratch1;
 173   const Register Rscratch2   = R0;
 174 
 175   ld(RjvmtiState, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
 176   li(Rscratch2, 0);
 177 
 178   switch (state) {
 179     case atos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);
 180                std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);
 181                break;
 182     case ltos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
 183                break;
 184     case btos: // fall through
 185     case ztos: // fall through
 186     case ctos: // fall through
 187     case stos: // fall through
 188     case itos: lwz(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
 189                break;
 190     case ftos: lfs(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
 191                break;
 192     case dtos: lfd(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
 193                break;
 194     case vtos: break;
 195     default  : ShouldNotReachHere();
 196   }
 197 
 198   // Clean up tos value in the jvmti thread state.
 199   std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
 200   // Set tos state field to illegal value.
 201   li(Rscratch2, ilgl);
 202   stw(Rscratch2, in_bytes(JvmtiThreadState::earlyret_tos_offset()), RjvmtiState);
 203 }
 204 
 205 // Common code to dispatch and dispatch_only.
 206 // Dispatch value in Lbyte_code and increment Lbcp.
 207 
 208 void InterpreterMacroAssembler::load_dispatch_table(Register dst, address* table) {
 209   address table_base = (address)Interpreter::dispatch_table((TosState)0);
 210   intptr_t table_offs = (intptr_t)table - (intptr_t)table_base;
 211   if (is_simm16(table_offs)) {
 212     addi(dst, R25_templateTableBase, (int)table_offs);
 213   } else {
 214     load_const_optimized(dst, table, R0);
 215   }
 216 }
 217 
 218 void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, Register bytecode,
 219                                                     address* table, bool generate_poll) {
 220   assert_different_registers(bytecode, R11_scratch1);
 221 
 222   // Calc dispatch table address.
 223   load_dispatch_table(R11_scratch1, table);
 224 
 225   if (generate_poll) {
 226     address *sfpt_tbl = Interpreter::safept_table(state);
 227     if (table != sfpt_tbl) {
 228       Label dispatch;
 229       ld(R0, in_bytes(JavaThread::polling_word_offset()), R16_thread);
 230       // Armed page has poll_bit set, if poll bit is cleared just continue.
 231       andi_(R0, R0, SafepointMechanism::poll_bit());
 232       beq(CCR0, dispatch);
 233       load_dispatch_table(R11_scratch1, sfpt_tbl);
 234       align(32, 16);
 235       bind(dispatch);
 236     }
 237   }
 238 
 239   sldi(R12_scratch2, bytecode, LogBytesPerWord);
 240   ldx(R11_scratch1, R11_scratch1, R12_scratch2);
 241 
 242   // Jump off!
 243   mtctr(R11_scratch1);
 244   bcctr(bcondAlways, 0, bhintbhBCCTRisNotPredictable);
 245 }
 246 
 247 void InterpreterMacroAssembler::load_receiver(Register Rparam_count, Register Rrecv_dst) {
 248   sldi(Rrecv_dst, Rparam_count, Interpreter::logStackElementSize);
 249   ldx(Rrecv_dst, Rrecv_dst, R15_esp);
 250 }
 251 
 252 // helpers for expression stack
 253 
 254 void InterpreterMacroAssembler::pop_i(Register r) {
 255   lwzu(r, Interpreter::stackElementSize, R15_esp);
 256 }
 257 
 258 void InterpreterMacroAssembler::pop_ptr(Register r) {
 259   ldu(r, Interpreter::stackElementSize, R15_esp);
 260 }
 261 
 262 void InterpreterMacroAssembler::pop_l(Register r) {
 263   ld(r, Interpreter::stackElementSize, R15_esp);
 264   addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);
 265 }
 266 
 267 void InterpreterMacroAssembler::pop_f(FloatRegister f) {
 268   lfsu(f, Interpreter::stackElementSize, R15_esp);
 269 }
 270 
 271 void InterpreterMacroAssembler::pop_d(FloatRegister f) {
 272   lfd(f, Interpreter::stackElementSize, R15_esp);
 273   addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);
 274 }
 275 
 276 void InterpreterMacroAssembler::push_i(Register r) {
 277   stw(r, 0, R15_esp);
 278   addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
 279 }
 280 
 281 void InterpreterMacroAssembler::push_ptr(Register r) {
 282   std(r, 0, R15_esp);
 283   addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
 284 }
 285 
 286 void InterpreterMacroAssembler::push_l(Register r) {
 287   // Clear unused slot.
 288   load_const_optimized(R0, 0L);
 289   std(R0, 0, R15_esp);
 290   std(r, - Interpreter::stackElementSize, R15_esp);
 291   addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
 292 }
 293 
 294 void InterpreterMacroAssembler::push_f(FloatRegister f) {
 295   stfs(f, 0, R15_esp);
 296   addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
 297 }
 298 
 299 void InterpreterMacroAssembler::push_d(FloatRegister f)   {
 300   stfd(f, - Interpreter::stackElementSize, R15_esp);
 301   addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
 302 }
 303 
 304 void InterpreterMacroAssembler::push_2ptrs(Register first, Register second) {
 305   std(first, 0, R15_esp);
 306   std(second, -Interpreter::stackElementSize, R15_esp);
 307   addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
 308 }
 309 
 310 void InterpreterMacroAssembler::move_l_to_d(Register l, FloatRegister d) {
 311   if (VM_Version::has_mtfprd()) {
 312     mtfprd(d, l);
 313   } else {
 314     std(l, 0, R15_esp);
 315     lfd(d, 0, R15_esp);
 316   }
 317 }
 318 
 319 void InterpreterMacroAssembler::move_d_to_l(FloatRegister d, Register l) {
 320   if (VM_Version::has_mtfprd()) {
 321     mffprd(l, d);
 322   } else {
 323     stfd(d, 0, R15_esp);
 324     ld(l, 0, R15_esp);
 325   }
 326 }
 327 
 328 void InterpreterMacroAssembler::push(TosState state) {
 329   switch (state) {
 330     case atos: push_ptr();                break;
 331     case btos:
 332     case ztos:
 333     case ctos:
 334     case stos:
 335     case itos: push_i();                  break;
 336     case ltos: push_l();                  break;
 337     case ftos: push_f();                  break;
 338     case dtos: push_d();                  break;
 339     case vtos: /* nothing to do */        break;
 340     default  : ShouldNotReachHere();
 341   }
 342 }
 343 
 344 void InterpreterMacroAssembler::pop(TosState state) {
 345   switch (state) {
 346     case atos: pop_ptr();            break;
 347     case btos:
 348     case ztos:
 349     case ctos:
 350     case stos:
 351     case itos: pop_i();              break;
 352     case ltos: pop_l();              break;
 353     case ftos: pop_f();              break;
 354     case dtos: pop_d();              break;
 355     case vtos: /* nothing to do */   break;
 356     default  : ShouldNotReachHere();
 357   }
 358   verify_oop(R17_tos, state);
 359 }
 360 
 361 void InterpreterMacroAssembler::empty_expression_stack() {
 362   addi(R15_esp, R26_monitor, - Interpreter::stackElementSize);
 363 }
 364 
 365 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(int         bcp_offset,
 366                                                           Register    Rdst,
 367                                                           signedOrNot is_signed) {
 368 #if defined(VM_LITTLE_ENDIAN)
 369   if (bcp_offset) {
 370     load_const_optimized(Rdst, bcp_offset);
 371     lhbrx(Rdst, R14_bcp, Rdst);
 372   } else {
 373     lhbrx(Rdst, R14_bcp);
 374   }
 375   if (is_signed == Signed) {
 376     extsh(Rdst, Rdst);
 377   }
 378 #else
 379   // Read Java big endian format.
 380   if (is_signed == Signed) {
 381     lha(Rdst, bcp_offset, R14_bcp);
 382   } else {
 383     lhz(Rdst, bcp_offset, R14_bcp);
 384   }
 385 #endif
 386 }
 387 
 388 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(int         bcp_offset,
 389                                                           Register    Rdst,
 390                                                           signedOrNot is_signed) {
 391 #if defined(VM_LITTLE_ENDIAN)
 392   if (bcp_offset) {
 393     load_const_optimized(Rdst, bcp_offset);
 394     lwbrx(Rdst, R14_bcp, Rdst);
 395   } else {
 396     lwbrx(Rdst, R14_bcp);
 397   }
 398   if (is_signed == Signed) {
 399     extsw(Rdst, Rdst);
 400   }
 401 #else
 402   // Read Java big endian format.
 403   if (bcp_offset & 3) { // Offset unaligned?
 404     load_const_optimized(Rdst, bcp_offset);
 405     if (is_signed == Signed) {
 406       lwax(Rdst, R14_bcp, Rdst);
 407     } else {
 408       lwzx(Rdst, R14_bcp, Rdst);
 409     }
 410   } else {
 411     if (is_signed == Signed) {
 412       lwa(Rdst, bcp_offset, R14_bcp);
 413     } else {
 414       lwz(Rdst, bcp_offset, R14_bcp);
 415     }
 416   }
 417 #endif
 418 }
 419 
 420 
 421 // Load the constant pool cache index from the bytecode stream.
 422 //
 423 // Kills / writes:
 424 //   - Rdst, Rscratch
 425 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register Rdst, int bcp_offset,
 426                                                        size_t index_size) {
 427   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
 428   // Cache index is always in the native format, courtesy of Rewriter.
 429   if (index_size == sizeof(u2)) {
 430     lhz(Rdst, bcp_offset, R14_bcp);
 431   } else if (index_size == sizeof(u4)) {
 432     if (bcp_offset & 3) {
 433       load_const_optimized(Rdst, bcp_offset);
 434       lwax(Rdst, R14_bcp, Rdst);
 435     } else {
 436       lwa(Rdst, bcp_offset, R14_bcp);
 437     }
 438     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
 439     nand(Rdst, Rdst, Rdst); // convert to plain index
 440   } else if (index_size == sizeof(u1)) {
 441     lbz(Rdst, bcp_offset, R14_bcp);
 442   } else {
 443     ShouldNotReachHere();
 444   }
 445   // Rdst now contains cp cache index.
 446 }
 447 
 448 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, int bcp_offset,
 449                                                            size_t index_size) {
 450   get_cache_index_at_bcp(cache, bcp_offset, index_size);
 451   sldi(cache, cache, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord));
 452   add(cache, R27_constPoolCache, cache);
 453 }
 454 
 455 // Load 4-byte signed or unsigned integer in Java format (that is, big-endian format)
 456 // from (Rsrc)+offset.
 457 void InterpreterMacroAssembler::get_u4(Register Rdst, Register Rsrc, int offset,
 458                                        signedOrNot is_signed) {
 459 #if defined(VM_LITTLE_ENDIAN)
 460   if (offset) {
 461     load_const_optimized(Rdst, offset);
 462     lwbrx(Rdst, Rdst, Rsrc);
 463   } else {
 464     lwbrx(Rdst, Rsrc);
 465   }
 466   if (is_signed == Signed) {
 467     extsw(Rdst, Rdst);
 468   }
 469 #else
 470   if (is_signed == Signed) {
 471     lwa(Rdst, offset, Rsrc);
 472   } else {
 473     lwz(Rdst, offset, Rsrc);
 474   }
 475 #endif
 476 }
 477 
 478 // Load object from cpool->resolved_references(index).
 479 // Kills:
 480 //   - index
 481 void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index,
 482                                                                  Register tmp1, Register tmp2,
 483                                                                  Label *L_handle_null) {
 484   assert_different_registers(result, index, tmp1, tmp2);
 485   assert(index->is_nonvolatile(), "needs to survive C-call in resolve_oop_handle");
 486   get_constant_pool(result);
 487 
 488   // Convert from field index to resolved_references() index and from
 489   // word index to byte offset. Since this is a java object, it can be compressed.
 490   sldi(index, index, LogBytesPerHeapOop);
 491   // Load pointer for resolved_references[] objArray.
 492   ld(result, ConstantPool::cache_offset_in_bytes(), result);
 493   ld(result, ConstantPoolCache::resolved_references_offset_in_bytes(), result);
 494   resolve_oop_handle(result, tmp1, tmp2, MacroAssembler::PRESERVATION_NONE);
 495 #ifdef ASSERT
 496   Label index_ok;
 497   lwa(R0, arrayOopDesc::length_offset_in_bytes(), result);
 498   sldi(R0, R0, LogBytesPerHeapOop);
 499   cmpd(CCR0, index, R0);
 500   blt(CCR0, index_ok);
 501   stop("resolved reference index out of bounds");
 502   bind(index_ok);
 503 #endif
 504   // Add in the index.
 505   add(result, index, result);
 506   load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result,
 507                 tmp1, tmp2,
 508                 MacroAssembler::PRESERVATION_NONE,
 509                 0, L_handle_null);
 510 }
 511 
 512 // load cpool->resolved_klass_at(index)
 513 void InterpreterMacroAssembler::load_resolved_klass_at_offset(Register Rcpool, Register Roffset, Register Rklass) {
 514   // int value = *(Rcpool->int_at_addr(which));
 515   // int resolved_klass_index = extract_low_short_from_int(value);
 516   add(Roffset, Rcpool, Roffset);
 517 #if defined(VM_LITTLE_ENDIAN)
 518   lhz(Roffset, sizeof(ConstantPool), Roffset);     // Roffset = resolved_klass_index
 519 #else
 520   lhz(Roffset, sizeof(ConstantPool) + 2, Roffset); // Roffset = resolved_klass_index
 521 #endif
 522 
 523   ld(Rklass, ConstantPool::resolved_klasses_offset_in_bytes(), Rcpool); // Rklass = Rcpool->_resolved_klasses
 524 
 525   sldi(Roffset, Roffset, LogBytesPerWord);
 526   addi(Roffset, Roffset, Array<Klass*>::base_offset_in_bytes());
 527   isync(); // Order load of instance Klass wrt. tags.
 528   ldx(Rklass, Rklass, Roffset);
 529 }
 530 
 531 void InterpreterMacroAssembler::load_resolved_method_at_index(int byte_no,
 532                                                               Register cache,
 533                                                               Register method) {
 534   const int method_offset = in_bytes(
 535     ConstantPoolCache::base_offset() +
 536       ((byte_no == TemplateTable::f2_byte)
 537        ? ConstantPoolCacheEntry::f2_offset()
 538        : ConstantPoolCacheEntry::f1_offset()));
 539 
 540   ld(method, method_offset, cache); // get f1 Method*
 541 }
 542 
 543 // Generate a subtype check: branch to ok_is_subtype if sub_klass is
 544 // a subtype of super_klass. Blows registers Rsub_klass, tmp1, tmp2.
 545 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, Register Rsuper_klass, Register Rtmp1,
 546                                                   Register Rtmp2, Register Rtmp3, Label &ok_is_subtype) {
 547   // Profile the not-null value's klass.
 548   profile_typecheck(Rsub_klass, Rtmp1, Rtmp2);
 549   check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype);
 550   profile_typecheck_failed(Rtmp1, Rtmp2);
 551 }
 552 
 553 // Separate these two to allow for delay slot in middle.
 554 // These are used to do a test and full jump to exception-throwing code.
 555 
 556 // Check that index is in range for array, then shift index by index_shift,
 557 // and put arrayOop + shifted_index into res.
 558 // Note: res is still shy of address by array offset into object.
 559 
 560 void InterpreterMacroAssembler::index_check_without_pop(Register Rarray, Register Rindex,
 561                                                         int index_shift, Register Rtmp, Register Rres) {
 562   // Check that index is in range for array, then shift index by index_shift,
 563   // and put arrayOop + shifted_index into res.
 564   // Note: res is still shy of address by array offset into object.
 565   // Kills:
 566   //   - Rindex
 567   // Writes:
 568   //   - Rres: Address that corresponds to the array index if check was successful.
 569   verify_oop(Rarray);
 570   const Register Rlength   = R0;
 571   const Register RsxtIndex = Rtmp;
 572   Label LisNull, LnotOOR;
 573 
 574   // Array nullcheck
 575   if (!ImplicitNullChecks) {
 576     cmpdi(CCR0, Rarray, 0);
 577     beq(CCR0, LisNull);
 578   } else {
 579     null_check_throw(Rarray, arrayOopDesc::length_offset_in_bytes(), /*temp*/RsxtIndex);
 580   }
 581 
 582   // Rindex might contain garbage in upper bits (remember that we don't sign extend
 583   // during integer arithmetic operations). So kill them and put value into same register
 584   // where ArrayIndexOutOfBounds would expect the index in.
 585   rldicl(RsxtIndex, Rindex, 0, 32); // zero extend 32 bit -> 64 bit
 586 
 587   // Index check
 588   lwz(Rlength, arrayOopDesc::length_offset_in_bytes(), Rarray);
 589   cmplw(CCR0, Rindex, Rlength);
 590   sldi(RsxtIndex, RsxtIndex, index_shift);
 591   blt(CCR0, LnotOOR);
 592   // Index should be in R17_tos, array should be in R4_ARG2.
 593   mr_if_needed(R17_tos, Rindex);
 594   mr_if_needed(R4_ARG2, Rarray);
 595   load_dispatch_table(Rtmp, (address*)Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
 596   mtctr(Rtmp);
 597   bctr();
 598 
 599   if (!ImplicitNullChecks) {
 600     bind(LisNull);
 601     load_dispatch_table(Rtmp, (address*)Interpreter::_throw_NullPointerException_entry);
 602     mtctr(Rtmp);
 603     bctr();
 604   }
 605 
 606   align(32, 16);
 607   bind(LnotOOR);
 608 
 609   // Calc address
 610   add(Rres, RsxtIndex, Rarray);
 611 }
 612 
 613 void InterpreterMacroAssembler::index_check(Register array, Register index,
 614                                             int index_shift, Register tmp, Register res) {
 615   // pop array
 616   pop_ptr(array);
 617 
 618   // check array
 619   index_check_without_pop(array, index, index_shift, tmp, res);
 620 }
 621 
 622 void InterpreterMacroAssembler::get_const(Register Rdst) {
 623   ld(Rdst, in_bytes(Method::const_offset()), R19_method);
 624 }
 625 
 626 void InterpreterMacroAssembler::get_constant_pool(Register Rdst) {
 627   get_const(Rdst);
 628   ld(Rdst, in_bytes(ConstMethod::constants_offset()), Rdst);
 629 }
 630 
 631 void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) {
 632   get_constant_pool(Rdst);
 633   ld(Rdst, ConstantPool::cache_offset_in_bytes(), Rdst);
 634 }
 635 
 636 void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) {
 637   get_constant_pool(Rcpool);
 638   ld(Rtags, ConstantPool::tags_offset_in_bytes(), Rcpool);
 639 }
 640 
 641 // Unlock if synchronized method.
 642 //
 643 // Unlock the receiver if this is a synchronized method.
 644 // Unlock any Java monitors from synchronized blocks.
 645 //
 646 // If there are locked Java monitors
 647 //   If throw_monitor_exception
 648 //     throws IllegalMonitorStateException
 649 //   Else if install_monitor_exception
 650 //     installs IllegalMonitorStateException
 651 //   Else
 652 //     no error processing
 653 void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state,
 654                                                               bool throw_monitor_exception,
 655                                                               bool install_monitor_exception) {
 656   Label Lunlocked, Lno_unlock;
 657   {
 658     Register Rdo_not_unlock_flag = R11_scratch1;
 659     Register Raccess_flags       = R12_scratch2;
 660 
 661     // Check if synchronized method or unlocking prevented by
 662     // JavaThread::do_not_unlock_if_synchronized flag.
 663     lbz(Rdo_not_unlock_flag, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
 664     lwz(Raccess_flags, in_bytes(Method::access_flags_offset()), R19_method);
 665     li(R0, 0);
 666     stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); // reset flag
 667 
 668     push(state);
 669 
 670     // Skip if we don't have to unlock.
 671     rldicl_(R0, Raccess_flags, 64-JVM_ACC_SYNCHRONIZED_BIT, 63); // Extract bit and compare to 0.
 672     beq(CCR0, Lunlocked);
 673 
 674     cmpwi(CCR0, Rdo_not_unlock_flag, 0);
 675     bne(CCR0, Lno_unlock);
 676   }
 677 
 678   // Unlock
 679   {
 680     Register Rmonitor_base = R11_scratch1;
 681 
 682     Label Lunlock;
 683     // If it's still locked, everything is ok, unlock it.
 684     ld(Rmonitor_base, 0, R1_SP);
 685     addi(Rmonitor_base, Rmonitor_base,
 686          -(frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base
 687 
 688     ld(R0, BasicObjectLock::obj_offset_in_bytes(), Rmonitor_base);
 689     cmpdi(CCR0, R0, 0);
 690     bne(CCR0, Lunlock);
 691 
 692     // If it's already unlocked, throw exception.
 693     if (throw_monitor_exception) {
 694       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
 695       should_not_reach_here();
 696     } else {
 697       if (install_monitor_exception) {
 698         call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
 699         b(Lunlocked);
 700       }
 701     }
 702 
 703     bind(Lunlock);
 704     unlock_object(Rmonitor_base);
 705   }
 706 
 707   // Check that all other monitors are unlocked. Throw IllegelMonitorState exception if not.
 708   bind(Lunlocked);
 709   {
 710     Label Lexception, Lrestart;
 711     Register Rcurrent_obj_addr = R11_scratch1;
 712     const int delta = frame::interpreter_frame_monitor_size_in_bytes();
 713     assert((delta & LongAlignmentMask) == 0, "sizeof BasicObjectLock must be even number of doublewords");
 714 
 715     bind(Lrestart);
 716     // Set up search loop: Calc num of iterations.
 717     {
 718       Register Riterations = R12_scratch2;
 719       Register Rmonitor_base = Rcurrent_obj_addr;
 720       ld(Rmonitor_base, 0, R1_SP);
 721       addi(Rmonitor_base, Rmonitor_base, - frame::ijava_state_size);  // Monitor base
 722 
 723       subf_(Riterations, R26_monitor, Rmonitor_base);
 724       ble(CCR0, Lno_unlock);
 725 
 726       addi(Rcurrent_obj_addr, Rmonitor_base,
 727            BasicObjectLock::obj_offset_in_bytes() - frame::interpreter_frame_monitor_size_in_bytes());
 728       // Check if any monitor is on stack, bail out if not
 729       srdi(Riterations, Riterations, exact_log2(delta));
 730       mtctr(Riterations);
 731     }
 732 
 733     // The search loop: Look for locked monitors.
 734     {
 735       const Register Rcurrent_obj = R0;
 736       Label Lloop;
 737 
 738       ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
 739       addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);
 740       bind(Lloop);
 741 
 742       // Check if current entry is used.
 743       cmpdi(CCR0, Rcurrent_obj, 0);
 744       bne(CCR0, Lexception);
 745       // Preload next iteration's compare value.
 746       ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
 747       addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);
 748       bdnz(Lloop);
 749     }
 750     // Fell through: Everything's unlocked => finish.
 751     b(Lno_unlock);
 752 
 753     // An object is still locked => need to throw exception.
 754     bind(Lexception);
 755     if (throw_monitor_exception) {
 756       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
 757       should_not_reach_here();
 758     } else {
 759       // Stack unrolling. Unlock object and if requested, install illegal_monitor_exception.
 760       // Unlock does not block, so don't have to worry about the frame.
 761       Register Rmonitor_addr = R11_scratch1;
 762       addi(Rmonitor_addr, Rcurrent_obj_addr, -BasicObjectLock::obj_offset_in_bytes() + delta);
 763       unlock_object(Rmonitor_addr);
 764       if (install_monitor_exception) {
 765         call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
 766       }
 767       b(Lrestart);
 768     }
 769   }
 770 
 771   align(32, 12);
 772   bind(Lno_unlock);
 773   pop(state);
 774 }
 775 
 776 // Support function for remove_activation & Co.
 777 void InterpreterMacroAssembler::merge_frames(Register Rsender_sp, Register return_pc,
 778                                              Register Rscratch1, Register Rscratch2) {
 779   // Pop interpreter frame.
 780   ld(Rscratch1, 0, R1_SP); // *SP
 781   ld(Rsender_sp, _ijava_state_neg(sender_sp), Rscratch1); // top_frame_sp
 782   ld(Rscratch2, 0, Rscratch1); // **SP
 783   if (return_pc!=noreg) {
 784     ld(return_pc, _abi0(lr), Rscratch1); // LR
 785   }
 786 
 787   // Merge top frames.
 788   subf(Rscratch1, R1_SP, Rsender_sp); // top_frame_sp - SP
 789   stdux(Rscratch2, R1_SP, Rscratch1); // atomically set *(SP = top_frame_sp) = **SP
 790 }
 791 
 792 void InterpreterMacroAssembler::narrow(Register result) {
 793   Register ret_type = R11_scratch1;
 794   ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
 795   lbz(ret_type, in_bytes(ConstMethod::result_type_offset()), R11_scratch1);
 796 
 797   Label notBool, notByte, notChar, done;
 798 
 799   // common case first
 800   cmpwi(CCR0, ret_type, T_INT);
 801   beq(CCR0, done);
 802 
 803   cmpwi(CCR0, ret_type, T_BOOLEAN);
 804   bne(CCR0, notBool);
 805   andi(result, result, 0x1);
 806   b(done);
 807 
 808   bind(notBool);
 809   cmpwi(CCR0, ret_type, T_BYTE);
 810   bne(CCR0, notByte);
 811   extsb(result, result);
 812   b(done);
 813 
 814   bind(notByte);
 815   cmpwi(CCR0, ret_type, T_CHAR);
 816   bne(CCR0, notChar);
 817   andi(result, result, 0xffff);
 818   b(done);
 819 
 820   bind(notChar);
 821   // cmpwi(CCR0, ret_type, T_SHORT);  // all that's left
 822   // bne(CCR0, done);
 823   extsh(result, result);
 824 
 825   // Nothing to do for T_INT
 826   bind(done);
 827 }
 828 
 829 // Remove activation.
 830 //
 831 // Apply stack watermark barrier.
 832 // Unlock the receiver if this is a synchronized method.
 833 // Unlock any Java monitors from synchronized blocks.
 834 // Remove the activation from the stack.
 835 //
 836 // If there are locked Java monitors
 837 //    If throw_monitor_exception
 838 //       throws IllegalMonitorStateException
 839 //    Else if install_monitor_exception
 840 //       installs IllegalMonitorStateException
 841 //    Else
 842 //       no error processing
 843 void InterpreterMacroAssembler::remove_activation(TosState state,
 844                                                   bool throw_monitor_exception,
 845                                                   bool install_monitor_exception) {
 846   BLOCK_COMMENT("remove_activation {");
 847 
 848   // The below poll is for the stack watermark barrier. It allows fixing up frames lazily,
 849   // that would normally not be safe to use. Such bad returns into unsafe territory of
 850   // the stack, will call InterpreterRuntime::at_unwind.
 851   Label slow_path;
 852   Label fast_path;
 853   safepoint_poll(slow_path, R11_scratch1, true /* at_return */, false /* in_nmethod */);
 854   b(fast_path);
 855   bind(slow_path);
 856   push(state);
 857   set_last_Java_frame(R1_SP, noreg);
 858   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::at_unwind), R16_thread);
 859   reset_last_Java_frame();
 860   pop(state);
 861   align(32);
 862   bind(fast_path);
 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, NotifyJVMTI, true);
 868 
 869   BLOCK_COMMENT("reserved_stack_check:");
 870   if (StackReservedPages > 0) {
 871     // Test if reserved zone needs to be enabled.
 872     Label no_reserved_zone_enabling;
 873 
 874     // Compare frame pointers. There is no good stack pointer, as with stack
 875     // frame compression we can get different SPs when we do calls. A subsequent
 876     // call could have a smaller SP, so that this compare succeeds for an
 877     // inner call of the method annotated with ReservedStack.
 878     ld_ptr(R0, JavaThread::reserved_stack_activation_offset(), R16_thread);
 879     ld_ptr(R11_scratch1, _abi0(callers_sp), R1_SP); // Load frame pointer.
 880     cmpld(CCR0, R11_scratch1, R0);
 881     blt_predict_taken(CCR0, no_reserved_zone_enabling);
 882 
 883     // Enable reserved zone again, throw stack overflow exception.
 884     call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::enable_stack_reserved_zone), R16_thread);
 885     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_delayed_StackOverflowError));
 886 
 887     should_not_reach_here();
 888 
 889     bind(no_reserved_zone_enabling);
 890   }
 891 
 892   verify_oop(R17_tos, state);
 893   verify_thread();
 894 
 895   merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
 896   mtlr(R0);
 897   BLOCK_COMMENT("} remove_activation");
 898 }
 899 
 900 // Lock object
 901 //
 902 // Registers alive
 903 //   monitor - Address of the BasicObjectLock to be used for locking,
 904 //             which must be initialized with the object to lock.
 905 //   object  - Address of the object to be locked.
 906 //
 907 void InterpreterMacroAssembler::lock_object(Register monitor, Register object) {
 908   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), monitor);
 909 }
 910 
 911 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
 912 //
 913 // Registers alive
 914 //   monitor - Address of the BasicObjectLock to be used for locking,
 915 //             which must be initialized with the object to lock.
 916 //
 917 // Throw IllegalMonitorException if object is not locked by current thread.
 918 void InterpreterMacroAssembler::unlock_object(Register monitor) {
 919   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), monitor);
 920 }
 921 
 922 // Load compiled (i2c) or interpreter entry when calling from interpreted and
 923 // do the call. Centralized so that all interpreter calls will do the same actions.
 924 // If jvmti single stepping is on for a thread we must not call compiled code.
 925 //
 926 // Input:
 927 //   - Rtarget_method: method to call
 928 //   - Rret_addr:      return address
 929 //   - 2 scratch regs
 930 //
 931 void InterpreterMacroAssembler::call_from_interpreter(Register Rtarget_method, Register Rret_addr,
 932                                                       Register Rscratch1, Register Rscratch2) {
 933   assert_different_registers(Rscratch1, Rscratch2, Rtarget_method, Rret_addr);
 934   // Assume we want to go compiled if available.
 935   const Register Rtarget_addr = Rscratch1;
 936   const Register Rinterp_only = Rscratch2;
 937 
 938   ld(Rtarget_addr, in_bytes(Method::from_interpreted_offset()), Rtarget_method);
 939 
 940   if (JvmtiExport::can_post_interpreter_events()) {
 941     lwz(Rinterp_only, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
 942 
 943     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
 944     // compiled code in threads for which the event is enabled. Check here for
 945     // interp_only_mode if these events CAN be enabled.
 946     Label done;
 947     verify_thread();
 948     cmpwi(CCR0, Rinterp_only, 0);
 949     beq(CCR0, done);
 950     ld(Rtarget_addr, in_bytes(Method::interpreter_entry_offset()), Rtarget_method);
 951     align(32, 12);
 952     bind(done);
 953   }
 954 
 955 #ifdef ASSERT
 956   {
 957     Label Lok;
 958     cmpdi(CCR0, Rtarget_addr, 0);
 959     bne(CCR0, Lok);
 960     stop("null entry point");
 961     bind(Lok);
 962   }
 963 #endif // ASSERT
 964 
 965   mr(R21_sender_SP, R1_SP);
 966 
 967   // Calc a precise SP for the call. The SP value we calculated in
 968   // generate_fixed_frame() is based on the max_stack() value, so we would waste stack space
 969   // if esp is not max. Also, the i2c adapter extends the stack space without restoring
 970   // our pre-calced value, so repeating calls via i2c would result in stack overflow.
 971   // Since esp already points to an empty slot, we just have to sub 1 additional slot
 972   // to meet the abi scratch requirements.
 973   // The max_stack pointer will get restored by means of the GR_Lmax_stack local in
 974   // the return entry of the interpreter.
 975   addi(Rscratch2, R15_esp, Interpreter::stackElementSize - frame::abi_reg_args_size);
 976   clrrdi(Rscratch2, Rscratch2, exact_log2(frame::alignment_in_bytes)); // round towards smaller address
 977   resize_frame_absolute(Rscratch2, Rscratch2, R0);
 978 
 979   mr_if_needed(R19_method, Rtarget_method);
 980   mtctr(Rtarget_addr);
 981   mtlr(Rret_addr);
 982 
 983   save_interpreter_state(Rscratch2);
 984 #ifdef ASSERT
 985   ld(Rscratch1, _ijava_state_neg(top_frame_sp), Rscratch2); // Rscratch2 contains fp
 986   cmpd(CCR0, R21_sender_SP, Rscratch1);
 987   asm_assert_eq("top_frame_sp incorrect");
 988 #endif
 989 
 990   bctr();
 991 }
 992 
 993 // Set the method data pointer for the current bcp.
 994 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
 995   assert(ProfileInterpreter, "must be profiling interpreter");
 996   Label get_continue;
 997   ld(R28_mdx, in_bytes(Method::method_data_offset()), R19_method);
 998   test_method_data_pointer(get_continue);
 999   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), R19_method, R14_bcp);
1000 
1001   addi(R28_mdx, R28_mdx, in_bytes(MethodData::data_offset()));
1002   add(R28_mdx, R28_mdx, R3_RET);
1003   bind(get_continue);
1004 }
1005 
1006 // Test ImethodDataPtr. If it is null, continue at the specified label.
1007 void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue) {
1008   assert(ProfileInterpreter, "must be profiling interpreter");
1009   cmpdi(CCR0, R28_mdx, 0);
1010   beq(CCR0, zero_continue);
1011 }
1012 
1013 void InterpreterMacroAssembler::verify_method_data_pointer() {
1014   assert(ProfileInterpreter, "must be profiling interpreter");
1015 #ifdef ASSERT
1016   Label verify_continue;
1017   test_method_data_pointer(verify_continue);
1018 
1019   // If the mdp is valid, it will point to a DataLayout header which is
1020   // consistent with the bcp. The converse is highly probable also.
1021   lhz(R11_scratch1, in_bytes(DataLayout::bci_offset()), R28_mdx);
1022   ld(R12_scratch2, in_bytes(Method::const_offset()), R19_method);
1023   addi(R11_scratch1, R11_scratch1, in_bytes(ConstMethod::codes_offset()));
1024   add(R11_scratch1, R12_scratch2, R12_scratch2);
1025   cmpd(CCR0, R11_scratch1, R14_bcp);
1026   beq(CCR0, verify_continue);
1027 
1028   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp ), R19_method, R14_bcp, R28_mdx);
1029 
1030   bind(verify_continue);
1031 #endif
1032 }
1033 
1034 // Store a value at some constant offset from the method data pointer.
1035 void InterpreterMacroAssembler::set_mdp_data_at(int constant, Register value) {
1036   assert(ProfileInterpreter, "must be profiling interpreter");
1037 
1038   std(value, constant, R28_mdx);
1039 }
1040 
1041 // Increment the value at some constant offset from the method data pointer.
1042 void InterpreterMacroAssembler::increment_mdp_data_at(int constant,
1043                                                       Register counter_addr,
1044                                                       Register Rbumped_count,
1045                                                       bool decrement) {
1046   // Locate the counter at a fixed offset from the mdp:
1047   addi(counter_addr, R28_mdx, constant);
1048   increment_mdp_data_at(counter_addr, Rbumped_count, decrement);
1049 }
1050 
1051 // Increment the value at some non-fixed (reg + constant) offset from
1052 // the method data pointer.
1053 void InterpreterMacroAssembler::increment_mdp_data_at(Register reg,
1054                                                       int constant,
1055                                                       Register scratch,
1056                                                       Register Rbumped_count,
1057                                                       bool decrement) {
1058   // Add the constant to reg to get the offset.
1059   add(scratch, R28_mdx, reg);
1060   // Then calculate the counter address.
1061   addi(scratch, scratch, constant);
1062   increment_mdp_data_at(scratch, Rbumped_count, decrement);
1063 }
1064 
1065 void InterpreterMacroAssembler::increment_mdp_data_at(Register counter_addr,
1066                                                       Register Rbumped_count,
1067                                                       bool decrement) {
1068   assert(ProfileInterpreter, "must be profiling interpreter");
1069 
1070   // Load the counter.
1071   ld(Rbumped_count, 0, counter_addr);
1072 
1073   if (decrement) {
1074     // Decrement the register. Set condition codes.
1075     addi(Rbumped_count, Rbumped_count, - DataLayout::counter_increment);
1076     // Store the decremented counter, if it is still negative.
1077     std(Rbumped_count, 0, counter_addr);
1078     // Note: add/sub overflow check are not ported, since 64 bit
1079     // calculation should never overflow.
1080   } else {
1081     // Increment the register. Set carry flag.
1082     addi(Rbumped_count, Rbumped_count, DataLayout::counter_increment);
1083     // Store the incremented counter.
1084     std(Rbumped_count, 0, counter_addr);
1085   }
1086 }
1087 
1088 // Set a flag value at the current method data pointer position.
1089 void InterpreterMacroAssembler::set_mdp_flag_at(int flag_constant,
1090                                                 Register scratch) {
1091   assert(ProfileInterpreter, "must be profiling interpreter");
1092   // Load the data header.
1093   lbz(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx);
1094   // Set the flag.
1095   ori(scratch, scratch, flag_constant);
1096   // Store the modified header.
1097   stb(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx);
1098 }
1099 
1100 // Test the location at some offset from the method data pointer.
1101 // If it is not equal to value, branch to the not_equal_continue Label.
1102 void InterpreterMacroAssembler::test_mdp_data_at(int offset,
1103                                                  Register value,
1104                                                  Label& not_equal_continue,
1105                                                  Register test_out) {
1106   assert(ProfileInterpreter, "must be profiling interpreter");
1107 
1108   ld(test_out, offset, R28_mdx);
1109   cmpd(CCR0,  value, test_out);
1110   bne(CCR0, not_equal_continue);
1111 }
1112 
1113 // Update the method data pointer by the displacement located at some fixed
1114 // offset from the method data pointer.
1115 void InterpreterMacroAssembler::update_mdp_by_offset(int offset_of_disp,
1116                                                      Register scratch) {
1117   assert(ProfileInterpreter, "must be profiling interpreter");
1118 
1119   ld(scratch, offset_of_disp, R28_mdx);
1120   add(R28_mdx, scratch, R28_mdx);
1121 }
1122 
1123 // Update the method data pointer by the displacement located at the
1124 // offset (reg + offset_of_disp).
1125 void InterpreterMacroAssembler::update_mdp_by_offset(Register reg,
1126                                                      int offset_of_disp,
1127                                                      Register scratch) {
1128   assert(ProfileInterpreter, "must be profiling interpreter");
1129 
1130   add(scratch, reg, R28_mdx);
1131   ld(scratch, offset_of_disp, scratch);
1132   add(R28_mdx, scratch, R28_mdx);
1133 }
1134 
1135 // Update the method data pointer by a simple constant displacement.
1136 void InterpreterMacroAssembler::update_mdp_by_constant(int constant) {
1137   assert(ProfileInterpreter, "must be profiling interpreter");
1138   addi(R28_mdx, R28_mdx, constant);
1139 }
1140 
1141 // Update the method data pointer for a _ret bytecode whose target
1142 // was not among our cached targets.
1143 void InterpreterMacroAssembler::update_mdp_for_ret(TosState state,
1144                                                    Register return_bci) {
1145   assert(ProfileInterpreter, "must be profiling interpreter");
1146 
1147   push(state);
1148   assert(return_bci->is_nonvolatile(), "need to protect return_bci");
1149   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
1150   pop(state);
1151 }
1152 
1153 // Increments the backedge counter.
1154 // Returns backedge counter + invocation counter in Rdst.
1155 void InterpreterMacroAssembler::increment_backedge_counter(const Register Rcounters, const Register Rdst,
1156                                                            const Register Rtmp1, Register Rscratch) {
1157   assert(UseCompiler, "incrementing must be useful");
1158   assert_different_registers(Rdst, Rtmp1);
1159   const Register invocation_counter = Rtmp1;
1160   const Register counter = Rdst;
1161   // TODO: PPC port: assert(4 == InvocationCounter::sz_counter(), "unexpected field size.");
1162 
1163   // Load backedge counter.
1164   lwz(counter, in_bytes(MethodCounters::backedge_counter_offset()) +
1165                in_bytes(InvocationCounter::counter_offset()), Rcounters);
1166   // Load invocation counter.
1167   lwz(invocation_counter, in_bytes(MethodCounters::invocation_counter_offset()) +
1168                           in_bytes(InvocationCounter::counter_offset()), Rcounters);
1169 
1170   // Add the delta to the backedge counter.
1171   addi(counter, counter, InvocationCounter::count_increment);
1172 
1173   // Mask the invocation counter.
1174   andi(invocation_counter, invocation_counter, InvocationCounter::count_mask_value);
1175 
1176   // Store new counter value.
1177   stw(counter, in_bytes(MethodCounters::backedge_counter_offset()) +
1178                in_bytes(InvocationCounter::counter_offset()), Rcounters);
1179   // Return invocation counter + backedge counter.
1180   add(counter, counter, invocation_counter);
1181 }
1182 
1183 // Count a taken branch in the bytecodes.
1184 void InterpreterMacroAssembler::profile_taken_branch(Register scratch, Register bumped_count) {
1185   if (ProfileInterpreter) {
1186     Label profile_continue;
1187 
1188     // If no method data exists, go to profile_continue.
1189     test_method_data_pointer(profile_continue);
1190 
1191     // We are taking a branch. Increment the taken count.
1192     increment_mdp_data_at(in_bytes(JumpData::taken_offset()), scratch, bumped_count);
1193 
1194     // The method data pointer needs to be updated to reflect the new target.
1195     update_mdp_by_offset(in_bytes(JumpData::displacement_offset()), scratch);
1196     bind (profile_continue);
1197   }
1198 }
1199 
1200 // Count a not-taken branch in the bytecodes.
1201 void InterpreterMacroAssembler::profile_not_taken_branch(Register scratch1, Register scratch2) {
1202   if (ProfileInterpreter) {
1203     Label profile_continue;
1204 
1205     // If no method data exists, go to profile_continue.
1206     test_method_data_pointer(profile_continue);
1207 
1208     // We are taking a branch. Increment the not taken count.
1209     increment_mdp_data_at(in_bytes(BranchData::not_taken_offset()), scratch1, scratch2);
1210 
1211     // The method data pointer needs to be updated to correspond to the
1212     // next bytecode.
1213     update_mdp_by_constant(in_bytes(BranchData::branch_data_size()));
1214     bind (profile_continue);
1215   }
1216 }
1217 
1218 // Count a non-virtual call in the bytecodes.
1219 void InterpreterMacroAssembler::profile_call(Register scratch1, Register scratch2) {
1220   if (ProfileInterpreter) {
1221     Label profile_continue;
1222 
1223     // If no method data exists, go to profile_continue.
1224     test_method_data_pointer(profile_continue);
1225 
1226     // We are making a call. Increment the count.
1227     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
1228 
1229     // The method data pointer needs to be updated to reflect the new target.
1230     update_mdp_by_constant(in_bytes(CounterData::counter_data_size()));
1231     bind (profile_continue);
1232   }
1233 }
1234 
1235 // Count a final call in the bytecodes.
1236 void InterpreterMacroAssembler::profile_final_call(Register scratch1, Register scratch2) {
1237   if (ProfileInterpreter) {
1238     Label profile_continue;
1239 
1240     // If no method data exists, go to profile_continue.
1241     test_method_data_pointer(profile_continue);
1242 
1243     // We are making a call. Increment the count.
1244     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
1245 
1246     // The method data pointer needs to be updated to reflect the new target.
1247     update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
1248     bind (profile_continue);
1249   }
1250 }
1251 
1252 // Count a virtual call in the bytecodes.
1253 void InterpreterMacroAssembler::profile_virtual_call(Register Rreceiver,
1254                                                      Register Rscratch1,
1255                                                      Register Rscratch2,
1256                                                      bool receiver_can_be_null) {
1257   if (!ProfileInterpreter) { return; }
1258   Label profile_continue;
1259 
1260   // If no method data exists, go to profile_continue.
1261   test_method_data_pointer(profile_continue);
1262 
1263   Label skip_receiver_profile;
1264   if (receiver_can_be_null) {
1265     Label not_null;
1266     cmpdi(CCR0, Rreceiver, 0);
1267     bne(CCR0, not_null);
1268     // We are making a call. Increment the count for null receiver.
1269     increment_mdp_data_at(in_bytes(CounterData::count_offset()), Rscratch1, Rscratch2);
1270     b(skip_receiver_profile);
1271     bind(not_null);
1272   }
1273 
1274   // Record the receiver type.
1275   record_klass_in_profile(Rreceiver, Rscratch1, Rscratch2, true);
1276   bind(skip_receiver_profile);
1277 
1278   // The method data pointer needs to be updated to reflect the new target.
1279   update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
1280   bind (profile_continue);
1281 }
1282 
1283 void InterpreterMacroAssembler::profile_typecheck(Register Rklass, Register Rscratch1, Register Rscratch2) {
1284   if (ProfileInterpreter) {
1285     Label profile_continue;
1286 
1287     // If no method data exists, go to profile_continue.
1288     test_method_data_pointer(profile_continue);
1289 
1290     int mdp_delta = in_bytes(BitData::bit_data_size());
1291     if (TypeProfileCasts) {
1292       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1293 
1294       // Record the object type.
1295       record_klass_in_profile(Rklass, Rscratch1, Rscratch2, false);
1296     }
1297 
1298     // The method data pointer needs to be updated.
1299     update_mdp_by_constant(mdp_delta);
1300 
1301     bind (profile_continue);
1302   }
1303 }
1304 
1305 void InterpreterMacroAssembler::profile_typecheck_failed(Register Rscratch1, Register Rscratch2) {
1306   if (ProfileInterpreter && TypeProfileCasts) {
1307     Label profile_continue;
1308 
1309     // If no method data exists, go to profile_continue.
1310     test_method_data_pointer(profile_continue);
1311 
1312     int count_offset = in_bytes(CounterData::count_offset());
1313     // Back up the address, since we have already bumped the mdp.
1314     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
1315 
1316     // *Decrement* the counter. We expect to see zero or small negatives.
1317     increment_mdp_data_at(count_offset, Rscratch1, Rscratch2, true);
1318 
1319     bind (profile_continue);
1320   }
1321 }
1322 
1323 // Count a ret in the bytecodes.
1324 void InterpreterMacroAssembler::profile_ret(TosState state, Register return_bci,
1325                                             Register scratch1, Register scratch2) {
1326   if (ProfileInterpreter) {
1327     Label profile_continue;
1328     uint row;
1329 
1330     // If no method data exists, go to profile_continue.
1331     test_method_data_pointer(profile_continue);
1332 
1333     // Update the total ret count.
1334     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2 );
1335 
1336     for (row = 0; row < RetData::row_limit(); row++) {
1337       Label next_test;
1338 
1339       // See if return_bci is equal to bci[n]:
1340       test_mdp_data_at(in_bytes(RetData::bci_offset(row)), return_bci, next_test, scratch1);
1341 
1342       // return_bci is equal to bci[n]. Increment the count.
1343       increment_mdp_data_at(in_bytes(RetData::bci_count_offset(row)), scratch1, scratch2);
1344 
1345       // The method data pointer needs to be updated to reflect the new target.
1346       update_mdp_by_offset(in_bytes(RetData::bci_displacement_offset(row)), scratch1);
1347       b(profile_continue);
1348       bind(next_test);
1349     }
1350 
1351     update_mdp_for_ret(state, return_bci);
1352 
1353     bind (profile_continue);
1354   }
1355 }
1356 
1357 // Count the default case of a switch construct.
1358 void InterpreterMacroAssembler::profile_switch_default(Register scratch1,  Register scratch2) {
1359   if (ProfileInterpreter) {
1360     Label profile_continue;
1361 
1362     // If no method data exists, go to profile_continue.
1363     test_method_data_pointer(profile_continue);
1364 
1365     // Update the default case count
1366     increment_mdp_data_at(in_bytes(MultiBranchData::default_count_offset()),
1367                           scratch1, scratch2);
1368 
1369     // The method data pointer needs to be updated.
1370     update_mdp_by_offset(in_bytes(MultiBranchData::default_displacement_offset()),
1371                          scratch1);
1372 
1373     bind (profile_continue);
1374   }
1375 }
1376 
1377 // Count the index'th case of a switch construct.
1378 void InterpreterMacroAssembler::profile_switch_case(Register index,
1379                                                     Register scratch1,
1380                                                     Register scratch2,
1381                                                     Register scratch3) {
1382   if (ProfileInterpreter) {
1383     assert_different_registers(index, scratch1, scratch2, scratch3);
1384     Label profile_continue;
1385 
1386     // If no method data exists, go to profile_continue.
1387     test_method_data_pointer(profile_continue);
1388 
1389     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes().
1390     li(scratch3, in_bytes(MultiBranchData::case_array_offset()));
1391 
1392     assert (in_bytes(MultiBranchData::per_case_size()) == 16, "so that shladd works");
1393     sldi(scratch1, index, exact_log2(in_bytes(MultiBranchData::per_case_size())));
1394     add(scratch1, scratch1, scratch3);
1395 
1396     // Update the case count.
1397     increment_mdp_data_at(scratch1, in_bytes(MultiBranchData::relative_count_offset()), scratch2, scratch3);
1398 
1399     // The method data pointer needs to be updated.
1400     update_mdp_by_offset(scratch1, in_bytes(MultiBranchData::relative_displacement_offset()), scratch2);
1401 
1402     bind (profile_continue);
1403   }
1404 }
1405 
1406 void InterpreterMacroAssembler::profile_null_seen(Register Rscratch1, Register Rscratch2) {
1407   if (ProfileInterpreter) {
1408     assert_different_registers(Rscratch1, Rscratch2);
1409     Label profile_continue;
1410 
1411     // If no method data exists, go to profile_continue.
1412     test_method_data_pointer(profile_continue);
1413 
1414     set_mdp_flag_at(BitData::null_seen_byte_constant(), Rscratch1);
1415 
1416     // The method data pointer needs to be updated.
1417     int mdp_delta = in_bytes(BitData::bit_data_size());
1418     if (TypeProfileCasts) {
1419       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
1420     }
1421     update_mdp_by_constant(mdp_delta);
1422 
1423     bind (profile_continue);
1424   }
1425 }
1426 
1427 void InterpreterMacroAssembler::record_klass_in_profile(Register Rreceiver,
1428                                                         Register Rscratch1, Register Rscratch2,
1429                                                         bool is_virtual_call) {
1430   assert(ProfileInterpreter, "must be profiling");
1431   assert_different_registers(Rreceiver, Rscratch1, Rscratch2);
1432 
1433   Label done;
1434   record_klass_in_profile_helper(Rreceiver, Rscratch1, Rscratch2, 0, done, is_virtual_call);
1435   bind (done);
1436 }
1437 
1438 void InterpreterMacroAssembler::record_klass_in_profile_helper(
1439                                         Register receiver, Register scratch1, Register scratch2,
1440                                         int start_row, Label& done, bool is_virtual_call) {
1441   if (TypeProfileWidth == 0) {
1442     if (is_virtual_call) {
1443       increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
1444     }
1445     return;
1446   }
1447 
1448   int last_row = VirtualCallData::row_limit() - 1;
1449   assert(start_row <= last_row, "must be work left to do");
1450   // Test this row for both the receiver and for null.
1451   // Take any of three different outcomes:
1452   //   1. found receiver => increment count and goto done
1453   //   2. found null => keep looking for case 1, maybe allocate this cell
1454   //   3. found something else => keep looking for cases 1 and 2
1455   // Case 3 is handled by a recursive call.
1456   for (int row = start_row; row <= last_row; row++) {
1457     Label next_test;
1458     bool test_for_null_also = (row == start_row);
1459 
1460     // See if the receiver is receiver[n].
1461     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
1462     test_mdp_data_at(recvr_offset, receiver, next_test, scratch1);
1463     // delayed()->tst(scratch);
1464 
1465     // The receiver is receiver[n]. Increment count[n].
1466     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
1467     increment_mdp_data_at(count_offset, scratch1, scratch2);
1468     b(done);
1469     bind(next_test);
1470 
1471     if (test_for_null_also) {
1472       Label found_null;
1473       // Failed the equality check on receiver[n]... Test for null.
1474       if (start_row == last_row) {
1475         // The only thing left to do is handle the null case.
1476         if (is_virtual_call) {
1477           // Scratch1 contains test_out from test_mdp_data_at.
1478           cmpdi(CCR0, scratch1, 0);
1479           beq(CCR0, found_null);
1480           // Receiver did not match any saved receiver and there is no empty row for it.
1481           // Increment total counter to indicate polymorphic case.
1482           increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
1483           b(done);
1484           bind(found_null);
1485         } else {
1486           cmpdi(CCR0, scratch1, 0);
1487           bne(CCR0, done);
1488         }
1489         break;
1490       }
1491       // Since null is rare, make it be the branch-taken case.
1492       cmpdi(CCR0, scratch1, 0);
1493       beq(CCR0, found_null);
1494 
1495       // Put all the "Case 3" tests here.
1496       record_klass_in_profile_helper(receiver, scratch1, scratch2, start_row + 1, done, is_virtual_call);
1497 
1498       // Found a null. Keep searching for a matching receiver,
1499       // but remember that this is an empty (unused) slot.
1500       bind(found_null);
1501     }
1502   }
1503 
1504   // In the fall-through case, we found no matching receiver, but we
1505   // observed the receiver[start_row] is NULL.
1506 
1507   // Fill in the receiver field and increment the count.
1508   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
1509   set_mdp_data_at(recvr_offset, receiver);
1510   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
1511   li(scratch1, DataLayout::counter_increment);
1512   set_mdp_data_at(count_offset, scratch1);
1513   if (start_row > 0) {
1514     b(done);
1515   }
1516 }
1517 
1518 // Argument and return type profilig.
1519 // kills: tmp, tmp2, R0, CR0, CR1
1520 void InterpreterMacroAssembler::profile_obj_type(Register obj, Register mdo_addr_base,
1521                                                  RegisterOrConstant mdo_addr_offs,
1522                                                  Register tmp, Register tmp2) {
1523   Label do_nothing, do_update;
1524 
1525   // tmp2 = obj is allowed
1526   assert_different_registers(obj, mdo_addr_base, tmp, R0);
1527   assert_different_registers(tmp2, mdo_addr_base, tmp, R0);
1528   const Register klass = tmp2;
1529 
1530   verify_oop(obj);
1531 
1532   ld(tmp, mdo_addr_offs, mdo_addr_base);
1533 
1534   // Set null_seen if obj is 0.
1535   cmpdi(CCR0, obj, 0);
1536   ori(R0, tmp, TypeEntries::null_seen);
1537   beq(CCR0, do_update);
1538 
1539   load_klass(klass, obj);
1540 
1541   clrrdi(R0, tmp, exact_log2(-TypeEntries::type_klass_mask));
1542   // Basically same as andi(R0, tmp, TypeEntries::type_klass_mask);
1543   cmpd(CCR1, R0, klass);
1544   // Klass seen before, nothing to do (regardless of unknown bit).
1545   //beq(CCR1, do_nothing);
1546 
1547   andi_(R0, klass, TypeEntries::type_unknown);
1548   // Already unknown. Nothing to do anymore.
1549   //bne(CCR0, do_nothing);
1550   crorc(CCR0, Assembler::equal, CCR1, Assembler::equal); // cr0 eq = cr1 eq or cr0 ne
1551   beq(CCR0, do_nothing);
1552 
1553   clrrdi_(R0, tmp, exact_log2(-TypeEntries::type_mask));
1554   orr(R0, klass, tmp); // Combine klass and null_seen bit (only used if (tmp & type_mask)==0).
1555   beq(CCR0, do_update); // First time here. Set profile type.
1556 
1557   // Different than before. Cannot keep accurate profile.
1558   ori(R0, tmp, TypeEntries::type_unknown);
1559 
1560   bind(do_update);
1561   // update profile
1562   std(R0, mdo_addr_offs, mdo_addr_base);
1563 
1564   align(32, 12);
1565   bind(do_nothing);
1566 }
1567 
1568 void InterpreterMacroAssembler::profile_arguments_type(Register callee,
1569                                                        Register tmp1, Register tmp2,
1570                                                        bool is_virtual) {
1571   if (!ProfileInterpreter) {
1572     return;
1573   }
1574 
1575   assert_different_registers(callee, tmp1, tmp2, R28_mdx);
1576 
1577   if (MethodData::profile_arguments() || MethodData::profile_return()) {
1578     Label profile_continue;
1579 
1580     test_method_data_pointer(profile_continue);
1581 
1582     int off_to_start = is_virtual ?
1583       in_bytes(VirtualCallData::virtual_call_data_size()) : in_bytes(CounterData::counter_data_size());
1584 
1585     lbz(tmp1, in_bytes(DataLayout::tag_offset()) - off_to_start, R28_mdx);
1586     cmpwi(CCR0, tmp1, is_virtual ? DataLayout::virtual_call_type_data_tag : DataLayout::call_type_data_tag);
1587     bne(CCR0, profile_continue);
1588 
1589     if (MethodData::profile_arguments()) {
1590       Label done;
1591       int off_to_args = in_bytes(TypeEntriesAtCall::args_data_offset());
1592       add(R28_mdx, off_to_args, R28_mdx);
1593 
1594       for (int i = 0; i < TypeProfileArgsLimit; i++) {
1595         if (i > 0 || MethodData::profile_return()) {
1596           // If return value type is profiled we may have no argument to profile.
1597           ld(tmp1, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, R28_mdx);
1598           cmpdi(CCR0, tmp1, (i+1)*TypeStackSlotEntries::per_arg_count());
1599           addi(tmp1, tmp1, -i*TypeStackSlotEntries::per_arg_count());
1600           blt(CCR0, done);
1601         }
1602         ld(tmp1, in_bytes(Method::const_offset()), callee);
1603         lhz(tmp1, in_bytes(ConstMethod::size_of_parameters_offset()), tmp1);
1604         // Stack offset o (zero based) from the start of the argument
1605         // list, for n arguments translates into offset n - o - 1 from
1606         // the end of the argument list. But there's an extra slot at
1607         // the top of the stack. So the offset is n - o from Lesp.
1608         ld(tmp2, in_bytes(TypeEntriesAtCall::stack_slot_offset(i))-off_to_args, R28_mdx);
1609         subf(tmp1, tmp2, tmp1);
1610 
1611         sldi(tmp1, tmp1, Interpreter::logStackElementSize);
1612         ldx(tmp1, tmp1, R15_esp);
1613 
1614         profile_obj_type(tmp1, R28_mdx, in_bytes(TypeEntriesAtCall::argument_type_offset(i))-off_to_args, tmp2, tmp1);
1615 
1616         int to_add = in_bytes(TypeStackSlotEntries::per_arg_size());
1617         addi(R28_mdx, R28_mdx, to_add);
1618         off_to_args += to_add;
1619       }
1620 
1621       if (MethodData::profile_return()) {
1622         ld(tmp1, in_bytes(TypeEntriesAtCall::cell_count_offset())-off_to_args, R28_mdx);
1623         addi(tmp1, tmp1, -TypeProfileArgsLimit*TypeStackSlotEntries::per_arg_count());
1624       }
1625 
1626       bind(done);
1627 
1628       if (MethodData::profile_return()) {
1629         // We're right after the type profile for the last
1630         // argument. tmp1 is the number of cells left in the
1631         // CallTypeData/VirtualCallTypeData to reach its end. Non null
1632         // if there's a return to profile.
1633         assert(ReturnTypeEntry::static_cell_count() < TypeStackSlotEntries::per_arg_count(),
1634                "can't move past ret type");
1635         sldi(tmp1, tmp1, exact_log2(DataLayout::cell_size));
1636         add(R28_mdx, tmp1, R28_mdx);
1637       }
1638     } else {
1639       assert(MethodData::profile_return(), "either profile call args or call ret");
1640       update_mdp_by_constant(in_bytes(TypeEntriesAtCall::return_only_size()));
1641     }
1642 
1643     // Mdp points right after the end of the
1644     // CallTypeData/VirtualCallTypeData, right after the cells for the
1645     // return value type if there's one.
1646     align(32, 12);
1647     bind(profile_continue);
1648   }
1649 }
1650 
1651 void InterpreterMacroAssembler::profile_return_type(Register ret, Register tmp1, Register tmp2) {
1652   assert_different_registers(ret, tmp1, tmp2);
1653   if (ProfileInterpreter && MethodData::profile_return()) {
1654     Label profile_continue;
1655 
1656     test_method_data_pointer(profile_continue);
1657 
1658     if (MethodData::profile_return_jsr292_only()) {
1659       // If we don't profile all invoke bytecodes we must make sure
1660       // it's a bytecode we indeed profile. We can't go back to the
1661       // beginning of the ProfileData we intend to update to check its
1662       // type because we're right after it and we don't known its
1663       // length.
1664       lbz(tmp1, 0, R14_bcp);
1665       lbz(tmp2, Method::intrinsic_id_offset_in_bytes(), R19_method);
1666       cmpwi(CCR0, tmp1, Bytecodes::_invokedynamic);
1667       cmpwi(CCR1, tmp1, Bytecodes::_invokehandle);
1668       cror(CCR0, Assembler::equal, CCR1, Assembler::equal);
1669       cmpwi(CCR1, tmp2, static_cast<int>(vmIntrinsics::_compiledLambdaForm));
1670       cror(CCR0, Assembler::equal, CCR1, Assembler::equal);
1671       bne(CCR0, profile_continue);
1672     }
1673 
1674     profile_obj_type(ret, R28_mdx, -in_bytes(ReturnTypeEntry::size()), tmp1, tmp2);
1675 
1676     align(32, 12);
1677     bind(profile_continue);
1678   }
1679 }
1680 
1681 void InterpreterMacroAssembler::profile_parameters_type(Register tmp1, Register tmp2,
1682                                                         Register tmp3, Register tmp4) {
1683   if (ProfileInterpreter && MethodData::profile_parameters()) {
1684     Label profile_continue, done;
1685 
1686     test_method_data_pointer(profile_continue);
1687 
1688     // Load the offset of the area within the MDO used for
1689     // parameters. If it's negative we're not profiling any parameters.
1690     lwz(tmp1, in_bytes(MethodData::parameters_type_data_di_offset()) - in_bytes(MethodData::data_offset()), R28_mdx);
1691     cmpwi(CCR0, tmp1, 0);
1692     blt(CCR0, profile_continue);
1693 
1694     // Compute a pointer to the area for parameters from the offset
1695     // and move the pointer to the slot for the last
1696     // parameters. Collect profiling from last parameter down.
1697     // mdo start + parameters offset + array length - 1
1698 
1699     // Pointer to the parameter area in the MDO.
1700     const Register mdp = tmp1;
1701     add(mdp, tmp1, R28_mdx);
1702 
1703     // Offset of the current profile entry to update.
1704     const Register entry_offset = tmp2;
1705     // entry_offset = array len in number of cells
1706     ld(entry_offset, in_bytes(ArrayData::array_len_offset()), mdp);
1707 
1708     int off_base = in_bytes(ParametersTypeData::stack_slot_offset(0));
1709     assert(off_base % DataLayout::cell_size == 0, "should be a number of cells");
1710 
1711     // entry_offset (number of cells)  = array len - size of 1 entry + offset of the stack slot field
1712     addi(entry_offset, entry_offset, -TypeStackSlotEntries::per_arg_count() + (off_base / DataLayout::cell_size));
1713     // entry_offset in bytes
1714     sldi(entry_offset, entry_offset, exact_log2(DataLayout::cell_size));
1715 
1716     Label loop;
1717     align(32, 12);
1718     bind(loop);
1719 
1720     // Load offset on the stack from the slot for this parameter.
1721     ld(tmp3, entry_offset, mdp);
1722     sldi(tmp3, tmp3, Interpreter::logStackElementSize);
1723     neg(tmp3, tmp3);
1724     // Read the parameter from the local area.
1725     ldx(tmp3, tmp3, R18_locals);
1726 
1727     // Make entry_offset now point to the type field for this parameter.
1728     int type_base = in_bytes(ParametersTypeData::type_offset(0));
1729     assert(type_base > off_base, "unexpected");
1730     addi(entry_offset, entry_offset, type_base - off_base);
1731 
1732     // Profile the parameter.
1733     profile_obj_type(tmp3, mdp, entry_offset, tmp4, tmp3);
1734 
1735     // Go to next parameter.
1736     int delta = TypeStackSlotEntries::per_arg_count() * DataLayout::cell_size + (type_base - off_base);
1737     cmpdi(CCR0, entry_offset, off_base + delta);
1738     addi(entry_offset, entry_offset, -delta);
1739     bge(CCR0, loop);
1740 
1741     align(32, 12);
1742     bind(profile_continue);
1743   }
1744 }
1745 
1746 // Add a InterpMonitorElem to stack (see frame_sparc.hpp).
1747 void InterpreterMacroAssembler::add_monitor_to_stack(bool stack_is_empty, Register Rtemp1, Register Rtemp2) {
1748 
1749   // Very-local scratch registers.
1750   const Register esp  = Rtemp1;
1751   const Register slot = Rtemp2;
1752 
1753   // Extracted monitor_size.
1754   int monitor_size = frame::interpreter_frame_monitor_size_in_bytes();
1755   assert(Assembler::is_aligned((unsigned int)monitor_size,
1756                                (unsigned int)frame::alignment_in_bytes),
1757          "size of a monitor must respect alignment of SP");
1758 
1759   resize_frame(-monitor_size, /*temp*/esp); // Allocate space for new monitor
1760   std(R1_SP, _ijava_state_neg(top_frame_sp), esp); // esp contains fp
1761 
1762   // Shuffle expression stack down. Recall that stack_base points
1763   // just above the new expression stack bottom. Old_tos and new_tos
1764   // are used to scan thru the old and new expression stacks.
1765   if (!stack_is_empty) {
1766     Label copy_slot, copy_slot_finished;
1767     const Register n_slots = slot;
1768 
1769     addi(esp, R15_esp, Interpreter::stackElementSize); // Point to first element (pre-pushed stack).
1770     subf(n_slots, esp, R26_monitor);
1771     srdi_(n_slots, n_slots, LogBytesPerWord);          // Compute number of slots to copy.
1772     assert(LogBytesPerWord == 3, "conflicts assembler instructions");
1773     beq(CCR0, copy_slot_finished);                     // Nothing to copy.
1774 
1775     mtctr(n_slots);
1776 
1777     // loop
1778     bind(copy_slot);
1779     ld(slot, 0, esp);              // Move expression stack down.
1780     std(slot, -monitor_size, esp); // distance = monitor_size
1781     addi(esp, esp, BytesPerWord);
1782     bdnz(copy_slot);
1783 
1784     bind(copy_slot_finished);
1785   }
1786 
1787   addi(R15_esp, R15_esp, -monitor_size);
1788   addi(R26_monitor, R26_monitor, -monitor_size);
1789 
1790   // Restart interpreter
1791 }
1792 
1793 // ============================================================================
1794 // Java locals access
1795 
1796 // Load a local variable at index in Rindex into register Rdst_value.
1797 // Also puts address of local into Rdst_address as a service.
1798 // Kills:
1799 //   - Rdst_value
1800 //   - Rdst_address
1801 void InterpreterMacroAssembler::load_local_int(Register Rdst_value, Register Rdst_address, Register Rindex) {
1802   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
1803   subf(Rdst_address, Rdst_address, R18_locals);
1804   lwz(Rdst_value, 0, Rdst_address);
1805 }
1806 
1807 // Load a local variable at index in Rindex into register Rdst_value.
1808 // Also puts address of local into Rdst_address as a service.
1809 // Kills:
1810 //   - Rdst_value
1811 //   - Rdst_address
1812 void InterpreterMacroAssembler::load_local_long(Register Rdst_value, Register Rdst_address, Register Rindex) {
1813   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
1814   subf(Rdst_address, Rdst_address, R18_locals);
1815   ld(Rdst_value, -8, Rdst_address);
1816 }
1817 
1818 // Load a local variable at index in Rindex into register Rdst_value.
1819 // Also puts address of local into Rdst_address as a service.
1820 // Input:
1821 //   - Rindex:      slot nr of local variable
1822 // Kills:
1823 //   - Rdst_value
1824 //   - Rdst_address
1825 void InterpreterMacroAssembler::load_local_ptr(Register Rdst_value,
1826                                                Register Rdst_address,
1827                                                Register Rindex) {
1828   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
1829   subf(Rdst_address, Rdst_address, R18_locals);
1830   ld(Rdst_value, 0, Rdst_address);
1831 }
1832 
1833 // Load a local variable at index in Rindex into register Rdst_value.
1834 // Also puts address of local into Rdst_address as a service.
1835 // Kills:
1836 //   - Rdst_value
1837 //   - Rdst_address
1838 void InterpreterMacroAssembler::load_local_float(FloatRegister Rdst_value,
1839                                                  Register Rdst_address,
1840                                                  Register Rindex) {
1841   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
1842   subf(Rdst_address, Rdst_address, R18_locals);
1843   lfs(Rdst_value, 0, Rdst_address);
1844 }
1845 
1846 // Load a local variable at index in Rindex into register Rdst_value.
1847 // Also puts address of local into Rdst_address as a service.
1848 // Kills:
1849 //   - Rdst_value
1850 //   - Rdst_address
1851 void InterpreterMacroAssembler::load_local_double(FloatRegister Rdst_value,
1852                                                   Register Rdst_address,
1853                                                   Register Rindex) {
1854   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
1855   subf(Rdst_address, Rdst_address, R18_locals);
1856   lfd(Rdst_value, -8, Rdst_address);
1857 }
1858 
1859 // Store an int value at local variable slot Rindex.
1860 // Kills:
1861 //   - Rindex
1862 void InterpreterMacroAssembler::store_local_int(Register Rvalue, Register Rindex) {
1863   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
1864   subf(Rindex, Rindex, R18_locals);
1865   stw(Rvalue, 0, Rindex);
1866 }
1867 
1868 // Store a long value at local variable slot Rindex.
1869 // Kills:
1870 //   - Rindex
1871 void InterpreterMacroAssembler::store_local_long(Register Rvalue, Register Rindex) {
1872   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
1873   subf(Rindex, Rindex, R18_locals);
1874   std(Rvalue, -8, Rindex);
1875 }
1876 
1877 // Store an oop value at local variable slot Rindex.
1878 // Kills:
1879 //   - Rindex
1880 void InterpreterMacroAssembler::store_local_ptr(Register Rvalue, Register Rindex) {
1881   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
1882   subf(Rindex, Rindex, R18_locals);
1883   std(Rvalue, 0, Rindex);
1884 }
1885 
1886 // Store an int value at local variable slot Rindex.
1887 // Kills:
1888 //   - Rindex
1889 void InterpreterMacroAssembler::store_local_float(FloatRegister Rvalue, Register Rindex) {
1890   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
1891   subf(Rindex, Rindex, R18_locals);
1892   stfs(Rvalue, 0, Rindex);
1893 }
1894 
1895 // Store an int value at local variable slot Rindex.
1896 // Kills:
1897 //   - Rindex
1898 void InterpreterMacroAssembler::store_local_double(FloatRegister Rvalue, Register Rindex) {
1899   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
1900   subf(Rindex, Rindex, R18_locals);
1901   stfd(Rvalue, -8, Rindex);
1902 }
1903 
1904 // Read pending exception from thread and jump to interpreter.
1905 // Throw exception entry if one if pending. Fall through otherwise.
1906 void InterpreterMacroAssembler::check_and_forward_exception(Register Rscratch1, Register Rscratch2) {
1907   assert_different_registers(Rscratch1, Rscratch2, R3);
1908   Register Rexception = Rscratch1;
1909   Register Rtmp       = Rscratch2;
1910   Label Ldone;
1911   // Get pending exception oop.
1912   ld(Rexception, thread_(pending_exception));
1913   cmpdi(CCR0, Rexception, 0);
1914   beq(CCR0, Ldone);
1915   li(Rtmp, 0);
1916   mr_if_needed(R3, Rexception);
1917   std(Rtmp, thread_(pending_exception)); // Clear exception in thread
1918   if (Interpreter::rethrow_exception_entry() != NULL) {
1919     // Already got entry address.
1920     load_dispatch_table(Rtmp, (address*)Interpreter::rethrow_exception_entry());
1921   } else {
1922     // Dynamically load entry address.
1923     int simm16_rest = load_const_optimized(Rtmp, &Interpreter::_rethrow_exception_entry, R0, true);
1924     ld(Rtmp, simm16_rest, Rtmp);
1925   }
1926   mtctr(Rtmp);
1927   save_interpreter_state(Rtmp);
1928   bctr();
1929 
1930   align(32, 12);
1931   bind(Ldone);
1932 }
1933 
1934 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, bool check_exceptions) {
1935   save_interpreter_state(R11_scratch1);
1936 
1937   MacroAssembler::call_VM(oop_result, entry_point, false);
1938 
1939   restore_interpreter_state(R11_scratch1, /*bcp_and_mdx_only*/ true);
1940 
1941   check_and_handle_popframe(R11_scratch1);
1942   check_and_handle_earlyret(R11_scratch1);
1943   // Now check exceptions manually.
1944   if (check_exceptions) {
1945     check_and_forward_exception(R11_scratch1, R12_scratch2);
1946   }
1947 }
1948 
1949 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,
1950                                         Register arg_1, bool check_exceptions) {
1951   // ARG1 is reserved for the thread.
1952   mr_if_needed(R4_ARG2, arg_1);
1953   call_VM(oop_result, entry_point, check_exceptions);
1954 }
1955 
1956 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,
1957                                         Register arg_1, Register arg_2,
1958                                         bool check_exceptions) {
1959   // ARG1 is reserved for the thread.
1960   mr_if_needed(R4_ARG2, arg_1);
1961   assert(arg_2 != R4_ARG2, "smashed argument");
1962   mr_if_needed(R5_ARG3, arg_2);
1963   call_VM(oop_result, entry_point, check_exceptions);
1964 }
1965 
1966 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point,
1967                                         Register arg_1, Register arg_2, Register arg_3,
1968                                         bool check_exceptions) {
1969   // ARG1 is reserved for the thread.
1970   mr_if_needed(R4_ARG2, arg_1);
1971   assert(arg_2 != R4_ARG2, "smashed argument");
1972   mr_if_needed(R5_ARG3, arg_2);
1973   assert(arg_3 != R4_ARG2 && arg_3 != R5_ARG3, "smashed argument");
1974   mr_if_needed(R6_ARG4, arg_3);
1975   call_VM(oop_result, entry_point, check_exceptions);
1976 }
1977 
1978 void InterpreterMacroAssembler::save_interpreter_state(Register scratch) {
1979   ld(scratch, 0, R1_SP);
1980   std(R15_esp, _ijava_state_neg(esp), scratch);
1981   std(R14_bcp, _ijava_state_neg(bcp), scratch);
1982   std(R26_monitor, _ijava_state_neg(monitors), scratch);
1983   if (ProfileInterpreter) { std(R28_mdx, _ijava_state_neg(mdx), scratch); }
1984   // Other entries should be unchanged.
1985 }
1986 
1987 void InterpreterMacroAssembler::restore_interpreter_state(Register scratch, bool bcp_and_mdx_only) {
1988   ld(scratch, 0, R1_SP);
1989   ld(R14_bcp, _ijava_state_neg(bcp), scratch); // Changed by VM code (exception).
1990   if (ProfileInterpreter) { ld(R28_mdx, _ijava_state_neg(mdx), scratch); } // Changed by VM code.
1991   if (!bcp_and_mdx_only) {
1992     // Following ones are Metadata.
1993     ld(R19_method, _ijava_state_neg(method), scratch);
1994     ld(R27_constPoolCache, _ijava_state_neg(cpoolCache), scratch);
1995     // Following ones are stack addresses and don't require reload.
1996     ld(R15_esp, _ijava_state_neg(esp), scratch);
1997     ld(R18_locals, _ijava_state_neg(locals), scratch);
1998     ld(R26_monitor, _ijava_state_neg(monitors), scratch);
1999   }
2000 #ifdef ASSERT
2001   {
2002     Label Lok;
2003     subf(R0, R1_SP, scratch);
2004     cmpdi(CCR0, R0, frame::abi_reg_args_size + frame::ijava_state_size);
2005     bge(CCR0, Lok);
2006     stop("frame too small (restore istate)");
2007     bind(Lok);
2008   }
2009 #endif
2010 }
2011 
2012 void InterpreterMacroAssembler::get_method_counters(Register method,
2013                                                     Register Rcounters,
2014                                                     Label& skip) {
2015   BLOCK_COMMENT("Load and ev. allocate counter object {");
2016   Label has_counters;
2017   ld(Rcounters, in_bytes(Method::method_counters_offset()), method);
2018   cmpdi(CCR0, Rcounters, 0);
2019   bne(CCR0, has_counters);
2020   call_VM(noreg, CAST_FROM_FN_PTR(address,
2021                                   InterpreterRuntime::build_method_counters), method);
2022   ld(Rcounters, in_bytes(Method::method_counters_offset()), method);
2023   cmpdi(CCR0, Rcounters, 0);
2024   beq(CCR0, skip); // No MethodCounters, OutOfMemory.
2025   BLOCK_COMMENT("} Load and ev. allocate counter object");
2026 
2027   bind(has_counters);
2028 }
2029 
2030 void InterpreterMacroAssembler::increment_invocation_counter(Register Rcounters,
2031                                                              Register iv_be_count,
2032                                                              Register Rtmp_r0) {
2033   assert(UseCompiler, "incrementing must be useful");
2034   Register invocation_count = iv_be_count;
2035   Register backedge_count   = Rtmp_r0;
2036   int delta = InvocationCounter::count_increment;
2037 
2038   // Load each counter in a register.
2039   //  ld(inv_counter, Rtmp);
2040   //  ld(be_counter, Rtmp2);
2041   int inv_counter_offset = in_bytes(MethodCounters::invocation_counter_offset() +
2042                                     InvocationCounter::counter_offset());
2043   int be_counter_offset  = in_bytes(MethodCounters::backedge_counter_offset() +
2044                                     InvocationCounter::counter_offset());
2045 
2046   BLOCK_COMMENT("Increment profiling counters {");
2047 
2048   // Load the backedge counter.
2049   lwz(backedge_count, be_counter_offset, Rcounters); // is unsigned int
2050   // Mask the backedge counter.
2051   andi(backedge_count, backedge_count, InvocationCounter::count_mask_value);
2052 
2053   // Load the invocation counter.
2054   lwz(invocation_count, inv_counter_offset, Rcounters); // is unsigned int
2055   // Add the delta to the invocation counter and store the result.
2056   addi(invocation_count, invocation_count, delta);
2057   // Store value.
2058   stw(invocation_count, inv_counter_offset, Rcounters);
2059 
2060   // Add invocation counter + backedge counter.
2061   add(iv_be_count, backedge_count, invocation_count);
2062 
2063   // Note that this macro must leave the backedge_count + invocation_count in
2064   // register iv_be_count!
2065   BLOCK_COMMENT("} Increment profiling counters");
2066 }
2067 
2068 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
2069   if (state == atos) { MacroAssembler::verify_oop(reg, FILE_AND_LINE); }
2070 }
2071 
2072 // Local helper function for the verify_oop_or_return_address macro.
2073 static bool verify_return_address(Method* m, int bci) {
2074 #ifndef PRODUCT
2075   address pc = (address)(m->constMethod()) + in_bytes(ConstMethod::codes_offset()) + bci;
2076   // Assume it is a valid return address if it is inside m and is preceded by a jsr.
2077   if (!m->contains(pc))                                            return false;
2078   address jsr_pc;
2079   jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr);
2080   if (*jsr_pc == Bytecodes::_jsr   && jsr_pc >= m->code_base())    return true;
2081   jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr_w);
2082   if (*jsr_pc == Bytecodes::_jsr_w && jsr_pc >= m->code_base())    return true;
2083 #endif // PRODUCT
2084   return false;
2085 }
2086 
2087 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
2088   if (VerifyFPU) {
2089     unimplemented("verfiyFPU");
2090   }
2091 }
2092 
2093 void InterpreterMacroAssembler::verify_oop_or_return_address(Register reg, Register Rtmp) {
2094   if (!VerifyOops) return;
2095 
2096   // The VM documentation for the astore[_wide] bytecode allows
2097   // the TOS to be not only an oop but also a return address.
2098   Label test;
2099   Label skip;
2100   // See if it is an address (in the current method):
2101 
2102   const int log2_bytecode_size_limit = 16;
2103   srdi_(Rtmp, reg, log2_bytecode_size_limit);
2104   bne(CCR0, test);
2105 
2106   address fd = CAST_FROM_FN_PTR(address, verify_return_address);
2107   const int nbytes_save = MacroAssembler::num_volatile_regs * 8;
2108   save_volatile_gprs(R1_SP, -nbytes_save); // except R0
2109   save_LR_CR(Rtmp); // Save in old frame.
2110   push_frame_reg_args(nbytes_save, Rtmp);
2111 
2112   load_const_optimized(Rtmp, fd, R0);
2113   mr_if_needed(R4_ARG2, reg);
2114   mr(R3_ARG1, R19_method);
2115   call_c(Rtmp); // call C
2116 
2117   pop_frame();
2118   restore_LR_CR(Rtmp);
2119   restore_volatile_gprs(R1_SP, -nbytes_save); // except R0
2120   b(skip);
2121 
2122   // Perform a more elaborate out-of-line call.
2123   // Not an address; verify it:
2124   bind(test);
2125   verify_oop(reg);
2126   bind(skip);
2127 }
2128 
2129 // Inline assembly for:
2130 //
2131 // if (thread is in interp_only_mode) {
2132 //   InterpreterRuntime::post_method_entry();
2133 // }
2134 // if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY ) ||
2135 //     *jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_ENTRY2)   ) {
2136 //   SharedRuntime::jvmpi_method_entry(method, receiver);
2137 // }
2138 void InterpreterMacroAssembler::notify_method_entry() {
2139   // JVMTI
2140   // Whenever JVMTI puts a thread in interp_only_mode, method
2141   // entry/exit events are sent for that thread to track stack
2142   // depth. If it is possible to enter interp_only_mode we add
2143   // the code to check if the event should be sent.
2144   if (JvmtiExport::can_post_interpreter_events()) {
2145     Label jvmti_post_done;
2146 
2147     lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
2148     cmpwi(CCR0, R0, 0);
2149     beq(CCR0, jvmti_post_done);
2150     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry));
2151 
2152     bind(jvmti_post_done);
2153   }
2154 }
2155 
2156 // Inline assembly for:
2157 //
2158 // if (thread is in interp_only_mode) {
2159 //   // save result
2160 //   InterpreterRuntime::post_method_exit();
2161 //   // restore result
2162 // }
2163 // if (*jvmpi::event_flags_array_at_addr(JVMPI_EVENT_METHOD_EXIT)) {
2164 //   // save result
2165 //   SharedRuntime::jvmpi_method_exit();
2166 //   // restore result
2167 // }
2168 //
2169 // Native methods have their result stored in d_tmp and l_tmp.
2170 // Java methods have their result stored in the expression stack.
2171 void InterpreterMacroAssembler::notify_method_exit(bool is_native_method, TosState state,
2172                                                    NotifyMethodExitMode mode, bool check_exceptions) {
2173   // JVMTI
2174   // Whenever JVMTI puts a thread in interp_only_mode, method
2175   // entry/exit events are sent for that thread to track stack
2176   // depth. If it is possible to enter interp_only_mode we add
2177   // the code to check if the event should be sent.
2178   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
2179     Label jvmti_post_done;
2180 
2181     lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
2182     cmpwi(CCR0, R0, 0);
2183     beq(CCR0, jvmti_post_done);
2184     if (!is_native_method) { push(state); } // Expose tos to GC.
2185     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit), check_exceptions);
2186     if (!is_native_method) { pop(state); }
2187 
2188     align(32, 12);
2189     bind(jvmti_post_done);
2190   }
2191 
2192   // Dtrace support not implemented.
2193 }