| 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 5393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5404 } else { | 5404 } else { |
| 5405 for (int i = 0; i < prototypes->length(); i++) { | 5405 for (int i = 0; i < prototypes->length(); i++) { |
| 5406 __ LoadHeapObject(prototype_reg, prototypes->at(i)); | 5406 __ LoadHeapObject(prototype_reg, prototypes->at(i)); |
| 5407 __ ldr(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); | 5407 __ ldr(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); |
| 5408 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); | 5408 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); |
| 5409 } | 5409 } |
| 5410 } | 5410 } |
| 5411 } | 5411 } |
| 5412 | 5412 |
| 5413 | 5413 |
| 5414 void LCodeGen::DoAllocateObject(LAllocateObject* instr) { | |
| 5415 class DeferredAllocateObject: public LDeferredCode { | |
| 5416 public: | |
| 5417 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) | |
| 5418 : LDeferredCode(codegen), instr_(instr) { } | |
| 5419 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } | |
| 5420 virtual LInstruction* instr() { return instr_; } | |
| 5421 private: | |
| 5422 LAllocateObject* instr_; | |
| 5423 }; | |
| 5424 | |
| 5425 DeferredAllocateObject* deferred = | |
| 5426 new(zone()) DeferredAllocateObject(this, instr); | |
| 5427 | |
| 5428 Register result = ToRegister(instr->result()); | |
| 5429 Register scratch = ToRegister(instr->temp()); | |
| 5430 Register scratch2 = ToRegister(instr->temp2()); | |
| 5431 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); | |
| 5432 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); | |
| 5433 int instance_size = initial_map->instance_size(); | |
| 5434 ASSERT(initial_map->pre_allocated_property_fields() + | |
| 5435 initial_map->unused_property_fields() - | |
| 5436 initial_map->inobject_properties() == 0); | |
| 5437 | |
| 5438 __ Allocate(instance_size, result, scratch, scratch2, deferred->entry(), | |
| 5439 TAG_OBJECT); | |
| 5440 | |
| 5441 __ bind(deferred->exit()); | |
| 5442 if (FLAG_debug_code) { | |
| 5443 Label is_in_new_space; | |
| 5444 __ JumpIfInNewSpace(result, scratch, &is_in_new_space); | |
| 5445 __ Abort("Allocated object is not in new-space"); | |
| 5446 __ bind(&is_in_new_space); | |
| 5447 } | |
| 5448 | |
| 5449 // Load the initial map. | |
| 5450 Register map = scratch; | |
| 5451 __ LoadHeapObject(map, constructor); | |
| 5452 __ ldr(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); | |
| 5453 | |
| 5454 // Initialize map and fields of the newly allocated object. | |
| 5455 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); | |
| 5456 __ str(map, FieldMemOperand(result, JSObject::kMapOffset)); | |
| 5457 __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); | |
| 5458 __ str(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); | |
| 5459 __ str(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); | |
| 5460 if (initial_map->inobject_properties() != 0) { | |
| 5461 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); | |
| 5462 for (int i = 0; i < initial_map->inobject_properties(); i++) { | |
| 5463 int property_offset = JSObject::kHeaderSize + i * kPointerSize; | |
| 5464 __ str(scratch, FieldMemOperand(result, property_offset)); | |
| 5465 } | |
| 5466 } | |
| 5467 } | |
| 5468 | |
| 5469 | |
| 5470 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { | |
| 5471 Register result = ToRegister(instr->result()); | |
| 5472 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); | |
| 5473 int instance_size = initial_map->instance_size(); | |
| 5474 | |
| 5475 // TODO(3095996): Get rid of this. For now, we need to make the | |
| 5476 // result register contain a valid pointer because it is already | |
| 5477 // contained in the register pointer map. | |
| 5478 __ mov(result, Operand::Zero()); | |
| 5479 | |
| 5480 PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); | |
| 5481 __ mov(r0, Operand(Smi::FromInt(instance_size))); | |
| 5482 __ push(r0); | |
| 5483 CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); | |
| 5484 __ StoreToSafepointRegisterSlot(r0, result); | |
| 5485 } | |
| 5486 | |
| 5487 | |
| 5488 void LCodeGen::DoAllocate(LAllocate* instr) { | 5414 void LCodeGen::DoAllocate(LAllocate* instr) { |
| 5489 class DeferredAllocate: public LDeferredCode { | 5415 class DeferredAllocate: public LDeferredCode { |
| 5490 public: | 5416 public: |
| 5491 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | 5417 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
| 5492 : LDeferredCode(codegen), instr_(instr) { } | 5418 : LDeferredCode(codegen), instr_(instr) { } |
| 5493 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } | 5419 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } |
| 5494 virtual LInstruction* instr() { return instr_; } | 5420 virtual LInstruction* instr() { return instr_; } |
| 5495 private: | 5421 private: |
| 5496 LAllocate* instr_; | 5422 LAllocate* instr_; |
| 5497 }; | 5423 }; |
| (...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6000 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); | 5926 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); |
| 6001 __ ldr(result, FieldMemOperand(scratch, | 5927 __ ldr(result, FieldMemOperand(scratch, |
| 6002 FixedArray::kHeaderSize - kPointerSize)); | 5928 FixedArray::kHeaderSize - kPointerSize)); |
| 6003 __ bind(&done); | 5929 __ bind(&done); |
| 6004 } | 5930 } |
| 6005 | 5931 |
| 6006 | 5932 |
| 6007 #undef __ | 5933 #undef __ |
| 6008 | 5934 |
| 6009 } } // namespace v8::internal | 5935 } } // namespace v8::internal |
| OLD | NEW |