diff --git a/src/arm/full-codegen-arm.cc b/src/arm/full-codegen-arm.cc index 3fd57d2cc4..efbeb1783b 100644 --- a/src/arm/full-codegen-arm.cc +++ b/src/arm/full-codegen-arm.cc @@ -171,8 +171,7 @@ void FullCodeGenerator::Generate() { FrameScope frame_scope(masm_, StackFrame::MANUAL); info->set_prologue_offset(masm_->pc_offset()); - ASSERT(!info->IsStub()); - __ Prologue(info); + __ Prologue(info->IsCodePreAgingActive()); info->AddNoFrameRange(0, masm_->pc_offset()); { Comment cmnt(masm_, "[ Allocate locals"); diff --git a/src/arm/lithium-codegen-arm.cc b/src/arm/lithium-codegen-arm.cc index 86aa0b5d52..0b9411bf77 100644 --- a/src/arm/lithium-codegen-arm.cc +++ b/src/arm/lithium-codegen-arm.cc @@ -140,7 +140,11 @@ bool LCodeGen::GeneratePrologue() { info()->set_prologue_offset(masm_->pc_offset()); if (NeedsEagerFrame()) { - __ Prologue(info()); + if (info()->IsStub()) { + __ StubPrologue(); + } else { + __ Prologue(info()->IsCodePreAgingActive()); + } frame_is_built_ = true; info_->AddNoFrameRange(0, masm_->pc_offset()); } diff --git a/src/arm/macro-assembler-arm.cc b/src/arm/macro-assembler-arm.cc index f354843e4a..25bb678cd5 100644 --- a/src/arm/macro-assembler-arm.cc +++ b/src/arm/macro-assembler-arm.cc @@ -902,29 +902,34 @@ void MacroAssembler::LoadConstantPoolPointerRegister() { } -void MacroAssembler::Prologue(CompilationInfo* info) { - if (info->IsStub()) { - PushFixedFrame(); - Push(Smi::FromInt(StackFrame::STUB)); +void MacroAssembler::StubPrologue() { + PushFixedFrame(); + Push(Smi::FromInt(StackFrame::STUB)); + // Adjust FP to point to saved FP. + add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); + if (FLAG_enable_ool_constant_pool) { + LoadConstantPoolPointerRegister(); + set_constant_pool_available(true); + } +} + + +void MacroAssembler::Prologue(bool code_pre_aging) { + PredictableCodeSizeScope predictible_code_size_scope( + this, kNoCodeAgeSequenceLength); + // The following three instructions must remain together and unmodified + // for code aging to work properly. + if (code_pre_aging) { + // Pre-age the code. + Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); + add(r0, pc, Operand(-8)); + ldr(pc, MemOperand(pc, -4)); + emit_code_stub_address(stub); + } else { + PushFixedFrame(r1); + nop(ip.code()); // Adjust FP to point to saved FP. add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); - } else { - PredictableCodeSizeScope predictible_code_size_scope( - this, kNoCodeAgeSequenceLength); - // The following three instructions must remain together and unmodified - // for code aging to work properly. - if (info->IsCodePreAgingActive()) { - // Pre-age the code. - Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); - add(r0, pc, Operand(-8)); - ldr(pc, MemOperand(pc, -4)); - emit_code_stub_address(stub); - } else { - PushFixedFrame(r1); - nop(ip.code()); - // Adjust FP to point to saved FP. - add(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); - } } if (FLAG_enable_ool_constant_pool) { LoadConstantPoolPointerRegister(); diff --git a/src/arm/macro-assembler-arm.h b/src/arm/macro-assembler-arm.h index 9a2ee7a17d..98d2087179 100644 --- a/src/arm/macro-assembler-arm.h +++ b/src/arm/macro-assembler-arm.h @@ -519,7 +519,8 @@ class MacroAssembler: public Assembler { Label* not_int32); // Generates function and stub prologue code. - void Prologue(CompilationInfo* info); + void StubPrologue(); + void Prologue(bool code_pre_aging); // Enter exit frame. // stack_space - extra stack space, used for alignment before call to C. diff --git a/src/arm64/full-codegen-arm64.cc b/src/arm64/full-codegen-arm64.cc index 11acbb7803..c3f4a3d31b 100644 --- a/src/arm64/full-codegen-arm64.cc +++ b/src/arm64/full-codegen-arm64.cc @@ -170,8 +170,7 @@ void FullCodeGenerator::Generate() { // Push(lr, fp, cp, x1); // Add(fp, jssp, 2 * kPointerSize); info->set_prologue_offset(masm_->pc_offset()); - ASSERT(!info->IsStub()); - __ Prologue(info); + __ Prologue(info->IsCodePreAgingActive()); info->AddNoFrameRange(0, masm_->pc_offset()); // Reserve space on the stack for locals. diff --git a/src/arm64/lithium-codegen-arm64.cc b/src/arm64/lithium-codegen-arm64.cc index e070146c94..e35806acb5 100644 --- a/src/arm64/lithium-codegen-arm64.cc +++ b/src/arm64/lithium-codegen-arm64.cc @@ -671,7 +671,11 @@ bool LCodeGen::GeneratePrologue() { ASSERT(__ StackPointer().Is(jssp)); info()->set_prologue_offset(masm_->pc_offset()); if (NeedsEagerFrame()) { - __ Prologue(info()); + if (info()->IsStub()) { + __ StubPrologue(); + } else { + __ Prologue(info()->IsCodePreAgingActive()); + } frame_is_built_ = true; info_->AddNoFrameRange(0, masm_->pc_offset()); } diff --git a/src/arm64/macro-assembler-arm64.cc b/src/arm64/macro-assembler-arm64.cc index d35e69ca19..73126e6d04 100644 --- a/src/arm64/macro-assembler-arm64.cc +++ b/src/arm64/macro-assembler-arm64.cc @@ -2992,23 +2992,24 @@ void MacroAssembler::TruncateHeapNumberToI(Register result, } -void MacroAssembler::Prologue(CompilationInfo* info) { - if (info->IsStub()) { - ASSERT(StackPointer().Is(jssp)); - UseScratchRegisterScope temps(this); - Register temp = temps.AcquireX(); - __ Mov(temp, Smi::FromInt(StackFrame::STUB)); - // Compiled stubs don't age, and so they don't need the predictable code - // ageing sequence. - __ Push(lr, fp, cp, temp); - __ Add(fp, jssp, StandardFrameConstants::kFixedFrameSizeFromFp); +void MacroAssembler::StubPrologue() { + ASSERT(StackPointer().Is(jssp)); + UseScratchRegisterScope temps(this); + Register temp = temps.AcquireX(); + __ Mov(temp, Smi::FromInt(StackFrame::STUB)); + // Compiled stubs don't age, and so they don't need the predictable code + // ageing sequence. + __ Push(lr, fp, cp, temp); + __ Add(fp, jssp, StandardFrameConstants::kFixedFrameSizeFromFp); +} + + +void MacroAssembler::Prologue(bool code_pre_aging) { + if (code_pre_aging) { + Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); + __ EmitCodeAgeSequence(stub); } else { - if (info->IsCodePreAgingActive()) { - Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); - __ EmitCodeAgeSequence(stub); - } else { - __ EmitFrameSetupForCodeAgePatching(); - } + __ EmitFrameSetupForCodeAgePatching(); } } diff --git a/src/arm64/macro-assembler-arm64.h b/src/arm64/macro-assembler-arm64.h index a817958328..1f3aa14eae 100644 --- a/src/arm64/macro-assembler-arm64.h +++ b/src/arm64/macro-assembler-arm64.h @@ -1652,7 +1652,8 @@ class MacroAssembler : public Assembler { void ExitFrameRestoreFPRegs(); // Generates function and stub prologue code. - void Prologue(CompilationInfo* info); + void StubPrologue(); + void Prologue(bool code_pre_aging); // Enter exit frame. Exit frames are used when calling C code from generated // (JavaScript) code. diff --git a/src/full-codegen.h b/src/full-codegen.h index f03e6e848d..44dd9b1972 100644 --- a/src/full-codegen.h +++ b/src/full-codegen.h @@ -74,6 +74,7 @@ class FullCodeGenerator: public AstVisitor { info->zone()), back_edges_(2, info->zone()), ic_total_count_(0) { + ASSERT(!info->IsStub()); Initialize(); } diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc index 5250e1ed82..bd98ffa681 100644 --- a/src/ia32/full-codegen-ia32.cc +++ b/src/ia32/full-codegen-ia32.cc @@ -157,8 +157,7 @@ void FullCodeGenerator::Generate() { FrameScope frame_scope(masm_, StackFrame::MANUAL); info->set_prologue_offset(masm_->pc_offset()); - ASSERT(!info->IsStub()); - __ Prologue(info); + __ Prologue(info->IsCodePreAgingActive()); info->AddNoFrameRange(0, masm_->pc_offset()); { Comment cmnt(masm_, "[ Allocate locals"); diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc index 12ca48f089..159fd3d038 100644 --- a/src/ia32/lithium-codegen-ia32.cc +++ b/src/ia32/lithium-codegen-ia32.cc @@ -188,7 +188,11 @@ bool LCodeGen::GeneratePrologue() { if (NeedsEagerFrame()) { ASSERT(!frame_is_built_); frame_is_built_ = true; - __ Prologue(info()); + if (info()->IsStub()) { + __ StubPrologue(); + } else { + __ Prologue(info()->IsCodePreAgingActive()); + } info()->AddNoFrameRange(0, masm_->pc_offset()); } diff --git a/src/ia32/macro-assembler-ia32.cc b/src/ia32/macro-assembler-ia32.cc index c4b26cd1bf..2eb0fe4b50 100644 --- a/src/ia32/macro-assembler-ia32.cc +++ b/src/ia32/macro-assembler-ia32.cc @@ -900,26 +900,27 @@ void MacroAssembler::AssertNotSmi(Register object) { } -void MacroAssembler::Prologue(CompilationInfo* info) { - if (info->IsStub()) { +void MacroAssembler::StubPrologue() { + push(ebp); // Caller's frame pointer. + mov(ebp, esp); + push(esi); // Callee's context. + push(Immediate(Smi::FromInt(StackFrame::STUB))); +} + + +void MacroAssembler::Prologue(bool code_pre_aging) { + PredictableCodeSizeScope predictible_code_size_scope(this, + kNoCodeAgeSequenceLength); + if (code_pre_aging) { + // Pre-age the code. + call(isolate()->builtins()->MarkCodeAsExecutedOnce(), + RelocInfo::CODE_AGE_SEQUENCE); + Nop(kNoCodeAgeSequenceLength - Assembler::kCallInstructionLength); + } else { push(ebp); // Caller's frame pointer. mov(ebp, esp); push(esi); // Callee's context. - push(Immediate(Smi::FromInt(StackFrame::STUB))); - } else { - PredictableCodeSizeScope predictible_code_size_scope(this, - kNoCodeAgeSequenceLength); - if (info->IsCodePreAgingActive()) { - // Pre-age the code. - call(isolate()->builtins()->MarkCodeAsExecutedOnce(), - RelocInfo::CODE_AGE_SEQUENCE); - Nop(kNoCodeAgeSequenceLength - Assembler::kCallInstructionLength); - } else { - push(ebp); // Caller's frame pointer. - mov(ebp, esp); - push(esi); // Callee's context. - push(edi); // Callee's JS function. - } + push(edi); // Callee's JS function. } } diff --git a/src/ia32/macro-assembler-ia32.h b/src/ia32/macro-assembler-ia32.h index 4b7f7fce1a..71e7427d2d 100644 --- a/src/ia32/macro-assembler-ia32.h +++ b/src/ia32/macro-assembler-ia32.h @@ -204,7 +204,8 @@ class MacroAssembler: public Assembler { void DebugBreak(); // Generates function and stub prologue code. - void Prologue(CompilationInfo* info); + void StubPrologue(); + void Prologue(bool code_pre_aging); // Enter specific kind of exit frame. Expects the number of // arguments in register eax and sets up the number of arguments in diff --git a/src/mips/full-codegen-mips.cc b/src/mips/full-codegen-mips.cc index d80ec0ee78..736e8c3c50 100644 --- a/src/mips/full-codegen-mips.cc +++ b/src/mips/full-codegen-mips.cc @@ -176,8 +176,7 @@ void FullCodeGenerator::Generate() { FrameScope frame_scope(masm_, StackFrame::MANUAL); info->set_prologue_offset(masm_->pc_offset()); - ASSERT(!info->IsStub()); - __ Prologue(info); + __ Prologue(info->IsCodePreAgingActive()); info->AddNoFrameRange(0, masm_->pc_offset()); { Comment cmnt(masm_, "[ Allocate locals"); diff --git a/src/mips/lithium-codegen-mips.cc b/src/mips/lithium-codegen-mips.cc index e09feea3ee..d33cbb134d 100644 --- a/src/mips/lithium-codegen-mips.cc +++ b/src/mips/lithium-codegen-mips.cc @@ -162,7 +162,11 @@ bool LCodeGen::GeneratePrologue() { info()->set_prologue_offset(masm_->pc_offset()); if (NeedsEagerFrame()) { - __ Prologue(info()); + if (info()->IsStub()) { + __ StubPrologue(); + } else { + __ Prologue(info()->IsCodePreAgingActive()); + } frame_is_built_ = true; info_->AddNoFrameRange(0, masm_->pc_offset()); } diff --git a/src/mips/macro-assembler-mips.cc b/src/mips/macro-assembler-mips.cc index fa2e813bba..98b1da7484 100644 --- a/src/mips/macro-assembler-mips.cc +++ b/src/mips/macro-assembler-mips.cc @@ -4452,36 +4452,37 @@ void MacroAssembler::LoadGlobalFunctionInitialMap(Register function, } -void MacroAssembler::Prologue(CompilationInfo* info) { - if (info->IsStub()) { +void MacroAssembler::StubPrologue() { Push(ra, fp, cp); Push(Smi::FromInt(StackFrame::STUB)); // Adjust FP to point to saved FP. Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); - } else { - PredictableCodeSizeScope predictible_code_size_scope( +} + + +void MacroAssembler::Prologue(bool code_pre_aging) { + PredictableCodeSizeScope predictible_code_size_scope( this, kNoCodeAgeSequenceLength); - // The following three instructions must remain together and unmodified - // for code aging to work properly. - if (info->IsCodePreAgingActive()) { - // Pre-age the code. - Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); - nop(Assembler::CODE_AGE_MARKER_NOP); - // Load the stub address to t9 and call it, - // GetCodeAgeAndParity() extracts the stub address from this instruction. - li(t9, - Operand(reinterpret_cast(stub->instruction_start())), - CONSTANT_SIZE); - nop(); // Prevent jalr to jal optimization. - jalr(t9, a0); - nop(); // Branch delay slot nop. - nop(); // Pad the empty space. - } else { - Push(ra, fp, cp, a1); - nop(Assembler::CODE_AGE_SEQUENCE_NOP); - // Adjust fp to point to caller's fp. - Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); - } + // The following three instructions must remain together and unmodified + // for code aging to work properly. + if (code_pre_aging) { + // Pre-age the code. + Code* stub = Code::GetPreAgedCodeAgeStub(isolate()); + nop(Assembler::CODE_AGE_MARKER_NOP); + // Load the stub address to t9 and call it, + // GetCodeAgeAndParity() extracts the stub address from this instruction. + li(t9, + Operand(reinterpret_cast(stub->instruction_start())), + CONSTANT_SIZE); + nop(); // Prevent jalr to jal optimization. + jalr(t9, a0); + nop(); // Branch delay slot nop. + nop(); // Pad the empty space. + } else { + Push(ra, fp, cp, a1); + nop(Assembler::CODE_AGE_SEQUENCE_NOP); + // Adjust fp to point to caller's fp. + Addu(fp, sp, Operand(StandardFrameConstants::kFixedFrameSizeFromFp)); } } diff --git a/src/mips/macro-assembler-mips.h b/src/mips/macro-assembler-mips.h index e800aae530..1f815d91c0 100644 --- a/src/mips/macro-assembler-mips.h +++ b/src/mips/macro-assembler-mips.h @@ -1492,7 +1492,8 @@ const Operand& rt = Operand(zero_reg), BranchDelaySlot bd = PROTECT } // Generates function and stub prologue code. - void Prologue(CompilationInfo* info); + void StubPrologue(); + void Prologue(bool code_pre_aging); // Activation support. void EnterFrame(StackFrame::Type type); diff --git a/src/x64/full-codegen-x64.cc b/src/x64/full-codegen-x64.cc index a5e3464292..81b3b0be7d 100644 --- a/src/x64/full-codegen-x64.cc +++ b/src/x64/full-codegen-x64.cc @@ -157,8 +157,7 @@ void FullCodeGenerator::Generate() { FrameScope frame_scope(masm_, StackFrame::MANUAL); info->set_prologue_offset(masm_->pc_offset()); - ASSERT(!info->IsStub()); - __ Prologue(info); + __ Prologue(info->IsCodePreAgingActive()); info->AddNoFrameRange(0, masm_->pc_offset()); { Comment cmnt(masm_, "[ Allocate locals"); diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc index 113fd89ba7..c928523f44 100644 --- a/src/x64/lithium-codegen-x64.cc +++ b/src/x64/lithium-codegen-x64.cc @@ -149,7 +149,11 @@ bool LCodeGen::GeneratePrologue() { if (NeedsEagerFrame()) { ASSERT(!frame_is_built_); frame_is_built_ = true; - __ Prologue(info()); + if (info()->IsStub()) { + __ StubPrologue(); + } else { + __ Prologue(info()->IsCodePreAgingActive()); + } info()->AddNoFrameRange(0, masm_->pc_offset()); } diff --git a/src/x64/macro-assembler-x64.cc b/src/x64/macro-assembler-x64.cc index 8cbc0f66d5..14c3fa976b 100644 --- a/src/x64/macro-assembler-x64.cc +++ b/src/x64/macro-assembler-x64.cc @@ -3889,26 +3889,27 @@ void MacroAssembler::InvokePrologue(const ParameterCount& expected, } -void MacroAssembler::Prologue(CompilationInfo* info) { - if (info->IsStub()) { +void MacroAssembler::StubPrologue() { pushq(rbp); // Caller's frame pointer. movp(rbp, rsp); Push(rsi); // Callee's context. Push(Smi::FromInt(StackFrame::STUB)); +} + + +void MacroAssembler::Prologue(bool code_pre_aging) { + PredictableCodeSizeScope predictible_code_size_scope(this, + kNoCodeAgeSequenceLength); + if (code_pre_aging) { + // Pre-age the code. + Call(isolate()->builtins()->MarkCodeAsExecutedOnce(), + RelocInfo::CODE_AGE_SEQUENCE); + Nop(kNoCodeAgeSequenceLength - Assembler::kShortCallInstructionLength); } else { - PredictableCodeSizeScope predictible_code_size_scope(this, - kNoCodeAgeSequenceLength); - if (info->IsCodePreAgingActive()) { - // Pre-age the code. - Call(isolate()->builtins()->MarkCodeAsExecutedOnce(), - RelocInfo::CODE_AGE_SEQUENCE); - Nop(kNoCodeAgeSequenceLength - Assembler::kShortCallInstructionLength); - } else { - pushq(rbp); // Caller's frame pointer. - movp(rbp, rsp); - Push(rsi); // Callee's context. - Push(rdi); // Callee's JS function. - } + pushq(rbp); // Caller's frame pointer. + movp(rbp, rsp); + Push(rsi); // Callee's context. + Push(rdi); // Callee's JS function. } } diff --git a/src/x64/macro-assembler-x64.h b/src/x64/macro-assembler-x64.h index c85434a9be..b110f3a1f1 100644 --- a/src/x64/macro-assembler-x64.h +++ b/src/x64/macro-assembler-x64.h @@ -274,7 +274,8 @@ class MacroAssembler: public Assembler { void DebugBreak(); // Generates function and stub prologue code. - void Prologue(CompilationInfo* info); + void StubPrologue(); + void Prologue(bool code_pre_aging); // Enter specific kind of exit frame; either in normal or // debug mode. Expects the number of arguments in register rax and