| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/v8.h" | 5 #include "src/v8.h" |
| 6 | 6 |
| 7 #include "src/accessors.h" | 7 #include "src/accessors.h" |
| 8 #include "src/api.h" | 8 #include "src/api.h" |
| 9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
| 10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
| (...skipping 2786 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2797 #define ALLOCATE_PARTIAL_MAP(instance_type, size, field_name) \ | 2797 #define ALLOCATE_PARTIAL_MAP(instance_type, size, field_name) \ |
| 2798 { \ | 2798 { \ |
| 2799 Map* map; \ | 2799 Map* map; \ |
| 2800 if (!AllocatePartialMap((instance_type), (size)).To(&map)) return false; \ | 2800 if (!AllocatePartialMap((instance_type), (size)).To(&map)) return false; \ |
| 2801 set_##field_name##_map(map); \ | 2801 set_##field_name##_map(map); \ |
| 2802 } | 2802 } |
| 2803 | 2803 |
| 2804 ALLOCATE_PARTIAL_MAP(FIXED_ARRAY_TYPE, kVariableSizeSentinel, fixed_array); | 2804 ALLOCATE_PARTIAL_MAP(FIXED_ARRAY_TYPE, kVariableSizeSentinel, fixed_array); |
| 2805 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, undefined); | 2805 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, undefined); |
| 2806 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, null); | 2806 ALLOCATE_PARTIAL_MAP(ODDBALL_TYPE, Oddball::kSize, null); |
| 2807 ALLOCATE_PARTIAL_MAP(FEEDBACK_VECTOR_TYPE, kVariableSizeSentinel, |
| 2808 feedback_vector); |
| 2807 | 2809 |
| 2808 #undef ALLOCATE_PARTIAL_MAP | 2810 #undef ALLOCATE_PARTIAL_MAP |
| 2809 } | 2811 } |
| 2810 | 2812 |
| 2811 // Allocate the empty array. | 2813 // Allocate the empty array. |
| 2812 { | 2814 { |
| 2813 AllocationResult allocation = AllocateEmptyFixedArray(); | 2815 AllocationResult allocation = AllocateEmptyFixedArray(); |
| 2814 if (!allocation.To(&obj)) return false; | 2816 if (!allocation.To(&obj)) return false; |
| 2815 } | 2817 } |
| 2816 set_empty_fixed_array(FixedArray::cast(obj)); | 2818 set_empty_fixed_array(FixedArray::cast(obj)); |
| 2817 | 2819 |
| 2820 // Allocate the empty feedback vector. |
| 2821 { |
| 2822 AllocationResult allocation = AllocateEmptyFeedbackVector(); |
| 2823 if (!allocation.To(&obj)) return false; |
| 2824 } |
| 2825 set_empty_feedback_vector(TypeFeedbackVector::cast(obj)); |
| 2826 |
| 2818 { | 2827 { |
| 2819 AllocationResult allocation = Allocate(null_map(), OLD_SPACE); | 2828 AllocationResult allocation = Allocate(null_map(), OLD_SPACE); |
| 2820 if (!allocation.To(&obj)) return false; | 2829 if (!allocation.To(&obj)) return false; |
| 2821 } | 2830 } |
| 2822 set_null_value(Oddball::cast(obj)); | 2831 set_null_value(Oddball::cast(obj)); |
| 2823 Oddball::cast(obj)->set_kind(Oddball::kNull); | 2832 Oddball::cast(obj)->set_kind(Oddball::kNull); |
| 2824 | 2833 |
| 2825 { | 2834 { |
| 2826 AllocationResult allocation = Allocate(undefined_map(), OLD_SPACE); | 2835 AllocationResult allocation = Allocate(undefined_map(), OLD_SPACE); |
| 2827 if (!allocation.To(&obj)) return false; | 2836 if (!allocation.To(&obj)) return false; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2869 } | 2878 } |
| 2870 | 2879 |
| 2871 null_map()->set_code_cache(empty_fixed_array()); | 2880 null_map()->set_code_cache(empty_fixed_array()); |
| 2872 null_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); | 2881 null_map()->set_dependent_code(DependentCode::cast(empty_fixed_array())); |
| 2873 null_map()->set_raw_transitions(Smi::FromInt(0)); | 2882 null_map()->set_raw_transitions(Smi::FromInt(0)); |
| 2874 null_map()->set_instance_descriptors(empty_descriptor_array()); | 2883 null_map()->set_instance_descriptors(empty_descriptor_array()); |
| 2875 if (FLAG_unbox_double_fields) { | 2884 if (FLAG_unbox_double_fields) { |
| 2876 null_map()->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); | 2885 null_map()->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); |
| 2877 } | 2886 } |
| 2878 | 2887 |
| 2888 feedback_vector_map()->set_code_cache(empty_fixed_array()); |
| 2889 feedback_vector_map()->set_dependent_code( |
| 2890 DependentCode::cast(empty_fixed_array())); |
| 2891 feedback_vector_map()->set_raw_transitions(Smi::FromInt(0)); |
| 2892 feedback_vector_map()->set_instance_descriptors(empty_descriptor_array()); |
| 2893 if (FLAG_unbox_double_fields) { |
| 2894 feedback_vector_map()->set_layout_descriptor( |
| 2895 LayoutDescriptor::FastPointerLayout()); |
| 2896 } |
| 2897 |
| 2879 // Fix prototype object for existing maps. | 2898 // Fix prototype object for existing maps. |
| 2880 meta_map()->set_prototype(null_value()); | 2899 meta_map()->set_prototype(null_value()); |
| 2881 meta_map()->set_constructor_or_backpointer(null_value()); | 2900 meta_map()->set_constructor_or_backpointer(null_value()); |
| 2882 | 2901 |
| 2883 fixed_array_map()->set_prototype(null_value()); | 2902 fixed_array_map()->set_prototype(null_value()); |
| 2884 fixed_array_map()->set_constructor_or_backpointer(null_value()); | 2903 fixed_array_map()->set_constructor_or_backpointer(null_value()); |
| 2885 | 2904 |
| 2886 undefined_map()->set_prototype(null_value()); | 2905 undefined_map()->set_prototype(null_value()); |
| 2887 undefined_map()->set_constructor_or_backpointer(null_value()); | 2906 undefined_map()->set_constructor_or_backpointer(null_value()); |
| 2888 | 2907 |
| 2889 null_map()->set_prototype(null_value()); | 2908 null_map()->set_prototype(null_value()); |
| 2890 null_map()->set_constructor_or_backpointer(null_value()); | 2909 null_map()->set_constructor_or_backpointer(null_value()); |
| 2891 | 2910 |
| 2911 feedback_vector_map()->set_prototype(null_value()); |
| 2912 feedback_vector_map()->set_constructor_or_backpointer(null_value()); |
| 2913 |
| 2892 { // Map allocation | 2914 { // Map allocation |
| 2893 #define ALLOCATE_MAP(instance_type, size, field_name) \ | 2915 #define ALLOCATE_MAP(instance_type, size, field_name) \ |
| 2894 { \ | 2916 { \ |
| 2895 Map* map; \ | 2917 Map* map; \ |
| 2896 if (!AllocateMap((instance_type), size).To(&map)) return false; \ | 2918 if (!AllocateMap((instance_type), size).To(&map)) return false; \ |
| 2897 set_##field_name##_map(map); \ | 2919 set_##field_name##_map(map); \ |
| 2898 } | 2920 } |
| 2899 | 2921 |
| 2900 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \ | 2922 #define ALLOCATE_VARSIZE_MAP(instance_type, field_name) \ |
| 2901 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name) | 2923 ALLOCATE_MAP(instance_type, kVariableSizeSentinel, field_name) |
| (...skipping 1564 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4466 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); | 4488 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); |
| 4467 if (!allocation.To(&result)) return allocation; | 4489 if (!allocation.To(&result)) return allocation; |
| 4468 } | 4490 } |
| 4469 // Initialize the object. | 4491 // Initialize the object. |
| 4470 result->set_map_no_write_barrier(fixed_array_map()); | 4492 result->set_map_no_write_barrier(fixed_array_map()); |
| 4471 FixedArray::cast(result)->set_length(0); | 4493 FixedArray::cast(result)->set_length(0); |
| 4472 return result; | 4494 return result; |
| 4473 } | 4495 } |
| 4474 | 4496 |
| 4475 | 4497 |
| 4498 AllocationResult Heap::AllocateEmptyFeedbackVector() { |
| 4499 FeedbackVectorSpec empty_spec; |
| 4500 int size = TypeFeedbackVector::SizeFor(&empty_spec); |
| 4501 HeapObject* result; |
| 4502 { |
| 4503 AllocationResult allocation = AllocateRaw(size, OLD_SPACE, OLD_SPACE); |
| 4504 if (!allocation.To(&result)) return allocation; |
| 4505 } |
| 4506 // Initialize the object. |
| 4507 result->set_map_no_write_barrier(feedback_vector_map()); |
| 4508 TypeFeedbackVector::cast(result)->set_length(0); |
| 4509 return result; |
| 4510 } |
| 4511 |
| 4512 |
| 4476 AllocationResult Heap::AllocateEmptyExternalArray( | 4513 AllocationResult Heap::AllocateEmptyExternalArray( |
| 4477 ExternalArrayType array_type) { | 4514 ExternalArrayType array_type) { |
| 4478 return AllocateExternalArray(0, array_type, NULL, TENURED); | 4515 return AllocateExternalArray(0, array_type, NULL, TENURED); |
| 4479 } | 4516 } |
| 4480 | 4517 |
| 4481 | 4518 |
| 4482 AllocationResult Heap::CopyAndTenureFixedCOWArray(FixedArray* src) { | 4519 AllocationResult Heap::CopyAndTenureFixedCOWArray(FixedArray* src) { |
| 4483 if (!InNewSpace(src)) { | 4520 if (!InNewSpace(src)) { |
| 4484 return src; | 4521 return src; |
| 4485 } | 4522 } |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4547 if (!allocation.To(&obj)) return allocation; | 4584 if (!allocation.To(&obj)) return allocation; |
| 4548 } | 4585 } |
| 4549 obj->set_map_no_write_barrier(map); | 4586 obj->set_map_no_write_barrier(map); |
| 4550 CopyBlock(obj->address() + FixedDoubleArray::kLengthOffset, | 4587 CopyBlock(obj->address() + FixedDoubleArray::kLengthOffset, |
| 4551 src->address() + FixedDoubleArray::kLengthOffset, | 4588 src->address() + FixedDoubleArray::kLengthOffset, |
| 4552 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); | 4589 FixedDoubleArray::SizeFor(len) - FixedDoubleArray::kLengthOffset); |
| 4553 return obj; | 4590 return obj; |
| 4554 } | 4591 } |
| 4555 | 4592 |
| 4556 | 4593 |
| 4594 AllocationResult Heap::CopyTypeFeedbackVectorWithMap(TypeFeedbackVector* src, |
| 4595 Map* map) { |
| 4596 int len = src->length(); |
| 4597 int size = len * kPointerSize + TypeFeedbackVector::kHeaderSize; |
| 4598 if (len == 0) { |
| 4599 return empty_feedback_vector(); |
| 4600 } |
| 4601 |
| 4602 AllocationSpace space = SelectSpace(size, TENURED); |
| 4603 HeapObject* obj; |
| 4604 { |
| 4605 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); |
| 4606 if (!allocation.To(&obj)) return allocation; |
| 4607 } |
| 4608 obj->set_map_no_write_barrier(map); |
| 4609 TypeFeedbackVector* result = TypeFeedbackVector::cast(obj); |
| 4610 result->set_length(len); |
| 4611 |
| 4612 // Copy the content |
| 4613 DisallowHeapAllocation no_gc; |
| 4614 WriteBarrierMode mode = result->GetWriteBarrierMode(no_gc); |
| 4615 for (int i = 0; i < len; i++) result->set(i, src->get(i), mode); |
| 4616 return result; |
| 4617 } |
| 4618 |
| 4619 |
| 4557 AllocationResult Heap::AllocateRawFixedArray(int length, | 4620 AllocationResult Heap::AllocateRawFixedArray(int length, |
| 4558 PretenureFlag pretenure) { | 4621 PretenureFlag pretenure) { |
| 4559 if (length < 0 || length > FixedArray::kMaxLength) { | 4622 if (length < 0 || length > FixedArray::kMaxLength) { |
| 4560 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); | 4623 v8::internal::Heap::FatalProcessOutOfMemory("invalid array length", true); |
| 4561 } | 4624 } |
| 4562 int size = FixedArray::SizeFor(length); | 4625 int size = FixedArray::SizeFor(length); |
| 4563 AllocationSpace space = SelectSpace(size, pretenure); | 4626 AllocationSpace space = SelectSpace(size, pretenure); |
| 4564 | 4627 |
| 4565 return AllocateRaw(size, space, OLD_SPACE); | 4628 return AllocateRaw(size, space, OLD_SPACE); |
| 4566 } | 4629 } |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4635 { | 4698 { |
| 4636 AllocationResult allocation = | 4699 AllocationResult allocation = |
| 4637 AllocateRaw(size, space, OLD_SPACE, kDoubleAligned); | 4700 AllocateRaw(size, space, OLD_SPACE, kDoubleAligned); |
| 4638 if (!allocation.To(&object)) return allocation; | 4701 if (!allocation.To(&object)) return allocation; |
| 4639 } | 4702 } |
| 4640 | 4703 |
| 4641 return object; | 4704 return object; |
| 4642 } | 4705 } |
| 4643 | 4706 |
| 4644 | 4707 |
| 4708 template AllocationResult Heap::AllocateTypeFeedbackVector( |
| 4709 const ZoneFeedbackVectorSpec* spec); |
| 4710 template AllocationResult Heap::AllocateTypeFeedbackVector( |
| 4711 const FeedbackVectorSpec* spec); |
| 4712 |
| 4713 template <typename Spec> |
| 4714 AllocationResult Heap::AllocateTypeFeedbackVector(const Spec* spec) { |
| 4715 int size = TypeFeedbackVector::SizeFor(spec); |
| 4716 if (size == TypeFeedbackVector::kHeaderSize) { |
| 4717 return empty_feedback_vector(); |
| 4718 } |
| 4719 AllocationSpace space = SelectSpace(size, TENURED); |
| 4720 |
| 4721 HeapObject* object; |
| 4722 { |
| 4723 AllocationResult allocation = AllocateRaw(size, space, OLD_SPACE); |
| 4724 if (!allocation.To(&object)) return allocation; |
| 4725 } |
| 4726 |
| 4727 object->set_map_no_write_barrier(feedback_vector_map()); |
| 4728 |
| 4729 TypeFeedbackVector* vector = TypeFeedbackVector::cast(object); |
| 4730 vector->Init(isolate(), spec); |
| 4731 return vector; |
| 4732 } |
| 4733 |
| 4734 |
| 4645 AllocationResult Heap::AllocateSymbol() { | 4735 AllocationResult Heap::AllocateSymbol() { |
| 4646 // Statically ensure that it is safe to allocate symbols in paged spaces. | 4736 // Statically ensure that it is safe to allocate symbols in paged spaces. |
| 4647 STATIC_ASSERT(Symbol::kSize <= Page::kMaxRegularHeapObjectSize); | 4737 STATIC_ASSERT(Symbol::kSize <= Page::kMaxRegularHeapObjectSize); |
| 4648 | 4738 |
| 4649 HeapObject* result = NULL; | 4739 HeapObject* result = NULL; |
| 4650 AllocationResult allocation = | 4740 AllocationResult allocation = |
| 4651 AllocateRaw(Symbol::kSize, OLD_SPACE, OLD_SPACE); | 4741 AllocateRaw(Symbol::kSize, OLD_SPACE, OLD_SPACE); |
| 4652 if (!allocation.To(&result)) return allocation; | 4742 if (!allocation.To(&result)) return allocation; |
| 4653 | 4743 |
| 4654 result->set_map_no_write_barrier(symbol_map()); | 4744 result->set_map_no_write_barrier(symbol_map()); |
| (...skipping 2193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6848 *object_type = "CODE_TYPE"; \ | 6938 *object_type = "CODE_TYPE"; \ |
| 6849 *object_sub_type = "CODE_AGE/" #name; \ | 6939 *object_sub_type = "CODE_AGE/" #name; \ |
| 6850 return true; | 6940 return true; |
| 6851 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) | 6941 CODE_AGE_LIST_COMPLETE(COMPARE_AND_RETURN_NAME) |
| 6852 #undef COMPARE_AND_RETURN_NAME | 6942 #undef COMPARE_AND_RETURN_NAME |
| 6853 } | 6943 } |
| 6854 return false; | 6944 return false; |
| 6855 } | 6945 } |
| 6856 } // namespace internal | 6946 } // namespace internal |
| 6857 } // namespace v8 | 6947 } // namespace v8 |
| OLD | NEW |