Libraryless. Click here for Pure Java version (5566L/33K).
1 | sclass InvestigateNonTransientGraph {
|
2 | MetaTransformer mt; |
3 | Map back = identityHashMap(); |
4 | new MultiSet<O> objectsBySize; |
5 | new MultiMap<Class, O> objectsByClass; |
6 | new MultiSet<S> objectsByDynClass; |
7 | |
8 | *() {
|
9 | mt = metaTransformer_collectionAndMap(); |
10 | mt.add(new MTSH_nonTransientFields); |
11 | mt.avoidCycles(); |
12 | mt.markPointer = (a, b) -> {
|
13 | putIfNotThere(back, b, a); |
14 | }; |
15 | } |
16 | |
17 | void scan(O root) {
|
18 | VStack.Computable v = mt.new visit_vstackComputable(o -> {
|
19 | objectsBySize.add(o.getClass(), clampToInt(unsafe_sizeOf(o))); |
20 | objectsByClass.put(o.getClass(), o); |
21 | if (o instanceof DynamicObject) |
22 | objectsByDynClass.add(shortDynClassName(o)); |
23 | }, root); |
24 | |
25 | vstackCompute(v); |
26 | } |
27 | |
28 | void printResults() {
|
29 | print("Seen objects: " + n2(mt.seen));
|
30 | print(); |
31 | print("Most popular classes:");
|
32 | print(multiSetToLines(multiMapToMultiSet(objectsByClass), 20)); |
33 | print(); |
34 | print("Total bytes per class:");
|
35 | print(multiSetToLines(objectsBySize, 20)); |
36 | if (!empty(objectsByDynClass)) {
|
37 | print("Popular dynamic classes:");
|
38 | print(multiSetToLines(objectsByDynClass, 20)); |
39 | } |
40 | } |
41 | |
42 | <A> L<A> biggestOfClass(Class<A> c) {
|
43 | ret sortedByCalculatedFieldDesc unsafe_objectSize((Cl<A>) objectsByClass.get(c)); |
44 | } |
45 | |
46 | void printBiggestByteArrays() {
|
47 | for (var array : takeFirst(2, biggestOfClass(byteArrayType()))) {
|
48 | print("Byte array " + n2_l(array));
|
49 | O o = array; |
50 | repeat 10 {
|
51 | if (o == null) break; |
52 | o = back.get(o); |
53 | print(" <= " + className/*shortenedToStringWithClass*/(o));
|
54 | } |
55 | } |
56 | } |
57 | } |
download show line numbers debug dex old transpilations
Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt
No comments. add comment
| Snippet ID: | #1031759 |
| Snippet name: | InvestigateNonTransientGraph |
| Eternal ID of this version: | #1031759/11 |
| Text MD5: | a72fe02af9aa7e2c42bee89fcc97412c |
| Transpilation MD5: | d3798bb1d0c0129fa1919addef47bec2 |
| Author: | stefan |
| Category: | javax |
| Type: | JavaX fragment (include) |
| Public (visible to everyone): | Yes |
| Archived (hidden from active list): | No |
| Created/modified: | 2021-06-29 08:54:45 |
| Source code size: | 1678 bytes / 57 lines |
| Pitched / IR pitched: | No / No |
| Views / Downloads: | 455 / 700 |
| Version history: | 10 change(s) |
| Referenced in: | [show references] |