Chromium Code Reviews| 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 4197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4208 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) | 4208 DeferredAllocateObject(LCodeGen* codegen, LAllocateObject* instr) |
| 4209 : LDeferredCode(codegen), instr_(instr) { } | 4209 : LDeferredCode(codegen), instr_(instr) { } |
| 4210 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } | 4210 virtual void Generate() { codegen()->DoDeferredAllocateObject(instr_); } |
| 4211 virtual LInstruction* instr() { return instr_; } | 4211 virtual LInstruction* instr() { return instr_; } |
| 4212 private: | 4212 private: |
| 4213 LAllocateObject* instr_; | 4213 LAllocateObject* instr_; |
| 4214 }; | 4214 }; |
| 4215 | 4215 |
| 4216 DeferredAllocateObject* deferred = new DeferredAllocateObject(this, instr); | 4216 DeferredAllocateObject* deferred = new DeferredAllocateObject(this, instr); |
| 4217 | 4217 |
| 4218 // TODO(mstarzinger): Implement inlined version instead of jumping to | 4218 Register result = ToRegister(instr->result()); |
| 4219 // deferred runtime call. | 4219 Register scratch = ToRegister(instr->TempAt(0)); |
| 4220 __ jmp(deferred->entry()); | 4220 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
| 4221 Handle<Map> initial_map(constructor->initial_map()); | |
| 4222 int instance_size = initial_map->instance_size(); | |
| 4223 ASSERT(initial_map->pre_allocated_property_fields() + | |
| 4224 initial_map->unused_property_fields() - | |
| 4225 initial_map->inobject_properties() == 0); | |
| 4226 | |
| 4227 // Allocate memory for the object. The initial map might change when | |
| 4228 // the constructor's prototype changes, but instance size and property | |
| 4229 // counts remain unchanged (if slack tracking finished). | |
| 4230 ASSERT(!constructor->shared()->IsInobjectSlackTrackingInProgress()); | |
| 4231 __ AllocateInNewSpace(instance_size, | |
| 4232 result, | |
| 4233 no_reg, | |
| 4234 scratch, | |
| 4235 deferred->entry(), | |
| 4236 TAG_OBJECT); | |
| 4237 | |
| 4238 // Load the initial map. | |
| 4239 Register map = scratch; | |
| 4240 __ LoadHeapObject(scratch, constructor); | |
| 4241 __ mov(map, FieldOperand(scratch, JSFunction::kPrototypeOrInitialMapOffset)); | |
| 4242 | |
| 4243 if (FLAG_debug_code) { | |
| 4244 __ AbortIfSmi(map); | |
| 4245 __ cmpb(FieldOperand(map, Map::kInstanceSizeOffset), | |
| 4246 instance_size >> kPointerSizeLog2); | |
| 4247 __ Assert(equal, "Unexpected instance size"); | |
| 4248 __ cmpb(FieldOperand(map, Map::kPreAllocatedPropertyFieldsOffset), | |
| 4249 initial_map->pre_allocated_property_fields()); | |
| 4250 __ Assert(equal, "Unexpected pre-allocated property fields count"); | |
| 4251 __ cmpb(FieldOperand(map, Map::kUnusedPropertyFieldsOffset), | |
| 4252 initial_map->unused_property_fields()); | |
| 4253 __ Assert(equal, "Unexpected unused property fields count"); | |
| 4254 __ cmpb(FieldOperand(map, Map::kInObjectPropertiesOffset), | |
| 4255 initial_map->inobject_properties()); | |
| 4256 __ Assert(equal, "Unexpected in-object property fields count"); | |
| 4257 } | |
| 4258 | |
| 4259 // Initialize map and fields of the newly allocated object. | |
| 4260 ASSERT(initial_map->instance_type() == JS_OBJECT_TYPE); | |
| 4261 Handle<Object> undefined = factory()->undefined_value(); | |
| 4262 __ mov(FieldOperand(result, JSObject::kMapOffset), map); | |
| 4263 __ mov(scratch, factory()->empty_fixed_array()); | |
| 4264 __ mov(FieldOperand(result, JSObject::kElementsOffset), scratch); | |
| 4265 __ mov(FieldOperand(result, JSObject::kPropertiesOffset), scratch); | |
| 4266 for (int i = 0; i < initial_map->inobject_properties(); i++) { | |
| 4267 int property_offset = JSObject::kHeaderSize + i * kPointerSize; | |
| 4268 __ mov(FieldOperand(result, property_offset), undefined); | |
|
Vyacheslav Egorov (Chromium)
2012/03/01 10:34:28
I't might be better to load undefined into a regis
Michael Starzinger
2012/03/01 11:11:24
Done.
| |
| 4269 } | |
| 4221 | 4270 |
| 4222 __ bind(deferred->exit()); | 4271 __ bind(deferred->exit()); |
| 4223 } | 4272 } |
| 4224 | 4273 |
| 4225 | 4274 |
| 4226 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { | 4275 void LCodeGen::DoDeferredAllocateObject(LAllocateObject* instr) { |
| 4227 Register result = ToRegister(instr->result()); | 4276 Register result = ToRegister(instr->result()); |
| 4228 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); | 4277 Handle<JSFunction> constructor = instr->hydrogen()->constructor(); |
| 4229 | 4278 |
| 4230 // TODO(3095996): Get rid of this. For now, we need to make the | 4279 // TODO(3095996): Get rid of this. For now, we need to make the |
| (...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4850 FixedArray::kHeaderSize - kPointerSize)); | 4899 FixedArray::kHeaderSize - kPointerSize)); |
| 4851 __ bind(&done); | 4900 __ bind(&done); |
| 4852 } | 4901 } |
| 4853 | 4902 |
| 4854 | 4903 |
| 4855 #undef __ | 4904 #undef __ |
| 4856 | 4905 |
| 4857 } } // namespace v8::internal | 4906 } } // namespace v8::internal |
| 4858 | 4907 |
| 4859 #endif // V8_TARGET_ARCH_IA32 | 4908 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |