Skip to content

Commit 5edd546

Browse files
DingliZhangfeilongjiang
authored andcommitted
8361449: RISC-V: Code cleanup for native call
Reviewed-by: fyang, fjiang
1 parent a531c9a commit 5edd546

File tree

3 files changed

+29
-35
lines changed

3 files changed

+29
-35
lines changed

src/hotspot/cpu/riscv/nativeInst_riscv.cpp

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ class NativeFarCall: public NativeInstruction {
6060
address next_instruction_address() const { return addr_at(return_address_offset); }
6161
address return_address() const { return addr_at(return_address_offset); }
6262
address destination() const;
63-
address reloc_destination(address orig_address);
63+
address reloc_destination();
6464

6565
void set_destination(address dest);
6666
void verify();
6767
void print();
6868

69-
bool set_destination_mt_safe(address dest, bool assert_lock = true);
69+
bool set_destination_mt_safe(address dest);
7070
bool reloc_set_destination(address dest);
7171

7272
private:
@@ -88,28 +88,30 @@ address NativeFarCall::destination() const {
8888
address destination = MacroAssembler::target_addr_for_insn(addr);
8989

9090
CodeBlob* cb = CodeCache::find_blob(addr);
91-
assert(cb && cb->is_nmethod(), "sanity");
91+
assert(cb != nullptr && cb->is_nmethod(), "nmethod expected");
9292
nmethod *nm = (nmethod *)cb;
9393
assert(nm != nullptr, "Sanity");
9494
assert(nm->stub_contains(destination), "Sanity");
9595
assert(destination != nullptr, "Sanity");
9696
return stub_address_destination_at(destination);
9797
}
9898

99-
address NativeFarCall::reloc_destination(address orig_address) {
99+
address NativeFarCall::reloc_destination() {
100100
address call_addr = instruction_address();
101+
assert(NativeFarCall::is_at(call_addr), "unexpected code at call site");
101102

102103
CodeBlob *code = CodeCache::find_blob(call_addr);
103104
assert(code != nullptr, "Could not find the containing code blob");
104105

105106
address stub_addr = nullptr;
106-
if (code != nullptr && code->is_nmethod()) {
107-
stub_addr = trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);
107+
if (code->is_nmethod()) {
108+
stub_addr = trampoline_stub_Relocation::get_trampoline_for(call_addr, code->as_nmethod());
108109
}
109110

110111
if (stub_addr != nullptr) {
111112
stub_addr = MacroAssembler::target_addr_for_insn(call_addr);
112113
}
114+
113115
return stub_addr;
114116
}
115117

@@ -128,18 +130,13 @@ void NativeFarCall::print() {
128130
tty->print_cr(PTR_FORMAT ": auipc,ld,jalr x1, offset/reg, ", p2i(addr_at(0)));
129131
}
130132

131-
bool NativeFarCall::set_destination_mt_safe(address dest, bool assert_lock) {
133+
bool NativeFarCall::set_destination_mt_safe(address dest) {
132134
assert(NativeFarCall::is_at(addr_at(0)), "unexpected code at call site");
133-
assert(!assert_lock ||
134-
(CodeCache_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
135+
assert((CodeCache_lock->is_locked() || SafepointSynchronize::is_at_safepoint()) ||
135136
CompiledICLocker::is_safe(addr_at(0)),
136137
"concurrent code patching");
137138

138-
address call_addr = addr_at(0);
139-
assert(NativeFarCall::is_at(call_addr), "unexpected code at call site");
140-
141139
address stub_addr = stub_address();
142-
143140
if (stub_addr != nullptr) {
144141
set_stub_address_destination_at(stub_addr, dest);
145142
return true;
@@ -156,10 +153,9 @@ bool NativeFarCall::reloc_set_destination(address dest) {
156153
assert(code != nullptr, "Could not find the containing code blob");
157154

158155
address stub_addr = nullptr;
159-
if (code != nullptr && code->is_nmethod()) {
160-
stub_addr = trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);
156+
if (code->is_nmethod()) {
157+
stub_addr = trampoline_stub_Relocation::get_trampoline_for(call_addr, code->as_nmethod());
161158
}
162-
163159
if (stub_addr != nullptr) {
164160
MacroAssembler::pd_patch_instruction_size(call_addr, stub_addr);
165161
}
@@ -209,7 +205,7 @@ bool NativeFarCall::is_at(address addr) {
209205
(MacroAssembler::extract_rd(addr + instr_size) == x6) &&
210206
(MacroAssembler::extract_rs1(addr + instr_size) == x6) &&
211207
(MacroAssembler::extract_rs1(addr + 2 * instr_size) == x6) &&
212-
(MacroAssembler::extract_rd(addr + 2 * instr_size) == x1)) {
208+
(MacroAssembler::extract_rd(addr + 2 * instr_size) == x1)) {
213209
return true;
214210
}
215211
return false;
@@ -238,8 +234,8 @@ address NativeCall::destination() const {
238234
return NativeFarCall::at(addr_at(0))->destination();
239235
}
240236

241-
address NativeCall::reloc_destination(address orig_address) {
242-
return NativeFarCall::at(addr_at(0))->reloc_destination(orig_address);
237+
address NativeCall::reloc_destination() {
238+
return NativeFarCall::at(addr_at(0))->reloc_destination();
243239
}
244240

245241
void NativeCall::set_destination(address dest) {
@@ -254,8 +250,8 @@ void NativeCall::print() {
254250
NativeFarCall::at(addr_at(0))->print();;
255251
}
256252

257-
bool NativeCall::set_destination_mt_safe(address dest, bool assert_lock) {
258-
return NativeFarCall::at(addr_at(0))->set_destination_mt_safe(dest, assert_lock);
253+
bool NativeCall::set_destination_mt_safe(address dest) {
254+
return NativeFarCall::at(addr_at(0))->set_destination_mt_safe(dest);
259255
}
260256

261257
bool NativeCall::reloc_set_destination(address dest) {

src/hotspot/cpu/riscv/nativeInst_riscv.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,14 @@ class NativeCall: private NativeInstruction {
134134
address next_instruction_address() const;
135135
address return_address() const;
136136
address destination() const;
137-
address reloc_destination(address orig_address);
137+
address reloc_destination();
138138

139139
void verify_alignment() {} // do nothing on riscv
140140
void verify();
141141
void print();
142142

143143
void set_destination(address dest);
144-
bool set_destination_mt_safe(address dest, bool assert_lock = true);
144+
bool set_destination_mt_safe(address dest);
145145
bool reloc_set_destination(address dest);
146146

147147
static bool is_at(address addr);

src/hotspot/cpu/riscv/relocInfo_riscv.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@ void Relocation::pd_set_data_value(address x, bool verify_only) {
7272
}
7373

7474
address Relocation::pd_call_destination(address orig_addr) {
75-
assert(is_call(), "should be an address instruction here");
75+
assert(is_call(), "should be a call here");
7676
if (NativeCall::is_at(addr())) {
77-
return nativeCall_at(addr())->reloc_destination(orig_addr);
77+
return nativeCall_at(addr())->reloc_destination();
7878
}
79-
// Non call reloc
79+
8080
if (orig_addr != nullptr) {
81-
// the extracted address from the instructions in address orig_addr
8281
address new_addr = MacroAssembler::pd_call_destination(orig_addr);
8382
// If call is branch to self, don't try to relocate it, just leave it
8483
// as branch to self. This happens during code generation if the code
@@ -87,20 +86,19 @@ address Relocation::pd_call_destination(address orig_addr) {
8786
new_addr = (new_addr == orig_addr) ? addr() : new_addr;
8887
return new_addr;
8988
}
89+
9090
return MacroAssembler::pd_call_destination(addr());
9191
}
9292

9393
void Relocation::pd_set_call_destination(address x) {
94-
assert(is_call(), "should be an address instruction here");
94+
assert(is_call(), "should be a call here");
9595
if (NativeCall::is_at(addr())) {
96-
NativeCall* nc = nativeCall_at(addr());
97-
if (nc->reloc_set_destination(x)) {
98-
return;
99-
}
96+
NativeCall* call = nativeCall_at(addr());
97+
call->reloc_set_destination(x);
98+
} else {
99+
MacroAssembler::pd_patch_instruction_size(addr(), x);
100+
assert(pd_call_destination(addr()) == x, "fail in reloc");
100101
}
101-
MacroAssembler::pd_patch_instruction_size(addr(), x);
102-
address pd_call = pd_call_destination(addr());
103-
assert(pd_call == x, "fail in reloc");
104102
}
105103

106104
address* Relocation::pd_address_in_code() {

0 commit comments

Comments
 (0)