当前位置:网站首页>JVM中堆概念
JVM中堆概念
2022-07-04 07:30:00 【xmh-sxh-1314】
一.堆的概述
一个JVM实例只有一个堆内存,堆也是Java内存管理的核心区域,堆在JVM启动的时候创建,其空间大小也被创建,是JVM中最大的一块内存空间,所有线程共享Java堆,物理上不连续的逻辑上连续的内存空间,几乎所有的实例都在这里分配内存,在方法结束后,堆中的对象不会马上删除,仅仅在垃圾收集的时候被删除,堆是GC(垃圾收集器)执行垃圾回收的重点区域。
二.堆空间细分
Java7及以前将堆空间逻辑上分成三部分:新生区+养老区+永久代
Java8及以后将堆内存逻辑上分为:新生区+养老区+元空间
新生代:
1.新生代使用了复制算法
2.新生代为gc的重点对象,经官方测试70%对象都生命周期都会在新生代中完结
3.新生代又分为了eden、survivor1、survivor2,对象创建先放在eden中,经过一定时间还幸存就会放在幸存者区
4.内存比例分默认为:8:1:1
5.新生代收集器:Minor GC/Young GC
eden(新生区)
当初始加载对象时会进入新生区
survivor(幸存区)
幸存区又分为from 和 to —谁为空谁为to ,始终都会有一个区域为空。
幸存区不会主动进行垃圾回收,只会eden回收时才会附带进行gc
当在幸存区中的阈值达到了15后(默认15可修改)会自动进入老年代
当新生区(eden)出现了内存不足时,会进行YGC,那么会将没有指针的对象回收,还有指针引向的对象放入survivor1或者survivor2区域中,eden清空,数据放入一个survivor中。—当第二次进行gc那么会将eden数据放入另一个空的survivor中,并且将当前survivor中有效数据,放入空的survivor中,一次类推。
老年代
1.较大的对象数据会放入老年代
2.年代的数据都是相对于持久的不会频繁的gc
3.(MajorGC / Old GC) 在进行majorgc时会至少进行一次minorGc ,而且majorgc的效率是比minorGc 慢10倍的
4.老年代收集器:MajorGC / Old GC 要区分与Full GC
在一个对象进入内存时 会进入eden,如果满了(YGC进行回收没有引用的,如果还有引用的)会放入s1或者s0这就涉及到to from哪个为空就是to,(下次eden再次满了会将有数据的【举例s1】中 的数据放入s0,并且进行迭代版本)以此类推,当某个对象迭代阈值的次数达到默认15此后,(当然也会有特殊的优化:如当survivor区域中相同年龄的内存总和大于survivor的一半内存,会将大于等于平均年龄的对象提前放入老年代)会放入老年代 关于YGC 全程(YoungGC) 也可以为(Minor GC) s1,0是不会有单独的gc回收只会被动的依赖于eden的gc当eden进行gc时会自动回收s1,s0
yangGC只会在eden区满的时候进行,不会在survivor区满的时候进行,eden区GC时也会把survivor区进行GC,当survivor中age=15时会将数据放入老年区。
三为什么分代
四内存分配策略(或对象提升规则)
如果对象在EDEN出生并且经过一次MinnorGC后依然存活,并且能被Survivor容纳的话,将会被放在幸存者区,并将对象年龄设为1,每熬过一次MinnorGC,age增加一岁,当age增加到15时,会被放入老年代
五.TLAB
六逃逸分析
什么是逃逸?
也就是如果在方法内创建对象,并且return进行传出,或者赋值到外部的变量,那么就进行了逃逸。
-XX:+DoEscapeAnalysis (JDK1.8之后默认开启)
-XX:+DoEscapeAnalysis(关闭)
逃逸分析包括以下
栈上分配
也就是将对象直接分配到栈上,跟随栈的消亡而消亡,减少了gc(栈中没有gc),提高了性能、速度。
同步省略
因为是每个栈独有的,一个栈也就是一个线程所以不存在同步安全的问题。
分离对象或者标量替换
扩充:一个类代表一个:聚合量,标量是无法分析的最小数据,聚合量可以分析为标量,也就是分析属性
也就是当加载一个pojo类时,不会创建对象而是,标量替换进行分析成一个个小的属性,减少了内存,提高了性能。
但是基于hotSpot 虚拟机这项技术并不成熟,因为还需要进行判断是否 属于逃逸,如果没有逃逸,可能会浪费了判断的时间等一些问题。
但是最后标量替换还是引用到了hotSpot虚拟机中
边栏推荐
- Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg
- Zephyr learning notes 1, threads
- [C language] open the door of C
- Blog stop statement
- Cell reports: Wei Fuwen group of the Institute of zoology, Chinese Academy of Sciences analyzes the function of seasonal changes in the intestinal flora of giant pandas
- Why does the producer / consumer mode wait () use while instead of if (clear and understandable)
- How to buy financial products in 2022?
- University stage summary
- Zephyr 学习笔记2,Scheduling
- This article is enough for learning advanced mysql
猜你喜欢

Master-slave replication principle of MySQL database
![SQL foundation 9 [grouping data]](/img/8a/a72941d8c3413316b063033a1b5038.jpg)
SQL foundation 9 [grouping data]

BUUCTF(4)

What are the work contents of operation and maintenance engineers? Can you list it in detail?

Crawler (III) crawling house prices in Tianjin

Rhcsa day 3

Text processing function sorting in mysql, quick search of collection

Splicing plain text into JSON strings - easy language method

Improve the accuracy of 3D reconstruction of complex scenes | segmentation of UAV Remote Sensing Images Based on paddleseg

神经网络入门(下)
随机推荐
Rapidjson reading and writing JSON files
win10微软拼音输入法输入文字时候下方不出现中文提示
Zephyr Learning note 2, Scheduling
Master-slave replication principle of MySQL database
Blog stop statement
电脑通过Putty远程连接树莓派
The IP bound to the socket is inaddr_ The meaning of any htonl (inaddr_any) (0.0.0.0 all addresses, uncertain addresses, arbitrary addresses)
Technical experts from large factories: common thinking models in architecture design
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
Would you like to go? Go! Don't hesitate if you like it
2022-021rts: from the second half of the year
JVM -- class loading process and runtime data area
Detailed introduction to the big changes of Xcode 14
Boosting the Performance of Video Compression Artifact Reduction with Reference Frame Proposals and
L1-022 odd even split (10 points)
Blue Bridge Cup Quick sort (code completion)
Take you to master the formatter of visual studio code
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
[Android reverse] function interception (use cache_flush system function to refresh CPU cache | refresh CPU cache disadvantages | recommended time for function interception)
Zephyr 学习笔记2,Scheduling