@@ -720,6 +720,9 @@ Environment::Environment(IsolateData* isolate_data,
720720 inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
721721 options_->debug_options ().host_port );
722722
723+ heap_snapshot_near_heap_limit_ = static_cast <uint32_t >(
724+ options_->heap_snapshot_near_heap_limit );
725+
723726 if (!(flags_ & EnvironmentFlags::kOwnsProcessState )) {
724727 set_abort_on_uncaught_exception (false );
725728 }
@@ -834,9 +837,8 @@ Environment::~Environment() {
834837 // FreeEnvironment() should have set this.
835838 CHECK (is_stopping ());
836839
837- if (options_->heap_snapshot_near_heap_limit > heap_limit_snapshot_taken_) {
838- isolate_->RemoveNearHeapLimitCallback (Environment::NearHeapLimitCallback,
839- 0 );
840+ if (heapsnapshot_near_heap_limit_callback_added_) {
841+ remove_heapsnapshot_near_heap_limit_callback (0 );
840842 }
841843
842844 isolate ()->GetHeapProfiler ()->RemoveBuildEmbedderGraphCallback (
@@ -1952,8 +1954,8 @@ size_t Environment::NearHeapLimitCallback(void* data,
19521954 Debug (env,
19531955 DebugCategory::DIAGNOSTICS,
19541956 " Not generating snapshots because it's too risky.\n " );
1955- env->isolate ()-> RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1956- initial_heap_limit);
1957+ env->remove_heapsnapshot_near_heap_limit_callback (
1958+ initial_heap_limit);
19571959 // The new limit must be higher than current_heap_limit or V8 might
19581960 // crash.
19591961 return current_heap_limit + 1 ;
@@ -1973,17 +1975,16 @@ size_t Environment::NearHeapLimitCallback(void* data,
19731975
19741976 // Remove the callback first in case it's triggered when generating
19751977 // the snapshot.
1976- env->isolate ()-> RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1977- initial_heap_limit);
1978+ env->remove_heapsnapshot_near_heap_limit_callback (
1979+ initial_heap_limit);
19781980
19791981 heap::WriteSnapshot (env, filename.c_str ());
19801982 env->heap_limit_snapshot_taken_ += 1 ;
19811983
19821984 // Don't take more snapshots than the number specified by
19831985 // --heapsnapshot-near-heap-limit.
1984- if (env->heap_limit_snapshot_taken_ <
1985- env->options_ ->heap_snapshot_near_heap_limit ) {
1986- env->isolate ()->AddNearHeapLimitCallback (NearHeapLimitCallback, env);
1986+ if (env->heap_limit_snapshot_taken_ < env->heap_snapshot_near_heap_limit_ ) {
1987+ env->add_heapsnapshot_near_heap_limit_callback ();
19871988 }
19881989
19891990 FPrintF (stderr, " Wrote snapshot to %s\n " , filename.c_str ());
0 commit comments