Modified: trunk/Source/_javascript_Core/API/JSBase.cpp (253853 => 253854)
--- trunk/Source/_javascript_Core/API/JSBase.cpp 2019-12-20 23:51:36 UTC (rev 253853)
+++ trunk/Source/_javascript_Core/API/JSBase.cpp 2019-12-21 00:05:46 UTC (rev 253854)
@@ -33,10 +33,12 @@
#include "Completion.h"
#include "Exception.h"
#include "GCActivityCallback.h"
+#include "Identifier.h"
#include "InitializeThreading.h"
#include "JSGlobalObject.h"
#include "JSLock.h"
#include "JSObject.h"
+#include "ObjectConstructor.h"
#include "OpaqueJSString.h"
#include "JSCInlines.h"
#include "SourceCode.h"
@@ -187,6 +189,29 @@
GCActivityCallback::s_shouldCreateGCTimer = false;
}
+JSObjectRef JSGetMemoryUsageStatistics(JSContextRef ctx)
+{
+ if (!ctx) {
+ ASSERT_NOT_REACHED();
+ return 0;
+ }
+
+ JSGlobalObject* globalObject = toJS(ctx);
+ VM& vm = globalObject->vm();
+ JSLockHolder locker(vm);
+
+ JSObject* object = constructEmptyObject(globalObject);
+ object->putDirect(vm, Identifier::fromString(vm, "heapSize"), jsNumber(vm.heap.size()));
+ object->putDirect(vm, Identifier::fromString(vm, "heapCapacity"), jsNumber(vm.heap.capacity()));
+ object->putDirect(vm, Identifier::fromString(vm, "extraMemorySize"), jsNumber(vm.heap.extraMemorySize()));
+ object->putDirect(vm, Identifier::fromString(vm, "objectCount"), jsNumber(vm.heap.objectCount()));
+ object->putDirect(vm, Identifier::fromString(vm, "protectedObjectCount"), jsNumber(vm.heap.protectedObjectCount()));
+ object->putDirect(vm, Identifier::fromString(vm, "globalObjectCount"), jsNumber(vm.heap.globalObjectCount()));
+ object->putDirect(vm, Identifier::fromString(vm, "protectedGlobalObjectCount"), jsNumber(vm.heap.protectedGlobalObjectCount()));
+
+ return toRef(object);
+}
+
#if PLATFORM(IOS_FAMILY) && TARGET_OS_IOS
// FIXME: Expose symbols to tell dyld where to find _javascript_Core on older versions of
// iOS (< 7.0). We should remove these symbols once we no longer need to support such
Modified: trunk/Source/_javascript_Core/API/JSBasePrivate.h (253853 => 253854)
--- trunk/Source/_javascript_Core/API/JSBasePrivate.h 2019-12-20 23:51:36 UTC (rev 253853)
+++ trunk/Source/_javascript_Core/API/JSBasePrivate.h 2019-12-21 00:05:46 UTC (rev 253854)
@@ -47,6 +47,22 @@
JS_EXPORT void JSDisableGCTimer(void);
+/*!
+@function
+@abstract Produces an object with various statistics about current memory usage.
+@param ctx The execution context to use.
+@result An object containing GC heap status data.
+@discussion Specifically, the result object has the following integer-valued fields:
+ heapSize: current size of heap
+ heapCapacity: current capacity of heap
+ extraMemorySize: amount of non-GC memory referenced by GC objects (included in heap size / capacity)
+ objectCount: current count of GC objects
+ protectedObjectCount: current count of protected GC objects
+ globalObjectCount: current count of global GC objects
+ protectedGlobalObjectCount: current count of protected global GC objects
+*/
+JS_EXPORT JSObjectRef JSGetMemoryUsageStatistics(JSContextRef ctx);
+
#ifdef __cplusplus
}
#endif
Modified: trunk/Source/_javascript_Core/ChangeLog (253853 => 253854)
--- trunk/Source/_javascript_Core/ChangeLog 2019-12-20 23:51:36 UTC (rev 253853)
+++ trunk/Source/_javascript_Core/ChangeLog 2019-12-21 00:05:46 UTC (rev 253854)
@@ -1,3 +1,15 @@
+2019-12-20 Ross Kirsling <[email protected]>
+
+ [JSC] Memory usage statistics should be attainable without WebCore
+ https://bugs.webkit.org/show_bug.cgi?id=205366
+
+ Reviewed by Keith Miller.
+
+ * API/JSBase.cpp:
+ (JSGetMemoryUsageStatistics):
+ * API/JSBasePrivate.h:
+ Add a private JSC API exposing the same Heap stats as WebCore's PerformanceLogging::memoryUsageStatistics.
+
2019-12-19 Saam Barati <[email protected]>
Don't cache self customs on dictionaries