内容简介:本文主要研究一下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
- Java 8 String deduplication vs. String.intern()
- JEP 192: String Deduplication in G1
- String Deduplication – A new feature in Java 8 Update 20
- Java 8 Update 20: String Deduplication
- Duplicate Strings: How to Get Rid of Them and Save Memory
- String deduplication feature (from Java 8 update 20)
- G1 GC: Reducing Memory Consumption by 20%
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
莱昂氏UNIX源代码分析
(澳)John Lions / 尤晋元 / 机械工业出版社 / 2000-7-1 / 49.00
本书由上、下两篇组成。上篇为UNIX版本6的源代码,下篇是莱昂先生对UNIX操作系统版本6源代码的详细分析。本书语言简洁、透彻,曾作为未公开出版物广泛流传了二十多年,是一部杰出经典之作。本书适合UNIX操作系统编程人员、大专院校师生学习参考使用。一起来看看 《莱昂氏UNIX源代码分析》 这本书的介绍吧!