Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/cpu/aarch64/compiledIC_aarch64.cpp
40930 views
1
/*
2
* Copyright (c) 1997, 2021, 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.
5
*
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.
9
*
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).
15
*
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.
19
*
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
22
* questions.
23
*
24
*/
25
26
#include "precompiled.hpp"
27
#include "asm/macroAssembler.inline.hpp"
28
#include "code/compiledIC.hpp"
29
#include "code/icBuffer.hpp"
30
#include "code/nmethod.hpp"
31
#include "memory/resourceArea.hpp"
32
#include "runtime/mutexLocker.hpp"
33
#include "runtime/safepoint.hpp"
34
35
// ----------------------------------------------------------------------------
36
37
#define __ _masm.
38
address CompiledStaticCall::emit_to_interp_stub(CodeBuffer &cbuf, address mark) {
39
precond(cbuf.stubs()->start() != badAddress);
40
precond(cbuf.stubs()->end() != badAddress);
41
42
// Stub is fixed up when the corresponding call is converted from
43
// calling compiled code to calling interpreted code.
44
// mov rmethod, 0
45
// jmp -4 # to self
46
47
if (mark == NULL) {
48
mark = cbuf.insts_mark(); // Get mark within main instrs section.
49
}
50
51
// Note that the code buffer's insts_mark is always relative to insts.
52
// That's why we must use the macroassembler to generate a stub.
53
MacroAssembler _masm(&cbuf);
54
55
address base = __ start_a_stub(to_interp_stub_size());
56
int offset = __ offset();
57
if (base == NULL) {
58
return NULL; // CodeBuffer::expand failed
59
}
60
// static stub relocation stores the instruction address of the call
61
__ relocate(static_stub_Relocation::spec(mark));
62
63
{
64
__ emit_static_call_stub();
65
}
66
67
assert((__ offset() - offset) <= (int)to_interp_stub_size(), "stub too big");
68
__ end_a_stub();
69
return base;
70
}
71
#undef __
72
73
int CompiledStaticCall::to_interp_stub_size() {
74
// isb; movk; movz; movz; movk; movz; movz; br
75
return 8 * NativeInstruction::instruction_size;
76
}
77
78
int CompiledStaticCall::to_trampoline_stub_size() {
79
// Somewhat pessimistically, we count 3 instructions here (although
80
// there are only two) because we sometimes emit an alignment nop.
81
// Trampoline stubs are always word aligned.
82
return 3 * NativeInstruction::instruction_size + wordSize;
83
}
84
85
// Relocation entries for call stub, compiled java to interpreter.
86
int CompiledStaticCall::reloc_to_interp_stub() {
87
return 4; // 3 in emit_to_interp_stub + 1 in emit_call
88
}
89
90
void CompiledDirectStaticCall::set_to_interpreted(const methodHandle& callee, address entry) {
91
address stub = find_stub();
92
guarantee(stub != NULL, "stub not found");
93
94
if (TraceICs) {
95
ResourceMark rm;
96
tty->print_cr("CompiledDirectStaticCall@" INTPTR_FORMAT ": set_to_interpreted %s",
97
p2i(instruction_address()),
98
callee->name_and_sig_as_C_string());
99
}
100
101
// Creation also verifies the object.
102
NativeMovConstReg* method_holder
103
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);
104
105
#ifdef ASSERT
106
NativeGeneralJump* jump = nativeGeneralJump_at(method_holder->next_instruction_address());
107
verify_mt_safe(callee, entry, method_holder, jump);
108
#endif
109
110
// Update stub.
111
method_holder->set_data((intptr_t)callee());
112
NativeGeneralJump::insert_unconditional(method_holder->next_instruction_address(), entry);
113
ICache::invalidate_range(stub, to_interp_stub_size());
114
// Update jump to call.
115
set_destination_mt_safe(stub);
116
}
117
118
void CompiledDirectStaticCall::set_stub_to_clean(static_stub_Relocation* static_stub) {
119
// Reset stub.
120
address stub = static_stub->addr();
121
assert(stub != NULL, "stub not found");
122
assert(CompiledICLocker::is_safe(stub), "mt unsafe call");
123
// Creation also verifies the object.
124
NativeMovConstReg* method_holder
125
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);
126
method_holder->set_data(0);
127
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
128
jump->set_jump_destination((address)-1);
129
}
130
131
//-----------------------------------------------------------------------------
132
// Non-product mode code
133
#ifndef PRODUCT
134
135
void CompiledDirectStaticCall::verify() {
136
// Verify call.
137
_call->verify();
138
_call->verify_alignment();
139
140
// Verify stub.
141
address stub = find_stub();
142
assert(stub != NULL, "no stub found for static call");
143
// Creation also verifies the object.
144
NativeMovConstReg* method_holder
145
= nativeMovConstReg_at(stub + NativeInstruction::instruction_size);
146
NativeJump* jump = nativeJump_at(method_holder->next_instruction_address());
147
148
// Verify state.
149
assert(is_clean() || is_call_to_compiled() || is_call_to_interpreted(), "sanity check");
150
}
151
152
#endif // !PRODUCT
153
154