Java堆术语:年轻的,老的和永久的世代? [英] Java heap terminology: young, old and permanent generations?

查看:107
本文介绍了Java堆术语:年轻的,老的和永久的世代?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图理解Java堆术语中 young old 永久代的概念,更具体地说,三代之间的相互作用。

我的问题是:


  • 什么是年轻一代?

  • 什么是老一代?

  • 什么是永久代?

  • 三代人之间相互作用/相互关联?


解决方案

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



这是一个永久代的好贴子

我喜欢在Oracle的 JConsole指南


对于HotSpot Java VM,串行垃圾收集
的内存
池如下。




  • Eden Space(堆):内存最初为大多数对象分配
    的池。

  • 存活空间(heap):包含池在
    中存活的对象是Eden
    空间的垃圾回收。

  • Tenured Generation(heap):包含对象的池时间在幸存者空间。

  • 永久生成(非堆):该池包含虚拟机本身的所有反射
    数据,
    (例如类和方法对象)。使用类数据共享
    的Java虚拟机,
    这一代被分为
    只读和读写区域。
  • 代码缓存(非缓存-heap):HotSpot Java VM还包含一个代码缓存,
    包含用于
    编译和本地
    代码存储的内存。


Java使用分代垃圾收集。这意味着如果你有一个对象foo(它是某个类的一个实例),它存活的垃圾收集事件就越多(如果仍然有引用的话),它就会被提升。它开始于年轻一代(本身分为多个空间 - 伊甸园和幸存者),如果能够长期存活下来,它们最终会成为终身的一代。


I'm trying to understand how the concepts of young, old and permanent generations in the Java heap terminology, and more specifically the interactions between the three generations.

My questions are:

  • What is the young generation?
  • What is the old generation?
  • What is the permanent generation?
  • How does the three generations interact/relate to each other?

解决方案

This seems like a common misunderstanding. In Oracle's JVM, the permanent generation is not part of the heap. It's a separate space for class definitions and related data. In Java 6 and earlier, interned strings were also stored in the permanent generation. In Java 7, interned strings are stored in the main object heap.

Here is a good post on permanent generation.

I like the descriptions given for each space in Oracle's 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 uses generational garbage collection. This means that if you have an object foo (which is an instance of some class), the more garbage collection events it survives (if there are still references to it), the further it gets promoted. It starts in the young generation (which itself is divided into multiple spaces - Eden and Survivor) and would eventually end up in the tenured generation if it survived long enough.

这篇关于Java堆术语:年轻的,老的和永久的世代?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆