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