Skip to content

Instantly share code, notes, and snippets.

@zhengxiaolinX
Last active September 30, 2022 09:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zhengxiaolinX/3151db356a9001f58827d272c8330bb7 to your computer and use it in GitHub Desktop.
Save zhengxiaolinX/3151db356a9001f58827d272c8330bb7 to your computer and use it in GitHub Desktop.
Rewrite IncompressibleRegions (may not look good)
void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm, Label* slow_path, Label* continuation, Label* guard) {
BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
if (bs_nm == NULL) {
return;
}
// Assembler::IncompressibleRegion ir(masm); // Remove our IncompressibleRegion to rewrite it to an instruction-level granularity
Label local_guard;
NMethodPatchingType patching_type = nmethod_patching_type();
if (slow_path == NULL) {
guard = &local_guard;
// ...
__ align(4);
}
__ lwu(t0, *guard);
switch (patching_type) {
case NMethodPatchingType::conc_data_patch:
// ...
__ membar(MacroAssembler::LoadLoad);
case NMethodPatchingType::stw_instruction_and_data_patch:
{
// ...
// ...
// ...
// ...
// ...
// ...
// ...
Address thread_disarmed_addr(xthread, in_bytes(bs_nm->thread_disarmed_offset()));
__ lwu(t1, thread_disarmed_addr);
break;
}
case NMethodPatchingType::conc_instruction_and_data_patch:
{
// ...
// ...
// ...
// ...
// ...
// ...
// ...
// ...
__ la(t1, ExternalAddress((address)&_patching_epoch)); // We have to make things inside 'la' incompressible, transitive
// ...
__ _srli(ra, t0, 32); // Use '_' to prevent compressions
__ _orr(t1, t1, ra); // Use '_' to prevent compressions
// ...
__ lwu(t1, t1);
// ...
__ _slli(t1, t1, 32); // Use '_' to prevent compressions
__ _orr(t0, t0, t1); // Use '_' to prevent compressions
// ...
Address thread_disarmed_and_epoch_addr(xthread, in_bytes(bs_nm->thread_disarmed_offset()));
__ _ld(t1, thread_disarmed_and_epoch_addr); // Note that we have to add a _ld(Register, Address) here, because we only have the _ld(Register, Register, int32_t offset) in the code base; maybe we have to add a _ld(Register, address) as well...
break;
}
default:
ShouldNotReachHere();
}
if (slow_path == NULL) {
Label skip_barrier;
__ _beq(t0, t1, skip_barrier); // Use '_' to prevent compressions
int32_t offset = 0;
__ movptr_with_offset(t0, StubRoutines::riscv::method_entry_barrier(), offset); // We have to make what inside the movptr_with_offset incompressible...
__ _jalr(ra, t0, offset); // Use '_' to prevent compressions
__ _j(skip_barrier); // Use '_' to prevent compressions
__ bind(local_guard);
MacroAssembler::assert_alignment(__ pc());
__ emit_int32(0); // nmethod guard value. Skipped over in common case.
__ bind(skip_barrier);
} else {
__ _beq(t0, t1, *continuation); // Use '_' to prevent compressions
__ _j(*slow_path); // Use '_' to prevent compressions
__ bind(*continuation);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment