From f79096a3f257aff8d03f60ad1fcd7ce616ba947e Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Sat, 26 May 2018 00:34:38 +0200 Subject: [PATCH] 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: https://github.com/nodejs/node/pull/20971 Reviewed-By: Tiancheng "Timothy" Gu Reviewed-By: Minwoo Jung Reviewed-By: Ben Noordhuis Reviewed-By: Joyee Cheung Reviewed-By: James M Snell --- src/node_v8.cc | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/node_v8.cc b/src/node_v8.cc index bb41b569e6f796..d546eeba93f4d9 100644 --- a/src/node_v8.cc +++ b/src/node_v8.cc @@ -71,9 +71,6 @@ static const size_t kHeapSpaceStatisticsPropertiesCount = HEAP_SPACE_STATISTICS_PROPERTIES(V); #undef V -// Will be populated in InitializeV8Bindings. -static size_t number_of_heap_spaces = 0; - void CachedDataVersionTag(const FunctionCallbackInfo& args) { Environment* env = Environment::GetCurrent(args); @@ -100,6 +97,7 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo& args) { HeapSpaceStatistics s; Isolate* const isolate = env->isolate(); double* buffer = env->heap_space_statistics_buffer(); + size_t number_of_heap_spaces = env->isolate()->NumberOfHeapSpaces(); for (size_t i = 0; i < number_of_heap_spaces; i++) { isolate->GetHeapSpaceStatistics(&s, i); @@ -153,7 +151,7 @@ void Initialize(Local target, Uint32::NewFromUnsigned(env->isolate(), kHeapSpaceStatisticsPropertiesCount)); - number_of_heap_spaces = env->isolate()->NumberOfHeapSpaces(); + size_t number_of_heap_spaces = env->isolate()->NumberOfHeapSpaces(); // Heap space names are extracted once and exposed to JavaScript to // avoid excessive creation of heap space name Strings.