@@ -720,6 +720,8 @@ Environment::Environment(IsolateData* isolate_data,
720720 inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
721721 options_->debug_options ().host_port );
722722
723+ set_heap_snapshot_near_heap_limit (options_->heap_snapshot_near_heap_limit );
724+
723725 if (!(flags_ & EnvironmentFlags::kOwnsProcessState )) {
724726 set_abort_on_uncaught_exception (false );
725727 }
@@ -834,7 +836,8 @@ Environment::~Environment() {
834836 // FreeEnvironment() should have set this.
835837 CHECK (is_stopping ());
836838
837- if (options_->heap_snapshot_near_heap_limit > heap_limit_snapshot_taken_) {
839+ if (near_heap_callback_is_added ()) {
840+ set_near_heap_callback_is_added (false );
838841 isolate_->RemoveNearHeapLimitCallback (Environment::NearHeapLimitCallback,
839842 0 );
840843 }
@@ -1952,6 +1955,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
19521955 Debug (env,
19531956 DebugCategory::DIAGNOSTICS,
19541957 " Not generating snapshots because it's too risky.\n " );
1958+ env->set_near_heap_callback_is_added (false );
19551959 env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
19561960 initial_heap_limit);
19571961 // The new limit must be higher than current_heap_limit or V8 might
@@ -1973,16 +1977,17 @@ size_t Environment::NearHeapLimitCallback(void* data,
19731977
19741978 // Remove the callback first in case it's triggered when generating
19751979 // the snapshot.
1980+ env->set_near_heap_callback_is_added (false );
19761981 env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
19771982 initial_heap_limit);
19781983
19791984 heap::WriteSnapshot (env, filename.c_str ());
1980- env->heap_limit_snapshot_taken_ += 1 ;
1985+ env->set_heap_limit_snapshot_taken (env-> heap_limit_snapshot_taken () + 1 ) ;
19811986
19821987 // Don't take more snapshots than the number specified by
19831988 // --heapsnapshot-near-heap-limit.
1984- if (env->heap_limit_snapshot_taken_ <
1985- env->options_ -> heap_snapshot_near_heap_limit ) {
1989+ if (env->heap_limit_snapshot_taken () < env-> heap_snapshot_near_heap_limit ()) {
1990+ env->set_near_heap_callback_is_added ( true );
19861991 env->isolate ()->AddNearHeapLimitCallback (NearHeapLimitCallback, env);
19871992 }
19881993
0 commit comments