Skip to content

Commit f79096a

Browse files
addaleaxMylesBorins
authored andcommitted
src: do not cache NumberOfHeapSpaces() globally
While `NumberOfHeapSpaces()` currently returns a constant value, that is not strictly guaranteed by the V8 API as far as I can tell. Therefore, caching it globally does not seem appropriate. (The motivation here is that this squelches warnings which are produced by concurrency debugging tooling due to the apparent race conditions when accessing the global variable.) PR-URL: #20971 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent d84aa51 commit f79096a

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/node_v8.cc

+2-4
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,6 @@ static const size_t kHeapSpaceStatisticsPropertiesCount =
7171
HEAP_SPACE_STATISTICS_PROPERTIES(V);
7272
#undef V
7373

74-
// Will be populated in InitializeV8Bindings.
75-
static size_t number_of_heap_spaces = 0;
76-
7774

7875
void CachedDataVersionTag(const FunctionCallbackInfo<Value>& args) {
7976
Environment* env = Environment::GetCurrent(args);
@@ -100,6 +97,7 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {
10097
HeapSpaceStatistics s;
10198
Isolate* const isolate = env->isolate();
10299
double* buffer = env->heap_space_statistics_buffer();
100+
size_t number_of_heap_spaces = env->isolate()->NumberOfHeapSpaces();
103101

104102
for (size_t i = 0; i < number_of_heap_spaces; i++) {
105103
isolate->GetHeapSpaceStatistics(&s, i);
@@ -153,7 +151,7 @@ void Initialize(Local<Object> target,
153151
Uint32::NewFromUnsigned(env->isolate(),
154152
kHeapSpaceStatisticsPropertiesCount));
155153

156-
number_of_heap_spaces = env->isolate()->NumberOfHeapSpaces();
154+
size_t number_of_heap_spaces = env->isolate()->NumberOfHeapSpaces();
157155

158156
// Heap space names are extracted once and exposed to JavaScript to
159157
// avoid excessive creation of heap space name Strings.

0 commit comments

Comments
 (0)