testTenuringThreshold()方法的分析与问题处理
代码如下:
public class TestTenuringThreshold {
private static final int _1MB = 1024 * 1024;
/**
* vm-args: -verbose:gc -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails -XX:SurvivorRatio=8
* -XX:MaxTenuringThreshold=1 -XX:+PrintTenuringDistribution
*/
public static void testTenuringThreshold() {
byte[] allocation1, allocation2, allocation3;
allocation1 = new byte[_1MB / 4];
allocation2 = new byte[4 * _1MB];
allocation3 = new byte[4 * _1MB];
allocation3 = null;
allocation3 = new byte[4 * _1MB];
}
public static void main(String[] args) {
testTenuringThreshold();
}
}
代码分析:
这个代码会发生两次Minor GC:
第一次:allocation3第一次创建byte数组时,因为eden只有8M左右,没有内存再分配给新对象,所有进行了第一次GC-----allocation2的索引对象进入了老年代.
第二次:在allocation3 = null;执行以后,之前创建的对象已经"死亡",触发第二次GC回收死亡对象.与此同时,如果MaxTenuringThreshold的参数为1的话,在survivor中的allocation1的索引对象,因为age已经为1,所以会进入老年代.而当MaxTenuringThreshold大于1时,survivor中的allocation1的索引对象age+=1,不会进入老年代;
运行结果
MaxTenuringThreshold=1
[GC[DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 1)
- age 1: 700488 bytes, 700488 total
: 5392K->684K(9216K), 0.0048021 secs] 5392K->4780K(19456K), 0.0048690 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC[DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 1)
- age 1: 224 bytes, 224 total
: 5028K->0K(9216K), 0.0016226 secs] 9124K->4776K(19456K), 0.0016547 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 9216K, used 4234K [0x33c00000, 0x34600000, 0x34600000)
eden space 8192K, 51% used [0x33c00000, 0x34022830, 0x34400000)
from space 1024K, 0% used [0x34400000, 0x344000e0, 0x34500000)
to space 1024K, 0% used [0x34500000, 0x34500000, 0x34600000)
tenured generation total 10240K, used 4775K [0x34600000, 0x35000000, 0x35000000)
the space 10240K, 46% used [0x34600000, 0x34aa9f70, 0x34aaa000, 0x35000000)
compacting perm gen total 12288K, used 233K [0x35000000, 0x35c00000, 0x39000000)
the space 12288K, 1% used [0x35000000, 0x3503a4a0, 0x3503a600, 0x35c00000)
ro space 10240K, 44% used [0x39000000, 0x3947d3a8, 0x3947d400, 0x39a00000)
rw space 12288K, 52% used [0x39a00000, 0x3a049a18, 0x3a049c00, 0x3a600000)
MaxTenuringThreshold=15
[GC[DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 15)
- age 1: 700488 bytes, 700488 total
: 5556K->684K(9216K), 0.0053202 secs] 5556K->4780K(19456K), 0.0053826 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC[DefNew
Desired survivor size 524288 bytes, new threshold 15 (max 15)
- age 1: 224 bytes, 224 total
: 4948K->0K(9216K), 0.0016949 secs] 9044K->4776K(19456K), 0.0017323 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 9216K, used 4234K [0x33c00000, 0x34600000, 0x34600000)
eden space 8192K, 51% used [0x33c00000, 0x34022810, 0x34400000)
from space 1024K, 0% used [0x34400000, 0x344000e0, 0x34500000)
to space 1024K, 0% used [0x34500000, 0x34500000, 0x34600000)
tenured generation total 10240K, used 4775K [0x34600000, 0x35000000, 0x35000000)
the space 10240K, 46% used [0x34600000, 0x34aa9f70, 0x34aaa000, 0x35000000)
compacting perm gen total 12288K, used 233K [0x35000000, 0x35c00000, 0x39000000)
the space 12288K, 1% used [0x35000000, 0x3503a4a0, 0x3503a600, 0x35c00000)
ro space 10240K, 44% used [0x39000000, 0x3947d3a8, 0x3947d400, 0x39a00000)
rw space 12288K, 52% used [0x39a00000, 0x3a049a18, 0x3a049c00, 0x3a600000)
问题分析:
问题出现:MaxTenuringThreshold=1时,结果与分析完全对应.但MaxTenuringThreshold=15时的结果相对预期出现了偏差.
-----------第一次编辑-----------17.8.12 11:20
尝试解决:
尝试1:此时jdk使用的是1.7.0_80,更换jdk为1.6.0_24
MaxTenuringThreshold=1
[GC [DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 1)
- age 1: 441368 bytes, 441368 total
: 5023K->431K(9216K), 0.0033469 secs] 5023K->4527K(19456K), 0.0033763 secs] [Times: user=0.00 sys=0.02, real=0.00 secs]
[GC [DefNew
Desired survivor size 524288 bytes, new threshold 1 (max 1)
- age 1: 88 bytes, 88 total
: 4611K->0K(9216K), 0.0007613 secs] 8707K->4526K(19456K), 0.0007800 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 9216K, used 4260K [0x33040000, 0x33a40000, 0x33a40000)
eden space 8192K, 52% used [0x33040000, 0x33468fe0, 0x33840000)
from space 1024K, 0% used [0x33840000, 0x33840058, 0x33940000)
to space 1024K, 0% used [0x33940000, 0x33940000, 0x33a40000)
tenured generation total 10240K, used 4526K [0x33a40000, 0x34440000, 0x34440000)
the space 10240K, 44% used [0x33a40000, 0x33eabb98, 0x33eabc00, 0x34440000)
compacting perm gen total 12288K, used 412K [0x34440000, 0x35040000, 0x38440000)
the space 12288K, 3% used [0x34440000, 0x344a7368, 0x344a7400, 0x35040000)
ro space 10240K, 54% used [0x38440000, 0x389bd9f8, 0x389bda00, 0x38e40000)
rw space 12288K, 55% used [0x38e40000, 0x394e13f8, 0x394e1400, 0x39a40000)
MaxTenuringThreshold=15
[GC [DefNew
Desired survivor size 524288 bytes, new threshold 15 (max 15)
- age 1: 441368 bytes, 441368 total
: 5023K->431K(9216K), 0.0034562 secs] 5023K->4527K(19456K), 0.0034839 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC [DefNew
Desired survivor size 524288 bytes, new threshold 15 (max 15)
- age 1: 88 bytes, 88 total
- age 2: 441224 bytes, 441312 total
: 4611K->430K(9216K), 0.0009541 secs] 8707K->4526K(19456K), 0.0009800 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
Heap
def new generation total 9216K, used 4747K [0x33040000, 0x33a40000, 0x33a40000)
eden space 8192K, 52% used [0x33040000, 0x33477090, 0x33840000)
from space 1024K, 42% used [0x33840000, 0x338abbe0, 0x33940000)
to space 1024K, 0% used [0x33940000, 0x33940000, 0x33a40000)
tenured generation total 10240K, used 4096K [0x33a40000, 0x34440000, 0x34440000)
the space 10240K, 40% used [0x33a40000, 0x33e40010, 0x33e40200, 0x34440000)
compacting perm gen total 12288K, used 413K [0x34440000, 0x35040000, 0x38440000)
the space 12288K, 3% used [0x34440000, 0x344a76f8, 0x344a7800, 0x35040000)
ro space 10240K, 54% used [0x38440000, 0x389bd9f8, 0x389bda00, 0x38e40000)
rw space 12288K, 55% used [0x38e40000, 0x394e13f8, 0x394e1400, 0x39a40000)
发现在参数为15时第二次GC出现了age 2 字样,而且运行结果的 from space(即一个survivor)中存在数据
结果:
更换jdk版本以后结果符合了预期,可以看出jdk在升级以后对虚拟机进行了改动.
至于此改动的具体内容与意义,笔者现在无法分析,留在以后解决再更新
-----------第二次编辑-----------17.8.12 15:18
testTenuringThreshold()方法的分析与问题处理的更多相关文章
- 对tableView三种计算动态行高方法的分析
tableView是一个神奇的东西,可以这么说,就算是一个初学者如果能把tableView玩的很6,那编一般的iOS的需求都问题不大了.tableView是日常开发中用烂了的控件,但是关于tableV ...
- JQuery 支持 hide 和 show 事件的方法与分析
问题提出 JQuery不支持hide和show作为事件形式出现, 实际上这两个仅仅是JQuery对象的一个方法(fn): 有一类UI交互需求,根据一个DOM对象的或者显示对附属的DOM对象做相同操作 ...
- set方法内存分析
// // main.m // 04-set方法的内存管理分析 // // Created by apple on 14-3-17. // // #import <Foundation/F ...
- JVM内存状况查看方法和分析工具
Java本身提供了多种丰富的方法和工具来帮助开发人员查看和分析GC及JVM内存的状况,同时开源界和商业界也有一些工具可用于查看.分析GC及JVM内存的状况.通过这些分析,可以排查程序中内存泄露的问题及 ...
- JavaScript加密解密7种方法总结分析
原文地址:http://wenku.baidu.com/view/9048edee9e31433239689357.html 本文一共介绍了七种javascript加密方法: 在做网页时(其实是网页木 ...
- 常用的CSS清除浮动的方法优缺点分析(个人学习笔记)
一.抛一块问题砖(display: block)先看现象: 分析HTML代码结构: <div class="outer"> <div class="di ...
- uboot启动阶段修改启动参数方法及分析
作者:围补 本来启动方式这节不是什么复杂的事儿,不过想简单的说清楚明白,还真是不知道怎么组织.毕竟文字跟有声语言表达有别.但愿简单的东西别让我讲的太复杂! Arm板系统文件一般有三个——bootloa ...
- java执行程序的内存分析系列专栏二之static变量和方法内存分析
昨天写了简单的聊了下java执行程序时简单的内存划分,今天我们接着往下聊,聊聊static变量和方法的内存分析. 1.static变量和方法的第一个特性内存分析 statiic变量和方法的第一个特性能 ...
- Java ArrayList正确循环添加删除元素方法及分析
在阿里巴巴Java开发手册中,有这样一条规定: 但是手册中并没有给出具体原因,本文就来深入分析一下该规定背后的思考. 一.foreach循环 foreach循环(Foreach loop)是计算机编程 ...
随机推荐
- 对vue生命周期/钩子函数的理解
对于实现页面逻辑交互等效果,我们必须知晓vue的生命周期,才能愉快的玩耍,知道我们写的东西应该挂载到哪里,vue官方给出的api讲解的那叫一个简单啊,如下: 所有的生命周期钩子自动绑定this上下文到 ...
- 云计算之路-阿里云上-容器难容:自建docker swarm集群遭遇无法解决的问题
我们从今年6月开始在生产环境进行 docker 容器化部署,将已经迁移至 ASP.NET Core 的站点部署到 docker swarm 集群上.开始我们选用的阿里云容器服务,但是在使用过程中我们遭 ...
- Redis集群之节点管理
Redis集群一旦启动,就不能轻易删除掉一个节点了. 需要由redis-trib.rg这个ruby脚本行使集群管理的功能.所有的哈希槽都分配于master节点 一.delete master node ...
- js字符串 数组处理
/*字符串处理*/ var a="Hello world!" console.log(a.indexOf(& ...
- 简单sql注入学习
sql注入是什么? 所谓SQL注入,就是通过把SQL命令插入到Web表单提 交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令.具体来说,它是利用现有应用程序,将(恶意)的SQ ...
- 使用build_opener 自定义 opener
使用build_opener 自定义 opener,这种方法的好处是可以方便的拓展功能. import urllib.request import http.cookiejar def makeMyO ...
- STL中set的用法
set,顾名思义,就是数学上的集合——每个元素最多只出现一次,并且set中的元素已经从小到大排好序. 头文件:#include<set> 常用的函数: begin() 返回set容 ...
- python pip升级失败
接上篇,使用命令:python -m pip install --upgrade pip 发现pip升级时报错,无法升级 解决方法: 1.使用如下命令,查看具体失败原因: pip install -- ...
- MySQL(三)之SQL语句分类、基本操作、三大范式
一.SQL语句的分类 DML(Data Manipulation Langauge,数据操纵/管理语言) (insert,delete,update,select) DDL(Data ...
- 微信中通过页面(H5)直接打开本地app的解决方案
简述 微信中通过页面直接打开app分为安卓版和IOS版,两个的实现方式是完全不同的. 安卓版实现:使用腾讯的应用宝,只要配置了“微下载”之后,打开链接腾讯会帮你判断本地是否已经安装了app,如果本地安 ...