当前位置:网站首页>《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 流程图
根据源码梳理可得以下流程图:
如果对你有帮助的话,不要忘了点赞收藏啦!
边栏推荐
猜你喜欢

¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!

某次比赛wp

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

sklearn 高维数据集制作make_circles 和 make_moons

wav文件(波形文件)格式分析与详解

自定义注解之编译时注解(RetentionPolicy.CLASS)

The first techo day Tencent technology open day, 628 waiting for you!

【OpenCV】—离散傅里叶变换
![[final review notes] digital logic](/img/57/4431208b1c8b653f5c3f4ff4212cc3.png)
[final review notes] digital logic
![[opencv] - input and output XML and yaml files](/img/4e/7944e205c71246d0b0e3747eefca37.png)
[opencv] - input and output XML and yaml files
随机推荐
C#程序终止问题CLR20R3解决方法
matplotlib 简单逻辑回归可视化
Various synchronous learning notes
1、 Construction of single neural network
Oracle-单行函数大全
Matplotlib plt grid()
View all listening events on the current page by browser
打新债安全性有多高啊
Discrimination of configuration, software configuration items and software configuration management items
Analysis of a video website m3u8 non perceptual encryption
[final review notes] digital logic
atguigu----18-组件
Unity--configurable joint -- a simple tutorial to get you started with configurable joints
Explanation of assertions in JMeter
matplotlib matplotlib中plt.grid()
某视频网站m3u8非感知加密分析
QSS buttons of different styles
2、 Training fashion_ MNIST dataset
C#启动程序传递参数丢失双引号,如何解决?
How to solve the 10061 error of MySQL in Linux