LCOV - code coverage report
Current view: top level - src/heap - stress-scavenge-observer.cc (source / functions) Hit Total Coverage
Test: app.info Lines: 1 37 2.7 %
Date: 2019-02-19 Functions: 2 8 25.0 %

          Line data    Source code
       1             : // Copyright 2017 the V8 project authors. All rights reserved.
       2             : // Use of this source code is governed by a BSD-style license that can be
       3             : // found in the LICENSE file.
       4             : 
       5             : #include "src/heap/stress-scavenge-observer.h"
       6             : 
       7             : #include "src/base/utils/random-number-generator.h"
       8             : #include "src/heap/heap-inl.h"
       9             : #include "src/heap/spaces.h"
      10             : #include "src/isolate.h"
      11             : 
      12             : namespace v8 {
      13             : namespace internal {
      14             : 
      15             : // TODO(majeski): meaningful step_size
      16           0 : StressScavengeObserver::StressScavengeObserver(Heap& heap)
      17             :     : AllocationObserver(64),
      18             :       heap_(heap),
      19             :       has_requested_gc_(false),
      20           0 :       max_new_space_size_reached_(0.0) {
      21           0 :   limit_percentage_ = NextLimit();
      22             : 
      23           0 :   if (FLAG_trace_stress_scavenge && !FLAG_fuzzer_gc_analysis) {
      24             :     heap_.isolate()->PrintWithTimestamp(
      25           0 :         "[StressScavenge] %d%% is the new limit\n", limit_percentage_);
      26             :   }
      27           0 : }
      28             : 
      29           0 : void StressScavengeObserver::Step(int bytes_allocated, Address soon_object,
      30             :                                   size_t size) {
      31           0 :   if (has_requested_gc_ || heap_.new_space()->Capacity() == 0) {
      32           0 :     return;
      33             :   }
      34             : 
      35             :   double current_percent =
      36           0 :       heap_.new_space()->Size() * 100.0 / heap_.new_space()->Capacity();
      37             : 
      38           0 :   if (FLAG_trace_stress_scavenge) {
      39             :     heap_.isolate()->PrintWithTimestamp(
      40             :         "[Scavenge] %.2lf%% of the new space capacity reached\n",
      41           0 :         current_percent);
      42             :   }
      43             : 
      44           0 :   if (FLAG_fuzzer_gc_analysis) {
      45             :     max_new_space_size_reached_ =
      46           0 :         std::max(max_new_space_size_reached_, current_percent);
      47           0 :     return;
      48             :   }
      49             : 
      50           0 :   if (static_cast<int>(current_percent) >= limit_percentage_) {
      51           0 :     if (FLAG_trace_stress_scavenge) {
      52           0 :       heap_.isolate()->PrintWithTimestamp("[Scavenge] GC requested\n");
      53             :     }
      54             : 
      55           0 :     has_requested_gc_ = true;
      56           0 :     heap_.isolate()->stack_guard()->RequestGC();
      57             :   }
      58             : }
      59             : 
      60           0 : bool StressScavengeObserver::HasRequestedGC() const {
      61           0 :   return has_requested_gc_;
      62             : }
      63             : 
      64           0 : void StressScavengeObserver::RequestedGCDone() {
      65             :   double current_percent =
      66           0 :       heap_.new_space()->Size() * 100.0 / heap_.new_space()->Capacity();
      67           0 :   limit_percentage_ = NextLimit(static_cast<int>(current_percent));
      68             : 
      69           0 :   if (FLAG_trace_stress_scavenge) {
      70             :     heap_.isolate()->PrintWithTimestamp(
      71             :         "[Scavenge] %.2lf%% of the new space capacity reached\n",
      72           0 :         current_percent);
      73             :     heap_.isolate()->PrintWithTimestamp("[Scavenge] %d%% is the new limit\n",
      74           0 :                                         limit_percentage_);
      75             :   }
      76             : 
      77           0 :   has_requested_gc_ = false;
      78           0 : }
      79             : 
      80           0 : double StressScavengeObserver::MaxNewSpaceSizeReached() const {
      81           0 :   return max_new_space_size_reached_;
      82             : }
      83             : 
      84           0 : int StressScavengeObserver::NextLimit(int min) {
      85           0 :   int max = FLAG_stress_scavenge;
      86           0 :   if (min >= max) {
      87             :     return max;
      88             :   }
      89             : 
      90           0 :   return min + heap_.isolate()->fuzzer_rng()->NextInt(max - min + 1);
      91             : }
      92             : 
      93             : }  // namespace internal
      94      178779 : }  // namespace v8

Generated by: LCOV version 1.10