Index: src/x64/lithium-codegen-x64.cc |
diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc |
index beaa1f1df96853c515d0c47c7a88ad3380edaacd..596072617f11ddc0146714dd5dc0aa2448ddae2f 100644 |
--- a/src/x64/lithium-codegen-x64.cc |
+++ b/src/x64/lithium-codegen-x64.cc |
@@ -5084,6 +5084,94 @@ void LCodeGen::DoCheckPrototypeMaps(LCheckPrototypeMaps* instr) { |
} |
+void LCodeGen::DoAllocateObject(LAllocateObject* instr) { |
+ class DeferredAllocateObject: public LDeferredCode { |
+ public: |
+ DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
+ : LDeferredCode(codegen), instr_(instr) { } |
+ virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
+ virtual LInstruction* instr() { return instr_; } |
+ private: |
+ LAllocateObject* instr_; |
+ }; |
+ |
+ DeferredAllocateObject* deferred = |
+ new(zone()) DeferredAllocateObject(this, instr); |
+ |
+ Register result = ToRegister(instr->result()); |
+ Register scratch = ToRegister(instr->temp()); |
+ Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
+ Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
+ int instance_size = initial_map->instance_size(); |
+ ASSERT(initial_map->pre_allocated_property_fields() + |
+ initial_map->unused_property_fields() - |
+ initial_map->inobject_properties() == 0); |
+ |
+ __ Allocate(instance_size, result, no_reg, scratch, deferred->entry(), |
+ TAG_OBJECT); |
+ |
+ __ bind(deferred->exit()); |
+ if (FLAG_debug_code) { |
+ Label is_in_new_space; |
+ __ JumpIfInNewSpace(result, scratch, &is_in_new_space); |
+ __ Abort("Allocated object is not in new-space"); |
+ __ bind(&is_in_new_space); |
+ } |
+ |
+ // Load the initial map. |
+ Register map = scratch; |
+ __ LoadHeapObject(scratch, constructor); |
+ __ movq(map, FieldOperand(scratch, JSFunction::kPrototypeOrInitialMapOffset)); |
+ |
+ if (FLAG_debug_code) { |
+ __ AssertNotSmi(map); |
+ __ cmpb(FieldOperand(map, Map::kInstanceSizeOffset), |
+ Immediate(instance_size >> kPointerSizeLog2)); |
+ __ Assert(equal, "Unexpected instance size"); |
+ __ cmpb(FieldOperand(map, Map::kPreAllocatedPropertyFieldsOffset), |
+ Immediate(initial_map->pre_allocated_property_fields())); |
+ __ Assert(equal, "Unexpected pre-allocated property fields count"); |
+ __ cmpb(FieldOperand(map, Map::kUnusedPropertyFieldsOffset), |
+ Immediate(initial_map->unused_property_fields())); |
+ __ Assert(equal, "Unexpected unused property fields count"); |
+ __ cmpb(FieldOperand(map, Map::kInObjectPropertiesOffset), |
+ Immediate(initial_map->inobject_properties())); |
+ __ Assert(equal, "Unexpected in-object property fields count"); |
+ } |
+ |
+ // Initialize map and fields of the newly allocated object. |
+ ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); |
+ __ movq(FieldOperand(result, JSObject::kMapOffset), map); |
+ __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); |
+ __ movq(FieldOperand(result, JSObject::kElementsOffset), scratch); |
+ __ movq(FieldOperand(result, JSObject::kPropertiesOffset), scratch); |
+ if (initial_map->inobject_properties() != 0) { |
+ __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
+ for (int i = 0; i < initial_map->inobject_properties(); i++) { |
+ int property_offset = JSObject::kHeaderSize + i * kPointerSize; |
+ __ movq(FieldOperand(result, property_offset), scratch); |
+ } |
+ } |
+} |
+ |
+ |
+void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
+ Register result = ToRegister(instr->result()); |
+ Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
+ int instance_size = initial_map->instance_size(); |
+ |
+ // TODO(3095996): Get rid of this. For now, we need to make the |
+ // result register contain a valid pointer because it is already |
+ // contained in the register pointer map. |
+ __ Set(result, 0); |
+ |
+ PushSafepointRegistersScope scope(this); |
+ __ Push(Smi::FromInt(instance_size)); |
+ CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); |
+ __ StoreToSafepointRegisterSlot(result, rax); |
+} |
+ |
+ |
void LCodeGen::DoAllocate(LAllocate* instr) { |
class DeferredAllocate: public LDeferredCode { |
public: |