Skip to content

Commit fc2cd63

Browse files
bnoordhuisMylesBorins
authored andcommitted
lib,src: support values > 4GB in heap statistics
We were transporting the heap statistics as uint32 values to JS land but those wrap around for values > 4 GB. Use 64 bits floats instead, those should last us a while. Fixes: #10185 PR-URL: #10186 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
1 parent 0109321 commit fc2cd63

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

lib/v8.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const v8binding = process.binding('v8');
1818

1919
// Properties for heap statistics buffer extraction.
2020
const heapStatisticsBuffer =
21-
new Uint32Array(v8binding.heapStatisticsArrayBuffer);
21+
new Float64Array(v8binding.heapStatisticsArrayBuffer);
2222
const kTotalHeapSizeIndex = v8binding.kTotalHeapSizeIndex;
2323
const kTotalHeapSizeExecutableIndex = v8binding.kTotalHeapSizeExecutableIndex;
2424
const kTotalPhysicalSizeIndex = v8binding.kTotalPhysicalSizeIndex;
@@ -28,7 +28,7 @@ const kHeapSizeLimitIndex = v8binding.kHeapSizeLimitIndex;
2828

2929
// Properties for heap space statistics buffer extraction.
3030
const heapSpaceStatisticsBuffer =
31-
new Uint32Array(v8binding.heapSpaceStatisticsArrayBuffer);
31+
new Float64Array(v8binding.heapSpaceStatisticsArrayBuffer);
3232
const kHeapSpaces = v8binding.kHeapSpaces;
3333
const kNumberOfHeapSpaces = kHeapSpaces.length;
3434
const kHeapSpaceStatisticsPropertiesCount =

src/env-inl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,22 +378,22 @@ inline std::vector<int64_t>* Environment::destroy_ids_list() {
378378
return &destroy_ids_list_;
379379
}
380380

381-
inline uint32_t* Environment::heap_statistics_buffer() const {
381+
inline double* Environment::heap_statistics_buffer() const {
382382
CHECK_NE(heap_statistics_buffer_, nullptr);
383383
return heap_statistics_buffer_;
384384
}
385385

386-
inline void Environment::set_heap_statistics_buffer(uint32_t* pointer) {
386+
inline void Environment::set_heap_statistics_buffer(double* pointer) {
387387
CHECK_EQ(heap_statistics_buffer_, nullptr); // Should be set only once.
388388
heap_statistics_buffer_ = pointer;
389389
}
390390

391-
inline uint32_t* Environment::heap_space_statistics_buffer() const {
391+
inline double* Environment::heap_space_statistics_buffer() const {
392392
CHECK_NE(heap_space_statistics_buffer_, nullptr);
393393
return heap_space_statistics_buffer_;
394394
}
395395

396-
inline void Environment::set_heap_space_statistics_buffer(uint32_t* pointer) {
396+
inline void Environment::set_heap_space_statistics_buffer(double* pointer) {
397397
CHECK_EQ(heap_space_statistics_buffer_, nullptr); // Should be set only once.
398398
heap_space_statistics_buffer_ = pointer;
399399
}

src/env.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -462,11 +462,11 @@ class Environment {
462462
// List of id's that have been destroyed and need the destroy() cb called.
463463
inline std::vector<int64_t>* destroy_ids_list();
464464

465-
inline uint32_t* heap_statistics_buffer() const;
466-
inline void set_heap_statistics_buffer(uint32_t* pointer);
465+
inline double* heap_statistics_buffer() const;
466+
inline void set_heap_statistics_buffer(double* pointer);
467467

468-
inline uint32_t* heap_space_statistics_buffer() const;
469-
inline void set_heap_space_statistics_buffer(uint32_t* pointer);
468+
inline double* heap_space_statistics_buffer() const;
469+
inline void set_heap_space_statistics_buffer(double* pointer);
470470

471471
inline char* http_parser_buffer() const;
472472
inline void set_http_parser_buffer(char* buffer);
@@ -570,8 +570,8 @@ class Environment {
570570
&HandleCleanup::handle_cleanup_queue_> handle_cleanup_queue_;
571571
int handle_cleanup_waiting_;
572572

573-
uint32_t* heap_statistics_buffer_ = nullptr;
574-
uint32_t* heap_space_statistics_buffer_ = nullptr;
573+
double* heap_statistics_buffer_ = nullptr;
574+
double* heap_space_statistics_buffer_ = nullptr;
575575

576576
char* http_parser_buffer_;
577577

src/node_v8.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ void UpdateHeapStatisticsArrayBuffer(const FunctionCallbackInfo<Value>& args) {
5656
Environment* env = Environment::GetCurrent(args);
5757
HeapStatistics s;
5858
env->isolate()->GetHeapStatistics(&s);
59-
uint32_t* const buffer = env->heap_statistics_buffer();
60-
#define V(index, name, _) buffer[index] = static_cast<uint32_t>(s.name());
59+
double* const buffer = env->heap_statistics_buffer();
60+
#define V(index, name, _) buffer[index] = static_cast<double>(s.name());
6161
HEAP_STATISTICS_PROPERTIES(V)
6262
#undef V
6363
}
@@ -67,13 +67,13 @@ void UpdateHeapSpaceStatisticsBuffer(const FunctionCallbackInfo<Value>& args) {
6767
Environment* env = Environment::GetCurrent(args);
6868
HeapSpaceStatistics s;
6969
Isolate* const isolate = env->isolate();
70-
uint32_t* buffer = env->heap_space_statistics_buffer();
70+
double* buffer = env->heap_space_statistics_buffer();
7171

7272
for (size_t i = 0; i < number_of_heap_spaces; i++) {
7373
isolate->GetHeapSpaceStatistics(&s, i);
7474
size_t const property_offset = i * kHeapSpaceStatisticsPropertiesCount;
7575
#define V(index, name, _) buffer[property_offset + index] = \
76-
static_cast<uint32_t>(s.name());
76+
static_cast<double>(s.name());
7777
HEAP_SPACE_STATISTICS_PROPERTIES(V)
7878
#undef V
7979
}
@@ -102,7 +102,7 @@ void InitializeV8Bindings(Local<Object> target,
102102
"updateHeapStatisticsArrayBuffer",
103103
UpdateHeapStatisticsArrayBuffer);
104104

105-
env->set_heap_statistics_buffer(new uint32_t[kHeapStatisticsPropertiesCount]);
105+
env->set_heap_statistics_buffer(new double[kHeapStatisticsPropertiesCount]);
106106

107107
const size_t heap_statistics_buffer_byte_length =
108108
sizeof(*env->heap_statistics_buffer()) * kHeapStatisticsPropertiesCount;
@@ -148,7 +148,7 @@ void InitializeV8Bindings(Local<Object> target,
148148
UpdateHeapSpaceStatisticsBuffer);
149149

150150
env->set_heap_space_statistics_buffer(
151-
new uint32_t[kHeapSpaceStatisticsPropertiesCount * number_of_heap_spaces]);
151+
new double[kHeapSpaceStatisticsPropertiesCount * number_of_heap_spaces]);
152152

153153
const size_t heap_space_statistics_buffer_byte_length =
154154
sizeof(*env->heap_space_statistics_buffer()) *

0 commit comments

Comments
 (0)