0N/A/*
3790N/A * Copyright (c) 2003, 2012, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
1879N/A#include "precompiled.hpp"
1879N/A#include "asm/assembler.hpp"
1879N/A#include "interpreter/bytecodeHistogram.hpp"
1879N/A#include "interpreter/interpreter.hpp"
1879N/A#include "interpreter/interpreterGenerator.hpp"
1879N/A#include "interpreter/interpreterRuntime.hpp"
1879N/A#include "interpreter/templateTable.hpp"
1879N/A#include "oops/arrayOop.hpp"
1879N/A#include "oops/methodDataOop.hpp"
1879N/A#include "oops/methodOop.hpp"
1879N/A#include "oops/oop.inline.hpp"
1879N/A#include "prims/jvmtiExport.hpp"
1879N/A#include "prims/jvmtiThreadState.hpp"
1879N/A#include "runtime/arguments.hpp"
1879N/A#include "runtime/deoptimization.hpp"
1879N/A#include "runtime/frame.inline.hpp"
1879N/A#include "runtime/sharedRuntime.hpp"
1879N/A#include "runtime/stubRoutines.hpp"
1879N/A#include "runtime/synchronizer.hpp"
1879N/A#include "runtime/timer.hpp"
1879N/A#include "runtime/vframeArray.hpp"
1879N/A#include "utilities/debug.hpp"
0N/A
0N/A#define __ _masm->
0N/A
304N/A#ifndef CC_INTERP
304N/A
0N/Aconst int method_offset = frame::interpreter_frame_method_offset * wordSize;
0N/Aconst int bci_offset = frame::interpreter_frame_bcx_offset * wordSize;
0N/Aconst int locals_offset = frame::interpreter_frame_locals_offset * wordSize;
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A
0N/Aaddress TemplateInterpreterGenerator::generate_StackOverflowError_handler() {
0N/A address entry = __ pc();
0N/A
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
304N/A __ lea(rax, Address(rbp,
304N/A frame::interpreter_frame_monitor_block_top_offset *
304N/A wordSize));
304N/A __ cmpptr(rax, rsp); // rax = maximal rsp for current rbp (stack
304N/A // grows negative)
0N/A __ jcc(Assembler::aboveEqual, L); // check if frame is complete
0N/A __ stop ("interpreter frame not set up");
0N/A __ bind(L);
0N/A }
0N/A#endif // ASSERT
0N/A // Restore bcp under the assumption that the current frame is still
0N/A // interpreted
0N/A __ restore_bcp();
0N/A
0N/A // expression stack must be empty before entering the VM if an
0N/A // exception happened
0N/A __ empty_expression_stack();
0N/A // throw exception
0N/A __ call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::throw_StackOverflowError));
0N/A return entry;
0N/A}
0N/A
0N/Aaddress TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(
0N/A const char* name) {
0N/A address entry = __ pc();
0N/A // expression stack must be empty before entering the VM if an
0N/A // exception happened
0N/A __ empty_expression_stack();
0N/A // setup parameters
0N/A // ??? convention: expect aberrant index in register ebx
0N/A __ lea(c_rarg1, ExternalAddress((address)name));
0N/A __ call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::
0N/A throw_ArrayIndexOutOfBoundsException),
0N/A c_rarg1, rbx);
0N/A return entry;
0N/A}
0N/A
0N/Aaddress TemplateInterpreterGenerator::generate_ClassCastException_handler() {
0N/A address entry = __ pc();
0N/A
0N/A // object is at TOS
304N/A __ pop(c_rarg1);
0N/A
0N/A // expression stack must be empty before entering the VM if an
0N/A // exception happened
0N/A __ empty_expression_stack();
0N/A
0N/A __ call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::
0N/A throw_ClassCastException),
0N/A c_rarg1);
0N/A return entry;
0N/A}
0N/A
0N/Aaddress TemplateInterpreterGenerator::generate_exception_handler_common(
0N/A const char* name, const char* message, bool pass_oop) {
0N/A assert(!pass_oop || message == NULL, "either oop or message but not both");
0N/A address entry = __ pc();
0N/A if (pass_oop) {
0N/A // object is at TOS
304N/A __ pop(c_rarg2);
0N/A }
0N/A // expression stack must be empty before entering the VM if an
0N/A // exception happened
0N/A __ empty_expression_stack();
0N/A // setup parameters
0N/A __ lea(c_rarg1, ExternalAddress((address)name));
0N/A if (pass_oop) {
0N/A __ call_VM(rax, CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::
0N/A create_klass_exception),
0N/A c_rarg1, c_rarg2);
0N/A } else {
0N/A // kind of lame ExternalAddress can't take NULL because
0N/A // external_word_Relocation will assert.
0N/A if (message != NULL) {
0N/A __ lea(c_rarg2, ExternalAddress((address)message));
0N/A } else {
0N/A __ movptr(c_rarg2, NULL_WORD);
0N/A }
0N/A __ call_VM(rax,
0N/A CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception),
0N/A c_rarg1, c_rarg2);
0N/A }
0N/A // throw exception
0N/A __ jump(ExternalAddress(Interpreter::throw_exception_entry()));
0N/A return entry;
0N/A}
0N/A
0N/A
0N/Aaddress TemplateInterpreterGenerator::generate_continuation_for(TosState state) {
0N/A address entry = __ pc();
0N/A // NULL last_sp until next java call
304N/A __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
0N/A __ dispatch_next(state);
0N/A return entry;
0N/A}
0N/A
0N/A
2117N/Aaddress TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step) {
0N/A address entry = __ pc();
0N/A
0N/A // Restore stack bottom in case i2c adjusted stack
304N/A __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
0N/A // and NULL it as marker that esp is now tos until next java call
304N/A __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
0N/A
0N/A __ restore_bcp();
0N/A __ restore_locals();
304N/A
1108N/A Label L_got_cache, L_giant_index;
1108N/A if (EnableInvokeDynamic) {
1108N/A __ cmpb(Address(r13, 0), Bytecodes::_invokedynamic);
1108N/A __ jcc(Assembler::equal, L_giant_index);
1108N/A }
1485N/A __ get_cache_and_index_at_bcp(rbx, rcx, 1, sizeof(u2));
1108N/A __ bind(L_got_cache);
0N/A __ movl(rbx, Address(rbx, rcx,
1108N/A Address::times_ptr,
0N/A in_bytes(constantPoolCacheOopDesc::base_offset()) +
0N/A 3 * wordSize));
0N/A __ andl(rbx, 0xFF);
304N/A __ lea(rsp, Address(rsp, rbx, Address::times_8));
0N/A __ dispatch_next(state, step);
1108N/A
1108N/A // out of the main line of code...
1108N/A if (EnableInvokeDynamic) {
1108N/A __ bind(L_giant_index);
1485N/A __ get_cache_and_index_at_bcp(rbx, rcx, 1, sizeof(u4));
1108N/A __ jmp(L_got_cache);
1108N/A }
1108N/A
0N/A return entry;
0N/A}
0N/A
0N/A
0N/Aaddress TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state,
0N/A int step) {
0N/A address entry = __ pc();
0N/A // NULL last_sp until next java call
304N/A __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
0N/A __ restore_bcp();
0N/A __ restore_locals();
0N/A // handle exceptions
0N/A {
0N/A Label L;
304N/A __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD);
0N/A __ jcc(Assembler::zero, L);
0N/A __ call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::throw_pending_exception));
0N/A __ should_not_reach_here();
0N/A __ bind(L);
0N/A }
0N/A __ dispatch_next(state, step);
0N/A return entry;
0N/A}
0N/A
0N/Aint AbstractInterpreter::BasicType_as_index(BasicType type) {
0N/A int i = 0;
0N/A switch (type) {
0N/A case T_BOOLEAN: i = 0; break;
0N/A case T_CHAR : i = 1; break;
0N/A case T_BYTE : i = 2; break;
0N/A case T_SHORT : i = 3; break;
0N/A case T_INT : i = 4; break;
0N/A case T_LONG : i = 5; break;
0N/A case T_VOID : i = 6; break;
0N/A case T_FLOAT : i = 7; break;
0N/A case T_DOUBLE : i = 8; break;
0N/A case T_OBJECT : i = 9; break;
0N/A case T_ARRAY : i = 9; break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers,
0N/A "index out of bounds");
0N/A return i;
0N/A}
0N/A
0N/A
0N/Aaddress TemplateInterpreterGenerator::generate_result_handler_for(
0N/A BasicType type) {
0N/A address entry = __ pc();
0N/A switch (type) {
0N/A case T_BOOLEAN: __ c2bool(rax); break;
0N/A case T_CHAR : __ movzwl(rax, rax); break;
0N/A case T_BYTE : __ sign_extend_byte(rax); break;
0N/A case T_SHORT : __ sign_extend_short(rax); break;
0N/A case T_INT : /* nothing to do */ break;
0N/A case T_LONG : /* nothing to do */ break;
0N/A case T_VOID : /* nothing to do */ break;
0N/A case T_FLOAT : /* nothing to do */ break;
0N/A case T_DOUBLE : /* nothing to do */ break;
0N/A case T_OBJECT :
0N/A // retrieve result from frame
304N/A __ movptr(rax, Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize));
0N/A // and verify it
0N/A __ verify_oop(rax);
0N/A break;
0N/A default : ShouldNotReachHere();
0N/A }
0N/A __ ret(0); // return from result handler
0N/A return entry;
0N/A}
0N/A
0N/Aaddress TemplateInterpreterGenerator::generate_safept_entry_for(
0N/A TosState state,
0N/A address runtime_entry) {
0N/A address entry = __ pc();
0N/A __ push(state);
0N/A __ call_VM(noreg, runtime_entry);
0N/A __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos));
0N/A return entry;
0N/A}
0N/A
0N/A
0N/A
0N/A// Helpers for commoning out cases in the various type of method entries.
0N/A//
0N/A
0N/A
0N/A// increment invocation count & check for overflow
0N/A//
0N/A// Note: checking for negative value instead of overflow
0N/A// so we have a 'sticky' overflow test
0N/A//
0N/A// rbx: method
0N/A// ecx: invocation counter
0N/A//
0N/Avoid InterpreterGenerator::generate_counter_incr(
0N/A Label* overflow,
0N/A Label* profile_method,
0N/A Label* profile_method_continue) {
1703N/A const Address invocation_counter(rbx, in_bytes(methodOopDesc::invocation_counter_offset()) +
1703N/A in_bytes(InvocationCounter::counter_offset()));
1703N/A // Note: In tiered we increment either counters in methodOop or in MDO depending if we're profiling or not.
1703N/A if (TieredCompilation) {
1703N/A int increment = InvocationCounter::count_increment;
1703N/A int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift;
1703N/A Label no_mdo, done;
1703N/A if (ProfileInterpreter) {
1703N/A // Are we profiling?
1703N/A __ movptr(rax, Address(rbx, methodOopDesc::method_data_offset()));
1703N/A __ testptr(rax, rax);
1703N/A __ jccb(Assembler::zero, no_mdo);
1703N/A // Increment counter in the MDO
1703N/A const Address mdo_invocation_counter(rax, in_bytes(methodDataOopDesc::invocation_counter_offset()) +
1703N/A in_bytes(InvocationCounter::counter_offset()));
1703N/A __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rcx, false, Assembler::zero, overflow);
1703N/A __ jmpb(done);
1703N/A }
1703N/A __ bind(no_mdo);
1703N/A // Increment counter in methodOop (we don't need to load it, it's in ecx).
1703N/A __ increment_mask_and_jump(invocation_counter, increment, mask, rcx, true, Assembler::zero, overflow);
1703N/A __ bind(done);
1703N/A } else {
1703N/A const Address backedge_counter(rbx,
1703N/A methodOopDesc::backedge_counter_offset() +
0N/A InvocationCounter::counter_offset());
0N/A
1703N/A if (ProfileInterpreter) { // %%% Merge this into methodDataOop
1703N/A __ incrementl(Address(rbx,
1703N/A methodOopDesc::interpreter_invocation_counter_offset()));
1703N/A }
1703N/A // Update standard invocation counters
1703N/A __ movl(rax, backedge_counter); // load backedge counter
0N/A
1703N/A __ incrementl(rcx, InvocationCounter::count_increment);
1703N/A __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits
0N/A
1703N/A __ movl(invocation_counter, rcx); // save invocation count
1703N/A __ addl(rcx, rax); // add both counters
0N/A
1703N/A // profile_method is non-null only for interpreted method so
1703N/A // profile_method != NULL == !native_call
1703N/A
1703N/A if (ProfileInterpreter && profile_method != NULL) {
1703N/A // Test to see if we should create a method data oop
1703N/A __ cmp32(rcx, ExternalAddress((address)&InvocationCounter::InterpreterProfileLimit));
1703N/A __ jcc(Assembler::less, *profile_method_continue);
0N/A
1703N/A // if no method data exists, go to profile_method
1703N/A __ test_method_data_pointer(rax, *profile_method);
1703N/A }
1703N/A
1703N/A __ cmp32(rcx, ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit));
1703N/A __ jcc(Assembler::aboveEqual, *overflow);
0N/A }
0N/A}
0N/A
0N/Avoid InterpreterGenerator::generate_counter_overflow(Label* do_continue) {
0N/A
0N/A // Asm interpreter on entry
0N/A // r14 - locals
0N/A // r13 - bcp
0N/A // rbx - method
0N/A // edx - cpool --- DOES NOT APPEAR TO BE TRUE
0N/A // rbp - interpreter frame
0N/A
0N/A // On return (i.e. jump to entry_point) [ back to invocation of interpreter ]
0N/A // Everything as it was on entry
0N/A // rdx is not restored. Doesn't appear to really be set.
0N/A
0N/A const Address size_of_parameters(rbx,
0N/A methodOopDesc::size_of_parameters_offset());
0N/A
0N/A // InterpreterRuntime::frequency_counter_overflow takes two
0N/A // arguments, the first (thread) is passed by call_VM, the second
0N/A // indicates if the counter overflow occurs at a backwards branch
0N/A // (NULL bcp). We pass zero for it. The call returns the address
0N/A // of the verified entry point for the method or NULL if the
0N/A // compilation did not complete (either went background or bailed
0N/A // out).
0N/A __ movl(c_rarg1, 0);
0N/A __ call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::frequency_counter_overflow),
0N/A c_rarg1);
0N/A
304N/A __ movptr(rbx, Address(rbp, method_offset)); // restore methodOop
0N/A // Preserve invariant that r13/r14 contain bcp/locals of sender frame
0N/A // and jump to the interpreted entry.
0N/A __ jmp(*do_continue, relocInfo::none);
0N/A}
0N/A
0N/A// See if we've got enough room on the stack for locals plus overhead.
0N/A// The expression stack grows down incrementally, so the normal guard
0N/A// page mechanism will work for that.
0N/A//
0N/A// NOTE: Since the additional locals are also always pushed (wasn't
0N/A// obvious in generate_method_entry) so the guard should work for them
0N/A// too.
0N/A//
0N/A// Args:
0N/A// rdx: number of additional locals this frame needs (what we must check)
0N/A// rbx: methodOop
0N/A//
0N/A// Kills:
0N/A// rax
0N/Avoid InterpreterGenerator::generate_stack_overflow_check(void) {
0N/A
0N/A // monitor entry size: see picture of stack set
0N/A // (generate_method_entry) and frame_amd64.hpp
0N/A const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
0N/A
0N/A // total overhead size: entry_size + (saved rbp through expr stack
0N/A // bottom). be sure to change this if you add/subtract anything
0N/A // to/from the overhead area
0N/A const int overhead_size =
0N/A -(frame::interpreter_frame_initial_sp_offset * wordSize) + entry_size;
0N/A
0N/A const int page_size = os::vm_page_size();
0N/A
0N/A Label after_frame_check;
0N/A
0N/A // see if the frame is greater than one page in size. If so,
0N/A // then we need to verify there is enough stack space remaining
0N/A // for the additional locals.
1426N/A __ cmpl(rdx, (page_size - overhead_size) / Interpreter::stackElementSize);
0N/A __ jcc(Assembler::belowEqual, after_frame_check);
0N/A
0N/A // compute rsp as if this were going to be the last frame on
0N/A // the stack before the red zone
0N/A
0N/A const Address stack_base(r15_thread, Thread::stack_base_offset());
0N/A const Address stack_size(r15_thread, Thread::stack_size_offset());
0N/A
0N/A // locals + overhead, in bytes
304N/A __ mov(rax, rdx);
1426N/A __ shlptr(rax, Interpreter::logStackElementSize); // 2 slots per parameter.
304N/A __ addptr(rax, overhead_size);
0N/A
0N/A#ifdef ASSERT
0N/A Label stack_base_okay, stack_size_okay;
0N/A // verify that thread stack base is non-zero
304N/A __ cmpptr(stack_base, (int32_t)NULL_WORD);
0N/A __ jcc(Assembler::notEqual, stack_base_okay);
0N/A __ stop("stack base is zero");
0N/A __ bind(stack_base_okay);
0N/A // verify that thread stack size is non-zero
304N/A __ cmpptr(stack_size, 0);
0N/A __ jcc(Assembler::notEqual, stack_size_okay);
0N/A __ stop("stack size is zero");
0N/A __ bind(stack_size_okay);
0N/A#endif
0N/A
0N/A // Add stack base to locals and subtract stack size
304N/A __ addptr(rax, stack_base);
304N/A __ subptr(rax, stack_size);
0N/A
1135N/A // Use the maximum number of pages we might bang.
1135N/A const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages :
1135N/A (StackRedPages+StackYellowPages);
1135N/A
0N/A // add in the red and yellow zone sizes
1135N/A __ addptr(rax, max_pages * page_size);
0N/A
0N/A // check against the current stack bottom
304N/A __ cmpptr(rsp, rax);
0N/A __ jcc(Assembler::above, after_frame_check);
0N/A
3023N/A // Restore sender's sp as SP. This is necessary if the sender's
3023N/A // frame is an extended compiled frame (see gen_c2i_adapter())
3023N/A // and safer anyway in case of JSR292 adaptations.
3023N/A
3023N/A __ pop(rax); // return address must be moved if SP is changed
3023N/A __ mov(rsp, r13);
3023N/A __ push(rax);
3023N/A
3023N/A // Note: the restored frame is not necessarily interpreted.
3023N/A // Use the shared runtime version of the StackOverflowError.
3023N/A assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated");
3023N/A __ jump(ExternalAddress(StubRoutines::throw_StackOverflowError_entry()));
0N/A
0N/A // all done with frame size check
0N/A __ bind(after_frame_check);
0N/A}
0N/A
0N/A// Allocate monitor and lock method (asm interpreter)
0N/A//
0N/A// Args:
0N/A// rbx: methodOop
0N/A// r14: locals
0N/A//
0N/A// Kills:
0N/A// rax
0N/A// c_rarg0, c_rarg1, c_rarg2, c_rarg3, ...(param regs)
0N/A// rscratch1, rscratch2 (scratch regs)
0N/Avoid InterpreterGenerator::lock_method(void) {
0N/A // synchronize method
0N/A const Address access_flags(rbx, methodOopDesc::access_flags_offset());
0N/A const Address monitor_block_top(
0N/A rbp,
0N/A frame::interpreter_frame_monitor_block_top_offset * wordSize);
0N/A const int entry_size = frame::interpreter_frame_monitor_size() * wordSize;
0N/A
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
0N/A __ movl(rax, access_flags);
0N/A __ testl(rax, JVM_ACC_SYNCHRONIZED);
0N/A __ jcc(Assembler::notZero, L);
0N/A __ stop("method doesn't need synchronization");
0N/A __ bind(L);
0N/A }
0N/A#endif // ASSERT
0N/A
0N/A // get synchronization object
0N/A {
3042N/A const int mirror_offset = in_bytes(Klass::java_mirror_offset());
0N/A Label done;
0N/A __ movl(rax, access_flags);
0N/A __ testl(rax, JVM_ACC_STATIC);
0N/A // get receiver (assume this is frequent case)
304N/A __ movptr(rax, Address(r14, Interpreter::local_offset_in_bytes(0)));
0N/A __ jcc(Assembler::zero, done);
3790N/A __ movptr(rax, Address(rbx, methodOopDesc::const_offset()));
3790N/A __ movptr(rax, Address(rax, constMethodOopDesc::constants_offset()));
304N/A __ movptr(rax, Address(rax,
304N/A constantPoolOopDesc::pool_holder_offset_in_bytes()));
304N/A __ movptr(rax, Address(rax, mirror_offset));
0N/A
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
304N/A __ testptr(rax, rax);
0N/A __ jcc(Assembler::notZero, L);
0N/A __ stop("synchronization object is NULL");
0N/A __ bind(L);
0N/A }
0N/A#endif // ASSERT
0N/A
0N/A __ bind(done);
0N/A }
0N/A
0N/A // add space for monitor & lock
304N/A __ subptr(rsp, entry_size); // add space for a monitor entry
304N/A __ movptr(monitor_block_top, rsp); // set new monitor block top
0N/A // store object
304N/A __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax);
304N/A __ movptr(c_rarg1, rsp); // object address
0N/A __ lock_object(c_rarg1);
0N/A}
0N/A
0N/A// Generate a fixed interpreter frame. This is identical setup for
0N/A// interpreted methods and for native methods hence the shared code.
0N/A//
0N/A// Args:
0N/A// rax: return address
0N/A// rbx: methodOop
0N/A// r14: pointer to locals
0N/A// r13: sender sp
0N/A// rdx: cp cache
0N/Avoid TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) {
0N/A // initialize fixed part of activation frame
304N/A __ push(rax); // save return address
0N/A __ enter(); // save old & set new rbp
304N/A __ push(r13); // set sender sp
304N/A __ push((int)NULL_WORD); // leave last_sp as null
304N/A __ movptr(r13, Address(rbx, methodOopDesc::const_offset())); // get constMethodOop
304N/A __ lea(r13, Address(r13, constMethodOopDesc::codes_offset())); // get codebase
304N/A __ push(rbx); // save methodOop
0N/A if (ProfileInterpreter) {
0N/A Label method_data_continue;
304N/A __ movptr(rdx, Address(rbx, in_bytes(methodOopDesc::method_data_offset())));
304N/A __ testptr(rdx, rdx);
0N/A __ jcc(Assembler::zero, method_data_continue);
304N/A __ addptr(rdx, in_bytes(methodDataOopDesc::data_offset()));
0N/A __ bind(method_data_continue);
304N/A __ push(rdx); // set the mdp (method data pointer)
0N/A } else {
304N/A __ push(0);
0N/A }
0N/A
3790N/A __ movptr(rdx, Address(rbx, methodOopDesc::const_offset()));
3790N/A __ movptr(rdx, Address(rdx, constMethodOopDesc::constants_offset()));
304N/A __ movptr(rdx, Address(rdx, constantPoolOopDesc::cache_offset_in_bytes()));
304N/A __ push(rdx); // set constant pool cache
304N/A __ push(r14); // set locals pointer
0N/A if (native_call) {
304N/A __ push(0); // no bcp
0N/A } else {
304N/A __ push(r13); // set bcp
0N/A }
304N/A __ push(0); // reserve word for pointer to expression stack bottom
304N/A __ movptr(Address(rsp, 0), rsp); // set expression stack bottom
0N/A}
0N/A
0N/A// End of helpers
0N/A
304N/A// Various method entries
304N/A//------------------------------------------------------------------------------------------------------------------------
304N/A//
304N/A//
304N/A
304N/A// Call an accessor method (assuming it is resolved, otherwise drop
304N/A// into vanilla (slow path) entry
304N/Aaddress InterpreterGenerator::generate_accessor_entry(void) {
304N/A // rbx: methodOop
304N/A
304N/A // r13: senderSP must preserver for slow path, set SP to it on fast path
304N/A
304N/A address entry_point = __ pc();
304N/A Label xreturn_path;
304N/A
304N/A // do fastpath for resolved accessor methods
304N/A if (UseFastAccessorMethods) {
304N/A // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites
304N/A // thereof; parameter size = 1
304N/A // Note: We can only use this code if the getfield has been resolved
304N/A // and if we don't have a null-pointer exception => check for
304N/A // these conditions first and use slow path if necessary.
304N/A Label slow_path;
304N/A // If we need a safepoint check, generate full interpreter entry.
304N/A __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
304N/A SafepointSynchronize::_not_synchronized);
304N/A
304N/A __ jcc(Assembler::notEqual, slow_path);
304N/A // rbx: method
304N/A __ movptr(rax, Address(rsp, wordSize));
304N/A
304N/A // check if local 0 != NULL and read field
304N/A __ testptr(rax, rax);
304N/A __ jcc(Assembler::zero, slow_path);
304N/A
304N/A // read first instruction word and extract bytecode @ 1 and index @ 2
304N/A __ movptr(rdx, Address(rbx, methodOopDesc::const_offset()));
3790N/A __ movptr(rdi, Address(rdx, constMethodOopDesc::constants_offset()));
304N/A __ movl(rdx, Address(rdx, constMethodOopDesc::codes_offset()));
304N/A // Shift codes right to get the index on the right.
304N/A // The bytecode fetched looks like <index><0xb4><0x2a>
304N/A __ shrl(rdx, 2 * BitsPerByte);
304N/A __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size())));
304N/A __ movptr(rdi, Address(rdi, constantPoolOopDesc::cache_offset_in_bytes()));
304N/A
304N/A // rax: local 0
304N/A // rbx: method
304N/A // rdx: constant pool cache index
304N/A // rdi: constant pool cache
304N/A
304N/A // check if getfield has been resolved and read constant pool cache entry
304N/A // check the validity of the cache entry by testing whether _indices field
304N/A // contains Bytecode::_getfield in b1 byte.
304N/A assert(in_words(ConstantPoolCacheEntry::size()) == 4,
304N/A "adjust shift below");
304N/A __ movl(rcx,
304N/A Address(rdi,
304N/A rdx,
304N/A Address::times_8,
304N/A constantPoolCacheOopDesc::base_offset() +
304N/A ConstantPoolCacheEntry::indices_offset()));
304N/A __ shrl(rcx, 2 * BitsPerByte);
304N/A __ andl(rcx, 0xFF);
304N/A __ cmpl(rcx, Bytecodes::_getfield);
304N/A __ jcc(Assembler::notEqual, slow_path);
304N/A
304N/A // Note: constant pool entry is not valid before bytecode is resolved
304N/A __ movptr(rcx,
304N/A Address(rdi,
304N/A rdx,
304N/A Address::times_8,
304N/A constantPoolCacheOopDesc::base_offset() +
304N/A ConstantPoolCacheEntry::f2_offset()));
304N/A // edx: flags
304N/A __ movl(rdx,
304N/A Address(rdi,
304N/A rdx,
304N/A Address::times_8,
304N/A constantPoolCacheOopDesc::base_offset() +
304N/A ConstantPoolCacheEntry::flags_offset()));
304N/A
304N/A Label notObj, notInt, notByte, notShort;
304N/A const Address field_address(rax, rcx, Address::times_1);
304N/A
304N/A // Need to differentiate between igetfield, agetfield, bgetfield etc.
304N/A // because they are different sizes.
304N/A // Use the type from the constant pool cache
3932N/A __ shrl(rdx, ConstantPoolCacheEntry::tos_state_shift);
3932N/A // Make sure we don't need to mask edx after the above shift
3932N/A ConstantPoolCacheEntry::verify_tos_state_shift();
304N/A
304N/A __ cmpl(rdx, atos);
304N/A __ jcc(Assembler::notEqual, notObj);
304N/A // atos
304N/A __ load_heap_oop(rax, field_address);
304N/A __ jmp(xreturn_path);
304N/A
304N/A __ bind(notObj);
304N/A __ cmpl(rdx, itos);
304N/A __ jcc(Assembler::notEqual, notInt);
304N/A // itos
304N/A __ movl(rax, field_address);
304N/A __ jmp(xreturn_path);
304N/A
304N/A __ bind(notInt);
304N/A __ cmpl(rdx, btos);
304N/A __ jcc(Assembler::notEqual, notByte);
304N/A // btos
304N/A __ load_signed_byte(rax, field_address);
304N/A __ jmp(xreturn_path);
304N/A
304N/A __ bind(notByte);
304N/A __ cmpl(rdx, stos);
304N/A __ jcc(Assembler::notEqual, notShort);
304N/A // stos
622N/A __ load_signed_short(rax, field_address);
304N/A __ jmp(xreturn_path);
304N/A
304N/A __ bind(notShort);
304N/A#ifdef ASSERT
304N/A Label okay;
304N/A __ cmpl(rdx, ctos);
304N/A __ jcc(Assembler::equal, okay);
304N/A __ stop("what type is this?");
304N/A __ bind(okay);
304N/A#endif
304N/A // ctos
622N/A __ load_unsigned_short(rax, field_address);
304N/A
304N/A __ bind(xreturn_path);
304N/A
304N/A // _ireturn/_areturn
304N/A __ pop(rdi);
304N/A __ mov(rsp, r13);
304N/A __ jmp(rdi);
304N/A __ ret(0);
304N/A
304N/A // generate a vanilla interpreter entry as the slow path
304N/A __ bind(slow_path);
304N/A (void) generate_normal_entry(false);
304N/A } else {
304N/A (void) generate_normal_entry(false);
304N/A }
304N/A
304N/A return entry_point;
304N/A}
304N/A
2346N/A// Method entry for java.lang.ref.Reference.get.
2346N/Aaddress InterpreterGenerator::generate_Reference_get_entry(void) {
2346N/A#ifndef SERIALGC
2346N/A // Code: _aload_0, _getfield, _areturn
2346N/A // parameter size = 1
2346N/A //
2346N/A // The code that gets generated by this routine is split into 2 parts:
2346N/A // 1. The "intrinsified" code for G1 (or any SATB based GC),
2346N/A // 2. The slow path - which is an expansion of the regular method entry.
2346N/A //
2346N/A // Notes:-
2346N/A // * In the G1 code we do not check whether we need to block for
2346N/A // a safepoint. If G1 is enabled then we must execute the specialized
2346N/A // code for Reference.get (except when the Reference object is null)
2346N/A // so that we can log the value in the referent field with an SATB
2346N/A // update buffer.
2346N/A // If the code for the getfield template is modified so that the
2346N/A // G1 pre-barrier code is executed when the current method is
2346N/A // Reference.get() then going through the normal method entry
2346N/A // will be fine.
2346N/A // * The G1 code can, however, check the receiver object (the instance
2346N/A // of java.lang.Reference) and jump to the slow path if null. If the
2346N/A // Reference object is null then we obviously cannot fetch the referent
2346N/A // and so we don't need to call the G1 pre-barrier. Thus we can use the
2346N/A // regular method entry code to generate the NPE.
2346N/A //
2346N/A // This code is based on generate_accessor_enty.
2346N/A //
2346N/A // rbx: methodOop
2346N/A
2346N/A // r13: senderSP must preserve for slow path, set SP to it on fast path
2346N/A
2346N/A address entry = __ pc();
2346N/A
2346N/A const int referent_offset = java_lang_ref_Reference::referent_offset;
2346N/A guarantee(referent_offset > 0, "referent offset not initialized");
2346N/A
2346N/A if (UseG1GC) {
2346N/A Label slow_path;
2346N/A // rbx: method
2346N/A
2346N/A // Check if local 0 != NULL
2346N/A // If the receiver is null then it is OK to jump to the slow path.
2346N/A __ movptr(rax, Address(rsp, wordSize));
2346N/A
2346N/A __ testptr(rax, rax);
2346N/A __ jcc(Assembler::zero, slow_path);
2346N/A
2346N/A // rax: local 0
2346N/A // rbx: method (but can be used as scratch now)
2346N/A // rdx: scratch
2346N/A // rdi: scratch
2346N/A
2346N/A // Generate the G1 pre-barrier code to log the value of
2346N/A // the referent field in an SATB buffer.
2346N/A
2346N/A // Load the value of the referent field.
2346N/A const Address field_address(rax, referent_offset);
2346N/A __ load_heap_oop(rax, field_address);
2346N/A
2346N/A // Generate the G1 pre-barrier code to log the value of
2346N/A // the referent field in an SATB buffer.
2346N/A __ g1_write_barrier_pre(noreg /* obj */,
2346N/A rax /* pre_val */,
2346N/A r15_thread /* thread */,
2346N/A rbx /* tmp */,
2346N/A true /* tosca_live */,
2346N/A true /* expand_call */);
2346N/A
2346N/A // _areturn
2346N/A __ pop(rdi); // get return address
2346N/A __ mov(rsp, r13); // set sp to sender sp
2346N/A __ jmp(rdi);
2346N/A __ ret(0);
2346N/A
2346N/A // generate a vanilla interpreter entry as the slow path
2346N/A __ bind(slow_path);
2346N/A (void) generate_normal_entry(false);
2346N/A
2346N/A return entry;
2346N/A }
2346N/A#endif // SERIALGC
2346N/A
2346N/A // If G1 is not enabled then attempt to go through the accessor entry point
2346N/A // Reference.get is an accessor
2346N/A return generate_accessor_entry();
2346N/A}
2346N/A
2346N/A
0N/A// Interpreter stub for calling a native method. (asm interpreter)
0N/A// This sets up a somewhat different looking stack for calling the
0N/A// native method than the typical interpreter frame setup.
0N/Aaddress InterpreterGenerator::generate_native_entry(bool synchronized) {
0N/A // determine code generation flags
0N/A bool inc_counter = UseCompiler || CountCompiledCalls;
0N/A
0N/A // rbx: methodOop
0N/A // r13: sender sp
0N/A
0N/A address entry_point = __ pc();
0N/A
0N/A const Address size_of_parameters(rbx, methodOopDesc::
0N/A size_of_parameters_offset());
0N/A const Address invocation_counter(rbx, methodOopDesc::
0N/A invocation_counter_offset() +
0N/A InvocationCounter::counter_offset());
0N/A const Address access_flags (rbx, methodOopDesc::access_flags_offset());
0N/A
0N/A // get parameter size (always needed)
622N/A __ load_unsigned_short(rcx, size_of_parameters);
0N/A
0N/A // native calls don't need the stack size check since they have no
0N/A // expression stack and the arguments are already on the stack and
0N/A // we only add a handful of words to the stack
0N/A
0N/A // rbx: methodOop
0N/A // rcx: size of parameters
0N/A // r13: sender sp
304N/A __ pop(rax); // get return address
0N/A
0N/A // for natives the size of locals is zero
0N/A
0N/A // compute beginning of parameters (r14)
304N/A __ lea(r14, Address(rsp, rcx, Address::times_8, -wordSize));
0N/A
0N/A // add 2 zero-initialized slots for native calls
0N/A // initialize result_handler slot
304N/A __ push((int) NULL_WORD);
0N/A // slot for oop temp
0N/A // (static native method holder mirror/jni oop result)
304N/A __ push((int) NULL_WORD);
0N/A
0N/A if (inc_counter) {
0N/A __ movl(rcx, invocation_counter); // (pre-)fetch invocation count
0N/A }
0N/A
0N/A // initialize fixed part of activation frame
0N/A generate_fixed_frame(true);
0N/A
0N/A // make sure method is native & not abstract
0N/A#ifdef ASSERT
0N/A __ movl(rax, access_flags);
0N/A {
0N/A Label L;
0N/A __ testl(rax, JVM_ACC_NATIVE);
0N/A __ jcc(Assembler::notZero, L);
0N/A __ stop("tried to execute non-native method as native");
0N/A __ bind(L);
0N/A }
0N/A {
0N/A Label L;
0N/A __ testl(rax, JVM_ACC_ABSTRACT);
0N/A __ jcc(Assembler::zero, L);
0N/A __ stop("tried to execute abstract method in interpreter");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A
0N/A // Since at this point in the method invocation the exception handler
0N/A // would try to exit the monitor of synchronized methods which hasn't
0N/A // been entered yet, we set the thread local variable
0N/A // _do_not_unlock_if_synchronized to true. The remove_activation will
0N/A // check this flag.
0N/A
0N/A const Address do_not_unlock_if_synchronized(r15_thread,
0N/A in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
0N/A __ movbool(do_not_unlock_if_synchronized, true);
0N/A
0N/A // increment invocation count & check for overflow
0N/A Label invocation_counter_overflow;
0N/A if (inc_counter) {
0N/A generate_counter_incr(&invocation_counter_overflow, NULL, NULL);
0N/A }
0N/A
0N/A Label continue_after_compile;
0N/A __ bind(continue_after_compile);
0N/A
0N/A bang_stack_shadow_pages(true);
0N/A
0N/A // reset the _do_not_unlock_if_synchronized flag
0N/A __ movbool(do_not_unlock_if_synchronized, false);
0N/A
0N/A // check for synchronized methods
0N/A // Must happen AFTER invocation_counter check and stack overflow check,
0N/A // so method is not locked if overflows.
0N/A if (synchronized) {
0N/A lock_method();
0N/A } else {
0N/A // no synchronization necessary
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
0N/A __ movl(rax, access_flags);
0N/A __ testl(rax, JVM_ACC_SYNCHRONIZED);
0N/A __ jcc(Assembler::zero, L);
0N/A __ stop("method needs synchronization");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A }
0N/A
0N/A // start execution
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
0N/A const Address monitor_block_top(rbp,
0N/A frame::interpreter_frame_monitor_block_top_offset * wordSize);
304N/A __ movptr(rax, monitor_block_top);
304N/A __ cmpptr(rax, rsp);
0N/A __ jcc(Assembler::equal, L);
0N/A __ stop("broken stack frame setup in interpreter");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A
0N/A // jvmti support
0N/A __ notify_method_entry();
0N/A
0N/A // work registers
0N/A const Register method = rbx;
113N/A const Register t = r11;
0N/A
0N/A // allocate space for parameters
0N/A __ get_method(method);
0N/A __ verify_oop(method);
622N/A __ load_unsigned_short(t,
622N/A Address(method,
622N/A methodOopDesc::size_of_parameters_offset()));
1426N/A __ shll(t, Interpreter::logStackElementSize);
0N/A
304N/A __ subptr(rsp, t);
304N/A __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
605N/A __ andptr(rsp, -16); // must be 16 byte boundary (see amd64 ABI)
0N/A
0N/A // get signature handler
0N/A {
0N/A Label L;
304N/A __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
304N/A __ testptr(t, t);
0N/A __ jcc(Assembler::notZero, L);
0N/A __ call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::prepare_native_call),
0N/A method);
0N/A __ get_method(method);
304N/A __ movptr(t, Address(method, methodOopDesc::signature_handler_offset()));
0N/A __ bind(L);
0N/A }
0N/A
0N/A // call signature handler
0N/A assert(InterpreterRuntime::SignatureHandlerGenerator::from() == r14,
0N/A "adjust this code");
0N/A assert(InterpreterRuntime::SignatureHandlerGenerator::to() == rsp,
0N/A "adjust this code");
0N/A assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == rscratch1,
0N/A "adjust this code");
0N/A
0N/A // The generated handlers do not touch RBX (the method oop).
0N/A // However, large signatures cannot be cached and are generated
0N/A // each time here. The slow-path generator can do a GC on return,
0N/A // so we must reload it after the call.
0N/A __ call(t);
0N/A __ get_method(method); // slow path can do a GC, reload RBX
0N/A
0N/A
0N/A // result handler is in rax
0N/A // set result handler
304N/A __ movptr(Address(rbp,
304N/A (frame::interpreter_frame_result_handler_offset) * wordSize),
304N/A rax);
0N/A
0N/A // pass mirror handle if static call
0N/A {
0N/A Label L;
3042N/A const int mirror_offset = in_bytes(Klass::java_mirror_offset());
0N/A __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
0N/A __ testl(t, JVM_ACC_STATIC);
0N/A __ jcc(Assembler::zero, L);
0N/A // get mirror
3790N/A __ movptr(t, Address(method, methodOopDesc::const_offset()));
3790N/A __ movptr(t, Address(t, constMethodOopDesc::constants_offset()));
304N/A __ movptr(t, Address(t, constantPoolOopDesc::pool_holder_offset_in_bytes()));
304N/A __ movptr(t, Address(t, mirror_offset));
0N/A // copy mirror into activation frame
304N/A __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize),
0N/A t);
0N/A // pass handle to mirror
304N/A __ lea(c_rarg1,
304N/A Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize));
0N/A __ bind(L);
0N/A }
0N/A
0N/A // get native function entry point
0N/A {
0N/A Label L;
304N/A __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
0N/A ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry());
0N/A __ movptr(rscratch2, unsatisfied.addr());
304N/A __ cmpptr(rax, rscratch2);
0N/A __ jcc(Assembler::notEqual, L);
0N/A __ call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::prepare_native_call),
0N/A method);
0N/A __ get_method(method);
0N/A __ verify_oop(method);
304N/A __ movptr(rax, Address(method, methodOopDesc::native_function_offset()));
0N/A __ bind(L);
0N/A }
0N/A
0N/A // pass JNIEnv
304N/A __ lea(c_rarg0, Address(r15_thread, JavaThread::jni_environment_offset()));
0N/A
0N/A // It is enough that the pc() points into the right code
0N/A // segment. It does not have to be the correct return pc.
0N/A __ set_last_Java_frame(rsp, rbp, (address) __ pc());
0N/A
0N/A // change thread state
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
0N/A __ movl(t, Address(r15_thread, JavaThread::thread_state_offset()));
0N/A __ cmpl(t, _thread_in_Java);
0N/A __ jcc(Assembler::equal, L);
0N/A __ stop("Wrong thread state in native stub");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A
0N/A // Change state to native
0N/A
0N/A __ movl(Address(r15_thread, JavaThread::thread_state_offset()),
0N/A _thread_in_native);
0N/A
0N/A // Call the native method.
0N/A __ call(rax);
0N/A // result potentially in rax or xmm0
0N/A
4442N/A // Verify or restore cpu control state after JNI call
4442N/A __ restore_cpu_control_state_after_jni();
0N/A
0N/A // NOTE: The order of these pushes is known to frame::interpreter_frame_result
0N/A // in order to extract the result of a method call. If the order of these
0N/A // pushes change or anything else is added to the stack then the code in
0N/A // interpreter_frame_result must also change.
0N/A
0N/A __ push(dtos);
0N/A __ push(ltos);
0N/A
0N/A // change thread state
0N/A __ movl(Address(r15_thread, JavaThread::thread_state_offset()),
0N/A _thread_in_native_trans);
0N/A
0N/A if (os::is_MP()) {
0N/A if (UseMembar) {
0N/A // Force this write out before the read below
0N/A __ membar(Assembler::Membar_mask_bits(
0N/A Assembler::LoadLoad | Assembler::LoadStore |
0N/A Assembler::StoreLoad | Assembler::StoreStore));
0N/A } else {
0N/A // Write serialization page so VM thread can do a pseudo remote membar.
0N/A // We use the current thread pointer to calculate a thread specific
0N/A // offset to write to within the page. This minimizes bus traffic
0N/A // due to cache line collision.
0N/A __ serialize_memory(r15_thread, rscratch2);
0N/A }
0N/A }
0N/A
0N/A // check for safepoint operation in progress and/or pending suspend requests
0N/A {
0N/A Label Continue;
0N/A __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()),
0N/A SafepointSynchronize::_not_synchronized);
0N/A
0N/A Label L;
0N/A __ jcc(Assembler::notEqual, L);
0N/A __ cmpl(Address(r15_thread, JavaThread::suspend_flags_offset()), 0);
0N/A __ jcc(Assembler::equal, Continue);
0N/A __ bind(L);
0N/A
0N/A // Don't use call_VM as it will see a possible pending exception
0N/A // and forward it and never return here preventing us from
0N/A // clearing _last_native_pc down below. Also can't use
0N/A // call_VM_leaf either as it will check to see if r13 & r14 are
0N/A // preserved and correspond to the bcp/locals pointers. So we do a
0N/A // runtime call by hand.
0N/A //
304N/A __ mov(c_rarg0, r15_thread);
1883N/A __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM)
304N/A __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
304N/A __ andptr(rsp, -16); // align stack as required by ABI
0N/A __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, JavaThread::check_special_condition_for_native_trans)));
304N/A __ mov(rsp, r12); // restore sp
113N/A __ reinit_heapbase();
0N/A __ bind(Continue);
0N/A }
0N/A
0N/A // change thread state
0N/A __ movl(Address(r15_thread, JavaThread::thread_state_offset()), _thread_in_Java);
0N/A
0N/A // reset_last_Java_frame
0N/A __ reset_last_Java_frame(true, true);
0N/A
0N/A // reset handle block
304N/A __ movptr(t, Address(r15_thread, JavaThread::active_handles_offset()));
304N/A __ movptr(Address(t, JNIHandleBlock::top_offset_in_bytes()), (int32_t)NULL_WORD);
0N/A
0N/A // If result is an oop unbox and store it in frame where gc will see it
0N/A // and result handler will pick it up
0N/A
0N/A {
0N/A Label no_oop, store_result;
0N/A __ lea(t, ExternalAddress(AbstractInterpreter::result_handler(T_OBJECT)));
304N/A __ cmpptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize));
0N/A __ jcc(Assembler::notEqual, no_oop);
0N/A // retrieve result
0N/A __ pop(ltos);
304N/A __ testptr(rax, rax);
0N/A __ jcc(Assembler::zero, store_result);
304N/A __ movptr(rax, Address(rax, 0));
0N/A __ bind(store_result);
304N/A __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize), rax);
0N/A // keep stack depth as expected by pushing oop which will eventually be discarde
0N/A __ push(ltos);
0N/A __ bind(no_oop);
0N/A }
0N/A
0N/A
0N/A {
0N/A Label no_reguard;
0N/A __ cmpl(Address(r15_thread, JavaThread::stack_guard_state_offset()),
0N/A JavaThread::stack_guard_yellow_disabled);
0N/A __ jcc(Assembler::notEqual, no_reguard);
0N/A
304N/A __ pusha(); // XXX only save smashed registers
1883N/A __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM)
304N/A __ subptr(rsp, frame::arg_reg_save_area_bytes); // windows
304N/A __ andptr(rsp, -16); // align stack as required by ABI
0N/A __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages)));
304N/A __ mov(rsp, r12); // restore sp
304N/A __ popa(); // XXX only restore smashed registers
113N/A __ reinit_heapbase();
0N/A
0N/A __ bind(no_reguard);
0N/A }
0N/A
0N/A
0N/A // The method register is junk from after the thread_in_native transition
0N/A // until here. Also can't call_VM until the bcp has been
0N/A // restored. Need bcp for throwing exception below so get it now.
0N/A __ get_method(method);
0N/A __ verify_oop(method);
0N/A
0N/A // restore r13 to have legal interpreter frame, i.e., bci == 0 <=>
0N/A // r13 == code_base()
304N/A __ movptr(r13, Address(method, methodOopDesc::const_offset())); // get constMethodOop
304N/A __ lea(r13, Address(r13, constMethodOopDesc::codes_offset())); // get codebase
0N/A // handle exceptions (exception handling will handle unlocking!)
0N/A {
0N/A Label L;
304N/A __ cmpptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t) NULL_WORD);
0N/A __ jcc(Assembler::zero, L);
0N/A // Note: At some point we may want to unify this with the code
0N/A // used in call_VM_base(); i.e., we should use the
0N/A // StubRoutines::forward_exception code. For now this doesn't work
0N/A // here because the rsp is not correctly set at this point.
0N/A __ MacroAssembler::call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::throw_pending_exception));
0N/A __ should_not_reach_here();
0N/A __ bind(L);
0N/A }
0N/A
0N/A // do unlocking if necessary
0N/A {
0N/A Label L;
0N/A __ movl(t, Address(method, methodOopDesc::access_flags_offset()));
0N/A __ testl(t, JVM_ACC_SYNCHRONIZED);
0N/A __ jcc(Assembler::zero, L);
0N/A // the code below should be shared with interpreter macro
0N/A // assembler implementation
0N/A {
0N/A Label unlock;
0N/A // BasicObjectLock will be first in list, since this is a
0N/A // synchronized method. However, need to check that the object
0N/A // has not been unlocked by an explicit monitorexit bytecode.
0N/A const Address monitor(rbp,
0N/A (intptr_t)(frame::interpreter_frame_initial_sp_offset *
0N/A wordSize - sizeof(BasicObjectLock)));
0N/A
0N/A // monitor expect in c_rarg1 for slow unlock path
304N/A __ lea(c_rarg1, monitor); // address of first monitor
0N/A
304N/A __ movptr(t, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()));
304N/A __ testptr(t, t);
0N/A __ jcc(Assembler::notZero, unlock);
0N/A
0N/A // Entry already unlocked, need to throw exception
0N/A __ MacroAssembler::call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::throw_illegal_monitor_state_exception));
0N/A __ should_not_reach_here();
0N/A
0N/A __ bind(unlock);
0N/A __ unlock_object(c_rarg1);
0N/A }
0N/A __ bind(L);
0N/A }
0N/A
0N/A // jvmti support
0N/A // Note: This must happen _after_ handling/throwing any exceptions since
0N/A // the exception handler code notifies the runtime of method exits
0N/A // too. If this happens before, method entry/exit notifications are
0N/A // not properly paired (was bug - gri 11/22/99).
0N/A __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI);
0N/A
0N/A // restore potential result in edx:eax, call result handler to
0N/A // restore potential result in ST0 & handle result
0N/A
0N/A __ pop(ltos);
0N/A __ pop(dtos);
0N/A
304N/A __ movptr(t, Address(rbp,
304N/A (frame::interpreter_frame_result_handler_offset) * wordSize));
0N/A __ call(t);
0N/A
0N/A // remove activation
304N/A __ movptr(t, Address(rbp,
304N/A frame::interpreter_frame_sender_sp_offset *
304N/A wordSize)); // get sender sp
0N/A __ leave(); // remove frame anchor
304N/A __ pop(rdi); // get return address
304N/A __ mov(rsp, t); // set sp to sender sp
0N/A __ jmp(rdi);
0N/A
0N/A if (inc_counter) {
0N/A // Handle overflow of counter and compile method
0N/A __ bind(invocation_counter_overflow);
0N/A generate_counter_overflow(&continue_after_compile);
0N/A }
0N/A
0N/A return entry_point;
0N/A}
0N/A
0N/A//
0N/A// Generic interpreted method entry to (asm) interpreter
0N/A//
0N/Aaddress InterpreterGenerator::generate_normal_entry(bool synchronized) {
0N/A // determine code generation flags
0N/A bool inc_counter = UseCompiler || CountCompiledCalls;
0N/A
0N/A // ebx: methodOop
0N/A // r13: sender sp
0N/A address entry_point = __ pc();
0N/A
0N/A const Address size_of_parameters(rbx,
0N/A methodOopDesc::size_of_parameters_offset());
0N/A const Address size_of_locals(rbx, methodOopDesc::size_of_locals_offset());
0N/A const Address invocation_counter(rbx,
0N/A methodOopDesc::invocation_counter_offset() +
0N/A InvocationCounter::counter_offset());
0N/A const Address access_flags(rbx, methodOopDesc::access_flags_offset());
0N/A
0N/A // get parameter size (always needed)
622N/A __ load_unsigned_short(rcx, size_of_parameters);
0N/A
0N/A // rbx: methodOop
0N/A // rcx: size of parameters
0N/A // r13: sender_sp (could differ from sp+wordSize if we were called via c2i )
0N/A
622N/A __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words
0N/A __ subl(rdx, rcx); // rdx = no. of additional locals
0N/A
0N/A // YYY
0N/A// __ incrementl(rdx);
0N/A// __ andl(rdx, -2);
0N/A
0N/A // see if we've got enough room on the stack for locals plus overhead.
0N/A generate_stack_overflow_check();
0N/A
0N/A // get return address
304N/A __ pop(rax);
0N/A
0N/A // compute beginning of parameters (r14)
304N/A __ lea(r14, Address(rsp, rcx, Address::times_8, -wordSize));
0N/A
0N/A // rdx - # of additional locals
0N/A // allocate space for locals
0N/A // explicitly initialize locals
0N/A {
0N/A Label exit, loop;
0N/A __ testl(rdx, rdx);
0N/A __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0
0N/A __ bind(loop);
304N/A __ push((int) NULL_WORD); // initialize local variables
0N/A __ decrementl(rdx); // until everything initialized
0N/A __ jcc(Assembler::greater, loop);
0N/A __ bind(exit);
0N/A }
0N/A
0N/A // (pre-)fetch invocation count
0N/A if (inc_counter) {
0N/A __ movl(rcx, invocation_counter);
0N/A }
0N/A // initialize fixed part of activation frame
0N/A generate_fixed_frame(false);
0N/A
0N/A // make sure method is not native & not abstract
0N/A#ifdef ASSERT
0N/A __ movl(rax, access_flags);
0N/A {
0N/A Label L;
0N/A __ testl(rax, JVM_ACC_NATIVE);
0N/A __ jcc(Assembler::zero, L);
0N/A __ stop("tried to execute native method as non-native");
0N/A __ bind(L);
0N/A }
0N/A {
0N/A Label L;
0N/A __ testl(rax, JVM_ACC_ABSTRACT);
0N/A __ jcc(Assembler::zero, L);
0N/A __ stop("tried to execute abstract method in interpreter");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A
0N/A // Since at this point in the method invocation the exception
0N/A // handler would try to exit the monitor of synchronized methods
0N/A // which hasn't been entered yet, we set the thread local variable
0N/A // _do_not_unlock_if_synchronized to true. The remove_activation
0N/A // will check this flag.
0N/A
0N/A const Address do_not_unlock_if_synchronized(r15_thread,
0N/A in_bytes(JavaThread::do_not_unlock_if_synchronized_offset()));
0N/A __ movbool(do_not_unlock_if_synchronized, true);
0N/A
0N/A // increment invocation count & check for overflow
0N/A Label invocation_counter_overflow;
0N/A Label profile_method;
0N/A Label profile_method_continue;
0N/A if (inc_counter) {
0N/A generate_counter_incr(&invocation_counter_overflow,
0N/A &profile_method,
0N/A &profile_method_continue);
0N/A if (ProfileInterpreter) {
0N/A __ bind(profile_method_continue);
0N/A }
0N/A }
0N/A
0N/A Label continue_after_compile;
0N/A __ bind(continue_after_compile);
0N/A
0N/A // check for synchronized interpreted methods
0N/A bang_stack_shadow_pages(false);
0N/A
0N/A // reset the _do_not_unlock_if_synchronized flag
0N/A __ movbool(do_not_unlock_if_synchronized, false);
0N/A
0N/A // check for synchronized methods
0N/A // Must happen AFTER invocation_counter check and stack overflow check,
0N/A // so method is not locked if overflows.
0N/A if (synchronized) {
0N/A // Allocate monitor and lock method
0N/A lock_method();
0N/A } else {
0N/A // no synchronization necessary
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
0N/A __ movl(rax, access_flags);
0N/A __ testl(rax, JVM_ACC_SYNCHRONIZED);
0N/A __ jcc(Assembler::zero, L);
0N/A __ stop("method needs synchronization");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A }
0N/A
0N/A // start execution
0N/A#ifdef ASSERT
0N/A {
0N/A Label L;
0N/A const Address monitor_block_top (rbp,
0N/A frame::interpreter_frame_monitor_block_top_offset * wordSize);
304N/A __ movptr(rax, monitor_block_top);
304N/A __ cmpptr(rax, rsp);
0N/A __ jcc(Assembler::equal, L);
0N/A __ stop("broken stack frame setup in interpreter");
0N/A __ bind(L);
0N/A }
0N/A#endif
0N/A
0N/A // jvmti support
0N/A __ notify_method_entry();
0N/A
0N/A __ dispatch_next(vtos);
0N/A
0N/A // invocation counter overflow
0N/A if (inc_counter) {
0N/A if (ProfileInterpreter) {
0N/A // We have decided to profile this method in the interpreter
0N/A __ bind(profile_method);
2003N/A __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method));
2003N/A __ set_method_data_pointer_for_bcp();
2026N/A __ get_method(rbx);
0N/A __ jmp(profile_method_continue);
0N/A }
0N/A // Handle overflow of counter and compile method
0N/A __ bind(invocation_counter_overflow);
0N/A generate_counter_overflow(&continue_after_compile);
0N/A }
0N/A
0N/A return entry_point;
0N/A}
0N/A
0N/A// Entry points
0N/A//
0N/A// Here we generate the various kind of entries into the interpreter.
0N/A// The two main entry type are generic bytecode methods and native
0N/A// call method. These both come in synchronized and non-synchronized
0N/A// versions but the frame layout they create is very similar. The
0N/A// other method entry types are really just special purpose entries
0N/A// that are really entry and interpretation all in one. These are for
0N/A// trivial methods like accessor, empty, or special math methods.
0N/A//
0N/A// When control flow reaches any of the entry types for the interpreter
0N/A// the following holds ->
0N/A//
0N/A// Arguments:
0N/A//
0N/A// rbx: methodOop
0N/A//
0N/A// Stack layout immediately at entry
0N/A//
0N/A// [ return address ] <--- rsp
0N/A// [ parameter n ]
0N/A// ...
0N/A// [ parameter 1 ]
0N/A// [ expression stack ] (caller's java expression stack)
0N/A
0N/A// Assuming that we don't go to one of the trivial specialized entries
0N/A// the stack will look like below when we are ready to execute the
0N/A// first bytecode (or call the native routine). The register usage
0N/A// will be as the template based interpreter expects (see
0N/A// interpreter_amd64.hpp).
0N/A//
0N/A// local variables follow incoming parameters immediately; i.e.
0N/A// the return address is moved to the end of the locals).
0N/A//
0N/A// [ monitor entry ] <--- rsp
0N/A// ...
0N/A// [ monitor entry ]
0N/A// [ expr. stack bottom ]
0N/A// [ saved r13 ]
0N/A// [ current r14 ]
0N/A// [ methodOop ]
0N/A// [ saved ebp ] <--- rbp
0N/A// [ return address ]
0N/A// [ local variable m ]
0N/A// ...
0N/A// [ local variable 1 ]
0N/A// [ parameter n ]
0N/A// ...
0N/A// [ parameter 1 ] <--- r14
0N/A
0N/Aaddress AbstractInterpreterGenerator::generate_method_entry(
0N/A AbstractInterpreter::MethodKind kind) {
0N/A // determine code generation flags
0N/A bool synchronized = false;
0N/A address entry_point = NULL;
0N/A
0N/A switch (kind) {
0N/A case Interpreter::zerolocals : break;
0N/A case Interpreter::zerolocals_synchronized: synchronized = true; break;
3932N/A case Interpreter::native : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(false); break;
3932N/A case Interpreter::native_synchronized : entry_point = ((InterpreterGenerator*)this)->generate_native_entry(true); break;
3932N/A case Interpreter::empty : entry_point = ((InterpreterGenerator*)this)->generate_empty_entry(); break;
3932N/A case Interpreter::accessor : entry_point = ((InterpreterGenerator*)this)->generate_accessor_entry(); break;
3932N/A case Interpreter::abstract : entry_point = ((InterpreterGenerator*)this)->generate_abstract_entry(); break;
706N/A
706N/A case Interpreter::java_lang_math_sin : // fall thru
706N/A case Interpreter::java_lang_math_cos : // fall thru
706N/A case Interpreter::java_lang_math_tan : // fall thru
706N/A case Interpreter::java_lang_math_abs : // fall thru
706N/A case Interpreter::java_lang_math_log : // fall thru
706N/A case Interpreter::java_lang_math_log10 : // fall thru
3752N/A case Interpreter::java_lang_math_sqrt : // fall thru
3752N/A case Interpreter::java_lang_math_pow : // fall thru
3932N/A case Interpreter::java_lang_math_exp : entry_point = ((InterpreterGenerator*)this)->generate_math_entry(kind); break;
2346N/A case Interpreter::java_lang_ref_reference_get
2346N/A : entry_point = ((InterpreterGenerator*)this)->generate_Reference_get_entry(); break;
3932N/A default:
3932N/A fatal(err_msg("unexpected method kind: %d", kind));
3932N/A break;
0N/A }
0N/A
0N/A if (entry_point) {
0N/A return entry_point;
0N/A }
0N/A
0N/A return ((InterpreterGenerator*) this)->
0N/A generate_normal_entry(synchronized);
0N/A}
0N/A
1174N/A// These should never be compiled since the interpreter will prefer
1174N/A// the compiled version to the intrinsic version.
1174N/Abool AbstractInterpreter::can_be_compiled(methodHandle m) {
1174N/A switch (method_kind(m)) {
1174N/A case Interpreter::java_lang_math_sin : // fall thru
1174N/A case Interpreter::java_lang_math_cos : // fall thru
1174N/A case Interpreter::java_lang_math_tan : // fall thru
1174N/A case Interpreter::java_lang_math_abs : // fall thru
1174N/A case Interpreter::java_lang_math_log : // fall thru
1174N/A case Interpreter::java_lang_math_log10 : // fall thru
3752N/A case Interpreter::java_lang_math_sqrt : // fall thru
3752N/A case Interpreter::java_lang_math_pow : // fall thru
3752N/A case Interpreter::java_lang_math_exp :
1174N/A return false;
1174N/A default:
1174N/A return true;
1174N/A }
1174N/A}
1174N/A
0N/A// How much stack a method activation needs in words.
0N/Aint AbstractInterpreter::size_top_interpreter_activation(methodOop method) {
0N/A const int entry_size = frame::interpreter_frame_monitor_size();
0N/A
0N/A // total overhead size: entry_size + (saved rbp thru expr stack
0N/A // bottom). be sure to change this if you add/subtract anything
0N/A // to/from the overhead area
0N/A const int overhead_size =
0N/A -(frame::interpreter_frame_initial_sp_offset) + entry_size;
0N/A
0N/A const int stub_code = frame::entry_frame_after_call_words;
710N/A const int extra_stack = methodOopDesc::extra_stack_entries();
710N/A const int method_stack = (method->max_locals() + method->max_stack() + extra_stack) *
1426N/A Interpreter::stackElementWords;
0N/A return (overhead_size + method_stack + stub_code);
0N/A}
0N/A
0N/Aint AbstractInterpreter::layout_activation(methodOop method,
0N/A int tempcount,
0N/A int popframe_extra_args,
0N/A int moncount,
2466N/A int caller_actual_parameters,
0N/A int callee_param_count,
0N/A int callee_locals,
0N/A frame* caller,
0N/A frame* interpreter_frame,
4331N/A bool is_top_frame,
4331N/A bool is_bottom_frame) {
0N/A // Note: This calculation must exactly parallel the frame setup
0N/A // in AbstractInterpreterGenerator::generate_method_entry.
0N/A // If interpreter_frame!=NULL, set up the method, locals, and monitors.
0N/A // The frame interpreter_frame, if not NULL, is guaranteed to be the
0N/A // right size, as determined by a previous call to this method.
0N/A // It is also guaranteed to be walkable even though it is in a skeletal state
0N/A
0N/A // fixed size of an interpreter frame:
1426N/A int max_locals = method->max_locals() * Interpreter::stackElementWords;
0N/A int extra_locals = (method->max_locals() - method->size_of_parameters()) *
1426N/A Interpreter::stackElementWords;
0N/A
0N/A int overhead = frame::sender_sp_offset -
0N/A frame::interpreter_frame_initial_sp_offset;
0N/A // Our locals were accounted for by the caller (or last_frame_adjust
0N/A // on the transistion) Since the callee parameters already account
0N/A // for the callee's params we only need to account for the extra
0N/A // locals.
0N/A int size = overhead +
1426N/A (callee_locals - callee_param_count)*Interpreter::stackElementWords +
0N/A moncount * frame::interpreter_frame_monitor_size() +
1426N/A tempcount* Interpreter::stackElementWords + popframe_extra_args;
0N/A if (interpreter_frame != NULL) {
0N/A#ifdef ASSERT
2263N/A if (!EnableInvokeDynamic)
1135N/A // @@@ FIXME: Should we correct interpreter_frame_sender_sp in the calling sequences?
1135N/A // Probably, since deoptimization doesn't work yet.
1135N/A assert(caller->unextended_sp() == interpreter_frame->interpreter_frame_sender_sp(), "Frame not properly walkable");
0N/A assert(caller->sp() == interpreter_frame->sender_sp(), "Frame not properly walkable(2)");
0N/A#endif
0N/A
0N/A interpreter_frame->interpreter_frame_set_method(method);
0N/A // NOTE the difference in using sender_sp and
0N/A // interpreter_frame_sender_sp interpreter_frame_sender_sp is
0N/A // the original sp of the caller (the unextended_sp) and
0N/A // sender_sp is fp+16 XXX
0N/A intptr_t* locals = interpreter_frame->sender_sp() + max_locals - 1;
0N/A
2880N/A#ifdef ASSERT
2880N/A if (caller->is_interpreted_frame()) {
2880N/A assert(locals < caller->fp() + frame::interpreter_frame_initial_sp_offset, "bad placement");
2880N/A }
2880N/A#endif
2880N/A
0N/A interpreter_frame->interpreter_frame_set_locals(locals);
0N/A BasicObjectLock* montop = interpreter_frame->interpreter_frame_monitor_begin();
0N/A BasicObjectLock* monbot = montop - moncount;
0N/A interpreter_frame->interpreter_frame_set_monitor_end(monbot);
0N/A
0N/A // Set last_sp
0N/A intptr_t* esp = (intptr_t*) monbot -
1426N/A tempcount*Interpreter::stackElementWords -
0N/A popframe_extra_args;
0N/A interpreter_frame->interpreter_frame_set_last_sp(esp);
0N/A
0N/A // All frames but the initial (oldest) interpreter frame we fill in have
0N/A // a value for sender_sp that allows walking the stack but isn't
0N/A // truly correct. Correct the value here.
0N/A if (extra_locals != 0 &&
0N/A interpreter_frame->sender_sp() ==
0N/A interpreter_frame->interpreter_frame_sender_sp()) {
0N/A interpreter_frame->set_interpreter_frame_sender_sp(caller->sp() +
0N/A extra_locals);
0N/A }
0N/A *interpreter_frame->interpreter_frame_cache_addr() =
0N/A method->constants()->cache();
0N/A }
0N/A return size;
0N/A}
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Exceptions
0N/A
0N/Avoid TemplateInterpreterGenerator::generate_throw_exception() {
0N/A // Entry point in previous activation (i.e., if the caller was
0N/A // interpreted)
0N/A Interpreter::_rethrow_exception_entry = __ pc();
0N/A // Restore sp to interpreter_frame_last_sp even though we are going
0N/A // to empty the expression stack for the exception processing.
304N/A __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
0N/A // rax: exception
0N/A // rdx: return address/pc that threw exception
0N/A __ restore_bcp(); // r13 points to call/send
0N/A __ restore_locals();
113N/A __ reinit_heapbase(); // restore r12 as heapbase.
0N/A // Entry point for exceptions thrown within interpreter code
0N/A Interpreter::_throw_exception_entry = __ pc();
0N/A // expression stack is undefined here
0N/A // rax: exception
0N/A // r13: exception bcp
0N/A __ verify_oop(rax);
304N/A __ mov(c_rarg1, rax);
0N/A
0N/A // expression stack must be empty before entering the VM in case of
0N/A // an exception
0N/A __ empty_expression_stack();
0N/A // find exception handler address and preserve exception oop
0N/A __ call_VM(rdx,
0N/A CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::exception_handler_for_exception),
0N/A c_rarg1);
0N/A // rax: exception handler entry point
0N/A // rdx: preserved exception oop
0N/A // r13: bcp for exception handler
0N/A __ push_ptr(rdx); // push exception which is now the only value on the stack
0N/A __ jmp(rax); // jump to exception handler (may be _remove_activation_entry!)
0N/A
0N/A // If the exception is not handled in the current frame the frame is
0N/A // removed and the exception is rethrown (i.e. exception
0N/A // continuation is _rethrow_exception).
0N/A //
0N/A // Note: At this point the bci is still the bxi for the instruction
0N/A // which caused the exception and the expression stack is
0N/A // empty. Thus, for any VM calls at this point, GC will find a legal
0N/A // oop map (with empty expression stack).
0N/A
0N/A // In current activation
0N/A // tos: exception
0N/A // esi: exception bcp
0N/A
0N/A //
0N/A // JVMTI PopFrame support
0N/A //
0N/A
0N/A Interpreter::_remove_activation_preserving_args_entry = __ pc();
0N/A __ empty_expression_stack();
0N/A // Set the popframe_processing bit in pending_popframe_condition
0N/A // indicating that we are currently handling popframe, so that
0N/A // call_VMs that may happen later do not trigger new popframe
0N/A // handling cycles.
0N/A __ movl(rdx, Address(r15_thread, JavaThread::popframe_condition_offset()));
0N/A __ orl(rdx, JavaThread::popframe_processing_bit);
0N/A __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()), rdx);
0N/A
0N/A {
0N/A // Check to see whether we are returning to a deoptimized frame.
0N/A // (The PopFrame call ensures that the caller of the popped frame is
0N/A // either interpreted or compiled and deoptimizes it if compiled.)
0N/A // In this case, we can't call dispatch_next() after the frame is
0N/A // popped, but instead must save the incoming arguments and restore
0N/A // them after deoptimization has occurred.
0N/A //
0N/A // Note that we don't compare the return PC against the
0N/A // deoptimization blob's unpack entry because of the presence of
0N/A // adapter frames in C2.
0N/A Label caller_not_deoptimized;
304N/A __ movptr(c_rarg1, Address(rbp, frame::return_addr_offset * wordSize));
0N/A __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
0N/A InterpreterRuntime::interpreter_contains), c_rarg1);
0N/A __ testl(rax, rax);
0N/A __ jcc(Assembler::notZero, caller_not_deoptimized);
0N/A
0N/A // Compute size of arguments for saving when returning to
0N/A // deoptimized caller
0N/A __ get_method(rax);
622N/A __ load_unsigned_short(rax, Address(rax, in_bytes(methodOopDesc::
0N/A size_of_parameters_offset())));
1426N/A __ shll(rax, Interpreter::logStackElementSize);
0N/A __ restore_locals(); // XXX do we need this?
304N/A __ subptr(r14, rax);
304N/A __ addptr(r14, wordSize);
0N/A // Save these arguments
0N/A __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
0N/A Deoptimization::
0N/A popframe_preserve_args),
0N/A r15_thread, rax, r14);
0N/A
0N/A __ remove_activation(vtos, rdx,
0N/A /* throw_monitor_exception */ false,
0N/A /* install_monitor_exception */ false,
0N/A /* notify_jvmdi */ false);
0N/A
0N/A // Inform deoptimization that it is responsible for restoring
0N/A // these arguments
0N/A __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()),
0N/A JavaThread::popframe_force_deopt_reexecution_bit);
0N/A
0N/A // Continue in deoptimization handler
0N/A __ jmp(rdx);
0N/A
0N/A __ bind(caller_not_deoptimized);
0N/A }
0N/A
0N/A __ remove_activation(vtos, rdx, /* rdx result (retaddr) is not used */
0N/A /* throw_monitor_exception */ false,
0N/A /* install_monitor_exception */ false,
0N/A /* notify_jvmdi */ false);
0N/A
0N/A // Finish with popframe handling
0N/A // A previous I2C followed by a deoptimization might have moved the
0N/A // outgoing arguments further up the stack. PopFrame expects the
0N/A // mutations to those outgoing arguments to be preserved and other
0N/A // constraints basically require this frame to look exactly as
0N/A // though it had previously invoked an interpreted activation with
0N/A // no space between the top of the expression stack (current
0N/A // last_sp) and the top of stack. Rather than force deopt to
0N/A // maintain this kind of invariant all the time we call a small
0N/A // fixup routine to move the mutated arguments onto the top of our
0N/A // expression stack if necessary.
304N/A __ mov(c_rarg1, rsp);
304N/A __ movptr(c_rarg2, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
0N/A // PC must point into interpreter here
0N/A __ set_last_Java_frame(noreg, rbp, __ pc());
0N/A __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), r15_thread, c_rarg1, c_rarg2);
0N/A __ reset_last_Java_frame(true, true);
0N/A // Restore the last_sp and null it out
304N/A __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize));
304N/A __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD);
0N/A
0N/A __ restore_bcp(); // XXX do we need this?
0N/A __ restore_locals(); // XXX do we need this?
0N/A // The method data pointer was incremented already during
0N/A // call profiling. We have to restore the mdp for the current bcp.
0N/A if (ProfileInterpreter) {
0N/A __ set_method_data_pointer_for_bcp();
0N/A }
0N/A
0N/A // Clear the popframe condition flag
0N/A __ movl(Address(r15_thread, JavaThread::popframe_condition_offset()),
0N/A JavaThread::popframe_inactive);
0N/A
0N/A __ dispatch_next(vtos);
0N/A // end of PopFrame support
0N/A
0N/A Interpreter::_remove_activation_entry = __ pc();
0N/A
0N/A // preserve exception over this code sequence
0N/A __ pop_ptr(rax);
304N/A __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), rax);
0N/A // remove the activation (without doing throws on illegalMonitorExceptions)
0N/A __ remove_activation(vtos, rdx, false, true, false);
0N/A // restore exception
304N/A __ movptr(rax, Address(r15_thread, JavaThread::vm_result_offset()));
304N/A __ movptr(Address(r15_thread, JavaThread::vm_result_offset()), (int32_t)NULL_WORD);
0N/A __ verify_oop(rax);
0N/A
0N/A // In between activations - previous activation type unknown yet
0N/A // compute continuation point - the continuation point expects the
0N/A // following registers set up:
0N/A //
0N/A // rax: exception
0N/A // rdx: return address/pc that threw exception
0N/A // rsp: expression stack of caller
0N/A // rbp: ebp of caller
304N/A __ push(rax); // save exception
304N/A __ push(rdx); // save return address
0N/A __ super_call_VM_leaf(CAST_FROM_FN_PTR(address,
0N/A SharedRuntime::exception_handler_for_return_address),
1295N/A r15_thread, rdx);
304N/A __ mov(rbx, rax); // save exception handler
304N/A __ pop(rdx); // restore return address
304N/A __ pop(rax); // restore exception
0N/A // Note that an "issuing PC" is actually the next PC after the call
0N/A __ jmp(rbx); // jump to exception
0N/A // handler of caller
0N/A}
0N/A
0N/A
0N/A//
0N/A// JVMTI ForceEarlyReturn support
0N/A//
0N/Aaddress TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) {
0N/A address entry = __ pc();
0N/A
0N/A __ restore_bcp();
0N/A __ restore_locals();
0N/A __ empty_expression_stack();
0N/A __ load_earlyret_value(state);
0N/A
304N/A __ movptr(rdx, Address(r15_thread, JavaThread::jvmti_thread_state_offset()));
0N/A Address cond_addr(rdx, JvmtiThreadState::earlyret_state_offset());
0N/A
0N/A // Clear the earlyret state
0N/A __ movl(cond_addr, JvmtiThreadState::earlyret_inactive);
0N/A
0N/A __ remove_activation(state, rsi,
0N/A false, /* throw_monitor_exception */
0N/A false, /* install_monitor_exception */
0N/A true); /* notify_jvmdi */
0N/A __ jmp(rsi);
0N/A
0N/A return entry;
0N/A} // end of ForceEarlyReturn support
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Helper for vtos entry point generation
0N/A
0N/Avoid TemplateInterpreterGenerator::set_vtos_entry_points(Template* t,
0N/A address& bep,
0N/A address& cep,
0N/A address& sep,
0N/A address& aep,
0N/A address& iep,
0N/A address& lep,
0N/A address& fep,
0N/A address& dep,
0N/A address& vep) {
0N/A assert(t->is_valid() && t->tos_in() == vtos, "illegal template");
0N/A Label L;
0N/A aep = __ pc(); __ push_ptr(); __ jmp(L);
0N/A fep = __ pc(); __ push_f(); __ jmp(L);
0N/A dep = __ pc(); __ push_d(); __ jmp(L);
0N/A lep = __ pc(); __ push_l(); __ jmp(L);
0N/A bep = cep = sep =
0N/A iep = __ pc(); __ push_i();
0N/A vep = __ pc();
0N/A __ bind(L);
0N/A generate_and_dispatch(t);
0N/A}
0N/A
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A// Generation of individual instructions
0N/A
0N/A// helpers for generate_and_dispatch
0N/A
0N/A
0N/AInterpreterGenerator::InterpreterGenerator(StubQueue* code)
0N/A : TemplateInterpreterGenerator(code) {
0N/A generate_all(); // down here so it can be "virtual"
0N/A}
0N/A
0N/A//-----------------------------------------------------------------------------
0N/A
0N/A// Non-product code
0N/A#ifndef PRODUCT
0N/Aaddress TemplateInterpreterGenerator::generate_trace_code(TosState state) {
0N/A address entry = __ pc();
0N/A
0N/A __ push(state);
304N/A __ push(c_rarg0);
304N/A __ push(c_rarg1);
304N/A __ push(c_rarg2);
304N/A __ push(c_rarg3);
304N/A __ mov(c_rarg2, rax); // Pass itos
0N/A#ifdef _WIN64
0N/A __ movflt(xmm3, xmm0); // Pass ftos
0N/A#endif
0N/A __ call_VM(noreg,
0N/A CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode),
0N/A c_rarg1, c_rarg2, c_rarg3);
304N/A __ pop(c_rarg3);
304N/A __ pop(c_rarg2);
304N/A __ pop(c_rarg1);
304N/A __ pop(c_rarg0);
0N/A __ pop(state);
0N/A __ ret(0); // return from result handler
0N/A
0N/A return entry;
0N/A}
0N/A
0N/Avoid TemplateInterpreterGenerator::count_bytecode() {
0N/A __ incrementl(ExternalAddress((address) &BytecodeCounter::_counter_value));
0N/A}
0N/A
0N/Avoid TemplateInterpreterGenerator::histogram_bytecode(Template* t) {
0N/A __ incrementl(ExternalAddress((address) &BytecodeHistogram::_counters[t->bytecode()]));
0N/A}
0N/A
0N/Avoid TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) {
0N/A __ mov32(rbx, ExternalAddress((address) &BytecodePairHistogram::_index));
0N/A __ shrl(rbx, BytecodePairHistogram::log2_number_of_codes);
0N/A __ orl(rbx,
0N/A ((int) t->bytecode()) <<
0N/A BytecodePairHistogram::log2_number_of_codes);
0N/A __ mov32(ExternalAddress((address) &BytecodePairHistogram::_index), rbx);
0N/A __ lea(rscratch1, ExternalAddress((address) BytecodePairHistogram::_counters));
0N/A __ incrementl(Address(rscratch1, rbx, Address::times_4));
0N/A}
0N/A
0N/A
0N/Avoid TemplateInterpreterGenerator::trace_bytecode(Template* t) {
0N/A // Call a little run-time stub to avoid blow-up for each bytecode.
0N/A // The run-time runtime saves the right registers, depending on
0N/A // the tosca in-state for the given template.
0N/A
0N/A assert(Interpreter::trace_code(t->tos_in()) != NULL,
0N/A "entry must have been generated");
1883N/A __ mov(r12, rsp); // remember sp (can only use r12 if not using call_VM)
304N/A __ andptr(rsp, -16); // align stack as required by ABI
0N/A __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in())));
304N/A __ mov(rsp, r12); // restore sp
113N/A __ reinit_heapbase();
0N/A}
0N/A
0N/A
0N/Avoid TemplateInterpreterGenerator::stop_interpreter_at() {
0N/A Label L;
0N/A __ cmp32(ExternalAddress((address) &BytecodeCounter::_counter_value),
0N/A StopInterpreterAt);
0N/A __ jcc(Assembler::notEqual, L);
0N/A __ int3();
0N/A __ bind(L);
0N/A}
0N/A#endif // !PRODUCT
304N/A#endif // ! CC_INTERP