From 912ea36474727c25cc0feb46eb92c77f59536bb1 Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Thu, 6 May 2021 12:12:37 +0800 Subject: [PATCH] 8266609: AArch64: include FP/LR space in LIR_Assembler::initial_frame_size_in_bytes() LIR_Assembler::initial_frame_size_in_bytes() returns the frame size without the additional 2*wordSize needed to store FP/LR (i.e. just the space required for the C1 locals). When we pass this value to MacroAssembler build_frame and remove_frame we need to remember to add back the 2*wordSize. This patch changes initial_frame_size_in_bytes() to return the full frame size including the space for FP/LR. The PPC and S390 ports already do this, and it also matches the behaviour of C->output()->frame_size_in_bytes() in C2. This change may seem a bit trivial in mainline but the Valhalla lworld branch makes more calls to build_frame/remove_frame in C1 and keeping track of whether "framesize" is with or without FP/LR quickly becomes confusing. Tested tier1 on AArch64. The only use of this function is as input to C1_MacroAssembler build_frame() and remove_frame() so seems safe. --- src/hotspot/cpu/aarch64/aarch64.ad | 1 - src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp | 5 +---- src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp | 6 +++--- src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp | 6 ++++-- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/hotspot/cpu/aarch64/aarch64.ad b/src/hotspot/cpu/aarch64/aarch64.ad index f7963197b62fe..caa1574ad410f 100644 --- a/src/hotspot/cpu/aarch64/aarch64.ad +++ b/src/hotspot/cpu/aarch64/aarch64.ad @@ -1886,7 +1886,6 @@ void MachPrologNode::emit(CodeBuffer &cbuf, PhaseRegAlloc *ra_) const { // n.b. frame size includes space for return pc and rfp const int framesize = C->output()->frame_size_in_bytes(); - assert(framesize%(2*wordSize) == 0, "must preserve 2*wordSize alignment"); // insert a nop at the start of the prolog so we can patch in a // branch if we need to invalidate the method later diff --git a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp index 26051c1784695..d8875a14e0f9c 100644 --- a/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c1_LIRAssembler_aarch64.cpp @@ -374,10 +374,7 @@ void LIR_Assembler::jobject2reg_with_patching(Register reg, CodeEmitInfo *info) int LIR_Assembler::initial_frame_size_in_bytes() const { // if rounding, must let FrameMap know! - // The frame_map records size in slots (32bit word) - - // subtract two words to account for return address and link - return (frame_map()->framesize() - (2*VMRegImpl::slots_per_word)) * VMRegImpl::stack_slot_size; + return in_bytes(frame_map()->framesize_in_bytes()); } diff --git a/src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp index 0616ecc1eb913..6ce4af0372d6c 100644 --- a/src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/c1_MacroAssembler_aarch64.cpp @@ -341,9 +341,9 @@ void C1_MacroAssembler::inline_cache_check(Register receiver, Register iCache) { void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) { assert(bang_size_in_bytes >= framesize, "stack bang size incorrect"); // Make sure there is enough stack space for this method's activation. - // Note that we do this before doing an enter(). + // Note that we do this before creating a frame. generate_stack_overflow_check(bang_size_in_bytes); - MacroAssembler::build_frame(framesize + 2 * wordSize); + MacroAssembler::build_frame(framesize); // Insert nmethod entry barrier into frame. BarrierSetAssembler* bs = BarrierSet::barrier_set()->barrier_set_assembler(); @@ -351,7 +351,7 @@ void C1_MacroAssembler::build_frame(int framesize, int bang_size_in_bytes) { } void C1_MacroAssembler::remove_frame(int framesize) { - MacroAssembler::remove_frame(framesize + 2 * wordSize); + MacroAssembler::remove_frame(framesize); } diff --git a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp index 6e961e575939d..3790951778b0c 100644 --- a/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp +++ b/src/hotspot/cpu/aarch64/macroAssembler_aarch64.cpp @@ -4438,7 +4438,8 @@ void MacroAssembler::load_byte_map_base(Register reg) { } void MacroAssembler::build_frame(int framesize) { - assert(framesize > 0, "framesize must be > 0"); + assert(framesize >= 2 * wordSize, "framesize must include space for FP/LR"); + assert(framesize % (2*wordSize) == 0, "must preserve 2*wordSize alignment"); if (framesize < ((1 << 9) + 2 * wordSize)) { sub(sp, sp, framesize); stp(rfp, lr, Address(sp, framesize - 2 * wordSize)); @@ -4457,7 +4458,8 @@ void MacroAssembler::build_frame(int framesize) { } void MacroAssembler::remove_frame(int framesize) { - assert(framesize > 0, "framesize must be > 0"); + assert(framesize >= 2 * wordSize, "framesize must include space for FP/LR"); + assert(framesize % (2*wordSize) == 0, "must preserve 2*wordSize alignment"); if (framesize < ((1 << 9) + 2 * wordSize)) { ldp(rfp, lr, Address(sp, framesize - 2 * wordSize)); add(sp, sp, framesize);