aoqi@0: /* aoqi@0: * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: * aoqi@0: */ aoqi@0: aoqi@0: #include "precompiled.hpp" aoqi@0: #include "asm/macroAssembler.hpp" aoqi@0: #include "interpreter/bytecodeHistogram.hpp" aoqi@0: #include "interpreter/interpreter.hpp" aoqi@0: #include "interpreter/interpreterGenerator.hpp" aoqi@0: #include "interpreter/interpreterRuntime.hpp" aoqi@0: #include "interpreter/templateTable.hpp" aoqi@0: #include "oops/arrayOop.hpp" aoqi@0: #include "oops/methodData.hpp" aoqi@0: #include "oops/method.hpp" aoqi@0: #include "oops/oop.inline.hpp" aoqi@0: #include "prims/jvmtiExport.hpp" aoqi@0: #include "prims/jvmtiThreadState.hpp" aoqi@0: #include "runtime/arguments.hpp" aoqi@0: #include "runtime/deoptimization.hpp" aoqi@0: #include "runtime/frame.inline.hpp" aoqi@0: #include "runtime/sharedRuntime.hpp" aoqi@0: #include "runtime/stubRoutines.hpp" aoqi@0: #include "runtime/synchronizer.hpp" aoqi@0: #include "runtime/timer.hpp" aoqi@0: #include "runtime/vframeArray.hpp" aoqi@0: #include "utilities/debug.hpp" aoqi@0: #include "utilities/macros.hpp" aoqi@0: aoqi@0: #define __ _masm-> aoqi@0: aoqi@0: aoqi@0: #ifndef CC_INTERP aoqi@0: const int method_offset = frame::interpreter_frame_method_offset * wordSize; aoqi@0: const int bci_offset = frame::interpreter_frame_bcx_offset * wordSize; aoqi@0: const int locals_offset = frame::interpreter_frame_locals_offset * wordSize; aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_StackOverflowError_handler() { aoqi@0: address entry = __ pc(); aoqi@0: aoqi@0: // Note: There should be a minimal interpreter frame set up when stack aoqi@0: // overflow occurs since we check explicitly for it now. aoqi@0: // aoqi@0: #ifdef ASSERT aoqi@0: { Label L; aoqi@0: __ lea(rax, Address(rbp, aoqi@0: frame::interpreter_frame_monitor_block_top_offset * wordSize)); aoqi@0: __ cmpptr(rax, rsp); // rax, = maximal rsp for current rbp, aoqi@0: // (stack grows negative) aoqi@0: __ jcc(Assembler::aboveEqual, L); // check if frame is complete aoqi@0: __ stop ("interpreter frame not set up"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif // ASSERT aoqi@0: // Restore bcp under the assumption that the current frame is still aoqi@0: // interpreted aoqi@0: __ restore_bcp(); aoqi@0: aoqi@0: // expression stack must be empty before entering the VM if an exception aoqi@0: // happened aoqi@0: __ empty_expression_stack(); aoqi@0: __ empty_FPU_stack(); aoqi@0: // throw exception aoqi@0: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_StackOverflowError)); aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_ArrayIndexOutOfBounds_handler(const char* name) { aoqi@0: address entry = __ pc(); aoqi@0: // expression stack must be empty before entering the VM if an exception happened aoqi@0: __ empty_expression_stack(); aoqi@0: __ empty_FPU_stack(); aoqi@0: // setup parameters aoqi@0: // ??? convention: expect aberrant index in register rbx, aoqi@0: __ lea(rax, ExternalAddress((address)name)); aoqi@0: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_ArrayIndexOutOfBoundsException), rax, rbx); aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_ClassCastException_handler() { aoqi@0: address entry = __ pc(); aoqi@0: // object is at TOS aoqi@0: __ pop(rax); aoqi@0: // expression stack must be empty before entering the VM if an exception aoqi@0: // happened aoqi@0: __ empty_expression_stack(); aoqi@0: __ empty_FPU_stack(); aoqi@0: __ call_VM(noreg, aoqi@0: CAST_FROM_FN_PTR(address, aoqi@0: InterpreterRuntime::throw_ClassCastException), aoqi@0: rax); aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_exception_handler_common(const char* name, const char* message, bool pass_oop) { aoqi@0: assert(!pass_oop || message == NULL, "either oop or message but not both"); aoqi@0: address entry = __ pc(); aoqi@0: if (pass_oop) { aoqi@0: // object is at TOS aoqi@0: __ pop(rbx); aoqi@0: } aoqi@0: // expression stack must be empty before entering the VM if an exception happened aoqi@0: __ empty_expression_stack(); aoqi@0: __ empty_FPU_stack(); aoqi@0: // setup parameters aoqi@0: __ lea(rax, ExternalAddress((address)name)); aoqi@0: if (pass_oop) { aoqi@0: __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_klass_exception), rax, rbx); aoqi@0: } else { aoqi@0: if (message != NULL) { aoqi@0: __ lea(rbx, ExternalAddress((address)message)); aoqi@0: } else { aoqi@0: __ movptr(rbx, NULL_WORD); aoqi@0: } aoqi@0: __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::create_exception), rax, rbx); aoqi@0: } aoqi@0: // throw exception aoqi@0: __ jump(ExternalAddress(Interpreter::throw_exception_entry())); aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_continuation_for(TosState state) { aoqi@0: address entry = __ pc(); aoqi@0: // NULL last_sp until next java call aoqi@0: __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD); aoqi@0: __ dispatch_next(state); aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_return_entry_for(TosState state, int step, size_t index_size) { aoqi@0: address entry = __ pc(); aoqi@0: aoqi@0: #ifdef COMPILER2 aoqi@0: // The FPU stack is clean if UseSSE >= 2 but must be cleaned in other cases aoqi@0: if ((state == ftos && UseSSE < 1) || (state == dtos && UseSSE < 2)) { aoqi@0: for (int i = 1; i < 8; i++) { aoqi@0: __ ffree(i); aoqi@0: } aoqi@0: } else if (UseSSE < 2) { aoqi@0: __ empty_FPU_stack(); aoqi@0: } aoqi@0: #endif aoqi@0: if ((state == ftos && UseSSE < 1) || (state == dtos && UseSSE < 2)) { aoqi@0: __ MacroAssembler::verify_FPU(1, "generate_return_entry_for compiled"); aoqi@0: } else { aoqi@0: __ MacroAssembler::verify_FPU(0, "generate_return_entry_for compiled"); aoqi@0: } aoqi@0: aoqi@0: // In SSE mode, interpreter returns FP results in xmm0 but they need aoqi@0: // to end up back on the FPU so it can operate on them. aoqi@0: if (state == ftos && UseSSE >= 1) { aoqi@0: __ subptr(rsp, wordSize); aoqi@0: __ movflt(Address(rsp, 0), xmm0); aoqi@0: __ fld_s(Address(rsp, 0)); aoqi@0: __ addptr(rsp, wordSize); aoqi@0: } else if (state == dtos && UseSSE >= 2) { aoqi@0: __ subptr(rsp, 2*wordSize); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ addptr(rsp, 2*wordSize); aoqi@0: } aoqi@0: aoqi@0: __ MacroAssembler::verify_FPU(state == ftos || state == dtos ? 1 : 0, "generate_return_entry_for in interpreter"); aoqi@0: aoqi@0: // Restore stack bottom in case i2c adjusted stack aoqi@0: __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize)); aoqi@0: // and NULL it as marker that rsp is now tos until next java call aoqi@0: __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD); aoqi@0: aoqi@0: __ restore_bcp(); aoqi@0: __ restore_locals(); aoqi@0: aoqi@0: if (state == atos) { aoqi@0: Register mdp = rbx; aoqi@0: Register tmp = rcx; aoqi@0: __ profile_return_type(mdp, rax, tmp); aoqi@0: } aoqi@0: aoqi@0: const Register cache = rbx; aoqi@0: const Register index = rcx; aoqi@0: __ get_cache_and_index_at_bcp(cache, index, 1, index_size); aoqi@0: aoqi@0: const Register flags = cache; aoqi@0: __ movl(flags, Address(cache, index, Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset())); aoqi@0: __ andl(flags, ConstantPoolCacheEntry::parameter_size_mask); aoqi@0: __ lea(rsp, Address(rsp, flags, Interpreter::stackElementScale())); aoqi@0: __ dispatch_next(state, step); aoqi@0: aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_deopt_entry_for(TosState state, int step) { aoqi@0: address entry = __ pc(); aoqi@0: aoqi@0: // In SSE mode, FP results are in xmm0 aoqi@0: if (state == ftos && UseSSE > 0) { aoqi@0: __ subptr(rsp, wordSize); aoqi@0: __ movflt(Address(rsp, 0), xmm0); aoqi@0: __ fld_s(Address(rsp, 0)); aoqi@0: __ addptr(rsp, wordSize); aoqi@0: } else if (state == dtos && UseSSE >= 2) { aoqi@0: __ subptr(rsp, 2*wordSize); aoqi@0: __ movdbl(Address(rsp, 0), xmm0); aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: __ addptr(rsp, 2*wordSize); aoqi@0: } aoqi@0: aoqi@0: __ MacroAssembler::verify_FPU(state == ftos || state == dtos ? 1 : 0, "generate_deopt_entry_for in interpreter"); aoqi@0: aoqi@0: // The stack is not extended by deopt but we must NULL last_sp as this aoqi@0: // entry is like a "return". aoqi@0: __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD); aoqi@0: __ restore_bcp(); aoqi@0: __ restore_locals(); aoqi@0: // handle exceptions aoqi@0: { Label L; aoqi@0: const Register thread = rcx; aoqi@0: __ get_thread(thread); aoqi@0: __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception)); aoqi@0: __ should_not_reach_here(); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: __ dispatch_next(state, step); aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: int AbstractInterpreter::BasicType_as_index(BasicType type) { aoqi@0: int i = 0; aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: i = 0; break; aoqi@0: case T_CHAR : i = 1; break; aoqi@0: case T_BYTE : i = 2; break; aoqi@0: case T_SHORT : i = 3; break; aoqi@0: case T_INT : // fall through aoqi@0: case T_LONG : // fall through aoqi@0: case T_VOID : i = 4; break; aoqi@0: case T_FLOAT : i = 5; break; // have to treat float and double separately for SSE aoqi@0: case T_DOUBLE : i = 6; break; aoqi@0: case T_OBJECT : // fall through aoqi@0: case T_ARRAY : i = 7; break; aoqi@0: default : ShouldNotReachHere(); aoqi@0: } aoqi@0: assert(0 <= i && i < AbstractInterpreter::number_of_result_handlers, "index out of bounds"); aoqi@0: return i; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_result_handler_for(BasicType type) { aoqi@0: address entry = __ pc(); aoqi@0: switch (type) { aoqi@0: case T_BOOLEAN: __ c2bool(rax); break; aoqi@0: case T_CHAR : __ andptr(rax, 0xFFFF); break; aoqi@0: case T_BYTE : __ sign_extend_byte (rax); break; aoqi@0: case T_SHORT : __ sign_extend_short(rax); break; aoqi@0: case T_INT : /* nothing to do */ break; aoqi@0: case T_DOUBLE : aoqi@0: case T_FLOAT : aoqi@0: { const Register t = InterpreterRuntime::SignatureHandlerGenerator::temp(); aoqi@0: __ pop(t); // remove return address first aoqi@0: // Must return a result for interpreter or compiler. In SSE aoqi@0: // mode, results are returned in xmm0 and the FPU stack must aoqi@0: // be empty. aoqi@0: if (type == T_FLOAT && UseSSE >= 1) { aoqi@0: // Load ST0 aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: // Store as float and empty fpu stack aoqi@0: __ fstp_s(Address(rsp, 0)); aoqi@0: // and reload aoqi@0: __ movflt(xmm0, Address(rsp, 0)); aoqi@0: } else if (type == T_DOUBLE && UseSSE >= 2 ) { aoqi@0: __ movdbl(xmm0, Address(rsp, 0)); aoqi@0: } else { aoqi@0: // restore ST0 aoqi@0: __ fld_d(Address(rsp, 0)); aoqi@0: } aoqi@0: // and pop the temp aoqi@0: __ addptr(rsp, 2 * wordSize); aoqi@0: __ push(t); // restore return address aoqi@0: } aoqi@0: break; aoqi@0: case T_OBJECT : aoqi@0: // retrieve result from frame aoqi@0: __ movptr(rax, Address(rbp, frame::interpreter_frame_oop_temp_offset*wordSize)); aoqi@0: // and verify it aoqi@0: __ verify_oop(rax); aoqi@0: break; aoqi@0: default : ShouldNotReachHere(); aoqi@0: } aoqi@0: __ ret(0); // return from result handler aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: address TemplateInterpreterGenerator::generate_safept_entry_for(TosState state, address runtime_entry) { aoqi@0: address entry = __ pc(); aoqi@0: __ push(state); aoqi@0: __ call_VM(noreg, runtime_entry); aoqi@0: __ dispatch_via(vtos, Interpreter::_normal_table.table_for(vtos)); aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // Helpers for commoning out cases in the various type of method entries. aoqi@0: // aoqi@0: aoqi@0: // increment invocation count & check for overflow aoqi@0: // aoqi@0: // Note: checking for negative value instead of overflow aoqi@0: // so we have a 'sticky' overflow test aoqi@0: // aoqi@0: // rbx,: method aoqi@0: // rcx: invocation counter aoqi@0: // aoqi@0: void InterpreterGenerator::generate_counter_incr(Label* overflow, Label* profile_method, Label* profile_method_continue) { aoqi@0: Label done; aoqi@0: // Note: In tiered we increment either counters in MethodCounters* or in MDO aoqi@0: // depending if we're profiling or not. aoqi@0: if (TieredCompilation) { aoqi@0: int increment = InvocationCounter::count_increment; aoqi@0: int mask = ((1 << Tier0InvokeNotifyFreqLog) - 1) << InvocationCounter::count_shift; aoqi@0: Label no_mdo; aoqi@0: if (ProfileInterpreter) { aoqi@0: // Are we profiling? aoqi@0: __ movptr(rax, Address(rbx, Method::method_data_offset())); aoqi@0: __ testptr(rax, rax); aoqi@0: __ jccb(Assembler::zero, no_mdo); aoqi@0: // Increment counter in the MDO aoqi@0: const Address mdo_invocation_counter(rax, in_bytes(MethodData::invocation_counter_offset()) + aoqi@0: in_bytes(InvocationCounter::counter_offset())); aoqi@0: __ increment_mask_and_jump(mdo_invocation_counter, increment, mask, rcx, false, Assembler::zero, overflow); aoqi@0: __ jmp(done); aoqi@0: } aoqi@0: __ bind(no_mdo); aoqi@0: // Increment counter in MethodCounters aoqi@0: const Address invocation_counter(rax, aoqi@0: MethodCounters::invocation_counter_offset() + aoqi@0: InvocationCounter::counter_offset()); aoqi@0: aoqi@0: __ get_method_counters(rbx, rax, done); aoqi@0: __ increment_mask_and_jump(invocation_counter, increment, mask, aoqi@0: rcx, false, Assembler::zero, overflow); aoqi@0: __ bind(done); aoqi@0: } else { aoqi@0: const Address backedge_counter (rax, aoqi@0: MethodCounters::backedge_counter_offset() + aoqi@0: InvocationCounter::counter_offset()); aoqi@0: const Address invocation_counter(rax, aoqi@0: MethodCounters::invocation_counter_offset() + aoqi@0: InvocationCounter::counter_offset()); aoqi@0: aoqi@0: __ get_method_counters(rbx, rax, done); aoqi@0: aoqi@0: if (ProfileInterpreter) { aoqi@0: __ incrementl(Address(rax, aoqi@0: MethodCounters::interpreter_invocation_counter_offset())); aoqi@0: } aoqi@0: aoqi@0: // Update standard invocation counters aoqi@0: __ movl(rcx, invocation_counter); aoqi@0: __ incrementl(rcx, InvocationCounter::count_increment); aoqi@0: __ movl(invocation_counter, rcx); // save invocation count aoqi@0: aoqi@0: __ movl(rax, backedge_counter); // load backedge counter aoqi@0: __ andl(rax, InvocationCounter::count_mask_value); // mask out the status bits aoqi@0: aoqi@0: __ addl(rcx, rax); // add both counters aoqi@0: aoqi@0: // profile_method is non-null only for interpreted method so aoqi@0: // profile_method != NULL == !native_call aoqi@0: // BytecodeInterpreter only calls for native so code is elided. aoqi@0: aoqi@0: if (ProfileInterpreter && profile_method != NULL) { aoqi@0: // Test to see if we should create a method data oop aoqi@0: __ cmp32(rcx, aoqi@0: ExternalAddress((address)&InvocationCounter::InterpreterProfileLimit)); aoqi@0: __ jcc(Assembler::less, *profile_method_continue); aoqi@0: aoqi@0: // if no method data exists, go to profile_method aoqi@0: __ test_method_data_pointer(rax, *profile_method); aoqi@0: } aoqi@0: aoqi@0: __ cmp32(rcx, aoqi@0: ExternalAddress((address)&InvocationCounter::InterpreterInvocationLimit)); aoqi@0: __ jcc(Assembler::aboveEqual, *overflow); aoqi@0: __ bind(done); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void InterpreterGenerator::generate_counter_overflow(Label* do_continue) { aoqi@0: aoqi@0: // Asm interpreter on entry aoqi@0: // rdi - locals aoqi@0: // rsi - bcp aoqi@0: // rbx, - method aoqi@0: // rdx - cpool aoqi@0: // rbp, - interpreter frame aoqi@0: aoqi@0: // C++ interpreter on entry aoqi@0: // rsi - new interpreter state pointer aoqi@0: // rbp - interpreter frame pointer aoqi@0: // rbx - method aoqi@0: aoqi@0: // On return (i.e. jump to entry_point) [ back to invocation of interpreter ] aoqi@0: // rbx, - method aoqi@0: // rcx - rcvr (assuming there is one) aoqi@0: // top of stack return address of interpreter caller aoqi@0: // rsp - sender_sp aoqi@0: aoqi@0: // C++ interpreter only aoqi@0: // rsi - previous interpreter state pointer aoqi@0: aoqi@0: // InterpreterRuntime::frequency_counter_overflow takes one argument aoqi@0: // indicating if the counter overflow occurs at a backwards branch (non-NULL bcp). aoqi@0: // The call returns the address of the verified entry point for the method or NULL aoqi@0: // if the compilation did not complete (either went background or bailed out). aoqi@0: __ movptr(rax, (intptr_t)false); aoqi@0: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::frequency_counter_overflow), rax); aoqi@0: aoqi@0: __ movptr(rbx, Address(rbp, method_offset)); // restore Method* aoqi@0: aoqi@0: // Preserve invariant that rsi/rdi contain bcp/locals of sender frame aoqi@0: // and jump to the interpreted entry. aoqi@0: __ jmp(*do_continue, relocInfo::none); aoqi@0: aoqi@0: } aoqi@0: aoqi@0: void InterpreterGenerator::generate_stack_overflow_check(void) { aoqi@0: // see if we've got enough room on the stack for locals plus overhead. aoqi@0: // the expression stack grows down incrementally, so the normal guard aoqi@0: // page mechanism will work for that. aoqi@0: // aoqi@0: // Registers live on entry: aoqi@0: // aoqi@0: // Asm interpreter aoqi@0: // rdx: number of additional locals this frame needs (what we must check) aoqi@0: // rbx,: Method* aoqi@0: aoqi@0: // destroyed on exit aoqi@0: // rax, aoqi@0: aoqi@0: // NOTE: since the additional locals are also always pushed (wasn't obvious in aoqi@0: // generate_method_entry) so the guard should work for them too. aoqi@0: // aoqi@0: aoqi@0: // monitor entry size: see picture of stack set (generate_method_entry) and frame_x86.hpp aoqi@0: const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; aoqi@0: aoqi@0: // total overhead size: entry_size + (saved rbp, thru expr stack bottom). aoqi@0: // be sure to change this if you add/subtract anything to/from the overhead area aoqi@0: const int overhead_size = -(frame::interpreter_frame_initial_sp_offset*wordSize) + entry_size; aoqi@0: aoqi@0: const int page_size = os::vm_page_size(); aoqi@0: aoqi@0: Label after_frame_check; aoqi@0: aoqi@0: // see if the frame is greater than one page in size. If so, aoqi@0: // then we need to verify there is enough stack space remaining aoqi@0: // for the additional locals. aoqi@0: __ cmpl(rdx, (page_size - overhead_size)/Interpreter::stackElementSize); aoqi@0: __ jcc(Assembler::belowEqual, after_frame_check); aoqi@0: aoqi@0: // compute rsp as if this were going to be the last frame on aoqi@0: // the stack before the red zone aoqi@0: aoqi@0: Label after_frame_check_pop; aoqi@0: aoqi@0: __ push(rsi); aoqi@0: aoqi@0: const Register thread = rsi; aoqi@0: aoqi@0: __ get_thread(thread); aoqi@0: aoqi@0: const Address stack_base(thread, Thread::stack_base_offset()); aoqi@0: const Address stack_size(thread, Thread::stack_size_offset()); aoqi@0: aoqi@0: // locals + overhead, in bytes aoqi@0: __ lea(rax, Address(noreg, rdx, Interpreter::stackElementScale(), overhead_size)); aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: Label stack_base_okay, stack_size_okay; aoqi@0: // verify that thread stack base is non-zero aoqi@0: __ cmpptr(stack_base, (int32_t)NULL_WORD); aoqi@0: __ jcc(Assembler::notEqual, stack_base_okay); aoqi@0: __ stop("stack base is zero"); aoqi@0: __ bind(stack_base_okay); aoqi@0: // verify that thread stack size is non-zero aoqi@0: __ cmpptr(stack_size, 0); aoqi@0: __ jcc(Assembler::notEqual, stack_size_okay); aoqi@0: __ stop("stack size is zero"); aoqi@0: __ bind(stack_size_okay); aoqi@0: #endif aoqi@0: aoqi@0: // Add stack base to locals and subtract stack size aoqi@0: __ addptr(rax, stack_base); aoqi@0: __ subptr(rax, stack_size); aoqi@0: aoqi@0: // Use the maximum number of pages we might bang. aoqi@0: const int max_pages = StackShadowPages > (StackRedPages+StackYellowPages) ? StackShadowPages : aoqi@0: (StackRedPages+StackYellowPages); aoqi@0: __ addptr(rax, max_pages * page_size); aoqi@0: aoqi@0: // check against the current stack bottom aoqi@0: __ cmpptr(rsp, rax); aoqi@0: __ jcc(Assembler::above, after_frame_check_pop); aoqi@0: aoqi@0: __ pop(rsi); // get saved bcp / (c++ prev state ). aoqi@0: aoqi@0: // Restore sender's sp as SP. This is necessary if the sender's aoqi@0: // frame is an extended compiled frame (see gen_c2i_adapter()) aoqi@0: // and safer anyway in case of JSR292 adaptations. aoqi@0: aoqi@0: __ pop(rax); // return address must be moved if SP is changed aoqi@0: __ mov(rsp, rsi); aoqi@0: __ push(rax); aoqi@0: aoqi@0: // Note: the restored frame is not necessarily interpreted. aoqi@0: // Use the shared runtime version of the StackOverflowError. aoqi@0: assert(StubRoutines::throw_StackOverflowError_entry() != NULL, "stub not yet generated"); aoqi@0: __ jump(ExternalAddress(StubRoutines::throw_StackOverflowError_entry())); aoqi@0: // all done with frame size check aoqi@0: __ bind(after_frame_check_pop); aoqi@0: __ pop(rsi); aoqi@0: aoqi@0: __ bind(after_frame_check); aoqi@0: } aoqi@0: aoqi@0: // Allocate monitor and lock method (asm interpreter) aoqi@0: // rbx, - Method* aoqi@0: // aoqi@0: void InterpreterGenerator::lock_method(void) { aoqi@0: // synchronize method aoqi@0: const Address access_flags (rbx, Method::access_flags_offset()); aoqi@0: const Address monitor_block_top (rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); aoqi@0: const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; aoqi@0: aoqi@0: #ifdef ASSERT aoqi@0: { Label L; aoqi@0: __ movl(rax, access_flags); aoqi@0: __ testl(rax, JVM_ACC_SYNCHRONIZED); aoqi@0: __ jcc(Assembler::notZero, L); aoqi@0: __ stop("method doesn't need synchronization"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif // ASSERT aoqi@0: // get synchronization object aoqi@0: { Label done; aoqi@0: const int mirror_offset = in_bytes(Klass::java_mirror_offset()); aoqi@0: __ movl(rax, access_flags); aoqi@0: __ testl(rax, JVM_ACC_STATIC); aoqi@0: __ movptr(rax, Address(rdi, Interpreter::local_offset_in_bytes(0))); // get receiver (assume this is frequent case) aoqi@0: __ jcc(Assembler::zero, done); aoqi@0: __ movptr(rax, Address(rbx, Method::const_offset())); aoqi@0: __ movptr(rax, Address(rax, ConstMethod::constants_offset())); aoqi@0: __ movptr(rax, Address(rax, ConstantPool::pool_holder_offset_in_bytes())); aoqi@0: __ movptr(rax, Address(rax, mirror_offset)); aoqi@0: __ bind(done); aoqi@0: } aoqi@0: // add space for monitor & lock aoqi@0: __ subptr(rsp, entry_size); // add space for a monitor entry aoqi@0: __ movptr(monitor_block_top, rsp); // set new monitor block top aoqi@0: __ movptr(Address(rsp, BasicObjectLock::obj_offset_in_bytes()), rax); // store object aoqi@0: __ mov(rdx, rsp); // object address aoqi@0: __ lock_object(rdx); aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // Generate a fixed interpreter frame. This is identical setup for interpreted methods aoqi@0: // and for native methods hence the shared code. aoqi@0: aoqi@0: void TemplateInterpreterGenerator::generate_fixed_frame(bool native_call) { aoqi@0: // initialize fixed part of activation frame aoqi@0: __ push(rax); // save return address aoqi@0: __ enter(); // save old & set new rbp, aoqi@0: aoqi@0: aoqi@0: __ push(rsi); // set sender sp aoqi@0: __ push((int32_t)NULL_WORD); // leave last_sp as null aoqi@0: __ movptr(rsi, Address(rbx,Method::const_offset())); // get ConstMethod* aoqi@0: __ lea(rsi, Address(rsi,ConstMethod::codes_offset())); // get codebase aoqi@0: __ push(rbx); // save Method* aoqi@0: if (ProfileInterpreter) { aoqi@0: Label method_data_continue; aoqi@0: __ movptr(rdx, Address(rbx, in_bytes(Method::method_data_offset()))); aoqi@0: __ testptr(rdx, rdx); aoqi@0: __ jcc(Assembler::zero, method_data_continue); aoqi@0: __ addptr(rdx, in_bytes(MethodData::data_offset())); aoqi@0: __ bind(method_data_continue); aoqi@0: __ push(rdx); // set the mdp (method data pointer) aoqi@0: } else { aoqi@0: __ push(0); aoqi@0: } aoqi@0: aoqi@0: __ movptr(rdx, Address(rbx, Method::const_offset())); aoqi@0: __ movptr(rdx, Address(rdx, ConstMethod::constants_offset())); aoqi@0: __ movptr(rdx, Address(rdx, ConstantPool::cache_offset_in_bytes())); aoqi@0: __ push(rdx); // set constant pool cache aoqi@0: __ push(rdi); // set locals pointer aoqi@0: if (native_call) { aoqi@0: __ push(0); // no bcp aoqi@0: } else { aoqi@0: __ push(rsi); // set bcp aoqi@0: } aoqi@0: __ push(0); // reserve word for pointer to expression stack bottom aoqi@0: __ movptr(Address(rsp, 0), rsp); // set expression stack bottom aoqi@0: } aoqi@0: aoqi@0: // End of helpers aoqi@0: aoqi@0: // aoqi@0: // Various method entries aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // aoqi@0: // aoqi@0: aoqi@0: // Call an accessor method (assuming it is resolved, otherwise drop into vanilla (slow path) entry aoqi@0: aoqi@0: address InterpreterGenerator::generate_accessor_entry(void) { aoqi@0: aoqi@0: // rbx,: Method* aoqi@0: // rcx: receiver (preserve for slow entry into asm interpreter) aoqi@0: aoqi@0: // rsi: senderSP must preserved for slow path, set SP to it on fast path aoqi@0: aoqi@0: address entry_point = __ pc(); aoqi@0: Label xreturn_path; aoqi@0: aoqi@0: // do fastpath for resolved accessor methods aoqi@0: if (UseFastAccessorMethods) { aoqi@0: Label slow_path; aoqi@0: // If we need a safepoint check, generate full interpreter entry. aoqi@0: ExternalAddress state(SafepointSynchronize::address_of_state()); aoqi@0: __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), aoqi@0: SafepointSynchronize::_not_synchronized); aoqi@0: aoqi@0: __ jcc(Assembler::notEqual, slow_path); aoqi@0: // ASM/C++ Interpreter aoqi@0: // Code: _aload_0, _(i|a)getfield, _(i|a)return or any rewrites thereof; parameter size = 1 aoqi@0: // Note: We can only use this code if the getfield has been resolved aoqi@0: // and if we don't have a null-pointer exception => check for aoqi@0: // these conditions first and use slow path if necessary. aoqi@0: // rbx,: method aoqi@0: // rcx: receiver aoqi@0: __ movptr(rax, Address(rsp, wordSize)); aoqi@0: aoqi@0: // check if local 0 != NULL and read field aoqi@0: __ testptr(rax, rax); aoqi@0: __ jcc(Assembler::zero, slow_path); aoqi@0: aoqi@0: // read first instruction word and extract bytecode @ 1 and index @ 2 aoqi@0: __ movptr(rdx, Address(rbx, Method::const_offset())); aoqi@0: __ movptr(rdi, Address(rdx, ConstMethod::constants_offset())); aoqi@0: __ movl(rdx, Address(rdx, ConstMethod::codes_offset())); aoqi@0: // Shift codes right to get the index on the right. aoqi@0: // The bytecode fetched looks like <0xb4><0x2a> aoqi@0: __ shrl(rdx, 2*BitsPerByte); aoqi@0: __ shll(rdx, exact_log2(in_words(ConstantPoolCacheEntry::size()))); aoqi@0: __ movptr(rdi, Address(rdi, ConstantPool::cache_offset_in_bytes())); aoqi@0: aoqi@0: // rax,: local 0 aoqi@0: // rbx,: method aoqi@0: // rcx: receiver - do not destroy since it is needed for slow path! aoqi@0: // rcx: scratch aoqi@0: // rdx: constant pool cache index aoqi@0: // rdi: constant pool cache aoqi@0: // rsi: sender sp aoqi@0: aoqi@0: // check if getfield has been resolved and read constant pool cache entry aoqi@0: // check the validity of the cache entry by testing whether _indices field aoqi@0: // contains Bytecode::_getfield in b1 byte. aoqi@0: assert(in_words(ConstantPoolCacheEntry::size()) == 4, "adjust shift below"); aoqi@0: __ movl(rcx, aoqi@0: Address(rdi, aoqi@0: rdx, aoqi@0: Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::indices_offset())); aoqi@0: __ shrl(rcx, 2*BitsPerByte); aoqi@0: __ andl(rcx, 0xFF); aoqi@0: __ cmpl(rcx, Bytecodes::_getfield); aoqi@0: __ jcc(Assembler::notEqual, slow_path); aoqi@0: aoqi@0: // Note: constant pool entry is not valid before bytecode is resolved aoqi@0: __ movptr(rcx, aoqi@0: Address(rdi, aoqi@0: rdx, aoqi@0: Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::f2_offset())); aoqi@0: __ movl(rdx, aoqi@0: Address(rdi, aoqi@0: rdx, aoqi@0: Address::times_ptr, ConstantPoolCache::base_offset() + ConstantPoolCacheEntry::flags_offset())); aoqi@0: aoqi@0: Label notByte, notShort, notChar; aoqi@0: const Address field_address (rax, rcx, Address::times_1); aoqi@0: aoqi@0: // Need to differentiate between igetfield, agetfield, bgetfield etc. aoqi@0: // because they are different sizes. aoqi@0: // Use the type from the constant pool cache aoqi@0: __ shrl(rdx, ConstantPoolCacheEntry::tos_state_shift); aoqi@0: // Make sure we don't need to mask rdx after the above shift aoqi@0: ConstantPoolCacheEntry::verify_tos_state_shift(); aoqi@0: __ cmpl(rdx, btos); aoqi@0: __ jcc(Assembler::notEqual, notByte); aoqi@0: __ load_signed_byte(rax, field_address); aoqi@0: __ jmp(xreturn_path); aoqi@0: aoqi@0: __ bind(notByte); aoqi@0: __ cmpl(rdx, stos); aoqi@0: __ jcc(Assembler::notEqual, notShort); aoqi@0: __ load_signed_short(rax, field_address); aoqi@0: __ jmp(xreturn_path); aoqi@0: aoqi@0: __ bind(notShort); aoqi@0: __ cmpl(rdx, ctos); aoqi@0: __ jcc(Assembler::notEqual, notChar); aoqi@0: __ load_unsigned_short(rax, field_address); aoqi@0: __ jmp(xreturn_path); aoqi@0: aoqi@0: __ bind(notChar); aoqi@0: #ifdef ASSERT aoqi@0: Label okay; aoqi@0: __ cmpl(rdx, atos); aoqi@0: __ jcc(Assembler::equal, okay); aoqi@0: __ cmpl(rdx, itos); aoqi@0: __ jcc(Assembler::equal, okay); aoqi@0: __ stop("what type is this?"); aoqi@0: __ bind(okay); aoqi@0: #endif // ASSERT aoqi@0: // All the rest are a 32 bit wordsize aoqi@0: // This is ok for now. Since fast accessors should be going away aoqi@0: __ movptr(rax, field_address); aoqi@0: aoqi@0: __ bind(xreturn_path); aoqi@0: aoqi@0: // _ireturn/_areturn aoqi@0: __ pop(rdi); // get return address aoqi@0: __ mov(rsp, rsi); // set sp to sender sp aoqi@0: __ jmp(rdi); aoqi@0: aoqi@0: // generate a vanilla interpreter entry as the slow path aoqi@0: __ bind(slow_path); aoqi@0: aoqi@0: (void) generate_normal_entry(false); aoqi@0: return entry_point; aoqi@0: } aoqi@0: return NULL; aoqi@0: aoqi@0: } aoqi@0: aoqi@0: // Method entry for java.lang.ref.Reference.get. aoqi@0: address InterpreterGenerator::generate_Reference_get_entry(void) { aoqi@0: #if INCLUDE_ALL_GCS aoqi@0: // Code: _aload_0, _getfield, _areturn aoqi@0: // parameter size = 1 aoqi@0: // aoqi@0: // The code that gets generated by this routine is split into 2 parts: aoqi@0: // 1. The "intrinsified" code for G1 (or any SATB based GC), aoqi@0: // 2. The slow path - which is an expansion of the regular method entry. aoqi@0: // aoqi@0: // Notes:- aoqi@0: // * In the G1 code we do not check whether we need to block for aoqi@0: // a safepoint. If G1 is enabled then we must execute the specialized aoqi@0: // code for Reference.get (except when the Reference object is null) aoqi@0: // so that we can log the value in the referent field with an SATB aoqi@0: // update buffer. aoqi@0: // If the code for the getfield template is modified so that the aoqi@0: // G1 pre-barrier code is executed when the current method is aoqi@0: // Reference.get() then going through the normal method entry aoqi@0: // will be fine. aoqi@0: // * The G1 code below can, however, check the receiver object (the instance aoqi@0: // of java.lang.Reference) and jump to the slow path if null. If the aoqi@0: // Reference object is null then we obviously cannot fetch the referent aoqi@0: // and so we don't need to call the G1 pre-barrier. Thus we can use the aoqi@0: // regular method entry code to generate the NPE. aoqi@0: // aoqi@0: // This code is based on generate_accessor_enty. aoqi@0: aoqi@0: // rbx,: Method* aoqi@0: // rcx: receiver (preserve for slow entry into asm interpreter) aoqi@0: aoqi@0: // rsi: senderSP must preserved for slow path, set SP to it on fast path aoqi@0: aoqi@0: address entry = __ pc(); aoqi@0: aoqi@0: const int referent_offset = java_lang_ref_Reference::referent_offset; aoqi@0: guarantee(referent_offset > 0, "referent offset not initialized"); aoqi@0: aoqi@0: if (UseG1GC) { aoqi@0: Label slow_path; aoqi@0: aoqi@0: // Check if local 0 != NULL aoqi@0: // If the receiver is null then it is OK to jump to the slow path. aoqi@0: __ movptr(rax, Address(rsp, wordSize)); aoqi@0: __ testptr(rax, rax); aoqi@0: __ jcc(Assembler::zero, slow_path); aoqi@0: aoqi@0: // rax: local 0 (must be preserved across the G1 barrier call) aoqi@0: // aoqi@0: // rbx: method (at this point it's scratch) aoqi@0: // rcx: receiver (at this point it's scratch) aoqi@0: // rdx: scratch aoqi@0: // rdi: scratch aoqi@0: // aoqi@0: // rsi: sender sp aoqi@0: aoqi@0: // Preserve the sender sp in case the pre-barrier aoqi@0: // calls the runtime aoqi@0: __ push(rsi); aoqi@0: aoqi@0: // Load the value of the referent field. aoqi@0: const Address field_address(rax, referent_offset); aoqi@0: __ movptr(rax, field_address); aoqi@0: aoqi@0: // Generate the G1 pre-barrier code to log the value of aoqi@0: // the referent field in an SATB buffer. aoqi@0: __ get_thread(rcx); aoqi@0: __ g1_write_barrier_pre(noreg /* obj */, aoqi@0: rax /* pre_val */, aoqi@0: rcx /* thread */, aoqi@0: rbx /* tmp */, aoqi@0: true /* tosca_save */, aoqi@0: true /* expand_call */); aoqi@0: aoqi@0: // _areturn aoqi@0: __ pop(rsi); // get sender sp aoqi@0: __ pop(rdi); // get return address aoqi@0: __ mov(rsp, rsi); // set sp to sender sp aoqi@0: __ jmp(rdi); aoqi@0: aoqi@0: __ bind(slow_path); aoqi@0: (void) generate_normal_entry(false); aoqi@0: aoqi@0: return entry; aoqi@0: } aoqi@0: #endif // INCLUDE_ALL_GCS aoqi@0: aoqi@0: // If G1 is not enabled then attempt to go through the accessor entry point aoqi@0: // Reference.get is an accessor aoqi@0: return generate_accessor_entry(); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Method entry for static native methods: aoqi@0: * int java.util.zip.CRC32.update(int crc, int b) aoqi@0: */ aoqi@0: address InterpreterGenerator::generate_CRC32_update_entry() { aoqi@0: if (UseCRC32Intrinsics) { aoqi@0: address entry = __ pc(); aoqi@0: aoqi@0: // rbx,: Method* aoqi@0: // rsi: senderSP must preserved for slow path, set SP to it on fast path aoqi@0: // rdx: scratch aoqi@0: // rdi: scratch aoqi@0: aoqi@0: Label slow_path; aoqi@0: // If we need a safepoint check, generate full interpreter entry. aoqi@0: ExternalAddress state(SafepointSynchronize::address_of_state()); aoqi@0: __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), aoqi@0: SafepointSynchronize::_not_synchronized); aoqi@0: __ jcc(Assembler::notEqual, slow_path); aoqi@0: aoqi@0: // We don't generate local frame and don't align stack because aoqi@0: // we call stub code and there is no safepoint on this path. aoqi@0: aoqi@0: // Load parameters aoqi@0: const Register crc = rax; // crc aoqi@0: const Register val = rdx; // source java byte value aoqi@0: const Register tbl = rdi; // scratch aoqi@0: aoqi@0: // Arguments are reversed on java expression stack aoqi@0: __ movl(val, Address(rsp, wordSize)); // byte value aoqi@0: __ movl(crc, Address(rsp, 2*wordSize)); // Initial CRC aoqi@0: aoqi@0: __ lea(tbl, ExternalAddress(StubRoutines::crc_table_addr())); aoqi@0: __ notl(crc); // ~crc aoqi@0: __ update_byte_crc32(crc, val, tbl); aoqi@0: __ notl(crc); // ~crc aoqi@0: // result in rax aoqi@0: aoqi@0: // _areturn aoqi@0: __ pop(rdi); // get return address aoqi@0: __ mov(rsp, rsi); // set sp to sender sp aoqi@0: __ jmp(rdi); aoqi@0: aoqi@0: // generate a vanilla native entry as the slow path aoqi@0: __ bind(slow_path); aoqi@0: aoqi@0: (void) generate_native_entry(false); aoqi@0: aoqi@0: return entry; aoqi@0: } aoqi@0: return generate_native_entry(false); aoqi@0: } aoqi@0: aoqi@0: /** aoqi@0: * Method entry for static native methods: aoqi@0: * int java.util.zip.CRC32.updateBytes(int crc, byte[] b, int off, int len) aoqi@0: * int java.util.zip.CRC32.updateByteBuffer(int crc, long buf, int off, int len) aoqi@0: */ aoqi@0: address InterpreterGenerator::generate_CRC32_updateBytes_entry(AbstractInterpreter::MethodKind kind) { aoqi@0: if (UseCRC32Intrinsics) { aoqi@0: address entry = __ pc(); aoqi@0: aoqi@0: // rbx,: Method* aoqi@0: // rsi: senderSP must preserved for slow path, set SP to it on fast path aoqi@0: // rdx: scratch aoqi@0: // rdi: scratch aoqi@0: aoqi@0: Label slow_path; aoqi@0: // If we need a safepoint check, generate full interpreter entry. aoqi@0: ExternalAddress state(SafepointSynchronize::address_of_state()); aoqi@0: __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), aoqi@0: SafepointSynchronize::_not_synchronized); aoqi@0: __ jcc(Assembler::notEqual, slow_path); aoqi@0: aoqi@0: // We don't generate local frame and don't align stack because aoqi@0: // we call stub code and there is no safepoint on this path. aoqi@0: aoqi@0: // Load parameters aoqi@0: const Register crc = rax; // crc aoqi@0: const Register buf = rdx; // source java byte array address aoqi@0: const Register len = rdi; // length aoqi@0: aoqi@0: // Arguments are reversed on java expression stack aoqi@0: __ movl(len, Address(rsp, wordSize)); // Length aoqi@0: // Calculate address of start element aoqi@0: if (kind == Interpreter::java_util_zip_CRC32_updateByteBuffer) { aoqi@0: __ movptr(buf, Address(rsp, 3*wordSize)); // long buf aoqi@0: __ addptr(buf, Address(rsp, 2*wordSize)); // + offset aoqi@0: __ movl(crc, Address(rsp, 5*wordSize)); // Initial CRC aoqi@0: } else { aoqi@0: __ movptr(buf, Address(rsp, 3*wordSize)); // byte[] array aoqi@0: __ addptr(buf, arrayOopDesc::base_offset_in_bytes(T_BYTE)); // + header size aoqi@0: __ addptr(buf, Address(rsp, 2*wordSize)); // + offset aoqi@0: __ movl(crc, Address(rsp, 4*wordSize)); // Initial CRC aoqi@0: } aoqi@0: aoqi@0: __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, StubRoutines::updateBytesCRC32()), crc, buf, len); aoqi@0: // result in rax aoqi@0: aoqi@0: // _areturn aoqi@0: __ pop(rdi); // get return address aoqi@0: __ mov(rsp, rsi); // set sp to sender sp aoqi@0: __ jmp(rdi); aoqi@0: aoqi@0: // generate a vanilla native entry as the slow path aoqi@0: __ bind(slow_path); aoqi@0: aoqi@0: (void) generate_native_entry(false); aoqi@0: aoqi@0: return entry; aoqi@0: } aoqi@0: return generate_native_entry(false); aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // Interpreter stub for calling a native method. (asm interpreter) aoqi@0: // This sets up a somewhat different looking stack for calling the native method aoqi@0: // than the typical interpreter frame setup. aoqi@0: // aoqi@0: aoqi@0: address InterpreterGenerator::generate_native_entry(bool synchronized) { aoqi@0: // determine code generation flags aoqi@0: bool inc_counter = UseCompiler || CountCompiledCalls; aoqi@0: aoqi@0: // rbx,: Method* aoqi@0: // rsi: sender sp aoqi@0: // rsi: previous interpreter state (C++ interpreter) must preserve aoqi@0: address entry_point = __ pc(); aoqi@0: aoqi@0: const Address constMethod (rbx, Method::const_offset()); aoqi@0: const Address access_flags (rbx, Method::access_flags_offset()); aoqi@0: const Address size_of_parameters(rcx, ConstMethod::size_of_parameters_offset()); aoqi@0: aoqi@0: // get parameter size (always needed) aoqi@0: __ movptr(rcx, constMethod); aoqi@0: __ load_unsigned_short(rcx, size_of_parameters); aoqi@0: aoqi@0: // native calls don't need the stack size check since they have no expression stack aoqi@0: // and the arguments are already on the stack and we only add a handful of words aoqi@0: // to the stack aoqi@0: aoqi@0: // rbx,: Method* aoqi@0: // rcx: size of parameters aoqi@0: // rsi: sender sp aoqi@0: aoqi@0: __ pop(rax); // get return address aoqi@0: // for natives the size of locals is zero aoqi@0: aoqi@0: // compute beginning of parameters (rdi) aoqi@0: __ lea(rdi, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize)); aoqi@0: aoqi@0: aoqi@0: // add 2 zero-initialized slots for native calls aoqi@0: // NULL result handler aoqi@0: __ push((int32_t)NULL_WORD); aoqi@0: // NULL oop temp (mirror or jni oop result) aoqi@0: __ push((int32_t)NULL_WORD); aoqi@0: aoqi@0: // initialize fixed part of activation frame aoqi@0: generate_fixed_frame(true); aoqi@0: aoqi@0: // make sure method is native & not abstract aoqi@0: #ifdef ASSERT aoqi@0: __ movl(rax, access_flags); aoqi@0: { aoqi@0: Label L; aoqi@0: __ testl(rax, JVM_ACC_NATIVE); aoqi@0: __ jcc(Assembler::notZero, L); aoqi@0: __ stop("tried to execute non-native method as native"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: { Label L; aoqi@0: __ testl(rax, JVM_ACC_ABSTRACT); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: __ stop("tried to execute abstract method in interpreter"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Since at this point in the method invocation the exception handler aoqi@0: // would try to exit the monitor of synchronized methods which hasn't aoqi@0: // been entered yet, we set the thread local variable aoqi@0: // _do_not_unlock_if_synchronized to true. The remove_activation will aoqi@0: // check this flag. aoqi@0: aoqi@0: __ get_thread(rax); aoqi@0: const Address do_not_unlock_if_synchronized(rax, aoqi@0: in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); aoqi@0: __ movbool(do_not_unlock_if_synchronized, true); aoqi@0: aoqi@0: // increment invocation count & check for overflow aoqi@0: Label invocation_counter_overflow; aoqi@0: if (inc_counter) { aoqi@0: generate_counter_incr(&invocation_counter_overflow, NULL, NULL); aoqi@0: } aoqi@0: aoqi@0: Label continue_after_compile; aoqi@0: __ bind(continue_after_compile); aoqi@0: aoqi@0: bang_stack_shadow_pages(true); aoqi@0: aoqi@0: // reset the _do_not_unlock_if_synchronized flag aoqi@0: __ get_thread(rax); aoqi@0: __ movbool(do_not_unlock_if_synchronized, false); aoqi@0: aoqi@0: // check for synchronized methods aoqi@0: // Must happen AFTER invocation_counter check and stack overflow check, aoqi@0: // so method is not locked if overflows. aoqi@0: // aoqi@0: if (synchronized) { aoqi@0: lock_method(); aoqi@0: } else { aoqi@0: // no synchronization necessary aoqi@0: #ifdef ASSERT aoqi@0: { Label L; aoqi@0: __ movl(rax, access_flags); aoqi@0: __ testl(rax, JVM_ACC_SYNCHRONIZED); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: __ stop("method needs synchronization"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: // start execution aoqi@0: #ifdef ASSERT aoqi@0: { Label L; aoqi@0: const Address monitor_block_top (rbp, aoqi@0: frame::interpreter_frame_monitor_block_top_offset * wordSize); aoqi@0: __ movptr(rax, monitor_block_top); aoqi@0: __ cmpptr(rax, rsp); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ stop("broken stack frame setup in interpreter"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // jvmti/dtrace support aoqi@0: __ notify_method_entry(); aoqi@0: aoqi@0: // work registers aoqi@0: const Register method = rbx; aoqi@0: const Register thread = rdi; aoqi@0: const Register t = rcx; aoqi@0: aoqi@0: // allocate space for parameters aoqi@0: __ get_method(method); aoqi@0: __ movptr(t, Address(method, Method::const_offset())); aoqi@0: __ load_unsigned_short(t, Address(t, ConstMethod::size_of_parameters_offset())); aoqi@0: aoqi@0: __ shlptr(t, Interpreter::logStackElementSize); aoqi@0: __ addptr(t, 2*wordSize); // allocate two more slots for JNIEnv and possible mirror aoqi@0: __ subptr(rsp, t); aoqi@0: __ andptr(rsp, -(StackAlignmentInBytes)); // gcc needs 16 byte aligned stacks to do XMM intrinsics aoqi@0: aoqi@0: // get signature handler aoqi@0: { Label L; aoqi@0: __ movptr(t, Address(method, Method::signature_handler_offset())); aoqi@0: __ testptr(t, t); aoqi@0: __ jcc(Assembler::notZero, L); aoqi@0: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method); aoqi@0: __ get_method(method); aoqi@0: __ movptr(t, Address(method, Method::signature_handler_offset())); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: aoqi@0: // call signature handler aoqi@0: assert(InterpreterRuntime::SignatureHandlerGenerator::from() == rdi, "adjust this code"); aoqi@0: assert(InterpreterRuntime::SignatureHandlerGenerator::to () == rsp, "adjust this code"); aoqi@0: assert(InterpreterRuntime::SignatureHandlerGenerator::temp() == t , "adjust this code"); aoqi@0: // The generated handlers do not touch RBX (the method oop). aoqi@0: // However, large signatures cannot be cached and are generated aoqi@0: // each time here. The slow-path generator will blow RBX aoqi@0: // sometime, so we must reload it after the call. aoqi@0: __ call(t); aoqi@0: __ get_method(method); // slow path call blows RBX on DevStudio 5.0 aoqi@0: aoqi@0: // result handler is in rax, aoqi@0: // set result handler aoqi@0: __ movptr(Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize), rax); aoqi@0: aoqi@0: // pass mirror handle if static call aoqi@0: { Label L; aoqi@0: const int mirror_offset = in_bytes(Klass::java_mirror_offset()); aoqi@0: __ movl(t, Address(method, Method::access_flags_offset())); aoqi@0: __ testl(t, JVM_ACC_STATIC); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: // get mirror aoqi@0: __ movptr(t, Address(method, Method:: const_offset())); aoqi@0: __ movptr(t, Address(t, ConstMethod::constants_offset())); aoqi@0: __ movptr(t, Address(t, ConstantPool::pool_holder_offset_in_bytes())); aoqi@0: __ movptr(t, Address(t, mirror_offset)); aoqi@0: // copy mirror into activation frame aoqi@0: __ movptr(Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize), t); aoqi@0: // pass handle to mirror aoqi@0: __ lea(t, Address(rbp, frame::interpreter_frame_oop_temp_offset * wordSize)); aoqi@0: __ movptr(Address(rsp, wordSize), t); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: aoqi@0: // get native function entry point aoqi@0: { Label L; aoqi@0: __ movptr(rax, Address(method, Method::native_function_offset())); aoqi@0: ExternalAddress unsatisfied(SharedRuntime::native_method_throw_unsatisfied_link_error_entry()); aoqi@0: __ cmpptr(rax, unsatisfied.addr()); aoqi@0: __ jcc(Assembler::notEqual, L); aoqi@0: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::prepare_native_call), method); aoqi@0: __ get_method(method); aoqi@0: __ movptr(rax, Address(method, Method::native_function_offset())); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: aoqi@0: // pass JNIEnv aoqi@0: __ get_thread(thread); aoqi@0: __ lea(t, Address(thread, JavaThread::jni_environment_offset())); aoqi@0: __ movptr(Address(rsp, 0), t); aoqi@0: aoqi@0: // set_last_Java_frame_before_call aoqi@0: // It is enough that the pc() aoqi@0: // points into the right code segment. It does not have to be the correct return pc. aoqi@0: __ set_last_Java_frame(thread, noreg, rbp, __ pc()); aoqi@0: aoqi@0: // change thread state aoqi@0: #ifdef ASSERT aoqi@0: { Label L; aoqi@0: __ movl(t, Address(thread, JavaThread::thread_state_offset())); aoqi@0: __ cmpl(t, _thread_in_Java); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ stop("Wrong thread state in native stub"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Change state to native aoqi@0: __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native); aoqi@0: __ call(rax); aoqi@0: aoqi@0: // result potentially in rdx:rax or ST0 aoqi@0: aoqi@0: // Verify or restore cpu control state after JNI call aoqi@0: __ restore_cpu_control_state_after_jni(); aoqi@0: aoqi@0: // save potential result in ST(0) & rdx:rax aoqi@0: // (if result handler is the T_FLOAT or T_DOUBLE handler, result must be in ST0 - aoqi@0: // the check is necessary to avoid potential Intel FPU overflow problems by saving/restoring 'empty' FPU registers) aoqi@0: // It is safe to do this push because state is _thread_in_native and return address will be found aoqi@0: // via _last_native_pc and not via _last_jave_sp aoqi@0: aoqi@0: // NOTE: the order of theses push(es) is known to frame::interpreter_frame_result. aoqi@0: // If the order changes or anything else is added to the stack the code in aoqi@0: // interpreter_frame_result will have to be changed. aoqi@0: aoqi@0: { Label L; aoqi@0: Label push_double; aoqi@0: ExternalAddress float_handler(AbstractInterpreter::result_handler(T_FLOAT)); aoqi@0: ExternalAddress double_handler(AbstractInterpreter::result_handler(T_DOUBLE)); aoqi@0: __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize), aoqi@0: float_handler.addr()); aoqi@0: __ jcc(Assembler::equal, push_double); aoqi@0: __ cmpptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset + 1)*wordSize), aoqi@0: double_handler.addr()); aoqi@0: __ jcc(Assembler::notEqual, L); aoqi@0: __ bind(push_double); aoqi@0: __ push(dtos); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: __ push(ltos); aoqi@0: aoqi@0: // change thread state aoqi@0: __ get_thread(thread); aoqi@0: __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_native_trans); aoqi@0: if(os::is_MP()) { aoqi@0: if (UseMembar) { aoqi@0: // Force this write out before the read below aoqi@0: __ membar(Assembler::Membar_mask_bits( aoqi@0: Assembler::LoadLoad | Assembler::LoadStore | aoqi@0: Assembler::StoreLoad | Assembler::StoreStore)); aoqi@0: } else { aoqi@0: // Write serialization page so VM thread can do a pseudo remote membar. aoqi@0: // We use the current thread pointer to calculate a thread specific aoqi@0: // offset to write to within the page. This minimizes bus traffic aoqi@0: // due to cache line collision. aoqi@0: __ serialize_memory(thread, rcx); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: if (AlwaysRestoreFPU) { aoqi@0: // Make sure the control word is correct. aoqi@0: __ fldcw(ExternalAddress(StubRoutines::addr_fpu_cntrl_wrd_std())); aoqi@0: } aoqi@0: aoqi@0: // check for safepoint operation in progress and/or pending suspend requests aoqi@0: { Label Continue; aoqi@0: aoqi@0: __ cmp32(ExternalAddress(SafepointSynchronize::address_of_state()), aoqi@0: SafepointSynchronize::_not_synchronized); aoqi@0: aoqi@0: Label L; aoqi@0: __ jcc(Assembler::notEqual, L); aoqi@0: __ cmpl(Address(thread, JavaThread::suspend_flags_offset()), 0); aoqi@0: __ jcc(Assembler::equal, Continue); aoqi@0: __ bind(L); aoqi@0: aoqi@0: // Don't use call_VM as it will see a possible pending exception and forward it aoqi@0: // and never return here preventing us from clearing _last_native_pc down below. aoqi@0: // Also can't use call_VM_leaf either as it will check to see if rsi & rdi are aoqi@0: // preserved and correspond to the bcp/locals pointers. So we do a runtime call aoqi@0: // by hand. aoqi@0: // aoqi@0: __ push(thread); aoqi@0: __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, aoqi@0: JavaThread::check_special_condition_for_native_trans))); aoqi@0: __ increment(rsp, wordSize); aoqi@0: __ get_thread(thread); aoqi@0: aoqi@0: __ bind(Continue); aoqi@0: } aoqi@0: aoqi@0: // change thread state aoqi@0: __ movl(Address(thread, JavaThread::thread_state_offset()), _thread_in_Java); aoqi@0: aoqi@0: __ reset_last_Java_frame(thread, true, true); aoqi@0: aoqi@0: // reset handle block aoqi@0: __ movptr(t, Address(thread, JavaThread::active_handles_offset())); aoqi@0: __ movl(Address(t, JNIHandleBlock::top_offset_in_bytes()), NULL_WORD); aoqi@0: aoqi@0: // If result was an oop then unbox and save it in the frame aoqi@0: { Label L; aoqi@0: Label no_oop, store_result; aoqi@0: ExternalAddress handler(AbstractInterpreter::result_handler(T_OBJECT)); aoqi@0: __ cmpptr(Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize), aoqi@0: handler.addr()); aoqi@0: __ jcc(Assembler::notEqual, no_oop); aoqi@0: __ cmpptr(Address(rsp, 0), (int32_t)NULL_WORD); aoqi@0: __ pop(ltos); aoqi@0: __ testptr(rax, rax); aoqi@0: __ jcc(Assembler::zero, store_result); aoqi@0: // unbox aoqi@0: __ movptr(rax, Address(rax, 0)); aoqi@0: __ bind(store_result); aoqi@0: __ movptr(Address(rbp, (frame::interpreter_frame_oop_temp_offset)*wordSize), rax); aoqi@0: // keep stack depth as expected by pushing oop which will eventually be discarded aoqi@0: __ push(ltos); aoqi@0: __ bind(no_oop); aoqi@0: } aoqi@0: aoqi@0: { aoqi@0: Label no_reguard; aoqi@0: __ cmpl(Address(thread, JavaThread::stack_guard_state_offset()), JavaThread::stack_guard_yellow_disabled); aoqi@0: __ jcc(Assembler::notEqual, no_reguard); aoqi@0: aoqi@0: __ pusha(); aoqi@0: __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, SharedRuntime::reguard_yellow_pages))); aoqi@0: __ popa(); aoqi@0: aoqi@0: __ bind(no_reguard); aoqi@0: } aoqi@0: aoqi@0: // restore rsi to have legal interpreter frame, aoqi@0: // i.e., bci == 0 <=> rsi == code_base() aoqi@0: // Can't call_VM until bcp is within reasonable. aoqi@0: __ get_method(method); // method is junk from thread_in_native to now. aoqi@0: __ movptr(rsi, Address(method,Method::const_offset())); // get ConstMethod* aoqi@0: __ lea(rsi, Address(rsi,ConstMethod::codes_offset())); // get codebase aoqi@0: aoqi@0: // handle exceptions (exception handling will handle unlocking!) aoqi@0: { Label L; aoqi@0: __ cmpptr(Address(thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: // Note: At some point we may want to unify this with the code used in call_VM_base(); aoqi@0: // i.e., we should use the StubRoutines::forward_exception code. For now this aoqi@0: // doesn't work here because the rsp is not correctly set at this point. aoqi@0: __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_pending_exception)); aoqi@0: __ should_not_reach_here(); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: aoqi@0: // do unlocking if necessary aoqi@0: { Label L; aoqi@0: __ movl(t, Address(method, Method::access_flags_offset())); aoqi@0: __ testl(t, JVM_ACC_SYNCHRONIZED); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: // the code below should be shared with interpreter macro assembler implementation aoqi@0: { Label unlock; aoqi@0: // BasicObjectLock will be first in list, since this is a synchronized method. However, need aoqi@0: // to check that the object has not been unlocked by an explicit monitorexit bytecode. aoqi@0: const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * wordSize - (int)sizeof(BasicObjectLock)); aoqi@0: aoqi@0: __ lea(rdx, monitor); // address of first monitor aoqi@0: aoqi@0: __ movptr(t, Address(rdx, BasicObjectLock::obj_offset_in_bytes())); aoqi@0: __ testptr(t, t); aoqi@0: __ jcc(Assembler::notZero, unlock); aoqi@0: aoqi@0: // Entry already unlocked, need to throw exception aoqi@0: __ MacroAssembler::call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::throw_illegal_monitor_state_exception)); aoqi@0: __ should_not_reach_here(); aoqi@0: aoqi@0: __ bind(unlock); aoqi@0: __ unlock_object(rdx); aoqi@0: } aoqi@0: __ bind(L); aoqi@0: } aoqi@0: aoqi@0: // jvmti/dtrace support aoqi@0: // Note: This must happen _after_ handling/throwing any exceptions since aoqi@0: // the exception handler code notifies the runtime of method exits aoqi@0: // too. If this happens before, method entry/exit notifications are aoqi@0: // not properly paired (was bug - gri 11/22/99). aoqi@0: __ notify_method_exit(vtos, InterpreterMacroAssembler::NotifyJVMTI); aoqi@0: aoqi@0: // restore potential result in rdx:rax, call result handler to restore potential result in ST0 & handle result aoqi@0: __ pop(ltos); aoqi@0: __ movptr(t, Address(rbp, frame::interpreter_frame_result_handler_offset*wordSize)); aoqi@0: __ call(t); aoqi@0: aoqi@0: // remove activation aoqi@0: __ movptr(t, Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); // get sender sp aoqi@0: __ leave(); // remove frame anchor aoqi@0: __ pop(rdi); // get return address aoqi@0: __ mov(rsp, t); // set sp to sender sp aoqi@0: __ jmp(rdi); aoqi@0: aoqi@0: if (inc_counter) { aoqi@0: // Handle overflow of counter and compile method aoqi@0: __ bind(invocation_counter_overflow); aoqi@0: generate_counter_overflow(&continue_after_compile); aoqi@0: } aoqi@0: aoqi@0: return entry_point; aoqi@0: } aoqi@0: aoqi@0: // aoqi@0: // Generic interpreted method entry to (asm) interpreter aoqi@0: // aoqi@0: address InterpreterGenerator::generate_normal_entry(bool synchronized) { aoqi@0: // determine code generation flags aoqi@0: bool inc_counter = UseCompiler || CountCompiledCalls; aoqi@0: aoqi@0: // rbx,: Method* aoqi@0: // rsi: sender sp aoqi@0: address entry_point = __ pc(); aoqi@0: aoqi@0: const Address constMethod (rbx, Method::const_offset()); aoqi@0: const Address access_flags (rbx, Method::access_flags_offset()); aoqi@0: const Address size_of_parameters(rdx, ConstMethod::size_of_parameters_offset()); aoqi@0: const Address size_of_locals (rdx, ConstMethod::size_of_locals_offset()); aoqi@0: aoqi@0: // get parameter size (always needed) aoqi@0: __ movptr(rdx, constMethod); aoqi@0: __ load_unsigned_short(rcx, size_of_parameters); aoqi@0: aoqi@0: // rbx,: Method* aoqi@0: // rcx: size of parameters aoqi@0: aoqi@0: // rsi: sender_sp (could differ from sp+wordSize if we were called via c2i ) aoqi@0: aoqi@0: __ load_unsigned_short(rdx, size_of_locals); // get size of locals in words aoqi@0: __ subl(rdx, rcx); // rdx = no. of additional locals aoqi@0: aoqi@0: // see if we've got enough room on the stack for locals plus overhead. aoqi@0: generate_stack_overflow_check(); aoqi@0: aoqi@0: // get return address aoqi@0: __ pop(rax); aoqi@0: aoqi@0: // compute beginning of parameters (rdi) aoqi@0: __ lea(rdi, Address(rsp, rcx, Interpreter::stackElementScale(), -wordSize)); aoqi@0: aoqi@0: // rdx - # of additional locals aoqi@0: // allocate space for locals aoqi@0: // explicitly initialize locals aoqi@0: { aoqi@0: Label exit, loop; aoqi@0: __ testl(rdx, rdx); aoqi@0: __ jcc(Assembler::lessEqual, exit); // do nothing if rdx <= 0 aoqi@0: __ bind(loop); aoqi@0: __ push((int32_t)NULL_WORD); // initialize local variables aoqi@0: __ decrement(rdx); // until everything initialized aoqi@0: __ jcc(Assembler::greater, loop); aoqi@0: __ bind(exit); aoqi@0: } aoqi@0: aoqi@0: // initialize fixed part of activation frame aoqi@0: generate_fixed_frame(false); aoqi@0: aoqi@0: // make sure method is not native & not abstract aoqi@0: #ifdef ASSERT aoqi@0: __ movl(rax, access_flags); aoqi@0: { aoqi@0: Label L; aoqi@0: __ testl(rax, JVM_ACC_NATIVE); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: __ stop("tried to execute native method as non-native"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: { Label L; aoqi@0: __ testl(rax, JVM_ACC_ABSTRACT); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: __ stop("tried to execute abstract method in interpreter"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // Since at this point in the method invocation the exception handler aoqi@0: // would try to exit the monitor of synchronized methods which hasn't aoqi@0: // been entered yet, we set the thread local variable aoqi@0: // _do_not_unlock_if_synchronized to true. The remove_activation will aoqi@0: // check this flag. aoqi@0: aoqi@0: __ get_thread(rax); aoqi@0: const Address do_not_unlock_if_synchronized(rax, aoqi@0: in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); aoqi@0: __ movbool(do_not_unlock_if_synchronized, true); aoqi@0: aoqi@0: __ profile_parameters_type(rax, rcx, rdx); aoqi@0: // increment invocation count & check for overflow aoqi@0: Label invocation_counter_overflow; aoqi@0: Label profile_method; aoqi@0: Label profile_method_continue; aoqi@0: if (inc_counter) { aoqi@0: generate_counter_incr(&invocation_counter_overflow, &profile_method, &profile_method_continue); aoqi@0: if (ProfileInterpreter) { aoqi@0: __ bind(profile_method_continue); aoqi@0: } aoqi@0: } aoqi@0: Label continue_after_compile; aoqi@0: __ bind(continue_after_compile); aoqi@0: aoqi@0: bang_stack_shadow_pages(false); aoqi@0: aoqi@0: // reset the _do_not_unlock_if_synchronized flag aoqi@0: __ get_thread(rax); aoqi@0: __ movbool(do_not_unlock_if_synchronized, false); aoqi@0: aoqi@0: // check for synchronized methods aoqi@0: // Must happen AFTER invocation_counter check and stack overflow check, aoqi@0: // so method is not locked if overflows. aoqi@0: // aoqi@0: if (synchronized) { aoqi@0: // Allocate monitor and lock method aoqi@0: lock_method(); aoqi@0: } else { aoqi@0: // no synchronization necessary aoqi@0: #ifdef ASSERT aoqi@0: { Label L; aoqi@0: __ movl(rax, access_flags); aoqi@0: __ testl(rax, JVM_ACC_SYNCHRONIZED); aoqi@0: __ jcc(Assembler::zero, L); aoqi@0: __ stop("method needs synchronization"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: } aoqi@0: aoqi@0: // start execution aoqi@0: #ifdef ASSERT aoqi@0: { Label L; aoqi@0: const Address monitor_block_top (rbp, aoqi@0: frame::interpreter_frame_monitor_block_top_offset * wordSize); aoqi@0: __ movptr(rax, monitor_block_top); aoqi@0: __ cmpptr(rax, rsp); aoqi@0: __ jcc(Assembler::equal, L); aoqi@0: __ stop("broken stack frame setup in interpreter"); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif aoqi@0: aoqi@0: // jvmti support aoqi@0: __ notify_method_entry(); aoqi@0: aoqi@0: __ dispatch_next(vtos); aoqi@0: aoqi@0: // invocation counter overflow aoqi@0: if (inc_counter) { aoqi@0: if (ProfileInterpreter) { aoqi@0: // We have decided to profile this method in the interpreter aoqi@0: __ bind(profile_method); aoqi@0: __ call_VM(noreg, CAST_FROM_FN_PTR(address, InterpreterRuntime::profile_method)); aoqi@0: __ set_method_data_pointer_for_bcp(); aoqi@0: __ get_method(rbx); aoqi@0: __ jmp(profile_method_continue); aoqi@0: } aoqi@0: // Handle overflow of counter and compile method aoqi@0: __ bind(invocation_counter_overflow); aoqi@0: generate_counter_overflow(&continue_after_compile); aoqi@0: } aoqi@0: aoqi@0: return entry_point; aoqi@0: } aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Entry points aoqi@0: // aoqi@0: // Here we generate the various kind of entries into the interpreter. aoqi@0: // The two main entry type are generic bytecode methods and native call method. aoqi@0: // These both come in synchronized and non-synchronized versions but the aoqi@0: // frame layout they create is very similar. The other method entry aoqi@0: // types are really just special purpose entries that are really entry aoqi@0: // and interpretation all in one. These are for trivial methods like aoqi@0: // accessor, empty, or special math methods. aoqi@0: // aoqi@0: // When control flow reaches any of the entry types for the interpreter aoqi@0: // the following holds -> aoqi@0: // aoqi@0: // Arguments: aoqi@0: // aoqi@0: // rbx,: Method* aoqi@0: // rcx: receiver aoqi@0: // aoqi@0: // aoqi@0: // Stack layout immediately at entry aoqi@0: // aoqi@0: // [ return address ] <--- rsp aoqi@0: // [ parameter n ] aoqi@0: // ... aoqi@0: // [ parameter 1 ] aoqi@0: // [ expression stack ] (caller's java expression stack) aoqi@0: aoqi@0: // Assuming that we don't go to one of the trivial specialized aoqi@0: // entries the stack will look like below when we are ready to execute aoqi@0: // the first bytecode (or call the native routine). The register usage aoqi@0: // will be as the template based interpreter expects (see interpreter_x86.hpp). aoqi@0: // aoqi@0: // local variables follow incoming parameters immediately; i.e. aoqi@0: // the return address is moved to the end of the locals). aoqi@0: // aoqi@0: // [ monitor entry ] <--- rsp aoqi@0: // ... aoqi@0: // [ monitor entry ] aoqi@0: // [ expr. stack bottom ] aoqi@0: // [ saved rsi ] aoqi@0: // [ current rdi ] aoqi@0: // [ Method* ] aoqi@0: // [ saved rbp, ] <--- rbp, aoqi@0: // [ return address ] aoqi@0: // [ local variable m ] aoqi@0: // ... aoqi@0: // [ local variable 1 ] aoqi@0: // [ parameter n ] aoqi@0: // ... aoqi@0: // [ parameter 1 ] <--- rdi aoqi@0: aoqi@0: address AbstractInterpreterGenerator::generate_method_entry(AbstractInterpreter::MethodKind kind) { aoqi@0: // determine code generation flags aoqi@0: bool synchronized = false; aoqi@0: address entry_point = NULL; aoqi@0: InterpreterGenerator* ig_this = (InterpreterGenerator*)this; aoqi@0: aoqi@0: switch (kind) { aoqi@0: case Interpreter::zerolocals : break; aoqi@0: case Interpreter::zerolocals_synchronized: synchronized = true; break; aoqi@0: case Interpreter::native : entry_point = ig_this->generate_native_entry(false); break; aoqi@0: case Interpreter::native_synchronized : entry_point = ig_this->generate_native_entry(true); break; aoqi@0: case Interpreter::empty : entry_point = ig_this->generate_empty_entry(); break; aoqi@0: case Interpreter::accessor : entry_point = ig_this->generate_accessor_entry(); break; aoqi@0: case Interpreter::abstract : entry_point = ig_this->generate_abstract_entry(); break; aoqi@0: aoqi@0: case Interpreter::java_lang_math_sin : // fall thru aoqi@0: case Interpreter::java_lang_math_cos : // fall thru aoqi@0: case Interpreter::java_lang_math_tan : // fall thru aoqi@0: case Interpreter::java_lang_math_abs : // fall thru aoqi@0: case Interpreter::java_lang_math_log : // fall thru aoqi@0: case Interpreter::java_lang_math_log10 : // fall thru aoqi@0: case Interpreter::java_lang_math_sqrt : // fall thru aoqi@0: case Interpreter::java_lang_math_pow : // fall thru aoqi@0: case Interpreter::java_lang_math_exp : entry_point = ig_this->generate_math_entry(kind); break; aoqi@0: case Interpreter::java_lang_ref_reference_get aoqi@0: : entry_point = ig_this->generate_Reference_get_entry(); break; aoqi@0: case Interpreter::java_util_zip_CRC32_update aoqi@0: : entry_point = ig_this->generate_CRC32_update_entry(); break; aoqi@0: case Interpreter::java_util_zip_CRC32_updateBytes aoqi@0: : // fall thru aoqi@0: case Interpreter::java_util_zip_CRC32_updateByteBuffer aoqi@0: : entry_point = ig_this->generate_CRC32_updateBytes_entry(kind); break; aoqi@0: default: aoqi@0: fatal(err_msg("unexpected method kind: %d", kind)); aoqi@0: break; aoqi@0: } aoqi@0: aoqi@0: if (entry_point) return entry_point; aoqi@0: aoqi@0: return ig_this->generate_normal_entry(synchronized); aoqi@0: aoqi@0: } aoqi@0: aoqi@0: // These should never be compiled since the interpreter will prefer aoqi@0: // the compiled version to the intrinsic version. aoqi@0: bool AbstractInterpreter::can_be_compiled(methodHandle m) { aoqi@0: switch (method_kind(m)) { aoqi@0: case Interpreter::java_lang_math_sin : // fall thru aoqi@0: case Interpreter::java_lang_math_cos : // fall thru aoqi@0: case Interpreter::java_lang_math_tan : // fall thru aoqi@0: case Interpreter::java_lang_math_abs : // fall thru aoqi@0: case Interpreter::java_lang_math_log : // fall thru aoqi@0: case Interpreter::java_lang_math_log10 : // fall thru aoqi@0: case Interpreter::java_lang_math_sqrt : // fall thru aoqi@0: case Interpreter::java_lang_math_pow : // fall thru aoqi@0: case Interpreter::java_lang_math_exp : aoqi@0: return false; aoqi@0: default: aoqi@0: return true; aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: // How much stack a method activation needs in words. aoqi@0: int AbstractInterpreter::size_top_interpreter_activation(Method* method) { aoqi@0: aoqi@0: const int stub_code = 4; // see generate_call_stub aoqi@0: // Save space for one monitor to get into the interpreted method in case aoqi@0: // the method is synchronized aoqi@0: int monitor_size = method->is_synchronized() ? aoqi@0: 1*frame::interpreter_frame_monitor_size() : 0; aoqi@0: aoqi@0: // total overhead size: entry_size + (saved rbp, thru expr stack bottom). aoqi@0: // be sure to change this if you add/subtract anything to/from the overhead area aoqi@0: const int overhead_size = -frame::interpreter_frame_initial_sp_offset; aoqi@0: aoqi@0: const int method_stack = (method->max_locals() + method->max_stack()) * aoqi@0: Interpreter::stackElementWords; aoqi@0: return overhead_size + method_stack + stub_code; aoqi@0: } aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Exceptions aoqi@0: aoqi@0: void TemplateInterpreterGenerator::generate_throw_exception() { aoqi@0: // Entry point in previous activation (i.e., if the caller was interpreted) aoqi@0: Interpreter::_rethrow_exception_entry = __ pc(); aoqi@0: const Register thread = rcx; aoqi@0: aoqi@0: // Restore sp to interpreter_frame_last_sp even though we are going aoqi@0: // to empty the expression stack for the exception processing. aoqi@0: __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD); aoqi@0: // rax,: exception aoqi@0: // rdx: return address/pc that threw exception aoqi@0: __ restore_bcp(); // rsi points to call/send aoqi@0: __ restore_locals(); aoqi@0: aoqi@0: // Entry point for exceptions thrown within interpreter code aoqi@0: Interpreter::_throw_exception_entry = __ pc(); aoqi@0: // expression stack is undefined here aoqi@0: // rax,: exception aoqi@0: // rsi: exception bcp aoqi@0: __ verify_oop(rax); aoqi@0: aoqi@0: // expression stack must be empty before entering the VM in case of an exception aoqi@0: __ empty_expression_stack(); aoqi@0: __ empty_FPU_stack(); aoqi@0: // find exception handler address and preserve exception oop aoqi@0: __ call_VM(rdx, CAST_FROM_FN_PTR(address, InterpreterRuntime::exception_handler_for_exception), rax); aoqi@0: // rax,: exception handler entry point aoqi@0: // rdx: preserved exception oop aoqi@0: // rsi: bcp for exception handler aoqi@0: __ push_ptr(rdx); // push exception which is now the only value on the stack aoqi@0: __ jmp(rax); // jump to exception handler (may be _remove_activation_entry!) aoqi@0: aoqi@0: // If the exception is not handled in the current frame the frame is removed and aoqi@0: // the exception is rethrown (i.e. exception continuation is _rethrow_exception). aoqi@0: // aoqi@0: // Note: At this point the bci is still the bxi for the instruction which caused aoqi@0: // the exception and the expression stack is empty. Thus, for any VM calls aoqi@0: // at this point, GC will find a legal oop map (with empty expression stack). aoqi@0: aoqi@0: // In current activation aoqi@0: // tos: exception aoqi@0: // rsi: exception bcp aoqi@0: aoqi@0: // aoqi@0: // JVMTI PopFrame support aoqi@0: // aoqi@0: aoqi@0: Interpreter::_remove_activation_preserving_args_entry = __ pc(); aoqi@0: __ empty_expression_stack(); aoqi@0: __ empty_FPU_stack(); aoqi@0: // Set the popframe_processing bit in pending_popframe_condition indicating that we are aoqi@0: // currently handling popframe, so that call_VMs that may happen later do not trigger new aoqi@0: // popframe handling cycles. aoqi@0: __ get_thread(thread); aoqi@0: __ movl(rdx, Address(thread, JavaThread::popframe_condition_offset())); aoqi@0: __ orl(rdx, JavaThread::popframe_processing_bit); aoqi@0: __ movl(Address(thread, JavaThread::popframe_condition_offset()), rdx); aoqi@0: aoqi@0: { aoqi@0: // Check to see whether we are returning to a deoptimized frame. aoqi@0: // (The PopFrame call ensures that the caller of the popped frame is aoqi@0: // either interpreted or compiled and deoptimizes it if compiled.) aoqi@0: // In this case, we can't call dispatch_next() after the frame is aoqi@0: // popped, but instead must save the incoming arguments and restore aoqi@0: // them after deoptimization has occurred. aoqi@0: // aoqi@0: // Note that we don't compare the return PC against the aoqi@0: // deoptimization blob's unpack entry because of the presence of aoqi@0: // adapter frames in C2. aoqi@0: Label caller_not_deoptimized; aoqi@0: __ movptr(rdx, Address(rbp, frame::return_addr_offset * wordSize)); aoqi@0: __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::interpreter_contains), rdx); aoqi@0: __ testl(rax, rax); aoqi@0: __ jcc(Assembler::notZero, caller_not_deoptimized); aoqi@0: aoqi@0: // Compute size of arguments for saving when returning to deoptimized caller aoqi@0: __ get_method(rax); aoqi@0: __ movptr(rax, Address(rax, Method::const_offset())); aoqi@0: __ load_unsigned_short(rax, Address(rax, ConstMethod::size_of_parameters_offset())); aoqi@0: __ shlptr(rax, Interpreter::logStackElementSize); aoqi@0: __ restore_locals(); aoqi@0: __ subptr(rdi, rax); aoqi@0: __ addptr(rdi, wordSize); aoqi@0: // Save these arguments aoqi@0: __ get_thread(thread); aoqi@0: __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, Deoptimization::popframe_preserve_args), thread, rax, rdi); aoqi@0: aoqi@0: __ remove_activation(vtos, rdx, aoqi@0: /* throw_monitor_exception */ false, aoqi@0: /* install_monitor_exception */ false, aoqi@0: /* notify_jvmdi */ false); aoqi@0: aoqi@0: // Inform deoptimization that it is responsible for restoring these arguments aoqi@0: __ get_thread(thread); aoqi@0: __ movl(Address(thread, JavaThread::popframe_condition_offset()), JavaThread::popframe_force_deopt_reexecution_bit); aoqi@0: aoqi@0: // Continue in deoptimization handler aoqi@0: __ jmp(rdx); aoqi@0: aoqi@0: __ bind(caller_not_deoptimized); aoqi@0: } aoqi@0: aoqi@0: __ remove_activation(vtos, rdx, aoqi@0: /* throw_monitor_exception */ false, aoqi@0: /* install_monitor_exception */ false, aoqi@0: /* notify_jvmdi */ false); aoqi@0: aoqi@0: // Finish with popframe handling aoqi@0: // A previous I2C followed by a deoptimization might have moved the aoqi@0: // outgoing arguments further up the stack. PopFrame expects the aoqi@0: // mutations to those outgoing arguments to be preserved and other aoqi@0: // constraints basically require this frame to look exactly as aoqi@0: // though it had previously invoked an interpreted activation with aoqi@0: // no space between the top of the expression stack (current aoqi@0: // last_sp) and the top of stack. Rather than force deopt to aoqi@0: // maintain this kind of invariant all the time we call a small aoqi@0: // fixup routine to move the mutated arguments onto the top of our aoqi@0: // expression stack if necessary. aoqi@0: __ mov(rax, rsp); aoqi@0: __ movptr(rbx, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize)); aoqi@0: __ get_thread(thread); aoqi@0: // PC must point into interpreter here aoqi@0: __ set_last_Java_frame(thread, noreg, rbp, __ pc()); aoqi@0: __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::popframe_move_outgoing_args), thread, rax, rbx); aoqi@0: __ get_thread(thread); aoqi@0: __ reset_last_Java_frame(thread, true, true); aoqi@0: // Restore the last_sp and null it out aoqi@0: __ movptr(rsp, Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize)); aoqi@0: __ movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), NULL_WORD); aoqi@0: aoqi@0: __ restore_bcp(); aoqi@0: __ restore_locals(); aoqi@0: // The method data pointer was incremented already during aoqi@0: // call profiling. We have to restore the mdp for the current bcp. aoqi@0: if (ProfileInterpreter) { aoqi@0: __ set_method_data_pointer_for_bcp(); aoqi@0: } aoqi@0: aoqi@0: // Clear the popframe condition flag aoqi@0: __ get_thread(thread); aoqi@0: __ movl(Address(thread, JavaThread::popframe_condition_offset()), JavaThread::popframe_inactive); aoqi@0: aoqi@0: #if INCLUDE_JVMTI aoqi@0: if (EnableInvokeDynamic) { aoqi@0: Label L_done; aoqi@0: const Register local0 = rdi; aoqi@0: aoqi@0: __ cmpb(Address(rsi, 0), Bytecodes::_invokestatic); aoqi@0: __ jcc(Assembler::notEqual, L_done); aoqi@0: aoqi@0: // The member name argument must be restored if _invokestatic is re-executed after a PopFrame call. aoqi@0: // Detect such a case in the InterpreterRuntime function and return the member name argument, or NULL. aoqi@0: aoqi@0: __ get_method(rdx); aoqi@0: __ movptr(rax, Address(local0, 0)); aoqi@0: __ call_VM(rax, CAST_FROM_FN_PTR(address, InterpreterRuntime::member_name_arg_or_null), rax, rdx, rsi); aoqi@0: aoqi@0: __ testptr(rax, rax); aoqi@0: __ jcc(Assembler::zero, L_done); aoqi@0: aoqi@0: __ movptr(Address(rbx, 0), rax); aoqi@0: __ bind(L_done); aoqi@0: } aoqi@0: #endif // INCLUDE_JVMTI aoqi@0: aoqi@0: __ dispatch_next(vtos); aoqi@0: // end of PopFrame support aoqi@0: aoqi@0: Interpreter::_remove_activation_entry = __ pc(); aoqi@0: aoqi@0: // preserve exception over this code sequence aoqi@0: __ pop_ptr(rax); aoqi@0: __ get_thread(thread); aoqi@0: __ movptr(Address(thread, JavaThread::vm_result_offset()), rax); aoqi@0: // remove the activation (without doing throws on illegalMonitorExceptions) aoqi@0: __ remove_activation(vtos, rdx, false, true, false); aoqi@0: // restore exception aoqi@0: __ get_thread(thread); aoqi@0: __ get_vm_result(rax, thread); aoqi@0: aoqi@0: // Inbetween activations - previous activation type unknown yet aoqi@0: // compute continuation point - the continuation point expects aoqi@0: // the following registers set up: aoqi@0: // aoqi@0: // rax: exception aoqi@0: // rdx: return address/pc that threw exception aoqi@0: // rsp: expression stack of caller aoqi@0: // rbp: rbp, of caller aoqi@0: __ push(rax); // save exception aoqi@0: __ push(rdx); // save return address aoqi@0: __ super_call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::exception_handler_for_return_address), thread, rdx); aoqi@0: __ mov(rbx, rax); // save exception handler aoqi@0: __ pop(rdx); // restore return address aoqi@0: __ pop(rax); // restore exception aoqi@0: // Note that an "issuing PC" is actually the next PC after the call aoqi@0: __ jmp(rbx); // jump to exception handler of caller aoqi@0: } aoqi@0: aoqi@0: aoqi@0: // aoqi@0: // JVMTI ForceEarlyReturn support aoqi@0: // aoqi@0: address TemplateInterpreterGenerator::generate_earlyret_entry_for(TosState state) { aoqi@0: address entry = __ pc(); aoqi@0: const Register thread = rcx; aoqi@0: aoqi@0: __ restore_bcp(); aoqi@0: __ restore_locals(); aoqi@0: __ empty_expression_stack(); aoqi@0: __ empty_FPU_stack(); aoqi@0: __ load_earlyret_value(state); aoqi@0: aoqi@0: __ get_thread(thread); aoqi@0: __ movptr(rcx, Address(thread, JavaThread::jvmti_thread_state_offset())); aoqi@0: const Address cond_addr(rcx, JvmtiThreadState::earlyret_state_offset()); aoqi@0: aoqi@0: // Clear the earlyret state aoqi@0: __ movl(cond_addr, JvmtiThreadState::earlyret_inactive); aoqi@0: aoqi@0: __ remove_activation(state, rsi, aoqi@0: false, /* throw_monitor_exception */ aoqi@0: false, /* install_monitor_exception */ aoqi@0: true); /* notify_jvmdi */ aoqi@0: __ jmp(rsi); aoqi@0: return entry; aoqi@0: } // end of ForceEarlyReturn support aoqi@0: aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Helper for vtos entry point generation aoqi@0: aoqi@0: 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) { aoqi@0: assert(t->is_valid() && t->tos_in() == vtos, "illegal template"); aoqi@0: Label L; aoqi@0: fep = __ pc(); __ push(ftos); __ jmp(L); aoqi@0: dep = __ pc(); __ push(dtos); __ jmp(L); aoqi@0: lep = __ pc(); __ push(ltos); __ jmp(L); aoqi@0: aep = __ pc(); __ push(atos); __ jmp(L); aoqi@0: bep = cep = sep = // fall through aoqi@0: iep = __ pc(); __ push(itos); // fall through aoqi@0: vep = __ pc(); __ bind(L); // fall through aoqi@0: generate_and_dispatch(t); aoqi@0: } aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: // Generation of individual instructions aoqi@0: aoqi@0: // helpers for generate_and_dispatch aoqi@0: aoqi@0: aoqi@0: aoqi@0: InterpreterGenerator::InterpreterGenerator(StubQueue* code) aoqi@0: : TemplateInterpreterGenerator(code) { aoqi@0: generate_all(); // down here so it can be "virtual" aoqi@0: } aoqi@0: aoqi@0: //------------------------------------------------------------------------------------------------------------------------ aoqi@0: aoqi@0: // Non-product code aoqi@0: #ifndef PRODUCT aoqi@0: address TemplateInterpreterGenerator::generate_trace_code(TosState state) { aoqi@0: address entry = __ pc(); aoqi@0: aoqi@0: // prepare expression stack aoqi@0: __ pop(rcx); // pop return address so expression stack is 'pure' aoqi@0: __ push(state); // save tosca aoqi@0: aoqi@0: // pass tosca registers as arguments & call tracer aoqi@0: __ call_VM(noreg, CAST_FROM_FN_PTR(address, SharedRuntime::trace_bytecode), rcx, rax, rdx); aoqi@0: __ mov(rcx, rax); // make sure return address is not destroyed by pop(state) aoqi@0: __ pop(state); // restore tosca aoqi@0: aoqi@0: // return aoqi@0: __ jmp(rcx); aoqi@0: aoqi@0: return entry; aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void TemplateInterpreterGenerator::count_bytecode() { aoqi@0: __ incrementl(ExternalAddress((address) &BytecodeCounter::_counter_value)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void TemplateInterpreterGenerator::histogram_bytecode(Template* t) { aoqi@0: __ incrementl(ExternalAddress((address) &BytecodeHistogram::_counters[t->bytecode()])); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void TemplateInterpreterGenerator::histogram_bytecode_pair(Template* t) { aoqi@0: __ mov32(ExternalAddress((address) &BytecodePairHistogram::_index), rbx); aoqi@0: __ shrl(rbx, BytecodePairHistogram::log2_number_of_codes); aoqi@0: __ orl(rbx, ((int)t->bytecode()) << BytecodePairHistogram::log2_number_of_codes); aoqi@0: ExternalAddress table((address) BytecodePairHistogram::_counters); aoqi@0: Address index(noreg, rbx, Address::times_4); aoqi@0: __ incrementl(ArrayAddress(table, index)); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void TemplateInterpreterGenerator::trace_bytecode(Template* t) { aoqi@0: // Call a little run-time stub to avoid blow-up for each bytecode. aoqi@0: // The run-time runtime saves the right registers, depending on aoqi@0: // the tosca in-state for the given template. aoqi@0: assert(Interpreter::trace_code(t->tos_in()) != NULL, aoqi@0: "entry must have been generated"); aoqi@0: __ call(RuntimeAddress(Interpreter::trace_code(t->tos_in()))); aoqi@0: } aoqi@0: aoqi@0: aoqi@0: void TemplateInterpreterGenerator::stop_interpreter_at() { aoqi@0: Label L; aoqi@0: __ cmp32(ExternalAddress((address) &BytecodeCounter::_counter_value), aoqi@0: StopInterpreterAt); aoqi@0: __ jcc(Assembler::notEqual, L); aoqi@0: __ int3(); aoqi@0: __ bind(L); aoqi@0: } aoqi@0: #endif // !PRODUCT aoqi@0: #endif // CC_INTERP