@@ -1962,7 +1962,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
1962
1962
" Invoked NearHeapLimitCallback, processing=%d, "
1963
1963
" current_limit=%" PRIu64 " , "
1964
1964
" initial_limit=%" PRIu64 " \n " ,
1965
- env->is_processing_heap_limit_callback_ ,
1965
+ env->is_in_heapsnapshot_heap_limit_callback_ ,
1966
1966
static_cast <uint64_t >(current_heap_limit),
1967
1967
static_cast <uint64_t >(initial_heap_limit));
1968
1968
@@ -2014,8 +2014,8 @@ size_t Environment::NearHeapLimitCallback(void* data,
2014
2014
// new limit, so in a heap with unbounded growth the isolate
2015
2015
// may eventually crash with this new limit - effectively raising
2016
2016
// the heap limit to the new one.
2017
- if (env-> is_processing_heap_limit_callback_ ) {
2018
- size_t new_limit = current_heap_limit + max_young_gen_size;
2017
+ size_t new_limit = current_heap_limit + max_young_gen_size;
2018
+ if (env-> is_in_heapsnapshot_heap_limit_callback_ ) {
2019
2019
Debug (env,
2020
2020
DebugCategory::DIAGNOSTICS,
2021
2021
" Not generating snapshots in nested callback. "
@@ -2031,14 +2031,14 @@ size_t Environment::NearHeapLimitCallback(void* data,
2031
2031
Debug (env,
2032
2032
DebugCategory::DIAGNOSTICS,
2033
2033
" Not generating snapshots because it's too risky.\n " );
2034
- env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit );
2034
+ env->RemoveHeapSnapshotNearHeapLimitCallback (0 );
2035
2035
// The new limit must be higher than current_heap_limit or V8 might
2036
2036
// crash.
2037
- return current_heap_limit + 1 ;
2037
+ return new_limit ;
2038
2038
}
2039
2039
2040
2040
// Take the snapshot synchronously.
2041
- env->is_processing_heap_limit_callback_ = true ;
2041
+ env->is_in_heapsnapshot_heap_limit_callback_ = true ;
2042
2042
2043
2043
std::string dir = env->options ()->diagnostic_dir ;
2044
2044
if (dir.empty ()) {
@@ -2049,29 +2049,33 @@ size_t Environment::NearHeapLimitCallback(void* data,
2049
2049
2050
2050
Debug (env, DebugCategory::DIAGNOSTICS, " Start generating %s...\n " , *name);
2051
2051
2052
- // Remove the callback first in case it's triggered when generating
2053
- // the snapshot.
2054
- env->RemoveHeapSnapshotNearHeapLimitCallback (initial_heap_limit);
2055
-
2056
2052
heap::WriteSnapshot (env->isolate (), filename.c_str ());
2057
2053
env->heap_limit_snapshot_taken_ += 1 ;
2058
2054
2059
- // Don't take more snapshots than the number specified by
2060
- // --heapsnapshot-near-heap-limit.
2061
- if (env->heap_limit_snapshot_taken_ < env->heap_snapshot_near_heap_limit_ ) {
2062
- env->AddHeapSnapshotNearHeapLimitCallback ();
2055
+ Debug (env,
2056
+ DebugCategory::DIAGNOSTICS,
2057
+ " %" PRIu32 " /%" PRIu32 " snapshots taken.\n " ,
2058
+ env->heap_limit_snapshot_taken_ ,
2059
+ env->heap_snapshot_near_heap_limit_ );
2060
+
2061
+ // Don't take more snapshots than the limit specified.
2062
+ if (env->heap_limit_snapshot_taken_ == env->heap_snapshot_near_heap_limit_ ) {
2063
+ Debug (env,
2064
+ DebugCategory::DIAGNOSTICS,
2065
+ " Removing the near heap limit callback" );
2066
+ env->RemoveHeapSnapshotNearHeapLimitCallback (0 );
2063
2067
}
2064
2068
2065
2069
FPrintF (stderr, " Wrote snapshot to %s\n " , filename.c_str ());
2066
2070
// Tell V8 to reset the heap limit once the heap usage falls down to
2067
2071
// 95% of the initial limit.
2068
2072
env->isolate ()->AutomaticallyRestoreInitialHeapLimit (0.95 );
2069
2073
2070
- env->is_processing_heap_limit_callback_ = false ;
2074
+ env->is_in_heapsnapshot_heap_limit_callback_ = false ;
2071
2075
2072
2076
// The new limit must be higher than current_heap_limit or V8 might
2073
2077
// crash.
2074
- return current_heap_limit + 1 ;
2078
+ return new_limit ;
2075
2079
}
2076
2080
2077
2081
inline size_t Environment::SelfSize () const {
0 commit comments