The Serviceability Agent(SA). The Serviceability Agent is a Sun private component in the HotSpot repository that was developed by HotSpot engineers to assist in debugging HotSpot. They then realized that SA could be used to craft serviceability tools for end users since it can expose Java objects as well as HotSpot data structures both in running processes and in core files.
HotSpot SA
alias clhsdb='java -classpath .:$JAVA_HOME/lib/sa-jdi.jar sun.jvm.hotspot.CLHSDB'
alias ssum="awk '{sum+=\$1}; END {print sum}'"
alias objectsizesumm="grep 'object size' | awk -F 'object size = ' '{print \$2}' | awk -F ')' '{print \$1}' | ssum"
http://javasourcecode.org/html/open-source/jdk/jdk-6u23/sun/jvm/hotspot/CLHSDB.java.html
http://rednaxelafx.iteye.com/blog/730461
https://gist.github.com/956694
- sun.jvm.hotspot.CLHSDB
命令行界面HotSpotDeBugger
- sun.jvm.hotspot.HSDB
图形界面HotSpotDeBugger
- sun.jvm.hotspot.tools.Tool
- sun.jvm.hotspot.tools.FinalizerInfo
查找 java.lang.ref.Finalizer 下的queue中的队列信息
- sun.jvm.hotspot.tools.FlagDumper
通过 VM.getVM().getCommandLineFlags() 打印所有的flag信息
- sun.jvm.hotspot.tools.HeapDumper
Dump内存数据为文件
- sun.jvm.hotspot.tools.HeapSummary
打印内存分配(分带)情况
- sun.jvm.hotspot.tools.JInfo
命令jinfo
- sun.jvm.hotspot.tools.JMap
命令jmap
- sun.jvm.hotspot.tools.JSnap
打印Perf信息
- sun.jvm.hotspot.tools.JStack
打印JVM的StackTrace
- sun.jvm.hotspot.tools.ObjectHistogram
打印'jmap -histo'信息
- sun.jvm.hotspot.tools.PermStat
- sun.jvm.hotspot.tools.PMap
- sun.jvm.hotspot.tools.PStack
- sun.jvm.hotspot.tools.StackTrace
- sun.jvm.hotspot.tools.SysPropsDumper
通过 VM.getVM().getSystemProperties() 打印 Properties getProperties() 的信息
- sun.jvm.hotspot.tools.jcore.ClassDump
打印内存中的class内存到文件
- sun.jvm.hotspot.tools.joql.JSDB
- sun.jvm.hotspot.tools.joql.JOQL
- sun.jvm.hotspot.runtime.VM
isCore |
boolean |
|
isClientCompiler |
boolean |
是否是C1(client)编译器 |
isServerCompiler |
boolean |
是否是C2(server)编译器 |
useDerivedPointerTable |
boolean |
|
isBigEndian |
boolean |
是否是BigEndian |
isLP64 |
boolean |
是否是64位JVM |
isSharingEnabled |
boolean |
|
isCompressedOopsEnabled |
boolean |
|
getUseTLAB |
boolean |
是否使用TLAB(Thread Local Allocation Buffer) |
isDebugging |
boolean |
|
wizardMode |
boolean |
|
getInvocationEntryBCI |
int |
|
getInvalidOSREntryBCI |
int |
|
getObjectAlignmentInBytes |
int |
|
getAddressSize |
long |
|
getOopSize |
long |
|
getLogAddressSize |
long |
|
getIntSize |
long |
|
getStackBias |
long |
|
getBytesPerLong |
int |
|
getMinObjAlignmentInBytes |
int |
|
getLogMinObjAlignmentInBytes |
int |
|
getHeapWordSize |
int |
|
getHeapOopSize |
int |
|
getOS |
java.lang.String |
操作系统: solaris, linux, win32 |
getCPU |
java.lang.String |
CPU架构: x86, sparc, ia64, amd64(x86_64) |
getVMRelease |
java.lang.String |
|
getVMInternalInfo |
java.lang.String |
|
getVM |
sun.jvm.hotspot.runtime.VM |
static: VM类singgleton实例 |
getBytes |
sun.jvm.hotspot.runtime.Bytes |
|
getThreads |
sun.jvm.hotspot.runtime.Threads |
|
getTypeDataBase |
sun.jvm.hotspot.types.TypeDataBase |
|
getUniverse |
sun.jvm.hotspot.memory.Universe |
|
getObjectHeap |
sun.jvm.hotspot.oops.ObjectHeap |
Heap区对象 |
getSymbolTable |
sun.jvm.hotspot.memory.SymbolTable |
JVM的符号池 |
getStringTable |
sun.jvm.hotspot.memory.StringTable |
JVM的字符串常量池 |
getSystemDictionary |
sun.jvm.hotspot.memory.SystemDictionary |
|
getObjectSynchronizer |
sun.jvm.hotspot.runtime.ObjectSynchronizer |
|
getJNIHandles |
sun.jvm.hotspot.runtime.JNIHandles |
|
getInterpreter |
sun.jvm.hotspot.interpreter.Interpreter |
|
getStubRoutines |
sun.jvm.hotspot.runtime.StubRoutines |
|
getVMRegImplInfo |
sun.jvm.hotspot.code.VMRegImpl |
|
getCodeCache |
sun.jvm.hotspot.code.CodeCache |
|
getRuntime1 |
sun.jvm.hotspot.c1.Runtime1 |
|
getDebugger |
sun.jvm.hotspot.debugger.JVMDebugger |
|
getRevPtrs |
sun.jvm.hotspot.utilities.ReversePtrs |
|
getCommandLineFlags |
sun.jvm.hotspot.runtime.VM$Flag[] |
JVM的各种参数 |
getSystemProperties |
java.util.Properties |
System.getProperties()的各种参数 |
- sun.jvm.hotspot.utilities.*
- CStringUtilities
- ObjectReader
- SystemDictionaryHelper
- sun.jvm.hotspot.oops.*
Visitors:
sun.jvm.hotspot.asm.InstructionVisitor
public interface InstructionVisitor {
sun.jvm.hotspot.code.CodeCacheVisitor
public interface CodeCacheVisitor {
sun.jvm.hotspot.compiler.OopMapVisitor
public interface OopMapVisitor {
sun.jvm.hotspot.debugger.cdbg.LineNumberVisitor
public interface LineNumberVisitor {
sun.jvm.hotspot.debugger.cdbg.ObjectVisitor
public interface ObjectVisitor {
sun.jvm.hotspot.debugger.cdbg.TypeVisitor
public interface TypeVisitor {
sun.jvm.hotspot.interpreter.BytecodeVisitor
public interface BytecodeVisitor {
sun.jvm.hotspot.memory.StringTable
public interface StringVisitor {
sun.jvm.hotspot.memory.SymbolTable
public interface SymbolVisitor {
sun.jvm.hotspot.memory.SystemDictionary
public static interface ClassVisitor {
public static interface ClassAndLoaderVisitor {
sun.jvm.hotspot.oops.HeapVisitor
public interface HeapVisitor {
sun.jvm.hotspot.oops.OopVisitor
public interface OopVisitor {
sun.jvm.hotspot.oops.RawHeapVisitor
public interface RawHeapVisitor extends AddressVisitor {
sun.jvm.hotspot.runtime.AddressVisitor
public interface AddressVisitor {
sun.jvm.hotspot.runtime.PerfMemory
public static interface PerfDataEntryVisitor {
sun.jvm.hotspot.utilities.soql.ObjectVisitor
public interface ObjectVisitor {
Sample:
private void readSystemProperties() {
InstanceKlass systemKls = getSystemDictionary().getSystemKlass();
systemKls.iterate(new DefaultOopVisitor() {
ObjectReader objReader = new ObjectReader();
public void doOop(sun.jvm.hotspot.oops.OopField field, boolean isVMField) {
if (field.getID().getName().equals("props")) {
try {
sysProps = (Properties) objReader.readObject(field.getValue(getObj()));
} catch (Exception e) {
if (Assert.ASSERTS_ENABLED) {
e.printStackTrace();
}
}
}
}
}, false);
}
参数资料
[1]. openjdk-6-src-b20-21_jun_2010.tar.gz
[2]. http://openjdk.java.net/groups/hotspot/docs/Serviceability.html
[3]. http://rednaxelafx.iteye.com/blog/730461