Skip to content

Commit 238665d

Browse files
committed
Enable RVC instructions (based on the basic patch)
1 parent d79411a commit 238665d

12 files changed

+498
-96
lines changed

src/hotspot/cpu/riscv/assembler_riscv.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ void Assembler::subw(Register Rd, Register Rn, int64_t decrement, Register temp)
8080
}
8181

8282
void Assembler::li(Register Rd, int64_t imm) {
83+
CHECK_CEXT_AND_COMPRESSIBLE(is_imm_in_range(imm, 6, 0) && Rd != x0) {
84+
c_li(Rd, imm);
85+
return;
86+
}
87+
8388
// int64_t is in range 0x8000 0000 0000 0000 ~ 0x7fff ffff ffff ffff
8489
int shift = 12;
8590
int64_t upper = imm, lower = imm;

src/hotspot/cpu/riscv/assembler_riscv.hpp

Lines changed: 99 additions & 84 deletions
Large diffs are not rendered by default.

src/hotspot/cpu/riscv/assembler_riscv_c.hpp

Lines changed: 323 additions & 0 deletions
Large diffs are not rendered by default.

src/hotspot/cpu/riscv/c1_LIRAssembler_riscv.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1322,7 +1322,12 @@ void LIR_Assembler::comp_fl2i(LIR_Code code, LIR_Opr left, LIR_Opr right, LIR_Op
13221322
}
13231323
}
13241324

1325-
void LIR_Assembler::align_call(LIR_Code code) { }
1325+
void LIR_Assembler::align_call(LIR_Code code) {
1326+
// C-Ext: With C-Ext a call may get 2-byte aligned.
1327+
// the address of jal itself (which will be patched later) should not span the cache line.
1328+
// See CallDynamicJavaDirectNode::compute_padding() for more info.
1329+
__ align(4);
1330+
}
13261331

13271332
void LIR_Assembler::call(LIR_OpJavaCall* op, relocInfo::relocType rtype) {
13281333
address call = __ trampoline_call(Address(op->addr(), rtype));

src/hotspot/cpu/riscv/c2_globals_riscv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ define_pd_global(intx, OnStackReplacePercentage, 140);
4646
define_pd_global(intx, ConditionalMoveLimit, 0);
4747
define_pd_global(intx, FreqInlineSize, 325);
4848
define_pd_global(intx, MinJumpTableSize, 10);
49-
define_pd_global(intx, InteriorEntryAlignment, 16);
49+
define_pd_global(intx, InteriorEntryAlignment, 4);
5050
define_pd_global(intx, NewSizeThreadIncrease, ScaleForWordSize(4*K));
5151
define_pd_global(intx, LoopUnrollLimit, 60);
5252
define_pd_global(intx, LoopPercentProfileLimit, 10);

src/hotspot/cpu/riscv/gc/shared/barrierSetAssembler_riscv.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,13 +231,19 @@ void BarrierSetAssembler::incr_allocated_bytes(MacroAssembler* masm,
231231
__ sd(tmp1, Address(xthread, in_bytes(JavaThread::allocated_bytes_offset())));
232232
}
233233

234+
extern int nmethod_barrier_guard_offset();
235+
234236
void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm) {
235237
BarrierSetNMethod* bs_nm = BarrierSet::barrier_set()->barrier_set_nmethod();
236238

237239
if (bs_nm == NULL) {
238240
return;
239241
}
240242

243+
// C-Ext: RISCV's amoswap instructions need an alignment for the memory address it swaps
244+
// when we reach here we may get a 2-byte alignment so need to align it
245+
__ align(4, nmethod_barrier_guard_offset());
246+
241247
Label skip, guard;
242248
Address thread_disarmed_addr(xthread, in_bytes(bs_nm->thread_disarmed_offset()));
243249

@@ -256,6 +262,7 @@ void BarrierSetAssembler::nmethod_entry_barrier(MacroAssembler* masm) {
256262

257263
__ bind(guard);
258264

265+
assert(__ offset() % 4 == 0, "RISCV CAS needs an alignment for memory");
259266
__ emit_int32(0); // nmethod guard value. Skipped over in common case.
260267

261268
__ bind(skip);

src/hotspot/cpu/riscv/gc/shared/barrierSetNMethod_riscv.cpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,18 @@
3636
#include "utilities/debug.hpp"
3737

3838
class NativeNMethodBarrier: public NativeInstruction {
39+
public:
40+
enum {
41+
guard_offset = 12 * instruction_size,
42+
barrier_size = guard_offset + 4, // guard_offset + an int32 nmethod guard value
43+
};
44+
45+
private:
3946
address instruction_address() const { return addr_at(0); }
4047

4148
int *guard_addr() {
4249
/* auipc + lwu + fence + lwu + beq + lui + addi + slli + addi + slli + jalr + j */
43-
return reinterpret_cast<int*>(instruction_address() + 12 * 4);
50+
return reinterpret_cast<int*>(instruction_address() + guard_offset);
4451
}
4552

4653
public:
@@ -55,6 +62,10 @@ class NativeNMethodBarrier: public NativeInstruction {
5562
void verify() const;
5663
};
5764

65+
int nmethod_barrier_guard_offset() {
66+
return NativeNMethodBarrier::guard_offset;
67+
}
68+
5869
// Store the instruction bitmask, bits and name for checking the barrier.
5970
struct CheckInsn {
6071
uint32_t mask;
@@ -141,7 +152,7 @@ void BarrierSetNMethod::deoptimize(nmethod* nm, address* return_address_ptr) {
141152

142153
// see BarrierSetAssembler::nmethod_entry_barrier
143154
// auipc + lwu + fence + lwu + beq + movptr_with_offset(5 instructions) + jalr + j + int32
144-
static const int entry_barrier_offset = -4 * 13;
155+
static const int entry_barrier_offset = - NativeNMethodBarrier::barrier_size;
145156

146157
static NativeNMethodBarrier* native_nmethod_barrier(nmethod* nm) {
147158
address barrier_address = nm->code_begin() + nm->frame_complete_offset() + entry_barrier_offset;

src/hotspot/cpu/riscv/globals_riscv.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ define_pd_global(bool, TrapBasedNullChecks, false);
3737
define_pd_global(bool, UncommonNullCast, true); // Uncommon-trap NULLs past to check cast
3838

3939
define_pd_global(uintx, CodeCacheSegmentSize, 64 COMPILER1_AND_COMPILER2_PRESENT(+64)); // Tiered compilation has large code-entry alignment.
40-
define_pd_global(intx, CodeEntryAlignment, 64);
40+
define_pd_global(intx, CodeEntryAlignment, 16);
4141
define_pd_global(intx, OptoLoopAlignment, 16);
4242

4343
#define DEFAULT_STACK_YELLOW_PAGES (2)

src/hotspot/cpu/riscv/macroAssembler_riscv.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,9 @@ static void pass_arg3(MacroAssembler* masm, Register arg) {
8888
}
8989
}
9090

91-
void MacroAssembler::align(int modulus) {
92-
while (offset() % modulus != 0) { nop(); }
91+
void MacroAssembler::align(int modulus, int extra_offset) {
92+
CompressibleRegion cr(this);
93+
while ((offset() + extra_offset) % modulus != 0) { nop(); }
9394
}
9495

9596
void MacroAssembler::call_VM_helper(Register oop_result, address entry_point, int number_of_arguments, bool check_exceptions) {
@@ -813,6 +814,7 @@ void MacroAssembler::la(Register Rd, Label &label) {
813814

814815
INSN(beq, feq, bnez);
815816
INSN(bne, feq, beqz);
817+
816818
#undef INSN
817819

818820

@@ -2924,7 +2926,8 @@ address MacroAssembler::emit_trampoline_stub(int insts_call_instruction_offset,
29242926

29252927
// make sure 4 byte aligned here, so that the destination address would be
29262928
// 8 byte aligned after 3 intructions
2927-
while (offset() % wordSize == 0) { nop(); }
2929+
// C-Ext: when we reach here we may get a 2-byte alignment so need to align it
2930+
align(wordSize, NativeCallTrampolineStub::data_offset);
29282931

29292932
relocate(trampoline_stub_Relocation::spec(code()->insts()->start() +
29302933
insts_call_instruction_offset));
@@ -2939,6 +2942,7 @@ address MacroAssembler::emit_trampoline_stub(int insts_call_instruction_offset,
29392942
bind(target);
29402943
assert(offset() - stub_start_offset == NativeCallTrampolineStub::data_offset,
29412944
"should be");
2945+
assert(offset() % wordSize == 0, "address loaded by ld must be 8-byte aligned under riscv64");
29422946
emit_int64((intptr_t)dest);
29432947

29442948
const address stub_start_addr = addr_at(stub_start_offset);

src/hotspot/cpu/riscv/macroAssembler_riscv.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class MacroAssembler: public Assembler {
4949
void safepoint_ifence();
5050

5151
// Alignment
52-
void align(int modulus);
52+
void align(int modulus, int extra_offset = 0);
5353

5454
// Stack frame creation/removal
5555
void enter() {
@@ -445,11 +445,11 @@ class MacroAssembler: public Assembler {
445445
void fsflagsi(unsigned imm);
446446

447447
void beqz(Register Rs, const address &dest);
448+
void bnez(Register Rs, const address &dest);
448449
void blez(Register Rs, const address &dest);
449450
void bgez(Register Rs, const address &dest);
450451
void bltz(Register Rs, const address &dest);
451452
void bgtz(Register Rs, const address &dest);
452-
void bnez(Register Rs, const address &dest);
453453
void la(Register Rd, Label &label);
454454
void la(Register Rd, const address &dest);
455455
void la(Register Rd, const Address &adr);

0 commit comments

Comments
 (0)