Skip to content

Commit

Permalink
Add Azul C4 (GPGC)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielThomas committed Oct 25, 2023
1 parent f62e774 commit 6ed0fb4
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@


import java.lang.management.ManagementFactory;
import java.lang.management.MemoryManagerMXBean;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

/**
* A {@link ArraySegmentRecycler} that chooses the appropriate recycler based on the garbage collector in use.
Expand All @@ -10,6 +15,8 @@
* delegate to {@link WastefulRecycler}. Otherwise the default {@link RecyclingRecycler} is used.
*/
public class GarbageCollectorAwareRecycler implements ArraySegmentRecycler {
private static final List<String> LOW_PAUSE_COLLECTORS = Arrays.asList("GPGC", "Shenandoah", "ZGC");

private final ArraySegmentRecycler delegate;

public GarbageCollectorAwareRecycler() {
Expand All @@ -19,7 +26,12 @@ public GarbageCollectorAwareRecycler() {
public GarbageCollectorAwareRecycler(int log2OfByteSegmentSize, int log2OfLongSegmentSize) {
boolean isLowPause = ManagementFactory.getGarbageCollectorMXBeans()
.stream()
.anyMatch(bean -> bean.getName().startsWith("Shenandoah") || bean.getName().startsWith("ZGC"));
.map(MemoryManagerMXBean::getName)
.map(name -> name.split(" ")[0])
.distinct()
.findFirst()
.map(LOW_PAUSE_COLLECTORS::contains)
.orElse(false);
delegate = isLowPause ? new WastefulRecycler(log2OfByteSegmentSize, log2OfLongSegmentSize)
: new RecyclingRecycler(log2OfByteSegmentSize, log2OfLongSegmentSize);
}
Expand Down

0 comments on commit 6ed0fb4

Please sign in to comment.