Skip to content

Commit

Permalink
Passed t1 and t2.
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Apr 11, 2024
1 parent 31b66c0 commit 8197344
Show file tree
Hide file tree
Showing 12 changed files with 700 additions and 186 deletions.
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ friend class ArrayCopyStub;
// See emit_static_call_stub for detail
// CompiledDirectCall::to_interp_stub_size() (14) + CompiledDirectCall::to_trampoline_stub_size() (1 + 3 + address)
_call_stub_size = 14 * NativeInstruction::instruction_size +
(NativeInstruction::instruction_size + NativeCallTrampolineStub::instruction_size),
(NativeInstruction::instruction_size + NativeShortCall::trampoline_size),
// See emit_exception_handler for detail
// verify_not_null_oop + far_call + should_not_reach_here + invalidate_registers(DEBUG_ONLY)
_exception_handler_size = DEBUG_ONLY(584) NOT_DEBUG(548), // or smaller
Expand Down
3 changes: 2 additions & 1 deletion src/hotspot/cpu/riscv/codeBuffer_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ static bool emit_shared_trampolines(CodeBuffer* cb, CodeBuffer::SharedTrampoline
if (requests == nullptr) {
return true;
}
assert(!UseNewCode, "Not null?");

MacroAssembler masm(cb);

Expand All @@ -60,7 +61,7 @@ static bool emit_shared_trampolines(CodeBuffer* cb, CodeBuffer::SharedTrampoline
address stub = __ emit_trampoline_stub(offset, dest);
assert(stub, "pre-allocated trampolines");

address reloc_pc = cb->stubs()->end() - NativeCallTrampolineStub::instruction_size;
address reloc_pc = cb->stubs()->end() - NativeShortCall::trampoline_size;
while (!it.is_empty()) {
offset = *it.next();
address caller_pc = cb->insts()->start() + offset;
Expand Down
2 changes: 1 addition & 1 deletion src/hotspot/cpu/riscv/codeBuffer_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

public:
void flush_bundle(bool start_new_bundle) {}
static constexpr bool supports_shared_stubs() { return true; }
static bool supports_shared_stubs() { return !UseNewCode; }

void share_trampoline_for(address dest, int caller_offset);

Expand Down
78 changes: 69 additions & 9 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,20 @@ void MacroAssembler::li(Register Rd, int64_t imm) {
}
}

void MacroAssembler::load_link(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");
//printf("Trampo auipc: %p\n", pc());
Assembler::auipc(temp, (int32_t)distance + 0x800);
//printf("Trampo ld: %p -> source: %p\n", pc(), source);
Assembler::_ld(temp, temp, ((int32_t)distance << 20) >> 20);
//printf("Trampo jalr: %p\n", pc());
Assembler::jalr(x1, temp, 0);
}

void MacroAssembler::jump_link(const address dest, Register temp) {
assert_cond(dest != nullptr);
int64_t distance = dest - pc();
Expand Down Expand Up @@ -898,7 +912,7 @@ void MacroAssembler::j(const address dest, Register temp) {
}
}

void MacroAssembler::j(const Address &adr, Register temp) {
void MacroAssembler::j(const Address &adr, Register temp) {
switch (adr.getMode()) {
case Address::literal: {
relocate(adr.rspec(), [&] {
Expand Down Expand Up @@ -3517,11 +3531,16 @@ address MacroAssembler::trampoline_call(Address entry) {

// We need a trampoline if branches are far.
if (!in_scratch_emit_size()) {
if (entry.rspec().type() == relocInfo::runtime_call_type) {
if (entry.rspec().type() == relocInfo::runtime_call_type && !UseNewCode) {
assert(CodeBuffer::supports_shared_stubs(), "must support shared stubs");
code()->share_trampoline_for(entry.target(), offset());
} else {
address stub = emit_trampoline_stub(offset(), target);
address stub = nullptr;
if (UseNewCode) {
stub = emit_address_stub(offset(), target);
} else {
stub = emit_trampoline_stub(offset(), target);
}
if (stub == nullptr) {
postcond(pc() == badAddress);
return nullptr; // CodeCache is full
Expand All @@ -3537,7 +3556,11 @@ address MacroAssembler::trampoline_call(Address entry) {
}
#endif
relocate(entry.rspec(), [&] {
jump_link(target, t0);
if (UseNewCode) {
load_link(target, t0);
} else {
jump_link(target, t0);
}
});

postcond(pc() != badAddress);
Expand Down Expand Up @@ -3594,6 +3617,38 @@ int MacroAssembler::ic_check(int end_alignment) {
return uep_offset;
}

address MacroAssembler::emit_address_stub(int insts_call_instruction_offset, address dest) {
address stub = start_a_stub(max_trampoline_stub_size());
if (stub == nullptr) {
return nullptr; // CodeBuffer::expand failed
}

// We are always 4-byte aligned here.
assert_alignment(pc());

// Make sure the address of destination 8-byte aligned.
align(wordSize, 0);

RelocationHolder rh = trampoline_stub_Relocation::spec(code()->insts()->start() +
insts_call_instruction_offset);
const int stub_start_offset = offset();
relocate(rh, [&] {
assert(offset() - stub_start_offset == 0,
"%ld - %ld == %ld : should be", (long)offset(), (long)stub_start_offset, (long)0);
assert(offset() % wordSize == 0, "bad alignment");
//printf("Data trampo at %p with dest: %p\n", pc(), dest);
//fflush(stdout);
emit_int64((int64_t)dest);
emit_int64((int64_t)0xababababababababull);
});

const address stub_start_addr = addr_at(stub_start_offset);
assert(NativeFarCall::is_stub_address_at(stub_start_addr), "doesn't look like an address");
end_a_stub();

return stub_start_addr;
}

// Emit a trampoline stub for a call to a target which is too far away.
//
// code sequences:
Expand All @@ -3613,6 +3668,8 @@ address MacroAssembler::emit_trampoline_stub(int insts_call_instruction_offset,
return nullptr; // CodeBuffer::expand failed
}

assert(!UseNewCode, "Bad");

// We are always 4-byte aligned here.
assert_alignment(pc());

Expand All @@ -3621,7 +3678,7 @@ address MacroAssembler::emit_trampoline_stub(int insts_call_instruction_offset,
// instructions code-section.

// Make sure the address of destination 8-byte aligned after 3 instructions.
align(wordSize, NativeCallTrampolineStub::data_offset);
align(wordSize, NativeShortCall::trampoline_data_offset);

RelocationHolder rh = trampoline_stub_Relocation::spec(code()->insts()->start() +
insts_call_instruction_offset);
Expand All @@ -3634,23 +3691,26 @@ address MacroAssembler::emit_trampoline_stub(int insts_call_instruction_offset,
ld(t0, target); // auipc + ld
jr(t0); // jalr
bind(target);
assert(offset() - stub_start_offset == NativeCallTrampolineStub::data_offset,
assert(offset() - stub_start_offset == NativeShortCall::trampoline_data_offset,
"should be");
assert(offset() % wordSize == 0, "bad alignment");
emit_int64((int64_t)dest);
});

const address stub_start_addr = addr_at(stub_start_offset);

assert(is_NativeCallTrampolineStub_at(stub_start_addr), "doesn't look like a trampoline");

end_a_stub();

return stub_start_addr;
}

int MacroAssembler::max_trampoline_stub_size() {
// Max stub size: alignment nop, TrampolineStub.
return NativeInstruction::instruction_size + NativeCallTrampolineStub::instruction_size;
if (UseNewCode) {
return 2 * wordSize;
} else {
return NativeInstruction::instruction_size + NativeShortCall::trampoline_size;
}
}

int MacroAssembler::static_call_stub_size() {
Expand Down
3 changes: 3 additions & 0 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -436,8 +436,10 @@ class MacroAssembler: public Assembler {
return false;
}

address emit_address_stub(int insts_call_instruction_offset, address target);
address emit_trampoline_stub(int insts_call_instruction_offset, address target);
static int max_trampoline_stub_size();

void emit_static_call_stub();
static int static_call_stub_size();

Expand Down Expand Up @@ -590,6 +592,7 @@ class MacroAssembler: public Assembler {
void bgtz(Register Rs, const address dest);

private:
void load_link(const address source, Register temp);
void jump_link(const address dest, Register temp);
void jump_link(const Address &adr, Register temp);
public:
Expand Down
Loading

0 comments on commit 8197344

Please sign in to comment.