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 4254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4265 } | 4265 } |
4266 | 4266 |
4267 | 4267 |
4268 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, | 4268 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, |
4269 Register result, | 4269 Register result, |
4270 Register source, | 4270 Register source, |
4271 int* offset) { | 4271 int* offset) { |
4272 ASSERT(!source.is(a2)); | 4272 ASSERT(!source.is(a2)); |
4273 ASSERT(!result.is(a2)); | 4273 ASSERT(!result.is(a2)); |
4274 | 4274 |
4275 // Only elements backing stores for non-cow arrays need to be copied. | |
4276 Handle<FixedArrayBase> elements(object->elements()); | |
4277 bool has_elements = elements->length() > 0 && | |
4278 elements->map() != isolate()->heap()->fixed_cow_array_map(); | |
4279 | |
4275 // Increase the offset so that subsequent objects end up right after | 4280 // Increase the offset so that subsequent objects end up right after |
4276 // this one. | 4281 // this object and its backing store. |
4277 int current_offset = *offset; | 4282 int object_offset = *offset; |
4278 int size = object->map()->instance_size(); | 4283 int object_size = object->map()->instance_size(); |
4279 *offset += size; | 4284 int elements_offset = *offset + object_size; |
4285 int elements_size = has_elements ? elements->Size() : 0; | |
4286 *offset += object_size + elements_size; | |
4280 | 4287 |
4281 // Copy object header. | 4288 // Copy object header. |
4282 ASSERT(object->properties()->length() == 0); | 4289 ASSERT(object->properties()->length() == 0); |
4283 ASSERT(object->elements()->length() == 0 || | |
4284 object->elements()->map() == isolate()->heap()->fixed_cow_array_map()); | |
4285 int inobject_properties = object->map()->inobject_properties(); | 4290 int inobject_properties = object->map()->inobject_properties(); |
4286 int header_size = size - inobject_properties * kPointerSize; | 4291 int header_size = object_size - inobject_properties * kPointerSize; |
4287 for (int i = 0; i < header_size; i += kPointerSize) { | 4292 for (int i = 0; i < header_size; i += kPointerSize) { |
4288 __ lw(a2, FieldMemOperand(source, i)); | 4293 if (has_elements && i == JSObject::kElementsOffset) { |
4289 __ sw(a2, FieldMemOperand(result, current_offset + i)); | 4294 __ Addu(a2, result, Operand(elements_offset)); |
4295 __ sw(a2, FieldMemOperand(result, object_offset + i)); | |
danno
2012/02/16 16:09:37
Factor our after if
Michael Starzinger
2012/02/16 17:34:37
Done.
| |
4296 } else { | |
4297 __ lw(a2, FieldMemOperand(source, i)); | |
4298 __ sw(a2, FieldMemOperand(result, object_offset + i)); | |
4299 } | |
4290 } | 4300 } |
4291 | 4301 |
4292 // Copy in-object properties. | 4302 // Copy in-object properties. |
4293 for (int i = 0; i < inobject_properties; i++) { | 4303 for (int i = 0; i < inobject_properties; i++) { |
4294 int total_offset = current_offset + object->GetInObjectPropertyOffset(i); | 4304 int total_offset = object_offset + object->GetInObjectPropertyOffset(i); |
4295 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); | 4305 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); |
4296 if (value->IsJSObject()) { | 4306 if (value->IsJSObject()) { |
4297 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | 4307 Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
4298 __ Addu(a2, result, Operand(*offset)); | 4308 __ Addu(a2, result, Operand(*offset)); |
4299 __ sw(a2, FieldMemOperand(result, total_offset)); | 4309 __ sw(a2, FieldMemOperand(result, total_offset)); |
4300 __ LoadHeapObject(source, value_object); | 4310 __ LoadHeapObject(source, value_object); |
4301 EmitDeepCopy(value_object, result, source, offset); | 4311 EmitDeepCopy(value_object, result, source, offset); |
4302 } else if (value->IsHeapObject()) { | 4312 } else if (value->IsHeapObject()) { |
4303 __ LoadHeapObject(a2, Handle<HeapObject>::cast(value)); | 4313 __ LoadHeapObject(a2, Handle<HeapObject>::cast(value)); |
4304 __ sw(a2, FieldMemOperand(result, total_offset)); | 4314 __ sw(a2, FieldMemOperand(result, total_offset)); |
4305 } else { | 4315 } else { |
4306 __ li(a2, Operand(value)); | 4316 __ li(a2, Operand(value)); |
4307 __ sw(a2, FieldMemOperand(result, total_offset)); | 4317 __ sw(a2, FieldMemOperand(result, total_offset)); |
4308 } | 4318 } |
4309 } | 4319 } |
4320 | |
4321 | |
4322 // Copy elements backing store header. | |
4323 ASSERT(!has_elements || elements->IsFixedArray()); | |
4324 if (has_elements) { | |
4325 __ LoadHeapObject(source, elements); | |
4326 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { | |
4327 __ lw(a2, FieldMemOperand(source, i)); | |
4328 __ sw(a2, FieldMemOperand(result, elements_offset + i)); | |
4329 } | |
4330 } | |
4331 | |
4332 // Copy elements backing store content. | |
4333 ASSERT(!has_elements || elements->IsFixedArray()); | |
4334 int elements_length = has_elements ? elements->length() : 0; | |
4335 for (int i = 0; i < elements_length; i++) { | |
4336 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i); | |
4337 Handle<Object> value = JSObject::GetElement(object, i); | |
4338 if (value->IsJSObject()) { | |
4339 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | |
4340 __ Addu(a2, result, Operand(*offset)); | |
4341 __ sw(a2, FieldMemOperand(result, total_offset)); | |
4342 __ LoadHeapObject(source, value_object); | |
4343 EmitDeepCopy(value_object, result, source, offset); | |
4344 } else if (value->IsHeapObject()) { | |
4345 __ LoadHeapObject(a2, Handle<HeapObject>::cast(value)); | |
4346 __ sw(a2, FieldMemOperand(result, total_offset)); | |
4347 } else { | |
4348 __ li(a2, Operand(value)); | |
4349 __ sw(a2, FieldMemOperand(result, total_offset)); | |
4350 } | |
4351 } | |
4310 } | 4352 } |
4311 | 4353 |
4312 | 4354 |
4313 void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) { | 4355 void LCodeGen::DoFastLiteral(LFastLiteral* instr) { |
4314 int size = instr->hydrogen()->total_size(); | 4356 int size = instr->hydrogen()->total_size(); |
4315 | 4357 |
4316 // Allocate all objects that are part of the literal in one big | 4358 // Allocate all objects that are part of the literal in one big |
4317 // allocation. This avoids multiple limit checks. | 4359 // allocation. This avoids multiple limit checks. |
4318 Label allocated, runtime_allocate; | 4360 Label allocated, runtime_allocate; |
4319 __ AllocateInNewSpace(size, v0, a2, a3, &runtime_allocate, TAG_OBJECT); | 4361 __ AllocateInNewSpace(size, v0, a2, a3, &runtime_allocate, TAG_OBJECT); |
4320 __ jmp(&allocated); | 4362 __ jmp(&allocated); |
4321 | 4363 |
4322 __ bind(&runtime_allocate); | 4364 __ bind(&runtime_allocate); |
4323 __ li(a0, Operand(Smi::FromInt(size))); | 4365 __ li(a0, Operand(Smi::FromInt(size))); |
4324 __ push(a0); | 4366 __ push(a0); |
4325 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | 4367 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
4326 | 4368 |
4327 __ bind(&allocated); | 4369 __ bind(&allocated); |
4328 int offset = 0; | 4370 int offset = 0; |
4329 __ LoadHeapObject(a1, instr->hydrogen()->boilerplate()); | 4371 __ LoadHeapObject(a1, instr->hydrogen()->boilerplate()); |
4330 EmitDeepCopy(instr->hydrogen()->boilerplate(), v0, a1, &offset); | 4372 EmitDeepCopy(instr->hydrogen()->boilerplate(), v0, a1, &offset); |
4331 ASSERT_EQ(size, offset); | 4373 ASSERT_EQ(size, offset); |
4332 } | 4374 } |
4333 | 4375 |
4334 | 4376 |
4335 void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) { | 4377 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
4336 ASSERT(ToRegister(instr->result()).is(v0)); | 4378 ASSERT(ToRegister(instr->result()).is(v0)); |
4337 Handle<FixedArray> literals(instr->environment()->closure()->literals()); | 4379 Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
4338 Handle<FixedArray> constant_properties = | 4380 Handle<FixedArray> constant_properties = |
4339 instr->hydrogen()->constant_properties(); | 4381 instr->hydrogen()->constant_properties(); |
4340 | 4382 |
4341 // Set up the parameters to the stub/runtime call. | 4383 // Set up the parameters to the stub/runtime call. |
4342 __ LoadHeapObject(t0, literals); | 4384 __ LoadHeapObject(t0, literals); |
4343 __ li(a3, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); | 4385 __ li(a3, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
4344 __ li(a2, Operand(constant_properties)); | 4386 __ li(a2, Operand(constant_properties)); |
4345 int flags = instr->hydrogen()->fast_elements() | 4387 int flags = instr->hydrogen()->fast_elements() |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4736 ASSERT(!environment->HasBeenRegistered()); | 4778 ASSERT(!environment->HasBeenRegistered()); |
4737 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | 4779 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
4738 ASSERT(osr_pc_offset_ == -1); | 4780 ASSERT(osr_pc_offset_ == -1); |
4739 osr_pc_offset_ = masm()->pc_offset(); | 4781 osr_pc_offset_ = masm()->pc_offset(); |
4740 } | 4782 } |
4741 | 4783 |
4742 | 4784 |
4743 #undef __ | 4785 #undef __ |
4744 | 4786 |
4745 } } // namespace v8::internal | 4787 } } // namespace v8::internal |
OLD | NEW |