Index: src/ia32/full-codegen-ia32.cc |
diff --git a/src/ia32/full-codegen-ia32.cc b/src/ia32/full-codegen-ia32.cc |
index 72021b4a9d4eeef30ff8f8f818754442ed589061..a058701aac5dfb6e879da12b151f0e7ceed62c41 100644 |
--- a/src/ia32/full-codegen-ia32.cc |
+++ b/src/ia32/full-codegen-ia32.cc |
@@ -2139,15 +2139,37 @@ void FullCodeGenerator::EmitNamedPropertyAssignment(Assignment* expr) { |
ASSERT(prop != NULL); |
ASSERT(prop->key()->AsLiteral() != NULL); |
+ // If the assignment starts a block of assignments to the same object, |
+ // change to slow case to avoid the quadratic behavior of repeatedly |
+ // adding fast properties. |
+ if (expr->starts_initialization_block()) { |
+ __ push(result_register()); |
+ __ push(Operand(esp, kPointerSize)); // Receiver is now under value. |
+ __ CallRuntime(Runtime::kToSlowProperties, 1); |
+ __ pop(result_register()); |
+ } |
+ |
// Record source code position before IC call. |
SetSourcePosition(expr->position()); |
__ mov(ecx, prop->key()->AsLiteral()->handle()); |
- __ pop(edx); |
+ if (expr->ends_initialization_block()) { |
+ __ mov(edx, Operand(esp, 0)); |
+ } else { |
+ __ pop(edx); |
+ } |
Handle<Code> ic = is_classic_mode() |
? isolate()->builtins()->StoreIC_Initialize() |
: isolate()->builtins()->StoreIC_Initialize_Strict(); |
CallIC(ic, RelocInfo::CODE_TARGET, expr->AssignmentFeedbackId()); |
+ // If the assignment ends an initialization block, revert to fast case. |
+ if (expr->ends_initialization_block()) { |
+ __ push(eax); // Result of assignment, saved even if not needed. |
+ __ push(Operand(esp, kPointerSize)); // Receiver is under value. |
+ __ CallRuntime(Runtime::kToFastProperties, 1); |
+ __ pop(eax); |
+ __ Drop(1); |
+ } |
PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
context()->Plug(eax); |
} |
@@ -2159,8 +2181,23 @@ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
// esp[0] : key |
// esp[kPointerSize] : receiver |
+ // If the assignment starts a block of assignments to the same object, |
+ // change to slow case to avoid the quadratic behavior of repeatedly |
+ // adding fast properties. |
+ if (expr->starts_initialization_block()) { |
+ __ push(result_register()); |
+ // Receiver is now under the key and value. |
+ __ push(Operand(esp, 2 * kPointerSize)); |
+ __ CallRuntime(Runtime::kToSlowProperties, 1); |
+ __ pop(result_register()); |
+ } |
+ |
__ pop(ecx); // Key. |
- __ pop(edx); |
+ if (expr->ends_initialization_block()) { |
+ __ mov(edx, Operand(esp, 0)); // Leave receiver on the stack for later. |
+ } else { |
+ __ pop(edx); |
+ } |
// Record source code position before IC call. |
SetSourcePosition(expr->position()); |
Handle<Code> ic = is_classic_mode() |
@@ -2168,6 +2205,15 @@ void FullCodeGenerator::EmitKeyedPropertyAssignment(Assignment* expr) { |
: isolate()->builtins()->KeyedStoreIC_Initialize_Strict(); |
CallIC(ic, RelocInfo::CODE_TARGET, expr->AssignmentFeedbackId()); |
+ // If the assignment ends an initialization block, revert to fast case. |
+ if (expr->ends_initialization_block()) { |
+ __ pop(edx); |
+ __ push(eax); // Result of assignment, saved even if not needed. |
+ __ push(edx); |
+ __ CallRuntime(Runtime::kToFastProperties, 1); |
+ __ pop(eax); |
+ } |
+ |
PrepareForBailoutForId(expr->AssignmentId(), TOS_REG); |
context()->Plug(eax); |
} |