Java JDK 8 内存布局和垃圾回收
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20563047/
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
JDK 8 Memory Layout and garbage collection
提问by Olimpiu POP
采纳答案by Adam Dyga
PermGen is replaced with Metaspacein Oracle/Sun JDK8, which is very similar. The main difference is that Metaspace can expand at runtime.
PermGen在 Oracle/Sun JDK8 中被 Metaspace 取代,非常相似。主要区别在于 Metaspace 可以在运行时扩展。
回答by pardeep131085
This is when permGen is there
这是 permGen 出现的时候
After Metaspace is introduced
引入元空间之后
Definitely, there is lot of improvement in GC in Java 8. You can check this stackoverflow post
当然,Java 8 中的 GC 有很多改进。您可以查看此stackoverflow 帖子
In Metaspace, multiple mapped virtual memory spaces are allocated for metadata and allocation ( in chunks) is per class loader depending on the type of classloader and its liveness . Chunks are returned to free chunks list and also virtual memory spaces returned when emptied.
在 Metaspace 中,为元数据分配了多个映射的虚拟内存空间,并且根据类加载器的类型及其活跃度为每个类加载器分配(以块为单位)。块返回到空闲块列表中,清空时也返回虚拟内存空间。
Advantage of GC would be
GC 的优点是
- During full collection, metadata to metadata pointers are not scanned
- A lot of complex code (particularly for CMS) for metadata scanning was removed.
- Metaspace contains few pointers into the Java heap.
- No compaction costs for metadata
- Reduces root scanning (no scanning of VM dictionary of loaded classes and other internal hashtables).
- 在完整收集期间,不会扫描元数据到元数据指针
- 删除了许多用于元数据扫描的复杂代码(尤其是 CMS)。
- 元空间包含很少的指向 Java 堆的指针。
- 元数据没有压缩成本
- 减少根扫描(不扫描加载类和其他内部哈希表的 VM 字典)。