Ark*_*tos 6 java objectsize memory-layout
这是在Java 6内存模型之后.在32位JVM中,对象的浅大小是
8 bytes (object header) + total of all instance variables + padding (optional)
Run Code Online (Sandbox Code Playgroud)
如果前两个术语没有加到8的倍数,则会有填充.
在64位JVM中,Shallow大小为
16 bytes (object header) + total of all instance variables + padding (optional)
Run Code Online (Sandbox Code Playgroud)
我的理解是这个Object头由2个单词组成(oracle hotspot VM)
在32位JVM上,对象头= 2*32位= 64位=
64位JVM上的8个字节,对象头= 2*64位= 128位= 16个字节
但使用CompressedOops,3低阶位被截断,因此应回8个字节在64位JVM对堆小于32场音乐会
但是当我使用JOL(Java对象布局)测试对象布局时,它显示了12个字节的Object头.
测试代码
public class App {
public static void main( String[] args )
{
System.out.println(System.getProperty("java.version"));
System.out.println(VMSupport.vmDetails());
System.out.println(ClassLayout.parseClass(A.class).toPrintable());
}
}
class A {
int a;
}
Run Code Online (Sandbox Code Playgroud)
产量
1.8.0_05
Running 64-bit HotSpot VM.
Using compressed references with 3-bit shift.
Objects are 8 bytes aligned.
Field sizes by type: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
Array element sizes: 4, 1, 1, 2, 2, 4, 4, 8, 8 [bytes]
com.layout.test.jolTesting.A object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 12 (object header) N/A
12 4 int A.a N/A
Instance size: 16 bytes (estimated, the sample instance is not available)
Space losses: 0 bytes internal + 0 bytes external = 0 bytes total
Run Code Online (Sandbox Code Playgroud)
我在这里缺少什么,增加了额外的4个字节?
据我所知,发生这种情况是因为,与 klass 词相反,标记词不是使用CompressedOops进行编码的。
所以 4 个字节(64 位压缩 klass 字)+ 8 个字节(标记字)= 12 个字节(标头)
| 归档时间: |
|
| 查看次数: |
1058 次 |
| 最近记录: |