Last active
January 1, 2016 06:19
-
-
Save caoxudong/8104610 to your computer and use it in GitHub Desktop.
hotspot中对象的内存排布
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
hsdb> mem 0x23c02cc8 12 | |
0x23c02cc8: 0x00000001 (标记字) | |
0x23c02ccc: 0x33ba2ca0 (类对象地址) | |
0x23c02cd0: 0x00000003 (属性域l) | |
0x23c02cd4: 0x00000000 | |
0x23c02cd8: 0x66666666 (属性域d) | |
0x23c02cdc: 0x40166666 | |
0x23c02ce0: 0x00000001 (属性域i) | |
0x23c02ce4: 0x00040032 (属性域c和s) | |
0x23c02ce8: 0x00000038 (属性域cc) | |
0x23c02cec: 0x23c02cf8 (Object数组的地址) | |
0x23c02cf0: 0x23c02d10 (Object对象的地址) | |
0x23c02cf4: 0x23c02eb8 (Integer对象的地址) | |
从上面的内容可以看到,jvm重新排布了对象的属性域,将对象引用都放到了最后,并且合并了shrot和char类型的属性域。 | |
hsdb> mem 0x23c02cf8 6 | |
0x23c02cf8: 0x00000001 (标记字) | |
0x23c02cfc: 0x38bc50a0 (类对象地址) | |
0x23c02d00: 0x00000003 (数组长度) | |
0x23c02d04: 0x00000000 (数组元素0) | |
0x23c02d08: 0x00000000 (数组元素1) | |
0x23c02d0c: 0x00000000 (数组元素2) | |
从上面的内容可以看到,在数组对象中,数组长度是紧跟在类对象后面的。 |
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
Intel(R) Core(TM) i3 CPU M 380 @ 2.53GHz | |
2.00 GB(1.74 GB可用) | |
32位操作系统 | |
java version "1.7.0_07" | |
Java(TM) SE Runtime Environment (build 1.7.0_07-b10) | |
Java HotSpot(TM) Client VM (build 23.3-b01, mixed mode, sharing) |
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
hsdb> universe | |
Heap Parameters: | |
Gen 0: eden [0x23b80000,0x23c16bb8,0x23fd0000) space capacity = 4521984, 13.653299082880435 used | |
from [0x23fd0000,0x23fd0000,0x24050000) space capacity = 524288, 0.0 used | |
to [0x24050000,0x24050000,0x240d0000) space capacity = 524288, 0.0 usedInvocations: 0 | |
Gen 1: old [0x290d0000,0x290d0000,0x29b80000) space capacity = 11206656, 0.0 usedInvocations: 0 | |
perm [0x33b80000,0x33ba3080,0x34780000) space capacity = 12582912, 1.1403401692708333 used ro space: [0x37b80000,0x38004650,0x38580000) space capacity = 10485760, 45.171661376953125 used, rw space: [0x38580000,0x38c07e58,0x39180000) space capacity = 12582912, 54.42371368408203 usedInvocations:0 | |
hsdb> scanoops 0x23b80000 0x23c16bb8 Test | |
0x23c02cc8 Test | |
hsdb> inspect 0x23c02cc8 | |
instance of Oop for Test @ 0x23c02cc8 @ 0x23c02cc8 (size = 48) | |
_mark: 1 | |
_metadata._klass: InstanceKlass for Test @ 0x33ba2ca0 Oop @ 0x33ba2ca0 | |
objectArray: ObjArray @ 0x23c02cf8 Oop for [Ljava/lang/Object; @ 0x23c02cf8 | |
obj: Oop for java/lang/Object @ 0x23c02d10 Oop for java/lang/Object @ 0x23c02d10 | |
i: 1 | |
c: '2' | |
l: 3 | |
s: 4 | |
d: 5.6 | |
integer: Oop for java/lang/Integer @ 0x23c02eb8 Oop for java/lang/Integer @ 0x23c02eb8 | |
cc: '8' | |
hsdb> mem 0x23c02cc8 12 | |
0x23c02cc8: 0x00000001 | |
0x23c02ccc: 0x33ba2ca0 | |
0x23c02cd0: 0x00000003 | |
0x23c02cd4: 0x00000000 | |
0x23c02cd8: 0x66666666 | |
0x23c02cdc: 0x40166666 | |
0x23c02ce0: 0x00000001 | |
0x23c02ce4: 0x00040032 | |
0x23c02ce8: 0x00000038 | |
0x23c02cec: 0x23c02cf8 | |
0x23c02cf0: 0x23c02d10 | |
0x23c02cf4: 0x23c02eb8 | |
hsdb> inspect 0x23c02cf8 | |
instance of ObjArray @ 0x23c02cf8 @ 0x23c02cf8 (size = 24) | |
_mark: 1 | |
_metadata._klass: ObjArrayKlass for InstanceKlass for java/lang/Object @ 0x38bc50a0 Oop @ 0x38bc50a0 | |
0: null null | |
1: null null | |
2: null null | |
hsdb> mem 0x23c02cf8 6 | |
0x23c02cf8: 0x00000001 | |
0x23c02cfc: 0x38bc50a0 | |
0x23c02d00: 0x00000003 | |
0x23c02d04: 0x00000000 | |
0x23c02d08: 0x00000000 | |
0x23c02d0c: 0x00000000 |
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
class Test{ | |
private static Object[] staticObjectArray = new Object[3]; | |
private Object[] objectArray = new Object[3]; | |
private Object obj = new Object(); | |
private int i = 1; | |
private char c = '2'; | |
private long l = 3L; | |
private short s = 4; | |
private double d = 5.6; | |
private Integer integer = new Integer(7); | |
private char cc = '8'; | |
public static int foo(int a) throws Exception{ | |
while(a != 0){ | |
Thread.sleep(500); | |
a --; | |
System.out.println(a); | |
} | |
return a; | |
} | |
public static void main(String[] args) throws Exception{ | |
Test t = new Test(); | |
while (true) { | |
foo(10); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment