Index: src/ia32/builtins-ia32.cc |
diff --git a/src/ia32/builtins-ia32.cc b/src/ia32/builtins-ia32.cc |
index d748d2362234ea67800e4f948a7ce50122750186..84075351a6dbc31ec80e1ed803d29f7eeef063ef 100644 |
--- a/src/ia32/builtins-ia32.cc |
+++ b/src/ia32/builtins-ia32.cc |
@@ -125,19 +125,29 @@ void Builtins::Generate_InOptimizationQueue(MacroAssembler* masm) { |
static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
bool is_api_function, |
- bool count_constructions) { |
+ bool count_constructions, |
+ bool create_memento) { |
// ----------- S t a t e ------------- |
// -- eax: number of arguments |
// -- edi: constructor function |
+ // -- ebx: allocation site or undefined |
// ----------------------------------- |
// Should never count constructions for api objects. |
ASSERT(!is_api_function || !count_constructions); |
+ // Should never create mementos for api functions. (true?) |
Hannes Payer (out of office)
2014/02/11 15:51:23
probably
mvstanton
2014/02/17 15:53:08
Done.
|
+ ASSERT(!is_api_function || !create_memento); |
+ |
// Enter a construct frame. |
{ |
FrameScope scope(masm, StackFrame::CONSTRUCT); |
+ if (create_memento) { |
+ __ AssertUndefinedOrAllocationSite(ebx); |
+ __ push(ebx); |
+ } |
+ |
// Store a smi-tagged arguments count on the stack. |
__ SmiTag(eax); |
__ push(eax); |
@@ -202,20 +212,41 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
// eax: initial map |
__ movzx_b(edi, FieldOperand(eax, Map::kInstanceSizeOffset)); |
__ shl(edi, kPointerSizeLog2); |
+ if (create_memento) { |
+ __ add(edi, Immediate(AllocationMemento::kSize)); |
+ } |
__ Allocate(edi, ebx, edi, no_reg, &rt_call, NO_ALLOCATION_FLAGS); |
+ Factory* factory = masm->isolate()->factory(); |
+ if (create_memento) { |
+ __ sub(edi, Immediate(AllocationMemento::kSize)); |
+ Handle<Map> allocation_memento_map = factory->allocation_memento_map(); |
+ __ mov(Operand(edi, AllocationMemento::kMapOffset), |
+ allocation_memento_map); |
+ // Get the cell or undefined. |
+ Label do_store; |
+ __ mov(ecx, Operand(esp, kPointerSize*2)); |
+ __ cmp(ecx, masm->isolate()->factory()->undefined_value()); |
+ __ j(equal, &do_store); |
+ // ecx is an AllocationSite. We are creating a memento from it, so we |
+ // need to increment the memento create count. |
+ __ add(Operand(ecx, AllocationSite::kPretenureCreateCountOffset), |
+ Immediate(Smi::FromInt(1))); |
+ __ bind(&do_store); |
Hannes Payer (out of office)
2014/02/11 15:51:23
We could also undo the Memento allocation. WDYT?
mvstanton
2014/02/17 15:53:08
Good point, I'll go ahead and fix it to only incre
|
+ __ mov(Operand(edi, AllocationMemento::kAllocationSiteOffset), |
+ ecx); |
+ } |
// Allocated the JSObject, now initialize the fields. |
// eax: initial map |
// ebx: JSObject |
- // edi: start of next object |
+ // edi: start of next object (or memento if create_memento) |
__ mov(Operand(ebx, JSObject::kMapOffset), eax); |
- Factory* factory = masm->isolate()->factory(); |
__ mov(ecx, factory->empty_fixed_array()); |
__ mov(Operand(ebx, JSObject::kPropertiesOffset), ecx); |
__ mov(Operand(ebx, JSObject::kElementsOffset), ecx); |
// Set extra fields in the newly allocated object. |
// eax: initial map |
// ebx: JSObject |
- // edi: start of next object |
+ // edi: start of next object (or memento if create_memento) |
__ lea(ecx, Operand(ebx, JSObject::kHeaderSize)); |
__ mov(edx, factory->undefined_value()); |
if (count_constructions) { |
@@ -233,6 +264,9 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
__ mov(edx, factory->one_pointer_filler_map()); |
} |
__ InitializeFieldsWithFiller(ecx, edi, edx); |
+ if (create_memento) { |
+ __ add(edi, Immediate(AllocationMemento::kSize)); |
+ } |
// Add the object tag to make the JSObject real, so that we can continue |
// and jump into the continuation code at any time from now on. Any |
@@ -323,11 +357,23 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
// Allocate the new receiver object using the runtime call. |
__ bind(&rt_call); |
+ int offset = 0; |
+ if (create_memento) { |
+ // Get the cell or allocation site. |
+ __ mov(edi, Operand(esp, kPointerSize*2)); |
+ __ push(edi); |
+ offset = kPointerSize; |
+ } |
+ |
// Must restore edi (constructor) before calling runtime. |
- __ mov(edi, Operand(esp, 0)); |
+ __ mov(edi, Operand(esp, offset)); |
// edi: function (constructor) |
__ push(edi); |
- __ CallRuntime(Runtime::kNewObject, 1); |
+ if (create_memento) { |
+ __ CallRuntime(Runtime::kNewObjectWithAllocationSite, 2); |
+ } else { |
+ __ CallRuntime(Runtime::kNewObject, 1); |
+ } |
__ mov(ebx, eax); // store result in ebx |
// New object allocated. |
@@ -415,17 +461,17 @@ static void Generate_JSConstructStubHelper(MacroAssembler* masm, |
void Builtins::Generate_JSConstructStubCountdown(MacroAssembler* masm) { |
- Generate_JSConstructStubHelper(masm, false, true); |
+ Generate_JSConstructStubHelper(masm, false, true, true); |
} |
void Builtins::Generate_JSConstructStubGeneric(MacroAssembler* masm) { |
- Generate_JSConstructStubHelper(masm, false, false); |
+ Generate_JSConstructStubHelper(masm, false, false, true); |
} |
void Builtins::Generate_JSConstructStubApi(MacroAssembler* masm) { |
- Generate_JSConstructStubHelper(masm, true, false); |
+ Generate_JSConstructStubHelper(masm, true, false, false); |
} |