Skip to content

Commit 4b7b8d0

Browse files
author
Thomas Schrott
committed
[GR-54524] Refactor the MXBean support.
PullRequest: graal/18128
2 parents 7fda885 + d9fb968 commit 4b7b8d0

File tree

10 files changed

+376
-274
lines changed

10 files changed

+376
-274
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,26 +25,22 @@
2525
package com.oracle.svm.core.genscavenge.graal;
2626

2727
import java.util.Arrays;
28-
import java.util.Collections;
2928
import java.util.List;
3029
import java.util.Map;
3130

3231
import org.graalvm.nativeimage.ImageSingletons;
3332
import org.graalvm.nativeimage.hosted.Feature;
3433

34+
import com.oracle.svm.core.GCRelatedMXBeans;
3535
import com.oracle.svm.core.SubstrateGCOptions;
3636
import com.oracle.svm.core.SubstrateOptions;
3737
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
3838
import com.oracle.svm.core.feature.InternalFeature;
3939
import com.oracle.svm.core.genscavenge.ChunkedImageHeapLayouter;
40-
import com.oracle.svm.core.genscavenge.CompleteGarbageCollectorMXBean;
41-
import com.oracle.svm.core.genscavenge.EpsilonGarbageCollectorMXBean;
4240
import com.oracle.svm.core.genscavenge.GenScavengeMemoryPoolMXBeans;
4341
import com.oracle.svm.core.genscavenge.HeapImpl;
44-
import com.oracle.svm.core.genscavenge.HeapImplMemoryMXBean;
4542
import com.oracle.svm.core.genscavenge.HeapVerifier;
4643
import com.oracle.svm.core.genscavenge.ImageHeapInfo;
47-
import com.oracle.svm.core.genscavenge.IncrementalGarbageCollectorMXBean;
4844
import com.oracle.svm.core.genscavenge.SerialGCOptions;
4945
import com.oracle.svm.core.genscavenge.jvmstat.EpsilonGCPerfData;
5046
import com.oracle.svm.core.genscavenge.jvmstat.SerialGCPerfData;
@@ -61,12 +57,9 @@
6157
import com.oracle.svm.core.heap.Heap;
6258
import com.oracle.svm.core.image.ImageHeapLayouter;
6359
import com.oracle.svm.core.jdk.RuntimeSupportFeature;
64-
import com.oracle.svm.core.jdk.management.ManagementFeature;
65-
import com.oracle.svm.core.jdk.management.ManagementSupport;
6660
import com.oracle.svm.core.jvmstat.PerfDataFeature;
6761
import com.oracle.svm.core.jvmstat.PerfDataHolder;
6862
import com.oracle.svm.core.jvmstat.PerfManager;
69-
import com.sun.management.GarbageCollectorMXBean;
7063

7164
import jdk.graal.compiler.graph.Node;
7265
import jdk.graal.compiler.options.OptionValues;
@@ -81,14 +74,18 @@ public boolean isInConfiguration(IsInConfigurationAccess access) {
8174

8275
@Override
8376
public List<Class<? extends Feature>> getRequiredFeatures() {
84-
return Arrays.asList(RuntimeSupportFeature.class, ManagementFeature.class, PerfDataFeature.class, AllocationFeature.class);
77+
return Arrays.asList(RuntimeSupportFeature.class, PerfDataFeature.class, AllocationFeature.class);
8578
}
8679

8780
@Override
8881
public void afterRegistration(AfterRegistrationAccess access) {
8982
RememberedSet rememberedSet = createRememberedSet();
9083
ImageSingletons.add(RememberedSet.class, rememberedSet);
9184
ImageSingletons.add(BarrierSetProvider.class, rememberedSet);
85+
86+
GenScavengeMemoryPoolMXBeans memoryPoolMXBeans = new GenScavengeMemoryPoolMXBeans();
87+
ImageSingletons.add(GenScavengeMemoryPoolMXBeans.class, memoryPoolMXBeans);
88+
ImageSingletons.add(GCRelatedMXBeans.class, new GenScavengeRelatedMXBeans(memoryPoolMXBeans));
9289
}
9390

9491
@Override
@@ -97,23 +94,6 @@ public void duringSetup(DuringSetupAccess access) {
9794
ImageSingletons.add(Heap.class, heap);
9895
ImageSingletons.add(GCAllocationSupport.class, new GenScavengeAllocationSupport());
9996

100-
GenScavengeMemoryPoolMXBeans memoryPoolMXBeans = new GenScavengeMemoryPoolMXBeans();
101-
ImageSingletons.add(GenScavengeMemoryPoolMXBeans.class, memoryPoolMXBeans);
102-
103-
List<GarbageCollectorMXBean> garbageCollectors;
104-
if (SubstrateOptions.useEpsilonGC()) {
105-
garbageCollectors = Arrays.asList(new EpsilonGarbageCollectorMXBean());
106-
} else {
107-
garbageCollectors = Arrays.asList(new IncrementalGarbageCollectorMXBean(), new CompleteGarbageCollectorMXBean());
108-
}
109-
110-
ManagementSupport managementSupport = ManagementSupport.getSingleton();
111-
managementSupport.addPlatformManagedObjectSingleton(java.lang.management.MemoryMXBean.class, new HeapImplMemoryMXBean());
112-
managementSupport.addPlatformManagedObjectList(java.lang.management.MemoryPoolMXBean.class, Arrays.asList(memoryPoolMXBeans.getMXBeans()));
113-
managementSupport.addPlatformManagedObjectList(com.sun.management.GarbageCollectorMXBean.class, garbageCollectors);
114-
/* Not supported yet. */
115-
managementSupport.addPlatformManagedObjectList(java.lang.management.BufferPoolMXBean.class, Collections.emptyList());
116-
11797
if (ImageSingletons.contains(PerfManager.class)) {
11898
ImageSingletons.lookup(PerfManager.class).register(createPerfData());
11999
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core.genscavenge.graal;
26+
27+
import java.util.Arrays;
28+
import java.util.Collections;
29+
import java.util.List;
30+
31+
import org.graalvm.nativeimage.Platform;
32+
import org.graalvm.nativeimage.Platforms;
33+
34+
import com.oracle.svm.core.GCRelatedMXBeans;
35+
import com.oracle.svm.core.SubstrateOptions;
36+
import com.oracle.svm.core.genscavenge.CompleteGarbageCollectorMXBean;
37+
import com.oracle.svm.core.genscavenge.EpsilonGarbageCollectorMXBean;
38+
import com.oracle.svm.core.genscavenge.GenScavengeMemoryPoolMXBeans;
39+
import com.oracle.svm.core.genscavenge.HeapImplMemoryMXBean;
40+
import com.oracle.svm.core.genscavenge.IncrementalGarbageCollectorMXBean;
41+
import com.sun.management.GarbageCollectorMXBean;
42+
43+
public final class GenScavengeRelatedMXBeans extends GCRelatedMXBeans {
44+
@Platforms(Platform.HOSTED_ONLY.class)
45+
public GenScavengeRelatedMXBeans(GenScavengeMemoryPoolMXBeans memoryPoolMXBeans) {
46+
List<GarbageCollectorMXBean> garbageCollectors;
47+
if (SubstrateOptions.useEpsilonGC()) {
48+
garbageCollectors = List.of(new EpsilonGarbageCollectorMXBean());
49+
} else {
50+
garbageCollectors = Arrays.asList(new IncrementalGarbageCollectorMXBean(), new CompleteGarbageCollectorMXBean());
51+
}
52+
53+
beans.addSingleton(java.lang.management.MemoryMXBean.class, new HeapImplMemoryMXBean());
54+
beans.addList(java.lang.management.MemoryPoolMXBean.class, Arrays.asList(memoryPoolMXBeans.getMXBeans()));
55+
beans.addList(java.lang.management.BufferPoolMXBean.class, Collections.emptyList());
56+
beans.addList(com.sun.management.GarbageCollectorMXBean.class, garbageCollectors);
57+
}
58+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* Copyright (c) 2024, 2024, Oracle and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation. Oracle designates this
8+
* particular file as subject to the "Classpath" exception as provided
9+
* by Oracle in the LICENSE file that accompanied this code.
10+
*
11+
* This code is distributed in the hope that it will be useful, but WITHOUT
12+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14+
* version 2 for more details (a copy is included in the LICENSE file that
15+
* accompanied this code).
16+
*
17+
* You should have received a copy of the GNU General Public License version
18+
* 2 along with this work; if not, write to the Free Software Foundation,
19+
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*
21+
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22+
* or visit www.oracle.com if you need additional information or have any
23+
* questions.
24+
*/
25+
package com.oracle.svm.core;
26+
27+
import java.lang.management.MemoryManagerMXBean;
28+
import java.lang.management.MemoryPoolMXBean;
29+
import java.util.List;
30+
31+
import org.graalvm.nativeimage.ImageSingletons;
32+
import org.graalvm.nativeimage.Platform;
33+
import org.graalvm.nativeimage.Platforms;
34+
35+
import com.oracle.svm.core.code.CodeCacheManagerMXBean;
36+
import com.oracle.svm.core.code.CodeCachePoolMXBean;
37+
import com.oracle.svm.core.jdk.management.ManagementSupport;
38+
39+
import jdk.graal.compiler.api.replacements.Fold;
40+
41+
/**
42+
* Keeps track of all GC-related MX beans. The actual implementation of this class is GC-specific.
43+
* Note that multiple instances of this class may be in the same image if the image contains more
44+
* than one garbage collector.
45+
*/
46+
public class GCRelatedMXBeans {
47+
protected final ManagementSupport.MXBeans beans = new ManagementSupport.MXBeans();
48+
49+
@Platforms(Platform.HOSTED_ONLY.class)
50+
public GCRelatedMXBeans() {
51+
beans.addList(MemoryManagerMXBean.class, List.of(new CodeCacheManagerMXBean()));
52+
beans.addList(MemoryPoolMXBean.class, List.of(new CodeCachePoolMXBean.CodeAndDataPool(), new CodeCachePoolMXBean.NativeMetadataPool()));
53+
}
54+
55+
@Fold
56+
public static ManagementSupport.MXBeans mxBeans() {
57+
return ImageSingletons.lookup(GCRelatedMXBeans.class).beans;
58+
}
59+
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeCacheManagerMXBean.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,14 @@
3939
import sun.management.Util;
4040

4141
public final class CodeCacheManagerMXBean implements MemoryManagerMXBean, NotificationEmitter {
42-
43-
@Platforms(Platform.HOSTED_ONLY.class)
44-
CodeCacheManagerMXBean() {
45-
}
46-
4742
public static final String CODE_CACHE_CODE_AND_DATA_POOL = "runtime code cache (code and data)";
4843
public static final String CODE_CACHE_NATIVE_METADATA_POOL = "runtime code cache (native metadata)";
4944
public static final String CODE_CACHE_MANAGER = "code cache";
5045

46+
@Platforms(Platform.HOSTED_ONLY.class)
47+
public CodeCacheManagerMXBean() {
48+
}
49+
5150
@Override
5251
public String getName() {
5352
return CODE_CACHE_MANAGER;

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeCachePoolMXBean.java

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.lang.management.MemoryPoolMXBean;
2929
import java.lang.management.MemoryType;
3030
import java.lang.management.MemoryUsage;
31-
import java.util.List;
3231

3332
import javax.management.ObjectName;
3433

@@ -136,11 +135,7 @@ public ObjectName getObjectName() {
136135
return Util.newObjectName(ManagementFactory.MEMORY_POOL_MXBEAN_DOMAIN_TYPE, getName());
137136
}
138137

139-
public static List<MemoryPoolMXBean> getMemoryPools() {
140-
return List.of(new CodeAndDataPool(), new NativeMetadataPool());
141-
}
142-
143-
static final class CodeAndDataPool extends CodeCachePoolMXBean {
138+
public static final class CodeAndDataPool extends CodeCachePoolMXBean {
144139
@Override
145140
protected long getCurrentSize() {
146141
RuntimeCodeInfoMemory.SizeCounters counters = RuntimeCodeInfoMemory.singleton().getSizeCounters();
@@ -164,7 +159,7 @@ public String getName() {
164159
}
165160
}
166161

167-
static final class NativeMetadataPool extends CodeCachePoolMXBean {
162+
public static final class NativeMetadataPool extends CodeCachePoolMXBean {
168163
@Override
169164
protected long getCurrentSize() {
170165
RuntimeCodeInfoMemory.SizeCounters counters = RuntimeCodeInfoMemory.singleton().getSizeCounters();

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/code/CodeInfoTable.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
*/
2525
package com.oracle.svm.core.code;
2626

27-
import java.lang.management.MemoryManagerMXBean;
28-
import java.lang.management.MemoryPoolMXBean;
2927
import java.util.Arrays;
3028
import java.util.List;
3129

@@ -47,7 +45,6 @@
4745
import com.oracle.svm.core.heap.RestrictHeapAccess;
4846
import com.oracle.svm.core.heap.RestrictHeapAccess.Access;
4947
import com.oracle.svm.core.heap.VMOperationInfos;
50-
import com.oracle.svm.core.jdk.management.ManagementSupport;
5148
import com.oracle.svm.core.log.Log;
5249
import com.oracle.svm.core.meta.SharedMethod;
5350
import com.oracle.svm.core.option.HostedOptionKey;
@@ -317,13 +314,6 @@ public void duringSetup(DuringSetupAccess access) {
317314
ImageSingletons.add(RuntimeCodeInfoHistory.class, new RuntimeCodeInfoHistory());
318315
ImageSingletons.add(RuntimeCodeCache.class, new RuntimeCodeCache());
319316
ImageSingletons.add(RuntimeCodeInfoMemory.class, new RuntimeCodeInfoMemory());
320-
321-
List<MemoryManagerMXBean> memoryManagers = List.of(new CodeCacheManagerMXBean());
322-
List<MemoryPoolMXBean> memoryPools = CodeCachePoolMXBean.getMemoryPools();
323-
324-
ManagementSupport managementSupport = ManagementSupport.getSingleton();
325-
managementSupport.addPlatformManagedObjectList(MemoryManagerMXBean.class, memoryManagers);
326-
managementSupport.addPlatformManagedObjectList(MemoryPoolMXBean.class, memoryPools);
327317
}
328318

329319
@Override

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/management/ManagementFeature.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void duringSetup(DuringSetupAccess access) {
8888
for (Class<? extends PlatformManagedObject> clazz : Arrays.asList(ClassLoadingMXBean.class, CompilationMXBean.class, RuntimeMXBean.class,
8989
ThreadMXBean.class, OperatingSystemMXBean.class, MemoryMXBean.class)) {
9090
PlatformManagedObject source = ManagementFactory.getPlatformMXBean(clazz);
91-
PlatformManagedObject target = (PlatformManagedObject) ManagementSupport.getSingleton().platformManagedObjectsMap.get(clazz);
91+
PlatformManagedObject target = ManagementSupport.getSingleton().getPlatformMXBeanRaw(clazz);
9292
if (source != null && target != null) {
9393
platformManagedObjectReplacements.put(source, target);
9494
}
@@ -125,6 +125,7 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
125125
access.registerReachabilityHandler(ManagementFeature::registerMXBeanMappingMakeOpenClass, method(access, "com.sun.jmx.mbeanserver.MXBeanMapping", "makeOpenClass", Type.class, OpenType.class));
126126

127127
assert verifyMemoryManagerBeans();
128+
assert ManagementSupport.getSingleton().verifyNoOverlappingMxBeans();
128129
}
129130

130131
private static boolean verifyMemoryManagerBeans() {

0 commit comments

Comments
 (0)