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)是计算机编程 ...
随机推荐
- MongoDB索引(一) --- 入门篇:学习使用MongoDB数据库索引
这个系列文章会分为两篇来写: 第一篇:入门篇,学习使用MongoDB数据库索引 第二篇:进阶篇,研究数据库索引原理--B/B+树的基本原理 1. 准备工作 在学习使用MongoDB数据库索引之前,有一 ...
- 【Ubuntu16]】ufw
Usage: ufw COMMAND Commands: enable enables the firewall 开启ufw防火墙 disable disables the firewall 禁用防火 ...
- 【Spring 核心】装配Bean(一) 自动化装配
Spring从两个角度实现自动化装配:组件扫描 (Spring自动发现应用上下文中所创建的bean)自动装配(autowiring)自动满足bean之间的依赖 组件扫描: package test.s ...
- C语言 入门程序
#include "stdio.h" #include "stdlib.h" #include "string.h" #define MAX ...
- JavaScript 学习笔记 - LocalStorage
前言 本文主要介绍本地存储的基本使用,以及它和 Cookie.SessionStorage 的区别. 简单回顾 Cookie 在 HTML5 之前,本地存储数据一般是通过 Cookie 来完成的.我们 ...
- hdu 3966 Aragorn's Story(树链剖分+树状数组/线段树)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3966 题意: 给出一棵树,并给定各个点权的值,然后有3种操作: I C1 C2 K: 把C1与C2的路 ...
- Struts拦截器解析
内建拦截器可以去struts-core.jar中的struts-default.xml文件中查看: 在没有引用内建拦截器时,已经帮我们指定了一个默认的拦截器: 使用的软件为MyEclipse:很强大!
- JavaScript笔记之第四天
HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). 查找 HTML 元素 通常,通过 JavaScript,您需要操作 ...
- Centos 6启动流程详解
author:JevonWei 版权声明:原创作品 Centos6 启动流程 POST开机自检 当按下电源键后,会启动ROM芯片中的CMOS程序检查CPU.内存等硬件设备是否正常运行,CMOS中的程序 ...
- 三、nginx实现反向代理负载均衡
1.反向代理 需求: 两个tomcat服务通过nginx反向代理 nginx服务器:192.168.101.3 tomcat1服务器:192.168.101.5 tomcat2服务器:192.168. ...