src/cpu/x86/vm/templateInterpreter_x86_32.cpp

Tue, 18 Jan 2011 18:00:06 -0800

author
iveresov
date
Tue, 18 Jan 2011 18:00:06 -0800
changeset 2461
b599a4c6c2df
parent 2438
dd031b2226de
child 2552
638119ce7cfd
permissions
-rw-r--r--

7012766: assert(false) failed: DEBUG MESSAGE in MacroAssembler::debug32
Summary: Interpreter expects to see methodOop in rbx on method entry, which needs to be restored after call to profile_method.
Reviewed-by: kvn, never

     1 /*
     2  * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     8  *
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    12  * version 2 for more details (a copy is included in the LICENSE file that
    13  * accompanied this code).
    14  *
    15  * You should have received a copy of the GNU General Public License version
    16  * 2 along with this work; if not, write to the Free Software Foundation,
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    18  *
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    20  * or visit www.oracle.com if you need additional information or have any
    21  * questions.
    22  *
    23  */
    25 #include "precompiled.hpp"
    26 #include "asm/assembler.hpp"
    27 #include "interpreter/bytecodeHistogram.hpp"
    28 #include "interpreter/interpreter.hpp"
    29 #include "interpreter/interpreterGenerator.hpp"
    30 #include "interpreter/interpreterRuntime.hpp"
    31 #include "interpreter/templateTable.hpp"
    32 #include "oops/arrayOop.hpp"
    33 #include "oops/methodDataOop.hpp"
    34 #include "oops/methodOop.hpp"
    35 #include "oops/oop.inline.hpp"
    36 #include "prims/jvmtiExport.hpp"
    37 #include "prims/jvmtiThreadState.hpp"
    38 #include "runtime/arguments.hpp"
    39 #include "runtime/deoptimization.hpp"
    40 #include "runtime/frame.inline.hpp"
    41 #include "runtime/sharedRuntime.hpp"
    42 #include "runtime/stubRoutines.hpp"
    43 #include "runtime/synchronizer.hpp"
    44 #include "runtime/timer.hpp"
    45 #include "runtime/vframeArray.hpp"
    46 #include "utilities/debug.hpp"
    48 #define __ _masm->
    51 #ifndef CC_INTERP
    52 const int method_offset = frame::interpreter_frame_method_offset * wordSize;
    53 const int bci_offset    = frame::interpreter_frame_bcx_offset    * wordSize;
    54 const int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
    56 //------------------------------------------------------------------------------------------------------------------------
    58 address TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
    59   address entry = __ pc();
    61   // Note: There should be a minimal interpreter frame set up when stack
    62   // overflow occurs since we check explicitly for it now.
    63   //
    64 #ifdef ASSERT
    65   { Label L;
    66     __ lea(rax, Address(rbp,
    67                 frame::interpreter_frame_monitor_block_top_offset * wordSize));
    68     __ cmpptr(rax, rsp);  // rax, = maximal rsp for current rbp,
    69                         //  (stack grows negative)
    70     __ jcc(Assembler::aboveEqual, L); // check if frame is complete
    71     __ stop ("interpreter frame not set up");
    72     __ bind(L);
    73   }
    74 #endif // ASSERT
    75   // Restore bcp under the assumption that the current frame is still
    76   // interpreted
    77   __ restore_bcp();
    79   // expression stack must be empty before entering the VM if an exception
    80   // happened
    81   __ empty_expression_stack();
    82   __ empty_FPU_stack();
    83   // throw exception
    84   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError));
    85   return entry;
    86 }
    88 address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char* name) {
    89   address entry = __ pc();
    90   // expression stack must be empty before entering the VM if an exception happened
    91   __ empty_expression_stack();
    92   __ empty_FPU_stack();
    93   // setup parameters
    94   // ??? convention: expect aberrant index in register rbx,
    95   __ lea(rax, ExternalAddress((address)name));
    96   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), rax, rbx);
    97   return entry;
    98 }
   100 address TemplateInterpreterGenerator::generate_ClassCastException_handler() {
   101   address entry = __ pc();
   102   // object is at TOS
   103   __ pop(rax);
   104   // expression stack must be empty before entering the VM if an exception
   105   // happened
   106   __ empty_expression_stack();
   107   __ empty_FPU_stack();
   108   __ call_VM(noreg,
   109              CAST_FROM_FN_PTR(address,
   110                               InterpreterRuntime::throw_ClassCastException),
   111              rax);
   112   return entry;
   113 }
   115 // Arguments are: required type at TOS+4, failing object (or NULL) at TOS.
   116 address TemplateInterpreterGenerator::generate_WrongMethodType_handler() {
   117   address entry = __ pc();
   119   __ pop(rbx);                  // actual failing object is at TOS
   120   __ pop(rax);                  // required type is at TOS+4
   122   __ verify_oop(rbx);
   123   __ verify_oop(rax);
   125   // Various method handle types use interpreter registers as temps.
   126   __ restore_bcp();
   127   __ restore_locals();
   129   // Expression stack must be empty before entering the VM for an exception.
   130   __ empty_expression_stack();
   131   __ empty_FPU_stack();
   132   __ call_VM(noreg,
   133              CAST_FROM_FN_PTR(address,
   134                               InterpreterRuntime::throw_WrongMethodTypeException),
   135              // pass required type, failing object (or NULL)
   136              rax, rbx);
   137   return entry;
   138 }
   141 address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) {
   142   assert(!pass_oop || message == NULL, "either oop or message but not both");
   143   address entry = __ pc();
   144   if (pass_oop) {
   145     // object is at TOS
   146     __ pop(rbx);
   147   }
   148   // expression stack must be empty before entering the VM if an exception happened
   149   __ empty_expression_stack();
   150   __ empty_FPU_stack();
   151   // setup parameters
   152   __ lea(rax, ExternalAddress((address)name));
   153   if (pass_oop) {
   154     __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), rax, rbx);
   155   } else {
   156     if (message != NULL) {
   157       __ lea(rbx, ExternalAddress((address)message));
   158     } else {
   159       __ movptr(rbx, NULL_WORD);
   160     }
   161     __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), rax, rbx);
   162   }
   163   // throw exception
   164   __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
   165   return entry;
   166 }
   169 address TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
   170   address entry = __ pc();
   171   // NULL last_sp until next java call
   172   __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
   173   __ dispatch_next(state);
   174   return entry;
   175 }
   178 address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step) {
   179   TosState incoming_state = state;
   181   Label interpreter_entry;
   182   address compiled_entry = __ pc();
   184 #ifdef COMPILER2
   185   // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases
   186   if ((incoming_state == ftos && UseSSE < 1) || (incoming_state == dtos && UseSSE < 2)) {
   187     for (int i = 1; i < 8; i++) {
   188         __ ffree(i);
   189     }
   190   } else if (UseSSE < 2) {
   191     __ empty_FPU_stack();
   192   }
   193 #endif
   194   if ((incoming_state == ftos && UseSSE < 1) || (incoming_state == dtos && UseSSE < 2)) {
   195     __ MacroAssembler::verify_FPU(1, "generate_return_entry_for compiled");
   196   } else {
   197     __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled");
   198   }
   200   __ jmp(interpreter_entry, relocInfo::none);
   201   // emit a sentinel we can test for when converting an interpreter
   202   // entry point to a compiled entry point.
   203   __ a_long(Interpreter::return_sentinel);
   204   __ a_long((int)compiled_entry);
   205   address entry = __ pc();
   206   __ bind(interpreter_entry);
   208   // In SSE mode, interpreter returns FP results in xmm0 but they need
   209   // to end up back on the FPU so it can operate on them.
   210   if (incoming_state == ftos && UseSSE >= 1) {
   211     __ subptr(rsp, wordSize);
   212     __ movflt(Address(rsp, 0), xmm0);
   213     __ fld_s(Address(rsp, 0));
   214     __ addptr(rsp, wordSize);
   215   } else if (incoming_state == dtos && UseSSE >= 2) {
   216     __ subptr(rsp, 2*wordSize);
   217     __ movdbl(Address(rsp, 0), xmm0);
   218     __ fld_d(Address(rsp, 0));
   219     __ addptr(rsp, 2*wordSize);
   220   }
   222   __ MacroAssembler::verify_FPU(state == ftos || state == dtos ? 1 : 0, "generate_return_entry_for in interpreter");
   224   // Restore stack bottom in case i2c adjusted stack
   225   __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
   226   // and NULL it as marker that rsp is now tos until next java call
   227   __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
   229   __ restore_bcp();
   230   __ restore_locals();
   232   Label L_got_cache, L_giant_index;
   233   if (EnableInvokeDynamic) {
   234     __ cmpb(Address(rsi, 0), Bytecodes::_invokedynamic);
   235     __ jcc(Assembler::equal, L_giant_index);
   236   }
   237   __ get_cache_and_index_at_bcp(rbx, rcx, 1, sizeof(u2));
   238   __ bind(L_got_cache);
   239   __ movl(rbx, Address(rbx, rcx,
   240                     Address::times_ptr, constantPoolCacheOopDesc::base_offset() +
   241                     ConstantPoolCacheEntry::flags_offset()));
   242   __ andptr(rbx, 0xFF);
   243   __ lea(rsp, Address(rsp, rbx, Interpreter::stackElementScale()));
   244   __ dispatch_next(state, step);
   246   // out of the main line of code...
   247   if (EnableInvokeDynamic) {
   248     __ bind(L_giant_index);
   249     __ get_cache_and_index_at_bcp(rbx, rcx, 1, sizeof(u4));
   250     __ jmp(L_got_cache);
   251   }
   253   return entry;
   254 }
   257 address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) {
   258   address entry = __ pc();
   260   // In SSE mode, FP results are in xmm0
   261   if (state == ftos && UseSSE > 0) {
   262     __ subptr(rsp, wordSize);
   263     __ movflt(Address(rsp, 0), xmm0);
   264     __ fld_s(Address(rsp, 0));
   265     __ addptr(rsp, wordSize);
   266   } else if (state == dtos && UseSSE >= 2) {
   267     __ subptr(rsp, 2*wordSize);
   268     __ movdbl(Address(rsp, 0), xmm0);
   269     __ fld_d(Address(rsp, 0));
   270     __ addptr(rsp, 2*wordSize);
   271   }
   273   __ MacroAssembler::verify_FPU(state == ftos || state == dtos ? 1 : 0, "generate_deopt_entry_for in interpreter");
   275   // The stack is not extended by deopt but we must NULL last_sp as this
   276   // entry is like a "return".
   277   __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
   278   __ restore_bcp();
   279   __ restore_locals();
   280   // handle exceptions
   281   { Label L;
   282     const Register thread = rcx;
   283     __ get_thread(thread);
   284     __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
   285     __ jcc(Assembler::zero, L);
   286     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
   287     __ should_not_reach_here();
   288     __ bind(L);
   289   }
   290   __ dispatch_next(state, step);
   291   return entry;
   292 }
   295 int AbstractInterpreter::BasicType_as_index(BasicType type) {
   296   int i = 0;
   297   switch (type) {
   298     case T_BOOLEAN: i = 0; break;
   299     case T_CHAR   : i = 1; break;
   300     case T_BYTE   : i = 2; break;
   301     case T_SHORT  : i = 3; break;
   302     case T_INT    : // fall through
   303     case T_LONG   : // fall through
   304     case T_VOID   : i = 4; break;
   305     case T_FLOAT  : i = 5; break;  // have to treat float and double separately for SSE
   306     case T_DOUBLE : i = 6; break;
   307     case T_OBJECT : // fall through
   308     case T_ARRAY  : i = 7; break;
   309     default       : ShouldNotReachHere();
   310   }
   311   assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds");
   312   return i;
   313 }
   316 address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) {
   317   address entry = __ pc();
   318   switch (type) {
   319     case T_BOOLEAN: __ c2bool(rax);            break;
   320     case T_CHAR   : __ andptr(rax, 0xFFFF);    break;
   321     case T_BYTE   : __ sign_extend_byte (rax); break;
   322     case T_SHORT  : __ sign_extend_short(rax); break;
   323     case T_INT    : /* nothing to do */        break;
   324     case T_DOUBLE :
   325     case T_FLOAT  :
   326       { const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp();
   327         __ pop(t);                            // remove return address first
   328         // Must return a result for interpreter or compiler. In SSE
   329         // mode, results are returned in xmm0 and the FPU stack must
   330         // be empty.
   331         if (type == T_FLOAT && UseSSE >= 1) {
   332           // Load ST0
   333           __ fld_d(Address(rsp, 0));
   334           // Store as float and empty fpu stack
   335           __ fstp_s(Address(rsp, 0));
   336           // and reload
   337           __ movflt(xmm0, Address(rsp, 0));
   338         } else if (type == T_DOUBLE && UseSSE >= 2 ) {
   339           __ movdbl(xmm0, Address(rsp, 0));
   340         } else {
   341           // restore ST0
   342           __ fld_d(Address(rsp, 0));
   343         }
   344         // and pop the temp
   345         __ addptr(rsp, 2 * wordSize);
   346         __ push(t);                           // restore return address
   347       }
   348       break;
   349     case T_OBJECT :
   350       // retrieve result from frame
   351       __ movptr(rax, Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize));
   352       // and verify it
   353       __ verify_oop(rax);
   354       break;
   355     default       : ShouldNotReachHere();
   356   }
   357   __ ret(0);                                   // return from result handler
   358   return entry;
   359 }
   361 address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) {
   362   address entry = __ pc();
   363   __ push(state);
   364   __ call_VM(noreg, runtime_entry);
   365   __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
   366   return entry;
   367 }
   370 // Helpers for commoning out cases in the various type of method entries.
   371 //
   373 // increment invocation count & check for overflow
   374 //
   375 // Note: checking for negative value instead of overflow
   376 //       so we have a 'sticky' overflow test
   377 //
   378 // rbx,: method
   379 // rcx: invocation counter
   380 //
   381 void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) {
   382   const Address invocation_counter(rbx, in_bytes(methodOopDesc::invocation_counter_offset()) +
   383                                         in_bytes(InvocationCounter::counter_offset()));
   384   // Note: In tiered we increment either counters in methodOop or in MDO depending if we're profiling or not.
   385   if (TieredCompilation) {
   386     int increment = InvocationCounter::count_increment;
   387     int mask = ((1 << Tier0InvokeNotifyFreqLog)  - 1) << InvocationCounter::count_shift;
   388     Label no_mdo, done;
   389     if (ProfileInterpreter) {
   390       // Are we profiling?
   391       __ movptr(rax, Address(rbx, methodOopDesc::method_data_offset()));
   392       __ testptr(rax, rax);
   393       __ jccb(Assembler::zero, no_mdo);
   394       // Increment counter in the MDO
   395       const Address mdo_invocation_counter(rax, in_bytes(methodDataOopDesc::invocation_counter_offset()) +
   396                                                 in_bytes(InvocationCounter::counter_offset()));
   397       __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rcx, false, Assembler::zero, overflow);
   398       __ jmpb(done);
   399     }
   400     __ bind(no_mdo);
   401     // Increment counter in methodOop (we don't need to load it, it's in rcx).
   402     __ increment_mask_and_jump(invocation_counter, increment, mask, rcx, true, Assembler::zero, overflow);
   403     __ bind(done);
   404   } else {
   405     const Address backedge_counter  (rbx, methodOopDesc::backedge_counter_offset() +
   406                                           InvocationCounter::counter_offset());
   408     if (ProfileInterpreter) { // %%% Merge this into methodDataOop
   409       __ incrementl(Address(rbx,methodOopDesc::interpreter_invocation_counter_offset()));
   410     }
   411     // Update standard invocation counters
   412     __ movl(rax, backedge_counter);               // load backedge counter
   414     __ incrementl(rcx, InvocationCounter::count_increment);
   415     __ andl(rax, InvocationCounter::count_mask_value);  // mask out the status bits
   417     __ movl(invocation_counter, rcx);             // save invocation count
   418     __ addl(rcx, rax);                            // add both counters
   420     // profile_method is non-null only for interpreted method so
   421     // profile_method != NULL == !native_call
   422     // BytecodeInterpreter only calls for native so code is elided.
   424     if (ProfileInterpreter && profile_method != NULL) {
   425       // Test to see if we should create a method data oop
   426       __ cmp32(rcx,
   427                ExternalAddress((address)&InvocationCounter::InterpreterProfileLimit));
   428       __ jcc(Assembler::less, *profile_method_continue);
   430       // if no method data exists, go to profile_method
   431       __ test_method_data_pointer(rax, *profile_method);
   432     }
   434     __ cmp32(rcx,
   435              ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));
   436     __ jcc(Assembler::aboveEqual, *overflow);
   437   }
   438 }
   440 void InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
   442   // Asm interpreter on entry
   443   // rdi - locals
   444   // rsi - bcp
   445   // rbx, - method
   446   // rdx - cpool
   447   // rbp, - interpreter frame
   449   // C++ interpreter on entry
   450   // rsi - new interpreter state pointer
   451   // rbp - interpreter frame pointer
   452   // rbx - method
   454   // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
   455   // rbx, - method
   456   // rcx - rcvr (assuming there is one)
   457   // top of stack return address of interpreter caller
   458   // rsp - sender_sp
   460   // C++ interpreter only
   461   // rsi - previous interpreter state pointer
   463   const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
   465   // InterpreterRuntime::frequency_counter_overflow takes one argument
   466   // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp).
   467   // The call returns the address of the verified entry point for the method or NULL
   468   // if the compilation did not complete (either went background or bailed out).
   469   __ movptr(rax, (intptr_t)false);
   470   __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax);
   472   __ movptr(rbx, Address(rbp, method_offset));   // restore methodOop
   474   // Preserve invariant that rsi/rdi contain bcp/locals of sender frame
   475   // and jump to the interpreted entry.
   476   __ jmp(*do_continue, relocInfo::none);
   478 }
   480 void InterpreterGenerator::generate_stack_overflow_check(void) {
   481   // see if we've got enough room on the stack for locals plus overhead.
   482   // the expression stack grows down incrementally, so the normal guard
   483   // page mechanism will work for that.
   484   //
   485   // Registers live on entry:
   486   //
   487   // Asm interpreter
   488   // rdx: number of additional locals this frame needs (what we must check)
   489   // rbx,: methodOop
   491   // destroyed on exit
   492   // rax,
   494   // NOTE:  since the additional locals are also always pushed (wasn't obvious in
   495   // generate_method_entry) so the guard should work for them too.
   496   //
   498   // monitor entry size: see picture of stack set (generate_method_entry) and frame_x86.hpp
   499   const int entry_size    = frame::interpreter_frame_monitor_size() * wordSize;
   501   // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
   502   // be sure to change this if you add/subtract anything to/from the overhead area
   503   const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize) + entry_size;
   505   const int page_size = os::vm_page_size();
   507   Label after_frame_check;
   509   // see if the frame is greater than one page in size. If so,
   510   // then we need to verify there is enough stack space remaining
   511   // for the additional locals.
   512   __ cmpl(rdx, (page_size - overhead_size)/Interpreter::stackElementSize);
   513   __ jcc(Assembler::belowEqual, after_frame_check);
   515   // compute rsp as if this were going to be the last frame on
   516   // the stack before the red zone
   518   Label after_frame_check_pop;
   520   __ push(rsi);
   522   const Register thread = rsi;
   524   __ get_thread(thread);
   526   const Address stack_base(thread, Thread::stack_base_offset());
   527   const Address stack_size(thread, Thread::stack_size_offset());
   529   // locals + overhead, in bytes
   530   __ lea(rax, Address(noreg, rdx, Interpreter::stackElementScale(), overhead_size));
   532 #ifdef ASSERT
   533   Label stack_base_okay, stack_size_okay;
   534   // verify that thread stack base is non-zero
   535   __ cmpptr(stack_base, (int32_t)NULL_WORD);
   536   __ jcc(Assembler::notEqual, stack_base_okay);
   537   __ stop("stack base is zero");
   538   __ bind(stack_base_okay);
   539   // verify that thread stack size is non-zero
   540   __ cmpptr(stack_size, 0);
   541   __ jcc(Assembler::notEqual, stack_size_okay);
   542   __ stop("stack size is zero");
   543   __ bind(stack_size_okay);
   544 #endif
   546   // Add stack base to locals and subtract stack size
   547   __ addptr(rax, stack_base);
   548   __ subptr(rax, stack_size);
   550   // Use the maximum number of pages we might bang.
   551   const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :
   552                                                                               (StackRedPages+StackYellowPages);
   553   __ addptr(rax, max_pages * page_size);
   555   // check against the current stack bottom
   556   __ cmpptr(rsp, rax);
   557   __ jcc(Assembler::above, after_frame_check_pop);
   559   __ pop(rsi);  // get saved bcp / (c++ prev state ).
   561   __ pop(rax);  // get return address
   562   __ jump(ExternalAddress(Interpreter::throw_StackOverflowError_entry()));
   564   // all done with frame size check
   565   __ bind(after_frame_check_pop);
   566   __ pop(rsi);
   568   __ bind(after_frame_check);
   569 }
   571 // Allocate monitor and lock method (asm interpreter)
   572 // rbx, - methodOop
   573 //
   574 void InterpreterGenerator::lock_method(void) {
   575   // synchronize method
   576   const Address access_flags      (rbx, methodOopDesc::access_flags_offset());
   577   const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize);
   578   const int entry_size            = frame::interpreter_frame_monitor_size() * wordSize;
   580   #ifdef ASSERT
   581     { Label L;
   582       __ movl(rax, access_flags);
   583       __ testl(rax, JVM_ACC_SYNCHRONIZED);
   584       __ jcc(Assembler::notZero, L);
   585       __ stop("method doesn't need synchronization");
   586       __ bind(L);
   587     }
   588   #endif // ASSERT
   589   // get synchronization object
   590   { Label done;
   591     const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
   592     __ movl(rax, access_flags);
   593     __ testl(rax, JVM_ACC_STATIC);
   594     __ movptr(rax, Address(rdi, Interpreter::local_offset_in_bytes(0)));  // get receiver (assume this is frequent case)
   595     __ jcc(Assembler::zero, done);
   596     __ movptr(rax, Address(rbx, methodOopDesc::constants_offset()));
   597     __ movptr(rax, Address(rax, constantPoolOopDesc::pool_holder_offset_in_bytes()));
   598     __ movptr(rax, Address(rax, mirror_offset));
   599     __ bind(done);
   600   }
   601   // add space for monitor & lock
   602   __ subptr(rsp, entry_size);                                           // add space for a monitor entry
   603   __ movptr(monitor_block_top, rsp);                                    // set new monitor block top
   604   __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); // store object
   605   __ mov(rdx, rsp);                                                    // object address
   606   __ lock_object(rdx);
   607 }
   609 //
   610 // Generate a fixed interpreter frame. This is identical setup for interpreted methods
   611 // and for native methods hence the shared code.
   613 void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
   614   // initialize fixed part of activation frame
   615   __ push(rax);                                       // save return address
   616   __ enter();                                         // save old & set new rbp,
   619   __ push(rsi);                                       // set sender sp
   620   __ push((int32_t)NULL_WORD);                        // leave last_sp as null
   621   __ movptr(rsi, Address(rbx,methodOopDesc::const_offset())); // get constMethodOop
   622   __ lea(rsi, Address(rsi,constMethodOopDesc::codes_offset())); // get codebase
   623   __ push(rbx);                                      // save methodOop
   624   if (ProfileInterpreter) {
   625     Label method_data_continue;
   626     __ movptr(rdx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
   627     __ testptr(rdx, rdx);
   628     __ jcc(Assembler::zero, method_data_continue);
   629     __ addptr(rdx, in_bytes(methodDataOopDesc::data_offset()));
   630     __ bind(method_data_continue);
   631     __ push(rdx);                                       // set the mdp (method data pointer)
   632   } else {
   633     __ push(0);
   634   }
   636   __ movptr(rdx, Address(rbx, methodOopDesc::constants_offset()));
   637   __ movptr(rdx, Address(rdx, constantPoolOopDesc::cache_offset_in_bytes()));
   638   __ push(rdx);                                       // set constant pool cache
   639   __ push(rdi);                                       // set locals pointer
   640   if (native_call) {
   641     __ push(0);                                       // no bcp
   642   } else {
   643     __ push(rsi);                                     // set bcp
   644     }
   645   __ push(0);                                         // reserve word for pointer to expression stack bottom
   646   __ movptr(Address(rsp, 0), rsp);                    // set expression stack bottom
   647 }
   649 // End of helpers
   651 //
   652 // Various method entries
   653 //------------------------------------------------------------------------------------------------------------------------
   654 //
   655 //
   657 // Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry
   659 address InterpreterGenerator::generate_accessor_entry(void) {
   661   // rbx,: methodOop
   662   // rcx: receiver (preserve for slow entry into asm interpreter)
   664   // rsi: senderSP must preserved for slow path, set SP to it on fast path
   666   address entry_point = __ pc();
   667   Label xreturn_path;
   669   // do fastpath for resolved accessor methods
   670   if (UseFastAccessorMethods) {
   671     Label slow_path;
   672     // If we need a safepoint check, generate full interpreter entry.
   673     ExternalAddress state(SafepointSynchronize::address_of_state());
   674     __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
   675              SafepointSynchronize::_not_synchronized);
   677     __ jcc(Assembler::notEqual, slow_path);
   678     // ASM/C++ Interpreter
   679     // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1
   680     // Note: We can only use this code if the getfield has been resolved
   681     //       and if we don't have a null-pointer exception => check for
   682     //       these conditions first and use slow path if necessary.
   683     // rbx,: method
   684     // rcx: receiver
   685     __ movptr(rax, Address(rsp, wordSize));
   687     // check if local 0 != NULL and read field
   688     __ testptr(rax, rax);
   689     __ jcc(Assembler::zero, slow_path);
   691     __ movptr(rdi, Address(rbx, methodOopDesc::constants_offset()));
   692     // read first instruction word and extract bytecode @ 1 and index @ 2
   693     __ movptr(rdx, Address(rbx, methodOopDesc::const_offset()));
   694     __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
   695     // Shift codes right to get the index on the right.
   696     // The bytecode fetched looks like <index><0xb4><0x2a>
   697     __ shrl(rdx, 2*BitsPerByte);
   698     __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));
   699     __ movptr(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes()));
   701     // rax,: local 0
   702     // rbx,: method
   703     // rcx: receiver - do not destroy since it is needed for slow path!
   704     // rcx: scratch
   705     // rdx: constant pool cache index
   706     // rdi: constant pool cache
   707     // rsi: sender sp
   709     // check if getfield has been resolved and read constant pool cache entry
   710     // check the validity of the cache entry by testing whether _indices field
   711     // contains Bytecode::_getfield in b1 byte.
   712     assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below");
   713     __ movl(rcx,
   714             Address(rdi,
   715                     rdx,
   716                     Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::indices_offset()));
   717     __ shrl(rcx, 2*BitsPerByte);
   718     __ andl(rcx, 0xFF);
   719     __ cmpl(rcx, Bytecodes::_getfield);
   720     __ jcc(Assembler::notEqual, slow_path);
   722     // Note: constant pool entry is not valid before bytecode is resolved
   723     __ movptr(rcx,
   724               Address(rdi,
   725                       rdx,
   726                       Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::f2_offset()));
   727     __ movl(rdx,
   728             Address(rdi,
   729                     rdx,
   730                     Address::times_ptr, constantPoolCacheOopDesc::base_offset() + ConstantPoolCacheEntry::flags_offset()));
   732     Label notByte, notShort, notChar;
   733     const Address field_address (rax, rcx, Address::times_1);
   735     // Need to differentiate between igetfield, agetfield, bgetfield etc.
   736     // because they are different sizes.
   737     // Use the type from the constant pool cache
   738     __ shrl(rdx, ConstantPoolCacheEntry::tosBits);
   739     // Make sure we don't need to mask rdx for tosBits after the above shift
   740     ConstantPoolCacheEntry::verify_tosBits();
   741     __ cmpl(rdx, btos);
   742     __ jcc(Assembler::notEqual, notByte);
   743     __ load_signed_byte(rax, field_address);
   744     __ jmp(xreturn_path);
   746     __ bind(notByte);
   747     __ cmpl(rdx, stos);
   748     __ jcc(Assembler::notEqual, notShort);
   749     __ load_signed_short(rax, field_address);
   750     __ jmp(xreturn_path);
   752     __ bind(notShort);
   753     __ cmpl(rdx, ctos);
   754     __ jcc(Assembler::notEqual, notChar);
   755     __ load_unsigned_short(rax, field_address);
   756     __ jmp(xreturn_path);
   758     __ bind(notChar);
   759 #ifdef ASSERT
   760     Label okay;
   761     __ cmpl(rdx, atos);
   762     __ jcc(Assembler::equal, okay);
   763     __ cmpl(rdx, itos);
   764     __ jcc(Assembler::equal, okay);
   765     __ stop("what type is this?");
   766     __ bind(okay);
   767 #endif // ASSERT
   768     // All the rest are a 32 bit wordsize
   769     // This is ok for now. Since fast accessors should be going away
   770     __ movptr(rax, field_address);
   772     __ bind(xreturn_path);
   774     // _ireturn/_areturn
   775     __ pop(rdi);                               // get return address
   776     __ mov(rsp, rsi);                          // set sp to sender sp
   777     __ jmp(rdi);
   779     // generate a vanilla interpreter entry as the slow path
   780     __ bind(slow_path);
   782     (void) generate_normal_entry(false);
   783     return entry_point;
   784   }
   785   return NULL;
   787 }
   789 //
   790 // Interpreter stub for calling a native method. (asm interpreter)
   791 // This sets up a somewhat different looking stack for calling the native method
   792 // than the typical interpreter frame setup.
   793 //
   795 address InterpreterGenerator::generate_native_entry(bool synchronized) {
   796   // determine code generation flags
   797   bool inc_counter  = UseCompiler || CountCompiledCalls;
   799   // rbx,: methodOop
   800   // rsi: sender sp
   801   // rsi: previous interpreter state (C++ interpreter) must preserve
   802   address entry_point = __ pc();
   805   const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
   806   const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
   807   const Address access_flags      (rbx, methodOopDesc::access_flags_offset());
   809   // get parameter size (always needed)
   810   __ load_unsigned_short(rcx, size_of_parameters);
   812   // native calls don't need the stack size check since they have no expression stack
   813   // and the arguments are already on the stack and we only add a handful of words
   814   // to the stack
   816   // rbx,: methodOop
   817   // rcx: size of parameters
   818   // rsi: sender sp
   820   __ pop(rax);                                       // get return address
   821   // for natives the size of locals is zero
   823   // compute beginning of parameters (rdi)
   824   __ lea(rdi, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize));
   827   // add 2 zero-initialized slots for native calls
   828   // NULL result handler
   829   __ push((int32_t)NULL_WORD);
   830   // NULL oop temp (mirror or jni oop result)
   831   __ push((int32_t)NULL_WORD);
   833   if (inc_counter) __ movl(rcx, invocation_counter);  // (pre-)fetch invocation count
   834   // initialize fixed part of activation frame
   836   generate_fixed_frame(true);
   838   // make sure method is native & not abstract
   839 #ifdef ASSERT
   840   __ movl(rax, access_flags);
   841   {
   842     Label L;
   843     __ testl(rax, JVM_ACC_NATIVE);
   844     __ jcc(Assembler::notZero, L);
   845     __ stop("tried to execute non-native method as native");
   846     __ bind(L);
   847   }
   848   { Label L;
   849     __ testl(rax, JVM_ACC_ABSTRACT);
   850     __ jcc(Assembler::zero, L);
   851     __ stop("tried to execute abstract method in interpreter");
   852     __ bind(L);
   853   }
   854 #endif
   856   // Since at this point in the method invocation the exception handler
   857   // would try to exit the monitor of synchronized methods which hasn't
   858   // been entered yet, we set the thread local variable
   859   // _do_not_unlock_if_synchronized to true. The remove_activation will
   860   // check this flag.
   862   __ get_thread(rax);
   863   const Address do_not_unlock_if_synchronized(rax,
   864         in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
   865   __ movbool(do_not_unlock_if_synchronized, true);
   867   // increment invocation count & check for overflow
   868   Label invocation_counter_overflow;
   869   if (inc_counter) {
   870     generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
   871   }
   873   Label continue_after_compile;
   874   __ bind(continue_after_compile);
   876   bang_stack_shadow_pages(true);
   878   // reset the _do_not_unlock_if_synchronized flag
   879   __ get_thread(rax);
   880   __ movbool(do_not_unlock_if_synchronized, false);
   882   // check for synchronized methods
   883   // Must happen AFTER invocation_counter check and stack overflow check,
   884   // so method is not locked if overflows.
   885   //
   886   if (synchronized) {
   887     lock_method();
   888   } else {
   889     // no synchronization necessary
   890 #ifdef ASSERT
   891       { Label L;
   892         __ movl(rax, access_flags);
   893         __ testl(rax, JVM_ACC_SYNCHRONIZED);
   894         __ jcc(Assembler::zero, L);
   895         __ stop("method needs synchronization");
   896         __ bind(L);
   897       }
   898 #endif
   899   }
   901   // start execution
   902 #ifdef ASSERT
   903   { Label L;
   904     const Address monitor_block_top (rbp,
   905                  frame::interpreter_frame_monitor_block_top_offset * wordSize);
   906     __ movptr(rax, monitor_block_top);
   907     __ cmpptr(rax, rsp);
   908     __ jcc(Assembler::equal, L);
   909     __ stop("broken stack frame setup in interpreter");
   910     __ bind(L);
   911   }
   912 #endif
   914   // jvmti/dtrace support
   915   __ notify_method_entry();
   917   // work registers
   918   const Register method = rbx;
   919   const Register thread = rdi;
   920   const Register t      = rcx;
   922   // allocate space for parameters
   923   __ get_method(method);
   924   __ verify_oop(method);
   925   __ load_unsigned_short(t, Address(method, methodOopDesc::size_of_parameters_offset()));
   926   __ shlptr(t, Interpreter::logStackElementSize);
   927   __ addptr(t, 2*wordSize);     // allocate two more slots for JNIEnv and possible mirror
   928   __ subptr(rsp, t);
   929   __ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics
   931   // get signature handler
   932   { Label L;
   933     __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
   934     __ testptr(t, t);
   935     __ jcc(Assembler::notZero, L);
   936     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
   937     __ get_method(method);
   938     __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
   939     __ bind(L);
   940   }
   942   // call signature handler
   943   assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rdi, "adjust this code");
   944   assert(InterpreterRuntime::SignatureHandlerGenerator::to  () == rsp, "adjust this code");
   945   assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t  , "adjust this code");
   946   // The generated handlers do not touch RBX (the method oop).
   947   // However, large signatures cannot be cached and are generated
   948   // each time here.  The slow-path generator will blow RBX
   949   // sometime, so we must reload it after the call.
   950   __ call(t);
   951   __ get_method(method);        // slow path call blows RBX on DevStudio 5.0
   953   // result handler is in rax,
   954   // set result handler
   955   __ movptr(Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize), rax);
   957   // pass mirror handle if static call
   958   { Label L;
   959     const int mirror_offset = klassOopDesc::klass_part_offset_in_bytes() + Klass::java_mirror_offset_in_bytes();
   960     __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
   961     __ testl(t, JVM_ACC_STATIC);
   962     __ jcc(Assembler::zero, L);
   963     // get mirror
   964     __ movptr(t, Address(method, methodOopDesc:: constants_offset()));
   965     __ movptr(t, Address(t, constantPoolOopDesc::pool_holder_offset_in_bytes()));
   966     __ movptr(t, Address(t, mirror_offset));
   967     // copy mirror into activation frame
   968     __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize), t);
   969     // pass handle to mirror
   970     __ lea(t, Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize));
   971     __ movptr(Address(rsp, wordSize), t);
   972     __ bind(L);
   973   }
   975   // get native function entry point
   976   { Label L;
   977     __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
   978     ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
   979     __ cmpptr(rax, unsatisfied.addr());
   980     __ jcc(Assembler::notEqual, L);
   981     __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method);
   982     __ get_method(method);
   983     __ verify_oop(method);
   984     __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
   985     __ bind(L);
   986   }
   988   // pass JNIEnv
   989   __ get_thread(thread);
   990   __ lea(t, Address(thread, JavaThread::jni_environment_offset()));
   991   __ movptr(Address(rsp, 0), t);
   993   // set_last_Java_frame_before_call
   994   // It is enough that the pc()
   995   // points into the right code segment. It does not have to be the correct return pc.
   996   __ set_last_Java_frame(thread, noreg, rbp, __ pc());
   998   // change thread state
   999 #ifdef ASSERT
  1000   { Label L;
  1001     __ movl(t, Address(thread, JavaThread::thread_state_offset()));
  1002     __ cmpl(t, _thread_in_Java);
  1003     __ jcc(Assembler::equal, L);
  1004     __ stop("Wrong thread state in native stub");
  1005     __ bind(L);
  1007 #endif
  1009   // Change state to native
  1010   __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native);
  1011   __ call(rax);
  1013   // result potentially in rdx:rax or ST0
  1015   // Either restore the MXCSR register after returning from the JNI Call
  1016   // or verify that it wasn't changed.
  1017   if (VM_Version::supports_sse()) {
  1018     if (RestoreMXCSROnJNICalls) {
  1019       __ ldmxcsr(ExternalAddress(StubRoutines::addr_mxcsr_std()));
  1021     else if (CheckJNICalls ) {
  1022       __ call(RuntimeAddress(StubRoutines::x86::verify_mxcsr_entry()));
  1026   // Either restore the x87 floating pointer control word after returning
  1027   // from the JNI call or verify that it wasn't changed.
  1028   if (CheckJNICalls) {
  1029     __ call(RuntimeAddress(StubRoutines::x86::verify_fpu_cntrl_wrd_entry()));
  1032   // save potential result in ST(0) & rdx:rax
  1033   // (if result handler is the T_FLOAT or T_DOUBLE handler, result must be in ST0 -
  1034   // the check is necessary to avoid potential Intel FPU overflow problems by saving/restoring 'empty' FPU registers)
  1035   // It is safe to do this push because state is _thread_in_native and return address will be found
  1036   // via _last_native_pc and not via _last_jave_sp
  1038   // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result.
  1039   // If the order changes or anything else is added to the stack the code in
  1040   // interpreter_frame_result will have to be changed.
  1042   { Label L;
  1043     Label push_double;
  1044     ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT));
  1045     ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE));
  1046     __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize),
  1047               float_handler.addr());
  1048     __ jcc(Assembler::equal, push_double);
  1049     __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize),
  1050               double_handler.addr());
  1051     __ jcc(Assembler::notEqual, L);
  1052     __ bind(push_double);
  1053     __ push(dtos);
  1054     __ bind(L);
  1056   __ push(ltos);
  1058   // change thread state
  1059   __ get_thread(thread);
  1060   __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans);
  1061   if(os::is_MP()) {
  1062     if (UseMembar) {
  1063       // Force this write out before the read below
  1064       __ membar(Assembler::Membar_mask_bits(
  1065            Assembler::LoadLoad | Assembler::LoadStore |
  1066            Assembler::StoreLoad | Assembler::StoreStore));
  1067     } else {
  1068       // Write serialization page so VM thread can do a pseudo remote membar.
  1069       // We use the current thread pointer to calculate a thread specific
  1070       // offset to write to within the page. This minimizes bus traffic
  1071       // due to cache line collision.
  1072       __ serialize_memory(thread, rcx);
  1076   if (AlwaysRestoreFPU) {
  1077     //  Make sure the control word is correct.
  1078     __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std()));
  1081   // check for safepoint operation in progress and/or pending suspend requests
  1082   { Label Continue;
  1084     __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
  1085              SafepointSynchronize::_not_synchronized);
  1087     Label L;
  1088     __ jcc(Assembler::notEqual, L);
  1089     __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0);
  1090     __ jcc(Assembler::equal, Continue);
  1091     __ bind(L);
  1093     // Don't use call_VM as it will see a possible pending exception and forward it
  1094     // and never return here preventing us from clearing _last_native_pc down below.
  1095     // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are
  1096     // preserved and correspond to the bcp/locals pointers. So we do a runtime call
  1097     // by hand.
  1098     //
  1099     __ push(thread);
  1100     __ call(RuntimeAddress(CAST_FROM_FN_PTR(address,
  1101                                             JavaThread::check_special_condition_for_native_trans)));
  1102     __ increment(rsp, wordSize);
  1103     __ get_thread(thread);
  1105     __ bind(Continue);
  1108   // change thread state
  1109   __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java);
  1111   __ reset_last_Java_frame(thread, true, true);
  1113   // reset handle block
  1114   __ movptr(t, Address(thread, JavaThread::active_handles_offset()));
  1115   __ movptr(Address(t, JNIHandleBlock::top_offset_in_bytes()), NULL_WORD);
  1117   // If result was an oop then unbox and save it in the frame
  1118   { Label L;
  1119     Label no_oop, store_result;
  1120     ExternalAddress handler(AbstractInterpreter::result_handler(T_OBJECT));
  1121     __ cmpptr(Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize),
  1122               handler.addr());
  1123     __ jcc(Assembler::notEqual, no_oop);
  1124     __ cmpptr(Address(rsp, 0), (int32_t)NULL_WORD);
  1125     __ pop(ltos);
  1126     __ testptr(rax, rax);
  1127     __ jcc(Assembler::zero, store_result);
  1128     // unbox
  1129     __ movptr(rax, Address(rax, 0));
  1130     __ bind(store_result);
  1131     __ movptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset)*wordSize), rax);
  1132     // keep stack depth as expected by pushing oop which will eventually be discarded
  1133     __ push(ltos);
  1134     __ bind(no_oop);
  1138      Label no_reguard;
  1139      __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled);
  1140      __ jcc(Assembler::notEqual, no_reguard);
  1142      __ pusha();
  1143      __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
  1144      __ popa();
  1146      __ bind(no_reguard);
  1149   // restore rsi to have legal interpreter frame,
  1150   // i.e., bci == 0 <=> rsi == code_base()
  1151   // Can't call_VM until bcp is within reasonable.
  1152   __ get_method(method);      // method is junk from thread_in_native to now.
  1153   __ verify_oop(method);
  1154   __ movptr(rsi, Address(method,methodOopDesc::const_offset()));   // get constMethodOop
  1155   __ lea(rsi, Address(rsi,constMethodOopDesc::codes_offset()));    // get codebase
  1157   // handle exceptions (exception handling will handle unlocking!)
  1158   { Label L;
  1159     __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
  1160     __ jcc(Assembler::zero, L);
  1161     // Note: At some point we may want to unify this with the code used in call_VM_base();
  1162     //       i.e., we should use the StubRoutines::forward_exception code. For now this
  1163     //       doesn't work here because the rsp is not correctly set at this point.
  1164     __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception));
  1165     __ should_not_reach_here();
  1166     __ bind(L);
  1169   // do unlocking if necessary
  1170   { Label L;
  1171     __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
  1172     __ testl(t, JVM_ACC_SYNCHRONIZED);
  1173     __ jcc(Assembler::zero, L);
  1174     // the code below should be shared with interpreter macro assembler implementation
  1175     { Label unlock;
  1176       // BasicObjectLock will be first in list, since this is a synchronized method. However, need
  1177       // to check that the object has not been unlocked by an explicit monitorexit bytecode.
  1178       const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock));
  1180       __ lea(rdx, monitor);                   // address of first monitor
  1182       __ movptr(t, Address(rdx, BasicObjectLock::obj_offset_in_bytes()));
  1183       __ testptr(t, t);
  1184       __ jcc(Assembler::notZero, unlock);
  1186       // Entry already unlocked, need to throw exception
  1187       __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception));
  1188       __ should_not_reach_here();
  1190       __ bind(unlock);
  1191       __ unlock_object(rdx);
  1193     __ bind(L);
  1196   // jvmti/dtrace support
  1197   // Note: This must happen _after_ handling/throwing any exceptions since
  1198   //       the exception handler code notifies the runtime of method exits
  1199   //       too. If this happens before, method entry/exit notifications are
  1200   //       not properly paired (was bug - gri 11/22/99).
  1201   __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
  1203   // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result
  1204   __ pop(ltos);
  1205   __ movptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize));
  1206   __ call(t);
  1208   // remove activation
  1209   __ movptr(t, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp
  1210   __ leave();                                // remove frame anchor
  1211   __ pop(rdi);                               // get return address
  1212   __ mov(rsp, t);                            // set sp to sender sp
  1213   __ jmp(rdi);
  1215   if (inc_counter) {
  1216     // Handle overflow of counter and compile method
  1217     __ bind(invocation_counter_overflow);
  1218     generate_counter_overflow(&continue_after_compile);
  1221   return entry_point;
  1224 //
  1225 // Generic interpreted method entry to (asm) interpreter
  1226 //
  1227 address InterpreterGenerator::generate_normal_entry(bool synchronized) {
  1228   // determine code generation flags
  1229   bool inc_counter  = UseCompiler || CountCompiledCalls;
  1231   // rbx,: methodOop
  1232   // rsi: sender sp
  1233   address entry_point = __ pc();
  1236   const Address size_of_parameters(rbx, methodOopDesc::size_of_parameters_offset());
  1237   const Address size_of_locals    (rbx, methodOopDesc::size_of_locals_offset());
  1238   const Address invocation_counter(rbx, methodOopDesc::invocation_counter_offset() + InvocationCounter::counter_offset());
  1239   const Address access_flags      (rbx, methodOopDesc::access_flags_offset());
  1241   // get parameter size (always needed)
  1242   __ load_unsigned_short(rcx, size_of_parameters);
  1244   // rbx,: methodOop
  1245   // rcx: size of parameters
  1247   // rsi: sender_sp (could differ from sp+wordSize if we were called via c2i )
  1249   __ load_unsigned_short(rdx, size_of_locals);       // get size of locals in words
  1250   __ subl(rdx, rcx);                                // rdx = no. of additional locals
  1252   // see if we've got enough room on the stack for locals plus overhead.
  1253   generate_stack_overflow_check();
  1255   // get return address
  1256   __ pop(rax);
  1258   // compute beginning of parameters (rdi)
  1259   __ lea(rdi, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize));
  1261   // rdx - # of additional locals
  1262   // allocate space for locals
  1263   // explicitly initialize locals
  1265     Label exit, loop;
  1266     __ testl(rdx, rdx);
  1267     __ jcc(Assembler::lessEqual, exit);               // do nothing if rdx <= 0
  1268     __ bind(loop);
  1269     __ push((int32_t)NULL_WORD);                      // initialize local variables
  1270     __ decrement(rdx);                                // until everything initialized
  1271     __ jcc(Assembler::greater, loop);
  1272     __ bind(exit);
  1275   if (inc_counter) __ movl(rcx, invocation_counter);  // (pre-)fetch invocation count
  1276   // initialize fixed part of activation frame
  1277   generate_fixed_frame(false);
  1279   // make sure method is not native & not abstract
  1280 #ifdef ASSERT
  1281   __ movl(rax, access_flags);
  1283     Label L;
  1284     __ testl(rax, JVM_ACC_NATIVE);
  1285     __ jcc(Assembler::zero, L);
  1286     __ stop("tried to execute native method as non-native");
  1287     __ bind(L);
  1289   { Label L;
  1290     __ testl(rax, JVM_ACC_ABSTRACT);
  1291     __ jcc(Assembler::zero, L);
  1292     __ stop("tried to execute abstract method in interpreter");
  1293     __ bind(L);
  1295 #endif
  1297   // Since at this point in the method invocation the exception handler
  1298   // would try to exit the monitor of synchronized methods which hasn't
  1299   // been entered yet, we set the thread local variable
  1300   // _do_not_unlock_if_synchronized to true. The remove_activation will
  1301   // check this flag.
  1303   __ get_thread(rax);
  1304   const Address do_not_unlock_if_synchronized(rax,
  1305         in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
  1306   __ movbool(do_not_unlock_if_synchronized, true);
  1308   // increment invocation count & check for overflow
  1309   Label invocation_counter_overflow;
  1310   Label profile_method;
  1311   Label profile_method_continue;
  1312   if (inc_counter) {
  1313     generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue);
  1314     if (ProfileInterpreter) {
  1315       __ bind(profile_method_continue);
  1318   Label continue_after_compile;
  1319   __ bind(continue_after_compile);
  1321   bang_stack_shadow_pages(false);
  1323   // reset the _do_not_unlock_if_synchronized flag
  1324   __ get_thread(rax);
  1325   __ movbool(do_not_unlock_if_synchronized, false);
  1327   // check for synchronized methods
  1328   // Must happen AFTER invocation_counter check and stack overflow check,
  1329   // so method is not locked if overflows.
  1330   //
  1331   if (synchronized) {
  1332     // Allocate monitor and lock method
  1333     lock_method();
  1334   } else {
  1335     // no synchronization necessary
  1336 #ifdef ASSERT
  1337       { Label L;
  1338         __ movl(rax, access_flags);
  1339         __ testl(rax, JVM_ACC_SYNCHRONIZED);
  1340         __ jcc(Assembler::zero, L);
  1341         __ stop("method needs synchronization");
  1342         __ bind(L);
  1344 #endif
  1347   // start execution
  1348 #ifdef ASSERT
  1349   { Label L;
  1350      const Address monitor_block_top (rbp,
  1351                  frame::interpreter_frame_monitor_block_top_offset * wordSize);
  1352     __ movptr(rax, monitor_block_top);
  1353     __ cmpptr(rax, rsp);
  1354     __ jcc(Assembler::equal, L);
  1355     __ stop("broken stack frame setup in interpreter");
  1356     __ bind(L);
  1358 #endif
  1360   // jvmti support
  1361   __ notify_method_entry();
  1363   __ dispatch_next(vtos);
  1365   // invocation counter overflow
  1366   if (inc_counter) {
  1367     if (ProfileInterpreter) {
  1368       // We have decided to profile this method in the interpreter
  1369       __ bind(profile_method);
  1370       __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
  1371       __ set_method_data_pointer_for_bcp();
  1372       __ get_method(rbx);
  1373       __ jmp(profile_method_continue);
  1375     // Handle overflow of counter and compile method
  1376     __ bind(invocation_counter_overflow);
  1377     generate_counter_overflow(&continue_after_compile);
  1380   return entry_point;
  1383 //------------------------------------------------------------------------------------------------------------------------
  1384 // Entry points
  1385 //
  1386 // Here we generate the various kind of entries into the interpreter.
  1387 // The two main entry type are generic bytecode methods and native call method.
  1388 // These both come in synchronized and non-synchronized versions but the
  1389 // frame layout they create is very similar. The other method entry
  1390 // types are really just special purpose entries that are really entry
  1391 // and interpretation all in one. These are for trivial methods like
  1392 // accessor, empty, or special math methods.
  1393 //
  1394 // When control flow reaches any of the entry types for the interpreter
  1395 // the following holds ->
  1396 //
  1397 // Arguments:
  1398 //
  1399 // rbx,: methodOop
  1400 // rcx: receiver
  1401 //
  1402 //
  1403 // Stack layout immediately at entry
  1404 //
  1405 // [ return address     ] <--- rsp
  1406 // [ parameter n        ]
  1407 //   ...
  1408 // [ parameter 1        ]
  1409 // [ expression stack   ] (caller's java expression stack)
  1411 // Assuming that we don't go to one of the trivial specialized
  1412 // entries the stack will look like below when we are ready to execute
  1413 // the first bytecode (or call the native routine). The register usage
  1414 // will be as the template based interpreter expects (see interpreter_x86.hpp).
  1415 //
  1416 // local variables follow incoming parameters immediately; i.e.
  1417 // the return address is moved to the end of the locals).
  1418 //
  1419 // [ monitor entry      ] <--- rsp
  1420 //   ...
  1421 // [ monitor entry      ]
  1422 // [ expr. stack bottom ]
  1423 // [ saved rsi          ]
  1424 // [ current rdi        ]
  1425 // [ methodOop          ]
  1426 // [ saved rbp,          ] <--- rbp,
  1427 // [ return address     ]
  1428 // [ local variable m   ]
  1429 //   ...
  1430 // [ local variable 1   ]
  1431 // [ parameter n        ]
  1432 //   ...
  1433 // [ parameter 1        ] <--- rdi
  1435 address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) {
  1436   // determine code generation flags
  1437   bool synchronized = false;
  1438   address entry_point = NULL;
  1440   switch (kind) {
  1441     case Interpreter::zerolocals             :                                                                             break;
  1442     case Interpreter::zerolocals_synchronized: synchronized = true;                                                        break;
  1443     case Interpreter::native                 : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false);  break;
  1444     case Interpreter::native_synchronized    : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true);   break;
  1445     case Interpreter::empty                  : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry();        break;
  1446     case Interpreter::accessor               : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry();     break;
  1447     case Interpreter::abstract               : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry();     break;
  1448     case Interpreter::method_handle          : entry_point = ((InterpreterGenerator*)this)->generate_method_handle_entry(); break;
  1450     case Interpreter::java_lang_math_sin     : // fall thru
  1451     case Interpreter::java_lang_math_cos     : // fall thru
  1452     case Interpreter::java_lang_math_tan     : // fall thru
  1453     case Interpreter::java_lang_math_abs     : // fall thru
  1454     case Interpreter::java_lang_math_log     : // fall thru
  1455     case Interpreter::java_lang_math_log10   : // fall thru
  1456     case Interpreter::java_lang_math_sqrt    : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind);     break;
  1457     default                                  : ShouldNotReachHere();                                                       break;
  1460   if (entry_point) return entry_point;
  1462   return ((InterpreterGenerator*)this)->generate_normal_entry(synchronized);
  1466 // These should never be compiled since the interpreter will prefer
  1467 // the compiled version to the intrinsic version.
  1468 bool AbstractInterpreter::can_be_compiled(methodHandle m) {
  1469   switch (method_kind(m)) {
  1470     case Interpreter::java_lang_math_sin     : // fall thru
  1471     case Interpreter::java_lang_math_cos     : // fall thru
  1472     case Interpreter::java_lang_math_tan     : // fall thru
  1473     case Interpreter::java_lang_math_abs     : // fall thru
  1474     case Interpreter::java_lang_math_log     : // fall thru
  1475     case Interpreter::java_lang_math_log10   : // fall thru
  1476     case Interpreter::java_lang_math_sqrt    :
  1477       return false;
  1478     default:
  1479       return true;
  1483 // How much stack a method activation needs in words.
  1484 int AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
  1486   const int stub_code = 4;  // see generate_call_stub
  1487   // Save space for one monitor to get into the interpreted method in case
  1488   // the method is synchronized
  1489   int monitor_size    = method->is_synchronized() ?
  1490                                 1*frame::interpreter_frame_monitor_size() : 0;
  1492   // total overhead size: entry_size + (saved rbp, thru expr stack bottom).
  1493   // be sure to change this if you add/subtract anything to/from the overhead area
  1494   const int overhead_size = -frame::interpreter_frame_initial_sp_offset;
  1496   const int extra_stack = methodOopDesc::extra_stack_entries();
  1497   const int method_stack = (method->max_locals() + method->max_stack() + extra_stack) *
  1498                            Interpreter::stackElementWords;
  1499   return overhead_size + method_stack + stub_code;
  1502 // asm based interpreter deoptimization helpers
  1504 int AbstractInterpreter::layout_activation(methodOop method,
  1505                                            int tempcount,
  1506                                            int popframe_extra_args,
  1507                                            int moncount,
  1508                                            int callee_param_count,
  1509                                            int callee_locals,
  1510                                            frame* caller,
  1511                                            frame* interpreter_frame,
  1512                                            bool is_top_frame) {
  1513   // Note: This calculation must exactly parallel the frame setup
  1514   // in AbstractInterpreterGenerator::generate_method_entry.
  1515   // If interpreter_frame!=NULL, set up the method, locals, and monitors.
  1516   // The frame interpreter_frame, if not NULL, is guaranteed to be the right size,
  1517   // as determined by a previous call to this method.
  1518   // It is also guaranteed to be walkable even though it is in a skeletal state
  1519   // NOTE: return size is in words not bytes
  1521   // fixed size of an interpreter frame:
  1522   int max_locals = method->max_locals() * Interpreter::stackElementWords;
  1523   int extra_locals = (method->max_locals() - method->size_of_parameters()) *
  1524                      Interpreter::stackElementWords;
  1526   int overhead = frame::sender_sp_offset - frame::interpreter_frame_initial_sp_offset;
  1528   // Our locals were accounted for by the caller (or last_frame_adjust on the transistion)
  1529   // Since the callee parameters already account for the callee's params we only need to account for
  1530   // the extra locals.
  1533   int size = overhead +
  1534          ((callee_locals - callee_param_count)*Interpreter::stackElementWords) +
  1535          (moncount*frame::interpreter_frame_monitor_size()) +
  1536          tempcount*Interpreter::stackElementWords + popframe_extra_args;
  1538   if (interpreter_frame != NULL) {
  1539 #ifdef ASSERT
  1540     if (!EnableMethodHandles)
  1541       // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
  1542       // Probably, since deoptimization doesn't work yet.
  1543       assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
  1544     assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable(2)");
  1545 #endif
  1547     interpreter_frame->interpreter_frame_set_method(method);
  1548     // NOTE the difference in using sender_sp and interpreter_frame_sender_sp
  1549     // interpreter_frame_sender_sp is the original sp of the caller (the unextended_sp)
  1550     // and sender_sp is fp+8
  1551     intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
  1553     interpreter_frame->interpreter_frame_set_locals(locals);
  1554     BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
  1555     BasicObjectLock* monbot = montop - moncount;
  1556     interpreter_frame->interpreter_frame_set_monitor_end(monbot);
  1558     // Set last_sp
  1559     intptr_t*  rsp = (intptr_t*) monbot  -
  1560                      tempcount*Interpreter::stackElementWords -
  1561                      popframe_extra_args;
  1562     interpreter_frame->interpreter_frame_set_last_sp(rsp);
  1564     // All frames but the initial (oldest) interpreter frame we fill in have a
  1565     // value for sender_sp that allows walking the stack but isn't
  1566     // truly correct. Correct the value here.
  1568     if (extra_locals != 0 &&
  1569         interpreter_frame->sender_sp() == interpreter_frame->interpreter_frame_sender_sp() ) {
  1570       interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() + extra_locals);
  1572     *interpreter_frame->interpreter_frame_cache_addr() =
  1573       method->constants()->cache();
  1575   return size;
  1579 //------------------------------------------------------------------------------------------------------------------------
  1580 // Exceptions
  1582 void TemplateInterpreterGenerator::generate_throw_exception() {
  1583   // Entry point in previous activation (i.e., if the caller was interpreted)
  1584   Interpreter::_rethrow_exception_entry = __ pc();
  1585   const Register thread = rcx;
  1587   // Restore sp to interpreter_frame_last_sp even though we are going
  1588   // to empty the expression stack for the exception processing.
  1589   __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
  1590   // rax,: exception
  1591   // rdx: return address/pc that threw exception
  1592   __ restore_bcp();                              // rsi points to call/send
  1593   __ restore_locals();
  1595   // Entry point for exceptions thrown within interpreter code
  1596   Interpreter::_throw_exception_entry = __ pc();
  1597   // expression stack is undefined here
  1598   // rax,: exception
  1599   // rsi: exception bcp
  1600   __ verify_oop(rax);
  1602   // expression stack must be empty before entering the VM in case of an exception
  1603   __ empty_expression_stack();
  1604   __ empty_FPU_stack();
  1605   // find exception handler address and preserve exception oop
  1606   __ call_VM(rdx, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), rax);
  1607   // rax,: exception handler entry point
  1608   // rdx: preserved exception oop
  1609   // rsi: bcp for exception handler
  1610   __ push_ptr(rdx);                              // push exception which is now the only value on the stack
  1611   __ jmp(rax);                                   // jump to exception handler (may be _remove_activation_entry!)
  1613   // If the exception is not handled in the current frame the frame is removed and
  1614   // the exception is rethrown (i.e. exception continuation is _rethrow_exception).
  1615   //
  1616   // Note: At this point the bci is still the bxi for the instruction which caused
  1617   //       the exception and the expression stack is empty. Thus, for any VM calls
  1618   //       at this point, GC will find a legal oop map (with empty expression stack).
  1620   // In current activation
  1621   // tos: exception
  1622   // rsi: exception bcp
  1624   //
  1625   // JVMTI PopFrame support
  1626   //
  1628    Interpreter::_remove_activation_preserving_args_entry = __ pc();
  1629   __ empty_expression_stack();
  1630   __ empty_FPU_stack();
  1631   // Set the popframe_processing bit in pending_popframe_condition indicating that we are
  1632   // currently handling popframe, so that call_VMs that may happen later do not trigger new
  1633   // popframe handling cycles.
  1634   __ get_thread(thread);
  1635   __ movl(rdx, Address(thread, JavaThread::popframe_condition_offset()));
  1636   __ orl(rdx, JavaThread::popframe_processing_bit);
  1637   __ movl(Address(thread, JavaThread::popframe_condition_offset()), rdx);
  1640     // Check to see whether we are returning to a deoptimized frame.
  1641     // (The PopFrame call ensures that the caller of the popped frame is
  1642     // either interpreted or compiled and deoptimizes it if compiled.)
  1643     // In this case, we can't call dispatch_next() after the frame is
  1644     // popped, but instead must save the incoming arguments and restore
  1645     // them after deoptimization has occurred.
  1646     //
  1647     // Note that we don't compare the return PC against the
  1648     // deoptimization blob's unpack entry because of the presence of
  1649     // adapter frames in C2.
  1650     Label caller_not_deoptimized;
  1651     __ movptr(rdx, Address(rbp, frame::return_addr_offset * wordSize));
  1652     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), rdx);
  1653     __ testl(rax, rax);
  1654     __ jcc(Assembler::notZero, caller_not_deoptimized);
  1656     // Compute size of arguments for saving when returning to deoptimized caller
  1657     __ get_method(rax);
  1658     __ verify_oop(rax);
  1659     __ load_unsigned_short(rax, Address(rax, in_bytes(methodOopDesc::size_of_parameters_offset())));
  1660     __ shlptr(rax, Interpreter::logStackElementSize);
  1661     __ restore_locals();
  1662     __ subptr(rdi, rax);
  1663     __ addptr(rdi, wordSize);
  1664     // Save these arguments
  1665     __ get_thread(thread);
  1666     __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), thread, rax, rdi);
  1668     __ remove_activation(vtos, rdx,
  1669                          /* throw_monitor_exception */ false,
  1670                          /* install_monitor_exception */ false,
  1671                          /* notify_jvmdi */ false);
  1673     // Inform deoptimization that it is responsible for restoring these arguments
  1674     __ get_thread(thread);
  1675     __ movl(Address(thread, JavaThread::popframe_condition_offset()), JavaThread::popframe_force_deopt_reexecution_bit);
  1677     // Continue in deoptimization handler
  1678     __ jmp(rdx);
  1680     __ bind(caller_not_deoptimized);
  1683   __ remove_activation(vtos, rdx,
  1684                        /* throw_monitor_exception */ false,
  1685                        /* install_monitor_exception */ false,
  1686                        /* notify_jvmdi */ false);
  1688   // Finish with popframe handling
  1689   // A previous I2C followed by a deoptimization might have moved the
  1690   // outgoing arguments further up the stack. PopFrame expects the
  1691   // mutations to those outgoing arguments to be preserved and other
  1692   // constraints basically require this frame to look exactly as
  1693   // though it had previously invoked an interpreted activation with
  1694   // no space between the top of the expression stack (current
  1695   // last_sp) and the top of stack. Rather than force deopt to
  1696   // maintain this kind of invariant all the time we call a small
  1697   // fixup routine to move the mutated arguments onto the top of our
  1698   // expression stack if necessary.
  1699   __ mov(rax, rsp);
  1700   __ movptr(rbx, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
  1701   __ get_thread(thread);
  1702   // PC must point into interpreter here
  1703   __ set_last_Java_frame(thread, noreg, rbp, __ pc());
  1704   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, rax, rbx);
  1705   __ get_thread(thread);
  1706   __ reset_last_Java_frame(thread, true, true);
  1707   // Restore the last_sp and null it out
  1708   __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
  1709   __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD);
  1711   __ restore_bcp();
  1712   __ restore_locals();
  1713   // The method data pointer was incremented already during
  1714   // call profiling. We have to restore the mdp for the current bcp.
  1715   if (ProfileInterpreter) {
  1716     __ set_method_data_pointer_for_bcp();
  1719   // Clear the popframe condition flag
  1720   __ get_thread(thread);
  1721   __ movl(Address(thread, JavaThread::popframe_condition_offset()), JavaThread::popframe_inactive);
  1723   __ dispatch_next(vtos);
  1724   // end of PopFrame support
  1726   Interpreter::_remove_activation_entry = __ pc();
  1728   // preserve exception over this code sequence
  1729   __ pop_ptr(rax);
  1730   __ get_thread(thread);
  1731   __ movptr(Address(thread, JavaThread::vm_result_offset()), rax);
  1732   // remove the activation (without doing throws on illegalMonitorExceptions)
  1733   __ remove_activation(vtos, rdx, false, true, false);
  1734   // restore exception
  1735   __ get_thread(thread);
  1736   __ movptr(rax, Address(thread, JavaThread::vm_result_offset()));
  1737   __ movptr(Address(thread, JavaThread::vm_result_offset()), NULL_WORD);
  1738   __ verify_oop(rax);
  1740   // Inbetween activations - previous activation type unknown yet
  1741   // compute continuation point - the continuation point expects
  1742   // the following registers set up:
  1743   //
  1744   // rax: exception
  1745   // rdx: return address/pc that threw exception
  1746   // rsp: expression stack of caller
  1747   // rbp: rbp, of caller
  1748   __ push(rax);                                  // save exception
  1749   __ push(rdx);                                  // save return address
  1750   __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, rdx);
  1751   __ mov(rbx, rax);                              // save exception handler
  1752   __ pop(rdx);                                   // restore return address
  1753   __ pop(rax);                                   // restore exception
  1754   // Note that an "issuing PC" is actually the next PC after the call
  1755   __ jmp(rbx);                                   // jump to exception handler of caller
  1759 //
  1760 // JVMTI ForceEarlyReturn support
  1761 //
  1762 address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
  1763   address entry = __ pc();
  1764   const Register thread = rcx;
  1766   __ restore_bcp();
  1767   __ restore_locals();
  1768   __ empty_expression_stack();
  1769   __ empty_FPU_stack();
  1770   __ load_earlyret_value(state);
  1772   __ get_thread(thread);
  1773   __ movptr(rcx, Address(thread, JavaThread::jvmti_thread_state_offset()));
  1774   const Address cond_addr(rcx, JvmtiThreadState::earlyret_state_offset());
  1776   // Clear the earlyret state
  1777   __ movl(cond_addr, JvmtiThreadState::earlyret_inactive);
  1779   __ remove_activation(state, rsi,
  1780                        false, /* throw_monitor_exception */
  1781                        false, /* install_monitor_exception */
  1782                        true); /* notify_jvmdi */
  1783   __ jmp(rsi);
  1784   return entry;
  1785 } // end of ForceEarlyReturn support
  1788 //------------------------------------------------------------------------------------------------------------------------
  1789 // Helper for vtos entry point generation
  1791 void TemplateInterpreterGenerator::set_vtos_entry_points (Template* t, address& bep, address& cep, address& sep, address& aep, address& iep, address& lep, address& fep, address& dep, address& vep) {
  1792   assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
  1793   Label L;
  1794   fep = __ pc(); __ push(ftos); __ jmp(L);
  1795   dep = __ pc(); __ push(dtos); __ jmp(L);
  1796   lep = __ pc(); __ push(ltos); __ jmp(L);
  1797   aep = __ pc(); __ push(atos); __ jmp(L);
  1798   bep = cep = sep =             // fall through
  1799   iep = __ pc(); __ push(itos); // fall through
  1800   vep = __ pc(); __ bind(L);    // fall through
  1801   generate_and_dispatch(t);
  1804 //------------------------------------------------------------------------------------------------------------------------
  1805 // Generation of individual instructions
  1807 // helpers for generate_and_dispatch
  1811 InterpreterGenerator::InterpreterGenerator(StubQueue* code)
  1812  : TemplateInterpreterGenerator(code) {
  1813    generate_all(); // down here so it can be "virtual"
  1816 //------------------------------------------------------------------------------------------------------------------------
  1818 // Non-product code
  1819 #ifndef PRODUCT
  1820 address TemplateInterpreterGenerator::generate_trace_code(TosState state) {
  1821   address entry = __ pc();
  1823   // prepare expression stack
  1824   __ pop(rcx);          // pop return address so expression stack is 'pure'
  1825   __ push(state);       // save tosca
  1827   // pass tosca registers as arguments & call tracer
  1828   __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), rcx, rax, rdx);
  1829   __ mov(rcx, rax);     // make sure return address is not destroyed by pop(state)
  1830   __ pop(state);        // restore tosca
  1832   // return
  1833   __ jmp(rcx);
  1835   return entry;
  1839 void TemplateInterpreterGenerator::count_bytecode() {
  1840   __ incrementl(ExternalAddress((address) &BytecodeCounter::_counter_value));
  1844 void TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
  1845   __ incrementl(ExternalAddress((address) &BytecodeHistogram::_counters[t->bytecode()]));
  1849 void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
  1850   __ mov32(ExternalAddress((address) &BytecodePairHistogram::_index), rbx);
  1851   __ shrl(rbx, BytecodePairHistogram::log2_number_of_codes);
  1852   __ orl(rbx, ((int)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes);
  1853   ExternalAddress table((address) BytecodePairHistogram::_counters);
  1854   Address index(noreg, rbx, Address::times_4);
  1855   __ incrementl(ArrayAddress(table, index));
  1859 void TemplateInterpreterGenerator::trace_bytecode(Template* t) {
  1860   // Call a little run-time stub to avoid blow-up for each bytecode.
  1861   // The run-time runtime saves the right registers, depending on
  1862   // the tosca in-state for the given template.
  1863   assert(Interpreter::trace_code(t->tos_in()) != NULL,
  1864          "entry must have been generated");
  1865   __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in())));
  1869 void TemplateInterpreterGenerator::stop_interpreter_at() {
  1870   Label L;
  1871   __ cmp32(ExternalAddress((address) &BytecodeCounter::_counter_value),
  1872            StopInterpreterAt);
  1873   __ jcc(Assembler::notEqual, L);
  1874   __ int3();
  1875   __ bind(L);
  1877 #endif // !PRODUCT
  1878 #endif // CC_INTERP

mercurial