OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 5071 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5082 } | 5082 } |
5083 } else { | 5083 } else { |
5084 for (int i = 0; i < prototypes->length(); i++) { | 5084 for (int i = 0; i < prototypes->length(); i++) { |
5085 __ LoadHeapObject(reg, prototypes->at(i)); | 5085 __ LoadHeapObject(reg, prototypes->at(i)); |
5086 DoCheckMapCommon(reg, maps->at(i), instr); | 5086 DoCheckMapCommon(reg, maps->at(i), instr); |
5087 } | 5087 } |
5088 } | 5088 } |
5089 } | 5089 } |
5090 | 5090 |
5091 | 5091 |
5092 void LCodeGen::DoAllocateObject(LAllocateObject* instr) { | |
5093 class DeferredAllocateObject: public LDeferredCode { | |
5094 public: | |
5095 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) | |
5096 : LDeferredCode(codegen), instr_(instr) { } | |
5097 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } | |
5098 virtual LInstruction* instr() { return instr_; } | |
5099 private: | |
5100 LAllocateObject* instr_; | |
5101 }; | |
5102 | |
5103 DeferredAllocateObject* deferred = | |
5104 new(zone()) DeferredAllocateObject(this, instr); | |
5105 | |
5106 Register result = ToRegister(instr->result()); | |
5107 Register scratch = ToRegister(instr->temp()); | |
5108 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); | |
5109 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); | |
5110 int instance_size = initial_map->instance_size(); | |
5111 ASSERT(initial_map->pre_allocated_property_fields() + | |
5112 initial_map->unused_property_fields() - | |
5113 initial_map->inobject_properties() == 0); | |
5114 | |
5115 __ Allocate(instance_size, result, no_reg, scratch, deferred->entry(), | |
5116 TAG_OBJECT); | |
5117 | |
5118 __ bind(deferred->exit()); | |
5119 if (FLAG_debug_code) { | |
5120 Label is_in_new_space; | |
5121 __ JumpIfInNewSpace(result, scratch, &is_in_new_space); | |
5122 __ Abort("Allocated object is not in new-space"); | |
5123 __ bind(&is_in_new_space); | |
5124 } | |
5125 | |
5126 // Load the initial map. | |
5127 Register map = scratch; | |
5128 __ LoadHeapObject(scratch, constructor); | |
5129 __ movq(map, FieldOperand(scratch, JSFunction::kPrototypeOrInitialMapOffset)); | |
5130 | |
5131 if (FLAG_debug_code) { | |
5132 __ AssertNotSmi(map); | |
5133 __ cmpb(FieldOperand(map, Map::kInstanceSizeOffset), | |
5134 Immediate(instance_size >> kPointerSizeLog2)); | |
5135 __ Assert(equal, "Unexpected instance size"); | |
5136 __ cmpb(FieldOperand(map, Map::kPreAllocatedPropertyFieldsOffset), | |
5137 Immediate(initial_map->pre_allocated_property_fields())); | |
5138 __ Assert(equal, "Unexpected pre-allocated property fields count"); | |
5139 __ cmpb(FieldOperand(map, Map::kUnusedPropertyFieldsOffset), | |
5140 Immediate(initial_map->unused_property_fields())); | |
5141 __ Assert(equal, "Unexpected unused property fields count"); | |
5142 __ cmpb(FieldOperand(map, Map::kInObjectPropertiesOffset), | |
5143 Immediate(initial_map->inobject_properties())); | |
5144 __ Assert(equal, "Unexpected in-object property fields count"); | |
5145 } | |
5146 | |
5147 // Initialize map and fields of the newly allocated object. | |
5148 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); | |
5149 __ movq(FieldOperand(result, JSObject::kMapOffset), map); | |
5150 __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); | |
5151 __ movq(FieldOperand(result, JSObject::kElementsOffset), scratch); | |
5152 __ movq(FieldOperand(result, JSObject::kPropertiesOffset), scratch); | |
5153 if (initial_map->inobject_properties() != 0) { | |
5154 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); | |
5155 for (int i = 0; i < initial_map->inobject_properties(); i++) { | |
5156 int property_offset = JSObject::kHeaderSize + i * kPointerSize; | |
5157 __ movq(FieldOperand(result, property_offset), scratch); | |
5158 } | |
5159 } | |
5160 } | |
5161 | |
5162 | |
5163 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { | |
5164 Register result = ToRegister(instr->result()); | |
5165 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); | |
5166 int instance_size = initial_map->instance_size(); | |
5167 | |
5168 // TODO(3095996): Get rid of this. For now, we need to make the | |
5169 // result register contain a valid pointer because it is already | |
5170 // contained in the register pointer map. | |
5171 __ Set(result, 0); | |
5172 | |
5173 PushSafepointRegistersScope scope(this); | |
5174 __ Push(Smi::FromInt(instance_size)); | |
5175 CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); | |
5176 __ StoreToSafepointRegisterSlot(result, rax); | |
5177 } | |
5178 | |
5179 | |
5180 void LCodeGen::DoAllocate(LAllocate* instr) { | 5092 void LCodeGen::DoAllocate(LAllocate* instr) { |
5181 class DeferredAllocate: public LDeferredCode { | 5093 class DeferredAllocate: public LDeferredCode { |
5182 public: | 5094 public: |
5183 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | 5095 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
5184 : LDeferredCode(codegen), instr_(instr) { } | 5096 : LDeferredCode(codegen), instr_(instr) { } |
5185 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } | 5097 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } |
5186 virtual LInstruction* instr() { return instr_; } | 5098 virtual LInstruction* instr() { return instr_; } |
5187 private: | 5099 private: |
5188 LAllocate* instr_; | 5100 LAllocate* instr_; |
5189 }; | 5101 }; |
(...skipping 508 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5698 FixedArray::kHeaderSize - kPointerSize)); | 5610 FixedArray::kHeaderSize - kPointerSize)); |
5699 __ bind(&done); | 5611 __ bind(&done); |
5700 } | 5612 } |
5701 | 5613 |
5702 | 5614 |
5703 #undef __ | 5615 #undef __ |
5704 | 5616 |
5705 } } // namespace v8::internal | 5617 } } // namespace v8::internal |
5706 | 5618 |
5707 #endif // V8_TARGET_ARCH_X64 | 5619 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |