Skip to content

Support GC cancellation and pending GC #786

Open
@wenyuzhao

Description

@wenyuzhao

Update the current GC trigger to support GC cancellation and pending GC.


Use case for OpenJDK

Context: JNI Critical Region

When JNI code is accessing data in a Java array as a raw buffer, it should mark the current piece of code as a "critical region" to prevent the GC to move this object under the hood.

GC plans can choose:

  • Either to ensure no GC can happen when there is at least one mutator is in the critical region
  • Or, directly pin this Java array -- Only a few plans in MMTk support object pinning.

Read more: https://shipilev.net/jvm/anatomy-quarks/9-jni-critical-gclocker/

Handle GC requests in critical region

If a GC happens when there are mutators inside critical regions, the OpenJDK GCs (like G1 or parallel) will cancel this GC request [1], and schedule a pending GC request [2].

Before all the threads exiting the critical region, some mutators may still allocate (with a few more retrial), before being blocked.

The pending GC will be executed right after all the threads are exited from the critical region [3].

The above process can be simulated entirely in mmtk-openjdk [4], but pending GC or GC request cancellation is a great feature to mmtk-core.

[1] https://github.com/mmtk/openjdk/blob/jdk-11.0.19%2B1-mmtk/src/hotspot/share/gc/g1/g1CollectedHeap.cpp#L1128-L1131
[2] https://github.com/mmtk/openjdk/blob/jdk-11.0.19%2B1-mmtk/src/hotspot/share/gc/shared/gcLocker.cpp#L98
[3] https://github.com/mmtk/openjdk/blob/jdk-11.0.19%2B1-mmtk/src/hotspot/share/gc/shared/gcLocker.cpp#L158
[4] https://github.com/wenyuzhao/mmtk-openjdk/compare/956fb128c6a72529d2aeface7e1d3b56ae9c61e2..8432f53686a5163ad199dcf6dda94cde5bd5a730

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-featureCategory: FeatureP-normalPriority: Normal.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions