Verbose GC alwayshappen after Allocation Failure.
I. Object Allocation:
1. less than 512 bytes (768 bytes on 64-bit platforms) or Larger objects are allocated from the cache if they can be contained in the existing cache -> Cache allocation
2. If not satisfied in the existing cache -> Heap lock allocation -> Attempted in SOA (Small Object Area) at first:
2.1 ifsatisfy, Enjoy your new object!
2.2 if no satisfy, but object size is less than 512 bytes -> Allocation Failure (AF)
2.3 if no satisfy, but object size is large than 512 bytes -> Attempted inLOA (Large Object Area):
2.3.1 if satisfy, Enjoy your new object!
2.3.2 if no satisfy, Allocation Failure ->Registers a GC cycle
II. GC cycle
1) STW (Stop The World)
2) Reclaim spaces of un-reachable objects
3) Marking -> Sweeping -> Compaction(optional, one condition: not enough free space is available to satisfy the allocation request)
Yes - 1. Successful object allocation
2. Possible Heap Shrinkage
NO - Heap Expansion Possible?
Yes Expand heap (Continuous), allocate object
No??? OutOfMemoryError (OOM)
Verbose GC alwayshappen after Allocation Failure.
I. Object Allocation:
1. less than 512 bytes (768 bytes on 64-bit platforms) or Larger objects are allocated from the cache if they can be contained in the existing cache -> Cache allocation
2. If not satisfied in the existing cache -> Heap lock allocation -> Attempted in SOA (Small Object Area) at first:
2.1 ifsatisfy, Enjoy your new object!
2.2 if no satisfy, but object size is less than 512 bytes -> Allocation Failure (AF)
2.3 if no satisfy, but object size is large than 512 bytes -> Attempted inLOA (Large Object Area):
2.3.1 if satisfy, Enjoy your new object!
2.3.2 if no satisfy, Allocation Failure ->Registers a GC cycle
II. GC cycle
1) STW (Stop The World)
2) Reclaim spaces of un-reachable objects
3) Marking -> Sweeping -> Compaction(optional, one condition: not enough free space is available to satisfy the allocation request)
Yes - 1. Successful object allocation
2. Possible Heap Shrinkage
NO - Heap Expansion Possible?
Yes Expand heap (Continuous), allocate object
No??? OutOfMemoryError (OOM)
本文深入探讨了Java中对象的内存分配过程及垃圾回收机制,详细解释了小对象区域、大对象区域和缓存区的工作原理,以及如何在不同场景下成功分配对象并避免内存溢出。
1万+

被折叠的 条评论
为什么被折叠?



