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 5275 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5286 if (!instr->hydrogen()->CanOmitPrototypeChecks()) { | 5286 if (!instr->hydrogen()->CanOmitPrototypeChecks()) { |
5287 for (int i = 0; i < prototypes->length(); i++) { | 5287 for (int i = 0; i < prototypes->length(); i++) { |
5288 __ LoadHeapObject(prototype_reg, prototypes->at(i)); | 5288 __ LoadHeapObject(prototype_reg, prototypes->at(i)); |
5289 __ lw(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); | 5289 __ lw(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); |
5290 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); | 5290 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); |
5291 } | 5291 } |
5292 } | 5292 } |
5293 } | 5293 } |
5294 | 5294 |
5295 | 5295 |
| 5296 void LCodeGen::DoAllocateObject(LAllocateObject* instr) { |
| 5297 class DeferredAllocateObject: public LDeferredCode { |
| 5298 public: |
| 5299 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
| 5300 : LDeferredCode(codegen), instr_(instr) { } |
| 5301 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
| 5302 virtual LInstruction* instr() { return instr_; } |
| 5303 private: |
| 5304 LAllocateObject* instr_; |
| 5305 }; |
| 5306 |
| 5307 DeferredAllocateObject* deferred = |
| 5308 new(zone()) DeferredAllocateObject(this, instr); |
| 5309 |
| 5310 Register result = ToRegister(instr->result()); |
| 5311 Register scratch = ToRegister(instr->temp()); |
| 5312 Register scratch2 = ToRegister(instr->temp2()); |
| 5313 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
| 5314 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
| 5315 int instance_size = initial_map->instance_size(); |
| 5316 ASSERT(initial_map->pre_allocated_property_fields() + |
| 5317 initial_map->unused_property_fields() - |
| 5318 initial_map->inobject_properties() == 0); |
| 5319 |
| 5320 __ Allocate(instance_size, result, scratch, scratch2, deferred->entry(), |
| 5321 TAG_OBJECT); |
| 5322 |
| 5323 __ bind(deferred->exit()); |
| 5324 if (FLAG_debug_code) { |
| 5325 Label is_in_new_space; |
| 5326 __ JumpIfInNewSpace(result, scratch, &is_in_new_space); |
| 5327 __ Abort("Allocated object is not in new-space"); |
| 5328 __ bind(&is_in_new_space); |
| 5329 } |
| 5330 |
| 5331 // Load the initial map. |
| 5332 Register map = scratch; |
| 5333 __ LoadHeapObject(map, constructor); |
| 5334 __ lw(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5335 |
| 5336 // Initialize map and fields of the newly allocated object. |
| 5337 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); |
| 5338 __ sw(map, FieldMemOperand(result, JSObject::kMapOffset)); |
| 5339 __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); |
| 5340 __ sw(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); |
| 5341 __ sw(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); |
| 5342 if (initial_map->inobject_properties() != 0) { |
| 5343 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5344 for (int i = 0; i < initial_map->inobject_properties(); i++) { |
| 5345 int property_offset = JSObject::kHeaderSize + i * kPointerSize; |
| 5346 __ sw(scratch, FieldMemOperand(result, property_offset)); |
| 5347 } |
| 5348 } |
| 5349 } |
| 5350 |
| 5351 |
| 5352 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
| 5353 Register result = ToRegister(instr->result()); |
| 5354 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
| 5355 int instance_size = initial_map->instance_size(); |
| 5356 |
| 5357 // TODO(3095996): Get rid of this. For now, we need to make the |
| 5358 // result register contain a valid pointer because it is already |
| 5359 // contained in the register pointer map. |
| 5360 __ mov(result, zero_reg); |
| 5361 |
| 5362 PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 5363 __ li(a0, Operand(Smi::FromInt(instance_size))); |
| 5364 __ push(a0); |
| 5365 CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); |
| 5366 __ StoreToSafepointRegisterSlot(v0, result); |
| 5367 } |
| 5368 |
| 5369 |
5296 void LCodeGen::DoAllocate(LAllocate* instr) { | 5370 void LCodeGen::DoAllocate(LAllocate* instr) { |
5297 class DeferredAllocate: public LDeferredCode { | 5371 class DeferredAllocate: public LDeferredCode { |
5298 public: | 5372 public: |
5299 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | 5373 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
5300 : LDeferredCode(codegen), instr_(instr) { } | 5374 : LDeferredCode(codegen), instr_(instr) { } |
5301 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } | 5375 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } |
5302 virtual LInstruction* instr() { return instr_; } | 5376 virtual LInstruction* instr() { return instr_; } |
5303 private: | 5377 private: |
5304 LAllocate* instr_; | 5378 LAllocate* instr_; |
5305 }; | 5379 }; |
(...skipping 542 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5848 __ Subu(scratch, result, scratch); | 5922 __ Subu(scratch, result, scratch); |
5849 __ lw(result, FieldMemOperand(scratch, | 5923 __ lw(result, FieldMemOperand(scratch, |
5850 FixedArray::kHeaderSize - kPointerSize)); | 5924 FixedArray::kHeaderSize - kPointerSize)); |
5851 __ bind(&done); | 5925 __ bind(&done); |
5852 } | 5926 } |
5853 | 5927 |
5854 | 5928 |
5855 #undef __ | 5929 #undef __ |
5856 | 5930 |
5857 } } // namespace v8::internal | 5931 } } // namespace v8::internal |
OLD | NEW |