Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit e88dd01

Browse filesBrowse files
authored
v8: changing total_allocated_bytes to avoid ABI changes
PR-URL: #60800 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent 8255cde commit e88dd01
Copy full SHA for e88dd01

9 files changed

+33-165Lines changed: 33 additions & 165 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎common.gypi‎

Copy file name to clipboardExpand all lines: common.gypi
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
# Reset this number to 0 on major V8 upgrades.
4040
# Increment by one for each non-official patch applied to deps/v8.
41-
'v8_embedder_string': '-node.17',
41+
'v8_embedder_string': '-node.18',
4242

4343
##### V8 defaults for Node.js #####
4444

Collapse file

‎deps/v8/include/v8-isolate.h‎

Copy file name to clipboardExpand all lines: deps/v8/include/v8-isolate.h
+7Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,6 +1001,13 @@ class V8_EXPORT Isolate {
10011001
*/
10021002
void GetHeapStatistics(HeapStatistics* heap_statistics);
10031003

1004+
/**
1005+
* Get total allocated bytes since isolate creation.
1006+
* This should be used only by Node.JS, since it's a temporary method
1007+
* to avoid breaking ABI on HeapStatistics.
1008+
*/
1009+
uint64_t GetTotalAllocatedBytes();
1010+
10041011
/**
10051012
* Returns the number of spaces in the heap.
10061013
*/
Collapse file

‎deps/v8/include/v8-statistics.h‎

Copy file name to clipboardExpand all lines: deps/v8/include/v8-statistics.h
-8Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,13 +154,6 @@ class V8_EXPORT HeapStatistics {
154154
size_t number_of_native_contexts() { return number_of_native_contexts_; }
155155
size_t number_of_detached_contexts() { return number_of_detached_contexts_; }
156156

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-
164157
/**
165158
* Returns a 0/1 boolean, which signifies whether the V8 overwrite heap
166159
* garbage with a bit pattern.
@@ -182,7 +175,6 @@ class V8_EXPORT HeapStatistics {
182175
size_t number_of_detached_contexts_;
183176
size_t total_global_handles_size_;
184177
size_t used_global_handles_size_;
185-
uint64_t total_allocated_bytes_;
186178

187179
friend class V8;
188180
friend class Isolate;
Collapse file

‎deps/v8/src/api/api.cc‎

Copy file name to clipboardExpand all lines: deps/v8/src/api/api.cc
+6-3Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6584,8 +6584,7 @@ HeapStatistics::HeapStatistics()
65846584
peak_malloced_memory_(0),
65856585
does_zap_garbage_(false),
65866586
number_of_native_contexts_(0),
6587-
number_of_detached_contexts_(0),
6588-
total_allocated_bytes_(0) {}
6587+
number_of_detached_contexts_(0) {}
65896588

65906589
HeapSpaceStatistics::HeapSpaceStatistics()
65916590
: space_name_(nullptr),
@@ -10439,7 +10438,6 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
1043910438
heap_statistics->number_of_native_contexts_ = heap->NumberOfNativeContexts();
1044010439
heap_statistics->number_of_detached_contexts_ =
1044110440
heap->NumberOfDetachedContexts();
10442-
heap_statistics->total_allocated_bytes_ = heap->GetTotalAllocatedBytes();
1044310441
heap_statistics->does_zap_garbage_ = i::heap::ShouldZapGarbage();
1044410442

1044510443
#if V8_ENABLE_WEBASSEMBLY
@@ -10450,6 +10448,11 @@ void Isolate::GetHeapStatistics(HeapStatistics* heap_statistics) {
1045010448
#endif // V8_ENABLE_WEBASSEMBLY
1045110449
}
1045210450

10451+
uint64_t Isolate::GetTotalAllocatedBytes() {
10452+
i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(this);
10453+
return i_isolate->heap()->GetTotalAllocatedBytes();
10454+
}
10455+
1045310456
size_t Isolate::NumberOfHeapSpaces() {
1045410457
return i::LAST_SPACE - i::FIRST_SPACE + 1;
1045510458
}
Collapse file

‎deps/v8/test/cctest/test-api.cc‎

Copy file name to clipboardExpand all lines: deps/v8/test/cctest/test-api.cc
-146Lines changed: 0 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -17656,152 +17656,6 @@ TEST(GetHeapSpaceStatistics) {
1765617656
CHECK_EQ(total_physical_size, heap_statistics.total_physical_size());
1765717657
}
1765817658

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-
1780517659
TEST(NumberOfNativeContexts) {
1780617660
static const size_t kNumTestContexts = 10;
1780717661
i::Isolate* isolate = CcTest::i_isolate();
Collapse file

‎doc/api/v8.md‎

Copy file name to clipboardExpand all lines: doc/api/v8.md
+3-2Lines changed: 3 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ used memory size of V8 global handles.
265265
buffers and external strings.
266266

267267
`total_allocated_bytes` The value of total allocated bytes since the Isolate
268-
creation
268+
creation.
269269

270270
<!-- eslint-skip -->
271271

@@ -284,7 +284,8 @@ creation
284284
number_of_detached_contexts: 0,
285285
total_global_handles_size: 8192,
286286
used_global_handles_size: 3296,
287-
external_memory: 318824
287+
external_memory: 318824,
288+
total_allocated_bytes: 45224088
288289
}
289290
```
290291

Collapse file

‎lib/v8.js‎

Copy file name to clipboardExpand all lines: lib/v8.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const {
117117
stopCpuProfile: _stopCpuProfile,
118118
isStringOneByteRepresentation: _isStringOneByteRepresentation,
119119
updateHeapStatisticsBuffer,
120+
getTotalAllocatedBytes,
120121
updateHeapSpaceStatisticsBuffer,
121122
updateHeapCodeStatisticsBuffer,
122123
setHeapSnapshotNearHeapLimit: _setHeapSnapshotNearHeapLimit,
@@ -136,7 +137,6 @@ const {
136137
kTotalGlobalHandlesSizeIndex,
137138
kUsedGlobalHandlesSizeIndex,
138139
kExternalMemoryIndex,
139-
kTotalAllocatedBytes,
140140

141141
// Properties for heap spaces statistics buffer extraction.
142142
kHeapSpaces,
@@ -247,7 +247,7 @@ function getHeapStatistics() {
247247
total_global_handles_size: buffer[kTotalGlobalHandlesSizeIndex],
248248
used_global_handles_size: buffer[kUsedGlobalHandlesSizeIndex],
249249
external_memory: buffer[kExternalMemoryIndex],
250-
total_allocated_bytes: buffer[kTotalAllocatedBytes],
250+
total_allocated_bytes: getTotalAllocatedBytes(),
251251
};
252252
}
253253

Collapse file

‎src/node_v8.cc‎

Copy file name to clipboardExpand all lines: src/node_v8.cc
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ using v8::Value;
7373
V(10, number_of_detached_contexts, kNumberOfDetachedContextsIndex) \
7474
V(11, total_global_handles_size, kTotalGlobalHandlesSizeIndex) \
7575
V(12, used_global_handles_size, kUsedGlobalHandlesSizeIndex) \
76-
V(13, external_memory, kExternalMemoryIndex) \
77-
V(14, total_allocated_bytes, kTotalAllocatedBytes)
76+
V(13, external_memory, kExternalMemoryIndex)
7877

7978
#define V(a, b, c) +1
8079
static constexpr size_t kHeapStatisticsPropertiesCount =
@@ -213,6 +212,12 @@ void UpdateHeapStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {
213212
#undef V
214213
}
215214

215+
void GetTotalAllocatedBytes(const FunctionCallbackInfo<Value>& args) {
216+
Isolate* isolate = args.GetIsolate();
217+
uint64_t allocated_bytes = isolate->GetTotalAllocatedBytes();
218+
args.GetReturnValue().Set(Number::New(isolate, allocated_bytes));
219+
}
220+
216221

217222
void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {
218223
BindingData* data = Realm::GetBindingData<BindingData>(args);
@@ -693,6 +698,11 @@ void Initialize(Local<Object> target,
693698
"updateHeapStatisticsBuffer",
694699
UpdateHeapStatisticsBuffer);
695700

701+
SetMethod(context,
702+
target,
703+
"getTotalAllocatedBytes",
704+
GetTotalAllocatedBytes);
705+
696706
SetMethod(context,
697707
target,
698708
"updateHeapCodeStatisticsBuffer",
@@ -774,6 +784,7 @@ void Initialize(Local<Object> target,
774784
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
775785
registry->Register(CachedDataVersionTag);
776786
registry->Register(UpdateHeapStatisticsBuffer);
787+
registry->Register(GetTotalAllocatedBytes);
777788
registry->Register(UpdateHeapCodeStatisticsBuffer);
778789
registry->Register(UpdateHeapSpaceStatisticsBuffer);
779790
registry->Register(SetFlagsFromString);
Collapse file

‎src/node_worker.cc‎

Copy file name to clipboardExpand all lines: src/node_worker.cc
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ void Worker::GetHeapStatistics(const FunctionCallbackInfo<Value>& args) {
12841284
Number::New(isolate, heap_stats->total_global_handles_size()),
12851285
Number::New(isolate, heap_stats->used_global_handles_size()),
12861286
Number::New(isolate, heap_stats->external_memory()),
1287-
Number::New(isolate, heap_stats->total_allocated_bytes())};
1287+
Number::New(isolate, isolate->GetTotalAllocatedBytes())};
12881288

12891289
Local<Object> obj;
12901290
if (!NewDictionaryInstanceNullProto(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.