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 3958 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3969 } | 3969 } |
3970 | 3970 |
3971 | 3971 |
3972 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, | 3972 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, |
3973 Register result, | 3973 Register result, |
3974 Register source, | 3974 Register source, |
3975 int* offset) { | 3975 int* offset) { |
3976 ASSERT(!source.is(rcx)); | 3976 ASSERT(!source.is(rcx)); |
3977 ASSERT(!result.is(rcx)); | 3977 ASSERT(!result.is(rcx)); |
3978 | 3978 |
| 3979 // Only elements backing stores for non-COW arrays need to be copied. |
| 3980 Handle<FixedArrayBase> elements(object->elements()); |
| 3981 bool has_elements = elements->length() > 0 && |
| 3982 elements->map() != isolate()->heap()->fixed_cow_array_map(); |
| 3983 |
3979 // Increase the offset so that subsequent objects end up right after | 3984 // Increase the offset so that subsequent objects end up right after |
3980 // this one. | 3985 // this object and its backing store. |
3981 int current_offset = *offset; | 3986 int object_offset = *offset; |
3982 int size = object->map()->instance_size(); | 3987 int object_size = object->map()->instance_size(); |
3983 *offset += size; | 3988 int elements_offset = *offset + object_size; |
| 3989 int elements_size = has_elements ? elements->Size() : 0; |
| 3990 *offset += object_size + elements_size; |
3984 | 3991 |
3985 // Copy object header. | 3992 // Copy object header. |
3986 ASSERT(object->properties()->length() == 0); | 3993 ASSERT(object->properties()->length() == 0); |
3987 ASSERT(object->elements()->length() == 0 || | |
3988 object->elements()->map() == isolate()->heap()->fixed_cow_array_map()); | |
3989 int inobject_properties = object->map()->inobject_properties(); | 3994 int inobject_properties = object->map()->inobject_properties(); |
3990 int header_size = size - inobject_properties * kPointerSize; | 3995 int header_size = object_size - inobject_properties * kPointerSize; |
3991 for (int i = 0; i < header_size; i += kPointerSize) { | 3996 for (int i = 0; i < header_size; i += kPointerSize) { |
3992 __ movq(rcx, FieldOperand(source, i)); | 3997 if (has_elements && i == JSObject::kElementsOffset) { |
3993 __ movq(FieldOperand(result, current_offset + i), rcx); | 3998 __ lea(rcx, Operand(result, elements_offset)); |
| 3999 } else { |
| 4000 __ movq(rcx, FieldOperand(source, i)); |
| 4001 } |
| 4002 __ movq(FieldOperand(result, object_offset + i), rcx); |
3994 } | 4003 } |
3995 | 4004 |
3996 // Copy in-object properties. | 4005 // Copy in-object properties. |
3997 for (int i = 0; i < inobject_properties; i++) { | 4006 for (int i = 0; i < inobject_properties; i++) { |
3998 int total_offset = current_offset + object->GetInObjectPropertyOffset(i); | 4007 int total_offset = object_offset + object->GetInObjectPropertyOffset(i); |
3999 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); | 4008 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); |
4000 if (value->IsJSObject()) { | 4009 if (value->IsJSObject()) { |
4001 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | 4010 Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
4002 __ lea(rcx, Operand(result, *offset)); | 4011 __ lea(rcx, Operand(result, *offset)); |
4003 __ movq(FieldOperand(result, total_offset), rcx); | 4012 __ movq(FieldOperand(result, total_offset), rcx); |
4004 __ LoadHeapObject(source, value_object); | 4013 __ LoadHeapObject(source, value_object); |
4005 EmitDeepCopy(value_object, result, source, offset); | 4014 EmitDeepCopy(value_object, result, source, offset); |
4006 } else if (value->IsHeapObject()) { | 4015 } else if (value->IsHeapObject()) { |
4007 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); | 4016 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); |
4008 __ movq(FieldOperand(result, total_offset), rcx); | 4017 __ movq(FieldOperand(result, total_offset), rcx); |
4009 } else { | 4018 } else { |
4010 __ movq(rcx, value, RelocInfo::NONE); | 4019 __ movq(rcx, value, RelocInfo::NONE); |
4011 __ movq(FieldOperand(result, total_offset), rcx); | 4020 __ movq(FieldOperand(result, total_offset), rcx); |
4012 } | 4021 } |
4013 } | 4022 } |
| 4023 |
| 4024 // Copy elements backing store header. |
| 4025 ASSERT(!has_elements || elements->IsFixedArray()); |
| 4026 if (has_elements) { |
| 4027 __ LoadHeapObject(source, elements); |
| 4028 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { |
| 4029 __ movq(rcx, FieldOperand(source, i)); |
| 4030 __ movq(FieldOperand(result, elements_offset + i), rcx); |
| 4031 } |
| 4032 } |
| 4033 |
| 4034 // Copy elements backing store content. |
| 4035 ASSERT(!has_elements || elements->IsFixedArray()); |
| 4036 int elements_length = has_elements ? elements->length() : 0; |
| 4037 for (int i = 0; i < elements_length; i++) { |
| 4038 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i); |
| 4039 Handle<Object> value = JSObject::GetElement(object, i); |
| 4040 if (value->IsJSObject()) { |
| 4041 Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
| 4042 __ lea(rcx, Operand(result, *offset)); |
| 4043 __ movq(FieldOperand(result, total_offset), rcx); |
| 4044 __ LoadHeapObject(source, value_object); |
| 4045 EmitDeepCopy(value_object, result, source, offset); |
| 4046 } else if (value->IsHeapObject()) { |
| 4047 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); |
| 4048 __ movq(FieldOperand(result, total_offset), rcx); |
| 4049 } else { |
| 4050 __ movq(rcx, value, RelocInfo::NONE); |
| 4051 __ movq(FieldOperand(result, total_offset), rcx); |
| 4052 } |
| 4053 } |
4014 } | 4054 } |
4015 | 4055 |
4016 | 4056 |
4017 void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) { | 4057 void LCodeGen::DoFastLiteral(LFastLiteral* instr) { |
4018 int size = instr->hydrogen()->total_size(); | 4058 int size = instr->hydrogen()->total_size(); |
4019 | 4059 |
4020 // Allocate all objects that are part of the literal in one big | 4060 // Allocate all objects that are part of the literal in one big |
4021 // allocation. This avoids multiple limit checks. | 4061 // allocation. This avoids multiple limit checks. |
4022 Label allocated, runtime_allocate; | 4062 Label allocated, runtime_allocate; |
4023 __ AllocateInNewSpace(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); | 4063 __ AllocateInNewSpace(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); |
4024 __ jmp(&allocated); | 4064 __ jmp(&allocated); |
4025 | 4065 |
4026 __ bind(&runtime_allocate); | 4066 __ bind(&runtime_allocate); |
4027 __ Push(Smi::FromInt(size)); | 4067 __ Push(Smi::FromInt(size)); |
4028 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | 4068 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
4029 | 4069 |
4030 __ bind(&allocated); | 4070 __ bind(&allocated); |
4031 int offset = 0; | 4071 int offset = 0; |
4032 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate()); | 4072 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate()); |
4033 EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset); | 4073 EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset); |
4034 ASSERT_EQ(size, offset); | 4074 ASSERT_EQ(size, offset); |
4035 } | 4075 } |
4036 | 4076 |
4037 | 4077 |
4038 void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) { | 4078 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
4039 Handle<FixedArray> literals(instr->environment()->closure()->literals()); | 4079 Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
4040 Handle<FixedArray> constant_properties = | 4080 Handle<FixedArray> constant_properties = |
4041 instr->hydrogen()->constant_properties(); | 4081 instr->hydrogen()->constant_properties(); |
4042 | 4082 |
4043 // Set up the parameters to the stub/runtime call. | 4083 // Set up the parameters to the stub/runtime call. |
4044 __ PushHeapObject(literals); | 4084 __ PushHeapObject(literals); |
4045 __ Push(Smi::FromInt(instr->hydrogen()->literal_index())); | 4085 __ Push(Smi::FromInt(instr->hydrogen()->literal_index())); |
4046 __ Push(constant_properties); | 4086 __ Push(constant_properties); |
4047 int flags = instr->hydrogen()->fast_elements() | 4087 int flags = instr->hydrogen()->fast_elements() |
4048 ? ObjectLiteral::kFastElements | 4088 ? ObjectLiteral::kFastElements |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4412 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | 4452 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
4413 ASSERT(osr_pc_offset_ == -1); | 4453 ASSERT(osr_pc_offset_ == -1); |
4414 osr_pc_offset_ = masm()->pc_offset(); | 4454 osr_pc_offset_ = masm()->pc_offset(); |
4415 } | 4455 } |
4416 | 4456 |
4417 #undef __ | 4457 #undef __ |
4418 | 4458 |
4419 } } // namespace v8::internal | 4459 } } // namespace v8::internal |
4420 | 4460 |
4421 #endif // V8_TARGET_ARCH_X64 | 4461 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |