@@ -770,6 +770,9 @@ Environment::Environment(IsolateData* isolate_data,
770
770
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
771
771
options_->debug_options ().host_port );
772
772
773
+ heap_snapshot_near_heap_limit_ =
774
+ static_cast <uint32_t >(options_->heap_snapshot_near_heap_limit );
775
+
773
776
if (!(flags_ & EnvironmentFlags::kOwnsProcessState )) {
774
777
set_abort_on_uncaught_exception (false );
775
778
}
@@ -884,9 +887,8 @@ Environment::~Environment() {
884
887
// FreeEnvironment() should have set this.
885
888
CHECK (is_stopping ());
886
889
887
- if (options_->heap_snapshot_near_heap_limit > heap_limit_snapshot_taken_) {
888
- isolate_->RemoveNearHeapLimitCallback (Environment::NearHeapLimitCallback,
889
- 0 );
890
+ if (heapsnapshot_near_heap_limit_callback_added_) {
891
+ RemoveHeapSnapshotNearHeapLimitCallback (0 );
890
892
}
891
893
892
894
isolate ()->GetHeapProfiler ()->RemoveBuildEmbedderGraphCallback (
@@ -2029,8 +2031,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
2029
2031
Debug (env,
2030
2032
DebugCategory::DIAGNOSTICS,
2031
2033
" Not generating snapshots because it's too risky.\n " );
2032
- env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
2033
- initial_heap_limit);
2034
+ env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
2034
2035
// The new limit must be higher than current_heap_limit or V8 might
2035
2036
// crash.
2036
2037
return current_heap_limit + 1 ;
@@ -2050,17 +2051,15 @@ size_t Environment::NearHeapLimitCallback(void* data,
2050
2051
2051
2052
// Remove the callback first in case it's triggered when generating
2052
2053
// the snapshot.
2053
- env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
2054
- initial_heap_limit);
2054
+ env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
2055
2055
2056
2056
heap::WriteSnapshot (env->isolate (), filename.c_str ());
2057
2057
env->heap_limit_snapshot_taken_ += 1 ;
2058
2058
2059
2059
// Don't take more snapshots than the number specified by
2060
2060
// --heapsnapshot-near-heap-limit.
2061
- if (env->heap_limit_snapshot_taken_ <
2062
- env->options_ ->heap_snapshot_near_heap_limit ) {
2063
- env->isolate ()->AddNearHeapLimitCallback (NearHeapLimitCallback, env);
2061
+ if (env->heap_limit_snapshot_taken_ < env->heap_snapshot_near_heap_limit_ ) {
2062
+ env->AddHeapSnapshotNearHeapLimitCallback ();
2064
2063
}
2065
2064
2066
2065
FPrintF (stderr, " Wrote snapshot to %s\n " , filename.c_str ());
0 commit comments