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 4325 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4336 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) | 4336 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
4337 : LDeferredCode(codegen), instr_(instr) { } | 4337 : LDeferredCode(codegen), instr_(instr) { } |
4338 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } | 4338 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
4339 virtual LInstruction* instr() { return instr_; } | 4339 virtual LInstruction* instr() { return instr_; } |
4340 private: | 4340 private: |
4341 LAllocateObject* instr_; | 4341 LAllocateObject* instr_; |
4342 }; | 4342 }; |
4343 | 4343 |
4344 DeferredAllocateObject* deferred = new DeferredAllocateObject(this, instr); | 4344 DeferredAllocateObject* deferred = new DeferredAllocateObject(this, instr); |
4345 | 4345 |
4346 // TODO(mstarzinger): Implement inlined version instead of jumping to | 4346 Register result = ToRegister(instr->result()); |
4347 // deferred runtime call. | 4347 Register scratch = ToRegister(instr->TempAt(0)); |
4348 __ jmp(deferred->entry()); | 4348 Register scratch2 = ToRegister(instr->TempAt(1)); |
| 4349 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
| 4350 Handle<Map> initial_map(constructor->initial_map()); |
| 4351 int instance_size = initial_map->instance_size(); |
| 4352 ASSERT(initial_map->pre_allocated_property_fields() + |
| 4353 initial_map->unused_property_fields() - |
| 4354 initial_map->inobject_properties() == 0); |
| 4355 |
| 4356 // Allocate memory for the object. The initial map might change when |
| 4357 // the constructor's prototype changes, but instance size and property |
| 4358 // counts remain unchanged (if slack tracking finished). |
| 4359 ASSERT(!constructor->shared()->IsInobjectSlackTrackingInProgress()); |
| 4360 __ AllocateInNewSpace(instance_size, |
| 4361 result, |
| 4362 scratch, |
| 4363 scratch2, |
| 4364 deferred->entry(), |
| 4365 TAG_OBJECT); |
| 4366 |
| 4367 // Load the initial map. |
| 4368 Register map = scratch; |
| 4369 __ LoadHeapObject(map, constructor); |
| 4370 __ ldr(map, FieldMemOperand(map, JSFunction::kPrototypeOrInitialMapOffset)); |
| 4371 |
| 4372 // Initialize map and fields of the newly allocated object. |
| 4373 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); |
| 4374 __ str(map, FieldMemOperand(result, JSObject::kMapOffset)); |
| 4375 __ LoadRoot(scratch, Heap::kEmptyFixedArrayRootIndex); |
| 4376 __ str(scratch, FieldMemOperand(result, JSObject::kElementsOffset)); |
| 4377 __ str(scratch, FieldMemOperand(result, JSObject::kPropertiesOffset)); |
| 4378 if (initial_map->inobject_properties() != 0) { |
| 4379 __ LoadRoot(scratch, Heap::kUndefinedValueRootIndex); |
| 4380 for (int i = 0; i < initial_map->inobject_properties(); i++) { |
| 4381 int property_offset = JSObject::kHeaderSize + i * kPointerSize; |
| 4382 __ str(scratch, FieldMemOperand(result, property_offset)); |
| 4383 } |
| 4384 } |
4349 | 4385 |
4350 __ bind(deferred->exit()); | 4386 __ bind(deferred->exit()); |
4351 } | 4387 } |
4352 | 4388 |
4353 | 4389 |
4354 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { | 4390 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
4355 Register result = ToRegister(instr->result()); | 4391 Register result = ToRegister(instr->result()); |
4356 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); | 4392 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
4357 | 4393 |
4358 // TODO(3095996): Get rid of this. For now, we need to make the | 4394 // TODO(3095996): Get rid of this. For now, we need to make the |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4976 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); | 5012 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); |
4977 __ ldr(result, FieldMemOperand(scratch, | 5013 __ ldr(result, FieldMemOperand(scratch, |
4978 FixedArray::kHeaderSize - kPointerSize)); | 5014 FixedArray::kHeaderSize - kPointerSize)); |
4979 __ bind(&done); | 5015 __ bind(&done); |
4980 } | 5016 } |
4981 | 5017 |
4982 | 5018 |
4983 #undef __ | 5019 #undef __ |
4984 | 5020 |
4985 } } // namespace v8::internal | 5021 } } // namespace v8::internal |
OLD | NEW |