gpt4 book ai didi

Java 堆术语 : young, 旧代和永久代?

转载 作者:可可西里 更新时间:2023-11-01 16:14:28 24 4
gpt4 key购买 nike

我正在尝试了解 Java 堆术语中 youngoldpermanent generations 的概念,更具体地说三代人之间的互动。

我的问题是:

  • 什么是年轻一代?
  • 什么是老年代?
  • 什么是永久代?
  • 这三代人如何互动/相互关联?

最佳答案

这似乎是一个常见的误解。在 Oracle 的 JVM 中,永久代不是堆的一部分。它是类定义和相关数据的单独空间。在 Java 6 及更早版本中,驻留字符串也存储在永久代中。在 Java 7 中,驻留字符串存储在主对象堆中。

这是关于 permanent generation 的好帖子.

我喜欢 Oracle 的 guide on JConsole 中对每个空格的描述:

For the HotSpot Java VM, the memory pools for serial garbage collection are the following.

  • Eden Space (heap): The pool from which memory is initially allocated for most objects.
  • Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.
  • Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.
  • Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.
  • Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.

Java 使用分代垃圾回收。这意味着如果你有一个对象 foo(它是某个类的实例),它存活的垃圾收集事件越多(如果仍然有对它的引用),它得到的提升就越多。它从年轻一代开始(它本身分为多个空间 - Eden 和 Survivor),如果存活时间足够长,最终将在 tenured generation 结束。

关于Java 堆术语 : young, 旧代和永久代?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24744700/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com