5 #include "src/heap/stress-scavenge-observer.h" 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" 16 StressScavengeObserver::StressScavengeObserver(Heap& heap)
17 : AllocationObserver(64),
19 has_requested_gc_(false),
20 max_new_space_size_reached_(0.0) {
21 limit_percentage_ = NextLimit();
23 if (FLAG_trace_stress_scavenge && !FLAG_fuzzer_gc_analysis) {
24 heap_.isolate()->PrintWithTimestamp(
25 "[StressScavenge] %d%% is the new limit\n", limit_percentage_);
29 void StressScavengeObserver::Step(
int bytes_allocated, Address soon_object,
31 if (has_requested_gc_ || heap_.new_space()->Capacity() == 0) {
35 double current_percent =
36 heap_.new_space()->Size() * 100.0 / heap_.new_space()->Capacity();
38 if (FLAG_trace_stress_scavenge) {
39 heap_.isolate()->PrintWithTimestamp(
40 "[Scavenge] %.2lf%% of the new space capacity reached\n",
44 if (FLAG_fuzzer_gc_analysis) {
45 max_new_space_size_reached_ =
46 std::max(max_new_space_size_reached_, current_percent);
50 if (static_cast<int>(current_percent) >= limit_percentage_) {
51 if (FLAG_trace_stress_scavenge) {
52 heap_.isolate()->PrintWithTimestamp(
"[Scavenge] GC requested\n");
55 has_requested_gc_ =
true;
56 heap_.isolate()->stack_guard()->RequestGC();
60 bool StressScavengeObserver::HasRequestedGC()
const {
61 return has_requested_gc_;
64 void StressScavengeObserver::RequestedGCDone() {
65 double current_percent =
66 heap_.new_space()->Size() * 100.0 / heap_.new_space()->Capacity();
67 limit_percentage_ = NextLimit(static_cast<int>(current_percent));
69 if (FLAG_trace_stress_scavenge) {
70 heap_.isolate()->PrintWithTimestamp(
71 "[Scavenge] %.2lf%% of the new space capacity reached\n",
73 heap_.isolate()->PrintWithTimestamp(
"[Scavenge] %d%% is the new limit\n",
77 has_requested_gc_ =
false;
80 double StressScavengeObserver::MaxNewSpaceSizeReached()
const {
81 return max_new_space_size_reached_;
84 int StressScavengeObserver::NextLimit(
int min) {
85 int max = FLAG_stress_scavenge;
90 return min + heap_.isolate()->fuzzer_rng()->NextInt(max - min + 1);