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/heap/heap.h" | 5 #include "src/heap/heap.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/ast/context-slot-cache.h" | 9 #include "src/ast/context-slot-cache.h" |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
163 // easier if you can define it as part of the build environment. | 163 // easier if you can define it as part of the build environment. |
164 #if defined(V8_MAX_SEMISPACE_SIZE) | 164 #if defined(V8_MAX_SEMISPACE_SIZE) |
165 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; | 165 max_semi_space_size_ = reserved_semispace_size_ = V8_MAX_SEMISPACE_SIZE; |
166 #endif | 166 #endif |
167 | 167 |
168 // Ensure old_generation_size_ is a multiple of kPageSize. | 168 // Ensure old_generation_size_ is a multiple of kPageSize. |
169 DCHECK((max_old_generation_size_ & (Page::kPageSize - 1)) == 0); | 169 DCHECK((max_old_generation_size_ & (Page::kPageSize - 1)) == 0); |
170 | 170 |
171 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); | 171 memset(roots_, 0, sizeof(roots_[0]) * kRootListLength); |
172 set_native_contexts_list(NULL); | 172 set_native_contexts_list(NULL); |
173 set_allocation_sites_list(Smi::kZero); | 173 set_allocation_sites_list(Smi::FromInt(0)); |
174 set_encountered_weak_collections(Smi::kZero); | 174 set_encountered_weak_collections(Smi::FromInt(0)); |
175 set_encountered_weak_cells(Smi::kZero); | 175 set_encountered_weak_cells(Smi::FromInt(0)); |
176 set_encountered_transition_arrays(Smi::kZero); | 176 set_encountered_transition_arrays(Smi::FromInt(0)); |
177 // Put a dummy entry in the remembered pages so we can find the list the | 177 // Put a dummy entry in the remembered pages so we can find the list the |
178 // minidump even if there are no real unmapped pages. | 178 // minidump even if there are no real unmapped pages. |
179 RememberUnmappedPage(NULL, false); | 179 RememberUnmappedPage(NULL, false); |
180 } | 180 } |
181 | 181 |
182 | 182 |
183 intptr_t Heap::Capacity() { | 183 intptr_t Heap::Capacity() { |
184 if (!HasBeenSetUp()) return 0; | 184 if (!HasBeenSetUp()) return 0; |
185 | 185 |
186 return new_space_->Capacity() + OldGenerationCapacity(); | 186 return new_space_->Capacity() + OldGenerationCapacity(); |
(...skipping 548 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
735 // a stack trace that has already been preprocessed. Guard against this. | 735 // a stack trace that has already been preprocessed. Guard against this. |
736 if (!maybe_code->IsAbstractCode()) break; | 736 if (!maybe_code->IsAbstractCode()) break; |
737 AbstractCode* abstract_code = AbstractCode::cast(maybe_code); | 737 AbstractCode* abstract_code = AbstractCode::cast(maybe_code); |
738 int offset = Smi::cast(elements->get(j + 3))->value(); | 738 int offset = Smi::cast(elements->get(j + 3))->value(); |
739 int pos = abstract_code->SourcePosition(offset); | 739 int pos = abstract_code->SourcePosition(offset); |
740 elements->set(j + 2, Smi::FromInt(pos)); | 740 elements->set(j + 2, Smi::FromInt(pos)); |
741 } | 741 } |
742 } | 742 } |
743 // We must not compact the weak fixed list here, as we may be in the middle | 743 // We must not compact the weak fixed list here, as we may be in the middle |
744 // of writing to it, when the GC triggered. Instead, we reset the root value. | 744 // of writing to it, when the GC triggered. Instead, we reset the root value. |
745 set_weak_stack_trace_list(Smi::kZero); | 745 set_weak_stack_trace_list(Smi::FromInt(0)); |
746 } | 746 } |
747 | 747 |
748 | 748 |
749 class GCCallbacksScope { | 749 class GCCallbacksScope { |
750 public: | 750 public: |
751 explicit GCCallbacksScope(Heap* heap) : heap_(heap) { | 751 explicit GCCallbacksScope(Heap* heap) : heap_(heap) { |
752 heap_->gc_callbacks_depth_++; | 752 heap_->gc_callbacks_depth_++; |
753 } | 753 } |
754 ~GCCallbacksScope() { heap_->gc_callbacks_depth_--; } | 754 ~GCCallbacksScope() { heap_->gc_callbacks_depth_--; } |
755 | 755 |
(...skipping 1298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2054 reinterpret_cast<Map*>(result)->clear_unused(); | 2054 reinterpret_cast<Map*>(result)->clear_unused(); |
2055 reinterpret_cast<Map*>(result) | 2055 reinterpret_cast<Map*>(result) |
2056 ->set_inobject_properties_or_constructor_function_index(0); | 2056 ->set_inobject_properties_or_constructor_function_index(0); |
2057 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); | 2057 reinterpret_cast<Map*>(result)->set_unused_property_fields(0); |
2058 reinterpret_cast<Map*>(result)->set_bit_field(0); | 2058 reinterpret_cast<Map*>(result)->set_bit_field(0); |
2059 reinterpret_cast<Map*>(result)->set_bit_field2(0); | 2059 reinterpret_cast<Map*>(result)->set_bit_field2(0); |
2060 int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) | | 2060 int bit_field3 = Map::EnumLengthBits::encode(kInvalidEnumCacheSentinel) | |
2061 Map::OwnsDescriptors::encode(true) | | 2061 Map::OwnsDescriptors::encode(true) | |
2062 Map::ConstructionCounter::encode(Map::kNoSlackTracking); | 2062 Map::ConstructionCounter::encode(Map::kNoSlackTracking); |
2063 reinterpret_cast<Map*>(result)->set_bit_field3(bit_field3); | 2063 reinterpret_cast<Map*>(result)->set_bit_field3(bit_field3); |
2064 reinterpret_cast<Map*>(result)->set_weak_cell_cache(Smi::kZero); | 2064 reinterpret_cast<Map*>(result)->set_weak_cell_cache(Smi::FromInt(0)); |
2065 return result; | 2065 return result; |
2066 } | 2066 } |
2067 | 2067 |
2068 | 2068 |
2069 AllocationResult Heap::AllocateMap(InstanceType instance_type, | 2069 AllocationResult Heap::AllocateMap(InstanceType instance_type, |
2070 int instance_size, | 2070 int instance_size, |
2071 ElementsKind elements_kind) { | 2071 ElementsKind elements_kind) { |
2072 HeapObject* result = nullptr; | 2072 HeapObject* result = nullptr; |
2073 AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE); | 2073 AllocationResult allocation = AllocateRaw(Map::kSize, MAP_SPACE); |
2074 if (!allocation.To(&result)) return allocation; | 2074 if (!allocation.To(&result)) return allocation; |
2075 | 2075 |
2076 isolate()->counters()->maps_created()->Increment(); | 2076 isolate()->counters()->maps_created()->Increment(); |
2077 result->set_map_no_write_barrier(meta_map()); | 2077 result->set_map_no_write_barrier(meta_map()); |
2078 Map* map = Map::cast(result); | 2078 Map* map = Map::cast(result); |
2079 map->set_instance_type(instance_type); | 2079 map->set_instance_type(instance_type); |
2080 map->set_prototype(null_value(), SKIP_WRITE_BARRIER); | 2080 map->set_prototype(null_value(), SKIP_WRITE_BARRIER); |
2081 map->set_constructor_or_backpointer(null_value(), SKIP_WRITE_BARRIER); | 2081 map->set_constructor_or_backpointer(null_value(), SKIP_WRITE_BARRIER); |
2082 map->set_instance_size(instance_size); | 2082 map->set_instance_size(instance_size); |
2083 map->clear_unused(); | 2083 map->clear_unused(); |
2084 map->set_inobject_properties_or_constructor_function_index(0); | 2084 map->set_inobject_properties_or_constructor_function_index(0); |
2085 map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); | 2085 map->set_code_cache(empty_fixed_array(), SKIP_WRITE_BARRIER); |
2086 map->set_dependent_code(DependentCode::cast(empty_fixed_array()), | 2086 map->set_dependent_code(DependentCode::cast(empty_fixed_array()), |
2087 SKIP_WRITE_BARRIER); | 2087 SKIP_WRITE_BARRIER); |
2088 map->set_weak_cell_cache(Smi::kZero); | 2088 map->set_weak_cell_cache(Smi::FromInt(0)); |
2089 map->set_raw_transitions(Smi::kZero); | 2089 map->set_raw_transitions(Smi::FromInt(0)); |
2090 map->set_unused_property_fields(0); | 2090 map->set_unused_property_fields(0); |
2091 map->set_instance_descriptors(empty_descriptor_array()); | 2091 map->set_instance_descriptors(empty_descriptor_array()); |
2092 if (FLAG_unbox_double_fields) { | 2092 if (FLAG_unbox_double_fields) { |
2093 map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); | 2093 map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); |
2094 } | 2094 } |
2095 // Must be called only after |instance_type|, |instance_size| and | 2095 // Must be called only after |instance_type|, |instance_size| and |
2096 // |layout_descriptor| are set. | 2096 // |layout_descriptor| are set. |
2097 map->set_visitor_id(Heap::GetStaticVisitorIdForMap(map)); | 2097 map->set_visitor_id(Heap::GetStaticVisitorIdForMap(map)); |
2098 map->set_bit_field(0); | 2098 map->set_bit_field(0); |
2099 map->set_bit_field2(1 << Map::kIsExtensible); | 2099 map->set_bit_field2(1 << Map::kIsExtensible); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2151 , | 2151 , |
2152 STRUCT_LIST(STRUCT_TABLE_ELEMENT) | 2152 STRUCT_LIST(STRUCT_TABLE_ELEMENT) |
2153 #undef STRUCT_TABLE_ELEMENT | 2153 #undef STRUCT_TABLE_ELEMENT |
2154 }; | 2154 }; |
2155 | 2155 |
2156 namespace { | 2156 namespace { |
2157 | 2157 |
2158 void FinalizePartialMap(Heap* heap, Map* map) { | 2158 void FinalizePartialMap(Heap* heap, Map* map) { |
2159 map->set_code_cache(heap->empty_fixed_array()); | 2159 map->set_code_cache(heap->empty_fixed_array()); |
2160 map->set_dependent_code(DependentCode::cast(heap->empty_fixed_array())); | 2160 map->set_dependent_code(DependentCode::cast(heap->empty_fixed_array())); |
2161 map->set_raw_transitions(Smi::kZero); | 2161 map->set_raw_transitions(Smi::FromInt(0)); |
2162 map->set_instance_descriptors(heap->empty_descriptor_array()); | 2162 map->set_instance_descriptors(heap->empty_descriptor_array()); |
2163 if (FLAG_unbox_double_fields) { | 2163 if (FLAG_unbox_double_fields) { |
2164 map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); | 2164 map->set_layout_descriptor(LayoutDescriptor::FastPointerLayout()); |
2165 } | 2165 } |
2166 map->set_prototype(heap->null_value()); | 2166 map->set_prototype(heap->null_value()); |
2167 map->set_constructor_or_backpointer(heap->null_value()); | 2167 map->set_constructor_or_backpointer(heap->null_value()); |
2168 } | 2168 } |
2169 | 2169 |
2170 } // namespace | 2170 } // namespace |
2171 | 2171 |
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2486 STATIC_ASSERT(PropertyCell::kSize <= kMaxRegularHeapObjectSize); | 2486 STATIC_ASSERT(PropertyCell::kSize <= kMaxRegularHeapObjectSize); |
2487 | 2487 |
2488 HeapObject* result = nullptr; | 2488 HeapObject* result = nullptr; |
2489 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); | 2489 AllocationResult allocation = AllocateRaw(size, OLD_SPACE); |
2490 if (!allocation.To(&result)) return allocation; | 2490 if (!allocation.To(&result)) return allocation; |
2491 | 2491 |
2492 result->set_map_no_write_barrier(global_property_cell_map()); | 2492 result->set_map_no_write_barrier(global_property_cell_map()); |
2493 PropertyCell* cell = PropertyCell::cast(result); | 2493 PropertyCell* cell = PropertyCell::cast(result); |
2494 cell->set_dependent_code(DependentCode::cast(empty_fixed_array()), | 2494 cell->set_dependent_code(DependentCode::cast(empty_fixed_array()), |
2495 SKIP_WRITE_BARRIER); | 2495 SKIP_WRITE_BARRIER); |
2496 cell->set_property_details(PropertyDetails(Smi::kZero)); | 2496 cell->set_property_details(PropertyDetails(Smi::FromInt(0))); |
2497 cell->set_value(the_hole_value()); | 2497 cell->set_value(the_hole_value()); |
2498 return result; | 2498 return result; |
2499 } | 2499 } |
2500 | 2500 |
2501 | 2501 |
2502 AllocationResult Heap::AllocateWeakCell(HeapObject* value) { | 2502 AllocationResult Heap::AllocateWeakCell(HeapObject* value) { |
2503 int size = WeakCell::kSize; | 2503 int size = WeakCell::kSize; |
2504 STATIC_ASSERT(WeakCell::kSize <= kMaxRegularHeapObjectSize); | 2504 STATIC_ASSERT(WeakCell::kSize <= kMaxRegularHeapObjectSize); |
2505 HeapObject* result = nullptr; | 2505 HeapObject* result = nullptr; |
2506 { | 2506 { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2616 set_string_table(*StringTable::New(isolate(), kInitialStringTableSize)); | 2616 set_string_table(*StringTable::New(isolate(), kInitialStringTableSize)); |
2617 | 2617 |
2618 // Allocate | 2618 // Allocate |
2619 | 2619 |
2620 // Finish initializing oddballs after creating the string table. | 2620 // Finish initializing oddballs after creating the string table. |
2621 Oddball::Initialize(isolate(), factory->undefined_value(), "undefined", | 2621 Oddball::Initialize(isolate(), factory->undefined_value(), "undefined", |
2622 factory->nan_value(), "undefined", Oddball::kUndefined); | 2622 factory->nan_value(), "undefined", Oddball::kUndefined); |
2623 | 2623 |
2624 // Initialize the null_value. | 2624 // Initialize the null_value. |
2625 Oddball::Initialize(isolate(), factory->null_value(), "null", | 2625 Oddball::Initialize(isolate(), factory->null_value(), "null", |
2626 handle(Smi::kZero, isolate()), "object", Oddball::kNull); | 2626 handle(Smi::FromInt(0), isolate()), "object", |
| 2627 Oddball::kNull); |
2627 | 2628 |
2628 // Initialize the_hole_value. | 2629 // Initialize the_hole_value. |
2629 Oddball::Initialize(isolate(), factory->the_hole_value(), "hole", | 2630 Oddball::Initialize(isolate(), factory->the_hole_value(), "hole", |
2630 factory->hole_nan_value(), "undefined", | 2631 factory->hole_nan_value(), "undefined", |
2631 Oddball::kTheHole); | 2632 Oddball::kTheHole); |
2632 | 2633 |
2633 // Initialize the true_value. | 2634 // Initialize the true_value. |
2634 Oddball::Initialize(isolate(), factory->true_value(), "true", | 2635 Oddball::Initialize(isolate(), factory->true_value(), "true", |
2635 handle(Smi::FromInt(1), isolate()), "boolean", | 2636 handle(Smi::FromInt(1), isolate()), "boolean", |
2636 Oddball::kTrue); | 2637 Oddball::kTrue); |
2637 | 2638 |
2638 // Initialize the false_value. | 2639 // Initialize the false_value. |
2639 Oddball::Initialize(isolate(), factory->false_value(), "false", | 2640 Oddball::Initialize(isolate(), factory->false_value(), "false", |
2640 handle(Smi::kZero, isolate()), "boolean", | 2641 handle(Smi::FromInt(0), isolate()), "boolean", |
2641 Oddball::kFalse); | 2642 Oddball::kFalse); |
2642 | 2643 |
2643 set_uninitialized_value( | 2644 set_uninitialized_value( |
2644 *factory->NewOddball(factory->uninitialized_map(), "uninitialized", | 2645 *factory->NewOddball(factory->uninitialized_map(), "uninitialized", |
2645 handle(Smi::FromInt(-1), isolate()), "undefined", | 2646 handle(Smi::FromInt(-1), isolate()), "undefined", |
2646 Oddball::kUninitialized)); | 2647 Oddball::kUninitialized)); |
2647 | 2648 |
2648 set_arguments_marker( | 2649 set_arguments_marker( |
2649 *factory->NewOddball(factory->arguments_marker_map(), "arguments_marker", | 2650 *factory->NewOddball(factory->arguments_marker_map(), "arguments_marker", |
2650 handle(Smi::FromInt(-4), isolate()), "undefined", | 2651 handle(Smi::FromInt(-4), isolate()), "undefined", |
(...skipping 25 matching lines...) Expand all Loading... |
2676 for (unsigned i = 0; i < arraysize(constant_string_table); i++) { | 2677 for (unsigned i = 0; i < arraysize(constant_string_table); i++) { |
2677 Handle<String> str = | 2678 Handle<String> str = |
2678 factory->InternalizeUtf8String(constant_string_table[i].contents); | 2679 factory->InternalizeUtf8String(constant_string_table[i].contents); |
2679 roots_[constant_string_table[i].index] = *str; | 2680 roots_[constant_string_table[i].index] = *str; |
2680 } | 2681 } |
2681 | 2682 |
2682 // Create the code_stubs dictionary. The initial size is set to avoid | 2683 // Create the code_stubs dictionary. The initial size is set to avoid |
2683 // expanding the dictionary during bootstrapping. | 2684 // expanding the dictionary during bootstrapping. |
2684 set_code_stubs(*UnseededNumberDictionary::New(isolate(), 128)); | 2685 set_code_stubs(*UnseededNumberDictionary::New(isolate(), 128)); |
2685 | 2686 |
2686 set_instanceof_cache_function(Smi::kZero); | 2687 set_instanceof_cache_function(Smi::FromInt(0)); |
2687 set_instanceof_cache_map(Smi::kZero); | 2688 set_instanceof_cache_map(Smi::FromInt(0)); |
2688 set_instanceof_cache_answer(Smi::kZero); | 2689 set_instanceof_cache_answer(Smi::FromInt(0)); |
2689 | 2690 |
2690 { | 2691 { |
2691 HandleScope scope(isolate()); | 2692 HandleScope scope(isolate()); |
2692 #define SYMBOL_INIT(name) \ | 2693 #define SYMBOL_INIT(name) \ |
2693 { \ | 2694 { \ |
2694 Handle<String> name##d = factory->NewStringFromStaticChars(#name); \ | 2695 Handle<String> name##d = factory->NewStringFromStaticChars(#name); \ |
2695 Handle<Symbol> symbol(isolate()->factory()->NewPrivateSymbol()); \ | 2696 Handle<Symbol> symbol(isolate()->factory()->NewPrivateSymbol()); \ |
2696 symbol->set_name(*name##d); \ | 2697 symbol->set_name(*name##d); \ |
2697 roots_[k##name##RootIndex] = *symbol; \ | 2698 roots_[k##name##RootIndex] = *symbol; \ |
2698 } | 2699 } |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2747 | 2748 |
2748 set_extra_natives_source_cache( | 2749 set_extra_natives_source_cache( |
2749 *factory->NewFixedArray(ExtraNatives::GetBuiltinsCount())); | 2750 *factory->NewFixedArray(ExtraNatives::GetBuiltinsCount())); |
2750 | 2751 |
2751 set_experimental_extra_natives_source_cache( | 2752 set_experimental_extra_natives_source_cache( |
2752 *factory->NewFixedArray(ExperimentalExtraNatives::GetBuiltinsCount())); | 2753 *factory->NewFixedArray(ExperimentalExtraNatives::GetBuiltinsCount())); |
2753 | 2754 |
2754 set_undefined_cell(*factory->NewCell(factory->undefined_value())); | 2755 set_undefined_cell(*factory->NewCell(factory->undefined_value())); |
2755 | 2756 |
2756 // The symbol registry is initialized lazily. | 2757 // The symbol registry is initialized lazily. |
2757 set_symbol_registry(Smi::kZero); | 2758 set_symbol_registry(Smi::FromInt(0)); |
2758 | 2759 |
2759 // Microtask queue uses the empty fixed array as a sentinel for "empty". | 2760 // Microtask queue uses the empty fixed array as a sentinel for "empty". |
2760 // Number of queued microtasks stored in Isolate::pending_microtask_count(). | 2761 // Number of queued microtasks stored in Isolate::pending_microtask_count(). |
2761 set_microtask_queue(empty_fixed_array()); | 2762 set_microtask_queue(empty_fixed_array()); |
2762 | 2763 |
2763 { | 2764 { |
2764 StaticFeedbackVectorSpec spec; | 2765 StaticFeedbackVectorSpec spec; |
2765 FeedbackVectorSlot slot = spec.AddLoadICSlot(); | 2766 FeedbackVectorSlot slot = spec.AddLoadICSlot(); |
2766 DCHECK_EQ(slot, FeedbackVectorSlot(TypeFeedbackVector::kDummyLoadICSlot)); | 2767 DCHECK_EQ(slot, FeedbackVectorSlot(TypeFeedbackVector::kDummyLoadICSlot)); |
2767 | 2768 |
(...skipping 27 matching lines...) Expand all Loading... |
2795 // functions that don't need actual type feedback slots. Note however | 2796 // functions that don't need actual type feedback slots. Note however |
2796 // that all these functions will share the same invocation count, but | 2797 // that all these functions will share the same invocation count, but |
2797 // that shouldn't matter since we only use the invocation count to | 2798 // that shouldn't matter since we only use the invocation count to |
2798 // relativize the absolute call counts, but we can only have call counts | 2799 // relativize the absolute call counts, but we can only have call counts |
2799 // if we have actual feedback slots. | 2800 // if we have actual feedback slots. |
2800 Handle<FixedArray> empty_type_feedback_vector = factory->NewFixedArray( | 2801 Handle<FixedArray> empty_type_feedback_vector = factory->NewFixedArray( |
2801 TypeFeedbackVector::kReservedIndexCount, TENURED); | 2802 TypeFeedbackVector::kReservedIndexCount, TENURED); |
2802 empty_type_feedback_vector->set(TypeFeedbackVector::kMetadataIndex, | 2803 empty_type_feedback_vector->set(TypeFeedbackVector::kMetadataIndex, |
2803 empty_fixed_array()); | 2804 empty_fixed_array()); |
2804 empty_type_feedback_vector->set(TypeFeedbackVector::kInvocationCountIndex, | 2805 empty_type_feedback_vector->set(TypeFeedbackVector::kInvocationCountIndex, |
2805 Smi::kZero); | 2806 Smi::FromInt(0)); |
2806 set_empty_type_feedback_vector(*empty_type_feedback_vector); | 2807 set_empty_type_feedback_vector(*empty_type_feedback_vector); |
2807 | 2808 |
2808 // We use a canonical empty LiteralsArray for all functions that neither | 2809 // We use a canonical empty LiteralsArray for all functions that neither |
2809 // have literals nor need a TypeFeedbackVector (besides the invocation | 2810 // have literals nor need a TypeFeedbackVector (besides the invocation |
2810 // count special slot). | 2811 // count special slot). |
2811 Handle<FixedArray> empty_literals_array = | 2812 Handle<FixedArray> empty_literals_array = |
2812 factory->NewFixedArray(1, TENURED); | 2813 factory->NewFixedArray(1, TENURED); |
2813 empty_literals_array->set(0, *empty_type_feedback_vector); | 2814 empty_literals_array->set(0, *empty_type_feedback_vector); |
2814 set_empty_literals_array(*empty_literals_array); | 2815 set_empty_literals_array(*empty_literals_array); |
2815 } | 2816 } |
(...skipping 15 matching lines...) Expand all Loading... |
2831 set_retained_maps(ArrayList::cast(empty_fixed_array())); | 2832 set_retained_maps(ArrayList::cast(empty_fixed_array())); |
2832 | 2833 |
2833 set_weak_object_to_code_table( | 2834 set_weak_object_to_code_table( |
2834 *WeakHashTable::New(isolate(), 16, USE_DEFAULT_MINIMUM_CAPACITY, | 2835 *WeakHashTable::New(isolate(), 16, USE_DEFAULT_MINIMUM_CAPACITY, |
2835 TENURED)); | 2836 TENURED)); |
2836 | 2837 |
2837 set_weak_new_space_object_to_code_list( | 2838 set_weak_new_space_object_to_code_list( |
2838 ArrayList::cast(*(factory->NewFixedArray(16, TENURED)))); | 2839 ArrayList::cast(*(factory->NewFixedArray(16, TENURED)))); |
2839 weak_new_space_object_to_code_list()->SetLength(0); | 2840 weak_new_space_object_to_code_list()->SetLength(0); |
2840 | 2841 |
2841 set_script_list(Smi::kZero); | 2842 set_script_list(Smi::FromInt(0)); |
2842 | 2843 |
2843 Handle<SeededNumberDictionary> slow_element_dictionary = | 2844 Handle<SeededNumberDictionary> slow_element_dictionary = |
2844 SeededNumberDictionary::New(isolate(), 0, TENURED); | 2845 SeededNumberDictionary::New(isolate(), 0, TENURED); |
2845 slow_element_dictionary->set_requires_slow_elements(); | 2846 slow_element_dictionary->set_requires_slow_elements(); |
2846 set_empty_slow_element_dictionary(*slow_element_dictionary); | 2847 set_empty_slow_element_dictionary(*slow_element_dictionary); |
2847 | 2848 |
2848 set_materialized_objects(*factory->NewFixedArray(0, TENURED)); | 2849 set_materialized_objects(*factory->NewFixedArray(0, TENURED)); |
2849 | 2850 |
2850 // Handling of script id generation is in Heap::NextScriptId(). | 2851 // Handling of script id generation is in Heap::NextScriptId(). |
2851 set_last_script_id(Smi::FromInt(v8::UnboundScript::kNoScriptId)); | 2852 set_last_script_id(Smi::FromInt(v8::UnboundScript::kNoScriptId)); |
2852 set_next_template_serial_number(Smi::kZero); | 2853 set_next_template_serial_number(Smi::FromInt(0)); |
2853 | 2854 |
2854 // Allocate the empty script. | 2855 // Allocate the empty script. |
2855 Handle<Script> script = factory->NewScript(factory->empty_string()); | 2856 Handle<Script> script = factory->NewScript(factory->empty_string()); |
2856 script->set_type(Script::TYPE_NATIVE); | 2857 script->set_type(Script::TYPE_NATIVE); |
2857 set_empty_script(*script); | 2858 set_empty_script(*script); |
2858 | 2859 |
2859 Handle<PropertyCell> cell = factory->NewPropertyCell(); | 2860 Handle<PropertyCell> cell = factory->NewPropertyCell(); |
2860 cell->set_value(Smi::FromInt(Isolate::kArrayProtectorValid)); | 2861 cell->set_value(Smi::FromInt(Isolate::kArrayProtectorValid)); |
2861 set_array_protector(*cell); | 2862 set_array_protector(*cell); |
2862 | 2863 |
(...skipping 12 matching lines...) Expand all Loading... |
2875 Handle<Cell> species_cell = factory->NewCell( | 2876 Handle<Cell> species_cell = factory->NewCell( |
2876 handle(Smi::FromInt(Isolate::kArrayProtectorValid), isolate())); | 2877 handle(Smi::FromInt(Isolate::kArrayProtectorValid), isolate())); |
2877 set_species_protector(*species_cell); | 2878 set_species_protector(*species_cell); |
2878 | 2879 |
2879 cell = factory->NewPropertyCell(); | 2880 cell = factory->NewPropertyCell(); |
2880 cell->set_value(Smi::FromInt(Isolate::kArrayProtectorValid)); | 2881 cell->set_value(Smi::FromInt(Isolate::kArrayProtectorValid)); |
2881 set_string_length_protector(*cell); | 2882 set_string_length_protector(*cell); |
2882 | 2883 |
2883 set_serialized_templates(empty_fixed_array()); | 2884 set_serialized_templates(empty_fixed_array()); |
2884 | 2885 |
2885 set_weak_stack_trace_list(Smi::kZero); | 2886 set_weak_stack_trace_list(Smi::FromInt(0)); |
2886 | 2887 |
2887 set_noscript_shared_function_infos(Smi::kZero); | 2888 set_noscript_shared_function_infos(Smi::FromInt(0)); |
2888 | 2889 |
2889 // Initialize keyed lookup cache. | 2890 // Initialize keyed lookup cache. |
2890 isolate_->keyed_lookup_cache()->Clear(); | 2891 isolate_->keyed_lookup_cache()->Clear(); |
2891 | 2892 |
2892 // Initialize context slot cache. | 2893 // Initialize context slot cache. |
2893 isolate_->context_slot_cache()->Clear(); | 2894 isolate_->context_slot_cache()->Clear(); |
2894 | 2895 |
2895 // Initialize descriptor cache. | 2896 // Initialize descriptor cache. |
2896 isolate_->descriptor_lookup_cache()->Clear(); | 2897 isolate_->descriptor_lookup_cache()->Clear(); |
2897 | 2898 |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3279 int size = FixedTypedArrayBase::kHeaderSize; | 3280 int size = FixedTypedArrayBase::kHeaderSize; |
3280 AllocationSpace space = SelectSpace(pretenure); | 3281 AllocationSpace space = SelectSpace(pretenure); |
3281 HeapObject* result = nullptr; | 3282 HeapObject* result = nullptr; |
3282 { | 3283 { |
3283 AllocationResult allocation = AllocateRaw(size, space); | 3284 AllocationResult allocation = AllocateRaw(size, space); |
3284 if (!allocation.To(&result)) return allocation; | 3285 if (!allocation.To(&result)) return allocation; |
3285 } | 3286 } |
3286 | 3287 |
3287 result->set_map_no_write_barrier(MapForFixedTypedArray(array_type)); | 3288 result->set_map_no_write_barrier(MapForFixedTypedArray(array_type)); |
3288 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(result); | 3289 FixedTypedArrayBase* elements = FixedTypedArrayBase::cast(result); |
3289 elements->set_base_pointer(Smi::kZero, SKIP_WRITE_BARRIER); | 3290 elements->set_base_pointer(Smi::FromInt(0), SKIP_WRITE_BARRIER); |
3290 elements->set_external_pointer(external_pointer, SKIP_WRITE_BARRIER); | 3291 elements->set_external_pointer(external_pointer, SKIP_WRITE_BARRIER); |
3291 elements->set_length(length); | 3292 elements->set_length(length); |
3292 return elements; | 3293 return elements; |
3293 } | 3294 } |
3294 | 3295 |
3295 static void ForFixedTypedArray(ExternalArrayType array_type, int* element_size, | 3296 static void ForFixedTypedArray(ExternalArrayType array_type, int* element_size, |
3296 ElementsKind* element_kind) { | 3297 ElementsKind* element_kind) { |
3297 switch (array_type) { | 3298 switch (array_type) { |
3298 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ | 3299 #define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \ |
3299 case kExternal##Type##Array: \ | 3300 case kExternal##Type##Array: \ |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3363 OnAllocationEvent(result, object_size); | 3364 OnAllocationEvent(result, object_size); |
3364 } | 3365 } |
3365 } | 3366 } |
3366 | 3367 |
3367 result->set_map_no_write_barrier(code_map()); | 3368 result->set_map_no_write_barrier(code_map()); |
3368 Code* code = Code::cast(result); | 3369 Code* code = Code::cast(result); |
3369 DCHECK(IsAligned(bit_cast<intptr_t>(code->address()), kCodeAlignment)); | 3370 DCHECK(IsAligned(bit_cast<intptr_t>(code->address()), kCodeAlignment)); |
3370 DCHECK(!memory_allocator()->code_range()->valid() || | 3371 DCHECK(!memory_allocator()->code_range()->valid() || |
3371 memory_allocator()->code_range()->contains(code->address()) || | 3372 memory_allocator()->code_range()->contains(code->address()) || |
3372 object_size <= code_space()->AreaSize()); | 3373 object_size <= code_space()->AreaSize()); |
3373 code->set_gc_metadata(Smi::kZero); | 3374 code->set_gc_metadata(Smi::FromInt(0)); |
3374 code->set_ic_age(global_ic_age_); | 3375 code->set_ic_age(global_ic_age_); |
3375 return code; | 3376 return code; |
3376 } | 3377 } |
3377 | 3378 |
3378 | 3379 |
3379 AllocationResult Heap::CopyCode(Code* code) { | 3380 AllocationResult Heap::CopyCode(Code* code) { |
3380 AllocationResult allocation; | 3381 AllocationResult allocation; |
3381 | 3382 |
3382 HeapObject* result = nullptr; | 3383 HeapObject* result = nullptr; |
3383 // Allocate an object the same size as the code object. | 3384 // Allocate an object the same size as the code object. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3460 } | 3461 } |
3461 | 3462 |
3462 | 3463 |
3463 void Heap::InitializeJSObjectFromMap(JSObject* obj, FixedArray* properties, | 3464 void Heap::InitializeJSObjectFromMap(JSObject* obj, FixedArray* properties, |
3464 Map* map) { | 3465 Map* map) { |
3465 obj->set_properties(properties); | 3466 obj->set_properties(properties); |
3466 obj->initialize_elements(); | 3467 obj->initialize_elements(); |
3467 // TODO(1240798): Initialize the object's body using valid initial values | 3468 // TODO(1240798): Initialize the object's body using valid initial values |
3468 // according to the object's initial map. For example, if the map's | 3469 // according to the object's initial map. For example, if the map's |
3469 // instance type is JS_ARRAY_TYPE, the length field should be initialized | 3470 // instance type is JS_ARRAY_TYPE, the length field should be initialized |
3470 // to a number (e.g. Smi::kZero) and the elements initialized to a | 3471 // to a number (e.g. Smi::FromInt(0)) and the elements initialized to a |
3471 // fixed array (e.g. Heap::empty_fixed_array()). Currently, the object | 3472 // fixed array (e.g. Heap::empty_fixed_array()). Currently, the object |
3472 // verification code has to cope with (temporarily) invalid objects. See | 3473 // verification code has to cope with (temporarily) invalid objects. See |
3473 // for example, JSArray::JSArrayVerify). | 3474 // for example, JSArray::JSArrayVerify). |
3474 InitializeJSObjectBody(obj, map, JSObject::kHeaderSize); | 3475 InitializeJSObjectBody(obj, map, JSObject::kHeaderSize); |
3475 } | 3476 } |
3476 | 3477 |
3477 | 3478 |
3478 void Heap::InitializeJSObjectBody(JSObject* obj, Map* map, int start_offset) { | 3479 void Heap::InitializeJSObjectBody(JSObject* obj, Map* map, int start_offset) { |
3479 if (start_offset == map->instance_size()) return; | 3480 if (start_offset == map->instance_size()) return; |
3480 DCHECK_LT(start_offset, map->instance_size()); | 3481 DCHECK_LT(start_offset, map->instance_size()); |
(...skipping 2059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5540 | 5541 |
5541 // Set up the special root array entries containing the stack limits. | 5542 // Set up the special root array entries containing the stack limits. |
5542 // These are actually addresses, but the tag makes the GC ignore it. | 5543 // These are actually addresses, but the tag makes the GC ignore it. |
5543 roots_[kStackLimitRootIndex] = reinterpret_cast<Object*>( | 5544 roots_[kStackLimitRootIndex] = reinterpret_cast<Object*>( |
5544 (isolate_->stack_guard()->jslimit() & ~kSmiTagMask) | kSmiTag); | 5545 (isolate_->stack_guard()->jslimit() & ~kSmiTagMask) | kSmiTag); |
5545 roots_[kRealStackLimitRootIndex] = reinterpret_cast<Object*>( | 5546 roots_[kRealStackLimitRootIndex] = reinterpret_cast<Object*>( |
5546 (isolate_->stack_guard()->real_jslimit() & ~kSmiTagMask) | kSmiTag); | 5547 (isolate_->stack_guard()->real_jslimit() & ~kSmiTagMask) | kSmiTag); |
5547 } | 5548 } |
5548 | 5549 |
5549 void Heap::ClearStackLimits() { | 5550 void Heap::ClearStackLimits() { |
5550 roots_[kStackLimitRootIndex] = Smi::kZero; | 5551 roots_[kStackLimitRootIndex] = Smi::FromInt(0); |
5551 roots_[kRealStackLimitRootIndex] = Smi::kZero; | 5552 roots_[kRealStackLimitRootIndex] = Smi::FromInt(0); |
5552 } | 5553 } |
5553 | 5554 |
5554 void Heap::PrintAlloctionsHash() { | 5555 void Heap::PrintAlloctionsHash() { |
5555 uint32_t hash = StringHasher::GetHashCore(raw_allocations_hash_); | 5556 uint32_t hash = StringHasher::GetHashCore(raw_allocations_hash_); |
5556 PrintF("\n### Allocations = %u, hash = 0x%08x\n", allocations_count(), hash); | 5557 PrintF("\n### Allocations = %u, hash = 0x%08x\n", allocations_count(), hash); |
5557 } | 5558 } |
5558 | 5559 |
5559 | 5560 |
5560 void Heap::NotifyDeserializationComplete() { | 5561 void Heap::NotifyDeserializationComplete() { |
5561 DCHECK_EQ(0, gc_count()); | 5562 DCHECK_EQ(0, gc_count()); |
(...skipping 947 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6509 } | 6510 } |
6510 | 6511 |
6511 | 6512 |
6512 // static | 6513 // static |
6513 int Heap::GetStaticVisitorIdForMap(Map* map) { | 6514 int Heap::GetStaticVisitorIdForMap(Map* map) { |
6514 return StaticVisitorBase::GetVisitorId(map); | 6515 return StaticVisitorBase::GetVisitorId(map); |
6515 } | 6516 } |
6516 | 6517 |
6517 } // namespace internal | 6518 } // namespace internal |
6518 } // namespace v8 | 6519 } // namespace v8 |
OLD | NEW |