直接分配给老年代的巨大对象的大小 [英] Size of Huge Objects directly allocated to Old Generation

查看:23
本文介绍了直接分配给老年代的巨大对象的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我一直在阅读 Java 中不同代的对象分配.大多数情况下,新对象会在 Eden(年轻代的一部分)中分配,然后如果满足以下任一条件,它们就会被提升到老年代.

Recently I've been reading about object allocations in different generations in Java. Most of the times new objects are allocated in Eden (part of Young Generation) and then they're promoted to Old Generation if any of the following criteria are met.

(1) 对象的年龄达到了任期阈值
(2) 当对象从 Eden(或)另一个幸存者空间(from)复制时,幸存者空间(to)已满

(1) Object's age reached the tenuring threshold
(2) Survivor space (to) is full when objects are being copied from Eden (or) another survivor space(from)

但还有一种特殊情况,对象直接在老年代分配,而不是从年轻代提升.当我们尝试创建的对象很大(可能是几 MB 的数量级)时,就会发生这种情况.

But there's also a special case in which objects are directly allocated in the Old Generation instead of being promoted from the young generation. This happens when the object that we're trying to create is huge (possibly of the order of few MBs).

有没有办法知道巨大/巨大物体的大小/限制?我知道 G1 垃圾收集器的巨大对象标准.我只想知道Java 6 之前或中的大小限制.

Is there any way to know the size/limit of the huge/humongous objects? I'm aware of the humongous objects criteria for G1 Garbage Collector. I just want to know the size limit before or in Java 6.

感谢您的时间:)

推荐答案

HotSpot JVM 可以在年轻代分配的对象的最大大小几乎与 Eden 的大小一样大(YoungGen 减去两个 Survivor 空间).

The maximum size of an object HotSpot JVM may allocate in young generation is nearly as large as the size of Eden (YoungGen minus two Survivor spaces).

这就是大致的分配方式:

That's how the allocation rougly looks like:

  1. 使用线程本地分配缓冲区 (TLAB),如果 tlab_top + size <= tlab_end
    这是最快的路径.分配只是 tlab_top 指针增量.
  2. 如果 TLAB 快满了,请在 Eden 中创建一个新的 TLAB,然后在新的 TLAB 中重试.
  3. 如果 TLAB 剩余空间不够但仍然大到无法丢弃,请尝试直接在 Eden 中分配对象.Eden 中的分配也是使用原子操作的指针增量(eden_top + size <= eden_end),因为 Eden 在所有线程之间共享.
  4. 如果 Eden 中的分配失败,通常会发生次要收集.
  5. 如果即使在 Young GC 之后 Eden 中也没有足够的空间,则会尝试直接在 Old generation 中分配.
  1. Use Thread Local Allocation Buffer (TLAB), if tlab_top + size <= tlab_end
    This is the fastest path. Allocation is just the tlab_top pointer increment.
  2. If TLAB is almost full, create a new TLAB in Eden and retry in a fresh TLAB.
  3. If TLAB remaining space is not enough but is still to big to discard, try to allocate an object directly in Eden. Allocation in Eden is also a pointer increment (eden_top + size <= eden_end) using atomic operation, since Eden is shared between all threads.
  4. If allocation in Eden fails, a minor collection typically occurs.
  5. If there is not enough space in Eden even after Young GC, an attempt to allocate directly in Old generation is made.

这篇关于直接分配给老年代的巨大对象的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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