38
38
#include " uv.h"
39
39
#include " v8.h"
40
40
41
+ #include < array>
41
42
#include < atomic>
42
43
#include < cstdint>
43
44
#include < functional>
@@ -330,31 +331,48 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2;
330
331
V (zero_return_string, " ZERO_RETURN" )
331
332
332
333
#define ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES (V ) \
333
- V (as_callback_data, v8::Object) \
334
334
V (as_callback_data_template, v8::FunctionTemplate) \
335
+ V (async_wrap_ctor_template, v8::FunctionTemplate) \
336
+ V (async_wrap_object_ctor_template, v8::FunctionTemplate) \
337
+ V (context, v8::Context) \
338
+ V (fd_constructor_template, v8::ObjectTemplate) \
339
+ V (fdclose_constructor_template, v8::ObjectTemplate) \
340
+ V (filehandlereadwrap_template, v8::ObjectTemplate) \
341
+ V (fsreqpromise_constructor_template, v8::ObjectTemplate) \
342
+ V (handle_wrap_ctor_template, v8::FunctionTemplate) \
343
+ V (http2settings_constructor_template, v8::ObjectTemplate) \
344
+ V (http2stream_constructor_template, v8::ObjectTemplate) \
345
+ V (http2ping_constructor_template, v8::ObjectTemplate) \
346
+ V (libuv_stream_wrap_ctor_template, v8::FunctionTemplate) \
347
+ V (message_event_object_template, v8::ObjectTemplate) \
348
+ V (message_port_constructor_template, v8::FunctionTemplate) \
349
+ V (pipe_constructor_template, v8::FunctionTemplate) \
350
+ V (promise_wrap_template, v8::ObjectTemplate) \
351
+ V (sab_lifetimepartner_constructor_template, v8::FunctionTemplate) \
352
+ V (script_context_constructor_template, v8::FunctionTemplate) \
353
+ V (secure_context_constructor_template, v8::FunctionTemplate) \
354
+ V (shutdown_wrap_template, v8::ObjectTemplate) \
355
+ V (streambaseoutputstream_constructor_template, v8::ObjectTemplate) \
356
+ V (tcp_constructor_template, v8::FunctionTemplate) \
357
+ V (tty_constructor_template, v8::FunctionTemplate) \
358
+ V (write_wrap_template, v8::ObjectTemplate)
359
+
360
+ #define ENVIRONMENT_STRONG_PERSISTENT_VALUES (V ) \
361
+ V (as_callback_data, v8::Object) \
335
362
V (async_hooks_after_function, v8::Function) \
336
363
V (async_hooks_before_function, v8::Function) \
337
364
V (async_hooks_binding, v8::Object) \
338
365
V (async_hooks_destroy_function, v8::Function) \
339
366
V (async_hooks_init_function, v8::Function) \
340
367
V (async_hooks_promise_resolve_function, v8::Function) \
341
- V (async_wrap_ctor_template, v8::FunctionTemplate) \
342
- V (async_wrap_object_ctor_template, v8::FunctionTemplate) \
343
368
V (buffer_prototype_object, v8::Object) \
344
369
V (coverage_connection, v8::Object) \
345
- V (context, v8::Context) \
346
370
V (crypto_key_object_constructor, v8::Function) \
347
371
V (domain_callback, v8::Function) \
348
372
V (domexception_function, v8::Function) \
349
- V (fd_constructor_template, v8::ObjectTemplate) \
350
- V (fdclose_constructor_template, v8::ObjectTemplate) \
351
- V (filehandlereadwrap_template, v8::ObjectTemplate) \
352
373
V (fs_use_promises_symbol, v8::Symbol) \
353
- V (fsreqpromise_constructor_template, v8::ObjectTemplate) \
354
- V (handle_wrap_ctor_template, v8::FunctionTemplate) \
355
374
V (host_import_module_dynamically_callback, v8::Function) \
356
375
V (host_initialize_import_meta_object_callback, v8::Function) \
357
- V (http2ping_constructor_template, v8::ObjectTemplate) \
358
376
V (http2session_on_altsvc_function, v8::Function) \
359
377
V (http2session_on_error_function, v8::Function) \
360
378
V (http2session_on_frame_error_function, v8::Function) \
@@ -367,48 +385,37 @@ constexpr size_t kFsStatsBufferLength = kFsStatsFieldsNumber * 2;
367
385
V (http2session_on_settings_function, v8::Function) \
368
386
V (http2session_on_stream_close_function, v8::Function) \
369
387
V (http2session_on_stream_trailers_function, v8::Function) \
370
- V (http2settings_constructor_template, v8::ObjectTemplate) \
371
- V (http2stream_constructor_template, v8::ObjectTemplate) \
372
388
V (internal_binding_loader, v8::Function) \
373
389
V (immediate_callback_function, v8::Function) \
374
390
V (inspector_console_extension_installer, v8::Function) \
375
- V (libuv_stream_wrap_ctor_template, v8::FunctionTemplate) \
376
391
V (message_port, v8::Object) \
377
- V (message_event_object_template, v8::ObjectTemplate) \
378
- V (message_port_constructor_template, v8::FunctionTemplate) \
379
392
V (native_module_require, v8::Function) \
380
393
V (on_coverage_message_function, v8::Function) \
381
394
V (performance_entry_callback, v8::Function) \
382
395
V (performance_entry_template, v8::Function) \
383
- V (pipe_constructor_template, v8::FunctionTemplate) \
384
396
V (process_object, v8::Object) \
385
397
V (primordials, v8::Object) \
386
398
V (promise_reject_callback, v8::Function) \
387
- V (promise_wrap_template, v8::ObjectTemplate) \
388
- V (sab_lifetimepartner_constructor_template, v8::FunctionTemplate) \
389
- V (script_context_constructor_template, v8::FunctionTemplate) \
390
399
V (script_data_constructor_function, v8::Function) \
391
- V (secure_context_constructor_template, v8::FunctionTemplate) \
392
- V (shutdown_wrap_template, v8::ObjectTemplate) \
393
- V (streambaseoutputstream_constructor_template, v8::ObjectTemplate) \
394
- V (tcp_constructor_template, v8::FunctionTemplate) \
395
400
V (tick_callback_function, v8::Function) \
396
401
V (timers_callback_function, v8::Function) \
397
402
V (tls_wrap_constructor_function, v8::Function) \
398
403
V (trace_category_state_function, v8::Function) \
399
- V (tty_constructor_template, v8::FunctionTemplate) \
400
404
V (udp_constructor_function, v8::Function) \
401
- V (url_constructor_function, v8::Function) \
402
- V (write_wrap_template, v8::ObjectTemplate)
405
+ V (url_constructor_function, v8::Function)
403
406
404
407
class Environment ;
405
408
406
- class IsolateData {
409
+ class IsolateData : public MemoryRetainer {
407
410
public:
408
411
IsolateData (v8::Isolate* isolate,
409
412
uv_loop_t * event_loop,
410
413
MultiIsolatePlatform* platform = nullptr ,
411
414
ArrayBufferAllocator* node_allocator = nullptr );
415
+ SET_MEMORY_INFO_NAME (IsolateData);
416
+ SET_SELF_SIZE (IsolateData);
417
+ void MemoryInfo (MemoryTracker* tracker) const override ;
418
+
412
419
inline uv_loop_t * event_loop () const ;
413
420
inline MultiIsolatePlatform* platform () const ;
414
421
inline std::shared_ptr<PerIsolateOptions> options ();
@@ -563,8 +570,12 @@ namespace per_process {
563
570
extern std::shared_ptr<KVStore> system_environment;
564
571
}
565
572
566
- class AsyncHooks {
573
+ class AsyncHooks : public MemoryRetainer {
567
574
public:
575
+ SET_MEMORY_INFO_NAME (AsyncHooks);
576
+ SET_SELF_SIZE (AsyncHooks);
577
+ void MemoryInfo (MemoryTracker* tracker) const override ;
578
+
568
579
// Reason for both UidFields and Fields are that one is stored as a double*
569
580
// and the other as a uint32_t*.
570
581
enum Fields {
@@ -626,7 +637,7 @@ class AsyncHooks {
626
637
friend class Environment ; // So we can call the constructor.
627
638
inline AsyncHooks ();
628
639
// Keep a list of all Persistent strings used for Provider types.
629
- v8::Eternal<v8::String> providers_[ AsyncWrap::PROVIDERS_LENGTH] ;
640
+ std::array< v8::Eternal<v8::String>, AsyncWrap::PROVIDERS_LENGTH> providers_ ;
630
641
// Stores the ids of the current execution context stack.
631
642
AliasedBuffer<double , v8::Float64Array> async_ids_stack_;
632
643
// Attached to a Uint32Array that tracks the number of active hooks for
@@ -650,7 +661,7 @@ class AsyncCallbackScope {
650
661
Environment* env_;
651
662
};
652
663
653
- class ImmediateInfo {
664
+ class ImmediateInfo : public MemoryRetainer {
654
665
public:
655
666
inline AliasedBuffer<uint32_t , v8::Uint32Array>& fields ();
656
667
inline uint32_t count () const ;
@@ -664,6 +675,10 @@ class ImmediateInfo {
664
675
ImmediateInfo (const ImmediateInfo&) = delete ;
665
676
ImmediateInfo& operator =(const ImmediateInfo&) = delete ;
666
677
678
+ SET_MEMORY_INFO_NAME (ImmediateInfo);
679
+ SET_SELF_SIZE (ImmediateInfo);
680
+ void MemoryInfo (MemoryTracker* tracker) const override ;
681
+
667
682
private:
668
683
friend class Environment ; // So we can call the constructor.
669
684
inline explicit ImmediateInfo (v8::Isolate* isolate);
@@ -673,12 +688,16 @@ class ImmediateInfo {
673
688
AliasedBuffer<uint32_t , v8::Uint32Array> fields_;
674
689
};
675
690
676
- class TickInfo {
691
+ class TickInfo : public MemoryRetainer {
677
692
public:
678
693
inline AliasedBuffer<uint8_t , v8::Uint8Array>& fields ();
679
694
inline bool has_tick_scheduled () const ;
680
695
inline bool has_rejection_to_warn () const ;
681
696
697
+ SET_MEMORY_INFO_NAME (TickInfo);
698
+ SET_SELF_SIZE (TickInfo);
699
+ void MemoryInfo (MemoryTracker* tracker) const override ;
700
+
682
701
TickInfo (const TickInfo&) = delete ;
683
702
TickInfo& operator =(const TickInfo&) = delete ;
684
703
@@ -720,11 +739,47 @@ class ShouldNotAbortOnUncaughtScope {
720
739
Environment* env_;
721
740
};
722
741
723
- class Environment {
742
+ class CleanupHookCallback {
743
+ public:
744
+ CleanupHookCallback (void (*fn)(void *),
745
+ void * arg,
746
+ uint64_t insertion_order_counter)
747
+ : fn_(fn), arg_(arg), insertion_order_counter_(insertion_order_counter) {}
748
+
749
+ // Only hashes `arg_`, since that is usually enough to identify the hook.
750
+ struct Hash {
751
+ inline size_t operator ()(const CleanupHookCallback& cb) const ;
752
+ };
753
+
754
+ // Compares by `fn_` and `arg_` being equal.
755
+ struct Equal {
756
+ inline bool operator ()(const CleanupHookCallback& a,
757
+ const CleanupHookCallback& b) const ;
758
+ };
759
+
760
+ inline BaseObject* GetBaseObject () const ;
761
+
762
+ private:
763
+ friend class Environment ;
764
+ void (*fn_)(void *);
765
+ void * arg_;
766
+
767
+ // We keep track of the insertion order for these objects, so that we can
768
+ // call the callbacks in reverse order when we are cleaning up.
769
+ uint64_t insertion_order_counter_;
770
+ };
771
+
772
+ class Environment : public MemoryRetainer {
724
773
public:
725
774
Environment (const Environment&) = delete ;
726
775
Environment& operator =(const Environment&) = delete ;
727
776
777
+ SET_MEMORY_INFO_NAME (Environment);
778
+
779
+ inline size_t SelfSize () const override ;
780
+ bool IsRootNode () const override { return true ; }
781
+ void MemoryInfo (MemoryTracker* tracker) const override ;
782
+
728
783
inline size_t async_callback_scope_depth () const ;
729
784
inline void PushAsyncCallbackScope ();
730
785
inline void PopAsyncCallbackScope ();
@@ -994,6 +1049,7 @@ class Environment {
994
1049
#define V (PropertyName, TypeName ) \
995
1050
inline v8::Local<TypeName> PropertyName () const ; \
996
1051
inline void set_ ## PropertyName(v8::Local<TypeName> value);
1052
+ ENVIRONMENT_STRONG_PERSISTENT_VALUES (V)
997
1053
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES (V)
998
1054
#undef V
999
1055
@@ -1182,28 +1238,6 @@ class Environment {
1182
1238
void RunAndClearNativeImmediates ();
1183
1239
static void CheckImmediate (uv_check_t * handle);
1184
1240
1185
- struct CleanupHookCallback {
1186
- void (*fn_)(void *);
1187
- void * arg_;
1188
-
1189
- // We keep track of the insertion order for these objects, so that we can
1190
- // call the callbacks in reverse order when we are cleaning up.
1191
- uint64_t insertion_order_counter_;
1192
-
1193
- // Only hashes `arg_`, since that is usually enough to identify the hook.
1194
- struct Hash {
1195
- inline size_t operator ()(const CleanupHookCallback& cb) const ;
1196
- };
1197
-
1198
- // Compares by `fn_` and `arg_` being equal.
1199
- struct Equal {
1200
- inline bool operator ()(const CleanupHookCallback& a,
1201
- const CleanupHookCallback& b) const ;
1202
- };
1203
-
1204
- inline BaseObject* GetBaseObject () const ;
1205
- };
1206
-
1207
1241
// Use an unordered_set, so that we have efficient insertion and removal.
1208
1242
std::unordered_set<CleanupHookCallback,
1209
1243
CleanupHookCallback::Hash,
@@ -1219,6 +1253,7 @@ class Environment {
1219
1253
void ForEachBaseObject (T&& iterator);
1220
1254
1221
1255
#define V (PropertyName, TypeName ) Persistent<TypeName> PropertyName ## _;
1256
+ ENVIRONMENT_STRONG_PERSISTENT_VALUES (V)
1222
1257
ENVIRONMENT_STRONG_PERSISTENT_PROPERTIES (V)
1223
1258
#undef V
1224
1259
};
0 commit comments