From e53f1a803316cb01dd7f9b7698275ed65bdf5a9d Mon Sep 17 00:00:00 2001 From: Bill McCloskey Date: Sat, 30 Jun 2012 14:18:04 -0700 Subject: [PATCH] Bug 758034 - Add new JS APIs for GC (r=terrence) --- js/src/jsfriendapi.cpp | 23 +++++++++++++++++++---- js/src/jsfriendapi.h | 5 ++++- js/src/jsgc.cpp | 7 +++++++ js/src/jsgc.h | 3 +++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index d454a8c2fe21..a1d97fb8361f 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -114,6 +114,18 @@ js::PrepareForFullGC(JSRuntime *rt) c->scheduleGC(); } +JS_FRIEND_API(void) +js::PrepareForIncrementalGC(JSRuntime *rt) +{ + if (rt->gcIncrementalState == gc::NO_INCREMENTAL) + return; + + for (CompartmentsIter c(rt); !c.done(); c.next()) { + if (c->needsBarrier()) + PrepareCompartmentForGC(c); + } +} + JS_FRIEND_API(bool) js::IsGCScheduled(JSRuntime *rt) { @@ -149,6 +161,12 @@ js::IncrementalGC(JSRuntime *rt, gcreason::Reason reason) GCSlice(rt, GC_NORMAL, reason); } +JS_FRIEND_API(void) +js::FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason) +{ + GCFinalSlice(rt, GC_NORMAL, reason); +} + JS_FRIEND_API(void) JS_ShrinkGCBuffers(JSRuntime *rt) { @@ -758,10 +776,7 @@ NotifyDidPaint(JSRuntime *rt) } if (rt->gcIncrementalState != gc::NO_INCREMENTAL && !rt->gcInterFrameGC) { - for (CompartmentsIter c(rt); !c.done(); c.next()) { - if (c->needsBarrier()) - PrepareCompartmentForGC(c); - } + PrepareForIncrementalGC(rt); GCSlice(rt, GC_NORMAL, gcreason::REFRESH_FRAME); } diff --git a/js/src/jsfriendapi.h b/js/src/jsfriendapi.h index 760cb06993d0..6b9c48159ea0 100644 --- a/js/src/jsfriendapi.h +++ b/js/src/jsfriendapi.h @@ -632,6 +632,9 @@ PrepareCompartmentForGC(JSCompartment *comp); extern JS_FRIEND_API(void) PrepareForFullGC(JSRuntime *rt); +extern JS_FRIEND_API(void) +PrepareForIncrementalGC(JSRuntime *rt); + extern JS_FRIEND_API(bool) IsGCScheduled(JSRuntime *rt); @@ -655,7 +658,7 @@ extern JS_FRIEND_API(void) IncrementalGC(JSRuntime *rt, gcreason::Reason reason); extern JS_FRIEND_API(void) -SetGCSliceTimeBudget(JSContext *cx, int64_t millis); +FinishIncrementalGC(JSRuntime *rt, gcreason::Reason reason); enum GCProgress { /* diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index dd5942aa5472..e418f91612ea 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -3914,6 +3914,13 @@ GCSlice(JSRuntime *rt, JSGCInvocationKind gckind, gcreason::Reason reason) Collect(rt, true, rt->gcSliceBudget, gckind, reason); } +void +GCFinalSlice(JSRuntime *rt, JSGCInvocationKind gckind, gcreason::Reason reason) +{ + Collect(rt, true, SliceBudget::Unlimited, gckind, reason); +} + + void GCDebugSlice(JSRuntime *rt, bool limit, int64_t objCount) { diff --git a/js/src/jsgc.h b/js/src/jsgc.h index 37fb33aa501c..ae20b85eb715 100644 --- a/js/src/jsgc.h +++ b/js/src/jsgc.h @@ -477,6 +477,9 @@ GC(JSRuntime *rt, JSGCInvocationKind gckind, js::gcreason::Reason reason); extern void GCSlice(JSRuntime *rt, JSGCInvocationKind gckind, js::gcreason::Reason reason); +extern void +GCFinalSlice(JSRuntime *rt, JSGCInvocationKind gckind, js::gcreason::Reason reason); + extern void GCDebugSlice(JSRuntime *rt, bool limit, int64_t objCount);