duke@435: /* trims@1907: * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved. duke@435: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@435: * duke@435: * This code is free software; you can redistribute it and/or modify it duke@435: * under the terms of the GNU General Public License version 2 only, as duke@435: * published by the Free Software Foundation. duke@435: * duke@435: * This code is distributed in the hope that it will be useful, but WITHOUT duke@435: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@435: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@435: * version 2 for more details (a copy is included in the LICENSE file that duke@435: * accompanied this code). duke@435: * duke@435: * You should have received a copy of the GNU General Public License version duke@435: * 2 along with this work; if not, write to the Free Software Foundation, duke@435: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@435: * trims@1907: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA trims@1907: * or visit www.oracle.com if you need additional information or have any trims@1907: * questions. duke@435: * duke@435: */ duke@435: stefank@2314: #include "precompiled.hpp" stefank@2314: #include "interp_masm_x86_64.hpp" stefank@2314: #include "interpreter/interpreter.hpp" stefank@2314: #include "interpreter/interpreterRuntime.hpp" stefank@2314: #include "oops/arrayOop.hpp" stefank@2314: #include "oops/markOop.hpp" stefank@2314: #include "oops/methodDataOop.hpp" stefank@2314: #include "oops/methodOop.hpp" stefank@2314: #include "prims/jvmtiExport.hpp" stefank@2314: #include "prims/jvmtiRedefineClassesTrace.hpp" stefank@2314: #include "prims/jvmtiThreadState.hpp" stefank@2314: #include "runtime/basicLock.hpp" stefank@2314: #include "runtime/biasedLocking.hpp" stefank@2314: #include "runtime/sharedRuntime.hpp" stefank@2314: #ifdef TARGET_OS_FAMILY_linux stefank@2314: # include "thread_linux.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_solaris stefank@2314: # include "thread_solaris.inline.hpp" stefank@2314: #endif stefank@2314: #ifdef TARGET_OS_FAMILY_windows stefank@2314: # include "thread_windows.inline.hpp" stefank@2314: #endif duke@435: duke@435: duke@435: // Implementation of InterpreterMacroAssembler duke@435: never@739: #ifdef CC_INTERP never@739: void InterpreterMacroAssembler::get_method(Register reg) { coleenp@955: movptr(reg, Address(rbp, -((int)sizeof(BytecodeInterpreter) + 2 * wordSize))); never@739: movptr(reg, Address(reg, byte_offset_of(BytecodeInterpreter, _method))); never@739: } never@739: #endif // CC_INTERP never@739: never@739: #ifndef CC_INTERP never@739: duke@435: void InterpreterMacroAssembler::call_VM_leaf_base(address entry_point, duke@435: int number_of_arguments) { duke@435: // interpreter specific duke@435: // duke@435: // Note: No need to save/restore bcp & locals (r13 & r14) pointer duke@435: // since these are callee saved registers and no blocking/ duke@435: // GC can happen in leaf calls. ysr@777: // Further Note: DO NOT save/restore bcp/locals. If a caller has ysr@777: // already saved them so that it can use esi/edi as temporaries ysr@777: // then a save/restore here will DESTROY the copy the caller ysr@777: // saved! There used to be a save_bcp() that only happened in ysr@777: // the ASSERT path (no restore_bcp). Which caused bizarre failures ysr@777: // when jvm built with ASSERTs. duke@435: #ifdef ASSERT duke@435: { duke@435: Label L; never@739: cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); duke@435: jcc(Assembler::equal, L); duke@435: stop("InterpreterMacroAssembler::call_VM_leaf_base:" duke@435: " last_sp != NULL"); duke@435: bind(L); duke@435: } duke@435: #endif duke@435: // super call duke@435: MacroAssembler::call_VM_leaf_base(entry_point, number_of_arguments); duke@435: // interpreter specific ysr@777: // Used to ASSERT that r13/r14 were equal to frame's bcp/locals ysr@777: // but since they may not have been saved (and we don't want to ysr@777: // save thme here (see note above) the assert is invalid. duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::call_VM_base(Register oop_result, duke@435: Register java_thread, duke@435: Register last_java_sp, duke@435: address entry_point, duke@435: int number_of_arguments, duke@435: bool check_exceptions) { duke@435: // interpreter specific duke@435: // duke@435: // Note: Could avoid restoring locals ptr (callee saved) - however doesn't duke@435: // really make a difference for these runtime calls, since they are duke@435: // slow anyway. Btw., bcp must be saved/restored since it may change duke@435: // due to GC. duke@435: // assert(java_thread == noreg , "not expecting a precomputed java thread"); duke@435: save_bcp(); duke@435: #ifdef ASSERT duke@435: { duke@435: Label L; never@739: cmpptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), (int32_t)NULL_WORD); duke@435: jcc(Assembler::equal, L); duke@435: stop("InterpreterMacroAssembler::call_VM_leaf_base:" duke@435: " last_sp != NULL"); duke@435: bind(L); duke@435: } duke@435: #endif /* ASSERT */ duke@435: // super call duke@435: MacroAssembler::call_VM_base(oop_result, noreg, last_java_sp, duke@435: entry_point, number_of_arguments, duke@435: check_exceptions); duke@435: // interpreter specific duke@435: restore_bcp(); duke@435: restore_locals(); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::check_and_handle_popframe(Register java_thread) { duke@435: if (JvmtiExport::can_pop_frame()) { duke@435: Label L; duke@435: // Initiate popframe handling only if it is not already being duke@435: // processed. If the flag has the popframe_processing bit set, it duke@435: // means that this code is called *during* popframe handling - we duke@435: // don't want to reenter. duke@435: // This method is only called just after the call into the vm in duke@435: // call_VM_base, so the arg registers are available. duke@435: movl(c_rarg0, Address(r15_thread, JavaThread::popframe_condition_offset())); duke@435: testl(c_rarg0, JavaThread::popframe_pending_bit); duke@435: jcc(Assembler::zero, L); duke@435: testl(c_rarg0, JavaThread::popframe_processing_bit); duke@435: jcc(Assembler::notZero, L); duke@435: // Call Interpreter::remove_activation_preserving_args_entry() to get the duke@435: // address of the same-named entrypoint in the generated interpreter code. duke@435: call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_preserving_args_entry)); duke@435: jmp(rax); duke@435: bind(L); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::load_earlyret_value(TosState state) { never@739: movptr(rcx, Address(r15_thread, JavaThread::jvmti_thread_state_offset())); duke@435: const Address tos_addr(rcx, JvmtiThreadState::earlyret_tos_offset()); duke@435: const Address oop_addr(rcx, JvmtiThreadState::earlyret_oop_offset()); duke@435: const Address val_addr(rcx, JvmtiThreadState::earlyret_value_offset()); duke@435: switch (state) { never@739: case atos: movptr(rax, oop_addr); never@739: movptr(oop_addr, (int32_t)NULL_WORD); duke@435: verify_oop(rax, state); break; never@739: case ltos: movptr(rax, val_addr); break; duke@435: case btos: // fall through duke@435: case ctos: // fall through duke@435: case stos: // fall through duke@435: case itos: movl(rax, val_addr); break; duke@435: case ftos: movflt(xmm0, val_addr); break; duke@435: case dtos: movdbl(xmm0, val_addr); break; duke@435: case vtos: /* nothing to do */ break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: // Clean up tos value in the thread object duke@435: movl(tos_addr, (int) ilgl); never@739: movl(val_addr, (int32_t) NULL_WORD); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::check_and_handle_earlyret(Register java_thread) { duke@435: if (JvmtiExport::can_force_early_return()) { duke@435: Label L; never@739: movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset())); never@739: testptr(c_rarg0, c_rarg0); duke@435: jcc(Assembler::zero, L); // if (thread->jvmti_thread_state() == NULL) exit; duke@435: duke@435: // Initiate earlyret handling only if it is not already being processed. duke@435: // If the flag has the earlyret_processing bit set, it means that this code duke@435: // is called *during* earlyret handling - we don't want to reenter. duke@435: movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_state_offset())); duke@435: cmpl(c_rarg0, JvmtiThreadState::earlyret_pending); duke@435: jcc(Assembler::notEqual, L); duke@435: duke@435: // Call Interpreter::remove_activation_early_entry() to get the address of the duke@435: // same-named entrypoint in the generated interpreter code. never@739: movptr(c_rarg0, Address(r15_thread, JavaThread::jvmti_thread_state_offset())); duke@435: movl(c_rarg0, Address(c_rarg0, JvmtiThreadState::earlyret_tos_offset())); duke@435: call_VM_leaf(CAST_FROM_FN_PTR(address, Interpreter::remove_activation_early_entry), c_rarg0); duke@435: jmp(rax); duke@435: bind(L); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_unsigned_2_byte_index_at_bcp( duke@435: Register reg, duke@435: int bcp_offset) { duke@435: assert(bcp_offset >= 0, "bcp is still pointing to start of bytecode"); duke@435: movl(reg, Address(r13, bcp_offset)); duke@435: bswapl(reg); duke@435: shrl(reg, 16); duke@435: } duke@435: duke@435: twisti@1543: void InterpreterMacroAssembler::get_cache_index_at_bcp(Register index, twisti@1543: int bcp_offset, jrose@1920: size_t index_size) { twisti@1543: assert(bcp_offset > 0, "bcp is still pointing to start of bytecode"); jrose@1920: if (index_size == sizeof(u2)) { twisti@1543: load_unsigned_short(index, Address(r13, bcp_offset)); jrose@1920: } else if (index_size == sizeof(u4)) { twisti@1543: assert(EnableInvokeDynamic, "giant index used only for EnableInvokeDynamic"); twisti@1543: movl(index, Address(r13, bcp_offset)); twisti@1543: // Check if the secondary index definition is still ~x, otherwise twisti@1543: // we have to change the following assembler code to calculate the twisti@1543: // plain index. twisti@1543: assert(constantPoolCacheOopDesc::decode_secondary_index(~123) == 123, "else change next line"); twisti@1543: notl(index); // convert to plain index jrose@1920: } else if (index_size == sizeof(u1)) { jrose@1920: assert(EnableMethodHandles, "tiny index used only for EnableMethodHandles"); jrose@1920: load_unsigned_byte(index, Address(r13, bcp_offset)); jrose@1920: } else { jrose@1920: ShouldNotReachHere(); twisti@1543: } twisti@1543: } twisti@1543: twisti@1543: duke@435: void InterpreterMacroAssembler::get_cache_and_index_at_bcp(Register cache, duke@435: Register index, twisti@1543: int bcp_offset, jrose@1920: size_t index_size) { duke@435: assert(cache != index, "must use different registers"); jrose@1920: get_cache_index_at_bcp(index, bcp_offset, index_size); never@739: movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); duke@435: assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below"); duke@435: // convert from field index to ConstantPoolCacheEntry index duke@435: shll(index, 2); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::get_cache_entry_pointer_at_bcp(Register cache, duke@435: Register tmp, twisti@1543: int bcp_offset, jrose@1920: size_t index_size) { duke@435: assert(cache != tmp, "must use different register"); jrose@1920: get_cache_index_at_bcp(tmp, bcp_offset, index_size); duke@435: assert(sizeof(ConstantPoolCacheEntry) == 4 * wordSize, "adjust code below"); duke@435: // convert from field index to ConstantPoolCacheEntry index duke@435: // and from word offset to byte offset duke@435: shll(tmp, 2 + LogBytesPerWord); never@739: movptr(cache, Address(rbp, frame::interpreter_frame_cache_offset * wordSize)); duke@435: // skip past the header never@739: addptr(cache, in_bytes(constantPoolCacheOopDesc::base_offset())); never@739: addptr(cache, tmp); // construct pointer to cache entry duke@435: } duke@435: duke@435: duke@435: // Generate a subtype check: branch to ok_is_subtype if sub_klass is a duke@435: // subtype of super_klass. duke@435: // duke@435: // Args: duke@435: // rax: superklass duke@435: // Rsub_klass: subklass duke@435: // duke@435: // Kills: duke@435: // rcx, rdi duke@435: void InterpreterMacroAssembler::gen_subtype_check(Register Rsub_klass, duke@435: Label& ok_is_subtype) { duke@435: assert(Rsub_klass != rax, "rax holds superklass"); duke@435: assert(Rsub_klass != r14, "r14 holds locals"); duke@435: assert(Rsub_klass != r13, "r13 holds bcp"); duke@435: assert(Rsub_klass != rcx, "rcx holds 2ndary super array length"); duke@435: assert(Rsub_klass != rdi, "rdi holds 2ndary super array scan ptr"); duke@435: jrose@1079: // Profile the not-null value's klass. jrose@1079: profile_typecheck(rcx, Rsub_klass, rdi); // blows rcx, reloads rdi duke@435: jrose@1079: // Do the check. jrose@1079: check_klass_subtype(Rsub_klass, rax, rcx, ok_is_subtype); // blows rcx duke@435: jrose@1079: // Profile the failure of the check. duke@435: profile_typecheck_failed(rcx); // blows rcx duke@435: } duke@435: duke@435: never@739: duke@435: // Java Expression Stack duke@435: duke@435: void InterpreterMacroAssembler::pop_ptr(Register r) { never@739: pop(r); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::pop_i(Register r) { never@739: // XXX can't use pop currently, upper half non clean duke@435: movl(r, Address(rsp, 0)); never@739: addptr(rsp, wordSize); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::pop_l(Register r) { duke@435: movq(r, Address(rsp, 0)); twisti@1861: addptr(rsp, 2 * Interpreter::stackElementSize); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::pop_f(XMMRegister r) { duke@435: movflt(r, Address(rsp, 0)); never@739: addptr(rsp, wordSize); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::pop_d(XMMRegister r) { duke@435: movdbl(r, Address(rsp, 0)); twisti@1861: addptr(rsp, 2 * Interpreter::stackElementSize); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push_ptr(Register r) { never@739: push(r); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push_i(Register r) { never@739: push(r); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push_l(Register r) { twisti@1861: subptr(rsp, 2 * wordSize); duke@435: movq(Address(rsp, 0), r); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push_f(XMMRegister r) { never@739: subptr(rsp, wordSize); duke@435: movflt(Address(rsp, 0), r); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push_d(XMMRegister r) { twisti@1861: subptr(rsp, 2 * wordSize); duke@435: movdbl(Address(rsp, 0), r); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::pop(TosState state) { duke@435: switch (state) { duke@435: case atos: pop_ptr(); break; duke@435: case btos: duke@435: case ctos: duke@435: case stos: duke@435: case itos: pop_i(); break; duke@435: case ltos: pop_l(); break; duke@435: case ftos: pop_f(); break; duke@435: case dtos: pop_d(); break; duke@435: case vtos: /* nothing to do */ break; duke@435: default: ShouldNotReachHere(); duke@435: } duke@435: verify_oop(rax, state); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::push(TosState state) { duke@435: verify_oop(rax, state); duke@435: switch (state) { duke@435: case atos: push_ptr(); break; duke@435: case btos: duke@435: case ctos: duke@435: case stos: duke@435: case itos: push_i(); break; duke@435: case ltos: push_l(); break; duke@435: case ftos: push_f(); break; duke@435: case dtos: push_d(); break; duke@435: case vtos: /* nothing to do */ break; duke@435: default : ShouldNotReachHere(); duke@435: } duke@435: } duke@435: duke@435: twisti@1861: // Helpers for swap and dup twisti@1861: void InterpreterMacroAssembler::load_ptr(int n, Register val) { never@739: movptr(val, Address(rsp, Interpreter::expr_offset_in_bytes(n))); duke@435: } duke@435: twisti@1861: void InterpreterMacroAssembler::store_ptr(int n, Register val) { never@739: movptr(Address(rsp, Interpreter::expr_offset_in_bytes(n)), val); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point) { duke@435: MacroAssembler::call_VM_leaf_base(entry_point, 0); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, duke@435: Register arg_1) { duke@435: if (c_rarg0 != arg_1) { never@739: mov(c_rarg0, arg_1); duke@435: } duke@435: MacroAssembler::call_VM_leaf_base(entry_point, 1); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, duke@435: Register arg_1, duke@435: Register arg_2) { duke@435: assert(c_rarg0 != arg_2, "smashed argument"); duke@435: assert(c_rarg1 != arg_1, "smashed argument"); duke@435: if (c_rarg0 != arg_1) { never@739: mov(c_rarg0, arg_1); duke@435: } duke@435: if (c_rarg1 != arg_2) { never@739: mov(c_rarg1, arg_2); duke@435: } duke@435: MacroAssembler::call_VM_leaf_base(entry_point, 2); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::super_call_VM_leaf(address entry_point, duke@435: Register arg_1, duke@435: Register arg_2, duke@435: Register arg_3) { duke@435: assert(c_rarg0 != arg_2, "smashed argument"); duke@435: assert(c_rarg0 != arg_3, "smashed argument"); duke@435: assert(c_rarg1 != arg_1, "smashed argument"); duke@435: assert(c_rarg1 != arg_3, "smashed argument"); duke@435: assert(c_rarg2 != arg_1, "smashed argument"); duke@435: assert(c_rarg2 != arg_2, "smashed argument"); duke@435: if (c_rarg0 != arg_1) { never@739: mov(c_rarg0, arg_1); duke@435: } duke@435: if (c_rarg1 != arg_2) { never@739: mov(c_rarg1, arg_2); duke@435: } duke@435: if (c_rarg2 != arg_3) { never@739: mov(c_rarg2, arg_3); duke@435: } duke@435: MacroAssembler::call_VM_leaf_base(entry_point, 3); duke@435: } duke@435: jrose@1145: void InterpreterMacroAssembler::prepare_to_jump_from_interpreted() { duke@435: // set sender sp never@739: lea(r13, Address(rsp, wordSize)); duke@435: // record last_sp never@739: movptr(Address(rbp, frame::interpreter_frame_last_sp_offset * wordSize), r13); jrose@1145: } jrose@1145: jrose@1145: jrose@1145: // Jump to from_interpreted entry of a call unless single stepping is possible jrose@1145: // in this thread in which case we must call the i2i entry jrose@1145: void InterpreterMacroAssembler::jump_from_interpreted(Register method, Register temp) { jrose@1145: prepare_to_jump_from_interpreted(); duke@435: duke@435: if (JvmtiExport::can_post_interpreter_events()) { duke@435: Label run_compiled_code; duke@435: // JVMTI events, such as single-stepping, are implemented partly by avoiding running duke@435: // compiled code in threads for which the event is enabled. Check here for duke@435: // interp_only_mode if these events CAN be enabled. duke@435: get_thread(temp); duke@435: // interp_only is an int, on little endian it is sufficient to test the byte only duke@435: // Is a cmpl faster (ce duke@435: cmpb(Address(temp, JavaThread::interp_only_mode_offset()), 0); duke@435: jcc(Assembler::zero, run_compiled_code); duke@435: jmp(Address(method, methodOopDesc::interpreter_entry_offset())); duke@435: bind(run_compiled_code); duke@435: } duke@435: duke@435: jmp(Address(method, methodOopDesc::from_interpreted_offset())); duke@435: duke@435: } duke@435: duke@435: duke@435: // The following two routines provide a hook so that an implementation duke@435: // can schedule the dispatch in two parts. amd64 does not do this. duke@435: void InterpreterMacroAssembler::dispatch_prolog(TosState state, int step) { duke@435: // Nothing amd64 specific to be done here duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::dispatch_epilog(TosState state, int step) { duke@435: dispatch_next(state, step); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::dispatch_base(TosState state, duke@435: address* table, duke@435: bool verifyoop) { duke@435: verify_FPU(1, state); duke@435: if (VerifyActivationFrameSize) { duke@435: Label L; never@739: mov(rcx, rbp); never@739: subptr(rcx, rsp); never@739: int32_t min_frame_size = duke@435: (frame::link_offset - frame::interpreter_frame_initial_sp_offset) * duke@435: wordSize; never@739: cmpptr(rcx, (int32_t)min_frame_size); duke@435: jcc(Assembler::greaterEqual, L); duke@435: stop("broken stack frame"); duke@435: bind(L); duke@435: } duke@435: if (verifyoop) { duke@435: verify_oop(rax, state); duke@435: } duke@435: lea(rscratch1, ExternalAddress((address)table)); duke@435: jmp(Address(rscratch1, rbx, Address::times_8)); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::dispatch_only(TosState state) { duke@435: dispatch_base(state, Interpreter::dispatch_table(state)); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::dispatch_only_normal(TosState state) { duke@435: dispatch_base(state, Interpreter::normal_table(state)); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::dispatch_only_noverify(TosState state) { duke@435: dispatch_base(state, Interpreter::normal_table(state), false); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::dispatch_next(TosState state, int step) { duke@435: // load next bytecode (load before advancing r13 to prevent AGI) duke@435: load_unsigned_byte(rbx, Address(r13, step)); duke@435: // advance r13 never@739: increment(r13, step); duke@435: dispatch_base(state, Interpreter::dispatch_table(state)); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::dispatch_via(TosState state, address* table) { duke@435: // load current bytecode duke@435: load_unsigned_byte(rbx, Address(r13, 0)); duke@435: dispatch_base(state, table); duke@435: } duke@435: duke@435: // remove activation duke@435: // duke@435: // Unlock the receiver if this is a synchronized method. duke@435: // Unlock any Java monitors from syncronized blocks. duke@435: // Remove the activation from the stack. duke@435: // duke@435: // If there are locked Java monitors duke@435: // If throw_monitor_exception duke@435: // throws IllegalMonitorStateException duke@435: // Else if install_monitor_exception duke@435: // installs IllegalMonitorStateException duke@435: // Else duke@435: // no error processing duke@435: void InterpreterMacroAssembler::remove_activation( duke@435: TosState state, duke@435: Register ret_addr, duke@435: bool throw_monitor_exception, duke@435: bool install_monitor_exception, duke@435: bool notify_jvmdi) { duke@435: // Note: Registers rdx xmm0 may be in use for the duke@435: // result check if synchronized method duke@435: Label unlocked, unlock, no_unlock; duke@435: duke@435: // get the value of _do_not_unlock_if_synchronized into rdx duke@435: const Address do_not_unlock_if_synchronized(r15_thread, duke@435: in_bytes(JavaThread::do_not_unlock_if_synchronized_offset())); duke@435: movbool(rdx, do_not_unlock_if_synchronized); duke@435: movbool(do_not_unlock_if_synchronized, false); // reset the flag duke@435: duke@435: // get method access flags never@739: movptr(rbx, Address(rbp, frame::interpreter_frame_method_offset * wordSize)); duke@435: movl(rcx, Address(rbx, methodOopDesc::access_flags_offset())); duke@435: testl(rcx, JVM_ACC_SYNCHRONIZED); duke@435: jcc(Assembler::zero, unlocked); duke@435: duke@435: // Don't unlock anything if the _do_not_unlock_if_synchronized flag duke@435: // is set. duke@435: testbool(rdx); duke@435: jcc(Assembler::notZero, no_unlock); duke@435: duke@435: // unlock monitor duke@435: push(state); // save result duke@435: duke@435: // BasicObjectLock will be first in list, since this is a duke@435: // synchronized method. However, need to check that the object has duke@435: // not been unlocked by an explicit monitorexit bytecode. duke@435: const Address monitor(rbp, frame::interpreter_frame_initial_sp_offset * duke@435: wordSize - (int) sizeof(BasicObjectLock)); duke@435: // We use c_rarg1 so that if we go slow path it will be the correct duke@435: // register for unlock_object to pass to VM directly never@739: lea(c_rarg1, monitor); // address of first monitor duke@435: never@739: movptr(rax, Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes())); never@739: testptr(rax, rax); duke@435: jcc(Assembler::notZero, unlock); duke@435: duke@435: pop(state); duke@435: if (throw_monitor_exception) { duke@435: // Entry already unlocked, need to throw exception duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, duke@435: InterpreterRuntime::throw_illegal_monitor_state_exception)); duke@435: should_not_reach_here(); duke@435: } else { duke@435: // Monitor already unlocked during a stack unroll. If requested, duke@435: // install an illegal_monitor_state_exception. Continue with duke@435: // stack unrolling. duke@435: if (install_monitor_exception) { duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, duke@435: InterpreterRuntime::new_illegal_monitor_state_exception)); duke@435: } duke@435: jmp(unlocked); duke@435: } duke@435: duke@435: bind(unlock); duke@435: unlock_object(c_rarg1); duke@435: pop(state); duke@435: duke@435: // Check that for block-structured locking (i.e., that all locked duke@435: // objects has been unlocked) duke@435: bind(unlocked); duke@435: duke@435: // rax: Might contain return value duke@435: duke@435: // Check that all monitors are unlocked duke@435: { duke@435: Label loop, exception, entry, restart; duke@435: const int entry_size = frame::interpreter_frame_monitor_size() * wordSize; duke@435: const Address monitor_block_top( duke@435: rbp, frame::interpreter_frame_monitor_block_top_offset * wordSize); duke@435: const Address monitor_block_bot( duke@435: rbp, frame::interpreter_frame_initial_sp_offset * wordSize); duke@435: duke@435: bind(restart); duke@435: // We use c_rarg1 so that if we go slow path it will be the correct duke@435: // register for unlock_object to pass to VM directly never@739: movptr(c_rarg1, monitor_block_top); // points to current entry, starting duke@435: // with top-most entry never@739: lea(rbx, monitor_block_bot); // points to word before bottom of duke@435: // monitor block duke@435: jmp(entry); duke@435: duke@435: // Entry already locked, need to throw exception duke@435: bind(exception); duke@435: duke@435: if (throw_monitor_exception) { duke@435: // Throw exception duke@435: MacroAssembler::call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, InterpreterRuntime:: duke@435: throw_illegal_monitor_state_exception)); duke@435: should_not_reach_here(); duke@435: } else { duke@435: // Stack unrolling. Unlock object and install illegal_monitor_exception. duke@435: // Unlock does not block, so don't have to worry about the frame. duke@435: // We don't have to preserve c_rarg1 since we are going to throw an exception. duke@435: duke@435: push(state); duke@435: unlock_object(c_rarg1); duke@435: pop(state); duke@435: duke@435: if (install_monitor_exception) { duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, duke@435: InterpreterRuntime:: duke@435: new_illegal_monitor_state_exception)); duke@435: } duke@435: duke@435: jmp(restart); duke@435: } duke@435: duke@435: bind(loop); duke@435: // check if current entry is used never@739: cmpptr(Address(c_rarg1, BasicObjectLock::obj_offset_in_bytes()), (int32_t) NULL); duke@435: jcc(Assembler::notEqual, exception); duke@435: never@739: addptr(c_rarg1, entry_size); // otherwise advance to next entry duke@435: bind(entry); never@739: cmpptr(c_rarg1, rbx); // check if bottom reached duke@435: jcc(Assembler::notEqual, loop); // if not at bottom then check this entry duke@435: } duke@435: duke@435: bind(no_unlock); duke@435: duke@435: // jvmti support duke@435: if (notify_jvmdi) { duke@435: notify_method_exit(state, NotifyJVMTI); // preserve TOSCA duke@435: } else { duke@435: notify_method_exit(state, SkipNotifyJVMTI); // preserve TOSCA duke@435: } duke@435: duke@435: // remove activation duke@435: // get sender sp never@739: movptr(rbx, never@739: Address(rbp, frame::interpreter_frame_sender_sp_offset * wordSize)); duke@435: leave(); // remove frame anchor never@739: pop(ret_addr); // get return address never@739: mov(rsp, rbx); // set sp to sender sp duke@435: } duke@435: never@739: #endif // C_INTERP never@739: duke@435: // Lock object duke@435: // duke@435: // Args: duke@435: // c_rarg1: BasicObjectLock to be used for locking duke@435: // duke@435: // Kills: duke@435: // rax duke@435: // c_rarg0, c_rarg1, c_rarg2, c_rarg3, .. (param regs) duke@435: // rscratch1, rscratch2 (scratch regs) duke@435: void InterpreterMacroAssembler::lock_object(Register lock_reg) { duke@435: assert(lock_reg == c_rarg1, "The argument is only for looks. It must be c_rarg1"); duke@435: duke@435: if (UseHeavyMonitors) { duke@435: call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), duke@435: lock_reg); duke@435: } else { duke@435: Label done; duke@435: duke@435: const Register swap_reg = rax; // Must use rax for cmpxchg instruction duke@435: const Register obj_reg = c_rarg3; // Will contain the oop duke@435: duke@435: const int obj_offset = BasicObjectLock::obj_offset_in_bytes(); duke@435: const int lock_offset = BasicObjectLock::lock_offset_in_bytes (); duke@435: const int mark_offset = lock_offset + duke@435: BasicLock::displaced_header_offset_in_bytes(); duke@435: duke@435: Label slow_case; duke@435: duke@435: // Load object pointer into obj_reg %c_rarg3 never@739: movptr(obj_reg, Address(lock_reg, obj_offset)); duke@435: duke@435: if (UseBiasedLocking) { duke@435: biased_locking_enter(lock_reg, obj_reg, swap_reg, rscratch1, false, done, &slow_case); duke@435: } duke@435: duke@435: // Load immediate 1 into swap_reg %rax duke@435: movl(swap_reg, 1); duke@435: duke@435: // Load (object->mark() | 1) into swap_reg %rax never@739: orptr(swap_reg, Address(obj_reg, 0)); duke@435: duke@435: // Save (object->mark() | 1) into BasicLock's displaced header never@739: movptr(Address(lock_reg, mark_offset), swap_reg); duke@435: duke@435: assert(lock_offset == 0, duke@435: "displached header must be first word in BasicObjectLock"); duke@435: duke@435: if (os::is_MP()) lock(); never@739: cmpxchgptr(lock_reg, Address(obj_reg, 0)); duke@435: if (PrintBiasedLockingStatistics) { duke@435: cond_inc32(Assembler::zero, duke@435: ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); duke@435: } duke@435: jcc(Assembler::zero, done); duke@435: duke@435: // Test if the oopMark is an obvious stack pointer, i.e., duke@435: // 1) (mark & 7) == 0, and duke@435: // 2) rsp <= mark < mark + os::pagesize() duke@435: // duke@435: // These 3 tests can be done by evaluating the following duke@435: // expression: ((mark - rsp) & (7 - os::vm_page_size())), duke@435: // assuming both stack pointer and pagesize have their duke@435: // least significant 3 bits clear. duke@435: // NOTE: the oopMark is in swap_reg %rax as the result of cmpxchg never@739: subptr(swap_reg, rsp); never@739: andptr(swap_reg, 7 - os::vm_page_size()); duke@435: duke@435: // Save the test result, for recursive case, the result is zero never@739: movptr(Address(lock_reg, mark_offset), swap_reg); duke@435: duke@435: if (PrintBiasedLockingStatistics) { duke@435: cond_inc32(Assembler::zero, duke@435: ExternalAddress((address) BiasedLocking::fast_path_entry_count_addr())); duke@435: } duke@435: jcc(Assembler::zero, done); duke@435: duke@435: bind(slow_case); duke@435: duke@435: // Call the runtime routine for slow case duke@435: call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorenter), duke@435: lock_reg); duke@435: duke@435: bind(done); duke@435: } duke@435: } duke@435: duke@435: duke@435: // Unlocks an object. Used in monitorexit bytecode and duke@435: // remove_activation. Throws an IllegalMonitorException if object is duke@435: // not locked by current thread. duke@435: // duke@435: // Args: duke@435: // c_rarg1: BasicObjectLock for lock duke@435: // duke@435: // Kills: duke@435: // rax duke@435: // c_rarg0, c_rarg1, c_rarg2, c_rarg3, ... (param regs) duke@435: // rscratch1, rscratch2 (scratch regs) duke@435: void InterpreterMacroAssembler::unlock_object(Register lock_reg) { duke@435: assert(lock_reg == c_rarg1, "The argument is only for looks. It must be rarg1"); duke@435: duke@435: if (UseHeavyMonitors) { duke@435: call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), duke@435: lock_reg); duke@435: } else { duke@435: Label done; duke@435: duke@435: const Register swap_reg = rax; // Must use rax for cmpxchg instruction duke@435: const Register header_reg = c_rarg2; // Will contain the old oopMark duke@435: const Register obj_reg = c_rarg3; // Will contain the oop duke@435: duke@435: save_bcp(); // Save in case of exception duke@435: duke@435: // Convert from BasicObjectLock structure to object and BasicLock duke@435: // structure Store the BasicLock address into %rax never@739: lea(swap_reg, Address(lock_reg, BasicObjectLock::lock_offset_in_bytes())); duke@435: duke@435: // Load oop into obj_reg(%c_rarg3) never@739: movptr(obj_reg, Address(lock_reg, BasicObjectLock::obj_offset_in_bytes())); duke@435: duke@435: // Free entry never@739: movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), (int32_t)NULL_WORD); duke@435: duke@435: if (UseBiasedLocking) { duke@435: biased_locking_exit(obj_reg, header_reg, done); duke@435: } duke@435: duke@435: // Load the old header from BasicLock structure never@739: movptr(header_reg, Address(swap_reg, never@739: BasicLock::displaced_header_offset_in_bytes())); duke@435: duke@435: // Test for recursion never@739: testptr(header_reg, header_reg); duke@435: duke@435: // zero for recursive case duke@435: jcc(Assembler::zero, done); duke@435: duke@435: // Atomic swap back the old header duke@435: if (os::is_MP()) lock(); never@739: cmpxchgptr(header_reg, Address(obj_reg, 0)); duke@435: duke@435: // zero for recursive case duke@435: jcc(Assembler::zero, done); duke@435: duke@435: // Call the runtime routine for slow case. never@739: movptr(Address(lock_reg, BasicObjectLock::obj_offset_in_bytes()), duke@435: obj_reg); // restore obj duke@435: call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, InterpreterRuntime::monitorexit), duke@435: lock_reg); duke@435: duke@435: bind(done); duke@435: duke@435: restore_bcp(); duke@435: } duke@435: } duke@435: never@739: #ifndef CC_INTERP duke@435: duke@435: void InterpreterMacroAssembler::test_method_data_pointer(Register mdp, duke@435: Label& zero_continue) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); never@739: movptr(mdp, Address(rbp, frame::interpreter_frame_mdx_offset * wordSize)); never@739: testptr(mdp, mdp); duke@435: jcc(Assembler::zero, zero_continue); duke@435: } duke@435: duke@435: duke@435: // Set the method data pointer for the current bcp. duke@435: void InterpreterMacroAssembler::set_method_data_pointer_for_bcp() { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: Label zero_continue; never@739: push(rax); never@739: push(rbx); duke@435: duke@435: get_method(rbx); duke@435: // Test MDO to avoid the call if it is NULL. never@739: movptr(rax, Address(rbx, in_bytes(methodOopDesc::method_data_offset()))); never@739: testptr(rax, rax); duke@435: jcc(Assembler::zero, zero_continue); duke@435: duke@435: // rbx: method duke@435: // r13: bcp duke@435: call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::bcp_to_di), rbx, r13); duke@435: // rax: mdi duke@435: never@739: movptr(rbx, Address(rbx, in_bytes(methodOopDesc::method_data_offset()))); never@739: testptr(rbx, rbx); duke@435: jcc(Assembler::zero, zero_continue); never@739: addptr(rbx, in_bytes(methodDataOopDesc::data_offset())); never@739: addptr(rbx, rax); never@739: movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), rbx); duke@435: duke@435: bind(zero_continue); never@739: pop(rbx); never@739: pop(rax); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::verify_method_data_pointer() { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: #ifdef ASSERT duke@435: Label verify_continue; never@739: push(rax); never@739: push(rbx); never@739: push(c_rarg3); never@739: push(c_rarg2); duke@435: test_method_data_pointer(c_rarg3, verify_continue); // If mdp is zero, continue duke@435: get_method(rbx); duke@435: duke@435: // If the mdp is valid, it will point to a DataLayout header which is duke@435: // consistent with the bcp. The converse is highly probable also. jrose@1057: load_unsigned_short(c_rarg2, jrose@1057: Address(c_rarg3, in_bytes(DataLayout::bci_offset()))); never@739: addptr(c_rarg2, Address(rbx, methodOopDesc::const_offset())); never@739: lea(c_rarg2, Address(c_rarg2, constMethodOopDesc::codes_offset())); never@739: cmpptr(c_rarg2, r13); duke@435: jcc(Assembler::equal, verify_continue); duke@435: // rbx: method duke@435: // r13: bcp duke@435: // c_rarg3: mdp duke@435: call_VM_leaf(CAST_FROM_FN_PTR(address, InterpreterRuntime::verify_mdp), duke@435: rbx, r13, c_rarg3); duke@435: bind(verify_continue); never@739: pop(c_rarg2); never@739: pop(c_rarg3); never@739: pop(rbx); never@739: pop(rax); duke@435: #endif // ASSERT duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::set_mdp_data_at(Register mdp_in, duke@435: int constant, duke@435: Register value) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: Address data(mdp_in, constant); never@739: movptr(data, value); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, duke@435: int constant, duke@435: bool decrement) { duke@435: // Counter address duke@435: Address data(mdp_in, constant); duke@435: duke@435: increment_mdp_data_at(data, decrement); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::increment_mdp_data_at(Address data, duke@435: bool decrement) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); never@739: // %%% this does 64bit counters at best it is wasting space never@739: // at worst it is a rare bug when counters overflow duke@435: duke@435: if (decrement) { duke@435: // Decrement the register. Set condition codes. never@739: addptr(data, (int32_t) -DataLayout::counter_increment); duke@435: // If the decrement causes the counter to overflow, stay negative duke@435: Label L; duke@435: jcc(Assembler::negative, L); never@739: addptr(data, (int32_t) DataLayout::counter_increment); duke@435: bind(L); duke@435: } else { duke@435: assert(DataLayout::counter_increment == 1, duke@435: "flow-free idiom only works with 1"); duke@435: // Increment the register. Set carry flag. never@739: addptr(data, DataLayout::counter_increment); duke@435: // If the increment causes the counter to overflow, pull back by 1. never@739: sbbptr(data, (int32_t)0); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::increment_mdp_data_at(Register mdp_in, duke@435: Register reg, duke@435: int constant, duke@435: bool decrement) { duke@435: Address data(mdp_in, reg, Address::times_1, constant); duke@435: duke@435: increment_mdp_data_at(data, decrement); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::set_mdp_flag_at(Register mdp_in, duke@435: int flag_byte_constant) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: int header_offset = in_bytes(DataLayout::header_offset()); duke@435: int header_bits = DataLayout::flag_mask_to_header_mask(flag_byte_constant); duke@435: // Set the flag duke@435: orl(Address(mdp_in, header_offset), header_bits); duke@435: } duke@435: duke@435: duke@435: duke@435: void InterpreterMacroAssembler::test_mdp_data_at(Register mdp_in, duke@435: int offset, duke@435: Register value, duke@435: Register test_value_out, duke@435: Label& not_equal_continue) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: if (test_value_out == noreg) { never@739: cmpptr(value, Address(mdp_in, offset)); duke@435: } else { duke@435: // Put the test value into a register, so caller can use it: never@739: movptr(test_value_out, Address(mdp_in, offset)); never@739: cmpptr(test_value_out, value); duke@435: } duke@435: jcc(Assembler::notEqual, not_equal_continue); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, duke@435: int offset_of_disp) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: Address disp_address(mdp_in, offset_of_disp); never@739: addptr(mdp_in, disp_address); never@739: movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::update_mdp_by_offset(Register mdp_in, duke@435: Register reg, duke@435: int offset_of_disp) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); duke@435: Address disp_address(mdp_in, reg, Address::times_1, offset_of_disp); never@739: addptr(mdp_in, disp_address); never@739: movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::update_mdp_by_constant(Register mdp_in, duke@435: int constant) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); never@739: addptr(mdp_in, constant); never@739: movptr(Address(rbp, frame::interpreter_frame_mdx_offset * wordSize), mdp_in); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::update_mdp_for_ret(Register return_bci) { duke@435: assert(ProfileInterpreter, "must be profiling interpreter"); never@739: push(return_bci); // save/restore across call_VM duke@435: call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, InterpreterRuntime::update_mdp_for_ret), duke@435: return_bci); never@739: pop(return_bci); duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_taken_branch(Register mdp, duke@435: Register bumped_count) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: // Otherwise, assign to mdp duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: // We are taking a branch. Increment the taken count. duke@435: // We inline increment_mdp_data_at to return bumped_count in a register duke@435: //increment_mdp_data_at(mdp, in_bytes(JumpData::taken_offset())); duke@435: Address data(mdp, in_bytes(JumpData::taken_offset())); never@739: movptr(bumped_count, data); duke@435: assert(DataLayout::counter_increment == 1, duke@435: "flow-free idiom only works with 1"); never@739: addptr(bumped_count, DataLayout::counter_increment); never@739: sbbptr(bumped_count, 0); never@739: movptr(data, bumped_count); // Store back out duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_offset(mdp, in_bytes(JumpData::displacement_offset())); duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_not_taken_branch(Register mdp) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: // We are taking a branch. Increment the not taken count. duke@435: increment_mdp_data_at(mdp, in_bytes(BranchData::not_taken_offset())); duke@435: duke@435: // The method data pointer needs to be updated to correspond to duke@435: // the next bytecode duke@435: update_mdp_by_constant(mdp, in_bytes(BranchData::branch_data_size())); duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_call(Register mdp) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: // We are making a call. Increment the count. duke@435: increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_constant(mdp, in_bytes(CounterData::counter_data_size())); duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_final_call(Register mdp) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: // We are making a call. Increment the count. duke@435: increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_constant(mdp, duke@435: in_bytes(VirtualCallData:: duke@435: virtual_call_data_size())); duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_virtual_call(Register receiver, duke@435: Register mdp, twisti@1543: Register reg2, twisti@1543: bool receiver_can_be_null) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: twisti@1543: Label skip_receiver_profile; twisti@1543: if (receiver_can_be_null) { kvn@1641: Label not_null; twisti@1543: testptr(receiver, receiver); kvn@1641: jccb(Assembler::notZero, not_null); kvn@1641: // We are making a call. Increment the count for null receiver. kvn@1641: increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); kvn@1641: jmp(skip_receiver_profile); kvn@1641: bind(not_null); twisti@1543: } twisti@1543: duke@435: // Record the receiver type. kvn@1641: record_klass_in_profile(receiver, mdp, reg2, true); twisti@1543: bind(skip_receiver_profile); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_constant(mdp, duke@435: in_bytes(VirtualCallData:: duke@435: virtual_call_data_size())); duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: // This routine creates a state machine for updating the multi-row duke@435: // type profile at a virtual call site (or other type-sensitive bytecode). duke@435: // The machine visits each row (of receiver/count) until the receiver type duke@435: // is found, or until it runs out of rows. At the same time, it remembers duke@435: // the location of the first empty row. (An empty row records null for its duke@435: // receiver, and can be allocated for a newly-observed receiver type.) duke@435: // Because there are two degrees of freedom in the state, a simple linear duke@435: // search will not work; it must be a decision tree. Hence this helper duke@435: // function is recursive, to generate the required tree structured code. duke@435: // It's the interpreter, so we are trading off code space for speed. duke@435: // See below for example code. duke@435: void InterpreterMacroAssembler::record_klass_in_profile_helper( duke@435: Register receiver, Register mdp, kvn@1641: Register reg2, int start_row, kvn@1641: Label& done, bool is_virtual_call) { kvn@1641: if (TypeProfileWidth == 0) { kvn@1641: if (is_virtual_call) { kvn@1641: increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); kvn@1641: } poonam@1402: return; kvn@1641: } poonam@1402: duke@435: int last_row = VirtualCallData::row_limit() - 1; duke@435: assert(start_row <= last_row, "must be work left to do"); duke@435: // Test this row for both the receiver and for null. duke@435: // Take any of three different outcomes: duke@435: // 1. found receiver => increment count and goto done duke@435: // 2. found null => keep looking for case 1, maybe allocate this cell duke@435: // 3. found something else => keep looking for cases 1 and 2 duke@435: // Case 3 is handled by a recursive call. duke@435: for (int row = start_row; row <= last_row; row++) { duke@435: Label next_test; duke@435: bool test_for_null_also = (row == start_row); duke@435: duke@435: // See if the receiver is receiver[n]. duke@435: int recvr_offset = in_bytes(VirtualCallData::receiver_offset(row)); duke@435: test_mdp_data_at(mdp, recvr_offset, receiver, duke@435: (test_for_null_also ? reg2 : noreg), duke@435: next_test); duke@435: // (Reg2 now contains the receiver from the CallData.) duke@435: duke@435: // The receiver is receiver[n]. Increment count[n]. duke@435: int count_offset = in_bytes(VirtualCallData::receiver_count_offset(row)); duke@435: increment_mdp_data_at(mdp, count_offset); duke@435: jmp(done); duke@435: bind(next_test); duke@435: duke@435: if (test_for_null_also) { kvn@1641: Label found_null; duke@435: // Failed the equality check on receiver[n]... Test for null. never@739: testptr(reg2, reg2); duke@435: if (start_row == last_row) { duke@435: // The only thing left to do is handle the null case. kvn@1641: if (is_virtual_call) { kvn@1641: jccb(Assembler::zero, found_null); kvn@1641: // Receiver did not match any saved receiver and there is no empty row for it. kvn@1686: // Increment total counter to indicate polymorphic case. kvn@1641: increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); kvn@1641: jmp(done); kvn@1641: bind(found_null); kvn@1641: } else { kvn@1641: jcc(Assembler::notZero, done); kvn@1641: } duke@435: break; duke@435: } duke@435: // Since null is rare, make it be the branch-taken case. duke@435: jcc(Assembler::zero, found_null); duke@435: duke@435: // Put all the "Case 3" tests here. kvn@1641: record_klass_in_profile_helper(receiver, mdp, reg2, start_row + 1, done, is_virtual_call); duke@435: duke@435: // Found a null. Keep searching for a matching receiver, duke@435: // but remember that this is an empty (unused) slot. duke@435: bind(found_null); duke@435: } duke@435: } duke@435: duke@435: // In the fall-through case, we found no matching receiver, but we duke@435: // observed the receiver[start_row] is NULL. duke@435: duke@435: // Fill in the receiver field and increment the count. duke@435: int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row)); duke@435: set_mdp_data_at(mdp, recvr_offset, receiver); duke@435: int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row)); duke@435: movl(reg2, DataLayout::counter_increment); duke@435: set_mdp_data_at(mdp, count_offset, reg2); kvn@1641: if (start_row > 0) { kvn@1641: jmp(done); kvn@1641: } duke@435: } duke@435: duke@435: // Example state machine code for three profile rows: duke@435: // // main copy of decision tree, rooted at row[1] duke@435: // if (row[0].rec == rec) { row[0].incr(); goto done; } duke@435: // if (row[0].rec != NULL) { duke@435: // // inner copy of decision tree, rooted at row[1] duke@435: // if (row[1].rec == rec) { row[1].incr(); goto done; } duke@435: // if (row[1].rec != NULL) { duke@435: // // degenerate decision tree, rooted at row[2] duke@435: // if (row[2].rec == rec) { row[2].incr(); goto done; } kvn@1641: // if (row[2].rec != NULL) { count.incr(); goto done; } // overflow duke@435: // row[2].init(rec); goto done; duke@435: // } else { duke@435: // // remember row[1] is empty duke@435: // if (row[2].rec == rec) { row[2].incr(); goto done; } duke@435: // row[1].init(rec); goto done; duke@435: // } duke@435: // } else { duke@435: // // remember row[0] is empty duke@435: // if (row[1].rec == rec) { row[1].incr(); goto done; } duke@435: // if (row[2].rec == rec) { row[2].incr(); goto done; } duke@435: // row[0].init(rec); goto done; duke@435: // } kvn@1641: // done: duke@435: duke@435: void InterpreterMacroAssembler::record_klass_in_profile(Register receiver, kvn@1641: Register mdp, Register reg2, kvn@1641: bool is_virtual_call) { duke@435: assert(ProfileInterpreter, "must be profiling"); duke@435: Label done; duke@435: kvn@1641: record_klass_in_profile_helper(receiver, mdp, reg2, 0, done, is_virtual_call); duke@435: duke@435: bind (done); duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::profile_ret(Register return_bci, duke@435: Register mdp) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: uint row; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: // Update the total ret count. duke@435: increment_mdp_data_at(mdp, in_bytes(CounterData::count_offset())); duke@435: duke@435: for (row = 0; row < RetData::row_limit(); row++) { duke@435: Label next_test; duke@435: duke@435: // See if return_bci is equal to bci[n]: duke@435: test_mdp_data_at(mdp, duke@435: in_bytes(RetData::bci_offset(row)), duke@435: return_bci, noreg, duke@435: next_test); duke@435: duke@435: // return_bci is equal to bci[n]. Increment the count. duke@435: increment_mdp_data_at(mdp, in_bytes(RetData::bci_count_offset(row))); duke@435: duke@435: // The method data pointer needs to be updated to reflect the new target. duke@435: update_mdp_by_offset(mdp, duke@435: in_bytes(RetData::bci_displacement_offset(row))); duke@435: jmp(profile_continue); duke@435: bind(next_test); duke@435: } duke@435: duke@435: update_mdp_for_ret(return_bci); duke@435: duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_null_seen(Register mdp) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: never@1261: set_mdp_flag_at(mdp, BitData::null_seen_byte_constant()); never@1261: duke@435: // The method data pointer needs to be updated. duke@435: int mdp_delta = in_bytes(BitData::bit_data_size()); duke@435: if (TypeProfileCasts) { duke@435: mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); duke@435: } duke@435: update_mdp_by_constant(mdp, mdp_delta); duke@435: duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_typecheck_failed(Register mdp) { duke@435: if (ProfileInterpreter && TypeProfileCasts) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: int count_offset = in_bytes(CounterData::count_offset()); duke@435: // Back up the address, since we have already bumped the mdp. duke@435: count_offset -= in_bytes(VirtualCallData::virtual_call_data_size()); duke@435: duke@435: // *Decrement* the counter. We expect to see zero or small negatives. duke@435: increment_mdp_data_at(mdp, count_offset, true); duke@435: duke@435: bind (profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_typecheck(Register mdp, Register klass, Register reg2) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: // The method data pointer needs to be updated. duke@435: int mdp_delta = in_bytes(BitData::bit_data_size()); duke@435: if (TypeProfileCasts) { duke@435: mdp_delta = in_bytes(VirtualCallData::virtual_call_data_size()); duke@435: duke@435: // Record the object type. kvn@1641: record_klass_in_profile(klass, mdp, reg2, false); duke@435: } duke@435: update_mdp_by_constant(mdp, mdp_delta); duke@435: duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_switch_default(Register mdp) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: // Update the default case count duke@435: increment_mdp_data_at(mdp, duke@435: in_bytes(MultiBranchData::default_count_offset())); duke@435: duke@435: // The method data pointer needs to be updated. duke@435: update_mdp_by_offset(mdp, duke@435: in_bytes(MultiBranchData:: duke@435: default_displacement_offset())); duke@435: duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::profile_switch_case(Register index, duke@435: Register mdp, duke@435: Register reg2) { duke@435: if (ProfileInterpreter) { duke@435: Label profile_continue; duke@435: duke@435: // If no method data exists, go to profile_continue. duke@435: test_method_data_pointer(mdp, profile_continue); duke@435: duke@435: // Build the base (index * per_case_size_in_bytes()) + duke@435: // case_array_offset_in_bytes() duke@435: movl(reg2, in_bytes(MultiBranchData::per_case_size())); never@739: imulptr(index, reg2); // XXX l ? never@739: addptr(index, in_bytes(MultiBranchData::case_array_offset())); // XXX l ? duke@435: duke@435: // Update the case count duke@435: increment_mdp_data_at(mdp, duke@435: index, duke@435: in_bytes(MultiBranchData::relative_count_offset())); duke@435: duke@435: // The method data pointer needs to be updated. duke@435: update_mdp_by_offset(mdp, duke@435: index, duke@435: in_bytes(MultiBranchData:: duke@435: relative_displacement_offset())); duke@435: duke@435: bind(profile_continue); duke@435: } duke@435: } duke@435: duke@435: never@739: duke@435: void InterpreterMacroAssembler::verify_oop(Register reg, TosState state) { duke@435: if (state == atos) { duke@435: MacroAssembler::verify_oop(reg); duke@435: } duke@435: } duke@435: duke@435: void InterpreterMacroAssembler::verify_FPU(int stack_depth, TosState state) { duke@435: } never@739: #endif // !CC_INTERP duke@435: duke@435: duke@435: void InterpreterMacroAssembler::notify_method_entry() { duke@435: // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to duke@435: // track stack depth. If it is possible to enter interp_only_mode we add duke@435: // the code to check if the event should be sent. duke@435: if (JvmtiExport::can_post_interpreter_events()) { duke@435: Label L; duke@435: movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset())); duke@435: testl(rdx, rdx); duke@435: jcc(Assembler::zero, L); duke@435: call_VM(noreg, CAST_FROM_FN_PTR(address, duke@435: InterpreterRuntime::post_method_entry)); duke@435: bind(L); duke@435: } duke@435: duke@435: { duke@435: SkipIfEqual skip(this, &DTraceMethodProbes, false); duke@435: get_method(c_rarg1); duke@435: call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_entry), duke@435: r15_thread, c_rarg1); duke@435: } dcubed@1045: dcubed@1045: // RedefineClasses() tracing support for obsolete method entry dcubed@1045: if (RC_TRACE_IN_RANGE(0x00001000, 0x00002000)) { dcubed@1045: get_method(c_rarg1); dcubed@1045: call_VM_leaf( dcubed@1045: CAST_FROM_FN_PTR(address, SharedRuntime::rc_trace_method_entry), dcubed@1045: r15_thread, c_rarg1); dcubed@1045: } duke@435: } duke@435: duke@435: duke@435: void InterpreterMacroAssembler::notify_method_exit( duke@435: TosState state, NotifyMethodExitMode mode) { duke@435: // Whenever JVMTI is interp_only_mode, method entry/exit events are sent to duke@435: // track stack depth. If it is possible to enter interp_only_mode we add duke@435: // the code to check if the event should be sent. duke@435: if (mode == NotifyJVMTI && JvmtiExport::can_post_interpreter_events()) { duke@435: Label L; duke@435: // Note: frame::interpreter_frame_result has a dependency on how the duke@435: // method result is saved across the call to post_method_exit. If this duke@435: // is changed then the interpreter_frame_result implementation will duke@435: // need to be updated too. never@739: never@739: // For c++ interpreter the result is always stored at a known location in the frame never@739: // template interpreter will leave it on the top of the stack. never@739: NOT_CC_INTERP(push(state);) duke@435: movl(rdx, Address(r15_thread, JavaThread::interp_only_mode_offset())); duke@435: testl(rdx, rdx); duke@435: jcc(Assembler::zero, L); duke@435: call_VM(noreg, duke@435: CAST_FROM_FN_PTR(address, InterpreterRuntime::post_method_exit)); duke@435: bind(L); never@739: NOT_CC_INTERP(pop(state)); duke@435: } duke@435: duke@435: { duke@435: SkipIfEqual skip(this, &DTraceMethodProbes, false); never@739: NOT_CC_INTERP(push(state)); duke@435: get_method(c_rarg1); duke@435: call_VM_leaf(CAST_FROM_FN_PTR(address, SharedRuntime::dtrace_method_exit), duke@435: r15_thread, c_rarg1); never@739: NOT_CC_INTERP(pop(state)); duke@435: } duke@435: } iveresov@2138: iveresov@2138: // Jump if ((*counter_addr += increment) & mask) satisfies the condition. iveresov@2138: void InterpreterMacroAssembler::increment_mask_and_jump(Address counter_addr, iveresov@2138: int increment, int mask, iveresov@2138: Register scratch, bool preloaded, iveresov@2138: Condition cond, Label* where) { iveresov@2138: if (!preloaded) { iveresov@2138: movl(scratch, counter_addr); iveresov@2138: } iveresov@2138: incrementl(scratch, increment); iveresov@2138: movl(counter_addr, scratch); iveresov@2138: andl(scratch, mask); iveresov@2138: jcc(cond, *where); iveresov@2138: }