v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
stress-scavenge-observer.cc
Go to the documentation of this file.
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
6
9#include "src/heap/heap-inl.h"
10#include "src/heap/spaces.h"
11
12namespace v8 {
13namespace internal {
14
15// TODO(majeski): meaningful step_size
18 heap_(heap),
19 has_requested_gc_(false),
20 max_new_space_size_reached_(0.0) {
22
23 if (v8_flags.trace_stress_scavenge && !v8_flags.fuzzer_gc_analysis) {
24 heap_->isolate()->PrintWithTimestamp(
25 "[StressScavenge] %d%% is the new limit\n", limit_percentage_);
26 }
27}
28
29void StressScavengeObserver::Step(int bytes_allocated, Address soon_object,
30 size_t size) {
31 if (has_requested_gc_ || heap_->new_space()->Capacity() == 0) {
32 return;
33 }
34
35 double current_percent =
36 heap_->new_space()->Size() * 100.0 / heap_->new_space()->TotalCapacity();
37
38 if (v8_flags.trace_stress_scavenge) {
39 heap_->isolate()->PrintWithTimestamp(
40 "[Scavenge] %.2lf%% of the new space capacity reached\n",
41 current_percent);
42 }
43
44 if (v8_flags.fuzzer_gc_analysis) {
46 std::max(max_new_space_size_reached_, current_percent);
47 return;
48 }
49
50 if (static_cast<int>(current_percent) >= limit_percentage_) {
51 if (v8_flags.trace_stress_scavenge) {
52 heap_->isolate()->PrintWithTimestamp("[Scavenge] GC requested\n");
53 }
54
55 has_requested_gc_ = true;
56 heap_->isolate()->stack_guard()->RequestGC();
57 }
58}
59
63
65 size_t new_space_size = heap_->new_space()->Size();
66 double current_percent =
67 new_space_size
68 ? new_space_size * 100.0 / heap_->new_space()->TotalCapacity()
69 : 0;
70 limit_percentage_ = NextLimit(static_cast<int>(current_percent));
71
72 if (v8_flags.trace_stress_scavenge) {
73 heap_->isolate()->PrintWithTimestamp(
74 "[Scavenge] %.2lf%% of the new space capacity reached\n",
75 current_percent);
76 heap_->isolate()->PrintWithTimestamp("[Scavenge] %d%% is the new limit\n",
78 }
79
80 has_requested_gc_ = false;
81}
82
86
88 int max = v8_flags.stress_scavenge;
89 if (min >= max) {
90 return max;
91 }
92
93 return min + heap_->isolate()->fuzzer_rng()->NextInt(max - min + 1);
94}
95
96} // namespace internal
97} // namespace v8
V8_INLINE int NextInt() V8_WARN_UNUSED_RESULT
NewSpace * new_space() const
Definition heap.h:727
Isolate * isolate() const
Definition heap-inl.h:61
StackGuard * stack_guard()
Definition isolate.h:1198
base::RandomNumberGenerator * fuzzer_rng()
Definition isolate.cc:6330
virtual size_t Capacity() const =0
virtual size_t TotalCapacity() const =0
void Step(int bytes_allocated, Address soon_object, size_t size) override
V8_EXPORT_PRIVATE FlagValues v8_flags
Heap * heap_