34
import java.lang.management.ManagementFactory;
36
public class TestMemoryManagerMXBean {
37
private static void checkName(String name) throws Exception {
38
if (name == null || name.length() == 0) {
39
throw new Exception("Invalid name");
43
public static void main(String[] args) throws Exception {
44
int zgcCyclesMemoryManagers = 0;
45
int zgcPausesMemoryManagers = 0;
46
int zgcCyclesMemoryPools = 0;
47
int zgcPausesMemoryPools = 0;
49
for (final var memoryManager : ManagementFactory.getMemoryManagerMXBeans()) {
50
final var memoryManagerName = memoryManager.getName();
51
checkName(memoryManagerName);
53
System.out.println("MemoryManager: " + memoryManagerName);
55
if (memoryManagerName.equals("ZGC Cycles")) {
56
zgcCyclesMemoryManagers++;
57
} else if (memoryManagerName.equals("ZGC Pauses")) {
58
zgcPausesMemoryManagers++;
61
for (final var memoryPoolName : memoryManager.getMemoryPoolNames()) {
62
checkName(memoryPoolName);
64
System.out.println(" MemoryPool: " + memoryPoolName);
66
if (memoryPoolName.equals("ZHeap")) {
67
if (memoryManagerName.equals("ZGC Cycles")) {
68
zgcCyclesMemoryPools++;
69
} else if (memoryManagerName.equals("ZGC Pauses")) {
70
zgcPausesMemoryPools++;
76
if (zgcCyclesMemoryManagers != 1) {
77
throw new Exception("Unexpected number of cycle MemoryManagers");
80
if (zgcPausesMemoryManagers != 1) {
81
throw new Exception("Unexpected number of pause MemoryManagers");
84
if (zgcCyclesMemoryPools != 1) {
85
throw new Exception("Unexpected number of cycle MemoryPools");
88
if (zgcPausesMemoryPools != 1) {
89
throw new Exception("Unexpected number of pause MemoryPools");