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 5347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5358 if (!instr->hydrogen()->CanOmitPrototypeChecks()) { | 5358 if (!instr->hydrogen()->CanOmitPrototypeChecks()) { |
5359 for (int i = 0; i < prototypes->length(); i++) { | 5359 for (int i = 0; i < prototypes->length(); i++) { |
5360 __ LoadHeapObject(prototype_reg, prototypes->at(i)); | 5360 __ LoadHeapObject(prototype_reg, prototypes->at(i)); |
5361 __ ldr(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); | 5361 __ ldr(map_reg, FieldMemOperand(prototype_reg, HeapObject::kMapOffset)); |
5362 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); | 5362 DoCheckMapCommon(map_reg, maps->at(i), instr->environment()); |
5363 } | 5363 } |
5364 } | 5364 } |
5365 } | 5365 } |
5366 | 5366 |
5367 | 5367 |
| 5368 void LCodeGen::DoAllocateObject(LAllocateObject* instr) { |
| 5369 class DeferredAllocateObject: public LDeferredCode { |
| 5370 public: |
| 5371 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
| 5372 : LDeferredCode(codegen), instr_(instr) { } |
| 5373 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
| 5374 virtual LInstruction* instr() { return instr_; } |
| 5375 private: |
| 5376 LAllocateObject* instr_; |
| 5377 }; |
| 5378 |
| 5379 DeferredAllocateObject* deferred = |
| 5380 new(zone()) DeferredAllocateObject(this, instr); |
| 5381 |
| 5382 Register result = ToRegister(instr->result()); |
| 5383 Register scratch = ToRegister(instr->temp()); |
| 5384 Register scratch2 = ToRegister(instr->temp2()); |
| 5385 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
| 5386 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
| 5387 int instance_size = initial_map->instance_size(); |
| 5388 ASSERT(initial_map->pre_allocated_property_fields() + |
| 5389 initial_map->unused_property_fields() - |
| 5390 initial_map->inobject_properties() == 0); |
| 5391 |
| 5392 __ Allocate(instance_size, result, scratch, scratch2, deferred->entry(), |
| 5393 TAG_OBJECT); |
| 5394 |
| 5395 __ bind(deferred->exit()); |
| 5396 if (FLAG_debug_code) { |
| 5397 Label is_in_new_space; |
| 5398 __ JumpIfInNewSpace(result, scratch, &is_in_new_space); |
| 5399 __ Abort("Allocated object is not in new-space"); |
| 5400 __ bind(&is_in_new_space); |
| 5401 } |
| 5402 |
| 5403 // Load the initial map. |
| 5404 Register map = scratch; |
| 5405 __ LoadHeapObject(map, constructor); |
| 5406 __ ldr(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); |
| 5407 |
| 5408 // Initialize map and fields of the newly allocated object. |
| 5409 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); |
| 5410 __ str(map, FieldMemOperand(result, JSObject::kMapOffset)); |
| 5411 __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); |
| 5412 __ str(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); |
| 5413 __ str(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); |
| 5414 if (initial_map->inobject_properties() != 0) { |
| 5415 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 5416 for (int i = 0; i < initial_map->inobject_properties(); i++) { |
| 5417 int property_offset = JSObject::kHeaderSize + i * kPointerSize; |
| 5418 __ str(scratch, FieldMemOperand(result, property_offset)); |
| 5419 } |
| 5420 } |
| 5421 } |
| 5422 |
| 5423 |
| 5424 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
| 5425 Register result = ToRegister(instr->result()); |
| 5426 Handle<Map> initial_map = instr->hydrogen()->constructor_initial_map(); |
| 5427 int instance_size = initial_map->instance_size(); |
| 5428 |
| 5429 // TODO(3095996): Get rid of this. For now, we need to make the |
| 5430 // result register contain a valid pointer because it is already |
| 5431 // contained in the register pointer map. |
| 5432 __ mov(result, Operand::Zero()); |
| 5433 |
| 5434 PushSafepointRegistersScope scope(this, Safepoint::kWithRegisters); |
| 5435 __ mov(r0, Operand(Smi::FromInt(instance_size))); |
| 5436 __ push(r0); |
| 5437 CallRuntimeFromDeferred(Runtime::kAllocateInNewSpace, 1, instr); |
| 5438 __ StoreToSafepointRegisterSlot(r0, result); |
| 5439 } |
| 5440 |
| 5441 |
5368 void LCodeGen::DoAllocate(LAllocate* instr) { | 5442 void LCodeGen::DoAllocate(LAllocate* instr) { |
5369 class DeferredAllocate: public LDeferredCode { | 5443 class DeferredAllocate: public LDeferredCode { |
5370 public: | 5444 public: |
5371 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) | 5445 DeferredAllocate(LCodeGen* codegen, LAllocate* instr) |
5372 : LDeferredCode(codegen), instr_(instr) { } | 5446 : LDeferredCode(codegen), instr_(instr) { } |
5373 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } | 5447 virtual void Generate() { codegen()->DoDeferredAllocate(instr_); } |
5374 virtual LInstruction* instr() { return instr_; } | 5448 virtual LInstruction* instr() { return instr_; } |
5375 private: | 5449 private: |
5376 LAllocate* instr_; | 5450 LAllocate* instr_; |
5377 }; | 5451 }; |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5880 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); | 5954 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); |
5881 __ ldr(result, FieldMemOperand(scratch, | 5955 __ ldr(result, FieldMemOperand(scratch, |
5882 FixedArray::kHeaderSize - kPointerSize)); | 5956 FixedArray::kHeaderSize - kPointerSize)); |
5883 __ bind(&done); | 5957 __ bind(&done); |
5884 } | 5958 } |
5885 | 5959 |
5886 | 5960 |
5887 #undef __ | 5961 #undef __ |
5888 | 5962 |
5889 } } // namespace v8::internal | 5963 } } // namespace v8::internal |
OLD | NEW |