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