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 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 __ movq(FieldOperand(result, object_offset + i), rcx); | |
|
danno
2012/02/16 16:09:37
After if
Michael Starzinger
2012/02/16 17:34:37
Done.
| |
| 4000 } else { | |
| 4001 __ movq(rcx, FieldOperand(source, i)); | |
| 4002 __ movq(FieldOperand(result, object_offset + i), rcx); | |
| 4003 } | |
| 3994 } | 4004 } |
| 3995 | 4005 |
| 3996 // Copy in-object properties. | 4006 // Copy in-object properties. |
| 3997 for (int i = 0; i < inobject_properties; i++) { | 4007 for (int i = 0; i < inobject_properties; i++) { |
| 3998 int total_offset = current_offset + object->GetInObjectPropertyOffset(i); | 4008 int total_offset = object_offset + object->GetInObjectPropertyOffset(i); |
| 3999 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); | 4009 Handle<Object> value = Handle<Object>(object->InObjectPropertyAt(i)); |
| 4000 if (value->IsJSObject()) { | 4010 if (value->IsJSObject()) { |
| 4001 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | 4011 Handle<JSObject> value_object = Handle<JSObject>::cast(value); |
| 4002 __ lea(rcx, Operand(result, *offset)); | 4012 __ lea(rcx, Operand(result, *offset)); |
| 4003 __ movq(FieldOperand(result, total_offset), rcx); | 4013 __ movq(FieldOperand(result, total_offset), rcx); |
| 4004 __ LoadHeapObject(source, value_object); | 4014 __ LoadHeapObject(source, value_object); |
| 4005 EmitDeepCopy(value_object, result, source, offset); | 4015 EmitDeepCopy(value_object, result, source, offset); |
| 4006 } else if (value->IsHeapObject()) { | 4016 } else if (value->IsHeapObject()) { |
| 4007 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); | 4017 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); |
| 4008 __ movq(FieldOperand(result, total_offset), rcx); | 4018 __ movq(FieldOperand(result, total_offset), rcx); |
| 4009 } else { | 4019 } else { |
| 4010 __ movq(rcx, value, RelocInfo::NONE); | 4020 __ movq(rcx, value, RelocInfo::NONE); |
| 4011 __ movq(FieldOperand(result, total_offset), rcx); | 4021 __ movq(FieldOperand(result, total_offset), rcx); |
| 4012 } | 4022 } |
| 4013 } | 4023 } |
| 4024 | |
| 4025 // Copy elements backing store header. | |
| 4026 ASSERT(!has_elements || elements->IsFixedArray()); | |
| 4027 if (has_elements) { | |
| 4028 __ LoadHeapObject(source, elements); | |
| 4029 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { | |
| 4030 __ movq(rcx, FieldOperand(source, i)); | |
| 4031 __ movq(FieldOperand(result, elements_offset + i), rcx); | |
| 4032 } | |
| 4033 } | |
| 4034 | |
| 4035 // Copy elements backing store content. | |
| 4036 ASSERT(!has_elements || elements->IsFixedArray()); | |
| 4037 int elements_length = has_elements ? elements->length() : 0; | |
| 4038 for (int i = 0; i < elements_length; i++) { | |
| 4039 int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i); | |
| 4040 Handle<Object> value = JSObject::GetElement(object, i); | |
| 4041 if (value->IsJSObject()) { | |
| 4042 Handle<JSObject> value_object = Handle<JSObject>::cast(value); | |
| 4043 __ lea(rcx, Operand(result, *offset)); | |
| 4044 __ movq(FieldOperand(result, total_offset), rcx); | |
| 4045 __ LoadHeapObject(source, value_object); | |
| 4046 EmitDeepCopy(value_object, result, source, offset); | |
| 4047 } else if (value->IsHeapObject()) { | |
| 4048 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); | |
| 4049 __ movq(FieldOperand(result, total_offset), rcx); | |
| 4050 } else { | |
| 4051 __ movq(rcx, value, RelocInfo::NONE); | |
| 4052 __ movq(FieldOperand(result, total_offset), rcx); | |
| 4053 } | |
| 4054 } | |
| 4014 } | 4055 } |
| 4015 | 4056 |
| 4016 | 4057 |
| 4017 void LCodeGen::DoObjectLiteralFast(LObjectLiteralFast* instr) { | 4058 void LCodeGen::DoFastLiteral(LFastLiteral* instr) { |
| 4018 int size = instr->hydrogen()->total_size(); | 4059 int size = instr->hydrogen()->total_size(); |
| 4019 | 4060 |
| 4020 // Allocate all objects that are part of the literal in one big | 4061 // Allocate all objects that are part of the literal in one big |
| 4021 // allocation. This avoids multiple limit checks. | 4062 // allocation. This avoids multiple limit checks. |
| 4022 Label allocated, runtime_allocate; | 4063 Label allocated, runtime_allocate; |
| 4023 __ AllocateInNewSpace(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); | 4064 __ AllocateInNewSpace(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); |
| 4024 __ jmp(&allocated); | 4065 __ jmp(&allocated); |
| 4025 | 4066 |
| 4026 __ bind(&runtime_allocate); | 4067 __ bind(&runtime_allocate); |
| 4027 __ Push(Smi::FromInt(size)); | 4068 __ Push(Smi::FromInt(size)); |
| 4028 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | 4069 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
| 4029 | 4070 |
| 4030 __ bind(&allocated); | 4071 __ bind(&allocated); |
| 4031 int offset = 0; | 4072 int offset = 0; |
| 4032 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate()); | 4073 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate()); |
| 4033 EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset); | 4074 EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset); |
| 4034 ASSERT_EQ(size, offset); | 4075 ASSERT_EQ(size, offset); |
| 4035 } | 4076 } |
| 4036 | 4077 |
| 4037 | 4078 |
| 4038 void LCodeGen::DoObjectLiteralGeneric(LObjectLiteralGeneric* instr) { | 4079 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
| 4039 Handle<FixedArray> literals(instr->environment()->closure()->literals()); | 4080 Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
| 4040 Handle<FixedArray> constant_properties = | 4081 Handle<FixedArray> constant_properties = |
| 4041 instr->hydrogen()->constant_properties(); | 4082 instr->hydrogen()->constant_properties(); |
| 4042 | 4083 |
| 4043 // Set up the parameters to the stub/runtime call. | 4084 // Set up the parameters to the stub/runtime call. |
| 4044 __ PushHeapObject(literals); | 4085 __ PushHeapObject(literals); |
| 4045 __ Push(Smi::FromInt(instr->hydrogen()->literal_index())); | 4086 __ Push(Smi::FromInt(instr->hydrogen()->literal_index())); |
| 4046 __ Push(constant_properties); | 4087 __ Push(constant_properties); |
| 4047 int flags = instr->hydrogen()->fast_elements() | 4088 int flags = instr->hydrogen()->fast_elements() |
| 4048 ? ObjectLiteral::kFastElements | 4089 ? ObjectLiteral::kFastElements |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4412 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); | 4453 RegisterEnvironmentForDeoptimization(environment, Safepoint::kNoLazyDeopt); |
| 4413 ASSERT(osr_pc_offset_ == -1); | 4454 ASSERT(osr_pc_offset_ == -1); |
| 4414 osr_pc_offset_ = masm()->pc_offset(); | 4455 osr_pc_offset_ = masm()->pc_offset(); |
| 4415 } | 4456 } |
| 4416 | 4457 |
| 4417 #undef __ | 4458 #undef __ |
| 4418 | 4459 |
| 4419 } } // namespace v8::internal | 4460 } } // namespace v8::internal |
| 4420 | 4461 |
| 4421 #endif // V8_TARGET_ARCH_X64 | 4462 #endif // V8_TARGET_ARCH_X64 |
| OLD | NEW |