当前位置:网站首页>13 and OOM simulation
13 and OOM simulation
2022-08-03 16:08:00 【jerry_dyy】
通过上文的分析,我们知道:Only possible in the method area(元数据区)and old age may occurOOM,So let's simulate both happening hereOOM的场景.
元数据区发生OOM:
这里我们通过cglibTo continuously create dynamically generated classes to simulate what happens in the metadata areaOOM的场景.
So called dynamically generated classes,That is, the classes are not written by hand.The classes we hand out are all.java,然后会编译为.class,Then it will be loaded into the metadata area by the class loader to become a statically generated class.The dynamically generated classes are in the process of running the system,通过操作、A class that edits the bytecode to generate dynamically.
启动JVMWhen setting the metadata area size:
-XX:MetaspaceSize=10m
-XX:MaxMetaspaceSize=10m
Then write the following code:
public class MetaspaceOOMDemo {
public static void main(String[] args) {
int count = 0;
while (true){
System.out.println("count: " + ++count);
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(Car.class);//To generate one dynamicallyCar类的子类
enhancer.setUseCache(false);//Whether to reuse dynamic classes
enhancer.setCallback(new MethodInterceptor() {
@Override
public Object intercept(Object obj, Method method, Object[] args, MethodProxy proxy) throws Throwable {
if(method.getName().equals("run")){
System.out.println("Safety checks before the car starts");
return proxy.invokeSuper(obj,args);//Specifically to callCarclass method
}else {
return proxy.invokeSuper(obj,args);
}
}
});
Car car = (Car) enhancer.create();//这里通过enhancer生成的car就是一个继承CarObject generated by the dynamic class of the class
car.run();
}
}
}
class Car{
public void run(){
System.out.println("汽车启动,开始行使...");
}
}
Because of the settings in the above codeenhancer.setUseCache(false),So new dynamic classes will be created constantly,These dynamic classes will continue to enter the metadata area,Eventually lead to the metadata areaOOM.
启动,Find out and run to the end246次的时候,发生:java.lang.OutOfMemoryError: Metaspace.Here you can see what happens in the metadata areaOOM,And the program exits directly.
老年代发生OOM:
We simulate the occurrence of the old generation by means of memory leaksOOM.
设置JVM启动参数,Set heap memory to 1MB大小:
-Xms1m –Xmx1m
编写以下代码:
public class HeapOOMDemo {
public static void main(String[] args) {
long count = 0;
List<Object> list = new ArrayList<>();
while (true){
list.add(new Object());
System.out.println("count: " + ++count);
}
}
}
The above code will keep creatingObject对象,and will not be released,Eventually it will be a memory leak problem,lead to heap memoryOOM.
启动,跑到第14053次的时候,发生:java.lang.OutOfMemoryError: Java heap space.堆内存溢出,And the program exits directly.
1、JVM是如何工作的?_jerry_dyy的博客-CSDN博客_jvm是如何运行的
2、JVM的类加载机制_jerry_dyy的博客-CSDN博客
3、JVM内存区域划分_jerry_dyy的博客-CSDN博客_jvm的内存区域划分
4、JVM垃圾回收机制_jerry_dyy的博客-CSDN博客
5、JVM分代模型--新生代 的垃圾回收_jerry_dyy的博客-CSDN博客_jvm新生代划分
6、JVM分代模型--老年代 的垃圾回收_jerry_dyy的博客-CSDN博客
7、常见的垃圾回收器_jerry_dyy的博客-CSDN博客
9、学会查看GC日志_jerry_dyy的博客-CSDN博客
10、摸清JVM运行状况_jerry_dyy的博客-CSDN博客
边栏推荐
- 技术干货|如何将 Pulsar 数据快速且无缝接入 Apache Doris
- STM32的HAL和LL库区别和性能对比
- 扫雷?拿来吧你(递归展开+坐标标记)
- 【Unity入门计划】基本概念(6)-精灵渲染器 Sprite Renderer
- QT QT 】 【 to have developed a good program for packaging into a dynamic library
- 人脸识别损失函数的汇总 | Pytorch版本实现
- 深度学习GPU最全对比,到底谁才是性价比之王?
- 请问大家,MySQL全量怎么样可以提高性能呢?我这里瓶颈是在Source上,在不增加并行度的情况下,
- 红蓝对抗经验分享:CS免杀姿势
- 【Unity入门计划】基本概念(8)-瓦片地图 TileMap 01
猜你喜欢
Daily practice------There are 10 numbers that are required to be output from large to small by selection method
【899. 有序队列】
Spark entry learning-2
"Avnet Embedded Weekly" Issue 276: 2022.07.25--2022.07.31
AI也有健忘症?英国41岁教授专访:解决灾难性遗忘
【数据库数据恢复】SqlServer数据库无法读取的数据恢复案例
JD6606SP5_JD6606SSP_JD6606SASP_JD6621W7百盛新纪元授权代理商
Yii2安装遇到Loading composer repositories with package information
CS免杀姿势
Fortinet产品导入AWS AMI操作文档
随机推荐
JS handwritten call apply bind (detailed) (interview)
MATLAB gcf figure save image with black background/transparent background
How to prevent hacking Windows server security Settings
移动应用出海,你的“网络优化”拖后腿了吗?
扩展欧几里得求逆元实例
全新探险者以40万的产品击穿豪华SUV价格壁垒
Awesome!Coroutines are finally here!Thread is about to be in the past
C#.NET 国密数字信封
ReentrantReadWriteLock详解
How to start an NFT collection
如何将二维空间先验注入到ViT中? UMA&港理工&阿里提出SP-ViT,为视觉Transformer学习2D空间先验知识!...
STM32 GPIO LED和蜂鸣器实现【第四天】
Introduction to spark learning - 1
Why do I strongly recommend using smart async?
How much does Ark Survival Evolved cost?
Basic knowledge points in js - events
袁小林:沃尔沃专注于出行的安全感,并且把它做到极致
面了个腾讯35k出来的,他让我见识到什么叫精通MySQL调优
Small Tools(4) 整合Seata1.5.2分布式事务
美国国防部更“青睐”光量子系统研究路线