聊聊G1 GC的String Deduplication

栏目: 编程语言 · Java · 发布时间: 4年前

内容简介:本文主要研究一下G1 GC的String Deduplication输出如下:输出如下:

本文主要研究一下G1 GC的String Deduplication

-XX:+UseStringDeduplication

前提是使用-XX:+UseG1GC

实例

实验代码

@Test
    public void testG1StringDeduplication() throws InterruptedException {
        List<String> data = IntStream.rangeClosed(1,10000000)
                .mapToObj(i -> "number is " + ( i % 2 == 0 ? "odd" : "even"))
                .collect(Collectors.toList());
        System.gc();
        long bytes = RamUsageEstimator.sizeOfAll(data);
        System.out.println("string list size in MB:" + bytes*1.0/1024/1024);
        System.out.println("used heap size in MB:" + ManagementFactory.getMemoryMXBean().getHeapMemoryUsage().getUsed()*1.0/1024/1024);
        System.out.println("used non heap size in MB:" + ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage().getUsed()*1.0/1024/1024);

    }

关闭StringDeduplication

-XX:+UseG1GC -XX:-UseStringDeduplication

输出如下:

string list size in MB:586.8727111816406
used heap size in MB:831.772346496582
used non heap size in MB:6.448394775390625
  • 整个jvm heap占用了约831MB,其中string list占用了约586MB

开启StringDeduplication

-XX:+UseG1GC -XX:+UseStringDeduplication

输出如下:

string list size in MB:296.83294677734375
used heap size in MB:645.0970153808594
used non heap size in MB:6.376350402832031
  • 整个jvm heap占用了约645MB,其中string list占用了约296MB

小结

前提是使用-XX:+UseG1GC

doc


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Introduction to Tornado

Introduction to Tornado

Michael Dory、Adam Parrish、Brendan Berg / O'Reilly Media / 2012-3-28 / USD 23.99

Tornado is a scalable, non-blocking web server and web application framework written in Python. It is also light-weight to deploy, fun to write for, and incredibly powerful. Tornado was written with p......一起来看看 《Introduction to Tornado》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

MD5 加密
MD5 加密

MD5 加密工具

html转js在线工具
html转js在线工具

html转js在线工具