@@ -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
0 commit comments