当前位置:网站首页>jvm原理
jvm原理
2022-07-28 09:57:00 【爱分享的驰哥】
一、类加载
1、启动类加载器
扩展类加载器
应用类加载器:用户自定义类加载
2、双亲委派:比如用户自定义类加载的时候会向上级去请求,一直到启动类加载器加载,如果启动类加载器不能完成加载任务,就还是交给第一个请求的类加载加载(这里是应用类加载器)。这样做的好处是,同一个类被不同类加载器加载之后,并不是同一个类了,会造成对这些类管理的杂乱,而如果都由启动类加载器的java.lang.Object类生成的在同一个Object下都是同一个类,便于管理。
二、gc垃圾回收
(参考 https://www.sohu.com/a/235928510_100123073)
三个角度来了解gc:
1jvm怎么确定哪些对象应该进行回收 ?
对象是否会被回收的两个经典算法:
引用计数法(未被引用,如果是循环引用,就不能解决这个问题,比如a,b,a中调用b,b调用a)
*可达性分析算法(虚拟机中用的是有向图,程序把所有的引用关系看作一张图,通过一系列的名为GC Roots的对象作为起始点,从这些节点开始向下搜索,搜索所走过的路径称为引用链。当一个对象到 GC Roots 没有任何引用链相连(就是从 GC Roots 到这个对象不可达)时,则证明此对象是不可用的。 如图:)
2jvm会在什么时候进行垃圾回收的动作 ?
答:1会在cpu空闲的时候自动进行回收 2在堆内存存储满了之后 3主动调用System.gc()后尝试进行回收
3jvm到底是怎么清除垃圾对象的?
算法又有四个:标记-清除算法 ,复制算法 ,标记-整理算法 ,分代收集算法(新生代,老年代,永久代(1.8及以后叫做元数据区))
1、System.gc()和Runtime.gc()会做什么事情?
这两个方法用来提示JVM要进行垃圾回收。但是,立即开始还是延迟进行垃圾回收是取决于JVM的。
2、但有一种JNI(Java Native Interface)调用non-Java程序(C或C++),finalize()的工作就是回收这部分的内存。
3、.如果对象的引用被置为null,垃圾收集器是否会立即释放对象占用的内存?
不会,在下一个垃圾回收周期中,这个对象将是可被回收的。
边栏推荐
- 排序——快速排序(快慢指针实现)
- Holy Grail of web and double wing layout, float, clear, both
- Introduction to timebasedrollingpolicy
- 为报复公司解雇,我更改了项目的所有代码注释!
- API 网关 APISIX 在Google Cloud T2A 和 T2D 的性能测试
- The blind box of super primitive series will be launched soon, and platofarm will enable more rights and interests
- In hot weather, the line of defense for safe production was strengthened, and Guangzhou Haizhu District carried out emergency drills for gas stations
- 基于docker安装MySQL
- 【FPGA教程案例41】图像案例1——通过verilog读取图片
- Irregular area of OSPF, LSA and serial number
猜你喜欢
![[ESP32][esp-idf][LVGL7.9] 使用oled iic编译失败](/img/16/e5aa43df6ef9bdbc173fa547c85559.png)
[ESP32][esp-idf][LVGL7.9] 使用oled iic编译失败

Thinking and summary of technical personnel | R & D Efficiency
![[esp32][esp idf] esp32s3 quickly build lvglv7.9](/img/39/8efef047d0a9223b97819a54b5edf8.png)
[esp32][esp idf] esp32s3 quickly build lvglv7.9

TCP Basics

OSPF expansion configuration, routing principles, anti ring and re release

Arthas tutorial

我用小程序容器让移动研发效率提升了5倍!

Why should I take the first-class constructor examination? How high is the gold content of the first-class Constructor Certificate?

选择供应商服务系统,是大健康产业企业迈向数字化转型的第一步
![[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals](/img/bf/0a968064a8f7c11b86a2a2820208e6.png)
[esp32][esp idf] ap+sta realizes wireless bridging and transferring WiFi signals
随机推荐
谈谈基于JS实现阻止别人调试通过控制台调试网站的问题
arthas使用教程
腾讯技术专家:解密亿级用户产品 微信、QQ、王者荣耀...全面上云实践!
【JZOF】15二进制中1的位数
双指针技巧
建筑建材行业B2B电子商务网站方案:赋能建材企业转型升级,实现降本提效
The blind box of super primitive series will be launched soon, and platofarm will enable more rights and interests
PHP connection MySQL native code
LIBCMTD.lib
Consul
Introduction to thresholdfilter
On July 13, 2021, we collapsed like this
ADVANCE.AI出海指南助力企业出海印尼,掌握东南亚市场半边天
_HUGE and __IMP__HUGE in “math.h“
leetcode——旋转数组的最小数字
Illustrate three mainstream enterprise architecture models (recommended collection!)
小黑重新站起来看leetcode:653. 两数之和 IV - 输入 BST
线程同步volatile与synchronized详解
【FPGA教程案例41】图像案例1——通过verilog读取图片
13 probability distributions that must be understood in deep learning