Last active
July 10, 2022 06:25
-
-
Save rednaxelafx/4986917 to your computer and use it in GitHub Desktop.
Very simple demo of using CLHSDB from HotSpot Serviceability Agent to inspect Java objects and class metadata
This file contains hidden or 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
D:\temp>notepad MysteryBox.java | |
D:\temp>javac MysteryBox.java | |
D:\temp>groovysh | |
Groovy Shell (1.8.4, JVM: 1.7.0_09) | |
Type 'help' or '\h' for help. | |
------------------------------------------------------------------------ | |
groovy:000> new MysteryBox() | |
===> MysteryBox@7a2145e6 | |
groovy:000> quit | |
D:\temp>java -version | |
java version "1.7.0_09" | |
Java(TM) SE Runtime Environment (build 1.7.0_09-b05) | |
Java HotSpot(TM) 64-Bit Server VM (build 23.5-b02, mixed mode) | |
D:\temp> |
This file contains hidden or 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
D:\temp>jps | |
500 Jps | |
9016 GroovyStarter | |
D:\temp>java -cp .;%JAVA_HOME%\lib\sa-jdi.jar sun.jvm.hotspot.CLHSDB | |
hsdb> attach 9016 | |
Attaching to process 9016, please wait... | |
hsdb> universe | |
Heap Parameters: | |
ParallelScavengeHeap [ PSYoungGen [ eden = [0x00000000fd560000,0x00000000fd68e780,0x00000000ff4c0000] , from = [0x00000000ff4c0000,0x00000000ff74e030,0x00000000ff750000] , to = [0x00000000ffd70000,0x00000000ffd70000,0x0000000100000000] ] PSOldGen [ [0x00000000f8000000,0x00000000f8b1bac0,0x00000000fa9b0000] ] PSPermGen [ [0x00000000f2e00000,0x00000000f3bb4c98,0x00000000f42c0000] ] ] hsdb> | |
hsdb> scanoops 0x00000000fd560000 0x00000000fd68e780 MysteryBox | |
0x00000000fd5bbd68 MysteryBox | |
hsdb> inspect 0x00000000fd5bbd68 | |
instance of Oop for MysteryBox @ 0x00000000fd5bbd68 @ 0x00000000fd5bbd68 (size = 40) | |
_mark: 524544239105 | |
x0: 0 | |
x1: 0 | |
y0: false | |
y1: false | |
y2: false | |
y3: false | |
z0: 0 | |
a: [D @ 0x00000000fd5bbd90 Oop for [D @ 0x00000000fd5bbd90 | |
hsdb> inspect 0x00000000fd5bbd90 | |
instance of [D @ 0x00000000fd5bbd90 @ 0x00000000fd5bbd90 (size = 80) | |
_mark: 1 | |
0: 0.0 | |
1: 0.0 | |
2: 0.0 | |
3: 0.0 | |
4: 0.0 | |
5: 0.0 | |
6: 0.0 | |
7: 0.0 | |
hsdb> class MysteryBox | |
MysteryBox @0x00000000f3b14610 | |
hsdb> print 0x00000000f3b14610 | |
public class MysteryBox @0x00000000f3b14610 | |
Super Class | |
public class java.lang.Object @0x00000000f2e02db0 | |
Fields | |
private long x0; (offset = 16) | |
private long x1; (offset = 24) | |
private boolean y0; (offset = 32) | |
private boolean y1; (offset = 33) | |
private boolean y2; (offset = 34) | |
private boolean y3; (offset = 35) | |
private int z0; (offset = 12) | |
private double[] a; (offset = 36) | |
Methods | |
public void <init>() @0x00000000f3b14588; | |
Constant Pool | |
Constant Pool of [public class MysteryBox @0x00000000f3b14610] @0x00000000f3b14350 | |
hsdb> quit | |
D:\temp> |
This file contains hidden or 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
public class MysteryBox { | |
private long x0, x1; | |
private boolean y0, y1, y2, y3; | |
private int z0; | |
private double[] a = new double[8]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment