实验一: 存活对象包含 小于survivor大小的对象 + 大于survivor的对象

 private static final Integer _1MB = 1024 * 1024;

    /**
* -XX:+UseSerialGC -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails
* eden=8m survivor=1m old=10m
* @param args
*/
public static void main(String[] args) { byte[] a1 = new byte[_1MB * 2];
byte[] a2 = new byte[_1MB * 2];
byte[] a3 = new byte[_1MB/2]; //第一次minor gc:创建a4的时候,eden 放不下,要先进行一次minor gc
//survivor=1M,放得下a3, 放不下a1和a2
byte[] a4 = new byte[_1MB * 4];
}

gc日志分析

[GC (Allocation Failure) [DefNew: 6837K->1023K(9216K), 0.0073394 secs] 6837K->5146K(19456K), 0.0073686 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]

年轻代回收了4m左右,但是总的堆占用还有5m, 减去年轻代的1023k 得出老年代占用4m左右 和下面打印的回收后日志匹配

Heap

def new generation total 9216K, used 5256K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000)

eden space 8192K, 51% used [0x00000007bec00000, 0x00000007bf0223b8, 0x00000007bf400000)

from space 1024K, 99% used [0x00000007bf500000, 0x00000007bf5ffff8, 0x00000007bf600000)

to space 1024K, 0% used [0x00000007bf400000, 0x00000007bf400000, 0x00000007bf500000)

tenured generation total 10240K, used 4122K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000)

the space 10240K, 40% used [0x00000007bf600000, 0x00000007bfa06b88, 0x00000007bfa06c00, 0x00000007c0000000)

Metaspace used 2956K, capacity 4496K, committed 4864K, reserved 1056768K

class space used 329K, capacity 388K, committed 512K, reserved 1048576K

回收后,老年代占用 4122k约等于4m 刚好是a1 + a2的大小 说明a3并没有进入老年代,还在survivor区

ps: 这边有500k左右的未知对象 忽略

实验二: 存活对象总大小 > survivor, 单个对象都小于survivor

private static final Integer _1MB = 1024 * 1024;

    /**
* -XX:+UseSerialGC -Xms20M -Xmx20M -Xmn10M -XX:+PrintGCDetails
* eden=8m survivor=1m old=10m
* @param args
*/
public static void main(String[] args) {
byte[] a1 = new byte[_1MB/2];
byte[] a2 = new byte[_1MB/2];
byte[] a3 = new byte[_1MB/2]; //a1+a2+a3=1.5M, 要创建a4=7M 放不下,需要先进行minor gc
// a1+a2+a3 > survivor 这种情况,谁会进入老年代?
byte[] a4 = new byte[_1MB * 7];
}

gc日志分析

[GC (Allocation Failure) [DefNew:3765K->1023K(9216K), 0.0018177 secs] 3765K->2074K(19456K), 0.0018397 secs] [Times: user=0.01 sys=0.00, real=0.00 secs]

Heap

def new generation total 9216K, used 8410K [0x00000007bec00000, 0x00000007bf600000, 0x00000007bf600000)

eden space 8192K, 90% used [0x00000007bec00000, 0x00000007bf336bc0, 0x00000007bf400000)

from space 1024K, 99% used [0x00000007bf500000, 0x00000007bf5ffff8, 0x00000007bf600000)

to space 1024K, 0% used [0x00000007bf400000, 0x00000007bf400000, 0x00000007bf500000)

tenured generation total 10240K, used 1050K [0x00000007bf600000, 0x00000007c0000000, 0x00000007c0000000)

the space 10240K, 10% used [0x00000007bf600000, 0x00000007bf706928, 0x00000007bf706a00, 0x00000007c0000000)

Metaspace used 2956K, capacity 4496K, committed 4864K, reserved 1056768K

class space used 329K, capacity 388K, committed 512K, reserved 1048576K

a1=a2=a3=0.5m 单个都小于survivor=1m,minor gc时他们都还存活 a1 + a2 + a3=1.5M > survivor=1M 总空间大于survivor,gc后老年代仅增加 1050k约等于1m,from区塞满,说明 a1/a2/a3只有2个对象进入老年代 还一个家伙被留到survivor中

结论

minor gc后,如果存活对象过多 survivor区放不下,并不是所有的存活对象都直接进入老年代,而是放不下的那部分对象才进入老年代

实验: survivor放不下的对象进入老年代的更多相关文章

  1. 关于gc日志中Desired Survivor的疑问和对象晋升老年代的小结

    问题背景 (下面的所有内容都是根据书上的Serial/Serial Old收集器下的情况) 在<深入理解JVM>一书中的——3.6.3长期存活的对象将进入老年代的介绍中, 一个例子的jvm ...

  2. 读《深入理解jvm虚拟机》之长期存活对象进入老年代,有感!!!!

    关于这一段代码 有几个不是让人很理解的地方,我一一说来. 1.Desired survivor size 524288 bytes 关于这个512KB空间是怎么来的,JVM有这样一个参数: -XX:T ...

  3. C++对象模型——继承体系下的对象构造(第五章)

    5.2 继承体系下的对象构造 当定义一个object例如以下: T object; 时,实际上会发生什么事情呢?假设T有一个constructor(不论是由user提供或是由编译器合成),它会被调用. ...

  4. C++对象模型——&quot;无继承&quot;情况下的对象构造(第五章)

    5.1 "无继承"情况下的对象构造 考虑以下这个程序片段: 1 Point global; 2 3 Point foobar() 4 { 5 Point local; 6 Poin ...

  5. python: HTML之 鼠标放上去下拉项字体显示不同颜色

    鼠标放上去下拉项字体显示不同颜色 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "h ...

  6. Oracle中删除用户下所有对象的多种方法

      Oracle删除用户下所有对象的方法未必人人都会,下面就为您介绍两种常用的Oracle删除用户下所有对象的方法,希望对您学习Oracle删除用户方面能有所帮助. 方法1: drop user XX ...

  7. ORACLE删除某用户下所有对象

    ORACLE删除某用户下所有对象 2013-10-26 15:50 4996人阅读 评论(1) 收藏 举报   --.sql脚本 --唯一注意的是下面的D:\dropobj.sql 为操作的.sql; ...

  8. 导航菜单,showHide插件 + Dropdown 下拉对象

    一,index.html文件 <!DOCTYPE html> <html lang="utf-8"> <head> <meta chars ...

  9. 实验十--- MySQL过程式数据库对象

    实验十 MySQL过程式数据库对象 一.  实验内容: 1. 存储过程的创建和调用 2. 存储函数的创建和调用 3. 触发器的创建和触发 4. 事件的创建和修改 一.  实验项目:员工管理数据库 用于 ...

随机推荐

  1. How to enable HTTPS for local development in macOS using Chrome

    How to enable HTTPS for local development in macOS using Chrome HTTPS, macOS, Chrome local HTTPS htt ...

  2. how HTTPS works

    How HTTPS works HTTPS comic tutorials How HTTPS works ...in a comic! https://howhttps.works/ A cat e ...

  3. Firewall & Network Security

    Firewall & Network Security 防火墙 & 网络安全 NAT Gateway VPC Virtual Private Cloud refs https://en ...

  4. LeetCode 高效刷题路径

    LeetCode 高效刷题路径 Hot 100 https://leetcode.com/problemset/hot-100/ https://leetcode-cn.com/problemset/ ...

  5. leetcode solution cracked tutorial

    leetcode solution cracked tutorial problemset https://leetcode.com/problemset/all/ Top Interview Que ...

  6. js online playground & web editor

    js online playground & web editor -javascript playgrounds 2019 https://scotch.io/tutorials/7-jav ...

  7. Serverless & Cloudflare Workers

    Serverless & Cloudflare Workers https://dash.cloudflare.com/6f3d5e68ab80892a372313b7c9b02a85/wor ...

  8. 「NGK每日快讯」2021.1.21日NGK公链第79期官方快讯!

  9. SpringBoot+Vue豆宝社区前后端分离项目手把手实战系列教程01---搭建前端工程

    豆宝社区项目实战教程简介 本项目实战教程配有免费视频教程,配套代码完全开源.手把手从零开始搭建一个目前应用最广泛的Springboot+Vue前后端分离多用户社区项目.本项目难度适中,为便于大家学习, ...

  10. django学习-16.返回给前端页面数据为json数据类型的3种方案

    目录结构 1.前言 2.JsonResponse类的源码简单分析 2.1.JsonResponse类的源码如下所示 2.2.JsonResponse类的构造函数里的每个入参的大概含义和作用 3.[方案 ...