| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent bf0de92 commit b9ba3a7
8 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -38,7 +38,7 @@ | |||
| 38 | 38 | ||
| 39 | 39 | # Reset this number to 0 on major V8 upgrades. | |
| 40 | 40 | # Increment by one for each non-official patch applied to deps/v8. | |
| 41 | - 'v8_embedder_string': '-node.12', | ||
| 41 | + 'v8_embedder_string': '-node.13', | ||
| 42 | 42 | ||
| 43 | 43 | ##### V8 defaults for Node.js ##### | |
| 44 | 44 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -154,6 +154,13 @@ class V8_EXPORT HeapStatistics { | |||
| 154 | 154 | size_t number_of_native_contexts() { return number_of_native_contexts_; } | |
| 155 | 155 | size_t number_of_detached_contexts() { return number_of_detached_contexts_; } | |
| 156 | 156 | ||
| 157 | + /** | ||
| 158 | + * Returns the total number of bytes allocated since the Isolate was created. | ||
| 159 | + * This includes all heap objects allocated in any space (new, old, code, | ||
| 160 | + * etc.). | ||
| 161 | + */ | ||
| 162 | + uint64_t total_allocated_bytes() { return total_allocated_bytes_; } | ||
| 163 | + | ||
| 157 | 164 | /** | |
| 158 | 165 | * Returns a 0/1 boolean, which signifies whether the V8 overwrite heap | |
| 159 | 166 | * garbage with a bit pattern. | |
@@ -175,6 +182,7 @@ class V8_EXPORT HeapStatistics { | |||
| 175 | 182 | size_t number_of_detached_contexts_; | |
| 176 | 183 | size_t total_global_handles_size_; | |
| 177 | 184 | size_t used_global_handles_size_; | |
| 185 | + uint64_t total_allocated_bytes_; | ||
| 178 | 186 | ||
| 179 | 187 | friend class V8; | |
| 180 | 188 | friend class Isolate; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6584,7 +6584,8 @@ HeapStatistics::HeapStatistics() | |||
| 6584 | 6584 | peak_malloced_memory_(0), | |
| 6585 | 6585 | does_zap_garbage_(false), | |
| 6586 | 6586 | number_of_native_contexts_(0), | |
| 6587 | - number_of_detached_contexts_(0) {} | ||
| 6587 | + number_of_detached_contexts_(0), | ||
| 6588 | + total_allocated_bytes_(0) {} | ||
| 6588 | 6589 | ||
| 6589 | 6590 | HeapSpaceStatistics::HeapSpaceStatistics() | |
| 6590 | 6591 | : space_name_(nullptr), | |
@@ -10438,6 +10439,7 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) { | |||
| 10438 | 10439 | heap_statistics->number_of_native_contexts_ = heap->NumberOfNativeContexts(); | |
| 10439 | 10440 | heap_statistics->number_of_detached_contexts_ = | |
| 10440 | 10441 | heap->NumberOfDetachedContexts(); | |
| 10442 | + heap_statistics->total_allocated_bytes_ = heap->GetTotalAllocatedBytes(); | ||
| 10441 | 10443 | heap_statistics->does_zap_garbage_ = i::heap::ShouldZapGarbage(); | |
| 10442 | 10444 | ||
| 10443 | 10445 | #if V8_ENABLE_WEBASSEMBLY | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -85,25 +85,42 @@ AllocationResult HeapAllocator::AllocateRawLargeInternal( | |||
| 85 | 85 | int size_in_bytes, AllocationType allocation, AllocationOrigin origin, | |
| 86 | 86 | AllocationAlignment alignment, AllocationHint hint) { | |
| 87 | 87 | DCHECK_GT(size_in_bytes, heap_->MaxRegularHeapObjectSize(allocation)); | |
| 88 | + AllocationResult allocation_result; | ||
| 88 | 89 | switch (allocation) { | |
| 89 | 90 | case AllocationType::kYoung: | |
| 90 | - return new_lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 91 | + allocation_result = | ||
| 92 | + new_lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 93 | + break; | ||
| 91 | 94 | case AllocationType::kOld: | |
| 92 | - return lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 95 | + allocation_result = | ||
| 96 | + lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 97 | + break; | ||
| 93 | 98 | case AllocationType::kCode: | |
| 94 | - return code_lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 99 | + allocation_result = | ||
| 100 | + code_lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 101 | + break; | ||
| 95 | 102 | case AllocationType::kSharedOld: | |
| 96 | - return shared_lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 103 | + allocation_result = | ||
| 104 | + shared_lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 105 | + break; | ||
| 97 | 106 | case AllocationType::kTrusted: | |
| 98 | - return trusted_lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 107 | + allocation_result = | ||
| 108 | + trusted_lo_space()->AllocateRaw(local_heap_, size_in_bytes, hint); | ||
| 109 | + break; | ||
| 99 | 110 | case AllocationType::kSharedTrusted: | |
| 100 | - return shared_trusted_lo_space()->AllocateRaw(local_heap_, size_in_bytes, | ||
| 101 | - hint); | ||
| 111 | + allocation_result = shared_trusted_lo_space()->AllocateRaw( | ||
| 112 | + local_heap_, size_in_bytes, hint); | ||
| 113 | + break; | ||
| 102 | 114 | case AllocationType::kMap: | |
| 103 | 115 | case AllocationType::kReadOnly: | |
| 104 | 116 | case AllocationType::kSharedMap: | |
| 105 | 117 | UNREACHABLE(); | |
| 106 | 118 | } | |
| 119 | + if (!allocation_result.IsFailure()) { | ||
| 120 | + int allocated_size = ALIGN_TO_ALLOCATION_ALIGNMENT(size_in_bytes); | ||
| 121 | + heap_->AddTotalAllocatedBytes(allocated_size); | ||
| 122 | + } | ||
| 123 | + return allocation_result; | ||
| 107 | 124 | } | |
| 108 | 125 | ||
| 109 | 126 | namespace { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7717,6 +7717,10 @@ int Heap::NextStackTraceId() { | |||
| 7717 | 7717 | return last_id; | |
| 7718 | 7718 | } | |
| 7719 | 7719 | ||
| 7720 | + uint64_t Heap::GetTotalAllocatedBytes() { | ||
| 7721 | + return total_allocated_bytes_.load(std::memory_order_relaxed); | ||
| 7722 | + } | ||
| 7723 | + | ||
| 7720 | 7724 | EmbedderStackStateScope::EmbedderStackStateScope( | |
| 7721 | 7725 | Heap* heap, EmbedderStackStateOrigin origin, StackState stack_state) | |
| 7722 | 7726 | : heap_(heap), | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1707,6 +1707,11 @@ class Heap final { | |||
| 1707 | 1707 | bool ShouldUseBackgroundThreads() const; | |
| 1708 | 1708 | bool ShouldUseIncrementalMarking() const; | |
| 1709 | 1709 | ||
| 1710 | + void AddTotalAllocatedBytes(size_t size) { | ||
| 1711 | + total_allocated_bytes_.fetch_add(size, std::memory_order_relaxed); | ||
| 1712 | + } | ||
| 1713 | + uint64_t GetTotalAllocatedBytes(); | ||
| 1714 | + | ||
| 1710 | 1715 | HeapAllocator* allocator() { return heap_allocator_; } | |
| 1711 | 1716 | const HeapAllocator* allocator() const { return heap_allocator_; } | |
| 1712 | 1717 | ||
@@ -2499,6 +2504,8 @@ class Heap final { | |||
| 2499 | 2504 | // no value was provided this will be 0. | |
| 2500 | 2505 | uint64_t physical_memory_; | |
| 2501 | 2506 | ||
| 2507 | + std::atomic<uint64_t> total_allocated_bytes_ = 0; | ||
| 2508 | + | ||
| 2502 | 2509 | // Classes in "heap" can be friends. | |
| 2503 | 2510 | friend class ActivateMemoryReducerTask; | |
| 2504 | 2511 | friend class AlwaysAllocateScope; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -297,6 +297,12 @@ void MainAllocator::ResetLab(Address start, Address end, Address extended_end) { | |||
| 297 | 297 | MemoryChunkMetadata::UpdateHighWaterMark(top()); | |
| 298 | 298 | } | |
| 299 | 299 | ||
| 300 | + // This is going to overestimate a bit of the total allocated bytes, since the | ||
| 301 | + // LAB was not used yet. However the leftover compared to the LAB itself is | ||
| 302 | + // quite small, so it seems tolerable. | ||
| 303 | + if (local_heap_) { | ||
| 304 | + local_heap_->heap()->AddTotalAllocatedBytes(end - start); | ||
| 305 | + } | ||
| 300 | 306 | allocation_info().Reset(start, end); | |
| 301 | 307 | extended_limit_ = extended_end; | |
| 302 | 308 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -17656,6 +17656,152 @@ TEST(GetHeapSpaceStatistics) { | |||
| 17656 | 17656 | CHECK_EQ(total_physical_size, heap_statistics.total_physical_size()); | |
| 17657 | 17657 | } | |
| 17658 | 17658 | ||
| 17659 | + UNINITIALIZED_TEST(GetHeapTotalAllocatedBytes) { | ||
| 17660 | + // This test is incompatible with concurrent allocation, which may occur | ||
| 17661 | + // while collecting the statistics and break the final `CHECK_EQ`s. | ||
| 17662 | + if (i::v8_flags.stress_concurrent_allocation) return; | ||
| 17663 | + | ||
| 17664 | + v8::Isolate::CreateParams create_params; | ||
| 17665 | + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | ||
| 17666 | + v8::Isolate* isolate = v8::Isolate::New(create_params); | ||
| 17667 | + | ||
| 17668 | + const uint32_t number_of_elements = 1; | ||
| 17669 | + const uint32_t allocation_size = i::FixedArray::SizeFor(number_of_elements); | ||
| 17670 | + const uint32_t trusted_allocation_size = | ||
| 17671 | + i::TrustedFixedArray::SizeFor(number_of_elements); | ||
| 17672 | + const uint32_t lo_number_of_elements = 256 * 1024; | ||
| 17673 | + const uint32_t lo_allocation_size = | ||
| 17674 | + i::FixedArray::SizeFor(lo_number_of_elements); | ||
| 17675 | + const uint32_t trusted_lo_allocation_size = | ||
| 17676 | + i::TrustedFixedArray::SizeFor(lo_number_of_elements); | ||
| 17677 | + const uint32_t expected_allocation_size = | ||
| 17678 | + allocation_size * 2 + lo_allocation_size * 2 + trusted_allocation_size + | ||
| 17679 | + trusted_lo_allocation_size; | ||
| 17680 | + | ||
| 17681 | + { | ||
| 17682 | + v8::Isolate::Scope isolate_scope(isolate); | ||
| 17683 | + v8::HandleScope handle_scope(isolate); | ||
| 17684 | + LocalContext env(isolate); | ||
| 17685 | + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | ||
| 17686 | + | ||
| 17687 | + v8::HeapStatistics heap_stats_before; | ||
| 17688 | + isolate->GetHeapStatistics(&heap_stats_before); | ||
| 17689 | + size_t initial_allocated = heap_stats_before.total_allocated_bytes(); | ||
| 17690 | + | ||
| 17691 | + i::MaybeHandle<i::FixedArray> young_alloc = | ||
| 17692 | + i_isolate->factory()->TryNewFixedArray(number_of_elements, | ||
| 17693 | + i::AllocationType::kYoung); | ||
| 17694 | + USE(young_alloc); | ||
| 17695 | + i::MaybeHandle<i::FixedArray> old_alloc = | ||
| 17696 | + i_isolate->factory()->TryNewFixedArray(number_of_elements, | ||
| 17697 | + i::AllocationType::kOld); | ||
| 17698 | + USE(old_alloc); | ||
| 17699 | + i::Handle<i::TrustedFixedArray> trusted_alloc = | ||
| 17700 | + i_isolate->factory()->NewTrustedFixedArray(number_of_elements, | ||
| 17701 | + i::AllocationType::kTrusted); | ||
| 17702 | + USE(trusted_alloc); | ||
| 17703 | + i::MaybeHandle<i::FixedArray> old_lo_alloc = | ||
| 17704 | + i_isolate->factory()->TryNewFixedArray(lo_number_of_elements, | ||
| 17705 | + i::AllocationType::kOld); | ||
| 17706 | + USE(old_lo_alloc); | ||
| 17707 | + | ||
| 17708 | + { | ||
| 17709 | + v8::HandleScope inner_handle_scope(isolate); | ||
| 17710 | + auto young_lo_alloc = i_isolate->factory()->TryNewFixedArray( | ||
| 17711 | + lo_number_of_elements, i::AllocationType::kYoung); | ||
| 17712 | + USE(young_lo_alloc); | ||
| 17713 | + } | ||
| 17714 | + | ||
| 17715 | + auto trusted_lo_alloc = i_isolate->factory()->NewTrustedFixedArray( | ||
| 17716 | + lo_number_of_elements, i::AllocationType::kTrusted); | ||
| 17717 | + USE(trusted_lo_alloc); | ||
| 17718 | + | ||
| 17719 | + v8::HeapStatistics heap_stats_after; | ||
| 17720 | + isolate->GetHeapStatistics(&heap_stats_after); | ||
| 17721 | + uint64_t final_allocated = heap_stats_after.total_allocated_bytes(); | ||
| 17722 | + | ||
| 17723 | + CHECK_GT(final_allocated, initial_allocated); | ||
| 17724 | + uint64_t allocated_diff = final_allocated - initial_allocated; | ||
| 17725 | + CHECK_GE(allocated_diff, expected_allocation_size); | ||
| 17726 | + | ||
| 17727 | + // This either tests counting happening when a LAB freed and validate | ||
| 17728 | + // there's no double counting on evacuated/promoted objects. | ||
| 17729 | + v8::internal::heap::InvokeAtomicMajorGC(i_isolate->heap()); | ||
| 17730 | + | ||
| 17731 | + v8::HeapStatistics heap_stats_after_gc; | ||
| 17732 | + isolate->GetHeapStatistics(&heap_stats_after_gc); | ||
| 17733 | + uint64_t total_allocation_after_gc = | ||
| 17734 | + heap_stats_after_gc.total_allocated_bytes(); | ||
| 17735 | + | ||
| 17736 | + CHECK_EQ(total_allocation_after_gc, final_allocated); | ||
| 17737 | + } | ||
| 17738 | + | ||
| 17739 | + isolate->Dispose(); | ||
| 17740 | + } | ||
| 17741 | + | ||
| 17742 | + #if V8_CAN_CREATE_SHARED_HEAP_BOOL | ||
| 17743 | + | ||
| 17744 | + UNINITIALIZED_TEST(GetHeapTotalAllocatedBytesSharedSpaces) { | ||
| 17745 | + // This test is incompatible with concurrent allocation, which may occur | ||
| 17746 | + // while collecting the statistics and break the final `CHECK_EQ`s. | ||
| 17747 | + if (i::v8_flags.stress_concurrent_allocation) return; | ||
| 17748 | + if (COMPRESS_POINTERS_IN_MULTIPLE_CAGES_BOOL) return; | ||
| 17749 | + | ||
| 17750 | + i::v8_flags.shared_heap = true; | ||
| 17751 | + i::FlagList::EnforceFlagImplications(); | ||
| 17752 | + | ||
| 17753 | + v8::Isolate::CreateParams create_params; | ||
| 17754 | + create_params.array_buffer_allocator = CcTest::array_buffer_allocator(); | ||
| 17755 | + v8::Isolate* isolate = v8::Isolate::New(create_params); | ||
| 17756 | + | ||
| 17757 | + { | ||
| 17758 | + v8::Isolate::Scope isolate_scope(isolate); | ||
| 17759 | + v8::HandleScope handle_scope(isolate); | ||
| 17760 | + LocalContext env(isolate); | ||
| 17761 | + | ||
| 17762 | + v8::HeapStatistics heap_stats_before; | ||
| 17763 | + isolate->GetHeapStatistics(&heap_stats_before); | ||
| 17764 | + size_t initial_allocated = heap_stats_before.total_allocated_bytes(); | ||
| 17765 | + | ||
| 17766 | + i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); | ||
| 17767 | + | ||
| 17768 | + const uint32_t number_of_elements = 1; | ||
| 17769 | + const uint32_t allocation_size = i::FixedArray::SizeFor(number_of_elements); | ||
| 17770 | + const uint32_t trusted_allocation_size = | ||
| 17771 | + i::TrustedFixedArray::SizeFor(number_of_elements); | ||
| 17772 | + const uint32_t lo_number_of_elements = 256 * 1024; | ||
| 17773 | + const uint32_t lo_allocation_size = | ||
| 17774 | + i::FixedArray::SizeFor(lo_number_of_elements); | ||
| 17775 | + const uint32_t expected_allocation_size = | ||
| 17776 | + allocation_size + trusted_allocation_size + lo_allocation_size; | ||
| 17777 | + | ||
| 17778 | + i::MaybeHandle<i::FixedArray> shared_alloc = | ||
| 17779 | + i_isolate->factory()->TryNewFixedArray(number_of_elements, | ||
| 17780 | + i::AllocationType::kSharedOld); | ||
| 17781 | + USE(shared_alloc); | ||
| 17782 | + i::Handle<i::TrustedFixedArray> shared_trusted_alloc = | ||
| 17783 | + i_isolate->factory()->NewTrustedFixedArray( | ||
| 17784 | + number_of_elements, i::AllocationType::kSharedTrusted); | ||
| 17785 | + USE(shared_trusted_alloc); | ||
| 17786 | + i::MaybeHandle<i::FixedArray> shared_lo_alloc = | ||
| 17787 | + i_isolate->factory()->TryNewFixedArray(lo_number_of_elements, | ||
| 17788 | + i::AllocationType::kSharedOld); | ||
| 17789 | + USE(shared_lo_alloc); | ||
| 17790 | + | ||
| 17791 | + v8::HeapStatistics heap_stats_after; | ||
| 17792 | + isolate->GetHeapStatistics(&heap_stats_after); | ||
| 17793 | + uint64_t final_allocated = heap_stats_after.total_allocated_bytes(); | ||
| 17794 | + | ||
| 17795 | + CHECK_GT(final_allocated, initial_allocated); | ||
| 17796 | + uint64_t allocated_diff = final_allocated - initial_allocated; | ||
| 17797 | + CHECK_GE(allocated_diff, expected_allocation_size); | ||
| 17798 | + } | ||
| 17799 | + | ||
| 17800 | + isolate->Dispose(); | ||
| 17801 | + } | ||
| 17802 | + | ||
| 17803 | + #endif // V8_CAN_CREATE_SHARED_HEAP_BOOL | ||
| 17804 | + | ||
| 17659 | 17805 | TEST(NumberOfNativeContexts) { | |
| 17660 | 17806 | static const size_t kNumTestContexts = 10; | |
| 17661 | 17807 | i::Isolate* isolate = CcTest::i_isolate(); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments