@@ -704,6 +704,9 @@ Environment::Environment(IsolateData* isolate_data,
704
704
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
705
705
options_->debug_options ().host_port );
706
706
707
+ heap_snapshot_near_heap_limit_ =
708
+ static_cast <uint32_t >(options_->heap_snapshot_near_heap_limit );
709
+
707
710
if (!(flags_ & EnvironmentFlags::kOwnsProcessState )) {
708
711
set_abort_on_uncaught_exception (false );
709
712
}
@@ -818,9 +821,8 @@ Environment::~Environment() {
818
821
// FreeEnvironment() should have set this.
819
822
CHECK (is_stopping ());
820
823
821
- if (options_->heap_snapshot_near_heap_limit > heap_limit_snapshot_taken_) {
822
- isolate_->RemoveNearHeapLimitCallback (Environment::NearHeapLimitCallback,
823
- 0 );
824
+ if (heapsnapshot_near_heap_limit_callback_added_) {
825
+ RemoveHeapSnapshotNearHeapLimitCallback (0 );
824
826
}
825
827
826
828
isolate ()->GetHeapProfiler ()->RemoveBuildEmbedderGraphCallback (
@@ -1905,8 +1907,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
1905
1907
Debug (env,
1906
1908
DebugCategory::DIAGNOSTICS,
1907
1909
" Not generating snapshots because it's too risky.\n " );
1908
- env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1909
- initial_heap_limit);
1910
+ env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
1910
1911
// The new limit must be higher than current_heap_limit or V8 might
1911
1912
// crash.
1912
1913
return current_heap_limit + 1 ;
@@ -1926,17 +1927,15 @@ size_t Environment::NearHeapLimitCallback(void* data,
1926
1927
1927
1928
// Remove the callback first in case it's triggered when generating
1928
1929
// the snapshot.
1929
- env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1930
- initial_heap_limit);
1930
+ env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
1931
1931
1932
1932
heap::WriteSnapshot (env, filename.c_str ());
1933
1933
env->heap_limit_snapshot_taken_ += 1 ;
1934
1934
1935
1935
// Don't take more snapshots than the number specified by
1936
1936
// --heapsnapshot-near-heap-limit.
1937
- if (env->heap_limit_snapshot_taken_ <
1938
- env->options_ ->heap_snapshot_near_heap_limit ) {
1939
- env->isolate ()->AddNearHeapLimitCallback (NearHeapLimitCallback, env);
1937
+ if (env->heap_limit_snapshot_taken_ < env->heap_snapshot_near_heap_limit_ ) {
1938
+ env->AddHeapSnapshotNearHeapLimitCallback ();
1940
1939
}
1941
1940
1942
1941
FPrintF (stderr, " Wrote snapshot to %s\n " , filename.c_str ());
0 commit comments