OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 5121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5132 } else { | 5132 } else { |
5133 for (int i = 0; i < prototypes->length(); i++) { | 5133 for (int i = 0; i < prototypes->length(); i++) { |
5134 __ LoadHeapObject(prototype_reg, prototypes->at(i)); | 5134 __ LoadHeapObject(prototype_reg, prototypes->at(i)); |
5135 __ lw(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); | 5135 __ lw(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); |
5136 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); | 5136 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); |
5137 } | 5137 } |
5138 } | 5138 } |
5139 } | 5139 } |
5140 | 5140 |
5141 | 5141 |
5142 void LCodeGen::DoAllocateObject(LAllocateObject* instr) { | |
5143 class DeferredAllocateObject: public LDeferredCode { | |
5144 public: | |
5145 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) | |
5146 : LDeferredCode(codegen), instr_(instr) { } | |
5147 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } | |
5148 virtual LInstruction* instr() { return instr_; } | |
5149 private: | |
5150 LAllocateObject* instr_; | |
5151 }; | |
5152 | |
5153 DeferredAllocateObject* deferred = | |
5154 new(zone()) DeferredAllocateObject(this, instr); | |
5155 | |
5156 Register result = ToRegister(instr->result()); | |
5157 Register scratch = ToRegister(instr->temp()); | |
5158 Register scratch2 = ToRegister(instr->temp2()); | |
5159 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); | |
5160 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); | |
5161 int instance_size = initial_map->instance_size(); | |
5162 ASSERT(initial_map->pre_allocated_property_fields() + | |
5163 initial_map->unused_property_fields() - | |
5164 initial_map->inobject_properties() == 0); | |
5165 | |
5166 __ Allocate(instance_size, result, scratch, scratch2, deferred->entry(), | |
5167 TAG_OBJECT); | |
5168 | |
5169 __ bind(deferred->exit()); | |
5170 if (FLAG_debug_code) { | |
5171 Label is_in_new_space; | |
5172 __ JumpIfInNewSpace(result, scratch, &is_in_new_space); | |
5173 __ Abort("Allocated object is not in new-space"); | |
5174 __ bind(&is_in_new_space); | |
5175 } | |
5176 | |
5177 // Load the initial map. | |
5178 Register map = scratch; | |
5179 __ LoadHeapObject(map, constructor); | |
5180 __ lw(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); | |
5181 | |
5182 // Initialize map and fields of the newly allocated object. | |
5183 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); | |
5184 __ sw(map, FieldMemOperand(result, JSObject::kMapOffset)); | |
5185 __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); | |
5186 __ sw(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); | |
5187 __ sw(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); | |
5188 if (initial_map->inobject_properties() != 0) { | |
5189 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); | |
5190 for (int i = 0; i < initial_map->inobject_properties(); i++) { | |
5191 int property_offset = JSObject::kHeaderSize + i * kPointerSize; | |
5192 __ sw(scratch, FieldMemOperand(result, property_offset)); | |
5193 } | |
5194 } | |
5195 } | |
5196 | |
5197 | |
5198 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { | |
5199 Register result = ToRegister(instr->result()); | |
5200 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); | |
5201 int instance_size = initial_map->instance_size(); | |
5202 | |
5203 // TODO(3095996): Get rid of this. For now, we need to make the | |
5204 // result register contain a valid pointer because it is already | |
5205 // contained in the register pointer map. | |
5206 __ mov(result, zero_reg); | |
5207 | |
5208 PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); | |
5209 __ li(a0, Operand(Smi::FromInt(instance_size))); | |
5210 __ push(a0); | |
5211 CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); | |
5212 __ StoreToSafepointRegisterSlot(v0, result); | |
5213 } | |
5214 | |
5215 | |
5216 void LCodeGen::DoAllocate(LAllocate* instr) { | 5142 void LCodeGen::DoAllocate(LAllocate* instr) { |
5217 class DeferredAllocate: public LDeferredCode { | 5143 class DeferredAllocate: public LDeferredCode { |
5218 public: | 5144 public: |
5219 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | 5145 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
5220 : LDeferredCode(codegen), instr_(instr) { } | 5146 : LDeferredCode(codegen), instr_(instr) { } |
5221 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } | 5147 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } |
5222 virtual LInstruction* instr() { return instr_; } | 5148 virtual LInstruction* instr() { return instr_; } |
5223 private: | 5149 private: |
5224 LAllocate* instr_; | 5150 LAllocate* instr_; |
5225 }; | 5151 }; |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5768 __ Subu(scratch, result, scratch); | 5694 __ Subu(scratch, result, scratch); |
5769 __ lw(result, FieldMemOperand(scratch, | 5695 __ lw(result, FieldMemOperand(scratch, |
5770 FixedArray::kHeaderSize - kPointerSize)); | 5696 FixedArray::kHeaderSize - kPointerSize)); |
5771 __ bind(&done); | 5697 __ bind(&done); |
5772 } | 5698 } |
5773 | 5699 |
5774 | 5700 |
5775 #undef __ | 5701 #undef __ |
5776 | 5702 |
5777 } } // namespace v8::internal | 5703 } } // namespace v8::internal |
OLD | NEW |