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 4922 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4933 ASSERT(instr->hydrogen()->depth() == 1); | 4933 ASSERT(instr->hydrogen()->depth() == 1); |
4934 FastCloneShallowArrayStub::Mode mode = | 4934 FastCloneShallowArrayStub::Mode mode = |
4935 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; | 4935 FastCloneShallowArrayStub::COPY_ON_WRITE_ELEMENTS; |
4936 FastCloneShallowArrayStub stub(mode, length); | 4936 FastCloneShallowArrayStub stub(mode, length); |
4937 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 4937 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
4938 } else if (instr->hydrogen()->depth() > 1) { | 4938 } else if (instr->hydrogen()->depth() > 1) { |
4939 CallRuntime(Runtime::kCreateArrayLiteral, 3, instr); | 4939 CallRuntime(Runtime::kCreateArrayLiteral, 3, instr); |
4940 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { | 4940 } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) { |
4941 CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr); | 4941 CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr); |
4942 } else { | 4942 } else { |
4943 FastCloneShallowArrayStub::Mode mode = | 4943 // TODO(mvstanton): I'm doing more work than necessary here by running |
| 4944 // CLONE_ANY_ELEMENTS instead of the more specific stub, but I'm doing it |
| 4945 // just because I want to track allocation info. Alternative approach: quick |
| 4946 // baking allocation tracking info into this field, instead just have it on |
| 4947 // all the time? |
| 4948 FastCloneShallowArrayStub::Mode mode = FastCloneShallowArrayStub:: |
| 4949 CLONE_ANY_ELEMENTS_WITH_ALLOCATION_SITE_INFO; |
| 4950 /* |
4944 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS | 4951 boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS |
4945 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | 4952 ? FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
4946 : FastCloneShallowArrayStub::CLONE_ELEMENTS; | 4953 : FastCloneShallowArrayStub::CLONE_ELEMENTS; |
| 4954 */ |
4947 FastCloneShallowArrayStub stub(mode, length); | 4955 FastCloneShallowArrayStub stub(mode, length); |
4948 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 4956 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
4949 } | 4957 } |
4950 } | 4958 } |
4951 | 4959 |
4952 | 4960 |
4953 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, | 4961 void LCodeGen::EmitDeepCopy(Handle<JSObject> object, |
4954 Register result, | 4962 Register result, |
4955 Register source, | 4963 Register source, |
4956 int* offset) { | 4964 int* offset, |
| 4965 bool create_allocation_site_info) { |
4957 ASSERT(!source.is(rcx)); | 4966 ASSERT(!source.is(rcx)); |
4958 ASSERT(!result.is(rcx)); | 4967 ASSERT(!result.is(rcx)); |
4959 | 4968 |
4960 // Only elements backing stores for non-COW arrays need to be copied. | 4969 // Only elements backing stores for non-COW arrays need to be copied. |
4961 Handle<FixedArrayBase> elements(object->elements()); | 4970 Handle<FixedArrayBase> elements(object->elements()); |
4962 bool has_elements = elements->length() > 0 && | 4971 bool has_elements = elements->length() > 0 && |
4963 elements->map() != isolate()->heap()->fixed_cow_array_map(); | 4972 elements->map() != isolate()->heap()->fixed_cow_array_map(); |
4964 | 4973 |
4965 // Increase the offset so that subsequent objects end up right after | 4974 // Increase the offset so that subsequent objects end up right after |
4966 // this object and its backing store. | 4975 // this object and its backing store. |
4967 int object_offset = *offset; | 4976 int object_offset = *offset; |
4968 int object_size = object->map()->instance_size(); | 4977 int object_size = object->map()->instance_size(); |
4969 int elements_offset = *offset + object_size; | 4978 int elements_offset = *offset + object_size; |
| 4979 if (create_allocation_site_info) { |
| 4980 elements_offset += AllocationSiteInfo::kSize; |
| 4981 } |
4970 int elements_size = has_elements ? elements->Size() : 0; | 4982 int elements_size = has_elements ? elements->Size() : 0; |
4971 *offset += object_size + elements_size; | 4983 *offset += object_size + elements_size; |
| 4984 if (create_allocation_site_info) { |
| 4985 *offset += AllocationSiteInfo::kSize; |
| 4986 } |
4972 | 4987 |
4973 // Copy object header. | 4988 // Copy object header. |
4974 ASSERT(object->properties()->length() == 0); | 4989 ASSERT(object->properties()->length() == 0); |
4975 int inobject_properties = object->map()->inobject_properties(); | 4990 int inobject_properties = object->map()->inobject_properties(); |
4976 int header_size = object_size - inobject_properties * kPointerSize; | 4991 int header_size = object_size - inobject_properties * kPointerSize; |
4977 for (int i = 0; i < header_size; i += kPointerSize) { | 4992 for (int i = 0; i < header_size; i += kPointerSize) { |
4978 if (has_elements && i == JSObject::kElementsOffset) { | 4993 if (has_elements && i == JSObject::kElementsOffset) { |
4979 __ lea(rcx, Operand(result, elements_offset)); | 4994 __ lea(rcx, Operand(result, elements_offset)); |
4980 } else { | 4995 } else { |
4981 __ movq(rcx, FieldOperand(source, i)); | 4996 __ movq(rcx, FieldOperand(source, i)); |
(...skipping 13 matching lines...) Expand all Loading... |
4995 EmitDeepCopy(value_object, result, source, offset); | 5010 EmitDeepCopy(value_object, result, source, offset); |
4996 } else if (value->IsHeapObject()) { | 5011 } else if (value->IsHeapObject()) { |
4997 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); | 5012 __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value)); |
4998 __ movq(FieldOperand(result, total_offset), rcx); | 5013 __ movq(FieldOperand(result, total_offset), rcx); |
4999 } else { | 5014 } else { |
5000 __ movq(rcx, value, RelocInfo::NONE64); | 5015 __ movq(rcx, value, RelocInfo::NONE64); |
5001 __ movq(FieldOperand(result, total_offset), rcx); | 5016 __ movq(FieldOperand(result, total_offset), rcx); |
5002 } | 5017 } |
5003 } | 5018 } |
5004 | 5019 |
| 5020 // Build Allocation Site Info if desired |
| 5021 if (create_allocation_site_info) { |
| 5022 __ LoadRoot(kScratchRegister, Heap::kAllocationSiteInfoMapRootIndex); |
| 5023 __ movq(FieldOperand(result, object_size), kScratchRegister); |
| 5024 __ movq(FieldOperand(result, object_size + kPointerSize), source); |
| 5025 } |
| 5026 |
5005 if (has_elements) { | 5027 if (has_elements) { |
5006 // Copy elements backing store header. | 5028 // Copy elements backing store header. |
5007 __ LoadHeapObject(source, elements); | 5029 __ LoadHeapObject(source, elements); |
5008 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { | 5030 for (int i = 0; i < FixedArray::kHeaderSize; i += kPointerSize) { |
5009 __ movq(rcx, FieldOperand(source, i)); | 5031 __ movq(rcx, FieldOperand(source, i)); |
5010 __ movq(FieldOperand(result, elements_offset + i), rcx); | 5032 __ movq(FieldOperand(result, elements_offset + i), rcx); |
5011 } | 5033 } |
5012 | 5034 |
5013 // Copy elements backing store content. | 5035 // Copy elements backing store content. |
5014 int elements_length = elements->length(); | 5036 int elements_length = elements->length(); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5075 __ AllocateInNewSpace(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); | 5097 __ AllocateInNewSpace(size, rax, rcx, rdx, &runtime_allocate, TAG_OBJECT); |
5076 __ jmp(&allocated); | 5098 __ jmp(&allocated); |
5077 | 5099 |
5078 __ bind(&runtime_allocate); | 5100 __ bind(&runtime_allocate); |
5079 __ Push(Smi::FromInt(size)); | 5101 __ Push(Smi::FromInt(size)); |
5080 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); | 5102 CallRuntime(Runtime::kAllocateInNewSpace, 1, instr); |
5081 | 5103 |
5082 __ bind(&allocated); | 5104 __ bind(&allocated); |
5083 int offset = 0; | 5105 int offset = 0; |
5084 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate()); | 5106 __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate()); |
5085 EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset); | 5107 EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset, |
| 5108 instr->hydrogen()->create_allocation_site_info()); |
5086 ASSERT_EQ(size, offset); | 5109 ASSERT_EQ(size, offset); |
5087 } | 5110 } |
5088 | 5111 |
5089 | 5112 |
5090 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { | 5113 void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) { |
5091 Handle<FixedArray> literals(instr->environment()->closure()->literals()); | 5114 Handle<FixedArray> literals(instr->environment()->closure()->literals()); |
5092 Handle<FixedArray> constant_properties = | 5115 Handle<FixedArray> constant_properties = |
5093 instr->hydrogen()->constant_properties(); | 5116 instr->hydrogen()->constant_properties(); |
5094 | 5117 |
5095 // Set up the parameters to the stub/runtime call. | 5118 // Set up the parameters to the stub/runtime call. |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5553 FixedArray::kHeaderSize - kPointerSize)); | 5576 FixedArray::kHeaderSize - kPointerSize)); |
5554 __ bind(&done); | 5577 __ bind(&done); |
5555 } | 5578 } |
5556 | 5579 |
5557 | 5580 |
5558 #undef __ | 5581 #undef __ |
5559 | 5582 |
5560 } } // namespace v8::internal | 5583 } } // namespace v8::internal |
5561 | 5584 |
5562 #endif // V8_TARGET_ARCH_X64 | 5585 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |