Issue #316 - Make the memory GC performance object conditional (WIP)

This was only added for GCubench and likely interfering with building
without devtools-server.
This commit is contained in:
wolfbeast 2020-02-20 12:00:26 +01:00 • committed by Roy Tam
commit 1e553d0e73
11 changed files with 36 additions and 0 deletions

View file

@ -96,8 +96,10 @@ public:
IMPL_EVENT_HANDLER(resourcetimingbufferfull) IMPL_EVENT_HANDLER(resourcetimingbufferfull)
#ifdef MOZ_DEVTOOLS_SERVER
virtual void GetMozMemory(JSContext *aCx, virtual void GetMozMemory(JSContext *aCx,
JS::MutableHandle<JSObject*> aObj) = 0; JS::MutableHandle<JSObject*> aObj) = 0;
#endif
virtual nsDOMNavigationTiming* GetDOMTiming() const = 0; virtual nsDOMNavigationTiming* GetDOMTiming() const = 0;

View file

@ -11,6 +11,7 @@
namespace mozilla { namespace mozilla {
namespace dom { namespace dom {
#ifdef MOZ_DEVTOOLS_SERVER
NS_IMPL_CYCLE_COLLECTION_CLASS(PerformanceMainThread) NS_IMPL_CYCLE_COLLECTION_CLASS(PerformanceMainThread)
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PerformanceMainThread, NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(PerformanceMainThread,
@ -36,6 +37,10 @@ NS_IMPL_CYCLE_COLLECTION_TRACE_END
NS_IMPL_ADDREF_INHERITED(PerformanceMainThread, Performance) NS_IMPL_ADDREF_INHERITED(PerformanceMainThread, Performance)
NS_IMPL_RELEASE_INHERITED(PerformanceMainThread, Performance) NS_IMPL_RELEASE_INHERITED(PerformanceMainThread, Performance)
#else
NS_IMPL_CYCLE_COLLECTION_INHERITED(PerformanceMainThread, Performance
mTiming, mNavigation, mDocEntry)
#endif
// QueryInterface implementation for PerformanceMainThread // QueryInterface implementation for PerformanceMainThread
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceMainThread) NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(PerformanceMainThread)
@ -55,9 +60,12 @@ PerformanceMainThread::PerformanceMainThread(nsPIDOMWindowInner* aWindow,
PerformanceMainThread::~PerformanceMainThread() PerformanceMainThread::~PerformanceMainThread()
{ {
#ifdef MOZ_DEVTOOLS_SERVER
mozilla::DropJSObjects(this); mozilla::DropJSObjects(this);
#endif
} }
#ifdef MOZ_DEVTOOLS_SERVER
void void
PerformanceMainThread::GetMozMemory(JSContext *aCx, PerformanceMainThread::GetMozMemory(JSContext *aCx,
JS::MutableHandle<JSObject*> aObj) JS::MutableHandle<JSObject*> aObj)
@ -71,6 +79,7 @@ PerformanceMainThread::GetMozMemory(JSContext *aCx,
aObj.set(mMozMemory); aObj.set(mMozMemory);
} }
#endif
PerformanceTiming* PerformanceTiming*
PerformanceMainThread::Timing() PerformanceMainThread::Timing()

View file

@ -20,8 +20,12 @@ public:
nsITimedChannel* aChannel); nsITimedChannel* aChannel);
NS_DECL_ISUPPORTS_INHERITED NS_DECL_ISUPPORTS_INHERITED
#ifdef MOZ_DEVTOOLS_SERVER
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PerformanceMainThread, NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_INHERITED(PerformanceMainThread,
Performance) Performance)
#else
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(PerformanceMainThread, Performance)
#endif
virtual PerformanceTiming* Timing() override; virtual PerformanceTiming* Timing() override;
@ -34,8 +38,10 @@ public:
DOMHighResTimeStamp CreationTime() const override; DOMHighResTimeStamp CreationTime() const override;
#ifdef MOZ_DEVTOOLS_SERVER
virtual void GetMozMemory(JSContext *aCx, virtual void GetMozMemory(JSContext *aCx,
JS::MutableHandle<JSObject*> aObj) override; JS::MutableHandle<JSObject*> aObj) override;
#endif
virtual nsDOMNavigationTiming* GetDOMTiming() const override virtual nsDOMNavigationTiming* GetDOMTiming() const override
{ {
@ -79,7 +85,9 @@ protected:
nsCOMPtr<nsITimedChannel> mChannel; nsCOMPtr<nsITimedChannel> mChannel;
RefPtr<PerformanceTiming> mTiming; RefPtr<PerformanceTiming> mTiming;
RefPtr<PerformanceNavigation> mNavigation; RefPtr<PerformanceNavigation> mNavigation;
#ifdef MOZ_DEVTOOLS_SERVER
JS::Heap<JSObject*> mMozMemory; JS::Heap<JSObject*> mMozMemory;
#endif
}; };
} // namespace dom } // namespace dom

View file

@ -43,11 +43,13 @@ public:
DOMHighResTimeStamp CreationTime() const override; DOMHighResTimeStamp CreationTime() const override;
#ifdef MOZ_DEVTOOLS_SERVER
virtual void GetMozMemory(JSContext *aCx, virtual void GetMozMemory(JSContext *aCx,
JS::MutableHandle<JSObject*> aObj) override JS::MutableHandle<JSObject*> aObj) override
{ {
MOZ_CRASH("This should not be called on workers."); MOZ_CRASH("This should not be called on workers.");
} }
#endif
virtual nsDOMNavigationTiming* GetDOMTiming() const override virtual nsDOMNavigationTiming* GetDOMTiming() const override
{ {

View file

@ -55,12 +55,14 @@ partial interface Performance {
attribute EventHandler onresourcetimingbufferfull; attribute EventHandler onresourcetimingbufferfull;
}; };
#ifdef MOZ_DEVTOOLS_SERVER
// GC microbenchmarks, pref-guarded, not for general use (bug 1125412) // GC microbenchmarks, pref-guarded, not for general use (bug 1125412)
[Exposed=Window] [Exposed=Window]
partial interface Performance { partial interface Performance {
[Pref="dom.enable_memory_stats"] [Pref="dom.enable_memory_stats"]
readonly attribute object mozMemory; readonly attribute object mozMemory;
}; };
#endif
// http://www.w3.org/TR/user-timing/ // http://www.w3.org/TR/user-timing/
[Exposed=(Window,Worker)] [Exposed=(Window,Worker)]

View file

@ -392,6 +392,7 @@ IsIncrementalBarrierNeededOnTenuredGCThing(JS::shadow::Runtime* rt, const JS::GC
return JS::shadow::Zone::asShadowZone(zone)->needsIncrementalBarrier(); return JS::shadow::Zone::asShadowZone(zone)->needsIncrementalBarrier();
} }
#ifdef MOZ_DEVTOOLS_SERVER
/** /**
* Create an object providing access to the garbage collector's internal notion * Create an object providing access to the garbage collector's internal notion
* of the current state of memory (both GC heap memory and GCthing-controlled * of the current state of memory (both GC heap memory and GCthing-controlled
@ -399,6 +400,7 @@ IsIncrementalBarrierNeededOnTenuredGCThing(JS::shadow::Runtime* rt, const JS::GC
*/ */
extern JS_PUBLIC_API(JSObject*) extern JS_PUBLIC_API(JSObject*)
NewMemoryInfoObject(JSContext* cx); NewMemoryInfoObject(JSContext* cx);
#endif
} /* namespace gc */ } /* namespace gc */
} /* namespace js */ } /* namespace js */

View file

@ -741,7 +741,9 @@ class GCRuntime
void removeBlackRootsTracer(JSTraceDataOp traceOp, void* data); void removeBlackRootsTracer(JSTraceDataOp traceOp, void* data);
void setMaxMallocBytes(size_t value); void setMaxMallocBytes(size_t value);
#ifdef MOZ_DEVTOOLS_SERVER
int32_t getMallocBytes() const { return mallocBytesUntilGC; } int32_t getMallocBytes() const { return mallocBytesUntilGC; }
#endif
void resetMallocBytes(); void resetMallocBytes();
bool isTooMuchMalloc() const { return mallocBytesUntilGC <= 0; } bool isTooMuchMalloc() const { return mallocBytesUntilGC <= 0; }
void updateMallocCounter(JS::Zone* zone, size_t nbytes); void updateMallocCounter(JS::Zone* zone, size_t nbytes);

View file

@ -505,7 +505,10 @@ js::Nursery::collect(JSRuntime* rt, JS::gcreason::Reason reason)
if (!isEnabled()) if (!isEnabled())
return; return;
#ifdef MOZ_DEVTOOLS_SERVER
// No need to obsessively track this without devtools
rt->gc.incMinorGcNumber(); rt->gc.incMinorGcNumber();
#endif
rt->gc.stats.beginNurseryCollection(reason); rt->gc.stats.beginNurseryCollection(reason);
TraceMinorGCStart(); TraceMinorGCStart();

View file

@ -6776,6 +6776,7 @@ js::gc::NextCellUniqueId(JSRuntime* rt)
return rt->gc.nextCellUniqueId(); return rt->gc.nextCellUniqueId();
} }
#ifdef MOZ_DEVTOOLS_SERVER
namespace js { namespace js {
namespace gc { namespace gc {
namespace MemInfo { namespace MemInfo {
@ -7032,6 +7033,7 @@ AutoEmptyNursery::AutoEmptyNursery(JSRuntime *rt)
} /* namespace gc */ } /* namespace gc */
} /* namespace js */ } /* namespace js */
#endif
#ifdef DEBUG #ifdef DEBUG
void void

View file

@ -1357,8 +1357,10 @@ class ZoneList
ZoneList& operator=(const ZoneList& other) = delete; ZoneList& operator=(const ZoneList& other) = delete;
}; };
#ifdef MOZ_DEVTOOLS_SERVER
JSObject* JSObject*
NewMemoryStatisticsObject(JSContext* cx); NewMemoryStatisticsObject(JSContext* cx);
#endif
struct MOZ_RAII AutoAssertNoNurseryAlloc struct MOZ_RAII AutoAssertNoNurseryAlloc
{ {

View file

@ -7090,6 +7090,7 @@ NewGlobalObject(JSContext* cx, JS::CompartmentOptions& options,
if (!DefineOS(cx, glob, fuzzingSafe, &gOutFile, &gErrFile)) if (!DefineOS(cx, glob, fuzzingSafe, &gOutFile, &gErrFile))
return nullptr; return nullptr;
#ifdef MOZ_DEVTOOLS_SERVER
RootedObject performanceObj(cx, JS_NewObject(cx, nullptr)); RootedObject performanceObj(cx, JS_NewObject(cx, nullptr));
if (!performanceObj) if (!performanceObj)
return nullptr; return nullptr;
@ -7105,6 +7106,7 @@ NewGlobalObject(JSContext* cx, JS::CompartmentOptions& options,
return nullptr; return nullptr;
if (!JS_DefineProperty(cx, mozMemoryObj, "gc", gcObj, JSPROP_ENUMERATE)) if (!JS_DefineProperty(cx, mozMemoryObj, "gc", gcObj, JSPROP_ENUMERATE))
return nullptr; return nullptr;
#endif
/* Initialize FakeDOMObject. */ /* Initialize FakeDOMObject. */
static const js::DOMCallbacks DOMcallbacks = { static const js::DOMCallbacks DOMcallbacks = {