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 4362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4373 } | 4373 } |
4374 | 4374 |
4375 | 4375 |
4376 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, | 4376 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, |
4377 Register result, | 4377 Register result, |
4378 Register source, | 4378 Register source, |
4379 int* offset) { | 4379 int* offset) { |
4380 ASSERT(!source.is(r2)); | 4380 ASSERT(!source.is(r2)); |
4381 ASSERT(!result.is(r2)); | 4381 ASSERT(!result.is(r2)); |
4382 | 4382 |
4383 // Only elements backing stores for non-cow arrays need to be copied. | |
4384 Handle<FixedArrayBase> elements(object->elements()); | |
4385 bool has_elements = elements->length() > 0 && | |
danno
2012/02/16 16:09:37
The empty fixed array should always be used when t
Michael Starzinger
2012/02/16 17:34:37
Actually adding an assertion that all non-COW arra
| |
4386 elements->map() != isolate()->heap()->fixed_cow_array_map(); | |
4387 | |
4383 // Increase the offset so that subsequent objects end up right after | 4388 // Increase the offset so that subsequent objects end up right after |
4384 // this one. | 4389 // this object and its backing store. |
4385 int current_offset = *offset; | 4390 int object_offset = *offset; |
4386 int size = object->map()->instance_size(); | 4391 int object_size = object->map()->instance_size(); |
4387 *offset += size; | 4392 int elements_offset = *offset + object_size; |
4393 int elements_size = has_elements ? elements->Size() : 0; | |
4394 *offset += object_size + elements_size; | |
4388 | 4395 |
4389 // Copy object header. | 4396 // Copy object header. |
4390 ASSERT(object->properties()->length() == 0); | 4397 ASSERT(object->properties()->length() == 0); |
4391 ASSERT(object->elements()->length() == 0 || | |
4392 object->elements()->map() == isolate()->heap()->fixed_cow_array_map()); | |
4393 int inobject_properties = object->map()->inobject_properties(); | 4398 int inobject_properties = object->map()->inobject_properties(); |
4394 int header_size = size - inobject_properties * kPointerSize; | 4399 int header_size = object_size - inobject_properties * kPointerSize; |
4395 for (int i = 0; i < header_size; i += kPointerSize) { | 4400 for (int i = 0; i < header_size; i += kPointerSize) { |
4396 __ ldr(r2, FieldMemOperand(source, i)); | 4401 if (has_elements && i == JSObject::kElementsOffset) { |
4397 __ str(r2, FieldMemOperand(result, current_offset + i)); | 4402 __ add(r2, result, Operand(elements_offset)); |
4403 __ str(r2, FieldMemOperand(result, object_offset + i)); | |
danno
2012/02/16 16:09:37
The store is the same and can be moved out of the
Michael Starzinger
2012/02/16 17:34:37
Done.
| |
4404 } else { | |
4405 __ ldr(r2, FieldMemOperand(source, i)); | |
4406 __ str(r2, FieldMemOperand(result, object_offset + i)); | |
4407 } | |
4398 } | 4408 } |
4399 | 4409 |
4400 // Copy in-object properties. | 4410 // Copy in-object properties. |
4401 for (int i = 0; i < inobject_properties; i++) { | 4411 for (int i = 0; i < inobject_properties; i++) { |
4402 int total_offset = current_offset + object->GetInObjectPropertyOffset(i); | 4412 int total_offset = object_offset + object->GetInObjectPropertyOffset(i); |
4403 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); | 4413 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); |
4404 if (value->IsJSObject()) { | 4414 if (value->IsJSObject()) { |
4405 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | 4415 Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
4406 __ add(r2, result, Operand(*offset)); | 4416 __ add(r2, result, Operand(*offset)); |
4407 __ str(r2, FieldMemOperand(result, total_offset)); | 4417 __ str(r2, FieldMemOperand(result, total_offset)); |
4408 __ LoadHeapObject(source, value_object); | 4418 __ LoadHeapObject(source, value_object); |
4409 EmitDeepCopy(value_object, result, source, offset); | 4419 EmitDeepCopy(value_object, result, source, offset); |
4410 } else if (value->IsHeapObject()) { | 4420 } else if (value->IsHeapObject()) { |
4411 __ LoadHeapObject(r2, Handle<HeapObject>::cast(value)); | 4421 __ LoadHeapObject(r2, Handle<HeapObject>::cast(value)); |
4412 __ str(r2, FieldMemOperand(result, total_offset)); | 4422 __ str(r2, FieldMemOperand(result, total_offset)); |
4413 } else { | 4423 } else { |
4414 __ mov(r2, Operand(value)); | 4424 __ mov(r2, Operand(value)); |
4415 __ str(r2, FieldMemOperand(result, total_offset)); | 4425 __ str(r2, FieldMemOperand(result, total_offset)); |
4416 } | 4426 } |
4417 } | 4427 } |
4428 | |
4429 // Copy elements backing store header. | |
4430 ASSERT(!has_elements || elements->IsFixedArray()); | |
4431 if (has_elements) { | |
4432 __ LoadHeapObject(source, elements); | |
4433 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { | |
4434 __ ldr(r2, FieldMemOperand(source, i)); | |
4435 __ str(r2, FieldMemOperand(result, elements_offset + i)); | |
4436 } | |
4437 } | |
4438 | |
4439 // Copy elements backing store content. | |
4440 ASSERT(!has_elements || elements->IsFixedArray()); | |
4441 int elements_length = has_elements ? elements->length() : 0; | |
4442 for (int i = 0; i < elements_length; i++) { | |
4443 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i); | |
4444 Handle<Object> value = JSObject::GetElement(object, i); | |
4445 if (value->IsJSObject()) { | |
4446 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | |
4447 __ add(r2, result, Operand(*offset)); | |
4448 __ str(r2, FieldMemOperand(result, total_offset)); | |
4449 __ LoadHeapObject(source, value_object); | |
4450 EmitDeepCopy(value_object, result, source, offset); | |
4451 } else if (value->IsHeapObject()) { | |
4452 __ LoadHeapObject(r2, Handle<HeapObject>::cast(value)); | |
4453 __ str(r2, FieldMemOperand(result, total_offset)); | |
4454 } else { | |
4455 __ mov(r2, Operand(value)); | |
4456 __ str(r2, FieldMemOperand(result, total_offset)); | |
4457 } | |
4458 } | |
4418 } | 4459 } |
4419 | 4460 |
4420 | 4461 |
4421 void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) { | 4462 void LCodeGen::DoFastLiteral(LFastLiteral* instr) { |
4422 int size = instr->hydrogen()->total_size(); | 4463 int size = instr->hydrogen()->total_size(); |
4423 | 4464 |
4424 // Allocate all objects that are part of the literal in one big | 4465 // Allocate all objects that are part of the literal in one big |
4425 // allocation. This avoids multiple limit checks. | 4466 // allocation. This avoids multiple limit checks. |
4426 Label allocated, runtime_allocate; | 4467 Label allocated, runtime_allocate; |
4427 __ AllocateInNewSpace(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); | 4468 __ AllocateInNewSpace(size, r0, r2, r3, &runtime_allocate, TAG_OBJECT); |
4428 __ jmp(&allocated); | 4469 __ jmp(&allocated); |
4429 | 4470 |
4430 __ bind(&runtime_allocate); | 4471 __ bind(&runtime_allocate); |
4431 __ mov(r0, Operand(Smi::FromInt(size))); | 4472 __ mov(r0, Operand(Smi::FromInt(size))); |
4432 __ push(r0); | 4473 __ push(r0); |
4433 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | 4474 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
4434 | 4475 |
4435 __ bind(&allocated); | 4476 __ bind(&allocated); |
4436 int offset = 0; | 4477 int offset = 0; |
4437 __ LoadHeapObject(r1, instr->hydrogen()->boilerplate()); | 4478 __ LoadHeapObject(r1, instr->hydrogen()->boilerplate()); |
4438 EmitDeepCopy(instr->hydrogen()->boilerplate(), r0, r1, &offset); | 4479 EmitDeepCopy(instr->hydrogen()->boilerplate(), r0, r1, &offset); |
4439 ASSERT_EQ(size, offset); | 4480 ASSERT_EQ(size, offset); |
4440 } | 4481 } |
4441 | 4482 |
4442 | 4483 |
4443 void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) { | 4484 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
4444 Handle<FixedArray> literals(instr->environment()->closure()->literals()); | 4485 Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
4445 Handle<FixedArray> constant_properties = | 4486 Handle<FixedArray> constant_properties = |
4446 instr->hydrogen()->constant_properties(); | 4487 instr->hydrogen()->constant_properties(); |
4447 | 4488 |
4448 // Set up the parameters to the stub/runtime call. | 4489 // Set up the parameters to the stub/runtime call. |
4449 __ LoadHeapObject(r4, literals); | 4490 __ LoadHeapObject(r4, literals); |
4450 __ mov(r3, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); | 4491 __ mov(r3, Operand(Smi::FromInt(instr->hydrogen()->literal_index()))); |
4451 __ mov(r2, Operand(constant_properties)); | 4492 __ mov(r2, Operand(constant_properties)); |
4452 int flags = instr->hydrogen()->fast_elements() | 4493 int flags = instr->hydrogen()->fast_elements() |
4453 ? ObjectLiteral::kFastElements | 4494 ? ObjectLiteral::kFastElements |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
4808 ASSERT(osr_pc_offset_ == -1); | 4849 ASSERT(osr_pc_offset_ == -1); |
4809 osr_pc_offset_ = masm()->pc_offset(); | 4850 osr_pc_offset_ = masm()->pc_offset(); |
4810 } | 4851 } |
4811 | 4852 |
4812 | 4853 |
4813 | 4854 |
4814 | 4855 |
4815 #undef __ | 4856 #undef __ |
4816 | 4857 |
4817 } } // namespace v8::internal | 4858 } } // namespace v8::internal |
OLD | NEW |