Bug 230957

Summary: [JSC] Add objectTypeCounts to JSGetMemoryUsageStatistics
Product: WebKit Reporter: Basuke Suzuki <Basuke.Suzuki>
Component: JavaScriptCoreAssignee: Basuke Suzuki <Basuke.Suzuki>
Status: RESOLVED FIXED    
Severity: Normal CC: Basuke.Suzuki, ews-watchlist, keith_miller, mark.lam, msaboff, ross.kirsling, saam, tzagallo, webkit-bug-importer, ysuzuki
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
Attachments:
Description Flags
PATCH
ysuzuki: review+
PATCH none

Description Basuke Suzuki 2021-09-29 08:54:35 PDT
It is very useful to have the numbers of each object types in the JS statistics.
Comment 1 Basuke Suzuki 2021-09-29 12:11:35 PDT
Created attachment 439639 [details]
PATCH
Comment 2 Basuke Suzuki 2021-09-29 12:14:26 PDT
Added memoryUsageStatistics() to jsc.

Input:

function dump(values, indent = '') {
    for (const key in values) {
        const value = values[key];
        if (typeof value === 'object') {
            print(`${indent}${key}:`);
            dump(value, indent + '  ');
        } else
            print(`${indent}${key}: ${value}`);
    }
}
dump(memoryUsageStatistics());

Output:

heapSize: 0
heapCapacity: 344064
extraMemorySize: 0
objectCount: 0
protectedObjectCount: 44
protectedGlobalObjectCount: 0
objectTypeCounts:
  JSProxy: 1
  Promise: 1
  Callee: 2
  Atomics: 1
...
Comment 3 Yusuke Suzuki 2021-09-29 14:48:47 PDT
Comment on attachment 439639 [details]
PATCH

I think this is fine. r=me
Comment 4 Ross Kirsling 2021-09-29 14:56:53 PDT
Comment on attachment 439639 [details]
PATCH

View in context: https://bugs.webkit.org/attachment.cgi?id=439639&action=review

> Source/JavaScriptCore/API/JSBase.cpp:208
> +    JSObject* objectTypeCounts = constructEmptyObject(globalObject);

I think you could do `constructEmptyObject(vm, globalObject->nullPrototypeObjectStructure())` since this object is just holding key-value pairs and doesn't need access to the Object prototype.

> Source/JavaScriptCore/API/JSBasePrivate.h:74
> + objectTypeCounts: object which has kind as key and its number as value for each GC objects 

I think something like "object with HeapCell kinds as keys and their current counts as values" would be clearer.
Comment 5 Basuke Suzuki 2021-09-29 15:39:41 PDT
Created attachment 439672 [details]
PATCH
Comment 6 Basuke Suzuki 2021-09-29 15:41:01 PDT
Thanks Ross.
Comment 7 EWS 2021-09-29 17:19:15 PDT
Committed r283286 (242313@main): <https://commits.webkit.org/242313@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 439672 [details].
Comment 8 Radar WebKit Bug Importer 2021-09-29 17:20:27 PDT
<rdar://problem/83696026>