@@ -704,6 +704,9 @@ Environment::Environment(IsolateData* isolate_data,
704704 inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
705705 options_->debug_options ().host_port );
706706
707+ heap_snapshot_near_heap_limit_ =
708+ static_cast <uint32_t >(options_->heap_snapshot_near_heap_limit );
709+
707710 if (!(flags_ & EnvironmentFlags::kOwnsProcessState )) {
708711 set_abort_on_uncaught_exception (false );
709712 }
@@ -818,9 +821,8 @@ Environment::~Environment() {
818821 // FreeEnvironment() should have set this.
819822 CHECK (is_stopping ());
820823
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 );
824826 }
825827
826828 isolate ()->GetHeapProfiler ()->RemoveBuildEmbedderGraphCallback (
@@ -1905,8 +1907,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
19051907 Debug (env,
19061908 DebugCategory::DIAGNOSTICS,
19071909 " Not generating snapshots because it's too risky.\n " );
1908- env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1909- initial_heap_limit);
1910+ env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
19101911 // The new limit must be higher than current_heap_limit or V8 might
19111912 // crash.
19121913 return current_heap_limit + 1 ;
@@ -1926,17 +1927,15 @@ size_t Environment::NearHeapLimitCallback(void* data,
19261927
19271928 // Remove the callback first in case it's triggered when generating
19281929 // the snapshot.
1929- env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1930- initial_heap_limit);
1930+ env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
19311931
19321932 heap::WriteSnapshot (env, filename.c_str ());
19331933 env->heap_limit_snapshot_taken_ += 1 ;
19341934
19351935 // Don't take more snapshots than the number specified by
19361936 // --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 ();
19401939 }
19411940
19421941 FPrintF (stderr, " Wrote snapshot to %s\n " , filename.c_str ());
0 commit comments