Skip to content

Commit

Permalink
To be pushed
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Jun 17, 2024
1 parent b3a4f8f commit b51702b
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 58 deletions.
3 changes: 1 addition & 2 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,6 @@ void MacroAssembler::li(Register Rd, int64_t imm) {

void MacroAssembler::load_link_jump(const address source, Register temp) {
assert(temp != noreg && temp != x0, "expecting a register");
assert(temp == x5, "expecting a register");
assert_cond(source != nullptr);
int64_t distance = source - pc();
assert(is_simm32(distance), "Must be");
Expand Down Expand Up @@ -3784,7 +3783,7 @@ address MacroAssembler::load_call(Address entry) {
}
#endif
relocate(entry.rspec(), [&] {
load_link_jump(target, t0);
load_link_jump(target);
});

postcond(pc() != badAddress);
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ class MacroAssembler: public Assembler {
void bgtz(Register Rs, const address dest);

private:
void load_link_jump(const address source, Register temp);
void load_link_jump(const address source, Register temp = t0);
void jump_link(const address dest, Register temp);
public:
// We try to follow risc-v asm menomics.
Expand Down
67 changes: 14 additions & 53 deletions src/hotspot/cpu/riscv/nativeInst_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ class NativeShortCallTrampolineStub : public NativeInstruction {
trampoline_data_offset = 3 * NativeInstruction::instruction_size // auipc + ld + jr
};

address destination(nmethod *nm = nullptr) const;
address destination() const;
void set_destination(address new_destination);

static bool is_at(address addr);
static NativeShortCallTrampolineStub* at(address addr);
};

address NativeShortCallTrampolineStub::destination(nmethod *nm) const {
address NativeShortCallTrampolineStub::destination() const {
return ptr_at(trampoline_data_offset);
}

Expand Down Expand Up @@ -108,10 +108,6 @@ NativeShortCallTrampolineStub* NativeShortCallTrampolineStub::at(address addr) {
// NativeShortCall
class NativeShortCall: private NativeInstruction {
public:
// Creation
friend NativeCall* nativeCall_at(address addr);
friend NativeCall* nativeCall_before(address return_address);

enum RISCV_specific_constants {
return_address_offset = 1 * NativeInstruction::instruction_size // jal
};
Expand All @@ -138,8 +134,6 @@ class NativeShortCall: private NativeInstruction {
static NativeShortCall* at(address addr);
static bool is_at(address addr);
static bool is_call_before(address return_address);
static void insert(address code_pos, address entry);
static void replace_mt_safe(address instr_addr, address code_buffer);
};

address NativeShortCall::destination() const {
Expand Down Expand Up @@ -224,20 +218,7 @@ bool NativeShortCall::set_destination_mt_safe(address dest, bool assert_lock) {
address call_addr = instruction_address();
assert(NativeCall::is_at(call_addr), "unexpected code at call site");

// Patch the constant in the call's trampoline stub.
address trampoline_stub_addr = get_trampoline();
if (trampoline_stub_addr != nullptr) {
assert (!NativeShortCallTrampolineStub::is_at(dest), "chained trampolines");
NativeShortCallTrampolineStub::at(trampoline_stub_addr)->set_destination(dest);
}

// Patch the call.
if (Assembler::reachable_from_branch_at(call_addr, dest)) {
set_destination(dest);
} else {
assert (trampoline_stub_addr != nullptr, "we need a trampoline");
set_destination(trampoline_stub_addr);
}
reloc_set_destination(dest);

ICache::invalidate_range(call_addr, instruction_size);
return true;
Expand Down Expand Up @@ -277,8 +258,7 @@ address NativeShortCall::get_trampoline() {
}

if (code != nullptr && code->is_nmethod()) {
address ret = trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);
return ret;
return trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);
}

return nullptr;
Expand Down Expand Up @@ -312,22 +292,10 @@ bool NativeShortCall::is_call_before(address return_address) {
return NativeShortCall::is_at(return_address - instruction_size);
}

void NativeShortCall::insert(address code_pos, address entry) {
Unimplemented();
}

void NativeShortCall::replace_mt_safe(address instr_addr, address code_buffer) {
Unimplemented();
}

//-----------------------------------------------------------------------------
// NativeFarCall
class NativeFarCall: public NativeInstruction {
public:
// Creation
friend NativeCall* nativeCall_at(address addr);
friend NativeCall* nativeCall_before(address return_address);

enum RISCV_specific_constants {
return_address_offset = 3 * NativeInstruction::instruction_size, // auipc + ld + jalr
};
Expand Down Expand Up @@ -355,8 +323,6 @@ class NativeFarCall: public NativeInstruction {
static NativeFarCall* at(address addr);
static bool is_at(address addr);
static bool is_call_before(address return_address);
static void insert(address code_pos, address entry);
static void replace_mt_safe(address instr_addr, address code_buffer);
};

address NativeFarCall::destination() const {
Expand All @@ -379,7 +345,11 @@ address NativeFarCall::reloc_destination(address orig_address) {

CodeBlob *code = CodeCache::find_blob(call_addr);
assert(code != nullptr, "Could not find the containing code blob");
address stub_addr = trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);

address stub_addr = nullptr;
if (code != nullptr && code->is_nmethod()) {
stub_addr = trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);
}

if (stub_addr != nullptr) {
stub_addr = MacroAssembler::target_addr_for_insn(call_addr);
Expand Down Expand Up @@ -428,7 +398,11 @@ bool NativeFarCall::reloc_set_destination(address dest) {

CodeBlob *code = CodeCache::find_blob(call_addr);
assert(code != nullptr, "Could not find the containing code blob");
address stub_addr = trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);

address stub_addr = nullptr;
if (code != nullptr && code->is_nmethod()) {
stub_addr = trampoline_stub_Relocation::get_trampoline_for(call_addr, (nmethod*)code);
}

if (stub_addr != nullptr) {
MacroAssembler::pd_patch_instruction_size(call_addr, stub_addr);
Expand Down Expand Up @@ -489,11 +463,6 @@ bool NativeFarCall::is_call_before(address return_address) {
return NativeFarCall::is_at(return_address - return_address_offset);
}

void NativeFarCall::replace_mt_safe(address instr_addr, address code_buffer) {
assert(NativeFarCall::is_at((address)instr_addr), "unexpected code at call site");
Unimplemented();
}

//-----------------------------------------------------------------------------
// NativeCall

Expand Down Expand Up @@ -593,14 +562,6 @@ bool NativeCall::is_call_before(address return_address) {
}
}

void NativeCall::replace_mt_safe(address instr_addr, address code_buffer) {
if (UseTrampolines) {
NativeShortCall::replace_mt_safe(instr_addr, code_buffer);
} else {
NativeFarCall::replace_mt_safe(instr_addr, code_buffer);
}
}

NativeCall* nativeCall_at(address addr) {
assert_cond(addr != nullptr);
NativeCall* call = (NativeCall*)(addr);
Expand Down
2 changes: 0 additions & 2 deletions src/hotspot/cpu/riscv/nativeInst_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ class NativeCall: private NativeInstruction {

static bool is_at(address addr);
static bool is_call_before(address return_address);
static void insert(address code_pos, address entry);
static void replace_mt_safe(address instr_addr, address code_buffer);
};

// An interface for accessing/manipulating native mov reg, imm instructions.
Expand Down

0 comments on commit b51702b

Please sign in to comment.