Reviewers: Hannes Payer,
Description:
Add a flag to over approximate the weak closure during GC
BUG=v8:3862
[email protected]
LOG=n
Please review this at https://codereview.chromium.org/894703002/
Base URL: https://chromium.googlesource.com/v8/v8.git@master
Affected files (+93, -3 lines):
M src/execution.cc
M src/flag-definitions.h
M src/heap/gc-tracer.h
M src/heap/gc-tracer.cc
M src/heap/heap.h
M src/heap/heap.cc
M src/heap/incremental-marking.h
M src/heap/incremental-marking.cc
M src/heap/mark-compact.h
M src/heap/mark-compact.cc
Index: src/execution.cc
diff --git a/src/execution.cc b/src/execution.cc
index
9f418ac5d843e0a1f300974313e5c404e28d58fb..af25b6ccd1596d0463ec4b21a492547f7698b6e1
100644
--- a/src/execution.cc
+++ b/src/execution.cc
@@ -719,7 +719,7 @@ Handle<String>
Execution::GetStackTraceLine(Handle<Object> recv,
Object* StackGuard::HandleInterrupts() {
if (CheckAndClearInterrupt(GC_REQUEST)) {
- isolate_->heap()->CollectAllGarbage(Heap::kNoGCFlags, "GC interrupt");
+ isolate_->heap()->HandleGCRequest();
}
if (CheckDebugBreak() || CheckDebugCommand()) {
Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index
5ccd47fbc7a7c87b320673102218863d33abf035..3057cde55a4ef90e9f6daa38a8d73e816e8b3386
100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -607,6 +607,8 @@ DEFINE_BOOL(age_code, true,
"old code (required for code flushing)")
DEFINE_BOOL(incremental_marking, true, "use incremental marking")
DEFINE_BOOL(incremental_marking_steps, true, "do incremental marking
steps")
+DEFINE_BOOL(overapproximate_weak_closure, false,
+ "overapproximate weak closer to reduce atomic pause time")
DEFINE_BOOL(concurrent_sweeping, true, "use concurrent sweeping")
DEFINE_BOOL(trace_incremental_marking, false,
"trace progress of the incremental marking")
Index: src/heap/gc-tracer.cc
diff --git a/src/heap/gc-tracer.cc b/src/heap/gc-tracer.cc
index
d46ed239c99ce5e9cc3f56d253be10f0fb157ffe..6843e211c472735d70d030a802dd9ab5a6adc7eb
100644
--- a/src/heap/gc-tracer.cc
+++ b/src/heap/gc-tracer.cc
@@ -350,6 +350,8 @@ void GCTracer::PrintNVP() const {
PrintF("misc_compaction=%.1f ",
current_.scopes[Scope::MC_UPDATE_MISC_POINTERS]);
PrintF("weak_closure=%.1f ", current_.scopes[Scope::MC_WEAKCLOSURE]);
+ PrintF("inc_weak_closure=%.1f ",
+ current_.scopes[Scope::MC_INCREMENTAL_WEAKCLOSURE]);
PrintF("weakcollection_process=%.1f ",
current_.scopes[Scope::MC_WEAKCOLLECTION_PROCESS]);
PrintF("weakcollection_clear=%.1f ",
Index: src/heap/gc-tracer.h
diff --git a/src/heap/gc-tracer.h b/src/heap/gc-tracer.h
index
07c175935d4fa27a2d325d61cf57e053894e7657..dc8105e7d4cc019eeb747b9fb8b29cf659bad19d
100644
--- a/src/heap/gc-tracer.h
+++ b/src/heap/gc-tracer.h
@@ -108,6 +108,7 @@ class GCTracer {
MC_UPDATE_POINTERS_TO_EVACUATED,
MC_UPDATE_POINTERS_BETWEEN_EVACUATED,
MC_UPDATE_MISC_POINTERS,
+ MC_INCREMENTAL_WEAKCLOSURE,
MC_WEAKCLOSURE,
MC_WEAKCOLLECTION_PROCESS,
MC_WEAKCOLLECTION_CLEAR,
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index
cec871403a718d8f2a88b8666af713e48ba56f54..16c6c5ad0e2b811d48d9c2dcc666f8081792626c
100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -735,6 +735,48 @@ void Heap::GarbageCollectionEpilogue() {
}
+void Heap::HandleGCRequest() {
+ if (incremental_marking()->IsComplete()) {
+ CollectAllGarbage(Heap::kNoGCFlags, "GC interrupt");
+ return;
+ }
+ DCHECK(FLAG_overapproximate_weak_closure);
+ DCHECK(!incremental_marking()->weak_closure_was_overapproximated());
+ OverApproximateWeakClosure("GC interrupt");
+}
+
+
+void Heap::OverApproximateWeakClosure(const char* gc_reason) {
+ if (FLAG_trace_incremental_marking) {
+ PrintF("[IncrementalMarking] Overapproximate weak closure (%s).\n",
+ gc_reason);
+ }
+ {
+ GCCallbacksScope scope(this);
+ if (scope.CheckReenter()) {
+ AllowHeapAllocation allow_allocation;
+ GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL);
+ VMState<EXTERNAL> state(isolate_);
+ HandleScope handle_scope(isolate_);
+ CallGCPrologueCallbacks(kGCTypeMarkSweepCompact, kNoGCCallbackFlags);
+ }
+ }
+ mark_compact_collector()->OverApproximateWeakClosure();
+ incremental_marking()->set_should_hurry(false);
+ incremental_marking()->set_weak_closure_was_overapproximated(true);
+ {
+ GCCallbacksScope scope(this);
+ if (scope.CheckReenter()) {
+ AllowHeapAllocation allow_allocation;
+ GCTracer::Scope scope(tracer(), GCTracer::Scope::EXTERNAL);
+ VMState<EXTERNAL> state(isolate_);
+ HandleScope handle_scope(isolate_);
+ CallGCEpilogueCallbacks(kGCTypeMarkSweepCompact, kNoGCCallbackFlags);
+ }
+ }
+}
+
+
void Heap::CollectAllGarbage(int flags, const char* gc_reason,
const v8::GCCallbackFlags gc_callback_flags) {
// Since we are ignoring the return value, the exact choice of space does
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index
ceae148bbc1862e51a5133356ecc4ed7f3db2b73..1d172bbac9e7aa337a835d82bd5ca0084fa45e9d
100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -754,6 +754,11 @@ class Heap {
// Making the heap iterable requires us to abort incremental marking.
static const int kMakeHeapIterableMask = kAbortIncrementalMarkingMask;
+ // Invoked when GC was requested via the stack guard.
+ void HandleGCRequest();
+
+ void OverApproximateWeakClosure(const char* gc_reason);
+
// Performs a full garbage collection. If (flags &
kMakeHeapIterableMask) is
// non-zero, then the slower precise sweeper is used, which leaves the
heap
// in a state where we can iterate over the heap visiting all objects.
Index: src/heap/incremental-marking.cc
diff --git a/src/heap/incremental-marking.cc
b/src/heap/incremental-marking.cc
index
a85d4a8489326ec84afcd2ca4191d45ebdda18fe..abca37ee408aa8d105c22c32e2f464ecc13b15ec
100644
--- a/src/heap/incremental-marking.cc
+++ b/src/heap/incremental-marking.cc
@@ -28,7 +28,8 @@ IncrementalMarking::IncrementalMarking(Heap* heap)
idle_marking_delay_counter_(0),
no_marking_scope_depth_(0),
unscanned_bytes_of_large_object_(0),
- was_activated_(false) {}
+ was_activated_(false),
+ weak_closure_was_overapproximated_(false) {}
void IncrementalMarking::RecordWriteSlow(HeapObject* obj, Object** slot,
@@ -495,6 +496,7 @@ void IncrementalMarking::Start(CompactionFlag flag) {
ResetStepCounters();
was_activated_ = true;
+ weak_closure_was_overapproximated_ = false;
if (!heap_->mark_compact_collector()->sweeping_in_progress()) {
StartMarking(flag);
@@ -772,13 +774,22 @@ void IncrementalMarking::Finalize() {
void IncrementalMarking::MarkingComplete(CompletionAction action) {
- state_ = COMPLETE;
// We will set the stack guard to request a GC now. This will mean the
rest
// of the GC gets performed as soon as possible (we can't do a GC here
in a
// record-write context). If a few things get allocated between now and
then
// that shouldn't make us do a scavenge and keep being incremental, so
we set
// the should-hurry flag to indicate that there can't be much work left
to do.
set_should_hurry(true);
+ if (FLAG_overapproximate_weak_closure &&
+ !weak_closure_was_overapproximated_ && action == GC_VIA_STACK_GUARD)
{
+ if (FLAG_trace_incremental_marking) {
+ PrintF(
+ "[IncrementalMarking] requesting weak closure
overapproximation.\n");
+ }
+ heap_->isolate()->stack_guard()->RequestGC();
+ return;
+ }
+ state_ = COMPLETE;
if (FLAG_trace_incremental_marking) {
PrintF("[IncrementalMarking] Complete (normal).\n");
}
Index: src/heap/incremental-marking.h
diff --git a/src/heap/incremental-marking.h b/src/heap/incremental-marking.h
index
56c5a24c2ceb732ab90bc1865da5bf184e5f46f8..63a708b69b208cd07789b12d3217c958a0558928
100644
--- a/src/heap/incremental-marking.h
+++ b/src/heap/incremental-marking.h
@@ -36,6 +36,13 @@ class IncrementalMarking {
bool should_hurry() { return should_hurry_; }
void set_should_hurry(bool val) { should_hurry_ = val; }
+ bool weak_closure_was_overapproximated() const {
+ return weak_closure_was_overapproximated_;
+ }
+ void set_weak_closure_was_overapproximated(bool val) {
+ weak_closure_was_overapproximated_ = val;
+ }
+
inline bool IsStopped() { return state() == STOPPED; }
INLINE(bool IsMarking()) { return state() >= MARKING; }
@@ -102,6 +109,7 @@ class IncrementalMarking {
inline void RestartIfNotMarking() {
if (state_ == COMPLETE) {
state_ = MARKING;
+ weak_closure_was_overapproximated_ = false;
if (FLAG_trace_incremental_marking) {
PrintF("[IncrementalMarking] Restarting (new grey objects)\n");
}
@@ -228,6 +236,8 @@ class IncrementalMarking {
bool was_activated_;
+ bool weak_closure_was_overapproximated_;
+
DISALLOW_IMPLICIT_CONSTRUCTORS(IncrementalMarking);
};
}
Index: src/heap/mark-compact.cc
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index
fa366eefb6b6a2e5003aa1efe550bd74c4a7ca4f..333ab86393fca81092ff9ef4005cb94dfe96a245
100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -2160,6 +2160,21 @@ void MarkCompactCollector::UncommitMarkingDeque() {
}
+void MarkCompactCollector::OverApproximateWeakClosure() {
+ GCTracer::Scope gc_scope(heap()->tracer(),
+ GCTracer::Scope::MC_INCREMENTAL_WEAKCLOSURE);
+
+ RootMarkingVisitor root_visitor(heap());
+ isolate()->global_handles()->IterateObjectGroups(
+ &root_visitor, &IsUnmarkedHeapObjectWithHeap);
+ MarkImplicitRefGroups();
+
+ // Remove object groups after marking phase.
+ heap()->isolate()->global_handles()->RemoveObjectGroups();
+ heap()->isolate()->global_handles()->RemoveImplicitRefGroups();
+}
+
+
void MarkCompactCollector::MarkLiveObjects() {
GCTracer::Scope gc_scope(heap()->tracer(), GCTracer::Scope::MC_MARK);
double start_time = 0.0;
Index: src/heap/mark-compact.h
diff --git a/src/heap/mark-compact.h b/src/heap/mark-compact.h
index
361f3a6377392022e69931832f2ee8ec6962d91d..f9f6dfe17164cbed72527f40b72460a4067f8686
100644
--- a/src/heap/mark-compact.h
+++ b/src/heap/mark-compact.h
@@ -667,6 +667,8 @@ class MarkCompactCollector {
void UncommitMarkingDeque();
+ void OverApproximateWeakClosure();
+
private:
class SweeperTask;
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.