[test] Stress start of young generation collection.
Introduce new flag for starting young generation collection early based on the current new space size. Bug: v8:6972 Change-Id: I73dd28b8ac7df873b5c3e6ca4b3e55bdec5295a1 Reviewed-on: https://chromium-review.googlesource.com/811304 Commit-Queue: Michał Majewski <majeski@google.com> Reviewed-by: Ulan Degenbaev <ulan@chromium.org> Reviewed-by: Michael Achenbach <machenbach@chromium.org> Cr-Commit-Position: refs/heads/master@{#49927}
This commit is contained in:
parent
88fc4cb863
commit
7ff3005e22
2
BUILD.gn
2
BUILD.gn
@ -1694,6 +1694,8 @@ v8_source_set("v8_base") {
|
||||
"src/heap/store-buffer.h",
|
||||
"src/heap/stress-marking-observer.cc",
|
||||
"src/heap/stress-marking-observer.h",
|
||||
"src/heap/stress-scavenge-observer.cc",
|
||||
"src/heap/stress-scavenge-observer.h",
|
||||
"src/heap/sweeper.cc",
|
||||
"src/heap/sweeper.h",
|
||||
"src/heap/worklist.h",
|
||||
|
@ -692,6 +692,11 @@ DEFINE_BOOL(stress_incremental_marking, false,
|
||||
DEFINE_INT(stress_marking, 0,
|
||||
"force marking at random points between 0 and X (inclusive) percent "
|
||||
"of the regular marking start limit")
|
||||
DEFINE_INT(stress_scavenge, 0,
|
||||
"force scavenge at random points between 0 and X (inclusive) "
|
||||
"percent of the new space capacity")
|
||||
DEFINE_BOOL(stress_scavenge_analysis, false, "enables stress-scavenge logging.")
|
||||
|
||||
DEFINE_BOOL(manual_evacuation_candidates_selection, false,
|
||||
"Test mode only flag. It allows an unit test to select evacuation "
|
||||
"candidates pages (requires --stress_compaction).")
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include "src/heap/scavenger-inl.h"
|
||||
#include "src/heap/store-buffer.h"
|
||||
#include "src/heap/stress-marking-observer.h"
|
||||
#include "src/heap/stress-scavenge-observer.h"
|
||||
#include "src/heap/sweeper.h"
|
||||
#include "src/interpreter/interpreter.h"
|
||||
#include "src/objects/data-handler.h"
|
||||
@ -177,6 +178,7 @@ Heap::Heap()
|
||||
allocations_count_(0),
|
||||
raw_allocations_hash_(0),
|
||||
stress_marking_observer_(nullptr),
|
||||
stress_scavenge_observer_(nullptr),
|
||||
ms_count_(0),
|
||||
gc_count_(0),
|
||||
mmap_region_base_(0),
|
||||
@ -1060,7 +1062,10 @@ class GCCallbacksScope {
|
||||
|
||||
|
||||
void Heap::HandleGCRequest() {
|
||||
if (HighMemoryPressure()) {
|
||||
if (FLAG_stress_scavenge > 0 && stress_scavenge_observer_->HasRequestedGC()) {
|
||||
CollectAllGarbage(NEW_SPACE, GarbageCollectionReason::kTesting);
|
||||
stress_scavenge_observer_->RequestedGCDone();
|
||||
} else if (HighMemoryPressure()) {
|
||||
incremental_marking()->reset_request_type();
|
||||
CheckMemoryPressure();
|
||||
} else if (incremental_marking()->request_type() ==
|
||||
@ -5668,6 +5673,10 @@ bool Heap::SetUp() {
|
||||
AddAllocationObserversToAllSpaces(stress_marking_observer_,
|
||||
stress_marking_observer_);
|
||||
}
|
||||
if (FLAG_stress_scavenge_analysis || FLAG_stress_scavenge > 0) {
|
||||
stress_scavenge_observer_ = new StressScavengeObserver(*this);
|
||||
new_space()->AddAllocationObserver(stress_scavenge_observer_);
|
||||
}
|
||||
|
||||
write_protect_code_memory_ = FLAG_write_protect_code_memory;
|
||||
|
||||
@ -5783,6 +5792,11 @@ void Heap::TearDown() {
|
||||
delete stress_marking_observer_;
|
||||
stress_marking_observer_ = nullptr;
|
||||
}
|
||||
if (FLAG_stress_scavenge_analysis || FLAG_stress_scavenge > 0) {
|
||||
new_space()->RemoveAllocationObserver(stress_scavenge_observer_);
|
||||
delete stress_scavenge_observer_;
|
||||
stress_scavenge_observer_ = nullptr;
|
||||
}
|
||||
|
||||
if (mark_compact_collector_ != nullptr) {
|
||||
mark_compact_collector_->TearDown();
|
||||
|
@ -413,10 +413,11 @@ class ObjectStats;
|
||||
class Page;
|
||||
class PagedSpace;
|
||||
class RootVisitor;
|
||||
class Scavenger;
|
||||
class ScavengeJob;
|
||||
class Scavenger;
|
||||
class Space;
|
||||
class StoreBuffer;
|
||||
class StressScavengeObserver;
|
||||
class TracePossibleWrapperReporter;
|
||||
class WeakObjectRetainer;
|
||||
|
||||
@ -2418,6 +2419,9 @@ class Heap {
|
||||
// limit.
|
||||
AllocationObserver* stress_marking_observer_;
|
||||
|
||||
// Observer that can cause early scavenge start.
|
||||
StressScavengeObserver* stress_scavenge_observer_;
|
||||
|
||||
// How many mark-sweep collections happened.
|
||||
unsigned int ms_count_;
|
||||
|
||||
|
87
src/heap/stress-scavenge-observer.cc
Normal file
87
src/heap/stress-scavenge-observer.cc
Normal file
@ -0,0 +1,87 @@
|
||||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#include "src/heap/stress-scavenge-observer.h"
|
||||
|
||||
#include "src/base/utils/random-number-generator.h"
|
||||
#include "src/heap/heap-inl.h"
|
||||
#include "src/heap/spaces.h"
|
||||
#include "src/isolate.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
// TODO(majeski): meaningful step_size
|
||||
StressScavengeObserver::StressScavengeObserver(Heap& heap)
|
||||
: AllocationObserver(64), heap_(heap), has_requested_gc_(false) {
|
||||
if (FLAG_stress_scavenge > 0) {
|
||||
limit_percentage_ = NextLimit();
|
||||
|
||||
if (FLAG_stress_scavenge_analysis) {
|
||||
heap_.isolate()->PrintWithTimestamp(
|
||||
"[StressScavenge] %d%% is the new limit\n", limit_percentage_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void StressScavengeObserver::Step(int bytes_allocated, Address soon_object,
|
||||
size_t size) {
|
||||
if (has_requested_gc_ || heap_.new_space()->Capacity() == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
double current_percent =
|
||||
heap_.new_space()->Size() * 100.0 / heap_.new_space()->Capacity();
|
||||
|
||||
if (FLAG_stress_scavenge_analysis) {
|
||||
heap_.isolate()->PrintWithTimestamp(
|
||||
"[StressScavenge] %.2lf%% of the new space capacity reached\n",
|
||||
current_percent);
|
||||
}
|
||||
|
||||
if (!FLAG_stress_scavenge) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (static_cast<int>(current_percent) >= limit_percentage_) {
|
||||
if (FLAG_stress_scavenge_analysis) {
|
||||
heap_.isolate()->PrintWithTimestamp("[StressScavenge] GC requested\n");
|
||||
}
|
||||
|
||||
has_requested_gc_ = true;
|
||||
heap_.isolate()->stack_guard()->RequestGC();
|
||||
}
|
||||
}
|
||||
|
||||
bool StressScavengeObserver::HasRequestedGC() const {
|
||||
return has_requested_gc_;
|
||||
}
|
||||
|
||||
void StressScavengeObserver::RequestedGCDone() {
|
||||
double current_percent =
|
||||
heap_.new_space()->Size() * 100.0 / heap_.new_space()->Capacity();
|
||||
limit_percentage_ = NextLimit(static_cast<int>(current_percent));
|
||||
|
||||
if (FLAG_stress_scavenge_analysis) {
|
||||
heap_.isolate()->PrintWithTimestamp(
|
||||
"[StressScavenge] %.2lf%% of the new space capacity reached\n",
|
||||
current_percent);
|
||||
heap_.isolate()->PrintWithTimestamp(
|
||||
"[StressScavenge] %d%% is the new limit\n", limit_percentage_);
|
||||
}
|
||||
|
||||
has_requested_gc_ = false;
|
||||
}
|
||||
|
||||
int StressScavengeObserver::NextLimit(int min) {
|
||||
int max = FLAG_stress_scavenge;
|
||||
if (min >= max) {
|
||||
return max;
|
||||
}
|
||||
|
||||
return min + heap_.isolate()->fuzzer_rng()->NextInt(max - min + 1);
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
33
src/heap/stress-scavenge-observer.h
Normal file
33
src/heap/stress-scavenge-observer.h
Normal file
@ -0,0 +1,33 @@
|
||||
// Copyright 2017 the V8 project authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
#ifndef V8_HEAP_STRESS_SCAVENGE_OBSERVER_H_
|
||||
#define V8_HEAP_STRESS_SCAVENGE_OBSERVER_H_
|
||||
|
||||
#include "src/heap/heap.h"
|
||||
|
||||
namespace v8 {
|
||||
namespace internal {
|
||||
|
||||
class StressScavengeObserver : public AllocationObserver {
|
||||
public:
|
||||
explicit StressScavengeObserver(Heap& heap);
|
||||
|
||||
void Step(int bytes_allocated, Address soon_object, size_t size) override;
|
||||
|
||||
bool HasRequestedGC() const;
|
||||
void RequestedGCDone();
|
||||
|
||||
private:
|
||||
Heap& heap_;
|
||||
int limit_percentage_;
|
||||
bool has_requested_gc_;
|
||||
|
||||
int NextLimit(int min = 0);
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
} // namespace v8
|
||||
|
||||
#endif
|
@ -1046,6 +1046,8 @@
|
||||
'heap/store-buffer.h',
|
||||
'heap/stress-marking-observer.cc',
|
||||
'heap/stress-marking-observer.h',
|
||||
'heap/stress-scavenge-observer.cc',
|
||||
'heap/stress-scavenge-observer.h',
|
||||
'heap/sweeper.cc',
|
||||
'heap/sweeper.h',
|
||||
'heap/worklist.h',
|
||||
|
Loading…
Reference in New Issue
Block a user