简单GC具体操作参数查看
代码:
public class HeapTest {
private static final int _1M = 1024 * 1024;
public static void main(String[] args) throws InterruptedException {
System.gc();
byte[] byte1 = new byte[2 * _1M];
byte[] byte2 = new byte[2 * _1M];
byte[] byte3 = new byte[2 * _1M];
byte[] byte4 = new byte[2 * _1M];
byte[] byte5 = new byte[2 * _1M];
byte[] byte6 = new byte[5 * _1M];
byte[] byte7 = new byte[2 * _1M];
System.out.println("asdf");
}
}
注意byte6是5M
vm参数:
-Xms20m
-Xmx20m
-Xmn10m
-verbose:gc
-XX:+PrintGCDetails
-XX:+PrintTenuringDistribution
-XX:+PrintGCTimeStamps
分别打上断点,使用
$ jmap -heap 17432
System.gc
1.049: [GC (System.gc())
Desired survivor size 1048576 bytes, new threshold 7 (max 15)
[PSYoungGen: 6657K->1000K(9216K)] 6657K->1337K(19456K), 0.0015197 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
1.051: [Full GC (System.gc()) [PSYoungGen: 1000K->0K(9216K)] [ParOldGen: 337K->1290K(10240K)] 1337K->1290K(19456K), [Metaspace: 3777K->3777K(1056768K)], 0.0063289 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
GC日志分析
Young GC日志:
Full GC日志:
堆信息:
查看堆信息:
$ jps -l
11120 com.qhong.gc.HeapTest
11652 sun.tools.jps.Jps
18708 com.shitou.Application
11352
18200 org.jetbrains.jps.cmdline.Launcher
13644 org.jetbrains.jps.cmdline.Launcher
jmap:
$ jmap -heap 11120
Attaching to process ID 11120, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.201-b09
using thread-local object allocation.
Parallel GC with 4 thread(s)
Heap Configuration:
MinHeapFreeRatio = 0
MaxHeapFreeRatio = 100 #GC后如果发现空闲堆内存占到整个预估堆内存的N%(百分比)
MaxHeapSize = 20971520 (20.0MB) # 堆最大空闲 jvm参数 -Xms20m
NewSize = 10485760 (10.0MB) # 年轻代空间 jvm参数 -Xmn10m
MaxNewSize = 10485760 (10.0MB) # 年轻代最大空间
OldSize = 10485760 (10.0MB) # 老年代空间 =(等于)堆内存大小 -(减去)年轻代大小
NewRatio = 2
SurvivorRatio = 8 # 年轻代内存又被分成三部分 Eden 空间 80% 而From Survivor 空间 和 To Survivor空间 分别占用10%
MetaspaceSize = 21807104 (20.796875MB) # 设置元空间的最大值 jvm参数 -XX:MaxMetaspaceSize
CompressedClassSpaceSize = 1073741824 (1024.0MB) # 类指针压缩空间大小, 默认为1G
MaxMetaspaceSize = 17592186044415 MB # 是分配给类元数据空间的最大值
G1HeapRegionSize = 0 (0.0MB) # G1区块的大小, 取值为1M至32M. 其取值是要根据最小Heap大小划分出2048个区块
Heap Usage:
PS Young Generation
Eden Space:
capacity = 8388608 (8.0MB)
used = 167792 (0.1600189208984375MB)
free = 8220816 (7.8399810791015625MB)
2.0002365112304688% used
From Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
To Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
PS Old Generation
capacity = 10485760 (10.0MB)
used = 1321344 (1.2601318359375MB)
free = 9164416 (8.7398681640625MB)
12.601318359375% used
2072 interned Strings occupying 186064 bytes.
byte1执行后
Eden Space:
capacity = 8388608 (8.0MB)
used = 2428440 (2.3159408569335938MB)
free = 5960168 (5.684059143066406MB)
28.949260711669922% used
From Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
To Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
PS Old Generation
capacity = 10485760 (10.0MB)
used = 1321480 (1.2602615356445312MB)
free = 9164280 (8.739738464355469MB)
12.602615356445312% used
byte2执行后
Eden Space:
capacity = 8388608 (8.0MB)
used = 4525528 (4.315879821777344MB)
free = 3863080 (3.6841201782226562MB)
53.9484977722168% used
From Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
To Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
PS Old Generation
capacity = 10485760 (10.0MB)
used = 1321344 (1.2601318359375MB)
free = 9164416 (8.7398681640625MB)
12.601318359375% used
byte3执行后
Eden Space:
capacity = 8388608 (8.0MB)
used = 6622696 (6.315895080566406MB)
free = 1765912 (1.6841049194335938MB)
78.94868850708008% used
From Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
To Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
PS Old Generation
capacity = 10485760 (10.0MB)
used = 1321344 (1.2601318359375MB)
free = 9164416 (8.7398681640625MB)
12.601318359375% used
byte4执行后
gc:
247.099: [GC (Allocation Failure)
Desired survivor size 1048576 bytes, new threshold 7 (max 15)
[PSYoungGen: 6467K->0K(9216K)] 7757K->7434K(19456K), 0.0041433 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
247.104: [Full GC (Ergonomics) [PSYoungGen: 0K->0K(9216K)] [ParOldGen: 7434K->7109K(10240K)] 7434K->7109K(19456K), [Metaspace: 3769K->3769K(1056768K)], 0.0083147 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
heap:
Eden Space:
capacity = 8388608 (8.0MB)
used = 2181072 (2.0800323486328125MB)
free = 6207536 (5.9199676513671875MB)
26.000404357910156% used
From Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
To Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
PS Old Generation
capacity = 10485760 (10.0MB)
used = 7280080 (6.9428253173828125MB)
free = 3205680 (3.0571746826171875MB)
69.42825317382812% used
byte5执行后
Eden Space:
capacity = 8388608 (8.0MB)
used = 4421640 (4.216804504394531MB)
free = 3966968 (3.7831954956054688MB)
52.71005630493164% used
From Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
To Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
PS Old Generation
capacity = 10485760 (10.0MB)
used = 7280080 (6.9428253173828125MB)
free = 3205680 (3.0571746826171875MB)
69.42825317382812% used
byte6执行后
GC:
337.887: [Full GC (Ergonomics) [PSYoungGen: 4318K->2048K(9216K)] [ParOldGen: 7109K->9157K(10240K)] 11427K->11205K(19456K), [Metaspace: 3769K->3769K(1056768K)], 0.0064432 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]
Heap:
Eden Space:
capacity = 8388608 (8.0MB)
used = 7340064 (7.000030517578125MB)
free = 1048544 (0.999969482421875MB)
87.50038146972656% used
From Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
To Space:
capacity = 1048576 (1.0MB)
used = 0 (0.0MB)
free = 1048576 (1.0MB)
0.0% used
PS Old Generation
capacity = 10485760 (10.0MB)
used = 9377000 (8.942604064941406MB)
free = 1108760 (1.0573959350585938MB)
89.42604064941406% used
byte7执行后
370.908: [Full GC (Ergonomics) [PSYoungGen: 7168K->7168K(9216K)] [ParOldGen: 9157K->9157K(10240K)] 16325K->16325K(19456K), [Metaspace: 3769K->3769K(1056768K)], 0.0045883 secs] [Times: user=0.02 sys=0.00, real=0.00 secs]
370.913: [Full GC (Allocation Failure) [PSYoungGen: 7168K->7168K(9216K)] [ParOldGen: 9157K->9157K(10240K)] 16325K->16325K(19456K), [Metaspace: 3769K->3769K(1056768K)], 0.0028624 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
at com.qhong.gc.HeapTest.main(HeapTest.java:18)
Heap
PSYoungGen total 9216K, used 7368K [0x00000000ff600000, 0x0000000100000000, 0x0000000100000000)
eden space 8192K, 89% used [0x00000000ff600000,0x00000000ffd32238,0x00000000ffe00000)
from space 1024K, 0% used [0x00000000fff00000,0x00000000fff00000,0x0000000100000000)
to space 1024K, 0% used [0x00000000ffe00000,0x00000000ffe00000,0x00000000fff00000)
ParOldGen total 10240K, used 9157K [0x00000000fec00000, 0x00000000ff600000, 0x00000000ff600000)
object space 10240K, 89% used [0x00000000fec00000,0x00000000ff4f14e8,0x00000000ff600000)
Metaspace used 3799K, capacity 4596K, committed 4864K, reserved 1056768K
class space used 414K, capacity 432K, committed 512K, reserved 1048576K
Disconnected from the target VM, address: '127.0.0.1:6560', transport: 'socket'
发现一开始eden区就不是空的
如果一开始不执行System.gc(),那么除了eden区,其他区都是空的,包括老年代也是空的
参考:
《深入理解Java虚拟机》(六)堆内存使用分析,垃圾收集器 GC 日志解读
简单GC具体操作参数查看的更多相关文章
- 简单绕过Chrome密码查看逻辑,查看浏览器已保存的密码
简单绕过Chrome密码查看逻辑,查看浏览器已保存的密码 利用场景: 同事或朋友外出有事,电脑未锁屏离开座位.可以利用这一间隙,查看Ta在Chrome浏览器上保存的账号密码 查看逻辑: 当我们要查 ...
- oracle简单存储过程以及如何查看编译错误
oracle简单存储过程以及如何查看编译错误; CREATE OR REPLACE PROCEDURE procedure_test ISval VARCHAR2(200);BEGIN /* val ...
- java查看简单GC日志
测试代码: public class GCtest { public static void main(String[] args) { for (int i = 0; i < 10000; i ...
- 【GC概述以及查看堆内存使用】Java内存管理和GC学习
内存划分 1.JAVA内存主要划分为方法栈.方法区.堆. 2.方法栈上内存会自动释放: 3.方法区上主要加载了类的元信息.静态变量.常量.改区域又称为持久代(Perm Gen),默认是最小16M,最大 ...
- 简单的CSS颜色查看工具
可以通过输入ARGB(A代表透明度)格式或者HEX格式查看颜色,也可以进行ARGB格式和者HEX格式转换,如下图 使用C#编写,我已将源代码压缩上传 下载地址:http://files.cnblogs ...
- 【简单脚本】Linux查看配置信息
命令比较多,统一整合了一下: 1.新建文件touch getComputerConf.sh 2.vim getComputerConf.sh 3.按i键插入,右键粘贴如下内容: #!/bin/sh e ...
- 压力测试 Jmeter的简单测试及常用查看结果参数介绍
(1)保存方案 (2)创建线程组 线程组用来模拟用户的并发访问 线程组主要包含三个参数:线程数.准备时长(Ramp-Up Period(in seconds)).循环次数. 线程数:虚拟用户数.一个虚 ...
- windows 命令行下 简单好用的查看端口占用情况的方法
在windows命令行窗口下执行: C:\>netstat -aon|findstr "4444" TCP 127.0.0.1:4444 0.0.0.0:0 LISTENIN ...
- 基于jQuery的一个简单的图片查看器
项目中自己diy了一个图片查看器.因为初始代码不是自己的,只是在上面改了一下也没有弄的很漂亮.等以后有时间了在重写一下样式和封装,作为备用的只是积累吧.如果有童鞋有用到,完全可以在此基础上改,比较容易 ...
随机推荐
- webToImage (网页转图片)模块试用分享
模块介绍: 本模块封装了把 webview 转换成图片的功能.调用本模块的transImage接口,可把当前 webview显示的内容转换成一张图片.注意,本模块只能把当前的webview页面转换为图 ...
- 深度学习基础(五)ResNet_Deep Residual Learning for Image Recognition
ResNet可以说是在过去几年中计算机视觉和深度学习领域最具开创性的工作.在其面世以后,目标检测.图像分割等任务中著名的网络模型纷纷借鉴其思想,进一步提升了各自的性能,比如yolo,Inception ...
- Map集合转成json数据
maven项目需要导入一下依赖: <dependency> <groupId>net.sf.json-lib</groupId> <artifactId> ...
- python摸爬滚打之day29----socketserver实现服务端和多个客户端通信
什么是socketserver? TCP协议下的socket实现了服务端一次只能和一个客户端进行通信, 而socketserver实现了服务端一次能和多个客户端进行通信, 底层调用的还是socket. ...
- npm run dev没反应
npm config set registry https://registry.npm.taobao.org npm install npm run dev
- 爬虫中报 SSLError 错误
- HFSS中查看增益
第一步:设置查看增益条件 radiation 中设置 第二步设置扫描方式 下面的save fields 一定要勾选 第三步:扫描完成就可以查看了 results 中 查看 其中 phi ...
- man scp
SCP(1) BSD General Commands Manual SCP(1) NAME scp - secure copy (remote file copy program) ...
- xgboost 最优参数, df某一个字段进行字符串搜索
0.909323 with: {'max_depth': 6, 'min_child_weight': 0.8, 'n_estimators': 800} df_huoguo = df[df.c ...
- mac OSx 安装 mysqlclient
首先需要安装 按照提示操作 brew install mysql-connector-c 然后 修改mysql_config 执行mysql_config可以看到文件所在位置 我的目录放在 /usr ...