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 3928 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3939 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) | 3939 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
3940 : LDeferredCode(codegen), instr_(instr) { } | 3940 : LDeferredCode(codegen), instr_(instr) { } |
3941 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } | 3941 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
3942 virtual LInstruction* instr() { return instr_; } | 3942 virtual LInstruction* instr() { return instr_; } |
3943 private: | 3943 private: |
3944 LAllocateObject* instr_; | 3944 LAllocateObject* instr_; |
3945 }; | 3945 }; |
3946 | 3946 |
3947 DeferredAllocateObject* deferred = new DeferredAllocateObject(this, instr); | 3947 DeferredAllocateObject* deferred = new DeferredAllocateObject(this, instr); |
3948 | 3948 |
3949 // TODO(mstarzinger): Implement inlined version instead of jumping to | 3949 Register result = ToRegister(instr->result()); |
3950 // deferred runtime call. | 3950 Register scratch = ToRegister(instr->TempAt(0)); |
3951 __ jmp(deferred->entry()); | 3951 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
3952 Handle<Map> initial_map(constructor->initial_map()); | |
3953 int instance_size = initial_map->instance_size(); | |
3954 ASSERT(initial_map->pre_allocated_property_fields() + | |
3955 initial_map->unused_property_fields() - | |
3956 initial_map->inobject_properties() == 0); | |
3957 | |
3958 // Allocate memory for the object. The initial map might change when | |
3959 // the constructor's prototype changes, but instance size and property | |
3960 // counts remain unchanged (if slack tracking finished). | |
3961 ASSERT(!constructor->shared()->IsInobjectSlackTrackingInProgress()); | |
3962 __ AllocateInNewSpace(instance_size, | |
3963 result, | |
3964 no_reg, | |
3965 scratch, | |
3966 deferred->entry(), | |
3967 TAG_OBJECT); | |
3968 | |
3969 // Load the initial map. | |
3970 Register map = scratch; | |
3971 __ LoadHeapObject(scratch, constructor); | |
3972 __ movq(map, FieldOperand(scratch, JSFunction::kPrototypeOrInitialMapOffset)); | |
3973 | |
3974 if (FLAG_debug_code) { | |
3975 __ AbortIfSmi(map); | |
3976 __ cmpb(FieldOperand(map, Map::kInstanceSizeOffset), | |
3977 Immediate(instance_size >> kPointerSizeLog2)); | |
3978 __ Assert(equal, "Unexpected instance size"); | |
3979 __ cmpb(FieldOperand(map, Map::kPreAllocatedPropertyFieldsOffset), | |
3980 Immediate(initial_map->pre_allocated_property_fields())); | |
3981 __ Assert(equal, "Unexpected pre-allocated property fields count"); | |
3982 __ cmpb(FieldOperand(map, Map::kUnusedPropertyFieldsOffset), | |
3983 Immediate(initial_map->unused_property_fields())); | |
3984 __ Assert(equal, "Unexpected unused property fields count"); | |
3985 __ cmpb(FieldOperand(map, Map::kInObjectPropertiesOffset), | |
3986 Immediate(initial_map->inobject_properties())); | |
3987 __ Assert(equal, "Unexpected in-object property fields count"); | |
3988 } | |
3989 | |
3990 // Initialize map and fields of the newly allocated object. | |
3991 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); | |
3992 Handle<Object> undefined = factory()->undefined_value(); | |
3993 __ movq(FieldOperand(result, JSObject::kMapOffset), map); | |
3994 __ Move(scratch, factory()->empty_fixed_array()); | |
3995 __ movq(FieldOperand(result, JSObject::kElementsOffset), scratch); | |
3996 __ movq(FieldOperand(result, JSObject::kPropertiesOffset), scratch); | |
3997 for (int i = 0; i < initial_map->inobject_properties(); i++) { | |
3998 int property_offset = JSObject::kHeaderSize + i * kPointerSize; | |
3999 __ Move(FieldOperand(result, property_offset), undefined); | |
Vyacheslav Egorov (Chromium)
2012/03/01 10:34:28
consider pre loading undefined into a register (it
Michael Starzinger
2012/03/01 11:11:24
Done.
| |
4000 } | |
3952 | 4001 |
3953 __ bind(deferred->exit()); | 4002 __ bind(deferred->exit()); |
3954 } | 4003 } |
3955 | 4004 |
3956 | 4005 |
3957 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { | 4006 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
3958 Register result = ToRegister(instr->result()); | 4007 Register result = ToRegister(instr->result()); |
3959 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); | 4008 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
3960 | 4009 |
3961 // TODO(3095996): Get rid of this. For now, we need to make the | 4010 // TODO(3095996): Get rid of this. For now, we need to make the |
(...skipping 624 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4586 FixedArray::kHeaderSize - kPointerSize)); | 4635 FixedArray::kHeaderSize - kPointerSize)); |
4587 __ bind(&done); | 4636 __ bind(&done); |
4588 } | 4637 } |
4589 | 4638 |
4590 | 4639 |
4591 #undef __ | 4640 #undef __ |
4592 | 4641 |
4593 } } // namespace v8::internal | 4642 } } // namespace v8::internal |
4594 | 4643 |
4595 #endif // V8_TARGET_ARCH_X64 | 4644 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |