1 /*
   2  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * Copyright 2012, 2014 SAP AG. All rights reserved.
   4  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   5  *
   6  * This code is free software; you can redistribute it and/or modify it
   7  * under the terms of the GNU General Public License version 2 only, as
   8  * published by the Free Software Foundation.
   9  *
  10  * This code is distributed in the hope that it will be useful, but WITHOUT
  11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  13  * version 2 for more details (a copy is included in the LICENSE file that
  14  * accompanied this code).
  15  *
  16  * You should have received a copy of the GNU General Public License version
  17  * 2 along with this work; if not, write to the Free Software Foundation,
  18  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  19  *
  20  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  21  * or visit www.oracle.com if you need additional information or have any
  22  * questions.
  23  *
  24  */
  25 
  26 #include "precompiled.hpp"
  27 #include "asm/assembler.hpp"
  28 #include "asm/macroAssembler.inline.hpp"
  29 #include "interpreter/bytecodeHistogram.hpp"
  30 #include "interpreter/interpreter.hpp"
  31 #include "interpreter/interpreterGenerator.hpp"
  32 #include "interpreter/interpreterRuntime.hpp"
  33 #include "interpreter/templateTable.hpp"
  34 #include "oops/arrayOop.hpp"
  35 #include "oops/methodData.hpp"
  36 #include "oops/method.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "prims/jvmtiExport.hpp"
  39 #include "prims/jvmtiThreadState.hpp"
  40 #include "prims/methodHandles.hpp"
  41 #include "runtime/arguments.hpp"
  42 #include "runtime/deoptimization.hpp"
  43 #include "runtime/frame.inline.hpp"
  44 #include "runtime/sharedRuntime.hpp"
  45 #include "runtime/stubRoutines.hpp"
  46 #include "runtime/synchronizer.hpp"
  47 #include "runtime/timer.hpp"
  48 #include "runtime/vframeArray.hpp"
  49 #include "utilities/debug.hpp"
  50 #ifdef COMPILER1
  51 #include "c1/c1_Runtime1.hpp"
  52 #endif
  53 
  54 #define __ _masm->
  55 
  56 #ifdef PRODUCT
  57 #define BLOCK_COMMENT(str) // nothing
  58 #else
  59 #define BLOCK_COMMENT(str) __ block_comment(str)
  60 #endif
  61 
  62 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
  63 
  64 int AbstractInterpreter::BasicType_as_index(BasicType type) {
  65   int i = 0;
  66   switch (type) {
  67     case T_BOOLEAN: i = 0; break;
  68     case T_CHAR   : i = 1; break;
  69     case T_BYTE   : i = 2; break;
  70     case T_SHORT  : i = 3; break;
  71     case T_INT    : i = 4; break;
  72     case T_LONG   : i = 5; break;
  73     case T_VOID   : i = 6; break;
  74     case T_FLOAT  : i = 7; break;
  75     case T_DOUBLE : i = 8; break;
  76     case T_OBJECT : i = 9; break;
  77     case T_ARRAY  : i = 9; break;
  78     default       : ShouldNotReachHere();
  79   }
  80   assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
  81   return i;
  82 }
  83 
  84 address AbstractInterpreterGenerator::generate_slow_signature_handler() {
  85   // Slow_signature handler that respects the PPC C calling conventions.
  86   //
  87   // We get called by the native entry code with our output register
  88   // area == 8. First we call InterpreterRuntime::get_result_handler
  89   // to copy the pointer to the signature string temporarily to the
  90   // first C-argument and to return the result_handler in
  91   // R3_RET. Since native_entry will copy the jni-pointer to the
  92   // first C-argument slot later on, it is OK to occupy this slot
  93   // temporarilly. Then we copy the argument list on the java
  94   // expression stack into native varargs format on the native stack
  95   // and load arguments into argument registers. Integer arguments in
  96   // the varargs vector will be sign-extended to 8 bytes.
  97   //
  98   // On entry:
  99   //   R3_ARG1        - intptr_t*     Address of java argument list in memory.
 100   //   R15_prev_state - BytecodeInterpreter* Address of interpreter state for
 101   //     this method
 102   //   R19_method
 103   //
 104   // On exit (just before return instruction):
 105   //   R3_RET            - contains the address of the result_handler.
 106   //   R4_ARG2           - is not updated for static methods and contains "this" otherwise.
 107   //   R5_ARG3-R10_ARG8: - When the (i-2)th Java argument is not of type float or double,
 108   //                       ARGi contains this argument. Otherwise, ARGi is not updated.
 109   //   F1_ARG1-F13_ARG13 - contain the first 13 arguments of type float or double.
 110 
 111   const int LogSizeOfTwoInstructions = 3;
 112 
 113   // FIXME: use Argument:: GL: Argument names different numbers!
 114   const int max_fp_register_arguments  = 13;
 115   const int max_int_register_arguments = 6;  // first 2 are reserved
 116 
 117   const Register arg_java       = R21_tmp1;
 118   const Register arg_c          = R22_tmp2;
 119   const Register signature      = R23_tmp3;  // is string
 120   const Register sig_byte       = R24_tmp4;
 121   const Register fpcnt          = R25_tmp5;
 122   const Register argcnt         = R26_tmp6;
 123   const Register intSlot        = R27_tmp7;
 124   const Register target_sp      = R28_tmp8;
 125   const FloatRegister floatSlot = F0;
 126 
 127   address entry = __ function_entry();
 128 
 129   __ save_LR_CR(R0);
 130   __ save_nonvolatile_gprs(R1_SP, _spill_nonvolatiles_neg(r14));
 131   // We use target_sp for storing arguments in the C frame.
 132   __ mr(target_sp, R1_SP);
 133   __ push_frame_reg_args_nonvolatiles(0, R11_scratch1);
 134 
 135   __ mr(arg_java, R3_ARG1);
 136 
 137   __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_signature), R16_thread, R19_method);
 138 
 139   // Signature is in R3_RET. Signature is callee saved.
 140   __ mr(signature, R3_RET);
 141 
 142   // Get the result handler.
 143   __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::get_result_handler), R16_thread, R19_method);
 144 
 145   {
 146     Label L;
 147     // test if static
 148     // _access_flags._flags must be at offset 0.
 149     // TODO PPC port: requires change in shared code.
 150     //assert(in_bytes(AccessFlags::flags_offset()) == 0,
 151     //       "MethodDesc._access_flags == MethodDesc._access_flags._flags");
 152     // _access_flags must be a 32 bit value.
 153     assert(sizeof(AccessFlags) == 4, "wrong size");
 154     __ lwa(R11_scratch1/*access_flags*/, method_(access_flags));
 155     // testbit with condition register.
 156     __ testbitdi(CCR0, R0, R11_scratch1/*access_flags*/, JVM_ACC_STATIC_BIT);
 157     __ btrue(CCR0, L);
 158     // For non-static functions, pass "this" in R4_ARG2 and copy it
 159     // to 2nd C-arg slot.
 160     // We need to box the Java object here, so we use arg_java
 161     // (address of current Java stack slot) as argument and don't
 162     // dereference it as in case of ints, floats, etc.
 163     __ mr(R4_ARG2, arg_java);
 164     __ addi(arg_java, arg_java, -BytesPerWord);
 165     __ std(R4_ARG2, _abi(carg_2), target_sp);
 166     __ bind(L);
 167   }
 168 
 169   // Will be incremented directly after loop_start. argcnt=0
 170   // corresponds to 3rd C argument.
 171   __ li(argcnt, -1);
 172   // arg_c points to 3rd C argument
 173   __ addi(arg_c, target_sp, _abi(carg_3));
 174   // no floating-point args parsed so far
 175   __ li(fpcnt, 0);
 176 
 177   Label move_intSlot_to_ARG, move_floatSlot_to_FARG;
 178   Label loop_start, loop_end;
 179   Label do_int, do_long, do_float, do_double, do_dontreachhere, do_object, do_array, do_boxed;
 180 
 181   // signature points to '(' at entry
 182 #ifdef ASSERT
 183   __ lbz(sig_byte, 0, signature);
 184   __ cmplwi(CCR0, sig_byte, '(');
 185   __ bne(CCR0, do_dontreachhere);
 186 #endif
 187 
 188   __ bind(loop_start);
 189 
 190   __ addi(argcnt, argcnt, 1);
 191   __ lbzu(sig_byte, 1, signature);
 192 
 193   __ cmplwi(CCR0, sig_byte, ')'); // end of signature
 194   __ beq(CCR0, loop_end);
 195 
 196   __ cmplwi(CCR0, sig_byte, 'B'); // byte
 197   __ beq(CCR0, do_int);
 198 
 199   __ cmplwi(CCR0, sig_byte, 'C'); // char
 200   __ beq(CCR0, do_int);
 201 
 202   __ cmplwi(CCR0, sig_byte, 'D'); // double
 203   __ beq(CCR0, do_double);
 204 
 205   __ cmplwi(CCR0, sig_byte, 'F'); // float
 206   __ beq(CCR0, do_float);
 207 
 208   __ cmplwi(CCR0, sig_byte, 'I'); // int
 209   __ beq(CCR0, do_int);
 210 
 211   __ cmplwi(CCR0, sig_byte, 'J'); // long
 212   __ beq(CCR0, do_long);
 213 
 214   __ cmplwi(CCR0, sig_byte, 'S'); // short
 215   __ beq(CCR0, do_int);
 216 
 217   __ cmplwi(CCR0, sig_byte, 'Z'); // boolean
 218   __ beq(CCR0, do_int);
 219 
 220   __ cmplwi(CCR0, sig_byte, 'L'); // object
 221   __ beq(CCR0, do_object);
 222 
 223   __ cmplwi(CCR0, sig_byte, '['); // array
 224   __ beq(CCR0, do_array);
 225 
 226   //  __ cmplwi(CCR0, sig_byte, 'V'); // void cannot appear since we do not parse the return type
 227   //  __ beq(CCR0, do_void);
 228 
 229   __ bind(do_dontreachhere);
 230 
 231   __ unimplemented("ShouldNotReachHere in slow_signature_handler", 120);
 232 
 233   __ bind(do_array);
 234 
 235   {
 236     Label start_skip, end_skip;
 237 
 238     __ bind(start_skip);
 239     __ lbzu(sig_byte, 1, signature);
 240     __ cmplwi(CCR0, sig_byte, '[');
 241     __ beq(CCR0, start_skip); // skip further brackets
 242     __ cmplwi(CCR0, sig_byte, '9');
 243     __ bgt(CCR0, end_skip);   // no optional size
 244     __ cmplwi(CCR0, sig_byte, '0');
 245     __ bge(CCR0, start_skip); // skip optional size
 246     __ bind(end_skip);
 247 
 248     __ cmplwi(CCR0, sig_byte, 'L');
 249     __ beq(CCR0, do_object);  // for arrays of objects, the name of the object must be skipped
 250     __ b(do_boxed);          // otherwise, go directly to do_boxed
 251   }
 252 
 253   __ bind(do_object);
 254   {
 255     Label L;
 256     __ bind(L);
 257     __ lbzu(sig_byte, 1, signature);
 258     __ cmplwi(CCR0, sig_byte, ';');
 259     __ bne(CCR0, L);
 260    }
 261   // Need to box the Java object here, so we use arg_java (address of
 262   // current Java stack slot) as argument and don't dereference it as
 263   // in case of ints, floats, etc.
 264   Label do_null;
 265   __ bind(do_boxed);
 266   __ ld(R0,0, arg_java);
 267   __ cmpdi(CCR0, R0, 0);
 268   __ li(intSlot,0);
 269   __ beq(CCR0, do_null);
 270   __ mr(intSlot, arg_java);
 271   __ bind(do_null);
 272   __ std(intSlot, 0, arg_c);
 273   __ addi(arg_java, arg_java, -BytesPerWord);
 274   __ addi(arg_c, arg_c, BytesPerWord);
 275   __ cmplwi(CCR0, argcnt, max_int_register_arguments);
 276   __ blt(CCR0, move_intSlot_to_ARG);
 277   __ b(loop_start);
 278 
 279   __ bind(do_int);
 280   __ lwa(intSlot, 0, arg_java);
 281   __ std(intSlot, 0, arg_c);
 282   __ addi(arg_java, arg_java, -BytesPerWord);
 283   __ addi(arg_c, arg_c, BytesPerWord);
 284   __ cmplwi(CCR0, argcnt, max_int_register_arguments);
 285   __ blt(CCR0, move_intSlot_to_ARG);
 286   __ b(loop_start);
 287 
 288   __ bind(do_long);
 289   __ ld(intSlot, -BytesPerWord, arg_java);
 290   __ std(intSlot, 0, arg_c);
 291   __ addi(arg_java, arg_java, - 2 * BytesPerWord);
 292   __ addi(arg_c, arg_c, BytesPerWord);
 293   __ cmplwi(CCR0, argcnt, max_int_register_arguments);
 294   __ blt(CCR0, move_intSlot_to_ARG);
 295   __ b(loop_start);
 296 
 297   __ bind(do_float);
 298   __ lfs(floatSlot, 0, arg_java);
 299 #if defined(LINUX)
 300   __ stfs(floatSlot, 4, arg_c);
 301 #elif defined(AIX)
 302   __ stfs(floatSlot, 0, arg_c);
 303 #else
 304 #error "unknown OS"
 305 #endif
 306   __ addi(arg_java, arg_java, -BytesPerWord);
 307   __ addi(arg_c, arg_c, BytesPerWord);
 308   __ cmplwi(CCR0, fpcnt, max_fp_register_arguments);
 309   __ blt(CCR0, move_floatSlot_to_FARG);
 310   __ b(loop_start);
 311 
 312   __ bind(do_double);
 313   __ lfd(floatSlot, - BytesPerWord, arg_java);
 314   __ stfd(floatSlot, 0, arg_c);
 315   __ addi(arg_java, arg_java, - 2 * BytesPerWord);
 316   __ addi(arg_c, arg_c, BytesPerWord);
 317   __ cmplwi(CCR0, fpcnt, max_fp_register_arguments);
 318   __ blt(CCR0, move_floatSlot_to_FARG);
 319   __ b(loop_start);
 320 
 321   __ bind(loop_end);
 322 
 323   __ pop_frame();
 324   __ restore_nonvolatile_gprs(R1_SP, _spill_nonvolatiles_neg(r14));
 325   __ restore_LR_CR(R0);
 326 
 327   __ blr();
 328 
 329   Label move_int_arg, move_float_arg;
 330   __ bind(move_int_arg); // each case must consist of 2 instructions (otherwise adapt LogSizeOfTwoInstructions)
 331   __ mr(R5_ARG3, intSlot);  __ b(loop_start);
 332   __ mr(R6_ARG4, intSlot);  __ b(loop_start);
 333   __ mr(R7_ARG5, intSlot);  __ b(loop_start);
 334   __ mr(R8_ARG6, intSlot);  __ b(loop_start);
 335   __ mr(R9_ARG7, intSlot);  __ b(loop_start);
 336   __ mr(R10_ARG8, intSlot); __ b(loop_start);
 337 
 338   __ bind(move_float_arg); // each case must consist of 2 instructions (otherwise adapt LogSizeOfTwoInstructions)
 339   __ fmr(F1_ARG1, floatSlot);   __ b(loop_start);
 340   __ fmr(F2_ARG2, floatSlot);   __ b(loop_start);
 341   __ fmr(F3_ARG3, floatSlot);   __ b(loop_start);
 342   __ fmr(F4_ARG4, floatSlot);   __ b(loop_start);
 343   __ fmr(F5_ARG5, floatSlot);   __ b(loop_start);
 344   __ fmr(F6_ARG6, floatSlot);   __ b(loop_start);
 345   __ fmr(F7_ARG7, floatSlot);   __ b(loop_start);
 346   __ fmr(F8_ARG8, floatSlot);   __ b(loop_start);
 347   __ fmr(F9_ARG9, floatSlot);   __ b(loop_start);
 348   __ fmr(F10_ARG10, floatSlot); __ b(loop_start);
 349   __ fmr(F11_ARG11, floatSlot); __ b(loop_start);
 350   __ fmr(F12_ARG12, floatSlot); __ b(loop_start);
 351   __ fmr(F13_ARG13, floatSlot); __ b(loop_start);
 352 
 353   __ bind(move_intSlot_to_ARG);
 354   __ sldi(R0, argcnt, LogSizeOfTwoInstructions);
 355   __ load_const(R11_scratch1, move_int_arg); // Label must be bound here.
 356   __ add(R11_scratch1, R0, R11_scratch1);
 357   __ mtctr(R11_scratch1/*branch_target*/);
 358   __ bctr();
 359   __ bind(move_floatSlot_to_FARG);
 360   __ sldi(R0, fpcnt, LogSizeOfTwoInstructions);
 361   __ addi(fpcnt, fpcnt, 1);
 362   __ load_const(R11_scratch1, move_float_arg); // Label must be bound here.
 363   __ add(R11_scratch1, R0, R11_scratch1);
 364   __ mtctr(R11_scratch1/*branch_target*/);
 365   __ bctr();
 366 
 367   return entry;
 368 }
 369 
 370 address AbstractInterpreterGenerator::generate_result_handler_for(BasicType type) {
 371   //
 372   // Registers alive
 373   //   R3_RET
 374   //   LR
 375   //
 376   // Registers updated
 377   //   R3_RET
 378   //
 379 
 380   Label done;
 381   address entry = __ pc();
 382 
 383   switch (type) {
 384   case T_BOOLEAN:
 385     // convert !=0 to 1
 386     __ neg(R0, R3_RET);
 387     __ orr(R0, R3_RET, R0);
 388     __ srwi(R3_RET, R0, 31);
 389     break;
 390   case T_BYTE:
 391      // sign extend 8 bits
 392      __ extsb(R3_RET, R3_RET);
 393      break;
 394   case T_CHAR:
 395      // zero extend 16 bits
 396      __ clrldi(R3_RET, R3_RET, 48);
 397      break;
 398   case T_SHORT:
 399      // sign extend 16 bits
 400      __ extsh(R3_RET, R3_RET);
 401      break;
 402   case T_INT:
 403      // sign extend 32 bits
 404      __ extsw(R3_RET, R3_RET);
 405      break;
 406   case T_LONG:
 407      break;
 408   case T_OBJECT:
 409     // unbox result if not null
 410     __ cmpdi(CCR0, R3_RET, 0);
 411     __ beq(CCR0, done);
 412     __ ld(R3_RET, 0, R3_RET);
 413     __ verify_oop(R3_RET);
 414     break;
 415   case T_FLOAT:
 416      break;
 417   case T_DOUBLE:
 418      break;
 419   case T_VOID:
 420      break;
 421   default: ShouldNotReachHere();
 422   }
 423 
 424   __ BIND(done);
 425   __ blr();
 426 
 427   return entry;
 428 }
 429 
 430 // Abstract method entry.
 431 //
 432 address InterpreterGenerator::generate_abstract_entry(void) {
 433   address entry = __ pc();
 434 
 435   //
 436   // Registers alive
 437   //   R16_thread     - JavaThread*
 438   //   R19_method     - callee's method (method to be invoked)
 439   //   R1_SP          - SP prepared such that caller's outgoing args are near top
 440   //   LR             - return address to caller
 441   //
 442   // Stack layout at this point:
 443   //
 444   //   0       [TOP_IJAVA_FRAME_ABI]         <-- R1_SP
 445   //           alignment (optional)
 446   //           [outgoing Java arguments]
 447   //           ...
 448   //   PARENT  [PARENT_IJAVA_FRAME_ABI]
 449   //            ...
 450   //
 451 
 452   // Can't use call_VM here because we have not set up a new
 453   // interpreter state. Make the call to the vm and make it look like
 454   // our caller set up the JavaFrameAnchor.
 455   __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/);
 456 
 457   // Push a new C frame and save LR.
 458   __ save_LR_CR(R0);
 459   __ push_frame_reg_args(0, R11_scratch1);
 460 
 461   // This is not a leaf but we have a JavaFrameAnchor now and we will
 462   // check (create) exceptions afterward so this is ok.
 463   __ call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_AbstractMethodError));
 464 
 465   // Pop the C frame and restore LR.
 466   __ pop_frame();
 467   __ restore_LR_CR(R0);
 468 
 469   // Reset JavaFrameAnchor from call_VM_leaf above.
 470   __ reset_last_Java_frame();
 471 
 472 #ifdef CC_INTERP
 473   // Return to frame manager, it will handle the pending exception.
 474   __ blr();
 475 #else
 476   // We don't know our caller, so jump to the general forward exception stub,
 477   // which will also pop our full frame off. Satisfy the interface of
 478   // SharedRuntime::generate_forward_exception()
 479   __ load_const_optimized(R11_scratch1, StubRoutines::forward_exception_entry(), R0);
 480   __ mtctr(R11_scratch1);
 481   __ bctr();
 482 #endif
 483 
 484   return entry;
 485 }
 486 
 487 // Call an accessor method (assuming it is resolved, otherwise drop into
 488 // vanilla (slow path) entry.
 489 address InterpreterGenerator::generate_accessor_entry(void) {
 490   if (!UseFastAccessorMethods && (!FLAG_IS_ERGO(UseFastAccessorMethods))) {
 491     return NULL;
 492   }
 493 
 494   Label Lslow_path, Lacquire;
 495 
 496   const Register
 497          Rclass_or_obj = R3_ARG1,
 498          Rconst_method = R4_ARG2,
 499          Rcodes        = Rconst_method,
 500          Rcpool_cache  = R5_ARG3,
 501          Rscratch      = R11_scratch1,
 502          Rjvmti_mode   = Rscratch,
 503          Roffset       = R12_scratch2,
 504          Rflags        = R6_ARG4,
 505          Rbtable       = R7_ARG5;
 506 
 507   static address branch_table[number_of_states];
 508 
 509   address entry = __ pc();
 510 
 511   // Check for safepoint:
 512   // Ditch this, real man don't need safepoint checks.
 513 
 514   // Also check for JVMTI mode
 515   // Check for null obj, take slow path if so.
 516   __ ld(Rclass_or_obj, Interpreter::stackElementSize, CC_INTERP_ONLY(R17_tos) NOT_CC_INTERP(R15_esp));
 517   __ lwz(Rjvmti_mode, thread_(interp_only_mode));
 518   __ cmpdi(CCR1, Rclass_or_obj, 0);
 519   __ cmpwi(CCR0, Rjvmti_mode, 0);
 520   __ crorc(/*CCR0 eq*/2, /*CCR1 eq*/4+2, /*CCR0 eq*/2);
 521   __ beq(CCR0, Lslow_path); // this==null or jvmti_mode!=0
 522 
 523   // Do 2 things in parallel:
 524   // 1. Load the index out of the first instruction word, which looks like this:
 525   //    <0x2a><0xb4><index (2 byte, native endianess)>.
 526   // 2. Load constant pool cache base.
 527   __ ld(Rconst_method, in_bytes(Method::const_offset()), R19_method);
 528   __ ld(Rcpool_cache, in_bytes(ConstMethod::constants_offset()), Rconst_method);
 529 
 530   __ lhz(Rcodes, in_bytes(ConstMethod::codes_offset()) + 2, Rconst_method); // Lower half of 32 bit field.
 531   __ ld(Rcpool_cache, ConstantPool::cache_offset_in_bytes(), Rcpool_cache);
 532 
 533   // Get the const pool entry by means of <index>.
 534   const int codes_shift = exact_log2(in_words(ConstantPoolCacheEntry::size()) * BytesPerWord);
 535   __ slwi(Rscratch, Rcodes, codes_shift); // (codes&0xFFFF)<<codes_shift
 536   __ add(Rcpool_cache, Rscratch, Rcpool_cache);
 537 
 538   // Check if cpool cache entry is resolved.
 539   // We are resolved if the indices offset contains the current bytecode.
 540   ByteSize cp_base_offset = ConstantPoolCache::base_offset();
 541   // Big Endian:
 542   __ lbz(Rscratch, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::indices_offset()) + 7 - 2, Rcpool_cache);
 543   __ cmpwi(CCR0, Rscratch, Bytecodes::_getfield);
 544   __ bne(CCR0, Lslow_path);
 545   __ isync(); // Order succeeding loads wrt. load of _indices field from cpool_cache.
 546 
 547   // Finally, start loading the value: Get cp cache entry into regs.
 548   __ ld(Rflags, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::flags_offset()), Rcpool_cache);
 549   __ ld(Roffset, in_bytes(cp_base_offset) + in_bytes(ConstantPoolCacheEntry::f2_offset()), Rcpool_cache);
 550 
 551   // Following code is from templateTable::getfield_or_static
 552   // Load pointer to branch table
 553   __ load_const_optimized(Rbtable, (address)branch_table, Rscratch);
 554 
 555   // Get volatile flag
 556   __ rldicl(Rscratch, Rflags, 64-ConstantPoolCacheEntry::is_volatile_shift, 63); // extract volatile bit
 557   // note: sync is needed before volatile load on PPC64
 558 
 559   // Check field type
 560   __ rldicl(Rflags, Rflags, 64-ConstantPoolCacheEntry::tos_state_shift, 64-ConstantPoolCacheEntry::tos_state_bits);
 561 
 562 #ifdef ASSERT
 563   Label LFlagInvalid;
 564   __ cmpldi(CCR0, Rflags, number_of_states);
 565   __ bge(CCR0, LFlagInvalid);
 566 
 567   __ ld(R9_ARG7, 0, R1_SP);
 568   __ ld(R10_ARG8, 0, R21_sender_SP);
 569   __ cmpd(CCR0, R9_ARG7, R10_ARG8);
 570   __ asm_assert_eq("backlink", 0x543);
 571 #endif // ASSERT
 572   __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
 573 
 574   // Load from branch table and dispatch (volatile case: one instruction ahead)
 575   __ sldi(Rflags, Rflags, LogBytesPerWord);
 576   __ cmpwi(CCR6, Rscratch, 1); // volatile?
 577   if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
 578     __ sldi(Rscratch, Rscratch, exact_log2(BytesPerInstWord)); // volatile ? size of 1 instruction : 0
 579   }
 580   __ ldx(Rbtable, Rbtable, Rflags);
 581 
 582   if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
 583     __ subf(Rbtable, Rscratch, Rbtable); // point to volatile/non-volatile entry point
 584   }
 585   __ mtctr(Rbtable);
 586   __ bctr();
 587 
 588 #ifdef ASSERT
 589   __ bind(LFlagInvalid);
 590   __ stop("got invalid flag", 0x6541);
 591 
 592   bool all_uninitialized = true,
 593        all_initialized   = true;
 594   for (int i = 0; i<number_of_states; ++i) {
 595     all_uninitialized = all_uninitialized && (branch_table[i] == NULL);
 596     all_initialized   = all_initialized   && (branch_table[i] != NULL);
 597   }
 598   assert(all_uninitialized != all_initialized, "consistency"); // either or
 599 
 600   __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
 601   if (branch_table[vtos] == 0) branch_table[vtos] = __ pc(); // non-volatile_entry point
 602   if (branch_table[dtos] == 0) branch_table[dtos] = __ pc(); // non-volatile_entry point
 603   if (branch_table[ftos] == 0) branch_table[ftos] = __ pc(); // non-volatile_entry point
 604   __ stop("unexpected type", 0x6551);
 605 #endif
 606 
 607   if (branch_table[itos] == 0) { // generate only once
 608     __ align(32, 28, 28); // align load
 609     __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
 610     branch_table[itos] = __ pc(); // non-volatile_entry point
 611     __ lwax(R3_RET, Rclass_or_obj, Roffset);
 612     __ beq(CCR6, Lacquire);
 613     __ blr();
 614   }
 615 
 616   if (branch_table[ltos] == 0) { // generate only once
 617     __ align(32, 28, 28); // align load
 618     __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
 619     branch_table[ltos] = __ pc(); // non-volatile_entry point
 620     __ ldx(R3_RET, Rclass_or_obj, Roffset);
 621     __ beq(CCR6, Lacquire);
 622     __ blr();
 623   }
 624 
 625   if (branch_table[btos] == 0) { // generate only once
 626     __ align(32, 28, 28); // align load
 627     __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
 628     branch_table[btos] = __ pc(); // non-volatile_entry point
 629     __ lbzx(R3_RET, Rclass_or_obj, Roffset);
 630     __ extsb(R3_RET, R3_RET);
 631     __ beq(CCR6, Lacquire);
 632     __ blr();
 633   }
 634 
 635   if (branch_table[ctos] == 0) { // generate only once
 636     __ align(32, 28, 28); // align load
 637     __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
 638     branch_table[ctos] = __ pc(); // non-volatile_entry point
 639     __ lhzx(R3_RET, Rclass_or_obj, Roffset);
 640     __ beq(CCR6, Lacquire);
 641     __ blr();
 642   }
 643 
 644   if (branch_table[stos] == 0) { // generate only once
 645     __ align(32, 28, 28); // align load
 646     __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
 647     branch_table[stos] = __ pc(); // non-volatile_entry point
 648     __ lhax(R3_RET, Rclass_or_obj, Roffset);
 649     __ beq(CCR6, Lacquire);
 650     __ blr();
 651   }
 652 
 653   if (branch_table[atos] == 0) { // generate only once
 654     __ align(32, 28, 28); // align load
 655     __ fence(); // volatile entry point (one instruction before non-volatile_entry point)
 656     branch_table[atos] = __ pc(); // non-volatile_entry point
 657     __ load_heap_oop(R3_RET, (RegisterOrConstant)Roffset, Rclass_or_obj);
 658     __ verify_oop(R3_RET);
 659     //__ dcbt(R3_RET); // prefetch
 660     __ beq(CCR6, Lacquire);
 661     __ blr();
 662   }
 663 
 664   __ align(32, 12);
 665   __ bind(Lacquire);
 666   __ twi_0(R3_RET);
 667   __ isync(); // acquire
 668   __ blr();
 669 
 670 #ifdef ASSERT
 671   for (int i = 0; i<number_of_states; ++i) {
 672     assert(branch_table[i], "accessor_entry initialization");
 673     //tty->print_cr("accessor_entry: branch_table[%d] = 0x%llx (opcode 0x%llx)", i, branch_table[i], *((unsigned int*)branch_table[i]));
 674   }
 675 #endif
 676 
 677   __ bind(Lslow_path);
 678   __ branch_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals), Rscratch);
 679   __ flush();
 680 
 681   return entry;
 682 }
 683 
 684 // Interpreter intrinsic for WeakReference.get().
 685 // 1. Don't push a full blown frame and go on dispatching, but fetch the value
 686 //    into R8 and return quickly
 687 // 2. If G1 is active we *must* execute this intrinsic for corrrectness:
 688 //    It contains a GC barrier which puts the reference into the satb buffer
 689 //    to indicate that someone holds a strong reference to the object the
 690 //    weak ref points to!
 691 address InterpreterGenerator::generate_Reference_get_entry(void) {
 692   // Code: _aload_0, _getfield, _areturn
 693   // parameter size = 1
 694   //
 695   // The code that gets generated by this routine is split into 2 parts:
 696   //    1. the "intrinsified" code for G1 (or any SATB based GC),
 697   //    2. the slow path - which is an expansion of the regular method entry.
 698   //
 699   // Notes:
 700   // * In the G1 code we do not check whether we need to block for
 701   //   a safepoint. If G1 is enabled then we must execute the specialized
 702   //   code for Reference.get (except when the Reference object is null)
 703   //   so that we can log the value in the referent field with an SATB
 704   //   update buffer.
 705   //   If the code for the getfield template is modified so that the
 706   //   G1 pre-barrier code is executed when the current method is
 707   //   Reference.get() then going through the normal method entry
 708   //   will be fine.
 709   // * The G1 code can, however, check the receiver object (the instance
 710   //   of java.lang.Reference) and jump to the slow path if null. If the
 711   //   Reference object is null then we obviously cannot fetch the referent
 712   //   and so we don't need to call the G1 pre-barrier. Thus we can use the
 713   //   regular method entry code to generate the NPE.
 714   //
 715   // This code is based on generate_accessor_enty.
 716 
 717   address entry = __ pc();
 718 
 719   const int referent_offset = java_lang_ref_Reference::referent_offset;
 720   guarantee(referent_offset > 0, "referent offset not initialized");
 721 
 722   if (UseG1GC) {
 723      Label slow_path;
 724 
 725     // Debugging not possible, so can't use __ skip_if_jvmti_mode(slow_path, GR31_SCRATCH);
 726 
 727     // In the G1 code we don't check if we need to reach a safepoint. We
 728     // continue and the thread will safepoint at the next bytecode dispatch.
 729 
 730     // If the receiver is null then it is OK to jump to the slow path.
 731     __ ld(R3_RET, Interpreter::stackElementSize, CC_INTERP_ONLY(R17_tos) NOT_CC_INTERP(R15_esp)); // get receiver
 732 
 733     // Check if receiver == NULL and go the slow path.
 734     __ cmpdi(CCR0, R3_RET, 0);
 735     __ beq(CCR0, slow_path);
 736 
 737     // Load the value of the referent field.
 738     __ load_heap_oop(R3_RET, referent_offset, R3_RET);
 739 
 740     // Generate the G1 pre-barrier code to log the value of
 741     // the referent field in an SATB buffer. Note with
 742     // these parameters the pre-barrier does not generate
 743     // the load of the previous value.
 744 
 745     // Restore caller sp for c2i case.
 746 #ifdef ASSERT
 747       __ ld(R9_ARG7, 0, R1_SP);
 748       __ ld(R10_ARG8, 0, R21_sender_SP);
 749       __ cmpd(CCR0, R9_ARG7, R10_ARG8);
 750       __ asm_assert_eq("backlink", 0x544);
 751 #endif // ASSERT
 752     __ mr(R1_SP, R21_sender_SP); // Cut the stack back to where the caller started.
 753 
 754     __ g1_write_barrier_pre(noreg,         // obj
 755                             noreg,         // offset
 756                             R3_RET,        // pre_val
 757                             R11_scratch1,  // tmp
 758                             R12_scratch2,  // tmp
 759                             true);         // needs_frame
 760 
 761     __ blr();
 762 
 763     // Generate regular method entry.
 764     __ bind(slow_path);
 765     __ branch_to_entry(Interpreter::entry_for_kind(Interpreter::zerolocals), R11_scratch1);
 766     __ flush();
 767 
 768     return entry;
 769   } else {
 770     return generate_accessor_entry();
 771   }
 772 }
 773 
 774 void Deoptimization::unwind_callee_save_values(frame* f, vframeArray* vframe_array) {
 775   // This code is sort of the equivalent of C2IAdapter::setup_stack_frame back in
 776   // the days we had adapter frames. When we deoptimize a situation where a
 777   // compiled caller calls a compiled caller will have registers it expects
 778   // to survive the call to the callee. If we deoptimize the callee the only
 779   // way we can restore these registers is to have the oldest interpreter
 780   // frame that we create restore these values. That is what this routine
 781   // will accomplish.
 782 
 783   // At the moment we have modified c2 to not have any callee save registers
 784   // so this problem does not exist and this routine is just a place holder.
 785 
 786   assert(f->is_interpreted_frame(), "must be interpreted");
 787 }