Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/cpu/x86/vm/compiledIC_x86.cpp
32285 views
/*1* Copyright (c) 1997, 2014, 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/compiledIC.hpp"27#include "code/icBuffer.hpp"28#include "code/nmethod.hpp"29#include "memory/resourceArea.hpp"30#include "runtime/mutexLocker.hpp"31#include "runtime/safepoint.hpp"3233// Release the CompiledICHolder* associated with this call site is there is one.34void CompiledIC::cleanup_call_site(virtual_call_Relocation* call_site) {35// This call site might have become stale so inspect it carefully.36NativeCall* call = nativeCall_at(call_site->addr());37if (is_icholder_entry(call->destination())) {38NativeMovConstReg* value = nativeMovConstReg_at(call_site->cached_value());39InlineCacheBuffer::queue_for_release((CompiledICHolder*)value->data());40}41}4243bool CompiledIC::is_icholder_call_site(virtual_call_Relocation* call_site) {44// This call site might have become stale so inspect it carefully.45NativeCall* call = nativeCall_at(call_site->addr());46return is_icholder_entry(call->destination());47}4849// ----------------------------------------------------------------------------5051#define __ _masm.52address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf) {53// Stub is fixed up when the corresponding call is converted from54// calling compiled code to calling interpreted code.55// movq rbx, 056// jmp -5 # to self5758address mark = cbuf.insts_mark(); // Get mark within main instrs section.5960// Note that the code buffer's insts_mark is always relative to insts.61// That's why we must use the macroassembler to generate a stub.62MacroAssembler _masm(&cbuf);6364address base = __ start_a_stub(to_interp_stub_size());65if (base == NULL) {66return NULL; // CodeBuffer::expand failed.67}68// Static stub relocation stores the instruction address of the call.69__ relocate(static_stub_Relocation::spec(mark), Assembler::imm_operand);70// Static stub relocation also tags the Method* in the code-stream.71__ mov_metadata(rbx, (Metadata*) NULL); // Method is zapped till fixup time.72// This is recognized as unresolved by relocs/nativeinst/ic code.73__ jump(RuntimeAddress(__ pc()));7475// Update current stubs pointer and restore insts_end.76__ end_a_stub();77return base;78}79#undef __8081int CompiledStaticCall::to_interp_stub_size() {82return NOT_LP64(10) // movl; jmp83LP64_ONLY(15); // movq (1+1+8); jmp (1+4)84}8586// Relocation entries for call stub, compiled java to interpreter.87int CompiledStaticCall::reloc_to_interp_stub() {88return 4; // 3 in emit_to_interp_stub + 1 in emit_call89}9091void CompiledStaticCall::set_to_interpreted(methodHandle callee, address entry) {92address stub = find_stub();93guarantee(stub != NULL, "stub not found");9495if (TraceICs) {96ResourceMark rm;97tty->print_cr("CompiledStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",98p2i(instruction_address()),99callee->name_and_sig_as_C_string());100}101102// Creation also verifies the object.103NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);104NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());105106assert(method_holder->data() == 0 || method_holder->data() == (intptr_t)callee(),107"a) MT-unsafe modification of inline cache");108assert(jump->jump_destination() == (address)-1 || jump->jump_destination() == entry,109"b) MT-unsafe modification of inline cache");110111// Update stub.112method_holder->set_data((intptr_t)callee());113jump->set_jump_destination(entry);114115// Update jump to call.116set_destination_mt_safe(stub);117}118119void CompiledStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {120assert (CompiledIC_lock->is_locked() || SafepointSynchronize::is_at_safepoint(), "mt unsafe call");121// Reset stub.122address stub = static_stub->addr();123assert(stub != NULL, "stub not found");124// Creation also verifies the object.125NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);126NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());127method_holder->set_data(0);128jump->set_jump_destination((address)-1);129}130131//-----------------------------------------------------------------------------132// Non-product mode code133#ifndef PRODUCT134135void CompiledStaticCall::verify() {136// Verify call.137NativeCall::verify();138if (os::is_MP()) {139verify_alignment();140}141142// Verify stub.143address stub = find_stub();144assert(stub != NULL, "no stub found for static call");145// Creation also verifies the object.146NativeMovConstReg* method_holder = nativeMovConstReg_at(stub);147NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());148149// Verify state.150assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");151}152153#endif // !PRODUCT154155156