| 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 5254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5265 if (!instr->hydrogen()->CanOmitPrototypeChecks()) { | 5265 if (!instr->hydrogen()->CanOmitPrototypeChecks()) { |
| 5266 for (int i = 0; i < prototypes->length(); i++) { | 5266 for (int i = 0; i < prototypes->length(); i++) { |
| 5267 __ LoadHeapObject(prototype_reg, prototypes->at(i)); | 5267 __ LoadHeapObject(prototype_reg, prototypes->at(i)); |
| 5268 __ lw(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); | 5268 __ lw(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); |
| 5269 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); | 5269 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); |
| 5270 } | 5270 } |
| 5271 } | 5271 } |
| 5272 } | 5272 } |
| 5273 | 5273 |
| 5274 | 5274 |
| 5275 void LCodeGen::DoAllocateObject(LAllocateObject* instr) { | |
| 5276 class DeferredAllocateObject: public LDeferredCode { | |
| 5277 public: | |
| 5278 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) | |
| 5279 : LDeferredCode(codegen), instr_(instr) { } | |
| 5280 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } | |
| 5281 virtual LInstruction* instr() { return instr_; } | |
| 5282 private: | |
| 5283 LAllocateObject* instr_; | |
| 5284 }; | |
| 5285 | |
| 5286 DeferredAllocateObject* deferred = | |
| 5287 new(zone()) DeferredAllocateObject(this, instr); | |
| 5288 | |
| 5289 Register result = ToRegister(instr->result()); | |
| 5290 Register scratch = ToRegister(instr->temp()); | |
| 5291 Register scratch2 = ToRegister(instr->temp2()); | |
| 5292 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); | |
| 5293 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); | |
| 5294 int instance_size = initial_map->instance_size(); | |
| 5295 ASSERT(initial_map->pre_allocated_property_fields() + | |
| 5296 initial_map->unused_property_fields() - | |
| 5297 initial_map->inobject_properties() == 0); | |
| 5298 | |
| 5299 __ Allocate(instance_size, result, scratch, scratch2, deferred->entry(), | |
| 5300 TAG_OBJECT); | |
| 5301 | |
| 5302 __ bind(deferred->exit()); | |
| 5303 if (FLAG_debug_code) { | |
| 5304 Label is_in_new_space; | |
| 5305 __ JumpIfInNewSpace(result, scratch, &is_in_new_space); | |
| 5306 __ Abort("Allocated object is not in new-space"); | |
| 5307 __ bind(&is_in_new_space); | |
| 5308 } | |
| 5309 | |
| 5310 // Load the initial map. | |
| 5311 Register map = scratch; | |
| 5312 __ LoadHeapObject(map, constructor); | |
| 5313 __ lw(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); | |
| 5314 | |
| 5315 // Initialize map and fields of the newly allocated object. | |
| 5316 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); | |
| 5317 __ sw(map, FieldMemOperand(result, JSObject::kMapOffset)); | |
| 5318 __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); | |
| 5319 __ sw(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); | |
| 5320 __ sw(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); | |
| 5321 if (initial_map->inobject_properties() != 0) { | |
| 5322 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); | |
| 5323 for (int i = 0; i < initial_map->inobject_properties(); i++) { | |
| 5324 int property_offset = JSObject::kHeaderSize + i * kPointerSize; | |
| 5325 __ sw(scratch, FieldMemOperand(result, property_offset)); | |
| 5326 } | |
| 5327 } | |
| 5328 } | |
| 5329 | |
| 5330 | |
| 5331 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { | |
| 5332 Register result = ToRegister(instr->result()); | |
| 5333 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); | |
| 5334 int instance_size = initial_map->instance_size(); | |
| 5335 | |
| 5336 // TODO(3095996): Get rid of this. For now, we need to make the | |
| 5337 // result register contain a valid pointer because it is already | |
| 5338 // contained in the register pointer map. | |
| 5339 __ mov(result, zero_reg); | |
| 5340 | |
| 5341 PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); | |
| 5342 __ li(a0, Operand(Smi::FromInt(instance_size))); | |
| 5343 __ push(a0); | |
| 5344 CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); | |
| 5345 __ StoreToSafepointRegisterSlot(v0, result); | |
| 5346 } | |
| 5347 | |
| 5348 | |
| 5349 void LCodeGen::DoAllocate(LAllocate* instr) { | 5275 void LCodeGen::DoAllocate(LAllocate* instr) { |
| 5350 class DeferredAllocate: public LDeferredCode { | 5276 class DeferredAllocate: public LDeferredCode { |
| 5351 public: | 5277 public: |
| 5352 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | 5278 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5353 : LDeferredCode(codegen), instr_(instr) { } | 5279 : LDeferredCode(codegen), instr_(instr) { } |
| 5354 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } | 5280 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } |
| 5355 virtual LInstruction* instr() { return instr_; } | 5281 virtual LInstruction* instr() { return instr_; } |
| 5356 private: | 5282 private: |
| 5357 LAllocate* instr_; | 5283 LAllocate* instr_; |
| 5358 }; | 5284 }; |
| (...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5868 __ Subu(scratch, result, scratch); | 5794 __ Subu(scratch, result, scratch); |
| 5869 __ lw(result, FieldMemOperand(scratch, | 5795 __ lw(result, FieldMemOperand(scratch, |
| 5870 FixedArray::kHeaderSize - kPointerSize)); | 5796 FixedArray::kHeaderSize - kPointerSize)); |
| 5871 __ bind(&done); | 5797 __ bind(&done); |
| 5872 } | 5798 } |
| 5873 | 5799 |
| 5874 | 5800 |
| 5875 #undef __ | 5801 #undef __ |
| 5876 | 5802 |
| 5877 } } // namespace v8::internal | 5803 } } // namespace v8::internal |
| OLD | NEW |