hotspot/src/cpu/ppc/vm/interp_masm_ppc_64.cpp
changeset 23221 b70675ece1ce
parent 22861 f5c393d456fc
child 24322 c2978d1578e3
equal deleted inserted replaced
23220:fc827339dc37 23221:b70675ece1ce
     1 /*
     1 /*
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * Copyright 2012, 2013 SAP AG. All rights reserved.
     3  * Copyright 2012, 2014 SAP AG. All rights reserved.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5  *
     5  *
     6  * This code is free software; you can redistribute it and/or modify it
     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
     7  * under the terms of the GNU General Public License version 2 only, as
     8  * published by the Free Software Foundation.
     8  * published by the Free Software Foundation.
    27 #include "precompiled.hpp"
    27 #include "precompiled.hpp"
    28 #include "asm/assembler.hpp"
    28 #include "asm/assembler.hpp"
    29 #include "asm/macroAssembler.inline.hpp"
    29 #include "asm/macroAssembler.inline.hpp"
    30 #include "interp_masm_ppc_64.hpp"
    30 #include "interp_masm_ppc_64.hpp"
    31 #include "interpreter/interpreterRuntime.hpp"
    31 #include "interpreter/interpreterRuntime.hpp"
       
    32 #include "prims/jvmtiThreadState.hpp"
    32 
    33 
    33 #ifdef PRODUCT
    34 #ifdef PRODUCT
    34 #define BLOCK_COMMENT(str) // nothing
    35 #define BLOCK_COMMENT(str) // nothing
    35 #else
    36 #else
    36 #define BLOCK_COMMENT(str) block_comment(str)
    37 #define BLOCK_COMMENT(str) block_comment(str)
    42 #else
    43 #else
    43   address exception_entry = Interpreter::throw_NullPointerException_entry();
    44   address exception_entry = Interpreter::throw_NullPointerException_entry();
    44 #endif
    45 #endif
    45   MacroAssembler::null_check_throw(a, offset, temp_reg, exception_entry);
    46   MacroAssembler::null_check_throw(a, offset, temp_reg, exception_entry);
    46 }
    47 }
       
    48 
       
    49 void InterpreterMacroAssembler::branch_to_entry(address entry, Register Rscratch) {
       
    50   assert(entry, "Entry must have been generated by now");
       
    51   if (is_within_range_of_b(entry, pc())) {
       
    52     b(entry);
       
    53   } else {
       
    54     load_const_optimized(Rscratch, entry, R0);
       
    55     mtctr(Rscratch);
       
    56     bctr();
       
    57   }
       
    58 }
       
    59 
       
    60 #ifndef CC_INTERP
       
    61 
       
    62 void InterpreterMacroAssembler::dispatch_next(TosState state, int bcp_incr) {
       
    63   Register bytecode = R12_scratch2;
       
    64   if (bcp_incr != 0) {
       
    65     lbzu(bytecode, bcp_incr, R14_bcp);
       
    66   } else {
       
    67     lbz(bytecode, 0, R14_bcp);
       
    68   }
       
    69 
       
    70   dispatch_Lbyte_code(state, bytecode, Interpreter::dispatch_table(state));
       
    71 }
       
    72 
       
    73 void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) {
       
    74   // Load current bytecode.
       
    75   Register bytecode = R12_scratch2;
       
    76   lbz(bytecode, 0, R14_bcp);
       
    77   dispatch_Lbyte_code(state, bytecode, table);
       
    78 }
       
    79 
       
    80 // Dispatch code executed in the prolog of a bytecode which does not do it's
       
    81 // own dispatch. The dispatch address is computed and placed in R24_dispatch_addr.
       
    82 void InterpreterMacroAssembler::dispatch_prolog(TosState state, int bcp_incr) {
       
    83   Register bytecode = R12_scratch2;
       
    84   lbz(bytecode, bcp_incr, R14_bcp);
       
    85 
       
    86   load_dispatch_table(R24_dispatch_addr, Interpreter::dispatch_table(state));
       
    87 
       
    88   sldi(bytecode, bytecode, LogBytesPerWord);
       
    89   ldx(R24_dispatch_addr, R24_dispatch_addr, bytecode);
       
    90 }
       
    91 
       
    92 // Dispatch code executed in the epilog of a bytecode which does not do it's
       
    93 // own dispatch. The dispatch address in R24_dispatch_addr is used for the
       
    94 // dispatch.
       
    95 void InterpreterMacroAssembler::dispatch_epilog(TosState state, int bcp_incr) {
       
    96   mtctr(R24_dispatch_addr);
       
    97   addi(R14_bcp, R14_bcp, bcp_incr);
       
    98   bctr();
       
    99 }
       
   100 
       
   101 void InterpreterMacroAssembler::check_and_handle_popframe(Register scratch_reg) {
       
   102   assert(scratch_reg != R0, "can't use R0 as scratch_reg here");
       
   103   if (JvmtiExport::can_pop_frame()) {
       
   104     Label L;
       
   105 
       
   106     // Check the "pending popframe condition" flag in the current thread.
       
   107     lwz(scratch_reg, in_bytes(JavaThread::popframe_condition_offset()), R16_thread);
       
   108 
       
   109     // Initiate popframe handling only if it is not already being
       
   110     // processed. If the flag has the popframe_processing bit set, it
       
   111     // means that this code is called *during* popframe handling - we
       
   112     // don't want to reenter.
       
   113     andi_(R0, scratch_reg, JavaThread::popframe_pending_bit);
       
   114     beq(CCR0, L);
       
   115 
       
   116     andi_(R0, scratch_reg, JavaThread::popframe_processing_bit);
       
   117     bne(CCR0, L);
       
   118 
       
   119     // Call the Interpreter::remove_activation_preserving_args_entry()
       
   120     // func to get the address of the same-named entrypoint in the
       
   121     // generated interpreter code.
       
   122     call_c(CAST_FROM_FN_PTR(FunctionDescriptor*,
       
   123                             Interpreter::remove_activation_preserving_args_entry),
       
   124            relocInfo::none);
       
   125 
       
   126     // Jump to Interpreter::_remove_activation_preserving_args_entry.
       
   127     mtctr(R3_RET);
       
   128     bctr();
       
   129 
       
   130     align(32, 12);
       
   131     bind(L);
       
   132   }
       
   133 }
       
   134 
       
   135 void InterpreterMacroAssembler::check_and_handle_earlyret(Register scratch_reg) {
       
   136   const Register Rthr_state_addr = scratch_reg;
       
   137   if (JvmtiExport::can_force_early_return()) {
       
   138     Label Lno_early_ret;
       
   139     ld(Rthr_state_addr, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
       
   140     cmpdi(CCR0, Rthr_state_addr, 0);
       
   141     beq(CCR0, Lno_early_ret);
       
   142 
       
   143     lwz(R0, in_bytes(JvmtiThreadState::earlyret_state_offset()), Rthr_state_addr);
       
   144     cmpwi(CCR0, R0, JvmtiThreadState::earlyret_pending);
       
   145     bne(CCR0, Lno_early_ret);
       
   146 
       
   147     // Jump to Interpreter::_earlyret_entry.
       
   148     lwz(R3_ARG1, in_bytes(JvmtiThreadState::earlyret_tos_offset()), Rthr_state_addr);
       
   149     call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry));
       
   150     mtlr(R3_RET);
       
   151     blr();
       
   152 
       
   153     align(32, 12);
       
   154     bind(Lno_early_ret);
       
   155   }
       
   156 }
       
   157 
       
   158 void InterpreterMacroAssembler::load_earlyret_value(TosState state, Register Rscratch1) {
       
   159   const Register RjvmtiState = Rscratch1;
       
   160   const Register Rscratch2   = R0;
       
   161 
       
   162   ld(RjvmtiState, in_bytes(JavaThread::jvmti_thread_state_offset()), R16_thread);
       
   163   li(Rscratch2, 0);
       
   164 
       
   165   switch (state) {
       
   166     case atos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);
       
   167                std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_oop_offset()), RjvmtiState);
       
   168                break;
       
   169     case ltos: ld(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
       
   170                break;
       
   171     case btos: // fall through
       
   172     case ctos: // fall through
       
   173     case stos: // fall through
       
   174     case itos: lwz(R17_tos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
       
   175                break;
       
   176     case ftos: lfs(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
       
   177                break;
       
   178     case dtos: lfd(F15_ftos, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
       
   179                break;
       
   180     case vtos: break;
       
   181     default  : ShouldNotReachHere();
       
   182   }
       
   183 
       
   184   // Clean up tos value in the jvmti thread state.
       
   185   std(Rscratch2, in_bytes(JvmtiThreadState::earlyret_value_offset()), RjvmtiState);
       
   186   // Set tos state field to illegal value.
       
   187   li(Rscratch2, ilgl);
       
   188   stw(Rscratch2, in_bytes(JvmtiThreadState::earlyret_tos_offset()), RjvmtiState);
       
   189 }
       
   190 
       
   191 // Common code to dispatch and dispatch_only.
       
   192 // Dispatch value in Lbyte_code and increment Lbcp.
       
   193 
       
   194 void InterpreterMacroAssembler::load_dispatch_table(Register dst, address* table) {
       
   195   address table_base = (address)Interpreter::dispatch_table((TosState)0);
       
   196   intptr_t table_offs = (intptr_t)table - (intptr_t)table_base;
       
   197   if (is_simm16(table_offs)) {
       
   198     addi(dst, R25_templateTableBase, (int)table_offs);
       
   199   } else {
       
   200     load_const_optimized(dst, table, R0);
       
   201   }
       
   202 }
       
   203 
       
   204 void InterpreterMacroAssembler::dispatch_Lbyte_code(TosState state, Register bytecode, address* table, bool verify) {
       
   205   if (verify) {
       
   206     unimplemented("dispatch_Lbyte_code: verify"); // See Sparc Implementation to implement this
       
   207   }
       
   208 
       
   209 #ifdef FAST_DISPATCH
       
   210   unimplemented("dispatch_Lbyte_code FAST_DISPATCH");
       
   211 #else
       
   212   assert_different_registers(bytecode, R11_scratch1);
       
   213 
       
   214   // Calc dispatch table address.
       
   215   load_dispatch_table(R11_scratch1, table);
       
   216 
       
   217   sldi(R12_scratch2, bytecode, LogBytesPerWord);
       
   218   ldx(R11_scratch1, R11_scratch1, R12_scratch2);
       
   219 
       
   220   // Jump off!
       
   221   mtctr(R11_scratch1);
       
   222   bctr();
       
   223 #endif
       
   224 }
       
   225 
       
   226 void InterpreterMacroAssembler::load_receiver(Register Rparam_count, Register Rrecv_dst) {
       
   227   sldi(Rrecv_dst, Rparam_count, Interpreter::logStackElementSize);
       
   228   ldx(Rrecv_dst, Rrecv_dst, R15_esp);
       
   229 }
       
   230 
       
   231 // helpers for expression stack
       
   232 
       
   233 void InterpreterMacroAssembler::pop_i(Register r) {
       
   234   lwzu(r, Interpreter::stackElementSize, R15_esp);
       
   235 }
       
   236 
       
   237 void InterpreterMacroAssembler::pop_ptr(Register r) {
       
   238   ldu(r, Interpreter::stackElementSize, R15_esp);
       
   239 }
       
   240 
       
   241 void InterpreterMacroAssembler::pop_l(Register r) {
       
   242   ld(r, Interpreter::stackElementSize, R15_esp);
       
   243   addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);
       
   244 }
       
   245 
       
   246 void InterpreterMacroAssembler::pop_f(FloatRegister f) {
       
   247   lfsu(f, Interpreter::stackElementSize, R15_esp);
       
   248 }
       
   249 
       
   250 void InterpreterMacroAssembler::pop_d(FloatRegister f) {
       
   251   lfd(f, Interpreter::stackElementSize, R15_esp);
       
   252   addi(R15_esp, R15_esp, 2 * Interpreter::stackElementSize);
       
   253 }
       
   254 
       
   255 void InterpreterMacroAssembler::push_i(Register r) {
       
   256   stw(r, 0, R15_esp);
       
   257   addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
       
   258 }
       
   259 
       
   260 void InterpreterMacroAssembler::push_ptr(Register r) {
       
   261   std(r, 0, R15_esp);
       
   262   addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
       
   263 }
       
   264 
       
   265 void InterpreterMacroAssembler::push_l(Register r) {
       
   266   std(r, - Interpreter::stackElementSize, R15_esp);
       
   267   addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
       
   268 }
       
   269 
       
   270 void InterpreterMacroAssembler::push_f(FloatRegister f) {
       
   271   stfs(f, 0, R15_esp);
       
   272   addi(R15_esp, R15_esp, - Interpreter::stackElementSize );
       
   273 }
       
   274 
       
   275 void InterpreterMacroAssembler::push_d(FloatRegister f)   {
       
   276   stfd(f, - Interpreter::stackElementSize, R15_esp);
       
   277   addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
       
   278 }
       
   279 
       
   280 void InterpreterMacroAssembler::push_2ptrs(Register first, Register second) {
       
   281   std(first, 0, R15_esp);
       
   282   std(second, -Interpreter::stackElementSize, R15_esp);
       
   283   addi(R15_esp, R15_esp, - 2 * Interpreter::stackElementSize );
       
   284 }
       
   285 
       
   286 void InterpreterMacroAssembler::push_l_pop_d(Register l, FloatRegister d) {
       
   287   std(l, 0, R15_esp);
       
   288   lfd(d, 0, R15_esp);
       
   289 }
       
   290 
       
   291 void InterpreterMacroAssembler::push_d_pop_l(FloatRegister d, Register l) {
       
   292   stfd(d, 0, R15_esp);
       
   293   ld(l, 0, R15_esp);
       
   294 }
       
   295 
       
   296 void InterpreterMacroAssembler::push(TosState state) {
       
   297   switch (state) {
       
   298     case atos: push_ptr();                break;
       
   299     case btos:
       
   300     case ctos:
       
   301     case stos:
       
   302     case itos: push_i();                  break;
       
   303     case ltos: push_l();                  break;
       
   304     case ftos: push_f();                  break;
       
   305     case dtos: push_d();                  break;
       
   306     case vtos: /* nothing to do */        break;
       
   307     default  : ShouldNotReachHere();
       
   308   }
       
   309 }
       
   310 
       
   311 void InterpreterMacroAssembler::pop(TosState state) {
       
   312   switch (state) {
       
   313     case atos: pop_ptr();            break;
       
   314     case btos:
       
   315     case ctos:
       
   316     case stos:
       
   317     case itos: pop_i();              break;
       
   318     case ltos: pop_l();              break;
       
   319     case ftos: pop_f();              break;
       
   320     case dtos: pop_d();              break;
       
   321     case vtos: /* nothing to do */   break;
       
   322     default  : ShouldNotReachHere();
       
   323   }
       
   324   verify_oop(R17_tos, state);
       
   325 }
       
   326 
       
   327 void InterpreterMacroAssembler::empty_expression_stack() {
       
   328   addi(R15_esp, R26_monitor, - Interpreter::stackElementSize);
       
   329 }
       
   330 
       
   331 void InterpreterMacroAssembler::get_2_byte_integer_at_bcp(int         bcp_offset,
       
   332                                                           Register    Rdst,
       
   333                                                           signedOrNot is_signed) {
       
   334   // Read Java big endian format.
       
   335   if (is_signed == Signed) {
       
   336     lha(Rdst, bcp_offset, R14_bcp);
       
   337   } else {
       
   338     lhz(Rdst, bcp_offset, R14_bcp);
       
   339   }
       
   340 #if 0
       
   341   assert(Rtmp != Rdst, "need separate temp register");
       
   342   Register Rfirst = Rtmp;
       
   343   lbz(Rfirst, bcp_offset, R14_bcp); // first byte
       
   344   lbz(Rdst, bcp_offset+1, R14_bcp); // second byte
       
   345 
       
   346   // Rdst = ((Rfirst<<8) & 0xFF00) | (Rdst &~ 0xFF00)
       
   347   rldimi(/*RA=*/Rdst, /*RS=*/Rfirst, /*sh=*/8, /*mb=*/48);
       
   348   if (is_signed == Signed) {
       
   349     extsh(Rdst, Rdst);
       
   350   }
       
   351 #endif
       
   352 }
       
   353 
       
   354 void InterpreterMacroAssembler::get_4_byte_integer_at_bcp(int         bcp_offset,
       
   355                                                           Register    Rdst,
       
   356                                                           signedOrNot is_signed) {
       
   357   // Read Java big endian format.
       
   358   if (bcp_offset & 3) { // Offset unaligned?
       
   359     load_const_optimized(Rdst, bcp_offset);
       
   360     if (is_signed == Signed) {
       
   361       lwax(Rdst, R14_bcp, Rdst);
       
   362     } else {
       
   363       lwzx(Rdst, R14_bcp, Rdst);
       
   364     }
       
   365   } else {
       
   366     if (is_signed == Signed) {
       
   367       lwa(Rdst, bcp_offset, R14_bcp);
       
   368     } else {
       
   369       lwz(Rdst, bcp_offset, R14_bcp);
       
   370     }
       
   371   }
       
   372 }
       
   373 
       
   374 // Load the constant pool cache index from the bytecode stream.
       
   375 //
       
   376 // Kills / writes:
       
   377 //   - Rdst, Rscratch
       
   378 void InterpreterMacroAssembler::get_cache_index_at_bcp(Register Rdst, int bcp_offset, size_t index_size) {
       
   379   assert(bcp_offset > 0, "bcp is still pointing to start of bytecode");
       
   380   if (index_size == sizeof(u2)) {
       
   381     get_2_byte_integer_at_bcp(bcp_offset, Rdst, Unsigned);
       
   382   } else if (index_size == sizeof(u4)) {
       
   383     assert(EnableInvokeDynamic, "giant index used only for JSR 292");
       
   384     get_4_byte_integer_at_bcp(bcp_offset, Rdst, Signed);
       
   385     assert(ConstantPool::decode_invokedynamic_index(~123) == 123, "else change next line");
       
   386     nand(Rdst, Rdst, Rdst); // convert to plain index
       
   387   } else if (index_size == sizeof(u1)) {
       
   388     lbz(Rdst, bcp_offset, R14_bcp);
       
   389   } else {
       
   390     ShouldNotReachHere();
       
   391   }
       
   392   // Rdst now contains cp cache index.
       
   393 }
       
   394 
       
   395 void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, int bcp_offset, size_t index_size) {
       
   396   get_cache_index_at_bcp(cache, bcp_offset, index_size);
       
   397   sldi(cache, cache, exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord));
       
   398   add(cache, R27_constPoolCache, cache);
       
   399 }
       
   400 
       
   401 // Load object from cpool->resolved_references(index).
       
   402 void InterpreterMacroAssembler::load_resolved_reference_at_index(Register result, Register index) {
       
   403   assert_different_registers(result, index);
       
   404   get_constant_pool(result);
       
   405 
       
   406   // Convert from field index to resolved_references() index and from
       
   407   // word index to byte offset. Since this is a java object, it can be compressed.
       
   408   Register tmp = index;  // reuse
       
   409   sldi(tmp, index, LogBytesPerHeapOop);
       
   410   // Load pointer for resolved_references[] objArray.
       
   411   ld(result, ConstantPool::resolved_references_offset_in_bytes(), result);
       
   412   // JNIHandles::resolve(result)
       
   413   ld(result, 0, result);
       
   414 #ifdef ASSERT
       
   415   Label index_ok;
       
   416   lwa(R0, arrayOopDesc::length_offset_in_bytes(), result);
       
   417   sldi(R0, R0, LogBytesPerHeapOop);
       
   418   cmpd(CCR0, tmp, R0);
       
   419   blt(CCR0, index_ok);
       
   420   stop("resolved reference index out of bounds", 0x09256);
       
   421   bind(index_ok);
       
   422 #endif
       
   423   // Add in the index.
       
   424   add(result, tmp, result);
       
   425   load_heap_oop(result, arrayOopDesc::base_offset_in_bytes(T_OBJECT), result);
       
   426 }
       
   427 
       
   428 // Generate a subtype check: branch to ok_is_subtype if sub_klass is
       
   429 // a subtype of super_klass. Blows registers Rsub_klass, tmp1, tmp2.
       
   430 void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, Register Rsuper_klass, Register Rtmp1,
       
   431                                                   Register Rtmp2, Register Rtmp3, Label &ok_is_subtype) {
       
   432   // Profile the not-null value's klass.
       
   433   profile_typecheck(Rsub_klass, Rtmp1, Rtmp2);
       
   434   check_klass_subtype(Rsub_klass, Rsuper_klass, Rtmp1, Rtmp2, ok_is_subtype);
       
   435   profile_typecheck_failed(Rtmp1, Rtmp2);
       
   436 }
       
   437 
       
   438 void InterpreterMacroAssembler::generate_stack_overflow_check_with_compare_and_throw(Register Rmem_frame_size, Register Rscratch1) {
       
   439   Label done;
       
   440   sub(Rmem_frame_size, R1_SP, Rmem_frame_size);
       
   441   ld(Rscratch1, thread_(stack_overflow_limit));
       
   442   cmpld(CCR0/*is_stack_overflow*/, Rmem_frame_size, Rscratch1);
       
   443   bgt(CCR0/*is_stack_overflow*/, done);
       
   444 
       
   445   // Load target address of the runtime stub.
       
   446   assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "generated in wrong order");
       
   447   load_const_optimized(Rscratch1, (StubRoutines::throw_StackOverflowError_entry()), R0);
       
   448   mtctr(Rscratch1);
       
   449   // Restore caller_sp.
       
   450 #ifdef ASSERT
       
   451   ld(Rscratch1, 0, R1_SP);
       
   452   ld(R0, 0, R21_sender_SP);
       
   453   cmpd(CCR0, R0, Rscratch1);
       
   454   asm_assert_eq("backlink", 0x547);
       
   455 #endif // ASSERT
       
   456   mr(R1_SP, R21_sender_SP);
       
   457   bctr();
       
   458 
       
   459   align(32, 12);
       
   460   bind(done);
       
   461 }
       
   462 
       
   463 // Separate these two to allow for delay slot in middle.
       
   464 // These are used to do a test and full jump to exception-throwing code.
       
   465 
       
   466 // Check that index is in range for array, then shift index by index_shift,
       
   467 // and put arrayOop + shifted_index into res.
       
   468 // Note: res is still shy of address by array offset into object.
       
   469 
       
   470 void InterpreterMacroAssembler::index_check_without_pop(Register Rarray, Register Rindex, int index_shift, Register Rtmp, Register Rres) {
       
   471   // Check that index is in range for array, then shift index by index_shift,
       
   472   // and put arrayOop + shifted_index into res.
       
   473   // Note: res is still shy of address by array offset into object.
       
   474   // Kills:
       
   475   //   - Rindex
       
   476   // Writes:
       
   477   //   - Rres: Address that corresponds to the array index if check was successful.
       
   478   verify_oop(Rarray);
       
   479   const Register Rlength   = R0;
       
   480   const Register RsxtIndex = Rtmp;
       
   481   Label LisNull, LnotOOR;
       
   482 
       
   483   // Array nullcheck
       
   484   if (!ImplicitNullChecks) {
       
   485     cmpdi(CCR0, Rarray, 0);
       
   486     beq(CCR0, LisNull);
       
   487   } else {
       
   488     null_check_throw(Rarray, arrayOopDesc::length_offset_in_bytes(), /*temp*/RsxtIndex);
       
   489   }
       
   490 
       
   491   // Rindex might contain garbage in upper bits (remember that we don't sign extend
       
   492   // during integer arithmetic operations). So kill them and put value into same register
       
   493   // where ArrayIndexOutOfBounds would expect the index in.
       
   494   rldicl(RsxtIndex, Rindex, 0, 32); // zero extend 32 bit -> 64 bit
       
   495 
       
   496   // Index check
       
   497   lwz(Rlength, arrayOopDesc::length_offset_in_bytes(), Rarray);
       
   498   cmplw(CCR0, Rindex, Rlength);
       
   499   sldi(RsxtIndex, RsxtIndex, index_shift);
       
   500   blt(CCR0, LnotOOR);
       
   501   load_dispatch_table(Rtmp, (address*)Interpreter::_throw_ArrayIndexOutOfBoundsException_entry);
       
   502   mtctr(Rtmp);
       
   503   bctr();
       
   504 
       
   505   if (!ImplicitNullChecks) {
       
   506     bind(LisNull);
       
   507     load_dispatch_table(Rtmp, (address*)Interpreter::_throw_NullPointerException_entry);
       
   508     mtctr(Rtmp);
       
   509     bctr();
       
   510   }
       
   511 
       
   512   align(32, 16);
       
   513   bind(LnotOOR);
       
   514 
       
   515   // Calc address
       
   516   add(Rres, RsxtIndex, Rarray);
       
   517 }
       
   518 
       
   519 void InterpreterMacroAssembler::index_check(Register array, Register index, int index_shift, Register tmp, Register res) {
       
   520   // pop array
       
   521   pop_ptr(array);
       
   522 
       
   523   // check array
       
   524   index_check_without_pop(array, index, index_shift, tmp, res);
       
   525 }
       
   526 
       
   527 void InterpreterMacroAssembler::get_const(Register Rdst) {
       
   528   ld(Rdst, in_bytes(Method::const_offset()), R19_method);
       
   529 }
       
   530 
       
   531 void InterpreterMacroAssembler::get_constant_pool(Register Rdst) {
       
   532   get_const(Rdst);
       
   533   ld(Rdst, in_bytes(ConstMethod::constants_offset()), Rdst);
       
   534 }
       
   535 
       
   536 void InterpreterMacroAssembler::get_constant_pool_cache(Register Rdst) {
       
   537   get_constant_pool(Rdst);
       
   538   ld(Rdst, ConstantPool::cache_offset_in_bytes(), Rdst);
       
   539 }
       
   540 
       
   541 void InterpreterMacroAssembler::get_cpool_and_tags(Register Rcpool, Register Rtags) {
       
   542   get_constant_pool(Rcpool);
       
   543   ld(Rtags, ConstantPool::tags_offset_in_bytes(), Rcpool);
       
   544 }
       
   545 
       
   546 // Unlock if synchronized method.
       
   547 //
       
   548 // Unlock the receiver if this is a synchronized method.
       
   549 // Unlock any Java monitors from synchronized blocks.
       
   550 //
       
   551 // If there are locked Java monitors
       
   552 //   If throw_monitor_exception
       
   553 //     throws IllegalMonitorStateException
       
   554 //   Else if install_monitor_exception
       
   555 //     installs IllegalMonitorStateException
       
   556 //   Else
       
   557 //     no error processing
       
   558 void InterpreterMacroAssembler::unlock_if_synchronized_method(TosState state,
       
   559                                                               bool throw_monitor_exception,
       
   560                                                               bool install_monitor_exception) {
       
   561   Label Lunlocked, Lno_unlock;
       
   562   {
       
   563     Register Rdo_not_unlock_flag = R11_scratch1;
       
   564     Register Raccess_flags       = R12_scratch2;
       
   565 
       
   566     // Check if synchronized method or unlocking prevented by
       
   567     // JavaThread::do_not_unlock_if_synchronized flag.
       
   568     lbz(Rdo_not_unlock_flag, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread);
       
   569     lwz(Raccess_flags, in_bytes(Method::access_flags_offset()), R19_method);
       
   570     li(R0, 0);
       
   571     stb(R0, in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()), R16_thread); // reset flag
       
   572 
       
   573     push(state);
       
   574 
       
   575     // Skip if we don't have to unlock.
       
   576     rldicl_(R0, Raccess_flags, 64-JVM_ACC_SYNCHRONIZED_BIT, 63); // Extract bit and compare to 0.
       
   577     beq(CCR0, Lunlocked);
       
   578 
       
   579     cmpwi(CCR0, Rdo_not_unlock_flag, 0);
       
   580     bne(CCR0, Lno_unlock);
       
   581   }
       
   582 
       
   583   // Unlock
       
   584   {
       
   585     Register Rmonitor_base = R11_scratch1;
       
   586 
       
   587     Label Lunlock;
       
   588     // If it's still locked, everything is ok, unlock it.
       
   589     ld(Rmonitor_base, 0, R1_SP);
       
   590     addi(Rmonitor_base, Rmonitor_base, - (frame::ijava_state_size + frame::interpreter_frame_monitor_size_in_bytes())); // Monitor base
       
   591 
       
   592     ld(R0, BasicObjectLock::obj_offset_in_bytes(), Rmonitor_base);
       
   593     cmpdi(CCR0, R0, 0);
       
   594     bne(CCR0, Lunlock);
       
   595 
       
   596     // If it's already unlocked, throw exception.
       
   597     if (throw_monitor_exception) {
       
   598       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
       
   599       should_not_reach_here();
       
   600     } else {
       
   601       if (install_monitor_exception) {
       
   602         call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
       
   603         b(Lunlocked);
       
   604       }
       
   605     }
       
   606 
       
   607     bind(Lunlock);
       
   608     unlock_object(Rmonitor_base);
       
   609   }
       
   610 
       
   611   // Check that all other monitors are unlocked. Throw IllegelMonitorState exception if not.
       
   612   bind(Lunlocked);
       
   613   {
       
   614     Label Lexception, Lrestart;
       
   615     Register Rcurrent_obj_addr = R11_scratch1;
       
   616     const int delta = frame::interpreter_frame_monitor_size_in_bytes();
       
   617     assert((delta & LongAlignmentMask) == 0, "sizeof BasicObjectLock must be even number of doublewords");
       
   618 
       
   619     bind(Lrestart);
       
   620     // Set up search loop: Calc num of iterations.
       
   621     {
       
   622       Register Riterations = R12_scratch2;
       
   623       Register Rmonitor_base = Rcurrent_obj_addr;
       
   624       ld(Rmonitor_base, 0, R1_SP);
       
   625       addi(Rmonitor_base, Rmonitor_base, - frame::ijava_state_size);  // Monitor base
       
   626 
       
   627       subf_(Riterations, R26_monitor, Rmonitor_base);
       
   628       ble(CCR0, Lno_unlock);
       
   629 
       
   630       addi(Rcurrent_obj_addr, Rmonitor_base, BasicObjectLock::obj_offset_in_bytes() - frame::interpreter_frame_monitor_size_in_bytes());
       
   631       // Check if any monitor is on stack, bail out if not
       
   632       srdi(Riterations, Riterations, exact_log2(delta));
       
   633       mtctr(Riterations);
       
   634     }
       
   635 
       
   636     // The search loop: Look for locked monitors.
       
   637     {
       
   638       const Register Rcurrent_obj = R0;
       
   639       Label Lloop;
       
   640 
       
   641       ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
       
   642       addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);
       
   643       bind(Lloop);
       
   644 
       
   645       // Check if current entry is used.
       
   646       cmpdi(CCR0, Rcurrent_obj, 0);
       
   647       bne(CCR0, Lexception);
       
   648       // Preload next iteration's compare value.
       
   649       ld(Rcurrent_obj, 0, Rcurrent_obj_addr);
       
   650       addi(Rcurrent_obj_addr, Rcurrent_obj_addr, -delta);
       
   651       bdnz(Lloop);
       
   652     }
       
   653     // Fell through: Everything's unlocked => finish.
       
   654     b(Lno_unlock);
       
   655 
       
   656     // An object is still locked => need to throw exception.
       
   657     bind(Lexception);
       
   658     if (throw_monitor_exception) {
       
   659       call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
       
   660       should_not_reach_here();
       
   661     } else {
       
   662       // Stack unrolling. Unlock object and if requested, install illegal_monitor_exception.
       
   663       // Unlock does not block, so don't have to worry about the frame.
       
   664       Register Rmonitor_addr = R11_scratch1;
       
   665       addi(Rmonitor_addr, Rcurrent_obj_addr, -BasicObjectLock::obj_offset_in_bytes() + delta);
       
   666       unlock_object(Rmonitor_addr);
       
   667       if (install_monitor_exception) {
       
   668         call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::new_illegal_monitor_state_exception));
       
   669       }
       
   670       b(Lrestart);
       
   671     }
       
   672   }
       
   673 
       
   674   align(32, 12);
       
   675   bind(Lno_unlock);
       
   676   pop(state);
       
   677 }
       
   678 
       
   679 // Support function for remove_activation & Co.
       
   680 void InterpreterMacroAssembler::merge_frames(Register Rsender_sp, Register return_pc, Register Rscratch1, Register Rscratch2) {
       
   681   // Pop interpreter frame.
       
   682   ld(Rscratch1, 0, R1_SP); // *SP
       
   683   ld(Rsender_sp, _ijava_state_neg(sender_sp), Rscratch1); // top_frame_sp
       
   684   ld(Rscratch2, 0, Rscratch1); // **SP
       
   685 #ifdef ASSERT
       
   686   {
       
   687     Label Lok;
       
   688     ld(R0, _ijava_state_neg(ijava_reserved), Rscratch1);
       
   689     cmpdi(CCR0, R0, 0x5afe);
       
   690     beq(CCR0, Lok);
       
   691     stop("frame corrupted (remove activation)", 0x5afe);
       
   692     bind(Lok);
       
   693   }
       
   694 #endif
       
   695   if (return_pc!=noreg) {
       
   696     ld(return_pc, _abi(lr), Rscratch1); // LR
       
   697   }
       
   698 
       
   699   // Merge top frames.
       
   700   subf(Rscratch1, R1_SP, Rsender_sp); // top_frame_sp - SP
       
   701   stdux(Rscratch2, R1_SP, Rscratch1); // atomically set *(SP = top_frame_sp) = **SP
       
   702 }
       
   703 
       
   704 // Remove activation.
       
   705 //
       
   706 // Unlock the receiver if this is a synchronized method.
       
   707 // Unlock any Java monitors from synchronized blocks.
       
   708 // Remove the activation from the stack.
       
   709 //
       
   710 // If there are locked Java monitors
       
   711 //    If throw_monitor_exception
       
   712 //       throws IllegalMonitorStateException
       
   713 //    Else if install_monitor_exception
       
   714 //       installs IllegalMonitorStateException
       
   715 //    Else
       
   716 //       no error processing
       
   717 void InterpreterMacroAssembler::remove_activation(TosState state,
       
   718                                                   bool throw_monitor_exception,
       
   719                                                   bool install_monitor_exception) {
       
   720   unlock_if_synchronized_method(state, throw_monitor_exception, install_monitor_exception);
       
   721 
       
   722   // Save result (push state before jvmti call and pop it afterwards) and notify jvmti.
       
   723   notify_method_exit(false, state, NotifyJVMTI, true);
       
   724 
       
   725   verify_oop(R17_tos, state);
       
   726   verify_thread();
       
   727 
       
   728   merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
       
   729   mtlr(R0);
       
   730 }
       
   731 
       
   732 #endif // !CC_INTERP
    47 
   733 
    48 // Lock object
   734 // Lock object
    49 //
   735 //
    50 // Registers alive
   736 // Registers alive
    51 //   monitor - Address of the BasicObjectLock to be used for locking,
   737 //   monitor - Address of the BasicObjectLock to be used for locking,
    79     Label done;
   765     Label done;
    80     Label cas_failed, slow_case;
   766     Label cas_failed, slow_case;
    81 
   767 
    82     assert_different_registers(displaced_header, object_mark_addr, current_header, tmp);
   768     assert_different_registers(displaced_header, object_mark_addr, current_header, tmp);
    83 
   769 
    84 
       
    85     // markOop displaced_header = obj->mark().set_unlocked();
   770     // markOop displaced_header = obj->mark().set_unlocked();
    86 
   771 
    87     // Load markOop from object into displaced_header.
   772     // Load markOop from object into displaced_header.
    88     ld(displaced_header, oopDesc::mark_offset_in_bytes(), object);
   773     ld(displaced_header, oopDesc::mark_offset_in_bytes(), object);
    89 
   774 
    91       biased_locking_enter(CCR0, object, displaced_header, tmp, current_header, done, &slow_case);
   776       biased_locking_enter(CCR0, object, displaced_header, tmp, current_header, done, &slow_case);
    92     }
   777     }
    93 
   778 
    94     // Set displaced_header to be (markOop of object | UNLOCK_VALUE).
   779     // Set displaced_header to be (markOop of object | UNLOCK_VALUE).
    95     ori(displaced_header, displaced_header, markOopDesc::unlocked_value);
   780     ori(displaced_header, displaced_header, markOopDesc::unlocked_value);
    96 
       
    97 
   781 
    98     // monitor->lock()->set_displaced_header(displaced_header);
   782     // monitor->lock()->set_displaced_header(displaced_header);
    99 
   783 
   100     // Initialize the box (Must happen before we update the object mark!).
   784     // Initialize the box (Must happen before we update the object mark!).
   101     std(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
   785     std(displaced_header, BasicObjectLock::lock_offset_in_bytes() +
   145     release();
   829     release();
   146     std(R0/*==0!*/, BasicObjectLock::lock_offset_in_bytes() +
   830     std(R0/*==0!*/, BasicObjectLock::lock_offset_in_bytes() +
   147         BasicLock::displaced_header_offset_in_bytes(), monitor);
   831         BasicLock::displaced_header_offset_in_bytes(), monitor);
   148     b(done);
   832     b(done);
   149 
   833 
   150 
       
   151     // } else {
   834     // } else {
   152     //   // Slow path.
   835     //   // Slow path.
   153     //   InterpreterRuntime::monitorenter(THREAD, monitor);
   836     //   InterpreterRuntime::monitorenter(THREAD, monitor);
   154 
   837 
   155     // None of the above fast optimizations worked so we have to get into the
   838     // None of the above fast optimizations worked so we have to get into the
   156     // slow case of monitor enter.
   839     // slow case of monitor enter.
   157     bind(slow_case);
   840     bind(slow_case);
   158     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
   841     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter),
   159             monitor, /*check_for_exceptions=*/true CC_INTERP_ONLY(&& false));
   842             monitor, /*check_for_exceptions=*/true CC_INTERP_ONLY(&& false));
   160     // }
   843     // }
   161 
   844     align(32, 12);
   162     bind(done);
   845     bind(done);
   163   }
   846   }
   164 }
   847 }
   165 
   848 
   166 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
   849 // Unlocks an object. Used in monitorexit bytecode and remove_activation.
   171 //
   854 //
   172 // Throw IllegalMonitorException if object is not locked by current thread.
   855 // Throw IllegalMonitorException if object is not locked by current thread.
   173 void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_exceptions) {
   856 void InterpreterMacroAssembler::unlock_object(Register monitor, bool check_for_exceptions) {
   174   if (UseHeavyMonitors) {
   857   if (UseHeavyMonitors) {
   175     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
   858     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit),
   176             monitor, /*check_for_exceptions=*/false);
   859             monitor, check_for_exceptions CC_INTERP_ONLY(&& false));
   177   } else {
   860   } else {
   178 
   861 
   179     // template code:
   862     // template code:
   180     //
   863     //
   181     // if ((displaced_header = monitor->displaced_header()) == NULL) {
   864     // if ((displaced_header = monitor->displaced_header()) == NULL) {
   182     //   // Recursive unlock.  Mark the monitor unlocked by setting the object field to NULL.
   865     //   // Recursive unlock. Mark the monitor unlocked by setting the object field to NULL.
   183     //   monitor->set_obj(NULL);
   866     //   monitor->set_obj(NULL);
   184     // } else if (Atomic::cmpxchg_ptr(displaced_header, obj->mark_addr(), monitor) == monitor) {
   867     // } else if (Atomic::cmpxchg_ptr(displaced_header, obj->mark_addr(), monitor) == monitor) {
   185     //   // We swapped the unlocked mark in displaced_header into the object's mark word.
   868     //   // We swapped the unlocked mark in displaced_header into the object's mark word.
   186     //   monitor->set_obj(NULL);
   869     //   monitor->set_obj(NULL);
   187     // } else {
   870     // } else {
   219     //   monitor->set_obj(NULL);
   902     //   monitor->set_obj(NULL);
   220 
   903 
   221     // If we still have a lightweight lock, unlock the object and be done.
   904     // If we still have a lightweight lock, unlock the object and be done.
   222 
   905 
   223     // The object address from the monitor is in object.
   906     // The object address from the monitor is in object.
   224     if (!UseBiasedLocking) ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor);
   907     if (!UseBiasedLocking) { ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor); }
   225     addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());
   908     addi(object_mark_addr, object, oopDesc::mark_offset_in_bytes());
   226 
   909 
   227     // We have the displaced header in displaced_header. If the lock is still
   910     // We have the displaced header in displaced_header. If the lock is still
   228     // lightweight, it will contain the monitor address and we'll store the
   911     // lightweight, it will contain the monitor address and we'll store the
   229     // displaced header back into the object's mark word.
   912     // displaced header back into the object's mark word.
   258     li(R0, 0);
   941     li(R0, 0);
   259     std(R0, BasicObjectLock::obj_offset_in_bytes(), monitor);
   942     std(R0, BasicObjectLock::obj_offset_in_bytes(), monitor);
   260     bind(done);
   943     bind(done);
   261   }
   944   }
   262 }
   945 }
       
   946 
       
   947 #ifndef CC_INTERP
       
   948 
       
   949 // Load compiled (i2c) or interpreter entry when calling from interpreted and
       
   950 // do the call. Centralized so that all interpreter calls will do the same actions.
       
   951 // If jvmti single stepping is on for a thread we must not call compiled code.
       
   952 //
       
   953 // Input:
       
   954 //   - Rtarget_method: method to call
       
   955 //   - Rret_addr:      return address
       
   956 //   - 2 scratch regs
       
   957 //
       
   958 void InterpreterMacroAssembler::call_from_interpreter(Register Rtarget_method, Register Rret_addr, Register Rscratch1, Register Rscratch2) {
       
   959   assert_different_registers(Rscratch1, Rscratch2, Rtarget_method, Rret_addr);
       
   960   // Assume we want to go compiled if available.
       
   961   const Register Rtarget_addr = Rscratch1;
       
   962   const Register Rinterp_only = Rscratch2;
       
   963 
       
   964   ld(Rtarget_addr, in_bytes(Method::from_interpreted_offset()), Rtarget_method);
       
   965 
       
   966   if (JvmtiExport::can_post_interpreter_events()) {
       
   967     lwz(Rinterp_only, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
       
   968 
       
   969     // JVMTI events, such as single-stepping, are implemented partly by avoiding running
       
   970     // compiled code in threads for which the event is enabled. Check here for
       
   971     // interp_only_mode if these events CAN be enabled.
       
   972     Label done;
       
   973     verify_thread();
       
   974     cmpwi(CCR0, Rinterp_only, 0);
       
   975     beq(CCR0, done);
       
   976     ld(Rtarget_addr, in_bytes(Method::interpreter_entry_offset()), Rtarget_method);
       
   977     align(32, 12);
       
   978     bind(done);
       
   979   }
       
   980 
       
   981 #ifdef ASSERT
       
   982   {
       
   983     Label Lok;
       
   984     cmpdi(CCR0, Rtarget_addr, 0);
       
   985     bne(CCR0, Lok);
       
   986     stop("null entry point");
       
   987     bind(Lok);
       
   988   }
       
   989 #endif // ASSERT
       
   990 
       
   991   mr(R21_sender_SP, R1_SP);
       
   992 
       
   993   // Calc a precise SP for the call. The SP value we calculated in
       
   994   // generate_fixed_frame() is based on the max_stack() value, so we would waste stack space
       
   995   // if esp is not max. Also, the i2c adapter extends the stack space without restoring
       
   996   // our pre-calced value, so repeating calls via i2c would result in stack overflow.
       
   997   // Since esp already points to an empty slot, we just have to sub 1 additional slot
       
   998   // to meet the abi scratch requirements.
       
   999   // The max_stack pointer will get restored by means of the GR_Lmax_stack local in
       
  1000   // the return entry of the interpreter.
       
  1001   addi(Rscratch2, R15_esp, Interpreter::stackElementSize - frame::abi_reg_args_size);
       
  1002   clrrdi(Rscratch2, Rscratch2, exact_log2(frame::alignment_in_bytes)); // round towards smaller address
       
  1003   resize_frame_absolute(Rscratch2, Rscratch2, R0);
       
  1004 
       
  1005   mr_if_needed(R19_method, Rtarget_method);
       
  1006   mtctr(Rtarget_addr);
       
  1007   mtlr(Rret_addr);
       
  1008 
       
  1009   save_interpreter_state(Rscratch2);
       
  1010 #ifdef ASSERT
       
  1011   ld(Rscratch1, _ijava_state_neg(top_frame_sp), Rscratch2); // Rscratch2 contains fp
       
  1012   cmpd(CCR0, R21_sender_SP, Rscratch1);
       
  1013   asm_assert_eq("top_frame_sp incorrect", 0x951);
       
  1014 #endif
       
  1015 
       
  1016   bctr();
       
  1017 }
       
  1018 
       
  1019 // Set the method data pointer for the current bcp.
       
  1020 void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() {
       
  1021   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1022   Label get_continue;
       
  1023   ld(R28_mdx, in_bytes(Method::method_data_offset()), R19_method);
       
  1024   test_method_data_pointer(get_continue);
       
  1025   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), R19_method, R14_bcp);
       
  1026 
       
  1027   addi(R28_mdx, R28_mdx, in_bytes(MethodData::data_offset()));
       
  1028   add(R28_mdx, R28_mdx, R3_RET);
       
  1029   bind(get_continue);
       
  1030 }
       
  1031 
       
  1032 // Test ImethodDataPtr. If it is null, continue at the specified label.
       
  1033 void InterpreterMacroAssembler::test_method_data_pointer(Label& zero_continue) {
       
  1034   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1035   cmpdi(CCR0, R28_mdx, 0);
       
  1036   beq(CCR0, zero_continue);
       
  1037 }
       
  1038 
       
  1039 void InterpreterMacroAssembler::verify_method_data_pointer() {
       
  1040   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1041 #ifdef ASSERT
       
  1042   Label verify_continue;
       
  1043   test_method_data_pointer(verify_continue);
       
  1044 
       
  1045   // If the mdp is valid, it will point to a DataLayout header which is
       
  1046   // consistent with the bcp. The converse is highly probable also.
       
  1047   lhz(R11_scratch1, in_bytes(DataLayout::bci_offset()), R28_mdx);
       
  1048   ld(R12_scratch2, in_bytes(Method::const_offset()), R19_method);
       
  1049   addi(R11_scratch1, R11_scratch1, in_bytes(ConstMethod::codes_offset()));
       
  1050   add(R11_scratch1, R12_scratch2, R12_scratch2);
       
  1051   cmpd(CCR0, R11_scratch1, R14_bcp);
       
  1052   beq(CCR0, verify_continue);
       
  1053 
       
  1054   call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp ), R19_method, R14_bcp, R28_mdx);
       
  1055 
       
  1056   bind(verify_continue);
       
  1057 #endif
       
  1058 }
       
  1059 
       
  1060 void InterpreterMacroAssembler::test_invocation_counter_for_mdp(Register invocation_count,
       
  1061                                                                 Register Rscratch,
       
  1062                                                                 Label &profile_continue) {
       
  1063   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1064   // Control will flow to "profile_continue" if the counter is less than the
       
  1065   // limit or if we call profile_method().
       
  1066   Label done;
       
  1067 
       
  1068   // If no method data exists, and the counter is high enough, make one.
       
  1069   int ipl_offs = load_const_optimized(Rscratch, &InvocationCounter::InterpreterProfileLimit, R0, true);
       
  1070   lwz(Rscratch, ipl_offs, Rscratch);
       
  1071 
       
  1072   cmpdi(CCR0, R28_mdx, 0);
       
  1073   // Test to see if we should create a method data oop.
       
  1074   cmpd(CCR1, Rscratch /* InterpreterProfileLimit */, invocation_count);
       
  1075   bne(CCR0, done);
       
  1076   bge(CCR1, profile_continue);
       
  1077 
       
  1078   // Build it now.
       
  1079   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
       
  1080   set_method_data_pointer_for_bcp();
       
  1081   b(profile_continue);
       
  1082 
       
  1083   align(32, 12);
       
  1084   bind(done);
       
  1085 }
       
  1086 
       
  1087 void InterpreterMacroAssembler::test_backedge_count_for_osr(Register backedge_count, Register branch_bcp, Register Rtmp) {
       
  1088   assert_different_registers(backedge_count, Rtmp, branch_bcp);
       
  1089   assert(UseOnStackReplacement,"Must UseOnStackReplacement to test_backedge_count_for_osr");
       
  1090 
       
  1091   Label did_not_overflow;
       
  1092   Label overflow_with_error;
       
  1093 
       
  1094   int ibbl_offs = load_const_optimized(Rtmp, &InvocationCounter::InterpreterBackwardBranchLimit, R0, true);
       
  1095   lwz(Rtmp, ibbl_offs, Rtmp);
       
  1096   cmpw(CCR0, backedge_count, Rtmp);
       
  1097 
       
  1098   blt(CCR0, did_not_overflow);
       
  1099 
       
  1100   // When ProfileInterpreter is on, the backedge_count comes from the
       
  1101   // methodDataOop, which value does not get reset on the call to
       
  1102   // frequency_counter_overflow(). To avoid excessive calls to the overflow
       
  1103   // routine while the method is being compiled, add a second test to make sure
       
  1104   // the overflow function is called only once every overflow_frequency.
       
  1105   if (ProfileInterpreter) {
       
  1106     const int overflow_frequency = 1024;
       
  1107     li(Rtmp, overflow_frequency-1);
       
  1108     andr(Rtmp, Rtmp, backedge_count);
       
  1109     cmpwi(CCR0, Rtmp, 0);
       
  1110     bne(CCR0, did_not_overflow);
       
  1111   }
       
  1112 
       
  1113   // Overflow in loop, pass branch bytecode.
       
  1114   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), branch_bcp, true);
       
  1115 
       
  1116   // Was an OSR adapter generated?
       
  1117   // O0 = osr nmethod
       
  1118   cmpdi(CCR0, R3_RET, 0);
       
  1119   beq(CCR0, overflow_with_error);
       
  1120 
       
  1121   // Has the nmethod been invalidated already?
       
  1122   lwz(Rtmp, nmethod::entry_bci_offset(), R3_RET);
       
  1123   cmpwi(CCR0, Rtmp, InvalidOSREntryBci);
       
  1124   beq(CCR0, overflow_with_error);
       
  1125 
       
  1126   // Migrate the interpreter frame off of the stack.
       
  1127   // We can use all registers because we will not return to interpreter from this point.
       
  1128 
       
  1129   // Save nmethod.
       
  1130   const Register osr_nmethod = R31;
       
  1131   mr(osr_nmethod, R3_RET);
       
  1132   set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R11_scratch1);
       
  1133   call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::OSR_migration_begin), R16_thread);
       
  1134   reset_last_Java_frame();
       
  1135   // OSR buffer is in ARG1
       
  1136 
       
  1137   // Remove the interpreter frame.
       
  1138   merge_frames(/*top_frame_sp*/ R21_sender_SP, /*return_pc*/ R0, R11_scratch1, R12_scratch2);
       
  1139 
       
  1140   // Jump to the osr code.
       
  1141   ld(R11_scratch1, nmethod::osr_entry_point_offset(), osr_nmethod);
       
  1142   mtlr(R0);
       
  1143   mtctr(R11_scratch1);
       
  1144   bctr();
       
  1145 
       
  1146   align(32, 12);
       
  1147   bind(overflow_with_error);
       
  1148   bind(did_not_overflow);
       
  1149 }
       
  1150 
       
  1151 // Store a value at some constant offset from the method data pointer.
       
  1152 void InterpreterMacroAssembler::set_mdp_data_at(int constant, Register value) {
       
  1153   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1154 
       
  1155   std(value, constant, R28_mdx);
       
  1156 }
       
  1157 
       
  1158 // Increment the value at some constant offset from the method data pointer.
       
  1159 void InterpreterMacroAssembler::increment_mdp_data_at(int constant,
       
  1160                                                       Register counter_addr,
       
  1161                                                       Register Rbumped_count,
       
  1162                                                       bool decrement) {
       
  1163   // Locate the counter at a fixed offset from the mdp:
       
  1164   addi(counter_addr, R28_mdx, constant);
       
  1165   increment_mdp_data_at(counter_addr, Rbumped_count, decrement);
       
  1166 }
       
  1167 
       
  1168 // Increment the value at some non-fixed (reg + constant) offset from
       
  1169 // the method data pointer.
       
  1170 void InterpreterMacroAssembler::increment_mdp_data_at(Register reg,
       
  1171                                                       int constant,
       
  1172                                                       Register scratch,
       
  1173                                                       Register Rbumped_count,
       
  1174                                                       bool decrement) {
       
  1175   // Add the constant to reg to get the offset.
       
  1176   add(scratch, R28_mdx, reg);
       
  1177   // Then calculate the counter address.
       
  1178   addi(scratch, scratch, constant);
       
  1179   increment_mdp_data_at(scratch, Rbumped_count, decrement);
       
  1180 }
       
  1181 
       
  1182 void InterpreterMacroAssembler::increment_mdp_data_at(Register counter_addr,
       
  1183                                                       Register Rbumped_count,
       
  1184                                                       bool decrement) {
       
  1185   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1186 
       
  1187   // Load the counter.
       
  1188   ld(Rbumped_count, 0, counter_addr);
       
  1189 
       
  1190   if (decrement) {
       
  1191     // Decrement the register. Set condition codes.
       
  1192     addi(Rbumped_count, Rbumped_count, - DataLayout::counter_increment);
       
  1193     // Store the decremented counter, if it is still negative.
       
  1194     std(Rbumped_count, 0, counter_addr);
       
  1195     // Note: add/sub overflow check are not ported, since 64 bit
       
  1196     // calculation should never overflow.
       
  1197   } else {
       
  1198     // Increment the register. Set carry flag.
       
  1199     addi(Rbumped_count, Rbumped_count, DataLayout::counter_increment);
       
  1200     // Store the incremented counter.
       
  1201     std(Rbumped_count, 0, counter_addr);
       
  1202   }
       
  1203 }
       
  1204 
       
  1205 // Set a flag value at the current method data pointer position.
       
  1206 void InterpreterMacroAssembler::set_mdp_flag_at(int flag_constant,
       
  1207                                                 Register scratch) {
       
  1208   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1209   // Load the data header.
       
  1210   lbz(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx);
       
  1211   // Set the flag.
       
  1212   ori(scratch, scratch, flag_constant);
       
  1213   // Store the modified header.
       
  1214   stb(scratch, in_bytes(DataLayout::flags_offset()), R28_mdx);
       
  1215 }
       
  1216 
       
  1217 // Test the location at some offset from the method data pointer.
       
  1218 // If it is not equal to value, branch to the not_equal_continue Label.
       
  1219 void InterpreterMacroAssembler::test_mdp_data_at(int offset,
       
  1220                                                  Register value,
       
  1221                                                  Label& not_equal_continue,
       
  1222                                                  Register test_out) {
       
  1223   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1224 
       
  1225   ld(test_out, offset, R28_mdx);
       
  1226   cmpd(CCR0,  value, test_out);
       
  1227   bne(CCR0, not_equal_continue);
       
  1228 }
       
  1229 
       
  1230 // Update the method data pointer by the displacement located at some fixed
       
  1231 // offset from the method data pointer.
       
  1232 void InterpreterMacroAssembler::update_mdp_by_offset(int offset_of_disp,
       
  1233                                                      Register scratch) {
       
  1234   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1235 
       
  1236   ld(scratch, offset_of_disp, R28_mdx);
       
  1237   add(R28_mdx, scratch, R28_mdx);
       
  1238 }
       
  1239 
       
  1240 // Update the method data pointer by the displacement located at the
       
  1241 // offset (reg + offset_of_disp).
       
  1242 void InterpreterMacroAssembler::update_mdp_by_offset(Register reg,
       
  1243                                                      int offset_of_disp,
       
  1244                                                      Register scratch) {
       
  1245   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1246 
       
  1247   add(scratch, reg, R28_mdx);
       
  1248   ld(scratch, offset_of_disp, scratch);
       
  1249   add(R28_mdx, scratch, R28_mdx);
       
  1250 }
       
  1251 
       
  1252 // Update the method data pointer by a simple constant displacement.
       
  1253 void InterpreterMacroAssembler::update_mdp_by_constant(int constant) {
       
  1254   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1255   addi(R28_mdx, R28_mdx, constant);
       
  1256 }
       
  1257 
       
  1258 // Update the method data pointer for a _ret bytecode whose target
       
  1259 // was not among our cached targets.
       
  1260 void InterpreterMacroAssembler::update_mdp_for_ret(TosState state,
       
  1261                                                    Register return_bci) {
       
  1262   assert(ProfileInterpreter, "must be profiling interpreter");
       
  1263 
       
  1264   push(state);
       
  1265   assert(return_bci->is_nonvolatile(), "need to protect return_bci");
       
  1266   call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), return_bci);
       
  1267   pop(state);
       
  1268 }
       
  1269 
       
  1270 // Increments the backedge counter.
       
  1271 // Returns backedge counter + invocation counter in Rdst.
       
  1272 void InterpreterMacroAssembler::increment_backedge_counter(const Register Rcounters, const Register Rdst,
       
  1273                                                            const Register Rtmp1, Register Rscratch) {
       
  1274   assert(UseCompiler, "incrementing must be useful");
       
  1275   assert_different_registers(Rdst, Rtmp1);
       
  1276   const Register invocation_counter = Rtmp1;
       
  1277   const Register counter = Rdst;
       
  1278   // TODO ppc port assert(4 == InvocationCounter::sz_counter(), "unexpected field size.");
       
  1279 
       
  1280   // Load backedge counter.
       
  1281   lwz(counter, in_bytes(MethodCounters::backedge_counter_offset()) +
       
  1282                in_bytes(InvocationCounter::counter_offset()), Rcounters);
       
  1283   // Load invocation counter.
       
  1284   lwz(invocation_counter, in_bytes(MethodCounters::invocation_counter_offset()) +
       
  1285                           in_bytes(InvocationCounter::counter_offset()), Rcounters);
       
  1286 
       
  1287   // Add the delta to the backedge counter.
       
  1288   addi(counter, counter, InvocationCounter::count_increment);
       
  1289 
       
  1290   // Mask the invocation counter.
       
  1291   li(Rscratch, InvocationCounter::count_mask_value);
       
  1292   andr(invocation_counter, invocation_counter, Rscratch);
       
  1293 
       
  1294   // Store new counter value.
       
  1295   stw(counter, in_bytes(MethodCounters::backedge_counter_offset()) +
       
  1296                in_bytes(InvocationCounter::counter_offset()), Rcounters);
       
  1297   // Return invocation counter + backedge counter.
       
  1298   add(counter, counter, invocation_counter);
       
  1299 }
       
  1300 
       
  1301 // Count a taken branch in the bytecodes.
       
  1302 void InterpreterMacroAssembler::profile_taken_branch(Register scratch, Register bumped_count) {
       
  1303   if (ProfileInterpreter) {
       
  1304     Label profile_continue;
       
  1305 
       
  1306     // If no method data exists, go to profile_continue.
       
  1307     test_method_data_pointer(profile_continue);
       
  1308 
       
  1309     // We are taking a branch. Increment the taken count.
       
  1310     increment_mdp_data_at(in_bytes(JumpData::taken_offset()), scratch, bumped_count);
       
  1311 
       
  1312     // The method data pointer needs to be updated to reflect the new target.
       
  1313     update_mdp_by_offset(in_bytes(JumpData::displacement_offset()), scratch);
       
  1314     bind (profile_continue);
       
  1315   }
       
  1316 }
       
  1317 
       
  1318 // Count a not-taken branch in the bytecodes.
       
  1319 void InterpreterMacroAssembler::profile_not_taken_branch(Register scratch1, Register scratch2) {
       
  1320   if (ProfileInterpreter) {
       
  1321     Label profile_continue;
       
  1322 
       
  1323     // If no method data exists, go to profile_continue.
       
  1324     test_method_data_pointer(profile_continue);
       
  1325 
       
  1326     // We are taking a branch. Increment the not taken count.
       
  1327     increment_mdp_data_at(in_bytes(BranchData::not_taken_offset()), scratch1, scratch2);
       
  1328 
       
  1329     // The method data pointer needs to be updated to correspond to the
       
  1330     // next bytecode.
       
  1331     update_mdp_by_constant(in_bytes(BranchData::branch_data_size()));
       
  1332     bind (profile_continue);
       
  1333   }
       
  1334 }
       
  1335 
       
  1336 // Count a non-virtual call in the bytecodes.
       
  1337 void InterpreterMacroAssembler::profile_call(Register scratch1, Register scratch2) {
       
  1338   if (ProfileInterpreter) {
       
  1339     Label profile_continue;
       
  1340 
       
  1341     // If no method data exists, go to profile_continue.
       
  1342     test_method_data_pointer(profile_continue);
       
  1343 
       
  1344     // We are making a call. Increment the count.
       
  1345     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
       
  1346 
       
  1347     // The method data pointer needs to be updated to reflect the new target.
       
  1348     update_mdp_by_constant(in_bytes(CounterData::counter_data_size()));
       
  1349     bind (profile_continue);
       
  1350   }
       
  1351 }
       
  1352 
       
  1353 // Count a final call in the bytecodes.
       
  1354 void InterpreterMacroAssembler::profile_final_call(Register scratch1, Register scratch2) {
       
  1355   if (ProfileInterpreter) {
       
  1356     Label profile_continue;
       
  1357 
       
  1358     // If no method data exists, go to profile_continue.
       
  1359     test_method_data_pointer(profile_continue);
       
  1360 
       
  1361     // We are making a call. Increment the count.
       
  1362     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
       
  1363 
       
  1364     // The method data pointer needs to be updated to reflect the new target.
       
  1365     update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
       
  1366     bind (profile_continue);
       
  1367   }
       
  1368 }
       
  1369 
       
  1370 // Count a virtual call in the bytecodes.
       
  1371 void InterpreterMacroAssembler::profile_virtual_call(Register Rreceiver,
       
  1372                                                      Register Rscratch1,
       
  1373                                                      Register Rscratch2,
       
  1374                                                      bool receiver_can_be_null) {
       
  1375   if (!ProfileInterpreter) { return; }
       
  1376   Label profile_continue;
       
  1377 
       
  1378   // If no method data exists, go to profile_continue.
       
  1379   test_method_data_pointer(profile_continue);
       
  1380 
       
  1381   Label skip_receiver_profile;
       
  1382   if (receiver_can_be_null) {
       
  1383     Label not_null;
       
  1384     cmpdi(CCR0, Rreceiver, 0);
       
  1385     bne(CCR0, not_null);
       
  1386     // We are making a call. Increment the count for null receiver.
       
  1387     increment_mdp_data_at(in_bytes(CounterData::count_offset()), Rscratch1, Rscratch2);
       
  1388     b(skip_receiver_profile);
       
  1389     bind(not_null);
       
  1390   }
       
  1391 
       
  1392   // Record the receiver type.
       
  1393   record_klass_in_profile(Rreceiver, Rscratch1, Rscratch2, true);
       
  1394   bind(skip_receiver_profile);
       
  1395 
       
  1396   // The method data pointer needs to be updated to reflect the new target.
       
  1397   update_mdp_by_constant(in_bytes(VirtualCallData::virtual_call_data_size()));
       
  1398   bind (profile_continue);
       
  1399 }
       
  1400 
       
  1401 void InterpreterMacroAssembler::profile_typecheck(Register Rklass, Register Rscratch1, Register Rscratch2) {
       
  1402   if (ProfileInterpreter) {
       
  1403     Label profile_continue;
       
  1404 
       
  1405     // If no method data exists, go to profile_continue.
       
  1406     test_method_data_pointer(profile_continue);
       
  1407 
       
  1408     int mdp_delta = in_bytes(BitData::bit_data_size());
       
  1409     if (TypeProfileCasts) {
       
  1410       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
       
  1411 
       
  1412       // Record the object type.
       
  1413       record_klass_in_profile(Rklass, Rscratch1, Rscratch2, false);
       
  1414     }
       
  1415 
       
  1416     // The method data pointer needs to be updated.
       
  1417     update_mdp_by_constant(mdp_delta);
       
  1418 
       
  1419     bind (profile_continue);
       
  1420   }
       
  1421 }
       
  1422 
       
  1423 void InterpreterMacroAssembler::profile_typecheck_failed(Register Rscratch1, Register Rscratch2) {
       
  1424   if (ProfileInterpreter && TypeProfileCasts) {
       
  1425     Label profile_continue;
       
  1426 
       
  1427     // If no method data exists, go to profile_continue.
       
  1428     test_method_data_pointer(profile_continue);
       
  1429 
       
  1430     int count_offset = in_bytes(CounterData::count_offset());
       
  1431     // Back up the address, since we have already bumped the mdp.
       
  1432     count_offset -= in_bytes(VirtualCallData::virtual_call_data_size());
       
  1433 
       
  1434     // *Decrement* the counter. We expect to see zero or small negatives.
       
  1435     increment_mdp_data_at(count_offset, Rscratch1, Rscratch2, true);
       
  1436 
       
  1437     bind (profile_continue);
       
  1438   }
       
  1439 }
       
  1440 
       
  1441 // Count a ret in the bytecodes.
       
  1442 void InterpreterMacroAssembler::profile_ret(TosState state, Register return_bci, Register scratch1, Register scratch2) {
       
  1443   if (ProfileInterpreter) {
       
  1444     Label profile_continue;
       
  1445     uint row;
       
  1446 
       
  1447     // If no method data exists, go to profile_continue.
       
  1448     test_method_data_pointer(profile_continue);
       
  1449 
       
  1450     // Update the total ret count.
       
  1451     increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2 );
       
  1452 
       
  1453     for (row = 0; row < RetData::row_limit(); row++) {
       
  1454       Label next_test;
       
  1455 
       
  1456       // See if return_bci is equal to bci[n]:
       
  1457       test_mdp_data_at(in_bytes(RetData::bci_offset(row)), return_bci, next_test, scratch1);
       
  1458 
       
  1459       // return_bci is equal to bci[n]. Increment the count.
       
  1460       increment_mdp_data_at(in_bytes(RetData::bci_count_offset(row)), scratch1, scratch2);
       
  1461 
       
  1462       // The method data pointer needs to be updated to reflect the new target.
       
  1463       update_mdp_by_offset(in_bytes(RetData::bci_displacement_offset(row)), scratch1);
       
  1464       b(profile_continue);
       
  1465       bind(next_test);
       
  1466     }
       
  1467 
       
  1468     update_mdp_for_ret(state, return_bci);
       
  1469 
       
  1470     bind (profile_continue);
       
  1471   }
       
  1472 }
       
  1473 
       
  1474 // Count the default case of a switch construct.
       
  1475 void InterpreterMacroAssembler::profile_switch_default(Register scratch1,  Register scratch2) {
       
  1476   if (ProfileInterpreter) {
       
  1477     Label profile_continue;
       
  1478 
       
  1479     // If no method data exists, go to profile_continue.
       
  1480     test_method_data_pointer(profile_continue);
       
  1481 
       
  1482     // Update the default case count
       
  1483     increment_mdp_data_at(in_bytes(MultiBranchData::default_count_offset()),
       
  1484                           scratch1, scratch2);
       
  1485 
       
  1486     // The method data pointer needs to be updated.
       
  1487     update_mdp_by_offset(in_bytes(MultiBranchData::default_displacement_offset()),
       
  1488                          scratch1);
       
  1489 
       
  1490     bind (profile_continue);
       
  1491   }
       
  1492 }
       
  1493 
       
  1494 // Count the index'th case of a switch construct.
       
  1495 void InterpreterMacroAssembler::profile_switch_case(Register index,
       
  1496                                                     Register scratch1,
       
  1497                                                     Register scratch2,
       
  1498                                                     Register scratch3) {
       
  1499   if (ProfileInterpreter) {
       
  1500     assert_different_registers(index, scratch1, scratch2, scratch3);
       
  1501     Label profile_continue;
       
  1502 
       
  1503     // If no method data exists, go to profile_continue.
       
  1504     test_method_data_pointer(profile_continue);
       
  1505 
       
  1506     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes().
       
  1507     li(scratch3, in_bytes(MultiBranchData::case_array_offset()));
       
  1508 
       
  1509     assert (in_bytes(MultiBranchData::per_case_size()) == 16, "so that shladd works");
       
  1510     sldi(scratch1, index, exact_log2(in_bytes(MultiBranchData::per_case_size())));
       
  1511     add(scratch1, scratch1, scratch3);
       
  1512 
       
  1513     // Update the case count.
       
  1514     increment_mdp_data_at(scratch1, in_bytes(MultiBranchData::relative_count_offset()), scratch2, scratch3);
       
  1515 
       
  1516     // The method data pointer needs to be updated.
       
  1517     update_mdp_by_offset(scratch1, in_bytes(MultiBranchData::relative_displacement_offset()), scratch2);
       
  1518 
       
  1519     bind (profile_continue);
       
  1520   }
       
  1521 }
       
  1522 
       
  1523 void InterpreterMacroAssembler::profile_null_seen(Register Rscratch1, Register Rscratch2) {
       
  1524   if (ProfileInterpreter) {
       
  1525     assert_different_registers(Rscratch1, Rscratch2);
       
  1526     Label profile_continue;
       
  1527 
       
  1528     // If no method data exists, go to profile_continue.
       
  1529     test_method_data_pointer(profile_continue);
       
  1530 
       
  1531     set_mdp_flag_at(BitData::null_seen_byte_constant(), Rscratch1);
       
  1532 
       
  1533     // The method data pointer needs to be updated.
       
  1534     int mdp_delta = in_bytes(BitData::bit_data_size());
       
  1535     if (TypeProfileCasts) {
       
  1536       mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size());
       
  1537     }
       
  1538     update_mdp_by_constant(mdp_delta);
       
  1539 
       
  1540     bind (profile_continue);
       
  1541   }
       
  1542 }
       
  1543 
       
  1544 void InterpreterMacroAssembler::record_klass_in_profile(Register Rreceiver,
       
  1545                                                         Register Rscratch1, Register Rscratch2,
       
  1546                                                         bool is_virtual_call) {
       
  1547   assert(ProfileInterpreter, "must be profiling");
       
  1548   assert_different_registers(Rreceiver, Rscratch1, Rscratch2);
       
  1549 
       
  1550   Label done;
       
  1551   record_klass_in_profile_helper(Rreceiver, Rscratch1, Rscratch2, 0, done, is_virtual_call);
       
  1552   bind (done);
       
  1553 }
       
  1554 
       
  1555 void InterpreterMacroAssembler::record_klass_in_profile_helper(
       
  1556                                         Register receiver, Register scratch1, Register scratch2,
       
  1557                                         int start_row, Label& done, bool is_virtual_call) {
       
  1558   if (TypeProfileWidth == 0) {
       
  1559     if (is_virtual_call) {
       
  1560       increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
       
  1561     }
       
  1562     return;
       
  1563   }
       
  1564 
       
  1565   int last_row = VirtualCallData::row_limit() - 1;
       
  1566   assert(start_row <= last_row, "must be work left to do");
       
  1567   // Test this row for both the receiver and for null.
       
  1568   // Take any of three different outcomes:
       
  1569   //   1. found receiver => increment count and goto done
       
  1570   //   2. found null => keep looking for case 1, maybe allocate this cell
       
  1571   //   3. found something else => keep looking for cases 1 and 2
       
  1572   // Case 3 is handled by a recursive call.
       
  1573   for (int row = start_row; row <= last_row; row++) {
       
  1574     Label next_test;
       
  1575     bool test_for_null_also = (row == start_row);
       
  1576 
       
  1577     // See if the receiver is receiver[n].
       
  1578     int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row));
       
  1579     test_mdp_data_at(recvr_offset, receiver, next_test, scratch1);
       
  1580     // delayed()->tst(scratch);
       
  1581 
       
  1582     // The receiver is receiver[n]. Increment count[n].
       
  1583     int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row));
       
  1584     increment_mdp_data_at(count_offset, scratch1, scratch2);
       
  1585     b(done);
       
  1586     bind(next_test);
       
  1587 
       
  1588     if (test_for_null_also) {
       
  1589       Label found_null;
       
  1590       // Failed the equality check on receiver[n]... Test for null.
       
  1591       if (start_row == last_row) {
       
  1592         // The only thing left to do is handle the null case.
       
  1593         if (is_virtual_call) {
       
  1594           // Scratch1 contains test_out from test_mdp_data_at.
       
  1595           cmpdi(CCR0, scratch1, 0);
       
  1596           beq(CCR0, found_null);
       
  1597           // Receiver did not match any saved receiver and there is no empty row for it.
       
  1598           // Increment total counter to indicate polymorphic case.
       
  1599           increment_mdp_data_at(in_bytes(CounterData::count_offset()), scratch1, scratch2);
       
  1600           b(done);
       
  1601           bind(found_null);
       
  1602         } else {
       
  1603           cmpdi(CCR0, scratch1, 0);
       
  1604           bne(CCR0, done);
       
  1605         }
       
  1606         break;
       
  1607       }
       
  1608       // Since null is rare, make it be the branch-taken case.
       
  1609       cmpdi(CCR0, scratch1, 0);
       
  1610       beq(CCR0, found_null);
       
  1611 
       
  1612       // Put all the "Case 3" tests here.
       
  1613       record_klass_in_profile_helper(receiver, scratch1, scratch2, start_row + 1, done, is_virtual_call);
       
  1614 
       
  1615       // Found a null. Keep searching for a matching receiver,
       
  1616       // but remember that this is an empty (unused) slot.
       
  1617       bind(found_null);
       
  1618     }
       
  1619   }
       
  1620 
       
  1621   // In the fall-through case, we found no matching receiver, but we
       
  1622   // observed the receiver[start_row] is NULL.
       
  1623 
       
  1624   // Fill in the receiver field and increment the count.
       
  1625   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
       
  1626   set_mdp_data_at(recvr_offset, receiver);
       
  1627   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
       
  1628   li(scratch1, DataLayout::counter_increment);
       
  1629   set_mdp_data_at(count_offset, scratch1);
       
  1630   if (start_row > 0) {
       
  1631     b(done);
       
  1632   }
       
  1633 }
       
  1634 
       
  1635 // Add a InterpMonitorElem to stack (see frame_sparc.hpp).
       
  1636 void InterpreterMacroAssembler::add_monitor_to_stack(bool stack_is_empty, Register Rtemp1, Register Rtemp2) {
       
  1637 
       
  1638   // Very-local scratch registers.
       
  1639   const Register esp  = Rtemp1;
       
  1640   const Register slot = Rtemp2;
       
  1641 
       
  1642   // Extracted monitor_size.
       
  1643   int monitor_size = frame::interpreter_frame_monitor_size_in_bytes();
       
  1644   assert(Assembler::is_aligned((unsigned int)monitor_size,
       
  1645                                (unsigned int)frame::alignment_in_bytes),
       
  1646          "size of a monitor must respect alignment of SP");
       
  1647 
       
  1648   resize_frame(-monitor_size, /*temp*/esp); // Allocate space for new monitor
       
  1649   std(R1_SP, _ijava_state_neg(top_frame_sp), esp); // esp contains fp
       
  1650 
       
  1651   // Shuffle expression stack down. Recall that stack_base points
       
  1652   // just above the new expression stack bottom. Old_tos and new_tos
       
  1653   // are used to scan thru the old and new expression stacks.
       
  1654   if (!stack_is_empty) {
       
  1655     Label copy_slot, copy_slot_finished;
       
  1656     const Register n_slots = slot;
       
  1657 
       
  1658     addi(esp, R15_esp, Interpreter::stackElementSize); // Point to first element (pre-pushed stack).
       
  1659     subf(n_slots, esp, R26_monitor);
       
  1660     srdi_(n_slots, n_slots, LogBytesPerWord);          // Compute number of slots to copy.
       
  1661     assert(LogBytesPerWord == 3, "conflicts assembler instructions");
       
  1662     beq(CCR0, copy_slot_finished);                     // Nothing to copy.
       
  1663 
       
  1664     mtctr(n_slots);
       
  1665 
       
  1666     // loop
       
  1667     bind(copy_slot);
       
  1668     ld(slot, 0, esp);              // Move expression stack down.
       
  1669     std(slot, -monitor_size, esp); // distance = monitor_size
       
  1670     addi(esp, esp, BytesPerWord);
       
  1671     bdnz(copy_slot);
       
  1672 
       
  1673     bind(copy_slot_finished);
       
  1674   }
       
  1675 
       
  1676   addi(R15_esp, R15_esp, -monitor_size);
       
  1677   addi(R26_monitor, R26_monitor, -monitor_size);
       
  1678 
       
  1679   // Restart interpreter
       
  1680 }
       
  1681 
       
  1682 // ============================================================================
       
  1683 // Java locals access
       
  1684 
       
  1685 // Load a local variable at index in Rindex into register Rdst_value.
       
  1686 // Also puts address of local into Rdst_address as a service.
       
  1687 // Kills:
       
  1688 //   - Rdst_value
       
  1689 //   - Rdst_address
       
  1690 void InterpreterMacroAssembler::load_local_int(Register Rdst_value, Register Rdst_address, Register Rindex) {
       
  1691   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
       
  1692   subf(Rdst_address, Rdst_address, R18_locals);
       
  1693   lwz(Rdst_value, 0, Rdst_address);
       
  1694 }
       
  1695 
       
  1696 // Load a local variable at index in Rindex into register Rdst_value.
       
  1697 // Also puts address of local into Rdst_address as a service.
       
  1698 // Kills:
       
  1699 //   - Rdst_value
       
  1700 //   - Rdst_address
       
  1701 void InterpreterMacroAssembler::load_local_long(Register Rdst_value, Register Rdst_address, Register Rindex) {
       
  1702   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
       
  1703   subf(Rdst_address, Rdst_address, R18_locals);
       
  1704   ld(Rdst_value, -8, Rdst_address);
       
  1705 }
       
  1706 
       
  1707 // Load a local variable at index in Rindex into register Rdst_value.
       
  1708 // Also puts address of local into Rdst_address as a service.
       
  1709 // Input:
       
  1710 //   - Rindex:      slot nr of local variable
       
  1711 // Kills:
       
  1712 //   - Rdst_value
       
  1713 //   - Rdst_address
       
  1714 void InterpreterMacroAssembler::load_local_ptr(Register Rdst_value, Register Rdst_address, Register Rindex) {
       
  1715   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
       
  1716   subf(Rdst_address, Rdst_address, R18_locals);
       
  1717   ld(Rdst_value, 0, Rdst_address);
       
  1718 }
       
  1719 
       
  1720 // Load a local variable at index in Rindex into register Rdst_value.
       
  1721 // Also puts address of local into Rdst_address as a service.
       
  1722 // Kills:
       
  1723 //   - Rdst_value
       
  1724 //   - Rdst_address
       
  1725 void InterpreterMacroAssembler::load_local_float(FloatRegister Rdst_value, Register Rdst_address, Register Rindex) {
       
  1726   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
       
  1727   subf(Rdst_address, Rdst_address, R18_locals);
       
  1728   lfs(Rdst_value, 0, Rdst_address);
       
  1729 }
       
  1730 
       
  1731 // Load a local variable at index in Rindex into register Rdst_value.
       
  1732 // Also puts address of local into Rdst_address as a service.
       
  1733 // Kills:
       
  1734 //   - Rdst_value
       
  1735 //   - Rdst_address
       
  1736 void InterpreterMacroAssembler::load_local_double(FloatRegister Rdst_value, Register Rdst_address, Register Rindex) {
       
  1737   sldi(Rdst_address, Rindex, Interpreter::logStackElementSize);
       
  1738   subf(Rdst_address, Rdst_address, R18_locals);
       
  1739   lfd(Rdst_value, -8, Rdst_address);
       
  1740 }
       
  1741 
       
  1742 // Store an int value at local variable slot Rindex.
       
  1743 // Kills:
       
  1744 //   - Rindex
       
  1745 void InterpreterMacroAssembler::store_local_int(Register Rvalue, Register Rindex) {
       
  1746   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
       
  1747   subf(Rindex, Rindex, R18_locals);
       
  1748   stw(Rvalue, 0, Rindex);
       
  1749 }
       
  1750 
       
  1751 // Store a long value at local variable slot Rindex.
       
  1752 // Kills:
       
  1753 //   - Rindex
       
  1754 void InterpreterMacroAssembler::store_local_long(Register Rvalue, Register Rindex) {
       
  1755   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
       
  1756   subf(Rindex, Rindex, R18_locals);
       
  1757   std(Rvalue, -8, Rindex);
       
  1758 }
       
  1759 
       
  1760 // Store an oop value at local variable slot Rindex.
       
  1761 // Kills:
       
  1762 //   - Rindex
       
  1763 void InterpreterMacroAssembler::store_local_ptr(Register Rvalue, Register Rindex) {
       
  1764   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
       
  1765   subf(Rindex, Rindex, R18_locals);
       
  1766   std(Rvalue, 0, Rindex);
       
  1767 }
       
  1768 
       
  1769 // Store an int value at local variable slot Rindex.
       
  1770 // Kills:
       
  1771 //   - Rindex
       
  1772 void InterpreterMacroAssembler::store_local_float(FloatRegister Rvalue, Register Rindex) {
       
  1773   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
       
  1774   subf(Rindex, Rindex, R18_locals);
       
  1775   stfs(Rvalue, 0, Rindex);
       
  1776 }
       
  1777 
       
  1778 // Store an int value at local variable slot Rindex.
       
  1779 // Kills:
       
  1780 //   - Rindex
       
  1781 void InterpreterMacroAssembler::store_local_double(FloatRegister Rvalue, Register Rindex) {
       
  1782   sldi(Rindex, Rindex, Interpreter::logStackElementSize);
       
  1783   subf(Rindex, Rindex, R18_locals);
       
  1784   stfd(Rvalue, -8, Rindex);
       
  1785 }
       
  1786 
       
  1787 // Read pending exception from thread and jump to interpreter.
       
  1788 // Throw exception entry if one if pending. Fall through otherwise.
       
  1789 void InterpreterMacroAssembler::check_and_forward_exception(Register Rscratch1, Register Rscratch2) {
       
  1790   assert_different_registers(Rscratch1, Rscratch2, R3);
       
  1791   Register Rexception = Rscratch1;
       
  1792   Register Rtmp       = Rscratch2;
       
  1793   Label Ldone;
       
  1794   // Get pending exception oop.
       
  1795   ld(Rexception, thread_(pending_exception));
       
  1796   cmpdi(CCR0, Rexception, 0);
       
  1797   beq(CCR0, Ldone);
       
  1798   li(Rtmp, 0);
       
  1799   mr_if_needed(R3, Rexception);
       
  1800   std(Rtmp, thread_(pending_exception)); // Clear exception in thread
       
  1801   if (Interpreter::rethrow_exception_entry() != NULL) {
       
  1802     // Already got entry address.
       
  1803     load_dispatch_table(Rtmp, (address*)Interpreter::rethrow_exception_entry());
       
  1804   } else {
       
  1805     // Dynamically load entry address.
       
  1806     int simm16_rest = load_const_optimized(Rtmp, &Interpreter::_rethrow_exception_entry, R0, true);
       
  1807     ld(Rtmp, simm16_rest, Rtmp);
       
  1808   }
       
  1809   mtctr(Rtmp);
       
  1810   save_interpreter_state(Rtmp);
       
  1811   bctr();
       
  1812 
       
  1813   align(32, 12);
       
  1814   bind(Ldone);
       
  1815 }
       
  1816 
       
  1817 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, bool check_exceptions) {
       
  1818   save_interpreter_state(R11_scratch1);
       
  1819 
       
  1820   MacroAssembler::call_VM(oop_result, entry_point, false);
       
  1821 
       
  1822   restore_interpreter_state(R11_scratch1, /*bcp_and_mdx_only*/ true);
       
  1823 
       
  1824   check_and_handle_popframe(R11_scratch1);
       
  1825   check_and_handle_earlyret(R11_scratch1);
       
  1826   // Now check exceptions manually.
       
  1827   if (check_exceptions) {
       
  1828     check_and_forward_exception(R11_scratch1, R12_scratch2);
       
  1829   }
       
  1830 }
       
  1831 
       
  1832 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, bool check_exceptions) {
       
  1833   // ARG1 is reserved for the thread.
       
  1834   mr_if_needed(R4_ARG2, arg_1);
       
  1835   call_VM(oop_result, entry_point, check_exceptions);
       
  1836 }
       
  1837 
       
  1838 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, bool check_exceptions) {
       
  1839   // ARG1 is reserved for the thread.
       
  1840   mr_if_needed(R4_ARG2, arg_1);
       
  1841   assert(arg_2 != R4_ARG2, "smashed argument");
       
  1842   mr_if_needed(R5_ARG3, arg_2);
       
  1843   call_VM(oop_result, entry_point, check_exceptions);
       
  1844 }
       
  1845 
       
  1846 void InterpreterMacroAssembler::call_VM(Register oop_result, address entry_point, Register arg_1, Register arg_2, Register arg_3, bool check_exceptions) {
       
  1847   // ARG1 is reserved for the thread.
       
  1848   mr_if_needed(R4_ARG2, arg_1);
       
  1849   assert(arg_2 != R4_ARG2, "smashed argument");
       
  1850   mr_if_needed(R5_ARG3, arg_2);
       
  1851   assert(arg_3 != R4_ARG2 && arg_3 != R5_ARG3, "smashed argument");
       
  1852   mr_if_needed(R6_ARG4, arg_3);
       
  1853   call_VM(oop_result, entry_point, check_exceptions);
       
  1854 }
       
  1855 
       
  1856 void InterpreterMacroAssembler::save_interpreter_state(Register scratch) {
       
  1857   ld(scratch, 0, R1_SP);
       
  1858   std(R15_esp, _ijava_state_neg(esp), scratch);
       
  1859   std(R14_bcp, _ijava_state_neg(bcp), scratch);
       
  1860   std(R26_monitor, _ijava_state_neg(monitors), scratch);
       
  1861   if (ProfileInterpreter) { std(R28_mdx, _ijava_state_neg(mdx), scratch); }
       
  1862   // Other entries should be unchanged.
       
  1863 }
       
  1864 
       
  1865 void InterpreterMacroAssembler::restore_interpreter_state(Register scratch, bool bcp_and_mdx_only) {
       
  1866   ld(scratch, 0, R1_SP);
       
  1867   ld(R14_bcp, _ijava_state_neg(bcp), scratch); // Changed by VM code (exception).
       
  1868   if (ProfileInterpreter) { ld(R28_mdx, _ijava_state_neg(mdx), scratch); } // Changed by VM code.
       
  1869   if (!bcp_and_mdx_only) {
       
  1870     // Following ones are Metadata.
       
  1871     ld(R19_method, _ijava_state_neg(method), scratch);
       
  1872     ld(R27_constPoolCache, _ijava_state_neg(cpoolCache), scratch);
       
  1873     // Following ones are stack addresses and don't require reload.
       
  1874     ld(R15_esp, _ijava_state_neg(esp), scratch);
       
  1875     ld(R18_locals, _ijava_state_neg(locals), scratch);
       
  1876     ld(R26_monitor, _ijava_state_neg(monitors), scratch);
       
  1877   }
       
  1878 #ifdef ASSERT
       
  1879   {
       
  1880     Label Lok;
       
  1881     subf(R0, R1_SP, scratch);
       
  1882     cmpdi(CCR0, R0, frame::abi_reg_args_size + frame::ijava_state_size);
       
  1883     bge(CCR0, Lok);
       
  1884     stop("frame too small (restore istate)", 0x5432);
       
  1885     bind(Lok);
       
  1886   }
       
  1887   {
       
  1888     Label Lok;
       
  1889     ld(R0, _ijava_state_neg(ijava_reserved), scratch);
       
  1890     cmpdi(CCR0, R0, 0x5afe);
       
  1891     beq(CCR0, Lok);
       
  1892     stop("frame corrupted (restore istate)", 0x5afe);
       
  1893     bind(Lok);
       
  1894   }
       
  1895 #endif
       
  1896 }
       
  1897 
       
  1898 #endif // !CC_INTERP
   263 
  1899 
   264 void InterpreterMacroAssembler::get_method_counters(Register method,
  1900 void InterpreterMacroAssembler::get_method_counters(Register method,
   265                                                     Register Rcounters,
  1901                                                     Register Rcounters,
   266                                                     Label& skip) {
  1902                                                     Label& skip) {
   267   BLOCK_COMMENT("Load and ev. allocate counter object {");
  1903   BLOCK_COMMENT("Load and ev. allocate counter object {");
   318 }
  1954 }
   319 
  1955 
   320 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
  1956 void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) {
   321   if (state == atos) { MacroAssembler::verify_oop(reg); }
  1957   if (state == atos) { MacroAssembler::verify_oop(reg); }
   322 }
  1958 }
       
  1959 
       
  1960 #ifndef CC_INTERP
       
  1961 // Local helper function for the verify_oop_or_return_address macro.
       
  1962 static bool verify_return_address(Method* m, int bci) {
       
  1963 #ifndef PRODUCT
       
  1964   address pc = (address)(m->constMethod()) + in_bytes(ConstMethod::codes_offset()) + bci;
       
  1965   // Assume it is a valid return address if it is inside m and is preceded by a jsr.
       
  1966   if (!m->contains(pc))                                            return false;
       
  1967   address jsr_pc;
       
  1968   jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr);
       
  1969   if (*jsr_pc == Bytecodes::_jsr   && jsr_pc >= m->code_base())    return true;
       
  1970   jsr_pc = pc - Bytecodes::length_for(Bytecodes::_jsr_w);
       
  1971   if (*jsr_pc == Bytecodes::_jsr_w && jsr_pc >= m->code_base())    return true;
       
  1972 #endif // PRODUCT
       
  1973   return false;
       
  1974 }
       
  1975 
       
  1976 void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) {
       
  1977   if (VerifyFPU) {
       
  1978     unimplemented("verfiyFPU");
       
  1979   }
       
  1980 }
       
  1981 
       
  1982 void InterpreterMacroAssembler::verify_oop_or_return_address(Register reg, Register Rtmp) {
       
  1983   if (!VerifyOops) return;
       
  1984 
       
  1985   // The VM documentation for the astore[_wide] bytecode allows
       
  1986   // the TOS to be not only an oop but also a return address.
       
  1987   Label test;
       
  1988   Label skip;
       
  1989   // See if it is an address (in the current method):
       
  1990 
       
  1991   const int log2_bytecode_size_limit = 16;
       
  1992   srdi_(Rtmp, reg, log2_bytecode_size_limit);
       
  1993   bne(CCR0, test);
       
  1994 
       
  1995   address fd = CAST_FROM_FN_PTR(address, verify_return_address);
       
  1996   unsigned int nbytes_save = 10*8; // 10 volatile gprs
       
  1997 
       
  1998   save_LR_CR(Rtmp);
       
  1999   push_frame_reg_args(nbytes_save, Rtmp);
       
  2000   save_volatile_gprs(R1_SP, 112); // except R0
       
  2001 
       
  2002   load_const_optimized(Rtmp, fd, R0);
       
  2003   mr_if_needed(R4_ARG2, reg);
       
  2004   mr(R3_ARG1, R19_method);
       
  2005   call_c(Rtmp); // call C
       
  2006 
       
  2007   restore_volatile_gprs(R1_SP, 112); // except R0
       
  2008   pop_frame();
       
  2009   restore_LR_CR(Rtmp);
       
  2010   b(skip);
       
  2011 
       
  2012   // Perform a more elaborate out-of-line call.
       
  2013   // Not an address; verify it:
       
  2014   bind(test);
       
  2015   verify_oop(reg);
       
  2016   bind(skip);
       
  2017 }
       
  2018 #endif // !CC_INTERP
   323 
  2019 
   324 // Inline assembly for:
  2020 // Inline assembly for:
   325 //
  2021 //
   326 // if (thread is in interp_only_mode) {
  2022 // if (thread is in interp_only_mode) {
   327 //   InterpreterRuntime::post_method_entry();
  2023 //   InterpreterRuntime::post_method_entry();
   341 
  2037 
   342     lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
  2038     lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
   343     cmpwi(CCR0, R0, 0);
  2039     cmpwi(CCR0, R0, 0);
   344     beq(CCR0, jvmti_post_done);
  2040     beq(CCR0, jvmti_post_done);
   345     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry),
  2041     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_entry),
   346             /*check_exceptions=*/false);
  2042             /*check_exceptions=*/true CC_INTERP_ONLY(&& false));
   347 
  2043 
   348     bind(jvmti_post_done);
  2044     bind(jvmti_post_done);
   349   }
  2045   }
   350 }
  2046 }
   351 
       
   352 
  2047 
   353 // Inline assembly for:
  2048 // Inline assembly for:
   354 //
  2049 //
   355 // if (thread is in interp_only_mode) {
  2050 // if (thread is in interp_only_mode) {
   356 //   // save result
  2051 //   // save result
   363 //   // restore result
  2058 //   // restore result
   364 // }
  2059 // }
   365 //
  2060 //
   366 // Native methods have their result stored in d_tmp and l_tmp.
  2061 // Native methods have their result stored in d_tmp and l_tmp.
   367 // Java methods have their result stored in the expression stack.
  2062 // Java methods have their result stored in the expression stack.
   368 void InterpreterMacroAssembler::notify_method_exit(bool is_native_method, TosState state) {
  2063 void InterpreterMacroAssembler::notify_method_exit(bool is_native_method, TosState state,
       
  2064                                                    NotifyMethodExitMode mode, bool check_exceptions) {
   369   // JVMTI
  2065   // JVMTI
   370   // Whenever JVMTI puts a thread in interp_only_mode, method
  2066   // Whenever JVMTI puts a thread in interp_only_mode, method
   371   // entry/exit events are sent for that thread to track stack
  2067   // entry/exit events are sent for that thread to track stack
   372   // depth. If it is possible to enter interp_only_mode we add
  2068   // depth. If it is possible to enter interp_only_mode we add
   373   // the code to check if the event should be sent.
  2069   // the code to check if the event should be sent.
   374   if (JvmtiExport::can_post_interpreter_events()) {
  2070   if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) {
   375     Label jvmti_post_done;
  2071     Label jvmti_post_done;
   376 
  2072 
   377     lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
  2073     lwz(R0, in_bytes(JavaThread::interp_only_mode_offset()), R16_thread);
   378     cmpwi(CCR0, R0, 0);
  2074     cmpwi(CCR0, R0, 0);
   379     beq(CCR0, jvmti_post_done);
  2075     beq(CCR0, jvmti_post_done);
       
  2076     CC_INTERP_ONLY(assert(is_native_method && !check_exceptions, "must not push state"));
       
  2077     if (!is_native_method) push(state); // Expose tos to GC.
   380     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit),
  2078     call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit),
   381             /*check_exceptions=*/false);
  2079             /*check_exceptions=*/check_exceptions);
       
  2080     if (!is_native_method) pop(state);
   382 
  2081 
   383     align(32, 12);
  2082     align(32, 12);
   384     bind(jvmti_post_done);
  2083     bind(jvmti_post_done);
   385   }
  2084   }
   386 }
  2085 
   387 
  2086   // Dtrace support not implemented.
       
  2087 }
       
  2088 
       
  2089 #ifdef CC_INTERP
   388 // Convert the current TOP_IJAVA_FRAME into a PARENT_IJAVA_FRAME
  2090 // Convert the current TOP_IJAVA_FRAME into a PARENT_IJAVA_FRAME
   389 // (using parent_frame_resize) and push a new interpreter
  2091 // (using parent_frame_resize) and push a new interpreter
   390 // TOP_IJAVA_FRAME (using frame_size).
  2092 // TOP_IJAVA_FRAME (using frame_size).
   391 void InterpreterMacroAssembler::push_interpreter_frame(Register top_frame_size, Register parent_frame_resize,
  2093 void InterpreterMacroAssembler::push_interpreter_frame(Register top_frame_size, Register parent_frame_resize,
   392                                                        Register tmp1, Register tmp2, Register tmp3,
  2094                                                        Register tmp1, Register tmp2, Register tmp3,
   440 
  2142 
   441   // Store the top-frame stack-pointer for c2i adapters.
  2143   // Store the top-frame stack-pointer for c2i adapters.
   442   std(R1_SP, _top_ijava_frame_abi(top_frame_sp), R1_SP);
  2144   std(R1_SP, _top_ijava_frame_abi(top_frame_sp), R1_SP);
   443 }
  2145 }
   444 
  2146 
   445 #ifdef CC_INTERP
       
   446 // Turn state's interpreter frame into the current TOP_IJAVA_FRAME.
  2147 // Turn state's interpreter frame into the current TOP_IJAVA_FRAME.
   447 void InterpreterMacroAssembler::pop_interpreter_frame_to_state(Register state, Register tmp1, Register tmp2, Register tmp3) {
  2148 void InterpreterMacroAssembler::pop_interpreter_frame_to_state(Register state, Register tmp1, Register tmp2, Register tmp3) {
   448   assert_different_registers(R14_state, R15_prev_state, tmp1, tmp2, tmp3);
  2149   assert_different_registers(R14_state, R15_prev_state, tmp1, tmp2, tmp3);
   449 
  2150 
   450   if (state == R14_state) {
  2151   if (state == R14_state) {
   469   get_PC_trash_LR(tmp3);
  2170   get_PC_trash_LR(tmp3);
   470   std(tmp3, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
  2171   std(tmp3, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
   471   // Used for non-initial callers by unextended_sp().
  2172   // Used for non-initial callers by unextended_sp().
   472   std(R1_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);
  2173   std(R1_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);
   473 }
  2174 }
   474 #endif // CC_INTERP
       
   475 
  2175 
   476 // Set SP to initial caller's sp, but before fix the back chain.
  2176 // Set SP to initial caller's sp, but before fix the back chain.
   477 void InterpreterMacroAssembler::resize_frame_to_initial_caller(Register tmp1, Register tmp2) {
  2177 void InterpreterMacroAssembler::resize_frame_to_initial_caller(Register tmp1, Register tmp2) {
   478   ld(tmp1, _parent_ijava_frame_abi(initial_caller_sp), R1_SP);
  2178   ld(tmp1, _parent_ijava_frame_abi(initial_caller_sp), R1_SP);
   479   ld(tmp2, _parent_ijava_frame_abi(callers_sp), R1_SP);
  2179   ld(tmp2, _parent_ijava_frame_abi(callers_sp), R1_SP);
   480   std(tmp2, _parent_ijava_frame_abi(callers_sp), tmp1); // Fix back chain ...
  2180   std(tmp2, _parent_ijava_frame_abi(callers_sp), tmp1); // Fix back chain ...
   481   mr(R1_SP, tmp1); // ... and resize to initial caller.
  2181   mr(R1_SP, tmp1); // ... and resize to initial caller.
   482 }
  2182 }
   483 
  2183 
   484 #ifdef CC_INTERP
       
   485 // Pop the current interpreter state (without popping the correspoding
  2184 // Pop the current interpreter state (without popping the correspoding
   486 // frame) and restore R14_state and R15_prev_state accordingly.
  2185 // frame) and restore R14_state and R15_prev_state accordingly.
   487 // Use prev_state_may_be_0 to indicate whether prev_state may be 0
  2186 // Use prev_state_may_be_0 to indicate whether prev_state may be 0
   488 // in order to generate an extra check before retrieving prev_state_(_prev_link).
  2187 // in order to generate an extra check before retrieving prev_state_(_prev_link).
   489 void InterpreterMacroAssembler::pop_interpreter_state(bool prev_state_may_be_0)
  2188 void InterpreterMacroAssembler::pop_interpreter_state(bool prev_state_may_be_0)