Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

64
LINES

< > BotCompany Repo | #1016518 // Stefan's OS memory leak finder [OK]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 0K of libraries. Click here for Pure Java version (5462L/38K).

1  
!7
2  
3  
// finds references to defunct class loaders
4  
5  
lib 1400084 // patched heap analyzer
6  
7  
import org.gridkit.jvmtool.heapdump.*;
8  
import org.netbeans.lib.profiler.heap.*;
9  
import java.lang.reflect.Field;
10  
11  
static Heap heap;
12  
13  
sbool fake = false;
14  
15  
p {
16  
  consoleIcon(#1101624);
17  
  centerHigherConsole();
18  
  tt();
19  
  
20  
  if (isAbsolutePath(first(args)))
21  
    setUserHome(first(args));
22  
23  
  File f = stefansOS_heapDumpFile();
24  
  print("Loading heap dump (" + toM(fileSize(f)) + " M)...");
25  
  heap = HeapFactory.createHeap(f);
26  
  print("Got heap.");
27  
  L<JavaClass> classes = heap.getAllClasses();
28  
  print("Got " + n2(classes, "class", "classes"));
29  
  //pnl(sortedIC(mapMethod(classes, 'getName)));
30  
  
31  
  L<JavaClass> classLoaderClasses = filter(classes, func(JavaClass c) -> bool { startsWithOneOf(c.getName(), "main$JavaXClassLoader", "x30$JavaXClassLoader") });
32  
  print("Got " + n2(classLoaderClasses, "class loader class", "class loader classes"));
33  
  L<Instance> classLoaders = concatLists(mapMethod('getInstances, classLoaderClasses));
34  
  print("Got " + n2(classLoaders, "class loader"));
35  
  
36  
  L<Instance> defunctClassLoaders = filter(classLoaders, func(Instance cl) { isTrue(cl.getValueOfField('retired)) });
37  
  print("Got " + n2(defunctClassLoaders, "defunct class loader"));
38  
  
39  
  print();
40  
  if (empty(defunctClassLoaders)) {
41  
    if (fake) {
42  
      defunctClassLoaders = classLoaders;
43  
      print("FAKING IT");
44  
    } else {
45  
      print("No memory leaks.");
46  
      ret;
47  
    }
48  
  }
49  
  
50  
  print("Calculating GC roots...");
51  
  
52  
  for (Instance cl : defunctClassLoaders) {
53  
    Instance progIDInstance = (Instance) cl.getValueOfField('progID);
54  
    S moduleID = HeapWalker.stringValue(progIDInstance);
55  
    print("Checking module ID: " + snippetWithTitle_cached(moduleID));
56  
    print("\nPath to GC root:");
57  
    printLinesWithGrowingIndent(map(func(Pair<Instance, S> p) -> S {
58  
      joinNempties(" in ", p.b, heapWalker_className(p.a))
59  
    }, heapWalker_pathToGCRootWithFieldNames(cl)));
60  
    print();
61  
    //Instance i = cl.getNearestGCRootPointer();
62  
    //print("i => " + i);
63  
  }
64  
}

Author comment

Began life as a copy of #1016517

download  show line numbers  debug dex  old transpilations   

Travelled to 29 computer(s): aoiabmzegqzx, ayivmpnvhhik, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, dbzfplsxganw, ekrmjmnbrukm, gwrvuhgaqvyk, hpgrupgrauku, ippswpntdvcc, irmadwmeruwu, ishqpsrjomds, jchfcwwgaovw, lpdgvwnxivlt, mqqgnosmbjvj, nnlgzsuogrvb, pyentgdyhuwx, pzhvpgtvlbxg, qaafgiputhfz, qmtsvidgarql, sekmkcqzslie, tslmcundralx, tvejysmllsmz, vouqrxazstgt, vzdtmrzilvqm, wdffvflfhhdx, whxojlpjdney, wpzdwgqboxjy, zkbeyrirjpvi

No comments. add comment

Snippet ID: #1016518
Snippet name: Stefan's OS memory leak finder [OK]
Eternal ID of this version: #1016518/61
Text MD5: 6fb8b4df95e06c65864ba7eaf25a4c3e
Transpilation MD5: e80bd9d5a588a457f855b983025224d0
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-03-26 14:13:35
Source code size: 2111 bytes / 64 lines
Pitched / IR pitched: No / No
Views / Downloads: 711 / 2732
Version history: 60 change(s)
Referenced in: [show references]