Index: src/ia32/lithium-codegen-ia32.cc |
diff --git a/src/ia32/lithium-codegen-ia32.cc b/src/ia32/lithium-codegen-ia32.cc |
index 841be732644ca0ae4b080aaddfbef65bd574be07..0f50d7fdc59dcee499f46745f6b0cc305abf7e46 100644 |
--- a/src/ia32/lithium-codegen-ia32.cc |
+++ b/src/ia32/lithium-codegen-ia32.cc |
@@ -4161,7 +4161,82 @@ void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) { |
} |
-void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
+void LCodeGen::EmitDeepCopy(Handle<JSObject> object, |
+ Register result, |
+ Register source, |
+ int* offset) { |
+ ASSERT(!source.is(ecx)); |
+ ASSERT(!result.is(ecx)); |
+ int current_offset = *offset; |
+ |
+ if (FLAG_debug_code && !HEAP->InNewSpace(*object)) { |
+ __ cmp(source, object); |
+ __ Assert(equal, "Unexpected object literal boilerplate"); |
+ } |
+ |
+ // Increase the offset so that subsequent objects end up right after |
+ // this one. |
+ int size = object->map()->instance_size(); |
+ *offset += size; |
+ |
+ // Copy object header. |
+ ASSERT(object->properties()->length() == 0); |
+ ASSERT(object->elements()->length() == 0 || |
+ object->elements()->map() == HEAP->fixed_cow_array_map()); |
+ int inobject_properties = object->map()->inobject_properties(); |
+ int header_size = size - inobject_properties * kPointerSize; |
+ for (int i = 0; i < header_size; i += kPointerSize) { |
+ __ mov(ecx, FieldOperand(source, i)); |
+ __ mov(FieldOperand(result, current_offset + i), ecx); |
+ } |
+ |
+ // Copy in-object properties. |
+ for (int i = 0; i < inobject_properties; i++) { |
fschneider
2011/11/22 17:26:16
Can you instead of cloning the original, just stor
Michael Starzinger
2011/11/23 10:55:32
Done.
|
+ int in_object_offset = object->GetInObjectPropertyOffset(i); |
+ Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); |
+ if (value->IsJSObject()) { |
+ Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
+ __ push(source); |
+ __ mov(source, FieldOperand(source, in_object_offset)); |
+ __ lea(ecx, Operand(result, *offset)); |
fschneider
2011/11/22 17:26:16
Replace the 3 lines above with:
__ LoadHeapObject
Michael Starzinger
2011/11/23 10:55:32
Done. As discussed offline, ecx needs to be loaded
|
+ __ mov(FieldOperand(result, current_offset + in_object_offset), ecx); |
+ EmitDeepCopy(value_object, result, source, offset); |
+ __ pop(source); |
+ } else { |
+ __ mov(ecx, FieldOperand(source, in_object_offset)); |
fschneider
2011/11/22 17:26:16
Here you could say:
if (value->IsHeapObject()) {
Michael Starzinger
2011/11/23 10:55:32
Done.
|
+ __ mov(FieldOperand(result, current_offset + in_object_offset), ecx); |
+ } |
+ } |
+} |
+ |
+ |
+void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) { |
+ ASSERT(ToRegister(instr->context()).is(esi)); |
+ int size = instr->hydrogen()->total_size(); |
+ |
+ // Allocate all objects that are part of the literal in one big |
+ // allocation. This avoids multiple limit checks. |
+ Label allocated, runtime_allocate; |
+ __ AllocateInNewSpace(size, eax, ecx, edx, &runtime_allocate, TAG_OBJECT); |
+ __ jmp(&allocated); |
+ |
+ __ bind(&runtime_allocate); |
+ __ push(Immediate(Smi::FromInt(size))); |
+ CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
+ |
+ __ bind(&allocated); |
+ int offset = 0; |
+ int literal_offset = FixedArray::kHeaderSize + |
+ instr->hydrogen()->literal_index() * kPointerSize; |
+ __ mov(ebx, Operand(ebp, JavaScriptFrameConstants::kFunctionOffset)); |
+ __ mov(ebx, FieldOperand(ebx, JSFunction::kLiteralsOffset)); |
+ __ mov(ebx, FieldOperand(ebx, literal_offset)); |
fschneider
2011/11/22 17:26:16
You could just load the boilerplace object directl
Michael Starzinger
2011/11/23 10:55:32
Done.
|
+ EmitDeepCopy(instr->hydrogen()->boilerplate(), eax, ebx, &offset); |
+ ASSERT_EQ(size, offset); |
+} |
+ |
+ |
+void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) { |
ASSERT(ToRegister(instr->context()).is(esi)); |
Handle<FixedArray> constant_properties = |
instr->hydrogen()->constant_properties(); |