Path: blob/master/src/hotspot/cpu/x86/compiledIC_x86.cpp
41145 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#include "precompiled.hpp"25#include "asm/macroAssembler.inline.hpp"26#include "code/codeCache.hpp"27#include "code/compiledIC.hpp"28#include "code/icBuffer.hpp"29#include "code/nmethod.hpp"30#include "memory/resourceArea.hpp"31#include "runtime/mutexLocker.hpp"32#include "runtime/safepoint.hpp"3334// ----------------------------------------------------------------------------3536#define __ _masm.37address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf, address mark) {38// Stub is fixed up when the corresponding call is converted from39// calling compiled code to calling interpreted code.40// movq rbx, 041// jmp -5 # to self4243if (mark == NULL) {44mark = cbuf.insts_mark(); // Get mark within main instrs section.45}4647// Note that the code buffer's insts_mark is always relative to insts.48// That's why we must use the macroassembler to generate a stub.49MacroAssembler _masm(&cbuf);5051address base = __ start_a_stub(to_interp_stub_size());52if (base == NULL) {53return NULL; // CodeBuffer::expand failed.54}55// Static stub relocation stores the instruction address of the call.56__ relocate(static_stub_Relocation::spec(mark), Assembler::imm_operand);57// Static stub relocation also tags the Method* in the code-stream.58__ mov_metadata(rbx, (Metadata*) NULL); // Method is zapped till fixup time.59// This is recognized as unresolved by relocs/nativeinst/ic code.60__ jump(RuntimeAddress(__ pc()));6162assert(__ pc() - base <= to_interp_stub_size(), "wrong stub size");6364// Update current stubs pointer and restore insts_end.65__ end_a_stub();66return base;67}68#undef __6970int CompiledStaticCall::to_interp_stub_size() {71return NOT_LP64(10) // movl; jmp72LP64_ONLY(15); // movq (1+1+8); jmp (1+4)73}7475int CompiledStaticCall::to_trampoline_stub_size() {76// x86 doesn't use trampolines.77return 0;78}7980// Relocation entries for call stub, compiled java to interpreter.81int CompiledStaticCall::reloc_to_interp_stub() {82return 4; // 3 in emit_to_interp_stub + 1 in emit_call83}8485void CompiledDirectStaticCall::set_to_interpreted(const methodHandle& callee, address entry) {86address stub = find_stub();87guarantee(stub != NULL, "stub not found");8889if (TraceICs) {90ResourceMark rm;91tty->print_cr("CompiledDirectStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",92p2i(instruction_address()),93callee->name_and_sig_as_C_string());94}9596// Creation also verifies the object.97NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);98NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());99verify_mt_safe(callee, entry, method_holder, jump);100101// Update stub.102method_holder->set_data((intptr_t)callee());103jump->set_jump_destination(entry);104105// Update jump to call.106set_destination_mt_safe(stub);107}108109void CompiledDirectStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {110assert(CompiledICLocker::is_safe(static_stub->addr()), "mt unsafe call");111// Reset stub.112address stub = static_stub->addr();113assert(stub != NULL, "stub not found");114// Creation also verifies the object.115NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);116method_holder->set_data(0);117NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());118jump->set_jump_destination((address)-1);119}120121122//-----------------------------------------------------------------------------123// Non-product mode code124#ifndef PRODUCT125126void CompiledDirectStaticCall::verify() {127// Verify call.128_call->verify();129_call->verify_alignment();130131#ifdef ASSERT132CodeBlob *cb = CodeCache::find_blob_unsafe((address) _call);133assert(cb != NULL, "sanity");134#endif135136// Verify stub.137address stub = find_stub();138assert(stub != NULL, "no stub found for static call");139// Creation also verifies the object.140NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);141NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());142143// Verify state.144assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");145}146#endif // !PRODUCT147148149