HotSpot JVM Memory Management(未完待续)

HotSpot JVM Memory Management

Automatic Memory Management

  • Object Allocations
  • Root Tracy
  • Mark
  • Collect Garbage
  • Compact
  • Allocations Continue

Generational Garbage Collection and Memory Spaces in the HotSpot JVM

  • Garbage collector is responsible for

    • Memory allocation
    • Keeping the referenced objects in memory
    • Reclaiming the space used by unreachable objects
  • Unreachable objects are called garbage

  • This whole process of reclaiming memory is garbage collection

Generational Garbage Collection

  • Memory space is divided into generations

  • Separate pools holding objects of different age ranges

  • Based on hypothesis(假设):

    • Most allocated objects die young
    • Few references from older to younger objects exist
  • To take advantage of this hypothesis, heap is divided into two generations

    • Young: small and collected frequently
    • Old : larger and occupancy grows slowly
  • Minor(young) and Major(Full) collections

Young and Old Generation

YoungOld
Eden|Survivor From |Survivor To|Virtual–|Virtual

Metaspace

  • JDK 8 does not have Permanent Generation
  • Class metadata is stored in a new space called Metaspace
  • Not contiguous with the Java Heap
  • Metaspace is allocated out of native memory
  • Maximum space available to the Metaspace is the available system memory
  • This can though be limited by MaxMetaspaceSize JVM option

Compressed Class Space

  • If UseCompressedClassesPointers is enabled then two separate areas of memory are used for the classes and its metadata

    • Metaspace
    • Compressed class space
  • 64-bit class pointers are represented with 32-bit offsets Class metadata referenced by the 32-bit offsets is stored in the Compressed Class Space

  • By default compressed class space is sized at 1GB

  • MaxMetaspaceSize sets an upper limit on the committed size of both of these spaces.

Java HeapMetaspace
mark
kclass
Klass
Other metadata
mark
kclass
Klass
Other metadata

Compressed Class Space

Java HeapMetaspace
mark
kclass
Klass
Klass
mark
kclass
Other metadata
Other metadata

Code Cache

  • Code Cache is used to store the compiled code generated by the Just-in-time compilers
  • It is allocated out of native memory
  • Managed by the Code Cache Sweeper

Native Memory

  • Available system memory
  • Not managed by the JVM memory management

Summary: Section 2

  • Memory space is divided into memory pools
  • Java Heap
    • Young generation
    • Old generation
  • Classes and metadata space
    • Permanent Generation (before JDK 8)
    • Metaspace(metaspace + compressed class space) (JDK 8 onwards)
  • CodeCache
  • Native Memory

Garbage Collectors in the HotSpot JVM

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值