Skip to content

Commit

Permalink
Fixed size
Browse files Browse the repository at this point in the history
  • Loading branch information
robehn committed Dec 4, 2023
1 parent 2c52f13 commit c2cca52
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 31 deletions.
33 changes: 16 additions & 17 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3329,41 +3329,40 @@ address MacroAssembler::ic_call(address entry, jint method_index) {
}

int MacroAssembler::ic_check_size() {
return NativeInstruction::instruction_size * 9;
// No compressed
return NativeInstruction::instruction_size *
(2 /* 2 loads */ + 1 /* branch */ + 2 /* auipc + jalr */);
}

int MacroAssembler::ic_check(int end_alignment) {
IncompressibleRegion ir(this);
Register receiver = j_rarg0;
Register data = t1;
Register tmp1 = t0;
Register tmp2 = t2;

int start_offset = offset();

align(end_alignment, offset() + ic_check_size());
Register tmp1 = t0; // t0 always scratch
// t2 is saved on call, thus should have been saved before this check.
// Hence we can clobber it.
Register tmp2 = t2;

align(end_alignment, ic_check_size());
int uep_offset = offset();

if (UseCompressedClassPointers) {
lw(tmp1, Address(receiver, oopDesc::klass_offset_in_bytes()));
lw(tmp2, Address(data, CompiledICData::speculated_klass_offset()));
lwu(tmp1, Address(receiver, oopDesc::klass_offset_in_bytes()));
lwu(tmp2, Address(data, CompiledICData::speculated_klass_offset()));
} else {
ld(tmp1, Address(receiver, oopDesc::klass_offset_in_bytes()));
ld(tmp2, Address(data, CompiledICData::speculated_klass_offset()));
}

Label dont;
beq(tmp1, tmp2, dont);
Label ic_hit;
beq(tmp1, tmp2, ic_hit);
// Note, far_jump is not fixed size.
// Is this ever generates a movptr alignment/size will be off.
far_jump(RuntimeAddress(SharedRuntime::get_ic_miss_stub()));
bind(dont);

int beoffs = offset();
align(end_alignment, 0);
bind(ic_hit);

int offs = offset();
assert((offs % end_alignment) == 0, "Misaligned verified entry point: %d %d %d %d %d %d",
start_offset, uep_offset, beoffs, offs, ic_check_size(), end_alignment);
assert((offset() % end_alignment) == 0, "Misaligned verified entry point.");
return uep_offset;
}

Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/riscv/macroAssembler_riscv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1071,7 +1071,7 @@ class MacroAssembler: public Assembler {

static int far_branch_size() {
if (far_branches()) {
return 2 * 4; // auipc + jalr, see far_call() & far_jump()
return 2 * NativeInstruction::instruction_size; // auipc + jalr, see far_call() & far_jump()
} else {
return 4;
}
Expand Down Expand Up @@ -1173,7 +1173,7 @@ class MacroAssembler: public Assembler {
uintptr_t create_ic_data();
address ic_call(address entry, jint method_index = 0);
static int ic_check_size();
int ic_check(int end_alignment);
int ic_check(int end_alignment = NativeInstruction::instruction_size);

// Support for memory inc/dec
// n.b. increment/decrement calls with an Address destination will
Expand Down
19 changes: 9 additions & 10 deletions src/hotspot/cpu/riscv/riscv.ad
Original file line number Diff line number Diff line change
Expand Up @@ -1807,14 +1807,13 @@ void MachUEPNode::format(PhaseRegAlloc* ra_, outputStream* st) const
assert_cond(st != NULL);
st->print_cr("# MachUEPNode");
if (UseCompressedClassPointers) {
st->print_cr("\tlwu t0, [j_rarg0, oopDesc::klass_offset_in_bytes()]\t# compressed klass");
if (CompressedKlassPointers::shift() != 0) {
st->print_cr("\tdecode_klass_not_null t0, t0");
}
st->print_cr("\tlwu t0, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass");
st->print_cr("\tlwu t2, [t1 + CompiledICData::speculated_klass_offset()]\t# compressed klass");
} else {
st->print_cr("\tld t0, [j_rarg0, oopDesc::klass_offset_in_bytes()]\t# compressed klass");
st->print_cr("\tld t0, [j_rarg0 + oopDesc::klass_offset_in_bytes()]\t# compressed klass");
st->print_cr("\tld t2, [t1 + CompiledICData::speculated_klass_offset()]\t# compressed klass");
}
st->print_cr("\tbeq t0, t1, ic_hit");
st->print_cr("\tbeq t0, t2, ic_hit");
st->print_cr("\tj, SharedRuntime::_ic_miss_stub\t # Inline cache check");
st->print_cr("\tic_hit:");
}
Expand All @@ -1825,10 +1824,10 @@ void MachUEPNode::emit(CodeBuffer& cbuf, PhaseRegAlloc* ra_) const
// This is the unverified entry point.
C2_MacroAssembler _masm(&cbuf);
__ ic_check(CodeEntryAlignment);
// These NOPs are critical so that verified entry point is properly
// 4 bytes aligned for patching by NativeJump::patch_verified_entry()
__ align(NativeInstruction::instruction_size);

// Verified entry point must be properly 4 bytes aligned for patching by NativeJump::patch_verified_entry().
// ic_check() aligns to CodeEntryAlignment >= InteriorEntryAlignment(min 16) > NativeInstruction::instruction_size(4).
assert(((__ offset()) % CodeEntryAlignment) == 0, "Misaligned verified entry point");
}

uint MachUEPNode::size(PhaseRegAlloc* ra_) const
Expand Down
4 changes: 2 additions & 2 deletions src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ AdapterHandlerEntry* SharedRuntime::generate_i2c2i_adapters(MacroAssembler *masm
{
__ block_comment("c2i_unverified_entry {");

__ ic_check(1 /* end_alignment */);
__ ic_check();
__ ld(xmethod, Address(holder, CompiledICData::speculated_method_offset()));

__ bind(ok);
Expand Down Expand Up @@ -1424,7 +1424,7 @@ nmethod* SharedRuntime::generate_native_wrapper(MacroAssembler* masm,
__ verify_oop(receiver);
assert_different_registers(receiver, t0, t1);

__ ic_check(8 /* end_alignment */);
__ ic_check();

int vep_offset = ((intptr_t)__ pc()) - start;

Expand Down

0 comments on commit c2cca52

Please sign in to comment.