当前位置:网站首页>Pointer compression for JVM
Pointer compression for JVM
2022-06-27 01:24:00 【Tangbohu points mosquito repellent incense DW】
After introducing the related contents of memory alignment , Let's introduce the compression pointer often mentioned earlier . Can pass JVM Parameters XX:+UseCompressedOops Turn on , Of course, the default is on .
Before starting this section , Let's start with a question , That's why compressed pointers are used ??
Suppose we are now preparing to 32 The bit system switches to 64 Bit system , At first, we might expect the system performance to improve immediately , But this may not be the case .
stay JVM The main reason for performance degradation in is 64 In bit system Object reference . We mentioned earlier ,64 References to objects and type pointers in the bit system 64 bit That is to say 8 Bytes .
This leads to the 64 The memory space occupied by object references in the bit system is 32 Twice the size in a bit system , Therefore, it indirectly leads to 64 More memory consumption and more frequent GC happen ,GC The amount of CPU The more time , So our application takes up CPU The less time you have .
Another is that the reference of the object becomes larger , that CPU There are relatively few cacheable objects , Increased access to memory . Combining the above points leads to the decline of system performance .
On the other hand , stay 64 The addressing space of memory in bit system is 2^48 = 256T, In reality, do we really need such a large addressing space ?? It doesn't seem necessary ~~
So we have new ideas : So should we switch back to 32 What about the bit system ?
If we switch back to 32 Bit system , How can we solve it in 32 There are more than... In the bit system 4G Memory addressing space ? Because now 4G The memory size of is obviously not enough for current applications .
I think the above questions , It was also in the beginning JVM Developers need to face and solve , Of course, they also gave a very perfect answer , That's it Using compressed pointers, you can 64 Use... In a bit system 32 Bit object reference gets more than 4G Memory addressing space .
7.1 How do you compress pointers ?
Remember what we mentioned earlier in the introduction to alignment padding and memory alignment , stay Java The starting address of the object in the virtual machine heap must be aligned to 8 Multiple Do you ?
Since the starting addresses of objects in the heap are aligned to 8 Multiple , So the object reference is when the compressed pointer is turned on 32 The last three bits of a binary are always 0( Because they can always be 8 to be divisible by ).
since JVM Having known the memory addresses of these objects, the last three digits are always 0, So these meaningless 0 There is no need to continue storing in the heap . contrary , We can use storage 0 the 3 position bit Store some meaningful information , So we have more 3 position bit Address space of .
So when storing ,JVM Or in accordance with 32 Bits to store , But the last three bits were originally used to store 0 Of bit Now it is used by us to store meaningful address space information .
When addressing ,JVM Will this 32 Bit object reference Move left 3 position ( The last three make up 0). This leads to when the compression pointer is turned on , We were 32 Bit memory addressing space becomes 35 position . Addressable memory space becomes 2^32 * 2^3 = 32G.

Compression pointer .png
thus ,JVM Although some additional bit operations are performed, it greatly improves the addressing space , And reduce the memory occupied by object references by half , Save a lot of space . Besides, these bit operations are for CPU It is a very easy and lightweight operation
Through the principle of compressing pointers, I found Another important reason for memory alignment Is to align memory to 8 Multiple , We can do it in 64 Compressed pointers are used in bit systems through 32 Promote the address bit of the object to the address space 32G.
from Java7 Start , When maximum heap size Less than 32G When , The compression pointer is turned on by default . But when maximum heap size Greater than 32G When , The compression pointer will close .
So how can we further expand the addressing space when the compressed pointer is turned on ???
7.2 How to further expand the addressing space
As mentioned earlier, we are Java The starting address of objects in the virtual machine heap needs to be adjusted to 8 Multiple , But we can pass this value JVM Parameters -XX:ObjectAlignmentInBytes To change ( The default value is 8). Of course, the value must be 2 Power of power , The value range needs to be in 8 - 256 Between .
Because the object address is aligned to 8 Multiple , There will be more 3 position bit Let's store additional address information , And then 4G Increase the addressing space to 32G.
Same thing , If we were to ObjectAlignmentInBytes The value of is set to 16 Well ?
Object addresses are aligned to 16 Multiple , Then there will be more 4 position bit Let's store additional address information . The address space becomes 2^32 * 2^4 = 64G.
Through the above rules , We can know , stay 64 When the compression pointer is turned on in the bit system , Calculation formula of addressing range :4G * ObjectAlignmentInBytes = Addressing range .
But I don't suggest that you do it rashly , Because it increases ObjectAlignmentInBytes Although it can expand the addressing range , But it may also increase byte padding between objects , As a result, the compressed pointer does not achieve the original effect of saving space .
边栏推荐
- Keepalived 实现 Redis AutoFailover (RedisHA)12
- IIS deploy static web site and FTP service
- Meituan: data management and pit avoidance strategy summarized after stepping on Thunder for several years
- How to convert an old keyboard into a USB keyboard and program it yourself?
- Generate flow chart with code, and how to use markdown
- BS-GX-016基于SSM实现教材管理系统
- 解决STC8G1K08程序不能运行的问题和端口配置
- Topolvm: kubernetes local persistence scheme based on LVM, capacity aware, dynamically create PV, and easily use local disk
- MySQL之账号管理、建库以及四大引擎+案例
- Beyond lithium battery -- the concept of battery in the future
猜你喜欢

可视化介绍 Matplotlib 和 Plotnine

通过Rust语言计算加速技术突破图片识别性能瓶颈

Central Limit Theorem

TopoLVM: 基于LVM的Kubernetes本地持久化方案,容量感知,动态创建PV,轻松使用本地磁盘

Ml: a detailed introduction to the division of the top ten roles, backgrounds, responsibilities and outputs of the machine learning engineering team

Basic introduction to C program structure Preview

Structure the fifth operation of the actual camp module

One click acceleration of Sony camera SD card file copy operation, file operation batch processing tutorial

Amazon ElastiCache 飞速搭建缓存服务集群,这才叫快

Gaussian and Summary Stats
随机推荐
解决STC8G1K08程序不能运行的问题和端口配置
ESP32实验-自建web服务器配网02
Modeling specifications: environment settings
3线spi屏幕驱动方式
用代码生成流程图,Markdown的使用方法
在线文本数字识别列表求和工具
Memcached foundation 2
Beyond lithium battery -- the concept of battery in the future
Custom MVC (imported into jar package) + difference from three-tier architecture + reflection + interview questions
ESP32-SOLO开发教程,解决CONFIG_FREERTOS_UNICORE问题
Buuctf PWN write UPS (6)
Statistical Hypothesis Testing
[graduation season] role conversion
Kept to implement redis autofailover (redisha) 11
Play OLED, u8g2 animation, increasing numbers, random triangles, etc
解决unable to create a folder to save the sketch: mkdir sketch
Account management, database building and four engines + cases of MySQL
疫情期间居家办公的总结体会 |社区征文
Weibo comments on high performance and high availability architecture
ArcGIS 镶嵌数据集切片丢失问题处理