当前位置:网站首页>JVM对象组成和存储
JVM对象组成和存储
2022-06-27 05:57:00 【季风泯灭的季节】
一、对象的创建过程

一个对象的创建过程大致可分为一下几步:
1.类加载检查:
- 当使用 Serial、ParNew 等带压缩整理过程的收集器时,系统采用的分配算法是指针碰撞,既简单又高效
- 而当使用 CMS 这种基于清除(Sweep)算法的收集器时,理论上就只能采用较为复杂的空闲列表来分配内存

5.执行<init>方法
执行<init>方法,即类的构造方法,对象按照程序员的意愿进行初始化。
二、对象大小与指针压缩
<dependency>
<groupId>org.openjdk.jol</groupId>
<artifactId>jol‐core</artifactId>
<version>0.9</version>
</dependency> import org.openjdk.jol.info.ClassLayout;
/**
* 计算对象大小
*/
public class JOLSample {
public static void main(String[] args) {
ClassLayout layout = ClassLayout.parseInstance(new Object());
System.out.println(layout.toPrintable());
System.out.println();
ClassLayout layout1 = ClassLayout.parseInstance(new int[]{});
System.out.println(layout1.toPrintable());
System.out.println();
ClassLayout layout2 = ClassLayout.parseInstance(new A());
System.out.println(layout2.toPrintable());
}
// ‐XX:+UseCompressedOops 默认开启的压缩所有指针
// ‐XX:+UseCompressedClassPointers 默认开启的压缩对象头里的类型指针Klass Pointer
// Oops : Ordinary Object Pointers
public static class A {
//8B mark word
//4B Klass Pointer 如果关闭压缩‐XX:‐UseCompressedClassPointers或‐XX:‐UseCompressedOops,则占用8B
int id; //4B
String name; //4B 如果关闭压缩‐XX:‐UseCompressedOops,则占用8B
byte b; //1B
Object o; //4B 如果关闭压缩‐XX:‐UseCompressedOops,则占用8B
}
}
运行结果:
java.lang.Object object internals:
OFFSET SIZE TYPE DESCRIPTION VALUE
0 4 (object header) 01 00 00 00 (00000001 00000000 00000000 00000000) (1) //mark word
4 4 (object header) 00 00 00 00 (00000000 00000000 00000000 00000000) (0) //mark word
8 4 (object header) e5 01 00 f8 (11100101 00000001 00000000 11111000) (‐134217243) //Klass Pointer
12 4 (loss due to the next object alignment)
Instance size: 16 bytes 43 Space losses: 0 bytes internal + 4 bytes external = 4 bytes 三、对象内存分配

public User test1() {
User user = new User();
user.setId(1);
user.setName("zhuge");
//TODO 保存到数据库
return user;
}
public void test2() {
User user = new User();
user.setId(1);
user.setName("zhuge");
//TODO 保存到数据库
} 
边栏推荐
- 【QT小记】QT中正则表达式QRegularExpression的基本使用
- OpenCV的轮廓检测和阈值处理综合运用
- 【QT小记】QT元对象系统简单认识
- The SCP command is used in the expect script. The perfect solution to the problem that the SCP command in the expect script cannot obtain the value
- Two position relay xjls-8g/220
- 【FPGA】基于bt1120时序设计实现棋盘格横纵向灰阶图数据输出
- Program ape learning Tiktok short video production
- cpu-z中如何查看内存的频率和内存插槽的个数?
- How win 10 opens the environment variables window
- 多线程基础部分Part3
猜你喜欢

汇编语言-王爽 第9章 转移指令的原理-笔记

Free SSH and telnet client putty

Dual position relay dls-34a dc0.5a 220VDC

Nlp-d62-nlp competition d31 & question brushing D15

Asp.Net Core6 WebSocket 简单案例

Formation and release of function stack frame

Junda technology - centralized monitoring scheme for multi brand precision air conditioners
![[FPGA] design and implementation of frequency division and doubling based on FPGA](/img/84/75d473d3d8e670260ba16d06705c2f.png)
[FPGA] design and implementation of frequency division and doubling based on FPGA

Multithreading basic part2

C语言练手小项目(巩固加深知识点理解)
随机推荐
多线程基础部分Part 1
Assembly language - Wang Shuang Chapter 3 notes and experiments
Double position relay jdp-1440/dc110v
Free SSH and telnet client putty
Webrtc series - Nomination and ice of 7-ice supplement for network transmission_ Model
Luogu p2939 [usaco09feb]revamping trails G
软件测试年终总结报告模板
Spark's projection
函数栈帧的形成与释放
Neo4j database export
leetcode299周赛记录
Senior [Software Test Engineer] learning route and necessary knowledge points
[collection] Introduction to basic knowledge of point cloud and functions of point cloud catalyst software
Leetcode298 weekly race record
Two position relay rxmvb2 r251 204 110dc
693. alternate bit binary number
爬虫学习5---反反爬之识别图片验证码(ddddocr和pytesseract实测效果)
竣达技术丨多品牌精密空调集中监控方案
Spark 之 WholeStageCodegen
微信小程序刷新当前页面