尽管 (Max)MetaspaceSize,Java 8 仍为 Metaspace 保留最小 1G

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31075761/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 10:36:33  来源:igfitidea点击:

Java 8 reserves minimum 1G for Metaspace despite (Max)MetaspaceSize

javajvmjvm-argumentsjvm-hotspot

提问by Eugene To

Java 8 reserves 1G for Metaspace just after it starts. It means that minimum metaspace size is 1G. But I set up MetaspaceSize to 300m and MaxMetaspaceSize to 400m. Why Java reserves more then I allow?

Java 8 刚启动就为 Metaspace 预留了 1G。这意味着最小元空间大小为 1G。但是我将 MetaspaceSize 设置为 300m,将 MaxMetaspaceSize 设置为 400m。为什么 Java 保留的比我允许的多?

Java Version

爪哇版

$ java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

VM Flags

虚拟机标志

$ jcmd 21689 VM.flags
21689:
-XX:CICompilerCount=3 -XX:ConcGCThreads=1 -XX:G1HeapRegionSize=1048576 -XX:InitialHeapSize=62914560 -XX:+ManagementServer -XX:MarkStackSize=4194304 -XX:MaxHeapSize=1006632960 -XX:MaxMetaspaceSize=399998976 -XX:MaxNewSize=603979776 -XX:MetaspaceSize=299999232 -XX:MinHeapDeltaBytes=1048576 -XX:NativeMemoryTracking=summary -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseFastUnorderedTimeStamps -XX:+UseG1GC 

NMT

神经网络模型

[jetty9-proxy@bm01 bin]$ jcmd 21689 VM.native_memory
21689:

Native Memory Tracking:

Total: reserved=2769543KB, committed=1311159KB

-                     Class (reserved=1221904KB, committed=197904KB)
                            (classes #36543)
                            (malloc=3344KB #44041) 
                            (mmap: reserved=1218560KB, committed=194560KB) 

And just after start it was

就在开始之后

Total: reserved=2402748KB, committed=150796KB     

-                     Class (reserved=1056956KB, committed=7868KB)
                            (classes #1300)
                            (malloc=188KB #564) 
                            (mmap: reserved=1056768KB, committed=7680KB) 

采纳答案by Eugene To

The reason why Java reserves 1G for Classes hides in the way how it manages compressed class pointers.

Java 为类保留 1G 的原因隐藏在它如何管理压缩类指针的方式中。

The long answer: read this doc https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/considerations.html

长答案:阅读此文档https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/thinkations.html

The short answer: setup the correct size in 'CompressedClassSpaceSize' property -XX:CompressedClassSpaceSize=300m

简短的回答:在 'CompressedClassSpaceSize' 属性中设置正确的大小 -XX:CompressedClassSpaceSize=300m

回答by the8472

Class (reserved=1221904KB

类(保留=1221904KB

this isn't memory that's being used, just virtual address space

这不是正在使用的内存,只是虚拟地址空间

committed=197904KB

已提交=197904KB

That's 197MB, not 1GB

那是 197MB,而不是 1GB

Therefore you're not showing that java actually consumes 1GB of memory for class data, only that it reserves 1GB worth of address space.

因此,您并没有表明 java 实际上为类数据消耗了 1GB 的内存,只是表明它保留了 1GB 的地址空间。