src/cpu/ppc/vm/interpreter_ppc.cpp

Thu, 06 Mar 2014 10:55:28 -0800

author
goetz
date
Thu, 06 Mar 2014 10:55:28 -0800
changeset 6511
31e80afe3fed
parent 6495
67fa91961822
child 6512
fd1b9f02cc91
permissions
-rw-r--r--

8035647: PPC64: Support for elf v2 abi.
Summary: ELFv2 ABI used by the little endian PowerPC64 on Linux.
Reviewed-by: kvn
Contributed-by: asmundak@google.com

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

mercurial