Title: [283286] trunk/Source/_javascript_Core
Revision
283286
Author
basuke.suz...@sony.com
Date
2021-09-29 17:19:07 -0700 (Wed, 29 Sep 2021)

Log Message

[JSC] Add objectTypeCounts to JSGetMemoryUsageStatistics
https://bugs.webkit.org/show_bug.cgi?id=230957

Reviewed by Yusuke Suzuki.

* API/JSBase.cpp: Added objectTypeCounts property
(JSGetMemoryUsageStatistics):
* API/JSBasePrivate.h: Added description of objectTypeCounts property
* jsc.cpp: Added memoryUsageStatistics() function

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSBase.cpp (283285 => 283286)


--- trunk/Source/_javascript_Core/API/JSBase.cpp	2021-09-30 00:07:14 UTC (rev 283285)
+++ trunk/Source/_javascript_Core/API/JSBase.cpp	2021-09-30 00:19:07 UTC (rev 283286)
@@ -204,6 +204,11 @@
     VM& vm = globalObject->vm();
     JSLockHolder locker(vm);
 
+    auto typeCounts = vm.heap.objectTypeCounts();
+    JSObject* objectTypeCounts = constructEmptyObject(globalObject);
+    for (auto& it : *typeCounts)
+        objectTypeCounts->putDirect(vm, Identifier::fromString(vm, it.key), jsNumber(it.value));
+
     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()));
@@ -212,6 +217,7 @@
     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()));
+    object->putDirect(vm, Identifier::fromString(vm, "objectTypeCounts"), objectTypeCounts);
 
     return toRef(object);
 }

Modified: trunk/Source/_javascript_Core/API/JSBasePrivate.h (283285 => 283286)


--- trunk/Source/_javascript_Core/API/JSBasePrivate.h	2021-09-30 00:07:14 UTC (rev 283285)
+++ trunk/Source/_javascript_Core/API/JSBasePrivate.h	2021-09-30 00:19:07 UTC (rev 283286)
@@ -71,6 +71,7 @@
  protectedObjectCount: current count of protected GC objects
  globalObjectCount: current count of global GC objects
  protectedGlobalObjectCount: current count of protected global GC objects
+ objectTypeCounts: object with GC object types as keys and their current counts as values
 */
 JS_EXPORT JSObjectRef JSGetMemoryUsageStatistics(JSContextRef ctx);
 

Modified: trunk/Source/_javascript_Core/ChangeLog (283285 => 283286)


--- trunk/Source/_javascript_Core/ChangeLog	2021-09-30 00:07:14 UTC (rev 283285)
+++ trunk/Source/_javascript_Core/ChangeLog	2021-09-30 00:19:07 UTC (rev 283286)
@@ -1,3 +1,15 @@
+2021-09-29  Basuke Suzuki  <basuke.suz...@sony.com>
+
+        [JSC] Add objectTypeCounts to JSGetMemoryUsageStatistics
+        https://bugs.webkit.org/show_bug.cgi?id=230957
+
+        Reviewed by Yusuke Suzuki.
+
+        * API/JSBase.cpp: Added objectTypeCounts property
+        (JSGetMemoryUsageStatistics):
+        * API/JSBasePrivate.h: Added description of objectTypeCounts property
+        * jsc.cpp: Added memoryUsageStatistics() function
+
 2021-09-29  Yusuke Suzuki  <ysuz...@apple.com>
 
         [JSC] Remove CodeBlock::m_llintExecuteCounter

Modified: trunk/Source/_javascript_Core/jsc.cpp (283285 => 283286)


--- trunk/Source/_javascript_Core/jsc.cpp	2021-09-30 00:07:14 UTC (rev 283285)
+++ trunk/Source/_javascript_Core/jsc.cpp	2021-09-30 00:19:07 UTC (rev 283286)
@@ -22,6 +22,7 @@
 
 #include "config.h"
 
+#include "APICast.h"
 #include "ArrayBuffer.h"
 #include "BigIntConstructor.h"
 #include "BytecodeCacheError.h"
@@ -44,6 +45,7 @@
 #include "JITSizeStatistics.h"
 #include "JSArray.h"
 #include "JSArrayBuffer.h"
+#include "JSBasePrivate.h"
 #include "JSBigInt.h"
 #include "JSFinalizationRegistry.h"
 #include "JSFunction.h"
@@ -285,6 +287,7 @@
 static JSC_DECLARE_HOST_FUNCTION(functionFullGC);
 static JSC_DECLARE_HOST_FUNCTION(functionEdenGC);
 static JSC_DECLARE_HOST_FUNCTION(functionHeapSize);
+static JSC_DECLARE_HOST_FUNCTION(functionMemoryUsageStatistics);
 static JSC_DECLARE_HOST_FUNCTION(functionCreateMemoryFootprint);
 static JSC_DECLARE_HOST_FUNCTION(functionResetMemoryPeak);
 static JSC_DECLARE_HOST_FUNCTION(functionAddressOf);
@@ -529,6 +532,7 @@
         addFunction(vm, "fullGC", functionFullGC, 0);
         addFunction(vm, "edenGC", functionEdenGC, 0);
         addFunction(vm, "gcHeapSize", functionHeapSize, 0);
+        addFunction(vm, "memoryUsageStatistics", functionMemoryUsageStatistics, 0);
         addFunction(vm, "MemoryFootprint", functionCreateMemoryFootprint, 0);
         addFunction(vm, "resetMemoryPeak", functionResetMemoryPeak, 0);
         addFunction(vm, "addressOf", functionAddressOf, 1);
@@ -1461,6 +1465,12 @@
 
 const ClassInfo JSCMemoryFootprint::s_info = { "MemoryFootprint", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSCMemoryFootprint) };
 
+JSC_DEFINE_HOST_FUNCTION(functionMemoryUsageStatistics, (JSGlobalObject* globalObject, CallFrame*))
+{
+    auto contextRef = toRef(globalObject);
+    return JSValue::encode(toJS(JSGetMemoryUsageStatistics(contextRef)));
+}
+
 JSC_DEFINE_HOST_FUNCTION(functionCreateMemoryFootprint, (JSGlobalObject* globalObject, CallFrame*))
 {
     VM& vm = globalObject->vm();
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to