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)是计算机编程 ...
随机推荐
- Hacking JWT(JSON Web Token)
0x01 JWT工作流程 JSON Web Token(JWT)是一个非常轻巧的规范. 这个规范允许我们使用JWT在用户和服务器之间传递安全可靠的信息. JWT常被用于前后端分离,可以和Restful ...
- Andrew Ng机器学习课程笔记--week4(神经网络)
Neural Networks: Representation 一. 内容概要 Neural Network Model Representation 1 Model Representation 2 ...
- 手把手封装数据层之DataUtil数据库操作的封装
上一篇我们写完了数据库连接的封装 没有看的请移步上一篇关于数据库连接的内容 这次我们讲数据库操作的封装.数据库的操作就是增删改查:心再大一点就可以直接分为查询和其他. 因为查询是有返回对象的,而其他都 ...
- 浅谈JS的继承
JS继承 继承是OO语言中最为人津津乐道的概念,许多OO语言都支持两种方式的继承:接口继承:实现继承. 接口继承:只继承方法签名. 实现继承:继承实际的方法. 由于ES里函数没有签名,所以在ES里面无 ...
- if 分支语句
写在<script></script>里面. if(判断条件){满足条件时要执行的语句} else{不满足条件时要执行的语句} 三元运算:var x = 判断条件?值1:值2: ...
- Java Spring的简单见解
Spring的注解特性,IOC控制反转 首先了解依赖注入是什么,就是在实例化对象的时候并不需要每次都new对象出来,spring管理对象,在你配置been或者@service时候 Spring会自动帮 ...
- 慎用kill -9,kill -15的作用
详见:http://blog.yemou.net/article/query/info/tytfjhfascvhzxcyt334 Perl语言专家Randal Schwartz在一篇短文里这样写: n ...
- JS自定义对象以及相关成绩系统完整案例演示
[自定义对象] 1.基本概念 ①对象是拥有一系列无无序属性和方法的集合 ②键值对:对象中的数据,用以键值对的形式存在,对象的每个属性和方法,都对应一个键值,以键取值 ③属性:描述对象特征的一系列变量称 ...
- 解决 SQL 注入的另类方法
本文是翻译,版权归原作者所有 原文地址(original source):https://bitcoinrevolt.wordpress.com/2016/03/08/solving-the-prob ...
- CCNP-3.vlan间路由及三层交换机的配置