From 466d8ba130b04e49e3dcf13c47e173153f9ec945 Mon Sep 17 00:00:00 2001 From: Jon Coppeard Date: Tue, 9 Dec 2014 10:09:26 +0000 Subject: [PATCH] Bug 650161 - Add API to disable compacting GC r=terrence --- js/public/GCAPI.h | 15 +++++++++++++++ js/src/gc/GCRuntime.h | 1 + js/src/jsfriendapi.cpp | 18 ++++++++++++++++++ js/src/jsgc.cpp | 8 +++++++- 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/js/public/GCAPI.h b/js/public/GCAPI.h index 8e5c064d117f..e09c958f2ea2 100644 --- a/js/public/GCAPI.h +++ b/js/public/GCAPI.h @@ -285,6 +285,21 @@ DisableIncrementalGC(JSRuntime *rt); extern JS_FRIEND_API(bool) IsIncrementalGCEnabled(JSRuntime *rt); +/* + * Compacting GC defaults to enabled, but may be disabled for testing or in + * embeddings that have not implemented the necessary object moved hooks or weak + * pointer callbacks. There is not currently a way to re-enable compacting GC + * once it has been disabled on the runtime. + */ +extern JS_FRIEND_API(void) +DisableCompactingGC(JSRuntime *rt); + +/* + * Returns true if compacting GC is enabled. + */ +extern JS_FRIEND_API(bool) +IsCompactingGCEnabled(JSRuntime *rt); + /* * Returns true while an incremental GC is ongoing, both when actively * collecting and between slices. diff --git a/js/src/gc/GCRuntime.h b/js/src/gc/GCRuntime.h index 2ddf86fb4ff6..04bb2fc0c4ad 100644 --- a/js/src/gc/GCRuntime.h +++ b/js/src/gc/GCRuntime.h @@ -444,6 +444,7 @@ class GCRuntime #ifdef JSGC_COMPACTING void disableCompactingGC(); void enableCompactingGC(); + bool isCompactingGCEnabled(); #endif void setGrayRootsTracer(JSTraceDataOp traceOp, void *data); diff --git a/js/src/jsfriendapi.cpp b/js/src/jsfriendapi.cpp index 1e6b3670b8f1..4e677da6eb40 100644 --- a/js/src/jsfriendapi.cpp +++ b/js/src/jsfriendapi.cpp @@ -1125,6 +1125,24 @@ JS::DisableIncrementalGC(JSRuntime *rt) rt->gc.disallowIncrementalGC(); } +JS_FRIEND_API(void) +JS::DisableCompactingGC(JSRuntime *rt) +{ +#ifdef JSGC_COMPACTING + rt->gc.disableCompactingGC(); +#endif +} + +JS_FRIEND_API(bool) +JS::IsCompactingGCEnabled(JSRuntime *rt) +{ +#ifdef JSGC_COMPACTING + return rt->gc.isCompactingGCEnabled(); +#else + return false; +#endif +} + JS::AutoDisableGenerationalGC::AutoDisableGenerationalGC(JSRuntime *rt) : gc(&rt->gc) #if defined(JSGC_GENERATIONAL) && defined(JS_GC_ZEAL) diff --git a/js/src/jsgc.cpp b/js/src/jsgc.cpp index aec7ed3492ab..86092f7ea822 100644 --- a/js/src/jsgc.cpp +++ b/js/src/jsgc.cpp @@ -2005,7 +2005,7 @@ bool GCRuntime::shouldCompact() { #ifdef JSGC_COMPACTING - return invocationKind == GC_SHRINK && !compactingDisabled; + return invocationKind == GC_SHRINK && isCompactingGCEnabled(); #else return false; #endif @@ -2026,6 +2026,12 @@ GCRuntime::enableCompactingGC() --compactingDisabled; } +bool +GCRuntime::isCompactingGCEnabled() +{ + return rt->gc.compactingDisabled == 0; +} + AutoDisableCompactingGC::AutoDisableCompactingGC(JSRuntime *rt) : gc(rt->gc) {