src/cpu/ppc/vm/cppInterpreter_ppc.cpp

Wed, 15 Apr 2020 11:49:55 +0800

author
aoqi
date
Wed, 15 Apr 2020 11:49:55 +0800
changeset 9852
70aa912cebe5
parent 6876
710a3c8b516e
permissions
-rw-r--r--

Merge

     2 /*
     3  * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     4  * Copyright 2012, 2014 SAP AG. All rights reserved.
     5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6  *
     7  * This code is free software; you can redistribute it and/or modify it
     8  * under the terms of the GNU General Public License version 2 only, as
     9  * published by the Free Software Foundation.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  *
    25  */
    27 #include "precompiled.hpp"
    28 #include "asm/assembler.hpp"
    29 #include "asm/macroAssembler.inline.hpp"
    30 #include "interpreter/bytecodeHistogram.hpp"
    31 #include "interpreter/cppInterpreter.hpp"
    32 #include "interpreter/interpreter.hpp"
    33 #include "interpreter/interpreterGenerator.hpp"
    34 #include "interpreter/interpreterRuntime.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 "runtime/arguments.hpp"
    42 #include "runtime/deoptimization.hpp"
    43 #include "runtime/frame.inline.hpp"
    44 #include "runtime/interfaceSupport.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 SHARK
    52 #include "shark/shark_globals.hpp"
    53 #endif
    55 #ifdef CC_INTERP
    57 #define __ _masm->
    59 // Contains is used for identifying interpreter frames during a stack-walk.
    60 // A frame with a PC in InterpretMethod must be identified as a normal C frame.
    61 bool CppInterpreter::contains(address pc) {
    62   return _code->contains(pc);
    63 }
    65 #ifdef PRODUCT
    66 #define BLOCK_COMMENT(str) // nothing
    67 #else
    68 #define BLOCK_COMMENT(str) __ block_comment(str)
    69 #endif
    71 #define BIND(label) bind(label); BLOCK_COMMENT(#label ":")
    73 static address interpreter_frame_manager        = NULL;
    74 static address frame_manager_specialized_return = NULL;
    75 static address native_entry                     = NULL;
    77 static address interpreter_return_address       = NULL;
    79 static address unctrap_frame_manager_entry      = NULL;
    81 static address deopt_frame_manager_return_atos  = NULL;
    82 static address deopt_frame_manager_return_btos  = NULL;
    83 static address deopt_frame_manager_return_itos  = NULL;
    84 static address deopt_frame_manager_return_ltos  = NULL;
    85 static address deopt_frame_manager_return_ftos  = NULL;
    86 static address deopt_frame_manager_return_dtos  = NULL;
    87 static address deopt_frame_manager_return_vtos  = NULL;
    89 // A result handler converts/unboxes a native call result into
    90 // a java interpreter/compiler result. The current frame is an
    91 // interpreter frame.
    92 address CppInterpreterGenerator::generate_result_handler_for(BasicType type) {
    93   return AbstractInterpreterGenerator::generate_result_handler_for(type);
    94 }
    96 // tosca based result to c++ interpreter stack based result.
    97 address CppInterpreterGenerator::generate_tosca_to_stack_converter(BasicType type) {
    98   //
    99   // A result is in the native abi result register from a native
   100   // method call. We need to return this result to the interpreter by
   101   // pushing the result on the interpreter's stack.
   102   //
   103   // Registers alive:
   104   //   R3_ARG1(R3_RET)/F1_ARG1(F1_RET) - result to move
   105   //   R4_ARG2                         - address of tos
   106   //   LR
   107   //
   108   // Registers updated:
   109   //   R3_RET(R3_ARG1)   - address of new tos (== R17_tos for T_VOID)
   110   //
   112   int number_of_used_slots = 1;
   114   const Register tos = R4_ARG2;
   115   Label done;
   116   Label is_false;
   118   address entry = __ pc();
   120   switch (type) {
   121   case T_BOOLEAN:
   122     __ cmpwi(CCR0, R3_RET, 0);
   123     __ beq(CCR0, is_false);
   124     __ li(R3_RET, 1);
   125     __ stw(R3_RET, 0, tos);
   126     __ b(done);
   127     __ bind(is_false);
   128     __ li(R3_RET, 0);
   129     __ stw(R3_RET, 0, tos);
   130     break;
   131   case T_BYTE:
   132   case T_CHAR:
   133   case T_SHORT:
   134   case T_INT:
   135     __ stw(R3_RET, 0, tos);
   136     break;
   137   case T_LONG:
   138     number_of_used_slots = 2;
   139     // mark unused slot for debugging
   140     // long goes to topmost slot
   141     __ std(R3_RET, -BytesPerWord, tos);
   142     __ li(R3_RET, 0);
   143     __ std(R3_RET, 0, tos);
   144     break;
   145   case T_OBJECT:
   146     __ verify_oop(R3_RET);
   147     __ std(R3_RET, 0, tos);
   148     break;
   149   case T_FLOAT:
   150     __ stfs(F1_RET, 0, tos);
   151     break;
   152   case T_DOUBLE:
   153     number_of_used_slots = 2;
   154     // mark unused slot for debugging
   155     __ li(R3_RET, 0);
   156     __ std(R3_RET, 0, tos);
   157     // double goes to topmost slot
   158     __ stfd(F1_RET, -BytesPerWord, tos);
   159     break;
   160   case T_VOID:
   161     number_of_used_slots = 0;
   162     break;
   163   default:
   164     ShouldNotReachHere();
   165   }
   167   __ BIND(done);
   169   // new expression stack top
   170   __ addi(R3_RET, tos, -BytesPerWord * number_of_used_slots);
   172   __ blr();
   174   return entry;
   175 }
   177 address CppInterpreterGenerator::generate_stack_to_stack_converter(BasicType type) {
   178   //
   179   // Copy the result from the callee's stack to the caller's stack,
   180   // caller and callee both being interpreted.
   181   //
   182   // Registers alive
   183   //   R3_ARG1        - address of callee's tos + BytesPerWord
   184   //   R4_ARG2        - address of caller's tos [i.e. free location]
   185   //   LR
   186   //
   187   //   stack grows upwards, memory grows downwards.
   188   //
   189   //   [      free         ]  <-- callee's tos
   190   //   [  optional result  ]  <-- R3_ARG1
   191   //   [  optional dummy   ]
   192   //          ...
   193   //   [      free         ]  <-- caller's tos, R4_ARG2
   194   //          ...
   195   // Registers updated
   196   //   R3_RET(R3_ARG1) - address of caller's new tos
   197   //
   198   //   stack grows upwards, memory grows downwards.
   199   //
   200   //   [      free         ]  <-- current tos, R3_RET
   201   //   [  optional result  ]
   202   //   [  optional dummy   ]
   203   //          ...
   204   //
   206   const Register from = R3_ARG1;
   207   const Register ret  = R3_ARG1;
   208   const Register tos  = R4_ARG2;
   209   const Register tmp1 = R21_tmp1;
   210   const Register tmp2 = R22_tmp2;
   212   address entry = __ pc();
   214   switch (type) {
   215   case T_BOOLEAN:
   216   case T_BYTE:
   217   case T_CHAR:
   218   case T_SHORT:
   219   case T_INT:
   220   case T_FLOAT:
   221     __ lwz(tmp1, 0, from);
   222     __ stw(tmp1, 0, tos);
   223     // New expression stack top.
   224     __ addi(ret, tos, - BytesPerWord);
   225     break;
   226   case T_LONG:
   227   case T_DOUBLE:
   228     // Move both entries for debug purposes even though only one is live.
   229     __ ld(tmp1, BytesPerWord, from);
   230     __ ld(tmp2, 0, from);
   231     __ std(tmp1, 0, tos);
   232     __ std(tmp2, -BytesPerWord, tos);
   233     // New expression stack top.
   234     __ addi(ret, tos, - 2 * BytesPerWord); // two slots
   235     break;
   236   case T_OBJECT:
   237     __ ld(tmp1, 0, from);
   238     __ verify_oop(tmp1);
   239     __ std(tmp1, 0, tos);
   240     // New expression stack top.
   241     __ addi(ret, tos, - BytesPerWord);
   242     break;
   243   case T_VOID:
   244     // New expression stack top.
   245     __ mr(ret, tos);
   246     break;
   247   default:
   248     ShouldNotReachHere();
   249   }
   251   __ blr();
   253   return entry;
   254 }
   256 address CppInterpreterGenerator::generate_stack_to_native_abi_converter(BasicType type) {
   257   //
   258   // Load a result from the callee's stack into the caller's expecting
   259   // return register, callee being interpreted, caller being call stub
   260   // or jit code.
   261   //
   262   // Registers alive
   263   //   R3_ARG1   - callee expression tos + BytesPerWord
   264   //   LR
   265   //
   266   //   stack grows upwards, memory grows downwards.
   267   //
   268   //   [      free         ]  <-- callee's tos
   269   //   [  optional result  ]  <-- R3_ARG1
   270   //   [  optional dummy   ]
   271   //          ...
   272   //
   273   // Registers updated
   274   //   R3_RET(R3_ARG1)/F1_RET - result
   275   //
   277   const Register from = R3_ARG1;
   278   const Register ret = R3_ARG1;
   279   const FloatRegister fret = F1_ARG1;
   281   address entry = __ pc();
   283   // Implemented uniformly for both kinds of endianness. The interpreter
   284   // implements boolean, byte, char, and short as jint (4 bytes).
   285   switch (type) {
   286   case T_BOOLEAN:
   287   case T_CHAR:
   288     // zero extension
   289     __ lwz(ret, 0, from);
   290     break;
   291   case T_BYTE:
   292   case T_SHORT:
   293   case T_INT:
   294     // sign extension
   295     __ lwa(ret, 0, from);
   296     break;
   297   case T_LONG:
   298     __ ld(ret, 0, from);
   299     break;
   300   case T_OBJECT:
   301     __ ld(ret, 0, from);
   302     __ verify_oop(ret);
   303     break;
   304   case T_FLOAT:
   305     __ lfs(fret, 0, from);
   306     break;
   307   case T_DOUBLE:
   308     __ lfd(fret, 0, from);
   309     break;
   310   case T_VOID:
   311     break;
   312   default:
   313     ShouldNotReachHere();
   314   }
   316   __ blr();
   318   return entry;
   319 }
   321 address CppInterpreter::return_entry(TosState state, int length, Bytecodes::Code code) {
   322   assert(interpreter_return_address != NULL, "Not initialized");
   323   return interpreter_return_address;
   324 }
   326 address CppInterpreter::deopt_entry(TosState state, int length) {
   327   address ret = NULL;
   328   if (length != 0) {
   329     switch (state) {
   330       case atos: ret = deopt_frame_manager_return_atos; break;
   331       case btos: ret = deopt_frame_manager_return_itos; break;
   332       case ctos:
   333       case stos:
   334       case itos: ret = deopt_frame_manager_return_itos; break;
   335       case ltos: ret = deopt_frame_manager_return_ltos; break;
   336       case ftos: ret = deopt_frame_manager_return_ftos; break;
   337       case dtos: ret = deopt_frame_manager_return_dtos; break;
   338       case vtos: ret = deopt_frame_manager_return_vtos; break;
   339       default: ShouldNotReachHere();
   340     }
   341   } else {
   342     ret = unctrap_frame_manager_entry;  // re-execute the bytecode (e.g. uncommon trap, popframe)
   343   }
   344   assert(ret != NULL, "Not initialized");
   345   return ret;
   346 }
   348 //
   349 // Helpers for commoning out cases in the various type of method entries.
   350 //
   352 //
   353 // Registers alive
   354 //   R16_thread      - JavaThread*
   355 //   R1_SP           - old stack pointer
   356 //   R19_method      - callee's Method
   357 //   R17_tos         - address of caller's tos (prepushed)
   358 //   R15_prev_state  - address of caller's BytecodeInterpreter or 0
   359 //   return_pc in R21_tmp15 (only when called within generate_native_entry)
   360 //
   361 // Registers updated
   362 //   R14_state       - address of callee's interpreter state
   363 //   R1_SP           - new stack pointer
   364 //   CCR4_is_synced  - current method is synchronized
   365 //
   366 void CppInterpreterGenerator::generate_compute_interpreter_state(Label& stack_overflow_return) {
   367   //
   368   // Stack layout at this point:
   369   //
   370   //   F1      [TOP_IJAVA_FRAME_ABI]              <-- R1_SP
   371   //           alignment (optional)
   372   //           [F1's outgoing Java arguments]     <-- R17_tos
   373   //           ...
   374   //   F2      [PARENT_IJAVA_FRAME_ABI]
   375   //            ...
   377   //=============================================================================
   378   // Allocate space for locals other than the parameters, the
   379   // interpreter state, monitors, and the expression stack.
   381   const Register local_count        = R21_tmp1;
   382   const Register parameter_count    = R22_tmp2;
   383   const Register max_stack          = R23_tmp3;
   384   // Must not be overwritten within this method!
   385   // const Register return_pc         = R29_tmp9;
   387   const ConditionRegister is_synced = CCR4_is_synced;
   388   const ConditionRegister is_native = CCR6;
   389   const ConditionRegister is_static = CCR7;
   391   assert(is_synced != is_native, "condition code registers must be distinct");
   392   assert(is_synced != is_static, "condition code registers must be distinct");
   393   assert(is_native != is_static, "condition code registers must be distinct");
   395   {
   397   // Local registers
   398   const Register top_frame_size     = R24_tmp4;
   399   const Register access_flags       = R25_tmp5;
   400   const Register state_offset       = R26_tmp6;
   401   Register mem_stack_limit          = R27_tmp7;
   402   const Register page_size          = R28_tmp8;
   404   BLOCK_COMMENT("compute_interpreter_state {");
   406   // access_flags = method->access_flags();
   407   // TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");
   408   __ lwa(access_flags, method_(access_flags));
   410   // parameter_count = method->constMethod->size_of_parameters();
   411   // TODO: PPC port: assert(2 == ConstMethod::sz_size_of_parameters(), "unexpected field size");
   412   __ ld(max_stack, in_bytes(Method::const_offset()), R19_method);   // Max_stack holds constMethod for a while.
   413   __ lhz(parameter_count, in_bytes(ConstMethod::size_of_parameters_offset()), max_stack);
   415   // local_count = method->constMethod()->max_locals();
   416   // TODO: PPC port: assert(2 == ConstMethod::sz_max_locals(), "unexpected field size");
   417   __ lhz(local_count, in_bytes(ConstMethod::size_of_locals_offset()), max_stack);
   419   // max_stack = method->constMethod()->max_stack();
   420   // TODO: PPC port: assert(2 == ConstMethod::sz_max_stack(), "unexpected field size");
   421   __ lhz(max_stack, in_bytes(ConstMethod::max_stack_offset()), max_stack);
   423   if (EnableInvokeDynamic) {
   424     // Take into account 'extra_stack_entries' needed by method handles (see method.hpp).
   425     __ addi(max_stack, max_stack, Method::extra_stack_entries());
   426   }
   428   // mem_stack_limit = thread->stack_limit();
   429   __ ld(mem_stack_limit, thread_(stack_overflow_limit));
   431   // Point locals at the first argument. Method's locals are the
   432   // parameters on top of caller's expression stack.
   434   // tos points past last Java argument
   435   __ sldi(R18_locals, parameter_count, Interpreter::logStackElementSize);
   436   __ add(R18_locals, R17_tos, R18_locals);
   438   // R18_locals - i*BytesPerWord points to i-th Java local (i starts at 0)
   440   // Set is_native, is_synced, is_static - will be used later.
   441   __ testbitdi(is_native, R0, access_flags, JVM_ACC_NATIVE_BIT);
   442   __ testbitdi(is_synced, R0, access_flags, JVM_ACC_SYNCHRONIZED_BIT);
   443   assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");
   444   __ testbitdi(is_static, R0, access_flags, JVM_ACC_STATIC_BIT);
   446   // PARENT_IJAVA_FRAME_ABI
   447   //
   448   // frame_size =
   449   //   round_to((local_count - parameter_count)*BytesPerWord +
   450   //              2*BytesPerWord +
   451   //              alignment +
   452   //              frame::interpreter_frame_cinterpreterstate_size_in_bytes()
   453   //              sizeof(PARENT_IJAVA_FRAME_ABI)
   454   //              method->is_synchronized() ? sizeof(BasicObjectLock) : 0 +
   455   //              max_stack*BytesPerWord,
   456   //            16)
   457   //
   458   // Note that this calculation is exactly mirrored by
   459   // AbstractInterpreter::layout_activation_impl() [ and
   460   // AbstractInterpreter::size_activation() ]. Which is used by
   461   // deoptimization so that it can allocate the proper sized
   462   // frame. This only happens for interpreted frames so the extra
   463   // notes below about max_stack below are not important. The other
   464   // thing to note is that for interpreter frames other than the
   465   // current activation the size of the stack is the size of the live
   466   // portion of the stack at the particular bcp and NOT the maximum
   467   // stack that the method might use.
   468   //
   469   // If we're calling a native method, we replace max_stack (which is
   470   // zero) with space for the worst-case signature handler varargs
   471   // vector, which is:
   472   //
   473   //   max_stack = max(Argument::n_register_parameters, parameter_count+2);
   474   //
   475   // We add two slots to the parameter_count, one for the jni
   476   // environment and one for a possible native mirror.  We allocate
   477   // space for at least the number of ABI registers, even though
   478   // InterpreterRuntime::slow_signature_handler won't write more than
   479   // parameter_count+2 words when it creates the varargs vector at the
   480   // top of the stack.  The generated slow signature handler will just
   481   // load trash into registers beyond the necessary number.  We're
   482   // still going to cut the stack back by the ABI register parameter
   483   // count so as to get SP+16 pointing at the ABI outgoing parameter
   484   // area, so we need to allocate at least that much even though we're
   485   // going to throw it away.
   486   //
   488   // Adjust max_stack for native methods:
   489   Label skip_native_calculate_max_stack;
   490   __ bfalse(is_native, skip_native_calculate_max_stack);
   491   // if (is_native) {
   492   //  max_stack = max(Argument::n_register_parameters, parameter_count+2);
   493   __ addi(max_stack, parameter_count, 2*Interpreter::stackElementWords);
   494   __ cmpwi(CCR0, max_stack, Argument::n_register_parameters);
   495   __ bge(CCR0, skip_native_calculate_max_stack);
   496   __ li(max_stack,  Argument::n_register_parameters);
   497   // }
   498   __ bind(skip_native_calculate_max_stack);
   499   // max_stack is now in bytes
   500   __ slwi(max_stack, max_stack, Interpreter::logStackElementSize);
   502   // Calculate number of non-parameter locals (in slots):
   503   Label not_java;
   504   __ btrue(is_native, not_java);
   505   // if (!is_native) {
   506   //   local_count = non-parameter local count
   507   __ sub(local_count, local_count, parameter_count);
   508   // } else {
   509   //   // nothing to do: method->max_locals() == 0 for native methods
   510   // }
   511   __ bind(not_java);
   514   // Calculate top_frame_size and parent_frame_resize.
   515   {
   516   const Register parent_frame_resize = R12_scratch2;
   518   BLOCK_COMMENT("Compute top_frame_size.");
   519   // top_frame_size = TOP_IJAVA_FRAME_ABI
   520   //                  + size of interpreter state
   521   __ li(top_frame_size, frame::top_ijava_frame_abi_size
   522                         + frame::interpreter_frame_cinterpreterstate_size_in_bytes());
   523   //                  + max_stack
   524   __ add(top_frame_size, top_frame_size, max_stack);
   525   //                  + stack slots for a BasicObjectLock for synchronized methods
   526   {
   527     Label not_synced;
   528     __ bfalse(is_synced, not_synced);
   529     __ addi(top_frame_size, top_frame_size, frame::interpreter_frame_monitor_size_in_bytes());
   530     __ bind(not_synced);
   531   }
   532   // align
   533   __ round_to(top_frame_size, frame::alignment_in_bytes);
   536   BLOCK_COMMENT("Compute parent_frame_resize.");
   537   // parent_frame_resize = R1_SP - R17_tos
   538   __ sub(parent_frame_resize, R1_SP, R17_tos);
   539   //__ li(parent_frame_resize, 0);
   540   //                       + PARENT_IJAVA_FRAME_ABI
   541   //                       + extra two slots for the no-parameter/no-locals
   542   //                         method result
   543   __ addi(parent_frame_resize, parent_frame_resize,
   544                                       frame::parent_ijava_frame_abi_size
   545                                     + 2*Interpreter::stackElementSize);
   546   //                       + (locals_count - params_count)
   547   __ sldi(R0, local_count, Interpreter::logStackElementSize);
   548   __ add(parent_frame_resize, parent_frame_resize, R0);
   549   // align
   550   __ round_to(parent_frame_resize, frame::alignment_in_bytes);
   552   //
   553   // Stack layout at this point:
   554   //
   555   // The new frame F0 hasn't yet been pushed, F1 is still the top frame.
   556   //
   557   //   F0      [TOP_IJAVA_FRAME_ABI]
   558   //           alignment (optional)
   559   //           [F0's full operand stack]
   560   //           [F0's monitors] (optional)
   561   //           [F0's BytecodeInterpreter object]
   562   //   F1      [PARENT_IJAVA_FRAME_ABI]
   563   //           alignment (optional)
   564   //           [F0's Java result]
   565   //           [F0's non-arg Java locals]
   566   //           [F1's outgoing Java arguments]     <-- R17_tos
   567   //           ...
   568   //   F2      [PARENT_IJAVA_FRAME_ABI]
   569   //            ...
   572   // Calculate new R14_state
   573   // and
   574   // test that the new memory stack pointer is above the limit,
   575   // throw a StackOverflowError otherwise.
   576   __ sub(R11_scratch1/*F1's SP*/,  R1_SP, parent_frame_resize);
   577   __ addi(R14_state, R11_scratch1/*F1's SP*/,
   578               -frame::interpreter_frame_cinterpreterstate_size_in_bytes());
   579   __ sub(R11_scratch1/*F0's SP*/,
   580              R11_scratch1/*F1's SP*/, top_frame_size);
   582   BLOCK_COMMENT("Test for stack overflow:");
   583   __ cmpld(CCR0/*is_stack_overflow*/, R11_scratch1, mem_stack_limit);
   584   __ blt(CCR0/*is_stack_overflow*/, stack_overflow_return);
   587   //=============================================================================
   588   // Frame_size doesn't overflow the stack. Allocate new frame and
   589   // initialize interpreter state.
   591   // Register state
   592   //
   593   //   R15            - local_count
   594   //   R16            - parameter_count
   595   //   R17            - max_stack
   596   //
   597   //   R18            - frame_size
   598   //   R19            - access_flags
   599   //   CCR4_is_synced - is_synced
   600   //
   601   //   GR_Lstate      - pointer to the uninitialized new BytecodeInterpreter.
   603   // _last_Java_pc just needs to be close enough that we can identify
   604   // the frame as an interpreted frame. It does not need to be the
   605   // exact return address from either calling
   606   // BytecodeInterpreter::InterpretMethod or the call to a jni native method.
   607   // So we can initialize it here with a value of a bundle in this
   608   // code fragment. We only do this initialization for java frames
   609   // where InterpretMethod needs a a way to get a good pc value to
   610   // store in the thread state. For interpreter frames used to call
   611   // jni native code we just zero the value in the state and move an
   612   // ip as needed in the native entry code.
   613   //
   614   // const Register last_Java_pc_addr     = GR24_SCRATCH;  // QQQ 27
   615   // const Register last_Java_pc          = GR26_SCRATCH;
   617   // Must reference stack before setting new SP since Windows
   618   // will not be able to deliver the exception on a bad SP.
   619   // Windows also insists that we bang each page one at a time in order
   620   // for the OS to map in the reserved pages. If we bang only
   621   // the final page, Windows stops delivering exceptions to our
   622   // VectoredExceptionHandler and terminates our program.
   623   // Linux only requires a single bang but it's rare to have
   624   // to bang more than 1 page so the code is enabled for both OS's.
   626   // BANG THE STACK
   627   //
   628   // Nothing to do for PPC, because updating the SP will automatically
   629   // bang the page.
   631   // Up to here we have calculated the delta for the new C-frame and
   632   // checked for a stack-overflow. Now we can savely update SP and
   633   // resize the C-frame.
   635   // R14_state has already been calculated.
   636   __ push_interpreter_frame(top_frame_size, parent_frame_resize,
   637                             R25_tmp5, R26_tmp6, R27_tmp7, R28_tmp8);
   639   }
   641   //
   642   // Stack layout at this point:
   643   //
   644   //   F0 has been been pushed!
   645   //
   646   //   F0      [TOP_IJAVA_FRAME_ABI]              <-- R1_SP
   647   //           alignment (optional)               (now it's here, if required)
   648   //           [F0's full operand stack]
   649   //           [F0's monitors] (optional)
   650   //           [F0's BytecodeInterpreter object]
   651   //   F1      [PARENT_IJAVA_FRAME_ABI]
   652   //           alignment (optional)               (now it's here, if required)
   653   //           [F0's Java result]
   654   //           [F0's non-arg Java locals]
   655   //           [F1's outgoing Java arguments]
   656   //           ...
   657   //   F2      [PARENT_IJAVA_FRAME_ABI]
   658   //           ...
   659   //
   660   // R14_state points to F0's BytecodeInterpreter object.
   661   //
   663   }
   665   //=============================================================================
   666   // new BytecodeInterpreter-object is save, let's initialize it:
   667   BLOCK_COMMENT("New BytecodeInterpreter-object is save.");
   669   {
   670   // Locals
   671   const Register bytecode_addr = R24_tmp4;
   672   const Register constants     = R25_tmp5;
   673   const Register tos           = R26_tmp6;
   674   const Register stack_base    = R27_tmp7;
   675   const Register local_addr    = R28_tmp8;
   676   {
   677     Label L;
   678     __ btrue(is_native, L);
   679     // if (!is_native) {
   680       // bytecode_addr = constMethod->codes();
   681       __ ld(bytecode_addr, method_(const));
   682       __ addi(bytecode_addr, bytecode_addr, in_bytes(ConstMethod::codes_offset()));
   683     // }
   684     __ bind(L);
   685   }
   687   __ ld(constants, in_bytes(Method::const_offset()), R19_method);
   688   __ ld(constants, in_bytes(ConstMethod::constants_offset()), constants);
   690   // state->_prev_link = prev_state;
   691   __ std(R15_prev_state, state_(_prev_link));
   693   // For assertions only.
   694   // TODO: not needed anyway because it coincides with `_monitor_base'. remove!
   695   // state->_self_link = state;
   696   DEBUG_ONLY(__ std(R14_state, state_(_self_link));)
   698   // state->_thread = thread;
   699   __ std(R16_thread, state_(_thread));
   701   // state->_method = method;
   702   __ std(R19_method, state_(_method));
   704   // state->_locals = locals;
   705   __ std(R18_locals, state_(_locals));
   707   // state->_oop_temp = NULL;
   708   __ li(R0, 0);
   709   __ std(R0, state_(_oop_temp));
   711   // state->_last_Java_fp = *R1_SP // Use *R1_SP as fp
   712   __ ld(R0, _abi(callers_sp), R1_SP);
   713   __ std(R0, state_(_last_Java_fp));
   715   BLOCK_COMMENT("load Stack base:");
   716   {
   717     // Stack_base.
   718     // if (!method->synchronized()) {
   719     //   stack_base = state;
   720     // } else {
   721     //   stack_base = (uintptr_t)state - sizeof(BasicObjectLock);
   722     // }
   723     Label L;
   724     __ mr(stack_base, R14_state);
   725     __ bfalse(is_synced, L);
   726     __ addi(stack_base, stack_base, -frame::interpreter_frame_monitor_size_in_bytes());
   727     __ bind(L);
   728   }
   730   // state->_mdx = NULL;
   731   __ li(R0, 0);
   732   __ std(R0, state_(_mdx));
   734   {
   735     // if (method->is_native()) state->_bcp = NULL;
   736     // else state->_bcp = bytecode_addr;
   737     Label label1, label2;
   738     __ bfalse(is_native, label1);
   739     __ std(R0, state_(_bcp));
   740     __ b(label2);
   741     __ bind(label1);
   742     __ std(bytecode_addr, state_(_bcp));
   743     __ bind(label2);
   744   }
   747   // state->_result._to_call._callee = NULL;
   748   __ std(R0, state_(_result._to_call._callee));
   750   // state->_monitor_base = state;
   751   __ std(R14_state, state_(_monitor_base));
   753   // state->_msg = BytecodeInterpreter::method_entry;
   754   __ li(R0, BytecodeInterpreter::method_entry);
   755   __ stw(R0, state_(_msg));
   757   // state->_last_Java_sp = R1_SP;
   758   __ std(R1_SP, state_(_last_Java_sp));
   760   // state->_stack_base = stack_base;
   761   __ std(stack_base, state_(_stack_base));
   763   // tos = stack_base - 1 slot (prepushed);
   764   // state->_stack.Tos(tos);
   765   __ addi(tos, stack_base, - Interpreter::stackElementSize);
   766   __ std(tos,  state_(_stack));
   769   {
   770     BLOCK_COMMENT("get last_Java_pc:");
   771     // if (!is_native) state->_last_Java_pc = <some_ip_in_this_code_buffer>;
   772     // else state->_last_Java_pc = NULL; (just for neatness)
   773     Label label1, label2;
   774     __ btrue(is_native, label1);
   775     __ get_PC_trash_LR(R0);
   776     __ std(R0, state_(_last_Java_pc));
   777     __ b(label2);
   778     __ bind(label1);
   779     __ li(R0, 0);
   780     __ std(R0, state_(_last_Java_pc));
   781     __ bind(label2);
   782   }
   785   // stack_limit = tos - max_stack;
   786   __ sub(R0, tos, max_stack);
   787   // state->_stack_limit = stack_limit;
   788   __ std(R0, state_(_stack_limit));
   791   // cache = method->constants()->cache();
   792    __ ld(R0, ConstantPool::cache_offset_in_bytes(), constants);
   793   // state->_constants = method->constants()->cache();
   794   __ std(R0, state_(_constants));
   798   //=============================================================================
   799   // synchronized method, allocate and initialize method object lock.
   800   // if (!method->is_synchronized()) goto fill_locals_with_0x0s;
   801   Label fill_locals_with_0x0s;
   802   __ bfalse(is_synced, fill_locals_with_0x0s);
   804   //   pool_holder = method->constants()->pool_holder();
   805   const int mirror_offset = in_bytes(Klass::java_mirror_offset());
   806   {
   807     Label label1, label2;
   808     // lockee = NULL; for java methods, correct value will be inserted in BytecodeInterpretMethod.hpp
   809     __ li(R0,0);
   810     __ bfalse(is_native, label2);
   812     __ bfalse(is_static, label1);
   813     // if (method->is_static()) lockee =
   814     // pool_holder->klass_part()->java_mirror();
   815     __ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(), constants);
   816     __ ld(R0/*lockee*/, mirror_offset, R11_scratch1/*pool_holder*/);
   817     __ b(label2);
   819     __ bind(label1);
   820     // else lockee = *(oop*)locals;
   821     __ ld(R0/*lockee*/, 0, R18_locals);
   822     __ bind(label2);
   824     // monitor->set_obj(lockee);
   825     __ std(R0/*lockee*/, BasicObjectLock::obj_offset_in_bytes(), stack_base);
   826   }
   828   // See if we need to zero the locals
   829   __ BIND(fill_locals_with_0x0s);
   832   //=============================================================================
   833   // fill locals with 0x0s
   834   Label locals_zeroed;
   835   __ btrue(is_native, locals_zeroed);
   837   if (true /* zerolocals */ || ClearInterpreterLocals) {
   838     // local_count is already num_locals_slots - num_param_slots
   839     __ sldi(R0, parameter_count, Interpreter::logStackElementSize);
   840     __ sub(local_addr, R18_locals, R0);
   841     __ cmpdi(CCR0, local_count, 0);
   842     __ ble(CCR0, locals_zeroed);
   844     __ mtctr(local_count);
   845     //__ ld_const_addr(R0, (address) 0xcafe0000babe);
   846     __ li(R0, 0);
   848     Label zero_slot;
   849     __ bind(zero_slot);
   851     // first local is at local_addr
   852     __ std(R0, 0, local_addr);
   853     __ addi(local_addr, local_addr, -BytesPerWord);
   854     __ bdnz(zero_slot);
   855   }
   857    __ BIND(locals_zeroed);
   859   }
   860   BLOCK_COMMENT("} compute_interpreter_state");
   861 }
   863 // Generate code to initiate compilation on invocation counter overflow.
   864 void CppInterpreterGenerator::generate_counter_overflow(Label& continue_entry) {
   865   // Registers alive
   866   //   R14_state
   867   //   R16_thread
   868   //
   869   // Registers updated
   870   //   R14_state
   871   //   R3_ARG1 (=R3_RET)
   872   //   R4_ARG2
   874   // After entering the vm we remove the activation and retry the
   875   // entry point in case the compilation is complete.
   877   // InterpreterRuntime::frequency_counter_overflow takes one argument
   878   // that indicates if the counter overflow occurs at a backwards
   879   // branch (NULL bcp). We pass zero. The call returns the address
   880   // of the verified entry point for the method or NULL if the
   881   // compilation did not complete (either went background or bailed
   882   // out).
   883   __ li(R4_ARG2, 0);
   885   // Pass false to call_VM so it doesn't check for pending exceptions,
   886   // since at this point in the method invocation the exception
   887   // handler would try to exit the monitor of synchronized methods
   888   // which haven't been entered yet.
   889   //
   890   // Returns verified_entry_point or NULL, we don't care which.
   891   //
   892   // Do not use the variant `frequency_counter_overflow' that returns
   893   // a structure, because this will change the argument list by a
   894   // hidden parameter (gcc 4.1).
   896   __ call_VM(noreg,
   897              CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow),
   898              R4_ARG2,
   899              false);
   900   // Returns verified_entry_point or NULL, we don't care which as we ignore it
   901   // and run interpreted.
   903   // Reload method, it may have moved.
   904   __ ld(R19_method, state_(_method));
   906   // We jump now to the label "continue_after_compile".
   907   __ b(continue_entry);
   908 }
   910 // Increment invocation count and check for overflow.
   911 //
   912 // R19_method must contain Method* of method to profile.
   913 void CppInterpreterGenerator::generate_counter_incr(Label& overflow) {
   914   Label done;
   915   const Register Rcounters             = R12_scratch2;
   916   const Register iv_be_count           = R11_scratch1;
   917   const Register invocation_limit      = R12_scratch2;
   918   const Register invocation_limit_addr = invocation_limit;
   920   // Load and ev. allocate MethodCounters object.
   921   __ get_method_counters(R19_method, Rcounters, done);
   923   // Update standard invocation counters.
   924   __ increment_invocation_counter(Rcounters, iv_be_count, R0);
   926   // Compare against limit.
   927   BLOCK_COMMENT("Compare counter against limit:");
   928   assert(4 == sizeof(InvocationCounter::InterpreterInvocationLimit),
   929          "must be 4 bytes");
   930   __ load_const(invocation_limit_addr, (address)&InvocationCounter::InterpreterInvocationLimit);
   931   __ lwa(invocation_limit, 0, invocation_limit_addr);
   932   __ cmpw(CCR0, iv_be_count, invocation_limit);
   933   __ bge(CCR0, overflow);
   934   __ bind(done);
   935 }
   937 //
   938 // Call a JNI method.
   939 //
   940 // Interpreter stub for calling a native method. (C++ interpreter)
   941 // This sets up a somewhat different looking stack for calling the native method
   942 // than the typical interpreter frame setup.
   943 //
   944 address CppInterpreterGenerator::generate_native_entry(void) {
   945   if (native_entry != NULL) return native_entry;
   946   address entry = __ pc();
   948   // Read
   949   //   R16_thread
   950   //   R15_prev_state  - address of caller's BytecodeInterpreter, if this snippet
   951   //                     gets called by the frame manager.
   952   //   R19_method      - callee's Method
   953   //   R17_tos         - address of caller's tos
   954   //   R1_SP           - caller's stack pointer
   955   //   R21_sender_SP   - initial caller sp
   956   //
   957   // Update
   958   //   R14_state       - address of caller's BytecodeInterpreter
   959   //   R3_RET          - integer result, if any.
   960   //   F1_RET          - float result, if any.
   961   //
   962   //
   963   // Stack layout at this point:
   964   //
   965   //    0       [TOP_IJAVA_FRAME_ABI]         <-- R1_SP
   966   //            alignment (optional)
   967   //            [outgoing Java arguments]     <-- R17_tos
   968   //            ...
   969   //    PARENT  [PARENT_IJAVA_FRAME_ABI]
   970   //            ...
   971   //
   973   const bool inc_counter = UseCompiler || CountCompiledCalls;
   975   const Register signature_handler_fd   = R21_tmp1;
   976   const Register pending_exception      = R22_tmp2;
   977   const Register result_handler_addr    = R23_tmp3;
   978   const Register native_method_fd       = R24_tmp4;
   979   const Register access_flags           = R25_tmp5;
   980   const Register active_handles         = R26_tmp6;
   981   const Register sync_state             = R27_tmp7;
   982   const Register sync_state_addr        = sync_state;     // Address is dead after use.
   983   const Register suspend_flags          = R24_tmp4;
   985   const Register return_pc              = R28_tmp8;       // Register will be locked for some time.
   987   const ConditionRegister is_synced     = CCR4_is_synced; // Live-on-exit from compute_interpreter_state.
   990   // R1_SP still points to caller's SP at this point.
   992   // Save initial_caller_sp to caller's abi. The caller frame must be
   993   // resized before returning to get rid of the c2i arguments (if
   994   // any).
   995   // Override the saved SP with the senderSP so we can pop c2i
   996   // arguments (if any) off when we return
   997   __ std(R21_sender_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);
   999   // Save LR to caller's frame. We don't use _abi(lr) here, because it is not safe.
  1000   __ mflr(return_pc);
  1001   __ std(return_pc, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
  1003   assert(return_pc->is_nonvolatile(), "return_pc must be a non-volatile register");
  1005   __ verify_method_ptr(R19_method);
  1007   //=============================================================================
  1009   // If this snippet gets called by the frame manager (at label
  1010   // `call_special'), then R15_prev_state is valid. If this snippet
  1011   // is not called by the frame manager, but e.g. by the call stub or
  1012   // by compiled code, then R15_prev_state is invalid.
  1014     // Set R15_prev_state to 0 if we don't return to the frame
  1015     // manager; we will return to the call_stub or to compiled code
  1016     // instead. If R15_prev_state is 0 there will be only one
  1017     // interpreter frame (we will set this up later) in this C frame!
  1018     // So we must take care about retrieving prev_state_(_prev_link)
  1019     // and restoring R1_SP when popping that interpreter.
  1020     Label prev_state_is_valid;
  1022     __ load_const(R11_scratch1/*frame_manager_returnpc_addr*/, (address)&frame_manager_specialized_return);
  1023     __ ld(R12_scratch2/*frame_manager_returnpc*/, 0, R11_scratch1/*frame_manager_returnpc_addr*/);
  1024     __ cmpd(CCR0, return_pc, R12_scratch2/*frame_manager_returnpc*/);
  1025     __ beq(CCR0, prev_state_is_valid);
  1027     __ li(R15_prev_state, 0);
  1029     __ BIND(prev_state_is_valid);
  1032   //=============================================================================
  1033   // Allocate new frame and initialize interpreter state.
  1035   Label exception_return;
  1036   Label exception_return_sync_check;
  1037   Label stack_overflow_return;
  1039   // Generate new interpreter state and jump to stack_overflow_return in case of
  1040   // a stack overflow.
  1041   generate_compute_interpreter_state(stack_overflow_return);
  1043   //=============================================================================
  1044   // Increment invocation counter. On overflow, entry to JNI method
  1045   // will be compiled.
  1046   Label invocation_counter_overflow;
  1047   if (inc_counter) {
  1048     generate_counter_incr(invocation_counter_overflow);
  1051   Label continue_after_compile;
  1052   __ BIND(continue_after_compile);
  1054   // access_flags = method->access_flags();
  1055   // Load access flags.
  1056   assert(access_flags->is_nonvolatile(),
  1057          "access_flags must be in a non-volatile register");
  1058   // Type check.
  1059   // TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");
  1060   __ lwz(access_flags, method_(access_flags));
  1062   // We don't want to reload R19_method and access_flags after calls
  1063   // to some helper functions.
  1064   assert(R19_method->is_nonvolatile(), "R19_method must be a non-volatile register");
  1066   // Check for synchronized methods. Must happen AFTER invocation counter
  1067   // check, so method is not locked if counter overflows.
  1070     Label method_is_not_synced;
  1071     // Is_synced is still alive.
  1072     assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");
  1073     __ bfalse(is_synced, method_is_not_synced);
  1075     lock_method();
  1076     // Reload method, it may have moved.
  1077     __ ld(R19_method, state_(_method));
  1079     __ BIND(method_is_not_synced);
  1082   // jvmti/jvmpi support
  1083   __ notify_method_entry();
  1085   // Reload method, it may have moved.
  1086   __ ld(R19_method, state_(_method));
  1088   //=============================================================================
  1089   // Get and call the signature handler
  1091   __ ld(signature_handler_fd, method_(signature_handler));
  1092   Label call_signature_handler;
  1094   __ cmpdi(CCR0, signature_handler_fd, 0);
  1095   __ bne(CCR0, call_signature_handler);
  1097   // Method has never been called. Either generate a specialized
  1098   // handler or point to the slow one.
  1099   //
  1100   // Pass parameter 'false' to avoid exception check in call_VM.
  1101   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), R19_method, false);
  1103   // Check for an exception while looking up the target method. If we
  1104   // incurred one, bail.
  1105   __ ld(pending_exception, thread_(pending_exception));
  1106   __ cmpdi(CCR0, pending_exception, 0);
  1107   __ bne(CCR0, exception_return_sync_check); // has pending exception
  1109   // reload method
  1110   __ ld(R19_method, state_(_method));
  1112   // Reload signature handler, it may have been created/assigned in the meanwhile
  1113   __ ld(signature_handler_fd, method_(signature_handler));
  1115   __ BIND(call_signature_handler);
  1117   // Before we call the signature handler we push a new frame to
  1118   // protect the interpreter frame volatile registers when we return
  1119   // from jni but before we can get back to Java.
  1121   // First set the frame anchor while the SP/FP registers are
  1122   // convenient and the slow signature handler can use this same frame
  1123   // anchor.
  1125   // We have a TOP_IJAVA_FRAME here, which belongs to us.
  1126   __ set_top_ijava_frame_at_SP_as_last_Java_frame(R1_SP, R12_scratch2/*tmp*/);
  1128   // Now the interpreter frame (and its call chain) have been
  1129   // invalidated and flushed. We are now protected against eager
  1130   // being enabled in native code. Even if it goes eager the
  1131   // registers will be reloaded as clean and we will invalidate after
  1132   // the call so no spurious flush should be possible.
  1134   // Call signature handler and pass locals address.
  1135   //
  1136   // Our signature handlers copy required arguments to the C stack
  1137   // (outgoing C args), R3_ARG1 to R10_ARG8, and F1_ARG1 to
  1138   // F13_ARG13.
  1139   __ mr(R3_ARG1, R18_locals);
  1140 #if !defined(ABI_ELFv2)
  1141   __ ld(signature_handler_fd, 0, signature_handler_fd);
  1142 #endif
  1143   __ call_stub(signature_handler_fd);
  1144   // reload method
  1145   __ ld(R19_method, state_(_method));
  1147   // Remove the register parameter varargs slots we allocated in
  1148   // compute_interpreter_state. SP+16 ends up pointing to the ABI
  1149   // outgoing argument area.
  1150   //
  1151   // Not needed on PPC64.
  1152   //__ add(SP, SP, Argument::n_register_parameters*BytesPerWord);
  1154   assert(result_handler_addr->is_nonvolatile(), "result_handler_addr must be in a non-volatile register");
  1155   // Save across call to native method.
  1156   __ mr(result_handler_addr, R3_RET);
  1158   // Set up fixed parameters and call the native method.
  1159   // If the method is static, get mirror into R4_ARG2.
  1162     Label method_is_not_static;
  1163     // access_flags is non-volatile and still, no need to restore it
  1165     // restore access flags
  1166     __ testbitdi(CCR0, R0, access_flags, JVM_ACC_STATIC_BIT);
  1167     __ bfalse(CCR0, method_is_not_static);
  1169     // constants = method->constants();
  1170     __ ld(R11_scratch1, in_bytes(Method::const_offset()), R19_method);
  1171     __ ld(R11_scratch1/*constants*/, in_bytes(ConstMethod::constants_offset()), R11_scratch1);
  1172     // pool_holder = method->constants()->pool_holder();
  1173     __ ld(R11_scratch1/*pool_holder*/, ConstantPool::pool_holder_offset_in_bytes(),
  1174           R11_scratch1/*constants*/);
  1176     const int mirror_offset = in_bytes(Klass::java_mirror_offset());
  1178     // mirror = pool_holder->klass_part()->java_mirror();
  1179     __ ld(R0/*mirror*/, mirror_offset, R11_scratch1/*pool_holder*/);
  1180     // state->_native_mirror = mirror;
  1181     __ std(R0/*mirror*/, state_(_oop_temp));
  1182     // R4_ARG2 = &state->_oop_temp;
  1183     __ addir(R4_ARG2, state_(_oop_temp));
  1185     __ BIND(method_is_not_static);
  1188   // At this point, arguments have been copied off the stack into
  1189   // their JNI positions. Oops are boxed in-place on the stack, with
  1190   // handles copied to arguments. The result handler address is in a
  1191   // register.
  1193   // pass JNIEnv address as first parameter
  1194   __ addir(R3_ARG1, thread_(jni_environment));
  1196   // Load the native_method entry before we change the thread state.
  1197   __ ld(native_method_fd, method_(native_function));
  1199   //=============================================================================
  1200   // Transition from _thread_in_Java to _thread_in_native. As soon as
  1201   // we make this change the safepoint code needs to be certain that
  1202   // the last Java frame we established is good. The pc in that frame
  1203   // just needs to be near here not an actual return address.
  1205   // We use release_store_fence to update values like the thread state, where
  1206   // we don't want the current thread to continue until all our prior memory
  1207   // accesses (including the new thread state) are visible to other threads.
  1208   __ li(R0, _thread_in_native);
  1209   __ release();
  1211   // TODO: PPC port: assert(4 == JavaThread::sz_thread_state(), "unexpected field size");
  1212   __ stw(R0, thread_(thread_state));
  1214   if (UseMembar) {
  1215     __ fence();
  1218   //=============================================================================
  1219   // Call the native method. Argument registers must not have been
  1220   // overwritten since "__ call_stub(signature_handler);" (except for
  1221   // ARG1 and ARG2 for static methods)
  1222   __ call_c(native_method_fd);
  1224   __ std(R3_RET, state_(_native_lresult));
  1225   __ stfd(F1_RET, state_(_native_fresult));
  1227   // The frame_manager_lr field, which we use for setting the last
  1228   // java frame, gets overwritten by the signature handler. Restore
  1229   // it now.
  1230   __ get_PC_trash_LR(R11_scratch1);
  1231   __ std(R11_scratch1, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
  1233   // Because of GC R19_method may no longer be valid.
  1235   // Block, if necessary, before resuming in _thread_in_Java state.
  1236   // In order for GC to work, don't clear the last_Java_sp until after
  1237   // blocking.
  1241   //=============================================================================
  1242   // Switch thread to "native transition" state before reading the
  1243   // synchronization state.  This additional state is necessary
  1244   // because reading and testing the synchronization state is not
  1245   // atomic w.r.t. GC, as this scenario demonstrates: Java thread A,
  1246   // in _thread_in_native state, loads _not_synchronized and is
  1247   // preempted.  VM thread changes sync state to synchronizing and
  1248   // suspends threads for GC. Thread A is resumed to finish this
  1249   // native method, but doesn't block here since it didn't see any
  1250   // synchronization in progress, and escapes.
  1252   // We use release_store_fence to update values like the thread state, where
  1253   // we don't want the current thread to continue until all our prior memory
  1254   // accesses (including the new thread state) are visible to other threads.
  1255   __ li(R0/*thread_state*/, _thread_in_native_trans);
  1256   __ release();
  1257   __ stw(R0/*thread_state*/, thread_(thread_state));
  1258   if (UseMembar) {
  1259     __ fence();
  1261   // Write serialization page so that the VM thread can do a pseudo remote
  1262   // membar. We use the current thread pointer to calculate a thread
  1263   // specific offset to write to within the page. This minimizes bus
  1264   // traffic due to cache line collision.
  1265   else {
  1266     __ serialize_memory(R16_thread, R11_scratch1, R12_scratch2);
  1269   // Now before we return to java we must look for a current safepoint
  1270   // (a new safepoint can not start since we entered native_trans).
  1271   // We must check here because a current safepoint could be modifying
  1272   // the callers registers right this moment.
  1274   // Acquire isn't strictly necessary here because of the fence, but
  1275   // sync_state is declared to be volatile, so we do it anyway.
  1276   __ load_const(sync_state_addr, SafepointSynchronize::address_of_state());
  1278   // TODO: PPC port: assert(4 == SafepointSynchronize::sz_state(), "unexpected field size");
  1279   __ lwz(sync_state, 0, sync_state_addr);
  1281   // TODO: PPC port: assert(4 == Thread::sz_suspend_flags(), "unexpected field size");
  1282   __ lwz(suspend_flags, thread_(suspend_flags));
  1284   __ acquire();
  1286   Label sync_check_done;
  1287   Label do_safepoint;
  1288   // No synchronization in progress nor yet synchronized
  1289   __ cmpwi(CCR0, sync_state, SafepointSynchronize::_not_synchronized);
  1290   // not suspended
  1291   __ cmpwi(CCR1, suspend_flags, 0);
  1293   __ bne(CCR0, do_safepoint);
  1294   __ beq(CCR1, sync_check_done);
  1295   __ bind(do_safepoint);
  1296   // Block.  We do the call directly and leave the current
  1297   // last_Java_frame setup undisturbed.  We must save any possible
  1298   // native result acrosss the call. No oop is present
  1300   __ mr(R3_ARG1, R16_thread);
  1301 #if defined(ABI_ELFv2)
  1302   __ call_c(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans),
  1303             relocInfo::none);
  1304 #else
  1305   __ call_c(CAST_FROM_FN_PTR(FunctionDescriptor*, JavaThread::check_special_condition_for_native_trans),
  1306             relocInfo::none);
  1307 #endif
  1308   __ bind(sync_check_done);
  1310   //=============================================================================
  1311   // <<<<<< Back in Interpreter Frame >>>>>
  1313   // We are in thread_in_native_trans here and back in the normal
  1314   // interpreter frame. We don't have to do anything special about
  1315   // safepoints and we can switch to Java mode anytime we are ready.
  1317   // Note: frame::interpreter_frame_result has a dependency on how the
  1318   // method result is saved across the call to post_method_exit. For
  1319   // native methods it assumes that the non-FPU/non-void result is
  1320   // saved in _native_lresult and a FPU result in _native_fresult. If
  1321   // this changes then the interpreter_frame_result implementation
  1322   // will need to be updated too.
  1324   // On PPC64, we have stored the result directly after the native call.
  1326   //=============================================================================
  1327   // back in Java
  1329   // We use release_store_fence to update values like the thread state, where
  1330   // we don't want the current thread to continue until all our prior memory
  1331   // accesses (including the new thread state) are visible to other threads.
  1332   __ li(R0/*thread_state*/, _thread_in_Java);
  1333   __ release();
  1334   __ stw(R0/*thread_state*/, thread_(thread_state));
  1335   if (UseMembar) {
  1336     __ fence();
  1339   __ reset_last_Java_frame();
  1341   // Reload GR27_method, call killed it. We can't look at
  1342   // state->_method until we're back in java state because in java
  1343   // state gc can't happen until we get to a safepoint.
  1344   //
  1345   // We've set thread_state to _thread_in_Java already, so restoring
  1346   // R19_method from R14_state works; R19_method is invalid, because
  1347   // GC may have happened.
  1348   __ ld(R19_method, state_(_method)); // reload method, may have moved
  1350   // jvmdi/jvmpi support. Whether we've got an exception pending or
  1351   // not, and whether unlocking throws an exception or not, we notify
  1352   // on native method exit. If we do have an exception, we'll end up
  1353   // in the caller's context to handle it, so if we don't do the
  1354   // notify here, we'll drop it on the floor.
  1356   __ notify_method_exit(true/*native method*/,
  1357                         ilgl /*illegal state (not used for native methods)*/,
  1358                         InterpreterMacroAssembler::NotifyJVMTI,
  1359                         false /*check_exceptions*/);
  1361   //=============================================================================
  1362   // Handle exceptions
  1364   // See if we must unlock.
  1365   //
  1367     Label method_is_not_synced;
  1368     // is_synced is still alive
  1369     assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");
  1370     __ bfalse(is_synced, method_is_not_synced);
  1372     unlock_method();
  1374     __ bind(method_is_not_synced);
  1377   // Reset active handles after returning from native.
  1378   // thread->active_handles()->clear();
  1379   __ ld(active_handles, thread_(active_handles));
  1380   // JNIHandleBlock::_top is an int.
  1381   // TODO:  PPC port: assert(4 == JNIHandleBlock::top_size_in_bytes(), "unexpected field size");
  1382   __ li(R0, 0);
  1383   __ stw(R0, JNIHandleBlock::top_offset_in_bytes(), active_handles);
  1385   Label no_pending_exception_from_native_method;
  1386   __ ld(R0/*pending_exception*/, thread_(pending_exception));
  1387   __ cmpdi(CCR0, R0/*pending_exception*/, 0);
  1388   __ beq(CCR0, no_pending_exception_from_native_method);
  1391   //-----------------------------------------------------------------------------
  1392   // An exception is pending. We call into the runtime only if the
  1393   // caller was not interpreted. If it was interpreted the
  1394   // interpreter will do the correct thing. If it isn't interpreted
  1395   // (call stub/compiled code) we will change our return and continue.
  1396   __ BIND(exception_return);
  1398   Label return_to_initial_caller_with_pending_exception;
  1399   __ cmpdi(CCR0, R15_prev_state, 0);
  1400   __ beq(CCR0, return_to_initial_caller_with_pending_exception);
  1402   // We are returning to an interpreter activation, just pop the state,
  1403   // pop our frame, leave the exception pending, and return.
  1404   __ pop_interpreter_state(/*prev_state_may_be_0=*/false);
  1405   __ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1 /* set to return pc */, R22_tmp2);
  1406   __ mtlr(R21_tmp1);
  1407   __ blr();
  1409   __ BIND(exception_return_sync_check);
  1411   assert(is_synced->is_nonvolatile(), "is_synced must be non-volatile");
  1412   __ bfalse(is_synced, exception_return);
  1413   unlock_method();
  1414   __ b(exception_return);
  1417   __ BIND(return_to_initial_caller_with_pending_exception);
  1418   // We are returning to a c2i-adapter / call-stub, get the address of the
  1419   // exception handler, pop the frame and return to the handler.
  1421   // First, pop to caller's frame.
  1422   __ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1  /* set to return pc */, R22_tmp2);
  1424   __ push_frame_reg_args(0, R11_scratch1);
  1425   // Get the address of the exception handler.
  1426   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
  1427                   R16_thread,
  1428                   R21_tmp1 /* return pc */);
  1429   __ pop_frame();
  1431   // Load the PC of the the exception handler into LR.
  1432   __ mtlr(R3_RET);
  1434   // Load exception into R3_ARG1 and clear pending exception in thread.
  1435   __ ld(R3_ARG1/*exception*/, thread_(pending_exception));
  1436   __ li(R4_ARG2, 0);
  1437   __ std(R4_ARG2, thread_(pending_exception));
  1439   // Load the original return pc into R4_ARG2.
  1440   __ mr(R4_ARG2/*issuing_pc*/, R21_tmp1);
  1442   // Resize frame to get rid of a potential extension.
  1443   __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
  1445   // Return to exception handler.
  1446   __ blr();
  1449   //-----------------------------------------------------------------------------
  1450   // No exception pending.
  1451   __ BIND(no_pending_exception_from_native_method);
  1453   // Move native method result back into proper registers and return.
  1454   // Invoke result handler (may unbox/promote).
  1455   __ ld(R3_RET, state_(_native_lresult));
  1456   __ lfd(F1_RET, state_(_native_fresult));
  1457   __ call_stub(result_handler_addr);
  1459   // We have created a new BytecodeInterpreter object, now we must destroy it.
  1460   //
  1461   // Restore previous R14_state and caller's SP.  R15_prev_state may
  1462   // be 0 here, because our caller may be the call_stub or compiled
  1463   // code.
  1464   __ pop_interpreter_state(/*prev_state_may_be_0=*/true);
  1465   __ pop_interpreter_frame(R11_scratch1, R12_scratch2, R21_tmp1 /* set to return pc */, R22_tmp2);
  1466   // Resize frame to get rid of a potential extension.
  1467   __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
  1469   // Must use the return pc which was loaded from the caller's frame
  1470   // as the VM uses return-pc-patching for deoptimization.
  1471   __ mtlr(R21_tmp1);
  1472   __ blr();
  1476   //=============================================================================
  1477   // We encountered an exception while computing the interpreter
  1478   // state, so R14_state isn't valid. Act as if we just returned from
  1479   // the callee method with a pending exception.
  1480   __ BIND(stack_overflow_return);
  1482   //
  1483   // Register state:
  1484   //   R14_state         invalid; trashed by compute_interpreter_state
  1485   //   R15_prev_state    valid, but may be 0
  1486   //
  1487   //   R1_SP             valid, points to caller's SP; wasn't yet updated by
  1488   //                     compute_interpreter_state
  1489   //
  1491   // Create exception oop and make it pending.
  1493   // Throw the exception via RuntimeStub "throw_StackOverflowError_entry".
  1494   //
  1495   // Previously, we called C-Code directly. As a consequence, a
  1496   // possible GC tried to process the argument oops of the top frame
  1497   // (see RegisterMap::clear, which sets the corresponding flag to
  1498   // true). This lead to crashes because:
  1499   //   1. The top register map did not contain locations for the argument registers
  1500   //   2. The arguments are dead anyway, could be already overwritten in the worst case
  1501   // Solution: Call via special runtime stub that pushes it's own
  1502   // frame. This runtime stub has the flag "CodeBlob::caller_must_gc_arguments()"
  1503   // set to "false", what prevents the dead arguments getting GC'd.
  1504   //
  1505   // 2 cases exist:
  1506   // 1. We were called by the c2i adapter / call stub
  1507   // 2. We were called by the frame manager
  1508   //
  1509   // Both cases are handled by this code:
  1510   // 1. - initial_caller_sp was saved in both cases on entry, so it's safe to load it back even if it was not changed.
  1511   //    - control flow will be:
  1512   //      throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->excp_blob of caller method
  1513   // 2. - control flow will be:
  1514   //      throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->rethrow_excp_entry of frame manager->resume_method
  1515   //      Since we restored the caller SP above, the rethrow_excp_entry can restore the original interpreter state
  1516   //      registers using the stack and resume the calling method with a pending excp.
  1518   // Pop any c2i extension from the stack, restore LR just to be sure
  1519   __ ld(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
  1520   __ mtlr(R0);
  1521   // Resize frame to get rid of a potential extension.
  1522   __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
  1524   assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "generated in wrong order");
  1525   // Load target address of the runtime stub.
  1526   __ load_const(R12_scratch2, (StubRoutines::throw_StackOverflowError_entry()));
  1527   __ mtctr(R12_scratch2);
  1528   __ bctr();
  1531   //=============================================================================
  1532   // Counter overflow.
  1534   if (inc_counter) {
  1535     // Handle invocation counter overflow
  1536     __ bind(invocation_counter_overflow);
  1538     generate_counter_overflow(continue_after_compile);
  1541   native_entry = entry;
  1542   return entry;
  1545 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  1546   // No special entry points that preclude compilation.
  1547   return true;
  1550 // Unlock the current method.
  1551 //
  1552 void CppInterpreterGenerator::unlock_method(void) {
  1553   // Find preallocated monitor and unlock method. Method monitor is
  1554   // the first one.
  1556   // Registers alive
  1557   //   R14_state
  1558   //
  1559   // Registers updated
  1560   //   volatiles
  1561   //
  1562   const Register monitor = R4_ARG2;
  1564   // Pass address of initial monitor we allocated.
  1565   //
  1566   // First monitor.
  1567   __ addi(monitor, R14_state, -frame::interpreter_frame_monitor_size_in_bytes());
  1569   // Unlock method
  1570   __ unlock_object(monitor);
  1573 // Lock the current method.
  1574 //
  1575 void CppInterpreterGenerator::lock_method(void) {
  1576   // Find preallocated monitor and lock method. Method monitor is the
  1577   // first one.
  1579   //
  1580   // Registers alive
  1581   //   R14_state
  1582   //
  1583   // Registers updated
  1584   //   volatiles
  1585   //
  1587   const Register monitor = R4_ARG2;
  1588   const Register object  = R5_ARG3;
  1590   // Pass address of initial monitor we allocated.
  1591   __ addi(monitor, R14_state, -frame::interpreter_frame_monitor_size_in_bytes());
  1593   // Pass object address.
  1594   __ ld(object, BasicObjectLock::obj_offset_in_bytes(), monitor);
  1596   // Lock method.
  1597   __ lock_object(monitor, object);
  1600 // Generate code for handling resuming a deopted method.
  1601 void CppInterpreterGenerator::generate_deopt_handling(Register result_index) {
  1603   //=============================================================================
  1604   // Returning from a compiled method into a deopted method. The
  1605   // bytecode at the bcp has completed. The result of the bytecode is
  1606   // in the native abi (the tosca for the template based
  1607   // interpreter). Any stack space that was used by the bytecode that
  1608   // has completed has been removed (e.g. parameters for an invoke) so
  1609   // all that we have to do is place any pending result on the
  1610   // expression stack and resume execution on the next bytecode.
  1612   Label return_from_deopt_common;
  1614   // R3_RET and F1_RET are live here! Load the array index of the
  1615   // required result stub address and continue at return_from_deopt_common.
  1617   // Deopt needs to jump to here to enter the interpreter (return a result).
  1618   deopt_frame_manager_return_atos = __ pc();
  1619   __ li(result_index, AbstractInterpreter::BasicType_as_index(T_OBJECT));
  1620   __ b(return_from_deopt_common);
  1622   deopt_frame_manager_return_btos = __ pc();
  1623   __ li(result_index, AbstractInterpreter::BasicType_as_index(T_BOOLEAN));
  1624   __ b(return_from_deopt_common);
  1626   deopt_frame_manager_return_itos = __ pc();
  1627   __ li(result_index, AbstractInterpreter::BasicType_as_index(T_INT));
  1628   __ b(return_from_deopt_common);
  1630   deopt_frame_manager_return_ltos = __ pc();
  1631   __ li(result_index, AbstractInterpreter::BasicType_as_index(T_LONG));
  1632   __ b(return_from_deopt_common);
  1634   deopt_frame_manager_return_ftos = __ pc();
  1635   __ li(result_index, AbstractInterpreter::BasicType_as_index(T_FLOAT));
  1636   __ b(return_from_deopt_common);
  1638   deopt_frame_manager_return_dtos = __ pc();
  1639   __ li(result_index, AbstractInterpreter::BasicType_as_index(T_DOUBLE));
  1640   __ b(return_from_deopt_common);
  1642   deopt_frame_manager_return_vtos = __ pc();
  1643   __ li(result_index, AbstractInterpreter::BasicType_as_index(T_VOID));
  1644   // Last one, fall-through to return_from_deopt_common.
  1646   // Deopt return common. An index is present that lets us move any
  1647   // possible result being return to the interpreter's stack.
  1648   //
  1649   __ BIND(return_from_deopt_common);
  1653 // Generate the code to handle a more_monitors message from the c++ interpreter.
  1654 void CppInterpreterGenerator::generate_more_monitors() {
  1656   //
  1657   // Registers alive
  1658   //   R16_thread      - JavaThread*
  1659   //   R15_prev_state  - previous BytecodeInterpreter or 0
  1660   //   R14_state       - BytecodeInterpreter* address of receiver's interpreter state
  1661   //   R1_SP           - old stack pointer
  1662   //
  1663   // Registers updated
  1664   //   R1_SP          - new stack pointer
  1665   //
  1667   // Very-local scratch registers.
  1668   const Register old_tos         = R21_tmp1;
  1669   const Register new_tos         = R22_tmp2;
  1670   const Register stack_base      = R23_tmp3;
  1671   const Register stack_limit     = R24_tmp4;
  1672   const Register slot            = R25_tmp5;
  1673   const Register n_slots         = R25_tmp5;
  1675   // Interpreter state fields.
  1676   const Register msg             = R24_tmp4;
  1678   // Load up relevant interpreter state.
  1680   __ ld(stack_base, state_(_stack_base));                // Old stack_base
  1681   __ ld(old_tos, state_(_stack));                        // Old tos
  1682   __ ld(stack_limit, state_(_stack_limit));              // Old stack_limit
  1684   // extracted monitor_size
  1685   int monitor_size = frame::interpreter_frame_monitor_size_in_bytes();
  1686   assert(Assembler::is_aligned((unsigned int)monitor_size,
  1687                                (unsigned int)frame::alignment_in_bytes),
  1688          "size of a monitor must respect alignment of SP");
  1690   // Save and restore top LR
  1691   __ ld(R12_scratch2, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
  1692   __ resize_frame(-monitor_size, R11_scratch1);// Allocate space for new monitor
  1693   __ std(R12_scratch2, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
  1694     // Initial_caller_sp is used as unextended_sp for non initial callers.
  1695   __ std(R1_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);
  1696   __ addi(stack_base, stack_base, -monitor_size);        // New stack_base
  1697   __ addi(new_tos, old_tos, -monitor_size);              // New tos
  1698   __ addi(stack_limit, stack_limit, -monitor_size);      // New stack_limit
  1700   __ std(R1_SP, state_(_last_Java_sp));                  // Update frame_bottom
  1702   __ std(stack_base, state_(_stack_base));               // Update stack_base
  1703   __ std(new_tos, state_(_stack));                       // Update tos
  1704   __ std(stack_limit, state_(_stack_limit));             // Update stack_limit
  1706   __ li(msg, BytecodeInterpreter::got_monitors);         // Tell interpreter we allocated the lock
  1707   __ stw(msg, state_(_msg));
  1709   // Shuffle expression stack down. Recall that stack_base points
  1710   // just above the new expression stack bottom. Old_tos and new_tos
  1711   // are used to scan thru the old and new expression stacks.
  1713   Label copy_slot, copy_slot_finished;
  1714   __ sub(n_slots, stack_base, new_tos);
  1715   __ srdi_(n_slots, n_slots, LogBytesPerWord);           // compute number of slots to copy
  1716   assert(LogBytesPerWord == 3, "conflicts assembler instructions");
  1717   __ beq(CCR0, copy_slot_finished);                       // nothing to copy
  1719   __ mtctr(n_slots);
  1721   // loop
  1722   __ bind(copy_slot);
  1723   __ ldu(slot, BytesPerWord, old_tos);                   // slot = *++old_tos;
  1724   __ stdu(slot, BytesPerWord, new_tos);                  // *++new_tos = slot;
  1725   __ bdnz(copy_slot);
  1727   __ bind(copy_slot_finished);
  1729   // Restart interpreter
  1730   __ li(R0, 0);
  1731   __ std(R0, BasicObjectLock::obj_offset_in_bytes(), stack_base);  // Mark lock as unused
  1734 address CppInterpreterGenerator::generate_normal_entry(void) {
  1735   if (interpreter_frame_manager != NULL) return interpreter_frame_manager;
  1737   address entry = __ pc();
  1739   address return_from_native_pc = (address) NULL;
  1741   // Initial entry to frame manager (from call_stub or c2i_adapter)
  1743   //
  1744   // Registers alive
  1745   //   R16_thread               - JavaThread*
  1746   //   R19_method               - callee's Method (method to be invoked)
  1747   //   R17_tos                  - address of sender tos (prepushed)
  1748   //   R1_SP                    - SP prepared by call stub such that caller's outgoing args are near top
  1749   //   LR                       - return address to caller (call_stub or c2i_adapter)
  1750   //   R21_sender_SP            - initial caller sp
  1751   //
  1752   // Registers updated
  1753   //   R15_prev_state           - 0
  1754   //
  1755   // Stack layout at this point:
  1756   //
  1757   //   0       [TOP_IJAVA_FRAME_ABI]         <-- R1_SP
  1758   //           alignment (optional)
  1759   //           [outgoing Java arguments]     <-- R17_tos
  1760   //           ...
  1761   //   PARENT  [PARENT_IJAVA_FRAME_ABI]
  1762   //           ...
  1763   //
  1765   // Save initial_caller_sp to caller's abi.
  1766   // The caller frame must be resized before returning to get rid of
  1767   // the c2i part on top of the calling compiled frame (if any).
  1768   // R21_tmp1 must match sender_sp in gen_c2i_adapter.
  1769   // Now override the saved SP with the senderSP so we can pop c2i
  1770   // arguments (if any) off when we return.
  1771   __ std(R21_sender_SP, _top_ijava_frame_abi(initial_caller_sp), R1_SP);
  1773   // Save LR to caller's frame. We don't use _abi(lr) here,
  1774   // because it is not safe.
  1775   __ mflr(R0);
  1776   __ std(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
  1778   // If we come here, it is the first invocation of the frame manager.
  1779   // So there is no previous interpreter state.
  1780   __ li(R15_prev_state, 0);
  1783   // Fall through to where "recursive" invocations go.
  1785   //=============================================================================
  1786   // Dispatch an instance of the interpreter. Recursive activations
  1787   // come here.
  1789   Label re_dispatch;
  1790   __ BIND(re_dispatch);
  1792   //
  1793   // Registers alive
  1794   //    R16_thread        - JavaThread*
  1795   //    R19_method        - callee's Method
  1796   //    R17_tos           - address of caller's tos (prepushed)
  1797   //    R15_prev_state    - address of caller's BytecodeInterpreter or 0
  1798   //    R1_SP             - caller's SP trimmed such that caller's outgoing args are near top.
  1799   //
  1800   // Stack layout at this point:
  1801   //
  1802   //   0       [TOP_IJAVA_FRAME_ABI]
  1803   //           alignment (optional)
  1804   //           [outgoing Java arguments]
  1805   //           ...
  1806   //   PARENT  [PARENT_IJAVA_FRAME_ABI]
  1807   //           ...
  1809   // fall through to interpreted execution
  1811   //=============================================================================
  1812   // Allocate a new Java frame and initialize the new interpreter state.
  1814   Label stack_overflow_return;
  1816   // Create a suitable new Java frame plus a new BytecodeInterpreter instance
  1817   // in the current (frame manager's) C frame.
  1818   generate_compute_interpreter_state(stack_overflow_return);
  1820   // fall through
  1822   //=============================================================================
  1823   // Interpreter dispatch.
  1825   Label call_interpreter;
  1826   __ BIND(call_interpreter);
  1828   //
  1829   // Registers alive
  1830   //   R16_thread       - JavaThread*
  1831   //   R15_prev_state   - previous BytecodeInterpreter or 0
  1832   //   R14_state        - address of receiver's BytecodeInterpreter
  1833   //   R1_SP            - receiver's stack pointer
  1834   //
  1836   // Thread fields.
  1837   const Register pending_exception = R21_tmp1;
  1839   // Interpreter state fields.
  1840   const Register msg               = R24_tmp4;
  1842   // Method fields.
  1843   const Register parameter_count   = R25_tmp5;
  1844   const Register result_index      = R26_tmp6;
  1846   const Register dummy             = R28_tmp8;
  1848   // Address of various interpreter stubs.
  1849   // R29_tmp9 is reserved.
  1850   const Register stub_addr         = R27_tmp7;
  1852   // Uncommon trap needs to jump to here to enter the interpreter
  1853   // (re-execute current bytecode).
  1854   unctrap_frame_manager_entry  = __ pc();
  1856   // If we are profiling, store our fp (BSP) in the thread so we can
  1857   // find it during a tick.
  1858   if (Arguments::has_profile()) {
  1859     // On PPC64 we store the pointer to the current BytecodeInterpreter,
  1860     // instead of the bsp of ia64. This should suffice to be able to
  1861     // find all interesting information.
  1862     __ std(R14_state, thread_(last_interpreter_fp));
  1865   // R16_thread, R14_state and R15_prev_state are nonvolatile
  1866   // registers. There is no need to save these. If we needed to save
  1867   // some state in the current Java frame, this could be a place to do
  1868   // so.
  1870   // Call Java bytecode dispatcher passing "BytecodeInterpreter* istate".
  1871   __ call_VM_leaf(CAST_FROM_FN_PTR(address,
  1872                                    JvmtiExport::can_post_interpreter_events()
  1873                                    ? BytecodeInterpreter::runWithChecks
  1874                                    : BytecodeInterpreter::run),
  1875                   R14_state);
  1877   interpreter_return_address  = __ last_calls_return_pc();
  1879   // R16_thread, R14_state and R15_prev_state have their values preserved.
  1881   // If we are profiling, clear the fp in the thread to tell
  1882   // the profiler that we are no longer in the interpreter.
  1883   if (Arguments::has_profile()) {
  1884     __ li(R11_scratch1, 0);
  1885     __ std(R11_scratch1, thread_(last_interpreter_fp));
  1888   // Load message from bytecode dispatcher.
  1889   // TODO: PPC port: guarantee(4 == BytecodeInterpreter::sz_msg(), "unexpected field size");
  1890   __ lwz(msg, state_(_msg));
  1893   Label more_monitors;
  1894   Label return_from_native;
  1895   Label return_from_native_common;
  1896   Label return_from_native_no_exception;
  1897   Label return_from_interpreted_method;
  1898   Label return_from_recursive_activation;
  1899   Label unwind_recursive_activation;
  1900   Label resume_interpreter;
  1901   Label return_to_initial_caller;
  1902   Label unwind_initial_activation;
  1903   Label unwind_initial_activation_pending_exception;
  1904   Label call_method;
  1905   Label call_special;
  1906   Label retry_method;
  1907   Label retry_method_osr;
  1908   Label popping_frame;
  1909   Label throwing_exception;
  1911   // Branch according to the received message
  1913   __ cmpwi(CCR1, msg, BytecodeInterpreter::call_method);
  1914   __ cmpwi(CCR2, msg, BytecodeInterpreter::return_from_method);
  1916   __ beq(CCR1, call_method);
  1917   __ beq(CCR2, return_from_interpreted_method);
  1919   __ cmpwi(CCR3, msg, BytecodeInterpreter::more_monitors);
  1920   __ cmpwi(CCR4, msg, BytecodeInterpreter::throwing_exception);
  1922   __ beq(CCR3, more_monitors);
  1923   __ beq(CCR4, throwing_exception);
  1925   __ cmpwi(CCR5, msg, BytecodeInterpreter::popping_frame);
  1926   __ cmpwi(CCR6, msg, BytecodeInterpreter::do_osr);
  1928   __ beq(CCR5, popping_frame);
  1929   __ beq(CCR6, retry_method_osr);
  1931   __ stop("bad message from interpreter");
  1934   //=============================================================================
  1935   // Add a monitor just below the existing one(s). State->_stack_base
  1936   // points to the lowest existing one, so we insert the new one just
  1937   // below it and shuffle the expression stack down. Ref. the above
  1938   // stack layout picture, we must update _stack_base, _stack, _stack_limit
  1939   // and _last_Java_sp in the interpreter state.
  1941   __ BIND(more_monitors);
  1943   generate_more_monitors();
  1944   __ b(call_interpreter);
  1946   generate_deopt_handling(result_index);
  1948   // Restoring the R14_state is already done by the deopt_blob.
  1950   // Current tos includes no parameter slots.
  1951   __ ld(R17_tos, state_(_stack));
  1952   __ li(msg, BytecodeInterpreter::deopt_resume);
  1953   __ b(return_from_native_common);
  1955   // We are sent here when we are unwinding from a native method or
  1956   // adapter with an exception pending. We need to notify the interpreter
  1957   // that there is an exception to process.
  1958   // We arrive here also if the frame manager called an (interpreted) target
  1959   // which returns with a StackOverflow exception.
  1960   // The control flow is in this case is:
  1961   // frame_manager->throw_excp_stub->forward_excp->rethrow_excp_entry
  1963   AbstractInterpreter::_rethrow_exception_entry = __ pc();
  1965   // Restore R14_state.
  1966   __ ld(R14_state, 0, R1_SP);
  1967   __ addi(R14_state, R14_state,
  1968               -frame::interpreter_frame_cinterpreterstate_size_in_bytes());
  1970   // Store exception oop into thread object.
  1971   __ std(R3_RET, thread_(pending_exception));
  1972   __ li(msg, BytecodeInterpreter::method_resume /*rethrow_exception*/);
  1973   //
  1974   // NOTE: the interpreter frame as setup be deopt does NOT include
  1975   // any parameter slots (good thing since we have no callee here
  1976   // and couldn't remove them) so we don't have to do any calculations
  1977   // here to figure it out.
  1978   //
  1979   __ ld(R17_tos, state_(_stack));
  1980   __ b(return_from_native_common);
  1983   //=============================================================================
  1984   // Returning from a native method.  Result is in the native abi
  1985   // location so we must move it to the java expression stack.
  1987   __ BIND(return_from_native);
  1988   guarantee(return_from_native_pc == (address) NULL, "precondition");
  1989   return_from_native_pc = __ pc();
  1991   // Restore R14_state.
  1992   __ ld(R14_state, 0, R1_SP);
  1993   __ addi(R14_state, R14_state, -frame::interpreter_frame_cinterpreterstate_size_in_bytes());
  1995   //
  1996   // Registers alive
  1997   //   R16_thread
  1998   //   R14_state    - address of caller's BytecodeInterpreter.
  1999   //   R3_RET       - integer result, if any.
  2000   //   F1_RET       - float result, if any.
  2001   //
  2002   // Registers updated
  2003   //   R19_method   - callee's Method
  2004   //   R17_tos      - caller's tos, with outgoing args popped
  2005   //   result_index - index of result handler.
  2006   //   msg          - message for resuming interpreter.
  2007   //
  2009   // Very-local scratch registers.
  2011   const ConditionRegister have_pending_exception = CCR0;
  2013   // Load callee Method, gc may have moved it.
  2014   __ ld(R19_method, state_(_result._to_call._callee));
  2016   // Load address of caller's tos. includes parameter slots.
  2017   __ ld(R17_tos, state_(_stack));
  2019   // Pop callee's parameters.
  2021   __ ld(parameter_count, in_bytes(Method::const_offset()), R19_method);
  2022   __ lhz(parameter_count, in_bytes(ConstMethod::size_of_parameters_offset()), parameter_count);
  2023   __ sldi(parameter_count, parameter_count, Interpreter::logStackElementSize);
  2024   __ add(R17_tos, R17_tos, parameter_count);
  2026   // Result stub address array index
  2027   // TODO: PPC port: assert(4 == sizeof(AccessFlags), "unexpected field size");
  2028   __ lwa(result_index, method_(result_index));
  2030   __ li(msg, BytecodeInterpreter::method_resume);
  2032   //
  2033   // Registers alive
  2034   //   R16_thread
  2035   //   R14_state    - address of caller's BytecodeInterpreter.
  2036   //   R17_tos      - address of caller's tos with outgoing args already popped
  2037   //   R3_RET       - integer return value, if any.
  2038   //   F1_RET       - float return value, if any.
  2039   //   result_index - index of result handler.
  2040   //   msg          - message for resuming interpreter.
  2041   //
  2042   // Registers updated
  2043   //   R3_RET       - new address of caller's tos, including result, if any
  2044   //
  2046   __ BIND(return_from_native_common);
  2048   // Check for pending exception
  2049   __ ld(pending_exception, thread_(pending_exception));
  2050   __ cmpdi(CCR0, pending_exception, 0);
  2051   __ beq(CCR0, return_from_native_no_exception);
  2053   // If there's a pending exception, we really have no result, so
  2054   // R3_RET is dead. Resume_interpreter assumes the new tos is in
  2055   // R3_RET.
  2056   __ mr(R3_RET, R17_tos);
  2057   // `resume_interpreter' expects R15_prev_state to be alive.
  2058   __ ld(R15_prev_state, state_(_prev_link));
  2059   __ b(resume_interpreter);
  2061   __ BIND(return_from_native_no_exception);
  2063   // No pending exception, copy method result from native ABI register
  2064   // to tos.
  2066   // Address of stub descriptor address array.
  2067   __ load_const(stub_addr, CppInterpreter::tosca_result_to_stack());
  2069   // Pass address of tos to stub.
  2070   __ mr(R4_ARG2, R17_tos);
  2072   // Address of stub descriptor address.
  2073   __ sldi(result_index, result_index, LogBytesPerWord);
  2074   __ add(stub_addr, stub_addr, result_index);
  2076   // Stub descriptor address.
  2077   __ ld(stub_addr, 0, stub_addr);
  2079   // TODO: don't do this via a call, do it in place!
  2080   //
  2081   // call stub via descriptor
  2082   // in R3_ARG1/F1_ARG1: result value (R3_RET or F1_RET)
  2083   __ call_stub(stub_addr);
  2085   // new tos = result of call in R3_RET
  2087   // `resume_interpreter' expects R15_prev_state to be alive.
  2088   __ ld(R15_prev_state, state_(_prev_link));
  2089   __ b(resume_interpreter);
  2091   //=============================================================================
  2092   // We encountered an exception while computing the interpreter
  2093   // state, so R14_state isn't valid. Act as if we just returned from
  2094   // the callee method with a pending exception.
  2095   __ BIND(stack_overflow_return);
  2097   //
  2098   // Registers alive
  2099   //   R16_thread        - JavaThread*
  2100   //   R1_SP             - old stack pointer
  2101   //   R19_method        - callee's Method
  2102   //   R17_tos           - address of caller's tos (prepushed)
  2103   //   R15_prev_state    - address of caller's BytecodeInterpreter or 0
  2104   //   R18_locals        - address of callee's locals array
  2105   //
  2106   // Registers updated
  2107   //   R3_RET           - address of resuming tos, if recursive unwind
  2109   Label Lskip_unextend_SP;
  2112   const ConditionRegister is_initial_call = CCR0;
  2113   const Register tos_save = R21_tmp1;
  2114   const Register tmp = R22_tmp2;
  2116   assert(tos_save->is_nonvolatile(), "need a nonvolatile");
  2118   // Is the exception thrown in the initial Java frame of this frame
  2119   // manager frame?
  2120   __ cmpdi(is_initial_call, R15_prev_state, 0);
  2121   __ bne(is_initial_call, Lskip_unextend_SP);
  2123   // Pop any c2i extension from the stack. This is necessary in the
  2124   // non-recursive case (that is we were called by the c2i adapter,
  2125   // meaning we have to prev state). In this case we entered the frame
  2126   // manager through a special entry which pushes the orignal
  2127   // unextended SP to the stack. Here we load it back.
  2128   __ ld(R0, _top_ijava_frame_abi(frame_manager_lr), R1_SP);
  2129   __ mtlr(R0);
  2130   // Resize frame to get rid of a potential extension.
  2131   __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
  2133   // Fall through
  2135   __ bind(Lskip_unextend_SP);
  2137   // Throw the exception via RuntimeStub "throw_StackOverflowError_entry".
  2138   //
  2139   // Previously, we called C-Code directly. As a consequence, a
  2140   // possible GC tried to process the argument oops of the top frame
  2141   // (see RegisterMap::clear, which sets the corresponding flag to
  2142   // true). This lead to crashes because:
  2143   // 1. The top register map did not contain locations for the argument registers
  2144   // 2. The arguments are dead anyway, could be already overwritten in the worst case
  2145   // Solution: Call via special runtime stub that pushes it's own frame. This runtime stub has the flag
  2146   // "CodeBlob::caller_must_gc_arguments()" set to "false", what prevents the dead arguments getting GC'd.
  2147   //
  2148   // 2 cases exist:
  2149   // 1. We were called by the c2i adapter / call stub
  2150   // 2. We were called by the frame manager
  2151   //
  2152   // Both cases are handled by this code:
  2153   // 1. - initial_caller_sp was saved on stack => Load it back and we're ok
  2154   //    - control flow will be:
  2155   //      throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->excp_blob of calling method
  2156   // 2. - control flow will be:
  2157   //      throw_stackoverflow_stub->VM->throw_stackoverflow_stub->forward_excep->
  2158   //        ->rethrow_excp_entry of frame manager->resume_method
  2159   //      Since we restored the caller SP above, the rethrow_excp_entry can restore the original interpreter state
  2160   //      registers using the stack and resume the calling method with a pending excp.
  2162   assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "generated in wrong order");
  2163   __ load_const(R3_ARG1, (StubRoutines::throw_StackOverflowError_entry()));
  2164   __ mtctr(R3_ARG1);
  2165   __ bctr();
  2167   //=============================================================================
  2168   // We have popped a frame from an interpreted call. We are assured
  2169   // of returning to an interpreted call by the popframe abi. We have
  2170   // no return value all we have to do is pop the current frame and
  2171   // then make sure that the top of stack (of the caller) gets set to
  2172   // where it was when we entered the callee (i.e. the args are still
  2173   // in place).  Or we are returning to the interpreter. In the first
  2174   // case we must extract result (if any) from the java expression
  2175   // stack and store it in the location the native abi would expect
  2176   // for a call returning this type. In the second case we must simply
  2177   // do a stack to stack move as we unwind.
  2179   __ BIND(popping_frame);
  2181   // Registers alive
  2182   //   R14_state
  2183   //   R15_prev_state
  2184   //   R17_tos
  2185   //
  2186   // Registers updated
  2187   //   R19_method
  2188   //   R3_RET
  2189   //   msg
  2191     Label L;
  2193     // Reload callee method, gc may have moved it.
  2194     __ ld(R19_method, state_(_method));
  2196     // We may be returning to a deoptimized frame in which case the
  2197     // usual assumption of a recursive return is not true.
  2199     // not equal = is recursive call
  2200     __ cmpdi(CCR0, R15_prev_state, 0);
  2202     __ bne(CCR0, L);
  2204     // Pop_frame capability.
  2205     // The pop_frame api says that the underlying frame is a Java frame, in this case
  2206     // (prev_state==null) it must be a compiled frame:
  2207     //
  2208     // Stack at this point: I, C2I + C, ...
  2209     //
  2210     // The outgoing arguments of the call have just been copied (popframe_preserve_args).
  2211     // By the pop_frame api, we must end up in an interpreted frame. So the compiled frame
  2212     // will be deoptimized. Deoptimization will restore the outgoing arguments from
  2213     // popframe_preserve_args, adjust the tos such that it includes the popframe_preserve_args,
  2214     // and adjust the bci such that the call will be executed again.
  2215     // We have no results, just pop the interpreter frame, resize the compiled frame to get rid
  2216     // of the c2i extension and return to the deopt_handler.
  2217     __ b(unwind_initial_activation);
  2219     // is recursive call
  2220     __ bind(L);
  2222     // Resume_interpreter expects the original tos in R3_RET.
  2223     __ ld(R3_RET, prev_state_(_stack));
  2225     // We're done.
  2226     __ li(msg, BytecodeInterpreter::popping_frame);
  2228     __ b(unwind_recursive_activation);
  2232   //=============================================================================
  2234   // We have finished an interpreted call. We are either returning to
  2235   // native (call_stub/c2) or we are returning to the interpreter.
  2236   // When returning to native, we must extract the result (if any)
  2237   // from the java expression stack and store it in the location the
  2238   // native abi expects. When returning to the interpreter we must
  2239   // simply do a stack to stack move as we unwind.
  2241   __ BIND(return_from_interpreted_method);
  2243   //
  2244   // Registers alive
  2245   //   R16_thread     - JavaThread*
  2246   //   R15_prev_state - address of caller's BytecodeInterpreter or 0
  2247   //   R14_state      - address of callee's interpreter state
  2248   //   R1_SP          - callee's stack pointer
  2249   //
  2250   // Registers updated
  2251   //   R19_method     - callee's method
  2252   //   R3_RET         - address of result (new caller's tos),
  2253   //
  2254   // if returning to interpreted
  2255   //   msg  - message for interpreter,
  2256   // if returning to interpreted
  2257   //
  2259   // Check if this is the initial invocation of the frame manager.
  2260   // If so, R15_prev_state will be null.
  2261   __ cmpdi(CCR0, R15_prev_state, 0);
  2263   // Reload callee method, gc may have moved it.
  2264   __ ld(R19_method, state_(_method));
  2266   // Load the method's result type.
  2267   __ lwz(result_index, method_(result_index));
  2269   // Go to return_to_initial_caller if R15_prev_state is null.
  2270   __ beq(CCR0, return_to_initial_caller);
  2272   // Copy callee's result to caller's expression stack via inline stack-to-stack
  2273   // converters.
  2275     Register new_tos   = R3_RET;
  2276     Register from_temp = R4_ARG2;
  2277     Register from      = R5_ARG3;
  2278     Register tos       = R6_ARG4;
  2279     Register tmp1      = R7_ARG5;
  2280     Register tmp2      = R8_ARG6;
  2282     ConditionRegister result_type_is_void   = CCR1;
  2283     ConditionRegister result_type_is_long   = CCR2;
  2284     ConditionRegister result_type_is_double = CCR3;
  2286     Label stack_to_stack_void;
  2287     Label stack_to_stack_double_slot; // T_LONG, T_DOUBLE
  2288     Label stack_to_stack_single_slot; // T_BOOLEAN, T_BYTE, T_CHAR, T_SHORT, T_INT, T_FLOAT, T_OBJECT
  2289     Label stack_to_stack_done;
  2291     // Pass callee's address of tos + BytesPerWord
  2292     __ ld(from_temp, state_(_stack));
  2294     // result type: void
  2295     __ cmpwi(result_type_is_void, result_index, AbstractInterpreter::BasicType_as_index(T_VOID));
  2297     // Pass caller's tos == callee's locals address
  2298     __ ld(tos, state_(_locals));
  2300     // result type: long
  2301     __ cmpwi(result_type_is_long, result_index, AbstractInterpreter::BasicType_as_index(T_LONG));
  2303     __ addi(from, from_temp, Interpreter::stackElementSize);
  2305     // !! don't branch above this line !!
  2307     // handle void
  2308     __ beq(result_type_is_void,   stack_to_stack_void);
  2310     // result type: double
  2311     __ cmpwi(result_type_is_double, result_index, AbstractInterpreter::BasicType_as_index(T_DOUBLE));
  2313     // handle long or double
  2314     __ beq(result_type_is_long, stack_to_stack_double_slot);
  2315     __ beq(result_type_is_double, stack_to_stack_double_slot);
  2317     // fall through to single slot types (incl. object)
  2320       __ BIND(stack_to_stack_single_slot);
  2321       // T_BOOLEAN, T_BYTE, T_CHAR, T_SHORT, T_INT, T_FLOAT, T_OBJECT
  2323       __ ld(tmp1, 0, from);
  2324       __ std(tmp1, 0, tos);
  2325       // New expression stack top
  2326       __ addi(new_tos, tos, - BytesPerWord);
  2328       __ b(stack_to_stack_done);
  2332       __ BIND(stack_to_stack_double_slot);
  2333       // T_LONG, T_DOUBLE
  2335       // Move both entries for debug purposes even though only one is live
  2336       __ ld(tmp1, BytesPerWord, from);
  2337       __ ld(tmp2, 0, from);
  2338       __ std(tmp1, 0, tos);
  2339       __ std(tmp2, -BytesPerWord, tos);
  2341       // new expression stack top
  2342       __ addi(new_tos, tos, - 2 * BytesPerWord); // two slots
  2343       __ b(stack_to_stack_done);
  2347       __ BIND(stack_to_stack_void);
  2348       // T_VOID
  2350       // new expression stack top
  2351       __ mr(new_tos, tos);
  2352       // fall through to stack_to_stack_done
  2355     __ BIND(stack_to_stack_done);
  2358   // new tos = R3_RET
  2360   // Get the message for the interpreter
  2361   __ li(msg, BytecodeInterpreter::method_resume);
  2363   // And fall thru
  2366   //=============================================================================
  2367   // Restore caller's interpreter state and pass pointer to caller's
  2368   // new tos to caller.
  2370   __ BIND(unwind_recursive_activation);
  2372   //
  2373   // Registers alive
  2374   //   R15_prev_state   - address of caller's BytecodeInterpreter
  2375   //   R3_RET           - address of caller's tos
  2376   //   msg              - message for caller's BytecodeInterpreter
  2377   //   R1_SP            - callee's stack pointer
  2378   //
  2379   // Registers updated
  2380   //   R14_state        - address of caller's BytecodeInterpreter
  2381   //   R15_prev_state   - address of its parent or 0
  2382   //
  2384   // Pop callee's interpreter and set R14_state to caller's interpreter.
  2385   __ pop_interpreter_state(/*prev_state_may_be_0=*/false);
  2387   // And fall thru
  2390   //=============================================================================
  2391   // Resume the (calling) interpreter after a call.
  2393   __ BIND(resume_interpreter);
  2395   //
  2396   // Registers alive
  2397   //   R14_state        - address of resuming BytecodeInterpreter
  2398   //   R15_prev_state   - address of its parent or 0
  2399   //   R3_RET           - address of resuming tos
  2400   //   msg              - message for resuming interpreter
  2401   //   R1_SP            - callee's stack pointer
  2402   //
  2403   // Registers updated
  2404   //   R1_SP            - caller's stack pointer
  2405   //
  2407   // Restore C stack pointer of caller (resuming interpreter),
  2408   // R14_state already points to the resuming BytecodeInterpreter.
  2409   __ pop_interpreter_frame_to_state(R14_state, R21_tmp1, R11_scratch1, R12_scratch2);
  2411   // Store new address of tos (holding return value) in interpreter state.
  2412   __ std(R3_RET, state_(_stack));
  2414   // Store message for interpreter.
  2415   __ stw(msg, state_(_msg));
  2417   __ b(call_interpreter);
  2419   //=============================================================================
  2420   // Interpreter returning to native code (call_stub/c1/c2) from
  2421   // initial activation. Convert stack result and unwind activation.
  2423   __ BIND(return_to_initial_caller);
  2425   //
  2426   // Registers alive
  2427   //   R19_method       - callee's Method
  2428   //   R14_state        - address of callee's interpreter state
  2429   //   R16_thread       - JavaThread
  2430   //   R1_SP            - callee's stack pointer
  2431   //
  2432   // Registers updated
  2433   //   R3_RET/F1_RET - result in expected output register
  2434   //
  2436   // If we have an exception pending we have no result and we
  2437   // must figure out where to really return to.
  2438   //
  2439   __ ld(pending_exception, thread_(pending_exception));
  2440   __ cmpdi(CCR0, pending_exception, 0);
  2441   __ bne(CCR0, unwind_initial_activation_pending_exception);
  2443   __ lwa(result_index, method_(result_index));
  2445   // Address of stub descriptor address array.
  2446   __ load_const(stub_addr, CppInterpreter::stack_result_to_native());
  2448   // Pass address of callee's tos + BytesPerWord.
  2449   // Will then point directly to result.
  2450   __ ld(R3_ARG1, state_(_stack));
  2451   __ addi(R3_ARG1, R3_ARG1, Interpreter::stackElementSize);
  2453   // Address of stub descriptor address
  2454   __ sldi(result_index, result_index, LogBytesPerWord);
  2455   __ add(stub_addr, stub_addr, result_index);
  2457   // Stub descriptor address
  2458   __ ld(stub_addr, 0, stub_addr);
  2460   // TODO: don't do this via a call, do it in place!
  2461   //
  2462   // call stub via descriptor
  2463   __ call_stub(stub_addr);
  2465   __ BIND(unwind_initial_activation);
  2467   // Unwind from initial activation. No exception is pending.
  2469   //
  2470   // Stack layout at this point:
  2471   //
  2472   //    0       [TOP_IJAVA_FRAME_ABI]         <-- R1_SP
  2473   //            ...
  2474   //    CALLER  [PARENT_IJAVA_FRAME_ABI]
  2475   //            ...
  2476   //    CALLER  [unextended ABI]
  2477   //            ...
  2478   //
  2479   //  The CALLER frame has a C2I adapter or is an entry-frame.
  2480   //
  2482   // An interpreter frame exists, we may pop the TOP_IJAVA_FRAME and
  2483   // turn the caller's PARENT_IJAVA_FRAME back into a TOP_IJAVA_FRAME.
  2484   // But, we simply restore the return pc from the caller's frame and
  2485   // use the caller's initial_caller_sp as the new SP which pops the
  2486   // interpreter frame and "resizes" the caller's frame to its "unextended"
  2487   // size.
  2489   // get rid of top frame
  2490   __ pop_frame();
  2492   // Load return PC from parent frame.
  2493   __ ld(R21_tmp1, _parent_ijava_frame_abi(lr), R1_SP);
  2495   // Resize frame to get rid of a potential extension.
  2496   __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
  2498   // update LR
  2499   __ mtlr(R21_tmp1);
  2501   // return
  2502   __ blr();
  2504   //=============================================================================
  2505   // Unwind from initial activation. An exception is pending
  2507   __ BIND(unwind_initial_activation_pending_exception);
  2509   //
  2510   // Stack layout at this point:
  2511   //
  2512   //   0       [TOP_IJAVA_FRAME_ABI]         <-- R1_SP
  2513   //           ...
  2514   //   CALLER  [PARENT_IJAVA_FRAME_ABI]
  2515   //           ...
  2516   //   CALLER  [unextended ABI]
  2517   //           ...
  2518   //
  2519   // The CALLER frame has a C2I adapter or is an entry-frame.
  2520   //
  2522   // An interpreter frame exists, we may pop the TOP_IJAVA_FRAME and
  2523   // turn the caller's PARENT_IJAVA_FRAME back into a TOP_IJAVA_FRAME.
  2524   // But, we just pop the current TOP_IJAVA_FRAME and fall through
  2526   __ pop_frame();
  2527   __ ld(R3_ARG1, _top_ijava_frame_abi(lr), R1_SP);
  2529   //
  2530   // Stack layout at this point:
  2531   //
  2532   //   CALLER  [PARENT_IJAVA_FRAME_ABI]      <-- R1_SP
  2533   //           ...
  2534   //   CALLER  [unextended ABI]
  2535   //           ...
  2536   //
  2537   // The CALLER frame has a C2I adapter or is an entry-frame.
  2538   //
  2539   // Registers alive
  2540   //   R16_thread
  2541   //   R3_ARG1 - return address to caller
  2542   //
  2543   // Registers updated
  2544   //   R3_ARG1 - address of pending exception
  2545   //   R4_ARG2 - issuing pc = return address to caller
  2546   //   LR      - address of exception handler stub
  2547   //
  2549   // Resize frame to get rid of a potential extension.
  2550   __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
  2552   __ mr(R14, R3_ARG1);   // R14 := ARG1
  2553   __ mr(R4_ARG2, R3_ARG1);  // ARG2 := ARG1
  2555   // Find the address of the "catch_exception" stub.
  2556   __ push_frame_reg_args(0, R11_scratch1);
  2557   __ call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address),
  2558                   R16_thread,
  2559                   R4_ARG2);
  2560   __ pop_frame();
  2562   // Load continuation address into LR.
  2563   __ mtlr(R3_RET);
  2565   // Load address of pending exception and clear it in thread object.
  2566   __ ld(R3_ARG1/*R3_RET*/, thread_(pending_exception));
  2567   __ li(R4_ARG2, 0);
  2568   __ std(R4_ARG2, thread_(pending_exception));
  2570   // re-load issuing pc
  2571   __ mr(R4_ARG2, R14);
  2573   // Branch to found exception handler.
  2574   __ blr();
  2576   //=============================================================================
  2577   // Call a new method. Compute new args and trim the expression stack
  2578   // to only what we are currently using and then recurse.
  2580   __ BIND(call_method);
  2582   //
  2583   //  Registers alive
  2584   //    R16_thread
  2585   //    R14_state      - address of caller's BytecodeInterpreter
  2586   //    R1_SP          - caller's stack pointer
  2587   //
  2588   //  Registers updated
  2589   //    R15_prev_state - address of caller's BytecodeInterpreter
  2590   //    R17_tos        - address of caller's tos
  2591   //    R19_method     - callee's Method
  2592   //    R1_SP          - trimmed back
  2593   //
  2595   // Very-local scratch registers.
  2597   const Register offset = R21_tmp1;
  2598   const Register tmp    = R22_tmp2;
  2599   const Register self_entry  = R23_tmp3;
  2600   const Register stub_entry  = R24_tmp4;
  2602   const ConditionRegister cr = CCR0;
  2604   // Load the address of the frame manager.
  2605   __ load_const(self_entry, &interpreter_frame_manager);
  2606   __ ld(self_entry, 0, self_entry);
  2608   // Load BytecodeInterpreter._result._to_call._callee (callee's Method).
  2609   __ ld(R19_method, state_(_result._to_call._callee));
  2610   // Load BytecodeInterpreter._stack (outgoing tos).
  2611   __ ld(R17_tos, state_(_stack));
  2613   // Save address of caller's BytecodeInterpreter.
  2614   __ mr(R15_prev_state, R14_state);
  2616   // Load the callee's entry point.
  2617   // Load BytecodeInterpreter._result._to_call._callee_entry_point.
  2618   __ ld(stub_entry, state_(_result._to_call._callee_entry_point));
  2620   // Check whether stub_entry is equal to self_entry.
  2621   __ cmpd(cr, self_entry, stub_entry);
  2622   // if (self_entry == stub_entry)
  2623   //   do a re-dispatch
  2624   __ beq(cr, re_dispatch);
  2625   // else
  2626   //   call the specialized entry (adapter for jni or compiled code)
  2627   __ BIND(call_special);
  2629   //
  2630   // Call the entry generated by `InterpreterGenerator::generate_native_entry'.
  2631   //
  2632   // Registers alive
  2633   //   R16_thread
  2634   //   R15_prev_state    - address of caller's BytecodeInterpreter
  2635   //   R19_method        - callee's Method
  2636   //   R17_tos           - address of caller's tos
  2637   //   R1_SP             - caller's stack pointer
  2638   //
  2640   // Mark return from specialized entry for generate_native_entry.
  2641   guarantee(return_from_native_pc != (address) NULL, "precondition");
  2642   frame_manager_specialized_return = return_from_native_pc;
  2644   // Set sender_SP in case we call interpreter native wrapper which
  2645   // will expect it. Compiled code should not care.
  2646   __ mr(R21_sender_SP, R1_SP);
  2648   // Do a tail call here, and let the link register point to
  2649   // frame_manager_specialized_return which is return_from_native_pc.
  2650   __ load_const(tmp, frame_manager_specialized_return);
  2651   __ call_stub_and_return_to(stub_entry,  tmp /* return_pc=tmp */);
  2654   //=============================================================================
  2655   //
  2656   // InterpretMethod triggered OSR compilation of some Java method M
  2657   // and now asks to run the compiled code.  We call this code the
  2658   // `callee'.
  2659   //
  2660   // This is our current idea on how OSR should look like on PPC64:
  2661   //
  2662   // While interpreting a Java method M the stack is:
  2663   //
  2664   //  (InterpretMethod (M), IJAVA_FRAME (M), ANY_FRAME, ...).
  2665   //
  2666   // After having OSR compiled M, `InterpretMethod' returns to the
  2667   // frame manager, sending the message `retry_method_osr'.  The stack
  2668   // is:
  2669   //
  2670   //  (IJAVA_FRAME (M), ANY_FRAME, ...).
  2671   //
  2672   // The compiler will have generated an `nmethod' suitable for
  2673   // continuing execution of M at the bytecode index at which OSR took
  2674   // place.  So now the frame manager calls the OSR entry.  The OSR
  2675   // entry sets up a JIT_FRAME for M and continues execution of M with
  2676   // initial state determined by the IJAVA_FRAME.
  2677   //
  2678   //  (JIT_FRAME (M), IJAVA_FRAME (M), ANY_FRAME, ...).
  2679   //
  2681   __ BIND(retry_method_osr);
  2683   //
  2684   // Registers alive
  2685   //   R16_thread
  2686   //   R15_prev_state     - address of caller's BytecodeInterpreter
  2687   //   R14_state          - address of callee's BytecodeInterpreter
  2688   //   R1_SP              - callee's SP before call to InterpretMethod
  2689   //
  2690   // Registers updated
  2691   //   R17                - pointer to callee's locals array
  2692   //                       (declared via `interpreter_arg_ptr_reg' in the AD file)
  2693   //   R19_method         - callee's Method
  2694   //   R1_SP              - callee's SP (will become SP of OSR adapter frame)
  2695   //
  2697   // Provide a debugger breakpoint in the frame manager if breakpoints
  2698   // in osr'd methods are requested.
  2699 #ifdef COMPILER2
  2700   NOT_PRODUCT( if (OptoBreakpointOSR) { __ illtrap(); } )
  2701 #endif
  2703   // Load callee's pointer to locals array from callee's state.
  2704   //  __ ld(R17, state_(_locals));
  2706   // Load osr entry.
  2707   __ ld(R12_scratch2, state_(_result._osr._osr_entry));
  2709   // Load address of temporary osr buffer to arg1.
  2710   __ ld(R3_ARG1, state_(_result._osr._osr_buf));
  2711   __ mtctr(R12_scratch2);
  2713   // Load method, gc may move it during execution of osr'd method.
  2714   __ ld(R22_tmp2, state_(_method));
  2715   // Load message 'call_method'.
  2716   __ li(R23_tmp3, BytecodeInterpreter::call_method);
  2719     // Pop the IJAVA frame of the method which we are going to call osr'd.
  2720     Label no_state, skip_no_state;
  2721     __ pop_interpreter_state(/*prev_state_may_be_0=*/true);
  2722     __ cmpdi(CCR0, R14_state,0);
  2723     __ beq(CCR0, no_state);
  2724     // return to interpreter
  2725     __ pop_interpreter_frame_to_state(R14_state, R11_scratch1, R12_scratch2, R21_tmp1);
  2727     // Init _result._to_call._callee and tell gc that it contains a valid oop
  2728     // by setting _msg to 'call_method'.
  2729     __ std(R22_tmp2, state_(_result._to_call._callee));
  2730     // TODO: PPC port: assert(4 == BytecodeInterpreter::sz_msg(), "unexpected field size");
  2731     __ stw(R23_tmp3, state_(_msg));
  2733     __ load_const(R21_tmp1, frame_manager_specialized_return);
  2734     __ b(skip_no_state);
  2735     __ bind(no_state);
  2737     // Return to initial caller.
  2739     // Get rid of top frame.
  2740     __ pop_frame();
  2742     // Load return PC from parent frame.
  2743     __ ld(R21_tmp1, _parent_ijava_frame_abi(lr), R1_SP);
  2745     // Resize frame to get rid of a potential extension.
  2746     __ resize_frame_to_initial_caller(R11_scratch1, R12_scratch2);
  2748     __ bind(skip_no_state);
  2750     // Update LR with return pc.
  2751     __ mtlr(R21_tmp1);
  2753   // Jump to the osr entry point.
  2754   __ bctr();
  2758   //=============================================================================
  2759   // Interpreted method "returned" with an exception, pass it on.
  2760   // Pass no result, unwind activation and continue/return to
  2761   // interpreter/call_stub/c2.
  2763   __ BIND(throwing_exception);
  2765   // Check if this is the initial invocation of the frame manager.  If
  2766   // so, previous interpreter state in R15_prev_state will be null.
  2768   // New tos of caller is callee's first parameter address, that is
  2769   // callee's incoming arguments are popped.
  2770   __ ld(R3_RET, state_(_locals));
  2772   // Check whether this is an initial call.
  2773   __ cmpdi(CCR0, R15_prev_state, 0);
  2774   // Yes, called from the call stub or from generated code via a c2i frame.
  2775   __ beq(CCR0, unwind_initial_activation_pending_exception);
  2777   // Send resume message, interpreter will see the exception first.
  2779   __ li(msg, BytecodeInterpreter::method_resume);
  2780   __ b(unwind_recursive_activation);
  2783   //=============================================================================
  2784   // Push the last instruction out to the code buffer.
  2787     __ unimplemented("end of InterpreterGenerator::generate_normal_entry", 128);
  2790   interpreter_frame_manager = entry;
  2791   return interpreter_frame_manager;
  2794 // Generate code for various sorts of method entries
  2795 //
  2796 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
  2797   address entry_point = NULL;
  2799   switch (kind) {
  2800     case Interpreter::zerolocals                 :                                                                              break;
  2801     case Interpreter::zerolocals_synchronized    :                                                                              break;
  2802     case Interpreter::native                     : // Fall thru
  2803     case Interpreter::native_synchronized        : entry_point = ((CppInterpreterGenerator*)this)->generate_native_entry();     break;
  2804     case Interpreter::empty                      :                                                                              break;
  2805     case Interpreter::accessor                   : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();      break;
  2806     case Interpreter::abstract                   : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();      break;
  2807     // These are special interpreter intrinsics which we don't support so far.
  2808     case Interpreter::java_lang_math_sin         :                                                                              break;
  2809     case Interpreter::java_lang_math_cos         :                                                                              break;
  2810     case Interpreter::java_lang_math_tan         :                                                                              break;
  2811     case Interpreter::java_lang_math_abs         :                                                                              break;
  2812     case Interpreter::java_lang_math_log         :                                                                              break;
  2813     case Interpreter::java_lang_math_log10       :                                                                              break;
  2814     case Interpreter::java_lang_math_sqrt        :                                                                              break;
  2815     case Interpreter::java_lang_math_pow         :                                                                              break;
  2816     case Interpreter::java_lang_math_exp         :                                                                              break;
  2817     case Interpreter::java_lang_ref_reference_get: entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
  2818     default                                      : ShouldNotReachHere();                                                        break;
  2821   if (entry_point) {
  2822     return entry_point;
  2824   return ((InterpreterGenerator*)this)->generate_normal_entry();
  2827 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
  2828  : CppInterpreterGenerator(code) {
  2829    generate_all(); // down here so it can be "virtual"
  2832 // How much stack a topmost interpreter method activation needs in words.
  2833 int AbstractInterpreter::size_top_interpreter_activation(Method* method) {
  2834   // Computation is in bytes not words to match layout_activation_impl
  2835   // below, but the return is in words.
  2837   //
  2838   //  0       [TOP_IJAVA_FRAME_ABI]                                                    \
  2839   //          alignment (optional)                                             \       |
  2840   //          [operand stack / Java parameters] > stack                        |       |
  2841   //          [monitors] (optional)             > monitors                     |       |
  2842   //          [PARENT_IJAVA_FRAME_ABI]                                \        |       |
  2843   //          [BytecodeInterpreter object]      > interpreter \       |        |       |
  2844   //          alignment (optional)                            | round | parent | round | top
  2845   //          [Java result] (2 slots)           > result      |       |        |       |
  2846   //          [Java non-arg locals]             \ locals      |       |        |       |
  2847   //          [arg locals]                      /             /       /        /       /
  2848   //
  2850   int locals = method->max_locals() * BytesPerWord;
  2851   int interpreter = frame::interpreter_frame_cinterpreterstate_size_in_bytes();
  2852   int result = 2 * BytesPerWord;
  2854   int parent = round_to(interpreter + result + locals, 16) + frame::parent_ijava_frame_abi_size;
  2856   int stack = method->max_stack() * BytesPerWord;
  2857   int monitors = method->is_synchronized() ? frame::interpreter_frame_monitor_size_in_bytes() : 0;
  2858   int top = round_to(parent + monitors + stack, 16) + frame::top_ijava_frame_abi_size;
  2860   return (top / BytesPerWord);
  2863 void BytecodeInterpreter::layout_interpreterState(interpreterState to_fill,
  2864                                                   frame* caller,
  2865                                                   frame* current,
  2866                                                   Method* method,
  2867                                                   intptr_t* locals,
  2868                                                   intptr_t* stack,
  2869                                                   intptr_t* stack_base,
  2870                                                   intptr_t* monitor_base,
  2871                                                   intptr_t* frame_sp,
  2872                                                   bool is_top_frame) {
  2873   // What about any vtable?
  2874   //
  2875   to_fill->_thread = JavaThread::current();
  2876   // This gets filled in later but make it something recognizable for now.
  2877   to_fill->_bcp = method->code_base();
  2878   to_fill->_locals = locals;
  2879   to_fill->_constants = method->constants()->cache();
  2880   to_fill->_method = method;
  2881   to_fill->_mdx = NULL;
  2882   to_fill->_stack = stack;
  2884   if (is_top_frame && JavaThread::current()->popframe_forcing_deopt_reexecution()) {
  2885     to_fill->_msg = deopt_resume2;
  2886   } else {
  2887     to_fill->_msg = method_resume;
  2889   to_fill->_result._to_call._bcp_advance = 0;
  2890   to_fill->_result._to_call._callee_entry_point = NULL; // doesn't matter to anyone
  2891   to_fill->_result._to_call._callee = NULL; // doesn't matter to anyone
  2892   to_fill->_prev_link = NULL;
  2894   if (caller->is_interpreted_frame()) {
  2895     interpreterState prev  = caller->get_interpreterState();
  2897     // Support MH calls. Make sure the interpreter will return the right address:
  2898     // 1. Caller did ordinary interpreted->compiled call call: Set a prev_state
  2899     //    which makes the CPP interpreter return to frame manager "return_from_interpreted_method"
  2900     //    entry after finishing execution.
  2901     // 2. Caller did a MH call: If the caller has a MethodHandleInvoke in it's
  2902     //    state (invariant: must be the caller of the bottom vframe) we used the
  2903     //    "call_special" entry to do the call, meaning the arguments have not been
  2904     //    popped from the stack. Therefore, don't enter a prev state in this case
  2905     //    in order to return to "return_from_native" frame manager entry which takes
  2906     //    care of popping arguments. Also, don't overwrite the MH.invoke Method in
  2907     //    the prev_state in order to be able to figure out the number of arguments to
  2908     //     pop.
  2909     // The parameter method can represent MethodHandle.invokeExact(...).
  2910     // The MethodHandleCompiler generates these synthetic Methods,
  2911     // including bytecodes, if an invokedynamic call gets inlined. In
  2912     // this case we want to return like from any other interpreted
  2913     // Java call, so we set _prev_link.
  2914     to_fill->_prev_link = prev;
  2916     if (*prev->_bcp == Bytecodes::_invokeinterface || *prev->_bcp == Bytecodes::_invokedynamic) {
  2917       prev->_result._to_call._bcp_advance = 5;
  2918     } else {
  2919       prev->_result._to_call._bcp_advance = 3;
  2922   to_fill->_oop_temp = NULL;
  2923   to_fill->_stack_base = stack_base;
  2924   // Need +1 here because stack_base points to the word just above the
  2925   // first expr stack entry and stack_limit is supposed to point to
  2926   // the word just below the last expr stack entry. See
  2927   // generate_compute_interpreter_state.
  2928   to_fill->_stack_limit = stack_base - (method->max_stack() + 1);
  2929   to_fill->_monitor_base = (BasicObjectLock*) monitor_base;
  2931   to_fill->_frame_bottom = frame_sp;
  2933   // PPC64 specific
  2934   to_fill->_last_Java_pc = NULL;
  2935   to_fill->_last_Java_fp = NULL;
  2936   to_fill->_last_Java_sp = frame_sp;
  2937 #ifdef ASSERT
  2938   to_fill->_self_link = to_fill;
  2939   to_fill->_native_fresult = 123456.789;
  2940   to_fill->_native_lresult = CONST64(0xdeafcafedeadc0de);
  2941 #endif
  2944 void BytecodeInterpreter::pd_layout_interpreterState(interpreterState istate,
  2945                                                      address last_Java_pc,
  2946                                                      intptr_t* last_Java_fp) {
  2947   istate->_last_Java_pc = last_Java_pc;
  2948   istate->_last_Java_fp = last_Java_fp;
  2951 // Computes monitor_size and top_frame_size in bytes.
  2952 static void frame_size_helper(int max_stack,
  2953                               int monitors,
  2954                               int& monitor_size,
  2955                               int& top_frame_size) {
  2956   monitor_size = frame::interpreter_frame_monitor_size_in_bytes() * monitors;
  2957   top_frame_size = round_to(frame::interpreter_frame_cinterpreterstate_size_in_bytes()
  2958                             + monitor_size
  2959                             + max_stack * Interpreter::stackElementSize
  2960                             + 2 * Interpreter::stackElementSize,
  2961                             frame::alignment_in_bytes)
  2962                    + frame::top_ijava_frame_abi_size;
  2965 // Returns number of stackElementWords needed for the interpreter frame with the
  2966 // given sections.
  2967 int AbstractInterpreter::size_activation(int max_stack,
  2968                                          int temps,
  2969                                          int extra_args,
  2970                                          int monitors,
  2971                                          int callee_params,
  2972                                          int callee_locals,
  2973                                          bool is_top_frame) {
  2974   int monitor_size = 0;
  2975   int top_frame_size = 0;
  2976   frame_size_helper(max_stack, monitors, monitor_size, top_frame_size);
  2978   int frame_size;
  2979   if (is_top_frame) {
  2980     frame_size = top_frame_size;
  2981   } else {
  2982     frame_size = round_to(frame::interpreter_frame_cinterpreterstate_size_in_bytes()
  2983                           + monitor_size
  2984                           + (temps - callee_params + callee_locals) * Interpreter::stackElementSize
  2985                           + 2 * Interpreter::stackElementSize,
  2986                           frame::alignment_in_bytes)
  2987                  + frame::parent_ijava_frame_abi_size;
  2988     assert(extra_args == 0, "non-zero for top_frame only");
  2991   return frame_size / Interpreter::stackElementSize;
  2994 void AbstractInterpreter::layout_activation(Method* method,
  2995                                             int temps,        // Number of slots on java expression stack in use.
  2996                                             int popframe_args,
  2997                                             int monitors,     // Number of active monitors.
  2998                                             int caller_actual_parameters,
  2999                                             int callee_params,// Number of slots for callee parameters.
  3000                                             int callee_locals,// Number of slots for locals.
  3001                                             frame* caller,
  3002                                             frame* interpreter_frame,
  3003                                             bool is_top_frame,
  3004                                             bool is_bottom_frame) {
  3006   // NOTE this code must exactly mimic what
  3007   // InterpreterGenerator::generate_compute_interpreter_state() does
  3008   // as far as allocating an interpreter frame. However there is an
  3009   // exception. With the C++ based interpreter only the top most frame
  3010   // has a full sized expression stack.  The 16 byte slop factor is
  3011   // both the abi scratch area and a place to hold a result from a
  3012   // callee on its way to the callers stack.
  3014   int monitor_size = 0;
  3015   int top_frame_size = 0;
  3016   frame_size_helper(method->max_stack(), monitors, monitor_size, top_frame_size);
  3018   intptr_t sp = (intptr_t)interpreter_frame->sp();
  3019   intptr_t fp = *(intptr_t *)sp;
  3020   assert(fp == (intptr_t)caller->sp(), "fp must match");
  3021   interpreterState cur_state =
  3022     (interpreterState)(fp - frame::interpreter_frame_cinterpreterstate_size_in_bytes());
  3024   // Now fill in the interpreterState object.
  3026   intptr_t* locals;
  3027   if (caller->is_interpreted_frame()) {
  3028     // Locals must agree with the caller because it will be used to set the
  3029     // caller's tos when we return.
  3030     interpreterState prev  = caller->get_interpreterState();
  3031     // Calculate start of "locals" for MH calls.  For MH calls, the
  3032     // current method() (= MH target) and prev->callee() (=
  3033     // MH.invoke*()) are different and especially have different
  3034     // signatures. To pop the argumentsof the caller, we must use
  3035     // the prev->callee()->size_of_arguments() because that's what
  3036     // the caller actually pushed.  Currently, for synthetic MH
  3037     // calls (deoptimized from inlined MH calls), detected by
  3038     // is_method_handle_invoke(), we use the callee's arguments
  3039     // because here, the caller's and callee's signature match.
  3040     if (true /*!caller->is_at_mh_callsite()*/) {
  3041       locals = prev->stack() + method->size_of_parameters();
  3042     } else {
  3043       // Normal MH call.
  3044       locals = prev->stack() + prev->callee()->size_of_parameters();
  3046   } else {
  3047     bool is_deopted;
  3048     locals = (intptr_t*) (fp + ((method->max_locals() - 1) * BytesPerWord) +
  3049                           frame::parent_ijava_frame_abi_size);
  3052   intptr_t* monitor_base = (intptr_t*) cur_state;
  3053   intptr_t* stack_base   = (intptr_t*) ((intptr_t) monitor_base - monitor_size);
  3055   // Provide pop_frame capability on PPC64, add popframe_args.
  3056   // +1 because stack is always prepushed.
  3057   intptr_t* stack = (intptr_t*) ((intptr_t) stack_base - (temps + popframe_args + 1) * BytesPerWord);
  3059   BytecodeInterpreter::layout_interpreterState(cur_state,
  3060                                                caller,
  3061                                                interpreter_frame,
  3062                                                method,
  3063                                                locals,
  3064                                                stack,
  3065                                                stack_base,
  3066                                                monitor_base,
  3067                                                (intptr_t*)(((intptr_t)fp) - top_frame_size),
  3068                                                is_top_frame);
  3070   BytecodeInterpreter::pd_layout_interpreterState(cur_state, interpreter_return_address,
  3071                                                   interpreter_frame->fp());
  3074 #endif // CC_INTERP

mercurial