2
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2014, 2018, Red Hat Inc. All rights reserved.
4
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6
* This code is free software; you can redistribute it and/or modify it
7
* under the terms of the GNU General Public License version 2 only, as
8
* published by the Free Software Foundation.
10
* This code is distributed in the hope that it will be useful, but WITHOUT
11
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
* version 2 for more details (a copy is included in the LICENSE file that
14
* accompanied this code).
16
* You should have received a copy of the GNU General Public License version
17
* 2 along with this work; if not, write to the Free Software Foundation,
18
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
* or visit www.oracle.com if you need additional information or have any
26
#include "precompiled.hpp"
27
#include "asm/macroAssembler.inline.hpp"
28
#include "code/compiledIC.hpp"
29
#include "code/nmethod.hpp"
30
#include "logging/log.hpp"
31
#include "memory/resourceArea.hpp"
32
#include "runtime/mutexLocker.hpp"
33
#include "runtime/safepoint.hpp"
35
// ----------------------------------------------------------------------------
38
address CompiledDirectCall::emit_to_interp_stub(MacroAssembler *masm, address mark) {
39
precond(__ code()->stubs()->start() != badAddress);
40
precond(__ code()->stubs()->end() != badAddress);
42
// Stub is fixed up when the corresponding call is converted from
43
// calling compiled code to calling interpreted code.
47
if (mark == nullptr) {
48
mark = __ inst_mark(); // Get mark within main instrs section.
51
address base = __ start_a_stub(to_interp_stub_size());
52
int offset = __ offset();
53
if (base == nullptr) {
54
return nullptr; // CodeBuffer::expand failed
56
// static stub relocation stores the instruction address of the call
57
__ relocate(static_stub_Relocation::spec(mark));
60
__ emit_static_call_stub();
63
assert((__ offset() - offset) <= (int)to_interp_stub_size(), "stub too big");
69
int CompiledDirectCall::to_interp_stub_size() {
70
return MacroAssembler::static_call_stub_size();
73
int CompiledDirectCall::to_trampoline_stub_size() {
74
// Somewhat pessimistically, we count 3 instructions here (although
75
// there are only two) because we sometimes emit an alignment nop.
76
// Trampoline stubs are always word aligned.
77
return MacroAssembler::max_trampoline_stub_size();
80
// Relocation entries for call stub, compiled java to interpreter.
81
int CompiledDirectCall::reloc_to_interp_stub() {
82
return 4; // 3 in emit_to_interp_stub + 1 in emit_call
85
void CompiledDirectCall::set_to_interpreted(const methodHandle& callee, address entry) {
86
address stub = find_stub();
87
guarantee(stub != nullptr, "stub not found");
89
// Creation also verifies the object.
90
NativeMovConstReg* method_holder
91
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);
94
NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());
95
verify_mt_safe(callee, entry, method_holder, jump);
99
method_holder->set_data((intptr_t)callee());
100
NativeGeneralJump::insert_unconditional(method_holder->next_instruction_address(), entry);
101
ICache::invalidate_range(stub, to_interp_stub_size());
102
// Update jump to call.
103
set_destination_mt_safe(stub);
106
void CompiledDirectCall::set_stub_to_clean(static_stub_Relocation* static_stub) {
108
address stub = static_stub->addr();
109
assert(stub != nullptr, "stub not found");
110
assert(CompiledICLocker::is_safe(stub), "mt unsafe call");
111
// Creation also verifies the object.
112
NativeMovConstReg* method_holder
113
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);
114
method_holder->set_data(0);
115
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
116
jump->set_jump_destination((address)-1);
119
//-----------------------------------------------------------------------------
120
// Non-product mode code
123
void CompiledDirectCall::verify() {
126
_call->verify_alignment();
129
address stub = find_stub();
130
assert(stub != nullptr, "no stub found for static call");
131
// Creation also verifies the object.
132
NativeMovConstReg* method_holder
133
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);
134
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
137
assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");