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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 02:49:56  来源:igfitidea点击:

JDK 8 Memory Layout and garbage collection

javagarbage-collectionjava-8

提问by Olimpiu POP

From what I know, starting with JDK 8 the PermGen will be a past page in java's history. Everything nice and merry... but what will the new Memory Layout look like? Will this affect GC on the new platform?

据我所知,从 JDK 8 开始,PermGen 将成为 Java 历史上的一页。一切美好而快乐……但是新的内存布局会是什么样子?这会影响新平台上的GC吗?

采纳答案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 enter image description here

这是 permGen 出现的时候 在此处输入图片说明

After Metaspace is introduced enter image description here

引入元空间之后 在此处输入图片说明

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 字典)。

More detail is here

更多细节在这里