読者です 読者をやめる 読者になる 読者になる

HSDB CLIを使ってJavaオブジェクトを調べる

このへん参照してやった。
http://www.oracle.com/webfolder/technetwork/jp/javamagazine/Java-JA12-architect-bajaj.pdf



事前準備

export SA_JAVA=/Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java


Javaのプロセスを調べる

$ jps
17968 GradleDaemon
17971 DemoApplication
17956 GradleWrapperMain
17800 RemoteMavenServer
17998 Jps


コアダンプを取得

$ sudo gcore -v -o core.17971 17971


HSDB CLIを起動

java -Dsun.jvm.hotspot.debugger.useProcDebugger=true -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/lib/sa-jdi.jar sun.jvm.hotspot.CLHSDB


取得したコアダンプをアタッチ

hsdb> attach /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home/bin/java core.17971
Opening core file, please wait...


Javaオブジェクトを調査

hsdb> class java.lang.Object
java/lang/Object @0x00000007c0000f28
hsdb> inspect 0x00000007c0000f28
Type is InstanceKlass (size of 440)
juint Klass::_super_check_offset: 40
Klass* Klass::_secondary_super_cache: Klass @ null
Array<Klass*>* Klass::_secondary_supers: Array<Klass*> @ 0x000000011c04f088
Klass* Klass::_primary_supers[0]: Klass @ 0x00000007c0000f28
oop Klass::_java_mirror: Oop for java/lang/Class @ 0x00000006c00007f0 Oop for java/lang/Class @ 0x00000006c00007f0
jint Klass::_modifier_flags: 1
Klass* Klass::_super: Klass @ null
Klass* Klass::_subklass: Klass @ 0x00000007c036ba18
jint Klass::_layout_helper: 16
Symbol* Klass::_name: Symbol @ 0x00000001019160b0
AccessFlags Klass::_access_flags: 553648161
markOop Klass::_prototype_header: 5
Klass* Klass::_next_sibling: Klass @ null
u8 Klass::_trace_id: 589824
Klass* InstanceKlass::_array_klasses: Klass @ 0x00000007c00117a8
Array<Method*>* InstanceKlass::_methods: Array<Method*> @ 0x000000011c04f3d0
Array<Method*>* InstanceKlass::_default_methods: Array<Method*> @ null
Array<Klass*>* InstanceKlass::_local_interfaces: Array<Klass*> @ 0x000000011c04f088
Array<Klass*>* InstanceKlass::_transitive_interfaces: Array<Klass*> @ 0x000000011c04f088
Array<u2>* InstanceKlass::_fields: Array<u2> @ 0x000000011c04f3b8
u2 InstanceKlass::_java_fields_count: 0
ConstantPool* InstanceKlass::_constants: ConstantPool @ 0x000000011c04f0f8
ClassLoaderData* InstanceKlass::_class_loader_data: ClassLoaderData @ 0x00007fd16c60d470
u2 InstanceKlass::_source_file_name_index: 48
char* InstanceKlass::_source_debug_extension: char @ null
Array<jushort>* InstanceKlass::_inner_classes: Array<jushort> @ 0x000000011c04f058
int InstanceKlass::_nonstatic_field_size: 0
int InstanceKlass::_static_field_size: 0
u2 InstanceKlass::_static_oop_field_count: 0
int InstanceKlass::_nonstatic_oop_map_size: 0
bool InstanceKlass::_is_marked_dependent: 0
u2 InstanceKlass::_minor_version: 0
u2 InstanceKlass::_major_version: 52
u1 InstanceKlass::_init_state: 4
Thread* InstanceKlass::_init_thread: Thread @ 0x00007fd16e00a800
int InstanceKlass::_vtable_len: 5
int InstanceKlass::_itable_len: 2
u1 InstanceKlass::_reference_type: 0
OopMapCache* InstanceKlass::_oop_map_cache: OopMapCache @ 0x00007fd16c4cd270
JNIid* InstanceKlass::_jni_ids: JNIid @ null
nmethod* InstanceKlass::_osr_nmethods_head: nmethod @ null
BreakpointInfo* InstanceKlass::_breakpoints: BreakpointInfo @ null
u2 InstanceKlass::_generic_signature_index: 0
jmethodID* InstanceKlass::_methods_jmethod_ids: jmethodID @ null
u2 InstanceKlass::_idnum_allocated_count: 14
Annotations* InstanceKlass::_annotations: Annotations @ null
nmethodBucket* InstanceKlass::_dependencies: nmethodBucket @ null
Array<int>* InstanceKlass::_method_ordering: Array<int> @ 0x000000011c04f040
Array<int>* InstanceKlass::_default_vtable_indices: Array<int> @ null