| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7fe8399 commit 647f3c7
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2761,6 +2761,14 @@ HeapObject Heap::AlignWithFiller(HeapObject object, int object_size, | |||
| 2761 | 2761 | ||
| 2762 | 2762 | void* Heap::AllocateExternalBackingStore( | |
| 2763 | 2763 | const std::function<void*(size_t)>& allocate, size_t byte_length) { | |
| 2764 | + size_t new_space_backing_store_bytes = | ||
| 2765 | + new_space()->ExternalBackingStoreBytes(); | ||
| 2766 | + if (new_space_backing_store_bytes >= 2 * kMaxSemiSpaceSize && | ||
| 2767 | + new_space_backing_store_bytes >= byte_length) { | ||
| 2768 | + // Performing a young generation GC amortizes over the allocated backing | ||
| 2769 | + // store bytes and may free enough external bytes for this allocation. | ||
| 2770 | + CollectGarbage(NEW_SPACE, GarbageCollectionReason::kExternalMemoryPressure); | ||
| 2771 | + } | ||
| 2764 | 2772 | // TODO(ulan): Perform GCs proactively based on the byte_length and | |
| 2765 | 2773 | // the current external backing store counters. | |
| 2766 | 2774 | void* result = allocate(byte_length); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1793,10 +1793,6 @@ class Heap { | |||
| 1793 | 1793 | ||
| 1794 | 1794 | void FinalizePartialMap(Map map); | |
| 1795 | 1795 | ||
| 1796 | - // Allocate empty fixed typed array of given type. | ||
| 1797 | - V8_WARN_UNUSED_RESULT AllocationResult | ||
| 1798 | - AllocateEmptyFixedTypedArray(ExternalArrayType array_type); | ||
| 1799 | - | ||
| 1800 | 1796 | void set_force_oom(bool value) { force_oom_ = value; } | |
| 1801 | 1797 | ||
| 1802 | 1798 | // =========================================================================== | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2804,14 +2804,14 @@ class V8_EXPORT_PRIVATE NewSpace | |||
| 2804 | 2804 | void Shrink(); | |
| 2805 | 2805 | ||
| 2806 | 2806 | // Return the allocated bytes in the active semispace. | |
| 2807 | - size_t Size() override { | ||
| 2807 | + size_t Size() final { | ||
| 2808 | 2808 | DCHECK_GE(top(), to_space_.page_low()); | |
| 2809 | 2809 | return to_space_.pages_used() * | |
| 2810 | 2810 | MemoryChunkLayout::AllocatableMemoryInDataPage() + | |
| 2811 | 2811 | static_cast<size_t>(top() - to_space_.page_low()); | |
| 2812 | 2812 | } | |
| 2813 | 2813 | ||
| 2814 | - size_t SizeOfObjects() override { return Size(); } | ||
| 2814 | + size_t SizeOfObjects() final { return Size(); } | ||
| 2815 | 2815 | ||
| 2816 | 2816 | // Return the allocatable capacity of a semispace. | |
| 2817 | 2817 | size_t Capacity() { | |
@@ -2829,30 +2829,38 @@ class V8_EXPORT_PRIVATE NewSpace | |||
| 2829 | 2829 | ||
| 2830 | 2830 | // Committed memory for NewSpace is the committed memory of both semi-spaces | |
| 2831 | 2831 | // combined. | |
| 2832 | - size_t CommittedMemory() override { | ||
| 2832 | + size_t CommittedMemory() final { | ||
| 2833 | 2833 | return from_space_.CommittedMemory() + to_space_.CommittedMemory(); | |
| 2834 | 2834 | } | |
| 2835 | 2835 | ||
| 2836 | - size_t MaximumCommittedMemory() override { | ||
| 2836 | + size_t MaximumCommittedMemory() final { | ||
| 2837 | 2837 | return from_space_.MaximumCommittedMemory() + | |
| 2838 | 2838 | to_space_.MaximumCommittedMemory(); | |
| 2839 | 2839 | } | |
| 2840 | 2840 | ||
| 2841 | 2841 | // Approximate amount of physical memory committed for this space. | |
| 2842 | - size_t CommittedPhysicalMemory() override; | ||
| 2842 | + size_t CommittedPhysicalMemory() final; | ||
| 2843 | 2843 | ||
| 2844 | 2844 | // Return the available bytes without growing. | |
| 2845 | - size_t Available() override { | ||
| 2845 | + size_t Available() final { | ||
| 2846 | 2846 | DCHECK_GE(Capacity(), Size()); | |
| 2847 | 2847 | return Capacity() - Size(); | |
| 2848 | 2848 | } | |
| 2849 | 2849 | ||
| 2850 | - size_t ExternalBackingStoreBytes( | ||
| 2851 | - ExternalBackingStoreType type) const override { | ||
| 2850 | + size_t ExternalBackingStoreBytes(ExternalBackingStoreType type) const final { | ||
| 2852 | 2851 | DCHECK_EQ(0, from_space_.ExternalBackingStoreBytes(type)); | |
| 2853 | 2852 | return to_space_.ExternalBackingStoreBytes(type); | |
| 2854 | 2853 | } | |
| 2855 | 2854 | ||
| 2855 | + size_t ExternalBackingStoreBytes() { | ||
| 2856 | + size_t result = 0; | ||
| 2857 | + for (int i = 0; i < ExternalBackingStoreType::kNumTypes; i++) { | ||
| 2858 | + result += | ||
| 2859 | + ExternalBackingStoreBytes(static_cast<ExternalBackingStoreType>(i)); | ||
| 2860 | + } | ||
| 2861 | + return result; | ||
| 2862 | + } | ||
| 2863 | + | ||
| 2856 | 2864 | size_t AllocatedSinceLastGC() { | |
| 2857 | 2865 | const Address age_mark = to_space_.age_mark(); | |
| 2858 | 2866 | DCHECK_NE(age_mark, kNullAddress); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6823,6 +6823,27 @@ TEST(CodeObjectRegistry) { | |||
| 6823 | 6823 | CHECK(MemoryChunk::FromAddress(code2_address)->Contains(code2_address)); | |
| 6824 | 6824 | } | |
| 6825 | 6825 | ||
| 6826 | + TEST(Regress9701) { | ||
| 6827 | + ManualGCScope manual_gc_scope; | ||
| 6828 | + if (!FLAG_incremental_marking) return; | ||
| 6829 | + CcTest::InitializeVM(); | ||
| 6830 | + Heap* heap = CcTest::heap(); | ||
| 6831 | + // Start with an empty new space. | ||
| 6832 | + CcTest::CollectGarbage(NEW_SPACE); | ||
| 6833 | + CcTest::CollectGarbage(NEW_SPACE); | ||
| 6834 | + | ||
| 6835 | + int mark_sweep_count_before = heap->ms_count(); | ||
| 6836 | + // Allocate many short living array buffers. | ||
| 6837 | + for (int i = 0; i < 1000; i++) { | ||
| 6838 | + HandleScope scope(heap->isolate()); | ||
| 6839 | + CcTest::i_isolate()->factory()->NewJSArrayBufferAndBackingStore( | ||
| 6840 | + 64 * KB, InitializedFlag::kZeroInitialized); | ||
| 6841 | + } | ||
| 6842 | + int mark_sweep_count_after = heap->ms_count(); | ||
| 6843 | + // We expect only scavenges, no full GCs. | ||
| 6844 | + CHECK_EQ(mark_sweep_count_before, mark_sweep_count_after); | ||
| 6845 | + } | ||
| 6846 | + | ||
| 6826 | 6847 | } // namespace heap | |
| 6827 | 6848 | } // namespace internal | |
| 6828 | 6849 | } // namespace v8 | |
| Back | FazBrowse Home | New Git URL |
0 commit comments