@@ -720,6 +720,8 @@ Environment::Environment(IsolateData* isolate_data,
720
720
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
721
721
options_->debug_options ().host_port );
722
722
723
+ set_heap_snapshot_near_heap_limit (options_->heap_snapshot_near_heap_limit );
724
+
723
725
if (!(flags_ & EnvironmentFlags::kOwnsProcessState )) {
724
726
set_abort_on_uncaught_exception (false );
725
727
}
@@ -834,7 +836,8 @@ Environment::~Environment() {
834
836
// FreeEnvironment() should have set this.
835
837
CHECK (is_stopping ());
836
838
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 );
838
841
isolate_->RemoveNearHeapLimitCallback (Environment::NearHeapLimitCallback,
839
842
0 );
840
843
}
@@ -1952,6 +1955,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
1952
1955
Debug (env,
1953
1956
DebugCategory::DIAGNOSTICS,
1954
1957
" Not generating snapshots because it's too risky.\n " );
1958
+ env->set_near_heap_callback_is_added (false );
1955
1959
env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1956
1960
initial_heap_limit);
1957
1961
// The new limit must be higher than current_heap_limit or V8 might
@@ -1973,16 +1977,17 @@ size_t Environment::NearHeapLimitCallback(void* data,
1973
1977
1974
1978
// Remove the callback first in case it's triggered when generating
1975
1979
// the snapshot.
1980
+ env->set_near_heap_callback_is_added (false );
1976
1981
env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1977
1982
initial_heap_limit);
1978
1983
1979
1984
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 ) ;
1981
1986
1982
1987
// Don't take more snapshots than the number specified by
1983
1988
// --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 );
1986
1991
env->isolate ()->AddNearHeapLimitCallback (NearHeapLimitCallback, env);
1987
1992
}
1988
1993
0 commit comments