Commit 3285e3bf authored by mlippautz's avatar mlippautz Committed by Commit bot

Fix memento initialization when constructing from new call

Additionally, push the allocation site or undefined independently of creating a memento to preserve a fixed size for the construct frames.

BUG=

Review URL: https://codereview.chromium.org/1239593003

Cr-Commit-Position: refs/heads/master@{#29719}
parent 40f0df5c
...@@ -332,12 +332,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -332,12 +332,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
{ {
FrameAndConstantPoolScope scope(masm, StackFrame::CONSTRUCT); FrameAndConstantPoolScope scope(masm, StackFrame::CONSTRUCT);
if (create_memento) {
__ AssertUndefinedOrAllocationSite(r2, r4);
__ push(r2);
}
// Preserve the incoming parameters on the stack. // Preserve the incoming parameters on the stack.
__ AssertUndefinedOrAllocationSite(r2, r4);
__ push(r2);
__ SmiTag(r0); __ SmiTag(r0);
__ push(r0); __ push(r0);
__ push(r1); __ push(r1);
...@@ -476,7 +473,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -476,7 +473,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
DCHECK_EQ(0 * kPointerSize, AllocationMemento::kMapOffset); DCHECK_EQ(0 * kPointerSize, AllocationMemento::kMapOffset);
__ str(r6, MemOperand(r5, kPointerSize, PostIndex)); __ str(r6, MemOperand(r5, kPointerSize, PostIndex));
// Load the AllocationSite // Load the AllocationSite
__ ldr(r6, MemOperand(sp, 2 * kPointerSize)); __ ldr(r6, MemOperand(sp, 3 * kPointerSize));
__ AssertUndefinedOrAllocationSite(r6, r0);
DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset); DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset);
__ str(r6, MemOperand(r5, kPointerSize, PostIndex)); __ str(r6, MemOperand(r5, kPointerSize, PostIndex));
} else { } else {
...@@ -664,12 +662,12 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { ...@@ -664,12 +662,12 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
// -- sp[...]: constructor arguments // -- sp[...]: constructor arguments
// ----------------------------------- // -----------------------------------
// TODO(dslomov): support pretenuring
CHECK(!FLAG_pretenuring_call_new);
{ {
FrameScope frame_scope(masm, StackFrame::CONSTRUCT); FrameScope frame_scope(masm, StackFrame::CONSTRUCT);
__ AssertUndefinedOrAllocationSite(r2, r4);
__ push(r2);
__ mov(r4, r0); __ mov(r4, r0);
__ SmiTag(r4); __ SmiTag(r4);
__ push(r4); // Smi-tagged arguments count. __ push(r4); // Smi-tagged arguments count.
......
...@@ -324,22 +324,20 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -324,22 +324,20 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
{ {
FrameScope scope(masm, StackFrame::CONSTRUCT); FrameScope scope(masm, StackFrame::CONSTRUCT);
// Preserve the three incoming parameters on the stack. // Preserve the four incoming parameters on the stack.
if (create_memento) {
__ AssertUndefinedOrAllocationSite(x2, x10);
__ Push(x2);
}
Register argc = x0; Register argc = x0;
Register constructor = x1; Register constructor = x1;
Register allocation_site = x2;
Register original_constructor = x3; Register original_constructor = x3;
// Preserve the incoming parameters on the stack. // Preserve the incoming parameters on the stack.
__ AssertUndefinedOrAllocationSite(allocation_site, x10);
__ SmiTag(argc); __ SmiTag(argc);
__ Push(argc, constructor, original_constructor); __ Push(allocation_site, argc, constructor, original_constructor);
// sp[0]: new.target // sp[0]: new.target
// sp[1]: Constructor function. // sp[1]: Constructor function.
// sp[2]: number of arguments (smi-tagged) // sp[2]: number of arguments (smi-tagged)
// sp[3]: allocation site
// Try to allocate the object without transitioning into C code. If any of // Try to allocate the object without transitioning into C code. If any of
// the preconditions is not met, the code bails out to the runtime call. // the preconditions is not met, the code bails out to the runtime call.
...@@ -483,7 +481,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -483,7 +481,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
DCHECK_EQ(0 * kPointerSize, AllocationMemento::kMapOffset); DCHECK_EQ(0 * kPointerSize, AllocationMemento::kMapOffset);
__ Str(x14, MemOperand(first_prop, kPointerSize, PostIndex)); __ Str(x14, MemOperand(first_prop, kPointerSize, PostIndex));
// Load the AllocationSite // Load the AllocationSite
__ Peek(x14, 2 * kXRegSize); __ Peek(x14, 3 * kXRegSize);
__ AssertUndefinedOrAllocationSite(x14, x10);
DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset); DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset);
__ Str(x14, MemOperand(first_prop, kPointerSize, PostIndex)); __ Str(x14, MemOperand(first_prop, kPointerSize, PostIndex));
first_prop = NoReg; first_prop = NoReg;
...@@ -669,18 +668,18 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { ...@@ -669,18 +668,18 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
// ----------------------------------- // -----------------------------------
ASM_LOCATION("Builtins::Generate_JSConstructStubForDerived"); ASM_LOCATION("Builtins::Generate_JSConstructStubForDerived");
// TODO(dslomov): support pretenuring
CHECK(!FLAG_pretenuring_call_new);
{ {
FrameScope frame_scope(masm, StackFrame::CONSTRUCT); FrameScope frame_scope(masm, StackFrame::CONSTRUCT);
__ AssertUndefinedOrAllocationSite(x2, x10);
__ Mov(x4, x0); __ Mov(x4, x0);
__ SmiTag(x4); __ SmiTag(x4);
__ LoadRoot(x10, Heap::kTheHoleValueRootIndex); __ LoadRoot(x10, Heap::kTheHoleValueRootIndex);
__ Push(x4, x3, x10); __ Push(x2, x4, x3, x10);
// sp[0]: number of arguments // sp[0]: receiver (the hole)
// sp[1]: new.target // sp[1]: new.target
// sp[2]: receiver (the hole) // sp[2]: number of arguments
// sp[3]: allocation site
// Set up pointer to last argument. // Set up pointer to last argument.
__ Add(x2, fp, StandardFrameConstants::kCallerSPOffset); __ Add(x2, fp, StandardFrameConstants::kCallerSPOffset);
......
...@@ -1221,6 +1221,12 @@ void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator, ...@@ -1221,6 +1221,12 @@ void Deoptimizer::DoComputeConstructStubFrame(TranslationIterator* iterator,
output_frame->SetFrameSlot(output_offset, value); output_frame->SetFrameSlot(output_offset, value);
DebugPrintOutputSlot(value, frame_index, output_offset, "code object\n"); DebugPrintOutputSlot(value, frame_index, output_offset, "code object\n");
// The allocation site.
output_offset -= kPointerSize;
value = reinterpret_cast<intptr_t>(isolate_->heap()->undefined_value());
output_frame->SetFrameSlot(output_offset, value);
DebugPrintOutputSlot(value, frame_index, output_offset, "allocation site\n");
// Number of incoming arguments. // Number of incoming arguments.
output_offset -= kPointerSize; output_offset -= kPointerSize;
value = reinterpret_cast<intptr_t>(Smi::FromInt(height - 1)); value = reinterpret_cast<intptr_t>(Smi::FromInt(height - 1));
......
...@@ -738,8 +738,8 @@ Object* JavaScriptFrame::GetOriginalConstructor() const { ...@@ -738,8 +738,8 @@ Object* JavaScriptFrame::GetOriginalConstructor() const {
} }
DCHECK(IsConstructFrame(fp)); DCHECK(IsConstructFrame(fp));
STATIC_ASSERT(ConstructFrameConstants::kOriginalConstructorOffset == STATIC_ASSERT(ConstructFrameConstants::kOriginalConstructorOffset ==
StandardFrameConstants::kExpressionsOffset - 2 * kPointerSize); StandardFrameConstants::kExpressionsOffset - 3 * kPointerSize);
return GetExpression(fp, 2); return GetExpression(fp, 3);
} }
......
...@@ -155,16 +155,18 @@ class ConstructFrameConstants : public AllStatic { ...@@ -155,16 +155,18 @@ class ConstructFrameConstants : public AllStatic {
public: public:
// FP-relative. // FP-relative.
static const int kImplicitReceiverOffset = static const int kImplicitReceiverOffset =
StandardFrameConstants::kExpressionsOffset - 3 * kPointerSize; StandardFrameConstants::kExpressionsOffset - 4 * kPointerSize;
static const int kOriginalConstructorOffset = static const int kOriginalConstructorOffset =
StandardFrameConstants::kExpressionsOffset - 2 * kPointerSize; StandardFrameConstants::kExpressionsOffset - 3 * kPointerSize;
static const int kLengthOffset = static const int kLengthOffset =
StandardFrameConstants::kExpressionsOffset - 2 * kPointerSize;
static const int kAllocationSiteOffset =
StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize; StandardFrameConstants::kExpressionsOffset - 1 * kPointerSize;
static const int kCodeOffset = static const int kCodeOffset =
StandardFrameConstants::kExpressionsOffset - 0 * kPointerSize; StandardFrameConstants::kExpressionsOffset - 0 * kPointerSize;
static const int kFrameSize = static const int kFrameSize =
StandardFrameConstants::kFixedFrameSize + 4 * kPointerSize; StandardFrameConstants::kFixedFrameSize + 5 * kPointerSize;
}; };
......
...@@ -117,12 +117,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -117,12 +117,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
{ {
FrameScope scope(masm, StackFrame::CONSTRUCT); FrameScope scope(masm, StackFrame::CONSTRUCT);
if (create_memento) {
__ AssertUndefinedOrAllocationSite(ebx);
__ push(ebx);
}
// Preserve the incoming parameters on the stack. // Preserve the incoming parameters on the stack.
__ AssertUndefinedOrAllocationSite(ebx);
__ push(ebx);
__ SmiTag(eax); __ SmiTag(eax);
__ push(eax); __ push(eax);
__ push(edi); __ push(edi);
...@@ -254,7 +251,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -254,7 +251,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ mov(Operand(esi, AllocationMemento::kMapOffset), __ mov(Operand(esi, AllocationMemento::kMapOffset),
factory->allocation_memento_map()); factory->allocation_memento_map());
// Get the cell or undefined. // Get the cell or undefined.
__ mov(edx, Operand(esp, kPointerSize*2)); __ mov(edx, Operand(esp, 3 * kPointerSize));
__ AssertUndefinedOrAllocationSite(edx);
__ mov(Operand(esi, AllocationMemento::kAllocationSiteOffset), __ mov(Operand(esi, AllocationMemento::kAllocationSiteOffset),
edx); edx);
} else { } else {
...@@ -422,12 +420,13 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { ...@@ -422,12 +420,13 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
// -- edx: original constructor // -- edx: original constructor
// ----------------------------------- // -----------------------------------
// TODO(dslomov): support pretenuring
CHECK(!FLAG_pretenuring_call_new);
{ {
FrameScope frame_scope(masm, StackFrame::CONSTRUCT); FrameScope frame_scope(masm, StackFrame::CONSTRUCT);
// Preserve allocation site.
__ AssertUndefinedOrAllocationSite(ebx);
__ push(ebx);
// Preserve actual arguments count. // Preserve actual arguments count.
__ SmiTag(eax); __ SmiTag(eax);
__ push(eax); __ push(eax);
......
...@@ -337,14 +337,10 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -337,14 +337,10 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
{ {
FrameScope scope(masm, StackFrame::CONSTRUCT); FrameScope scope(masm, StackFrame::CONSTRUCT);
if (create_memento) {
__ AssertUndefinedOrAllocationSite(a2, t0);
__ push(a2);
}
// Preserve the incoming parameters on the stack. // Preserve the incoming parameters on the stack.
__ AssertUndefinedOrAllocationSite(a2, t0);
__ SmiTag(a0); __ SmiTag(a0);
__ Push(a0, a1, a3); __ Push(a2, a0, a1, a3);
// Try to allocate the object without transitioning into C code. If any of // Try to allocate the object without transitioning into C code. If any of
// the preconditions is not met, the code bails out to the runtime call. // the preconditions is not met, the code bails out to the runtime call.
...@@ -476,7 +472,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -476,7 +472,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ sw(t7, MemOperand(t5)); __ sw(t7, MemOperand(t5));
__ Addu(t5, t5, kPointerSize); __ Addu(t5, t5, kPointerSize);
// Load the AllocationSite. // Load the AllocationSite.
__ lw(t7, MemOperand(sp, 2 * kPointerSize)); __ lw(t7, MemOperand(sp, 3 * kPointerSize));
__ AssertUndefinedOrAllocationSite(a2, t0);
DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset); DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset);
__ sw(t7, MemOperand(t5)); __ sw(t7, MemOperand(t5));
__ Addu(t5, t5, kPointerSize); __ Addu(t5, t5, kPointerSize);
...@@ -659,12 +656,12 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { ...@@ -659,12 +656,12 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
// -- sp[...]: constructor arguments // -- sp[...]: constructor arguments
// ----------------------------------- // -----------------------------------
// TODO(dslomov): support pretenuring
CHECK(!FLAG_pretenuring_call_new);
{ {
FrameScope frame_scope(masm, StackFrame::CONSTRUCT); FrameScope frame_scope(masm, StackFrame::CONSTRUCT);
__ AssertUndefinedOrAllocationSite(a2, t0);
__ push(a2);
__ mov(t0, a0); __ mov(t0, a0);
__ SmiTag(t0); __ SmiTag(t0);
__ push(t0); // Smi-tagged arguments count. __ push(t0); // Smi-tagged arguments count.
......
...@@ -336,14 +336,10 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -336,14 +336,10 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
{ {
FrameScope scope(masm, StackFrame::CONSTRUCT); FrameScope scope(masm, StackFrame::CONSTRUCT);
if (create_memento) {
__ AssertUndefinedOrAllocationSite(a2, t0);
__ push(a2);
}
// Preserve the incoming parameters on the stack. // Preserve the incoming parameters on the stack.
__ AssertUndefinedOrAllocationSite(a2, t0);
__ SmiTag(a0); __ SmiTag(a0);
__ Push(a0, a1, a3); __ Push(a2, a0, a1, a3);
// Try to allocate the object without transitioning into C code. If any of // Try to allocate the object without transitioning into C code. If any of
// the preconditions is not met, the code bails out to the runtime call. // the preconditions is not met, the code bails out to the runtime call.
...@@ -476,7 +472,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -476,7 +472,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ sd(t3, MemOperand(t1)); __ sd(t3, MemOperand(t1));
__ Daddu(t1, t1, kPointerSize); __ Daddu(t1, t1, kPointerSize);
// Load the AllocationSite. // Load the AllocationSite.
__ ld(t3, MemOperand(sp, 2 * kPointerSize)); __ ld(t3, MemOperand(sp, 3 * kPointerSize));
__ AssertUndefinedOrAllocationSite(t3, a0);
DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset); DCHECK_EQ(1 * kPointerSize, AllocationMemento::kAllocationSiteOffset);
__ sd(t3, MemOperand(t1)); __ sd(t3, MemOperand(t1));
__ Daddu(t1, t1, kPointerSize); __ Daddu(t1, t1, kPointerSize);
...@@ -658,12 +655,12 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { ...@@ -658,12 +655,12 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
// -- sp[...]: constructor arguments // -- sp[...]: constructor arguments
// ----------------------------------- // -----------------------------------
// TODO(dslomov): support pretenuring
CHECK(!FLAG_pretenuring_call_new);
{ {
FrameScope frame_scope(masm, StackFrame::CONSTRUCT); FrameScope frame_scope(masm, StackFrame::CONSTRUCT);
__ AssertUndefinedOrAllocationSite(a2, t0);
__ push(a2);
__ mov(a4, a0); __ mov(a4, a0);
__ SmiTag(a4); __ SmiTag(a4);
__ push(a4); // Smi-tagged arguments count. __ push(a4); // Smi-tagged arguments count.
......
...@@ -116,12 +116,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -116,12 +116,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
{ {
FrameScope scope(masm, StackFrame::CONSTRUCT); FrameScope scope(masm, StackFrame::CONSTRUCT);
if (create_memento) {
__ AssertUndefinedOrAllocationSite(rbx);
__ Push(rbx);
}
// Preserve the incoming parameters on the stack. // Preserve the incoming parameters on the stack.
__ AssertUndefinedOrAllocationSite(rbx);
__ Push(rbx);
__ Integer32ToSmi(rax, rax); __ Integer32ToSmi(rax, rax);
__ Push(rax); __ Push(rax);
__ Push(rdi); __ Push(rdi);
...@@ -254,7 +251,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, ...@@ -254,7 +251,8 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm,
__ Move(Operand(rsi, AllocationMemento::kMapOffset), __ Move(Operand(rsi, AllocationMemento::kMapOffset),
factory->allocation_memento_map()); factory->allocation_memento_map());
// Get the cell or undefined. // Get the cell or undefined.
__ movp(rdx, Operand(rsp, kPointerSize*2)); __ movp(rdx, Operand(rsp, 3 * kPointerSize));
__ AssertUndefinedOrAllocationSite(rdx);
__ movp(Operand(rsi, AllocationMemento::kAllocationSiteOffset), rdx); __ movp(Operand(rsi, AllocationMemento::kAllocationSiteOffset), rdx);
} else { } else {
__ InitializeFieldsWithFiller(rcx, rdi, rdx); __ InitializeFieldsWithFiller(rcx, rdi, rdx);
...@@ -420,12 +418,14 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) { ...@@ -420,12 +418,14 @@ void Builtins::Generate_JSConstructStubForDerived(MacroAssembler* masm) {
// -- rbx: allocation site or undefined // -- rbx: allocation site or undefined
// -- rdx: original constructor // -- rdx: original constructor
// ----------------------------------- // -----------------------------------
// TODO(dslomov): support pretenuring
CHECK(!FLAG_pretenuring_call_new);
{ {
FrameScope frame_scope(masm, StackFrame::CONSTRUCT); FrameScope frame_scope(masm, StackFrame::CONSTRUCT);
// Preserve allocation site.
__ AssertUndefinedOrAllocationSite(rbx);
__ Push(rbx);
// Store a smi-tagged arguments count on the stack. // Store a smi-tagged arguments count on the stack.
__ Integer32ToSmi(rax, rax); __ Integer32ToSmi(rax, rax);
__ Push(rax); __ Push(rax);
......
...@@ -101,6 +101,7 @@ TEST(PretenuringCallNew) { ...@@ -101,6 +101,7 @@ TEST(PretenuringCallNew) {
CcTest::InitializeVM(); CcTest::InitializeVM();
if (!i::FLAG_allocation_site_pretenuring) return; if (!i::FLAG_allocation_site_pretenuring) return;
if (!i::FLAG_pretenuring_call_new) return; if (!i::FLAG_pretenuring_call_new) return;
if (i::FLAG_always_opt) return;
v8::HandleScope scope(CcTest::isolate()); v8::HandleScope scope(CcTest::isolate());
Isolate* isolate = CcTest::i_isolate(); Isolate* isolate = CcTest::i_isolate();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment