dlong@5000: /* drchase@6680: * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. dlong@5000: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. dlong@5000: * dlong@5000: * This code is free software; you can redistribute it and/or modify it dlong@5000: * under the terms of the GNU General Public License version 2 only, as dlong@5000: * published by the Free Software Foundation. dlong@5000: * dlong@5000: * This code is distributed in the hope that it will be useful, but WITHOUT dlong@5000: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or dlong@5000: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License dlong@5000: * version 2 for more details (a copy is included in the LICENSE file that dlong@5000: * accompanied this code). dlong@5000: * dlong@5000: * You should have received a copy of the GNU General Public License version dlong@5000: * 2 along with this work; if not, write to the Free Software Foundation, dlong@5000: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. dlong@5000: * dlong@5000: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA dlong@5000: * or visit www.oracle.com if you need additional information or have any dlong@5000: * questions. dlong@5000: * dlong@5000: */ dlong@5000: dlong@5000: #include "precompiled.hpp" dlong@5000: #include "asm/macroAssembler.inline.hpp" dlong@5000: #include "code/compiledIC.hpp" dlong@5000: #include "code/icBuffer.hpp" dlong@5000: #include "code/nmethod.hpp" dlong@5000: #include "memory/resourceArea.hpp" dlong@5000: #include "runtime/mutexLocker.hpp" dlong@5000: #include "runtime/safepoint.hpp" dlong@5000: dlong@5000: // Release the CompiledICHolder* associated with this call site is there is one. dlong@5000: void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site) { dlong@5000: // This call site might have become stale so inspect it carefully. dlong@5000: NativeCall* call = nativeCall_at(call_site->addr()); dlong@5000: if (is_icholder_entry(call->destination())) { dlong@5000: NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value()); dlong@5000: InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data()); dlong@5000: } dlong@5000: } dlong@5000: dlong@5000: bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site) { dlong@5000: // This call site might have become stale so inspect it carefully. dlong@5000: NativeCall* call = nativeCall_at(call_site->addr()); dlong@5000: return is_icholder_entry(call->destination()); dlong@5000: } dlong@5000: dlong@5000: // ---------------------------------------------------------------------------- dlong@5000: dlong@5000: #define __ _masm. vkempik@8427: address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf) { dlong@5000: // Stub is fixed up when the corresponding call is converted from dlong@5000: // calling compiled code to calling interpreted code. dlong@5000: // movq rbx, 0 dlong@5000: // jmp -5 # to self dlong@5000: dlong@5000: address mark = cbuf.insts_mark(); // Get mark within main instrs section. dlong@5000: dlong@5000: // Note that the code buffer's insts_mark is always relative to insts. dlong@5000: // That's why we must use the macroassembler to generate a stub. dlong@5000: MacroAssembler _masm(&cbuf); dlong@5000: vkempik@8427: address base = __ start_a_stub(to_interp_stub_size()); vkempik@8427: if (base == NULL) { vkempik@8427: return NULL; // CodeBuffer::expand failed. vkempik@8427: } dlong@5000: // Static stub relocation stores the instruction address of the call. dlong@5000: __ relocate(static_stub_Relocation::spec(mark), Assembler::imm_operand); dlong@5000: // Static stub relocation also tags the Method* in the code-stream. dlong@5000: __ mov_metadata(rbx, (Metadata*) NULL); // Method is zapped till fixup time. dlong@5000: // This is recognized as unresolved by relocs/nativeinst/ic code. dlong@5000: __ jump(RuntimeAddress(__ pc())); dlong@5000: dlong@5000: // Update current stubs pointer and restore insts_end. dlong@5000: __ end_a_stub(); vkempik@8427: return base; dlong@5000: } dlong@5000: #undef __ dlong@5000: dlong@5000: int CompiledStaticCall::to_interp_stub_size() { dlong@5000: return NOT_LP64(10) // movl; jmp dlong@5000: LP64_ONLY(15); // movq (1+1+8); jmp (1+4) dlong@5000: } dlong@5000: dlong@5000: // Relocation entries for call stub, compiled java to interpreter. dlong@5000: int CompiledStaticCall::reloc_to_interp_stub() { dlong@5000: return 4; // 3 in emit_to_interp_stub + 1 in emit_call dlong@5000: } dlong@5000: dlong@5000: void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) { dlong@5000: address stub = find_stub(); dlong@5000: guarantee(stub != NULL, "stub not found"); dlong@5000: dlong@5000: if (TraceICs) { dlong@5000: ResourceMark rm; dlong@5000: tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s", drchase@6680: p2i(instruction_address()), dlong@5000: callee->name_and_sig_as_C_string()); dlong@5000: } dlong@5000: dlong@5000: // Creation also verifies the object. dlong@5000: NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); dlong@5000: NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); dlong@5000: dlong@5000: assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(), dlong@5000: "a) MT-unsafe modification of inline cache"); dlong@5000: assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry, dlong@5000: "b) MT-unsafe modification of inline cache"); dlong@5000: dlong@5000: // Update stub. dlong@5000: method_holder->set_data((intptr_t)callee()); dlong@5000: jump->set_jump_destination(entry); dlong@5000: dlong@5000: // Update jump to call. dlong@5000: set_destination_mt_safe(stub); dlong@5000: } dlong@5000: dlong@5000: void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) { dlong@5000: assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call"); dlong@5000: // Reset stub. dlong@5000: address stub = static_stub->addr(); dlong@5000: assert(stub != NULL, "stub not found"); dlong@5000: // Creation also verifies the object. dlong@5000: NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); dlong@5000: NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); dlong@5000: method_holder->set_data(0); dlong@5000: jump->set_jump_destination((address)-1); dlong@5000: } dlong@5000: dlong@5000: //----------------------------------------------------------------------------- dlong@5000: // Non-product mode code dlong@5000: #ifndef PRODUCT dlong@5000: dlong@5000: void CompiledStaticCall::verify() { dlong@5000: // Verify call. dlong@5000: NativeCall::verify(); dlong@5000: if (os::is_MP()) { dlong@5000: verify_alignment(); dlong@5000: } dlong@5000: dlong@5000: // Verify stub. dlong@5000: address stub = find_stub(); dlong@5000: assert(stub != NULL, "no stub found for static call"); dlong@5000: // Creation also verifies the object. dlong@5000: NativeMovConstReg* method_holder = nativeMovConstReg_at(stub); dlong@5000: NativeJump* jump = nativeJump_at(method_holder->next_instruction_address()); dlong@5000: dlong@5000: // Verify state. dlong@5000: assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check"); dlong@5000: } dlong@5000: dlong@5000: #endif // !PRODUCT