当前位置:网站首页>《JVM》对象内存分配的TLAB机制与G1中的TLAB流程
《JVM》对象内存分配的TLAB机制与G1中的TLAB流程
2022-06-25 08:19:00 【快乐的星球】
文章目录
一:重温对象的生命周期
1.1 对象生命周期流程图
1.2 重点强调
对象的finalize()方法只会被调用一次,也就是说对象只能有一次复活机会,但对象的复活会破坏对象的生命周期,干扰了JVM对对象的收集,因此在finalize()方法中一般写对象收集前的资源释放工作。
二: TLAB(内存分配缓冲区)
由上图中的对象的生命周期中,我们了解到了对象在使用前要先进行对象的内存分配与初始化操作,接下来我们讲述对象内存分配的两种策略
2.1 为什么要有TLAB
我们知道对象内存分配时最初考虑在新生代的Eden区为对象分配内存,但堆区是线程共享的区域,在多线程环境下多个线程同时操控同一块内存的现象是普遍的,为了保证对象分配时数据的安全性,我们需要用全局锁来解决多线程同时访问同一块内存的问题,但全局锁会降低效率与程序的吞吐量,为了解决该问题TLAB应运而生。
2.2 TLAB
TLAB对Eden区的内存进行了划分,划分出一小块区域,这块区域称为对象内存分配缓冲区,它为每一个线程都分配了一块空间。
优点:
- 使用TLAB可以避免一系列的线程安全问题。
- 提高了程序运行的效率与吞吐量。
这种使用TLAB进行内存分配的策略称为快速分配策略。
三:G1源码中的TLAB策略
3.1 简介
分配空间时,为了提高JVM的运行效率,应当尽量减少临界区范围,避免全局锁。G1的通常的应用场景中,会存在大量的访问器同时执行,为减少锁冲突,JVM引入了TLAB(线程本地分配缓冲区Thread Local Allocation Buffer)机制。
3.2 流程图
根据源码梳理可得以下流程图:
如果对你有帮助的话,不要忘了点赞收藏啦!
边栏推荐
- Jmeter中的断言使用讲解
- The city chain technology platform is realizing the real value Internet reconstruction!
- matplotlib matplotlib中plt.grid()
- [opencv] - Discrete Fourier transform
- About i/o -- the relationship between memory and CPU and disk
- Sharepoint:sharepoint server 2013 and adrms Integration Guide
- C # startup program loses double quotation marks for parameters passed. How to solve it?
- nodejs 使用Express框架demo
- Are the top ten securities companies at great risk of opening accounts and safe and reliable?
- 某次比赛wp
猜你喜欢
浅谈Mysql底层索引原理
Unity发布webGL的时候JsonConvert.SerializeObject()转换失败
How to design test cases
When unity released webgl, jsonconvert Serializeobject() conversion failed
四、卷积神经网络(Convolution Neural Networks)
[opencv] - Discrete Fourier transform
¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!
Close a thread
LVS-DR模式多网段案例
C language: find all integers that can divide y and are odd numbers, and put them in the array indicated by B in the order from small to large
随机推荐
四、卷积神经网络(Convolution Neural Networks)
打新债安全性有多高啊
声纹技术(六):声纹技术的其他应用
IC研发常用英文术语缩写
mysql之Unknown table ‘COLUMN_STATISTICS‘ in information_schema (1109)
¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!
六级易混词整理
annotation lib 和 processor lib如何引用
对常用I/O模型进行比较说明
微服务调用组件Ribbon底层调用流程分析
matplotlib matplotlib中plt.axis()用法
Where are the hotel enterprises that have been under pressure since the industry has warmed up in spring?
Level 6 easy to mix words
自定义注解之编译时注解(RetentionPolicy.CLASS)
On which platform is it safe to buy shares and open an account? Ask for sharing
Cazy eight trigrams maze of Chang'an campaign
[reinforcement learning notes] common symbols in reinforcement learning
Various synchronous learning notes
[operation tutorial] how does the tsingsee Qingxi video platform import the old database into the new database?
声纹技术(一):声纹技术的前世今生