Created
September 1, 2018 16:50
-
-
Save duqicauc/247b22b1ae8f50eeef1b9d115cfc36cc to your computer and use it in GitHub Desktop.
利用SA打印jvm中加载的类
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sun.jvm.hotspot.oops.*; | |
import sun.jvm.hotspot.runtime.*; | |
import sun.jvm.hotspot.tools.Tool; | |
/** | |
* @author duqi | |
* @createTime 2018/9/1 下午11:55 | |
**/ | |
public class PermTool extends Tool { | |
@Override | |
public void run() { | |
// Show PermGen object histogram | |
ObjectHistogram histo = new ObjectHistogram(); | |
VM.getVM().getObjectHeap().iterate(histo); | |
histo.print(); | |
// List all classes in PermGen with their ClassLoaders | |
VM.getVM().getObjectHeap().iterate(new DefaultHeapVisitor() { | |
@Override | |
public boolean doObj(Oop obj) { | |
if (obj.getKlass() instanceof InstanceKlass) { | |
obj.printValue(); | |
Oop loader = ((InstanceKlass) obj.getKlass()).getClassLoader(); | |
if (loader == null) { | |
System.out.println(" -- loaded by Bootstrap ClassLoader"); | |
} else { | |
System.out.print(" -- loaded by "); | |
loader.printValue(); | |
System.out.println(); | |
} | |
} | |
return false; | |
} | |
}); | |
} | |
public static void main(String[] args) { | |
new PermTool().execute(args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
JDK版本:1.8.0_151