Path: blob/master/src/hotspot/cpu/aarch64/compiledIC_aarch64.cpp
40930 views
/*1* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.2* Copyright (c) 2014, 2018, Red Hat Inc. All rights reserved.3* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.4*5* This code is free software; you can redistribute it and/or modify it6* under the terms of the GNU General Public License version 2 only, as7* published by the Free Software Foundation.8*9* This code is distributed in the hope that it will be useful, but WITHOUT10* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or11* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License12* version 2 for more details (a copy is included in the LICENSE file that13* accompanied this code).14*15* You should have received a copy of the GNU General Public License version16* 2 along with this work; if not, write to the Free Software Foundation,17* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.18*19* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA20* or visit www.oracle.com if you need additional information or have any21* questions.22*23*/2425#include "precompiled.hpp"26#include "asm/macroAssembler.inline.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) {38precond(cbuf.stubs()->start() != badAddress);39precond(cbuf.stubs()->end() != badAddress);4041// Stub is fixed up when the corresponding call is converted from42// calling compiled code to calling interpreted code.43// mov rmethod, 044// jmp -4 # to self4546if (mark == NULL) {47mark = cbuf.insts_mark(); // Get mark within main instrs section.48}4950// Note that the code buffer's insts_mark is always relative to insts.51// That's why we must use the macroassembler to generate a stub.52MacroAssembler _masm(&cbuf);5354address base = __ start_a_stub(to_interp_stub_size());55int offset = __ offset();56if (base == NULL) {57return NULL; // CodeBuffer::expand failed58}59// static stub relocation stores the instruction address of the call60__ relocate(static_stub_Relocation::spec(mark));6162{63__ emit_static_call_stub();64}6566assert((__ offset() - offset) <= (int)to_interp_stub_size(), "stub too big");67__ end_a_stub();68return base;69}70#undef __7172int CompiledStaticCall::to_interp_stub_size() {73// isb; movk; movz; movz; movk; movz; movz; br74return 8 * NativeInstruction::instruction_size;75}7677int CompiledStaticCall::to_trampoline_stub_size() {78// Somewhat pessimistically, we count 3 instructions here (although79// there are only two) because we sometimes emit an alignment nop.80// Trampoline stubs are always word aligned.81return 3 * NativeInstruction::instruction_size + wordSize;82}8384// Relocation entries for call stub, compiled java to interpreter.85int CompiledStaticCall::reloc_to_interp_stub() {86return 4; // 3 in emit_to_interp_stub + 1 in emit_call87}8889void CompiledDirectStaticCall::set_to_interpreted(const methodHandle& callee, address entry) {90address stub = find_stub();91guarantee(stub != NULL, "stub not found");9293if (TraceICs) {94ResourceMark rm;95tty->print_cr("CompiledDirectStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",96p2i(instruction_address()),97callee->name_and_sig_as_C_string());98}99100// Creation also verifies the object.101NativeMovConstReg* method_holder102= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);103104#ifdef ASSERT105NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());106verify_mt_safe(callee, entry, method_holder, jump);107#endif108109// Update stub.110method_holder->set_data((intptr_t)callee());111NativeGeneralJump::insert_unconditional(method_holder->next_instruction_address(), entry);112ICache::invalidate_range(stub, to_interp_stub_size());113// Update jump to call.114set_destination_mt_safe(stub);115}116117void CompiledDirectStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {118// Reset stub.119address stub = static_stub->addr();120assert(stub != NULL, "stub not found");121assert(CompiledICLocker::is_safe(stub), "mt unsafe call");122// Creation also verifies the object.123NativeMovConstReg* method_holder124= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);125method_holder->set_data(0);126NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());127jump->set_jump_destination((address)-1);128}129130//-----------------------------------------------------------------------------131// Non-product mode code132#ifndef PRODUCT133134void CompiledDirectStaticCall::verify() {135// Verify call.136_call->verify();137_call->verify_alignment();138139// Verify stub.140address stub = find_stub();141assert(stub != NULL, "no stub found for static call");142// Creation also verifies the object.143NativeMovConstReg* method_holder144= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);145NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());146147// Verify state.148assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");149}150151#endif // !PRODUCT152153154