@@ -682,6 +682,9 @@ Environment::Environment(IsolateData* isolate_data,
682
682
inspector_host_port_ = std::make_shared<ExclusiveAccess<HostPort>>(
683
683
options_->debug_options ().host_port );
684
684
685
+ heap_snapshot_near_heap_limit_ =
686
+ static_cast <uint32_t >(options_->heap_snapshot_near_heap_limit );
687
+
685
688
if (!(flags_ & EnvironmentFlags::kOwnsProcessState )) {
686
689
set_abort_on_uncaught_exception (false );
687
690
}
@@ -797,9 +800,8 @@ Environment::~Environment() {
797
800
// FreeEnvironment() should have set this.
798
801
CHECK (is_stopping ());
799
802
800
- if (options_->heap_snapshot_near_heap_limit > heap_limit_snapshot_taken_) {
801
- isolate_->RemoveNearHeapLimitCallback (Environment::NearHeapLimitCallback,
802
- 0 );
803
+ if (heapsnapshot_near_heap_limit_callback_added_) {
804
+ RemoveHeapSnapshotNearHeapLimitCallback (0 );
803
805
}
804
806
805
807
isolate ()->GetHeapProfiler ()->RemoveBuildEmbedderGraphCallback (
@@ -1788,8 +1790,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
1788
1790
Debug (env,
1789
1791
DebugCategory::DIAGNOSTICS,
1790
1792
" Not generating snapshots because it's too risky.\n " );
1791
- env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1792
- initial_heap_limit);
1793
+ env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
1793
1794
// The new limit must be higher than current_heap_limit or V8 might
1794
1795
// crash.
1795
1796
return current_heap_limit + 1 ;
@@ -1809,17 +1810,15 @@ size_t Environment::NearHeapLimitCallback(void* data,
1809
1810
1810
1811
// Remove the callback first in case it's triggered when generating
1811
1812
// the snapshot.
1812
- env->isolate ()->RemoveNearHeapLimitCallback (NearHeapLimitCallback,
1813
- initial_heap_limit);
1813
+ env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
1814
1814
1815
1815
heap::WriteSnapshot (env, filename.c_str ());
1816
1816
env->heap_limit_snapshot_taken_ += 1 ;
1817
1817
1818
1818
// Don't take more snapshots than the number specified by
1819
1819
// --heapsnapshot-near-heap-limit.
1820
- if (env->heap_limit_snapshot_taken_ <
1821
- env->options_ ->heap_snapshot_near_heap_limit ) {
1822
- env->isolate ()->AddNearHeapLimitCallback (NearHeapLimitCallback, env);
1820
+ if (env->heap_limit_snapshot_taken_ < env->heap_snapshot_near_heap_limit_ ) {
1821
+ env->AddHeapSnapshotNearHeapLimitCallback ();
1823
1822
}
1824
1823
1825
1824
FPrintF (stderr, " Wrote snapshot to %s\n " , filename.c_str ());
0 commit comments