Skip to content

Commit ce15d9a

Browse files
author
duke
committed
Backport 0737a5625269773dcf70b95f8b8ac90b3b6cc444
1 parent 89c5659 commit ce15d9a

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

src/hotspot/cpu/riscv/riscv.ad

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1184,6 +1184,8 @@ bool is_CAS(int opcode, bool maybe_volatile)
11841184
}
11851185
}
11861186

1187+
constexpr uint64_t MAJIK_DWORD = 0xabbaabbaabbaabbaull;
1188+
11871189
// predicate controlling translation of CAS
11881190
//
11891191
// returns true if CAS needs to use an acquiring load otherwise false
@@ -1363,10 +1365,15 @@ void MachPrologNode::format(PhaseRegAlloc *ra_, outputStream *st) const {
13631365
st->print("# stack bang size=%d\n\t", framesize);
13641366
}
13651367

1366-
st->print("sd fp, [sp, #%d]\n\t", - 2 * wordSize);
1367-
st->print("sd ra, [sp, #%d]\n\t", - wordSize);
1368-
if (PreserveFramePointer) { st->print("sub fp, sp, #%d\n\t", 2 * wordSize); }
13691368
st->print("sub sp, sp, #%d\n\t", framesize);
1369+
st->print("sd fp, [sp, #%d]\n\t", framesize - 2 * wordSize);
1370+
st->print("sd ra, [sp, #%d]\n\t", framesize - wordSize);
1371+
if (PreserveFramePointer) { st->print("add fp, sp, #%d\n\t", framesize); }
1372+
1373+
if (VerifyStackAtCalls) {
1374+
st->print("mv t2, %ld\n\t", MAJIK_DWORD);
1375+
st->print("sd t2, [sp, #%d]\n\t", framesize - 3 * wordSize);
1376+
}
13701377

13711378
if (C->stub_function() == nullptr) {
13721379
st->print("ld t0, [guard]\n\t");
@@ -1416,6 +1423,11 @@ void MachPrologNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
14161423

14171424
__ build_frame(framesize);
14181425

1426+
if (VerifyStackAtCalls) {
1427+
__ mv(t2, MAJIK_DWORD);
1428+
__ sd(t2, Address(sp, framesize - 3 * wordSize));
1429+
}
1430+
14191431
if (C->stub_function() == nullptr) {
14201432
BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler();
14211433
// Dummy labels for just measuring the code size
@@ -1437,10 +1449,6 @@ void MachPrologNode::emit(C2_MacroAssembler *masm, PhaseRegAlloc *ra_) const {
14371449
bs->nmethod_entry_barrier(masm, slow_path, continuation, guard);
14381450
}
14391451

1440-
if (VerifyStackAtCalls) {
1441-
Unimplemented();
1442-
}
1443-
14441452
C->output()->set_frame_complete(__ offset());
14451453

14461454
if (C->has_mach_constant_base_node()) {
@@ -2430,7 +2438,13 @@ encode %{
24302438
enc_class riscv_enc_call_epilog() %{
24312439
if (VerifyStackAtCalls) {
24322440
// Check that stack depth is unchanged: find majik cookie on stack
2433-
__ call_Unimplemented();
2441+
int framesize = ra_->reg2offset_unchecked(OptoReg::add(ra_->_matcher._old_SP, -3 * VMRegImpl::slots_per_word));
2442+
Label stack_ok;
2443+
__ ld(t1, Address(sp, framesize));
2444+
__ mv(t2, MAJIK_DWORD);
2445+
__ beq(t2, t1, stack_ok);
2446+
__ stop("MAJIK_DWORD not found");
2447+
__ bind(stack_ok);
24342448
}
24352449
%}
24362450

src/hotspot/cpu/riscv/sharedRuntime_riscv.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2486,7 +2486,7 @@ void SharedRuntime::generate_deopt_blob() {
24862486
// EPILOG must remove this many slots.
24872487
// RISCV needs two words for RA (return address) and FP (frame pointer).
24882488
uint SharedRuntime::in_preserve_stack_slots() {
2489-
return 2 * VMRegImpl::slots_per_word;
2489+
return 2 * VMRegImpl::slots_per_word + (VerifyStackAtCalls ? 0 : 2) ;
24902490
}
24912491

24922492
uint SharedRuntime::out_preserve_stack_slots() {

src/hotspot/share/opto/chaitin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2375,7 +2375,7 @@ void PhaseChaitin::dump_frame() const {
23752375
tty->print_cr("saved fp register");
23762376
else if (return_addr == OptoReg::add(reg, 2*VMRegImpl::slots_per_word) &&
23772377
VerifyStackAtCalls)
2378-
tty->print_cr("0xBADB100D +VerifyStackAtCalls");
2378+
tty->print_cr("<Majik cookie> +VerifyStackAtCalls");
23792379
else
23802380
tty->print_cr("in_preserve");
23812381
} else if ((int)OptoReg::reg2stack(reg) < fixed_slots) {

0 commit comments

Comments
 (0)