Skip to content

Commit 7c60e6d

Browse files
DingliZhangzifeihan
authored andcommitted
8293770: RISC-V: Reuse runtime call trampolines
Co-authored-by: zifeihan <caogui@iscas.ac.cn> Reviewed-by: fyang, shade
1 parent 9dce865 commit 7c60e6d

File tree

4 files changed

+68
-11
lines changed

4 files changed

+68
-11
lines changed

src/hotspot/cpu/riscv/codeBuffer_riscv.cpp

Lines changed: 51 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,56 @@
2727
#include "asm/codeBuffer.inline.hpp"
2828
#include "asm/macroAssembler.hpp"
2929

30+
void CodeBuffer::share_trampoline_for(address dest, int caller_offset) {
31+
if (_shared_trampoline_requests == nullptr) {
32+
constexpr unsigned init_size = 8;
33+
constexpr unsigned max_size = 256;
34+
_shared_trampoline_requests = new SharedTrampolineRequests(init_size, max_size);
35+
}
36+
37+
bool created;
38+
Offsets* offsets = _shared_trampoline_requests->put_if_absent(dest, &created);
39+
if (created) {
40+
_shared_trampoline_requests->maybe_grow();
41+
}
42+
offsets->add(caller_offset);
43+
_finalize_stubs = true;
44+
}
45+
46+
static bool emit_shared_trampolines(CodeBuffer* cb, CodeBuffer::SharedTrampolineRequests* requests) {
47+
if (requests == nullptr) {
48+
return true;
49+
}
50+
51+
MacroAssembler masm(cb);
52+
53+
bool p_succeeded = true;
54+
auto emit = [&](address dest, const CodeBuffer::Offsets &offsets) {
55+
masm.set_code_section(cb->stubs());
56+
masm.align(wordSize, NativeCallTrampolineStub::data_offset);
57+
58+
LinkedListIterator<int> it(offsets.head());
59+
int offset = *it.next();
60+
for (; !it.is_empty(); offset = *it.next()) {
61+
masm.relocate(trampoline_stub_Relocation::spec(cb->insts()->start() + offset));
62+
}
63+
masm.set_code_section(cb->insts());
64+
65+
address stub = masm.emit_trampoline_stub(offset, dest);
66+
if (stub == nullptr) {
67+
ciEnv::current()->record_failure("CodeCache is full");
68+
p_succeeded = false;
69+
}
70+
71+
return p_succeeded;
72+
};
73+
74+
requests->iterate(emit);
75+
76+
return p_succeeded;
77+
}
78+
3079
bool CodeBuffer::pd_finalize_stubs() {
31-
return emit_shared_stubs_to_interp<MacroAssembler>(this, _shared_stub_to_interp_requests);
80+
return emit_shared_stubs_to_interp<MacroAssembler>(this, _shared_stub_to_interp_requests)
81+
&& emit_shared_trampolines(this, _shared_trampoline_requests);
3282
}

src/hotspot/cpu/riscv/codeBuffer_riscv.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@
3535
void flush_bundle(bool start_new_bundle) {}
3636
static constexpr bool supports_shared_stubs() { return true; }
3737

38+
void share_trampoline_for(address dest, int caller_offset);
39+
3840
#endif // CPU_RISCV_CODEBUFFER_RISCV_HPP

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,8 @@ address MacroAssembler::trampoline_call(Address entry) {
28012801
entry.rspec().type() == relocInfo::static_call_type ||
28022802
entry.rspec().type() == relocInfo::virtual_call_type, "wrong reloc type");
28032803

2804+
address target = entry.target();
2805+
28042806
// We need a trampoline if branches are far.
28052807
if (far_branches()) {
28062808
bool in_scratch_emit_size = false;
@@ -2813,12 +2815,18 @@ address MacroAssembler::trampoline_call(Address entry) {
28132815
Compile::current()->output()->in_scratch_emit_size());
28142816
#endif
28152817
if (!in_scratch_emit_size) {
2816-
address stub = emit_trampoline_stub(offset(), entry.target());
2817-
if (stub == NULL) {
2818-
postcond(pc() == badAddress);
2819-
return NULL; // CodeCache is full
2818+
if (entry.rspec().type() == relocInfo::runtime_call_type) {
2819+
assert(CodeBuffer::supports_shared_stubs(), "must support shared stubs");
2820+
code()->share_trampoline_for(entry.target(), offset());
2821+
} else {
2822+
address stub = emit_trampoline_stub(offset(), target);
2823+
if (stub == NULL) {
2824+
postcond(pc() == badAddress);
2825+
return NULL; // CodeCache is full
2826+
}
28202827
}
28212828
}
2829+
target = pc();
28222830
}
28232831

28242832
address call_pc = pc();
@@ -2828,11 +2836,7 @@ address MacroAssembler::trampoline_call(Address entry) {
28282836
}
28292837
#endif
28302838
relocate(entry.rspec());
2831-
if (!far_branches()) {
2832-
jal(entry.target());
2833-
} else {
2834-
jal(pc());
2835-
}
2839+
jal(target);
28362840

28372841
postcond(pc() != badAddress);
28382842
return call_pc;

test/hotspot/jtreg/compiler/sharedstubs/SharedTrampolineTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
* @bug 8280152
2929
* @library /test/lib
3030
*
31-
* @requires vm.debug & os.arch=="aarch64"
31+
* @requires os.arch=="aarch64" | os.arch=="riscv64"
32+
* @requires vm.debug
3233
*
3334
* @run driver compiler.sharedstubs.SharedTrampolineTest
3435
*/

0 commit comments

Comments
 (0)