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

标签 java garbage-collection jvm heap-memory

我正在尝试了解 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/

相关文章:

java Ant : does ant build files have a @var@ parameters and how to handle them?

java - Android - 如何显示自定义键盘

java - 在Java中连接多行SQL语句的有效方法?

c - 如何实现平台无关的垃圾收集器?

java.lang.NullPointerException : null when I call a repository

android - Bitmap、Bitmap.recycle()、WeakReferences 和垃圾回收

c# - 工作环境的垃圾收集?

java - 如果其他 jar 是用 64 位编译的,那么用 32 位 java 构建安全吗?

scala - 为什么在已编译的 Scala 类上运行 javap 会在常量池中显示奇怪的条目?

java - 堆栈帧大小是否有上限