Skip to content

Commit 7955f11

Browse files
[GR-49691] Maximum size of serial GC memory pools is undefined.
PullRequest: graal/15898
2 parents f2492bd + e676225 commit 7955f11

File tree

5 files changed

+71
-75
lines changed

5 files changed

+71
-75
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractMemoryPoolMXBean.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@
4545

4646
public abstract class AbstractMemoryPoolMXBean extends AbstractMXBean implements MemoryPoolMXBean {
4747

48+
protected static final UnsignedWord UNDEFINED = WordFactory.unsigned(UNDEFINED_MEMORY_USAGE);
49+
4850
private final String name;
4951
private final String[] managerNames;
5052
protected final UninterruptibleUtils.AtomicUnsigned peakUsage = new UninterruptibleUtils.AtomicUnsigned();
5153

52-
private static final UnsignedWord UNDEFINED = WordFactory.zero();
53-
protected UnsignedWord initialValue = UNDEFINED;
54+
private UnsignedWord initialValue = UNDEFINED;
5455

5556
@Platforms(Platform.HOSTED_ONLY.class)
5657
protected AbstractMemoryPoolMXBean(String name, String... managerNames) {
@@ -67,8 +68,6 @@ UnsignedWord getInitialValue() {
6768

6869
abstract UnsignedWord computeInitialValue();
6970

70-
abstract UnsignedWord getMaximumValue();
71-
7271
abstract void beforeCollection();
7372

7473
abstract void afterCollection();
@@ -167,4 +166,9 @@ void updatePeakUsage(UnsignedWord value) {
167166
current = peakUsage.get();
168167
} while (value.aboveThan(current) && !peakUsage.compareAndSet(current, value));
169168
}
169+
170+
protected UnsignedWord getMaximumValue() {
171+
/* Actual usage may temporarily exceed the maximum, so we need to return UNDEFINED. */
172+
return UNDEFINED;
173+
}
170174
}

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929

3030
import java.lang.ref.Reference;
3131

32-
import jdk.graal.compiler.api.replacements.Fold;
3332
import org.graalvm.nativeimage.CurrentIsolate;
3433
import org.graalvm.nativeimage.IsolateThread;
3534
import org.graalvm.nativeimage.Platform;
@@ -97,6 +96,8 @@
9796
import com.oracle.svm.core.util.TimeUtils;
9897
import com.oracle.svm.core.util.VMError;
9998

99+
import jdk.graal.compiler.api.replacements.Fold;
100+
100101
/**
101102
* Garbage collector (incremental or complete) for {@link HeapImpl}.
102103
*/
@@ -211,14 +212,14 @@ assert getCollectionEpoch().equal(data.getRequestingEpoch()) ||
211212
printGCBefore(cause);
212213

213214
ThreadLocalAllocation.disableAndFlushForAllThreads();
214-
GenScavengeMemoryPoolMXBeans.notifyBeforeCollection();
215+
GenScavengeMemoryPoolMXBeans.singleton().notifyBeforeCollection();
215216
HeapImpl.getAccounting().notifyBeforeCollection();
216217

217218
boolean outOfMemory = collectImpl(cause, data.getRequestingNanoTime(), data.getForceFullGC());
218219
data.setOutOfMemory(outOfMemory);
219220

220221
HeapImpl.getAccounting().notifyAfterCollection();
221-
GenScavengeMemoryPoolMXBeans.notifyAfterCollection();
222+
GenScavengeMemoryPoolMXBeans.singleton().notifyAfterCollection();
222223

223224
printGCAfter(cause);
224225
JfrGCHeapSummaryEvent.emit(JfrGCWhen.AFTER_GC);

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GenScavengeMemoryPoolMXBeans.java

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
*/
2626
package com.oracle.svm.core.genscavenge;
2727

28-
import java.lang.management.MemoryPoolMXBean;
2928
import java.lang.management.MemoryUsage;
3029

30+
import org.graalvm.nativeimage.ImageSingletons;
3131
import org.graalvm.nativeimage.Platform;
3232
import org.graalvm.nativeimage.Platforms;
3333
import org.graalvm.word.UnsignedWord;
@@ -36,8 +36,9 @@
3636
import com.oracle.svm.core.SubstrateOptions;
3737
import com.oracle.svm.core.util.VMError;
3838

39-
public class GenScavengeMemoryPoolMXBeans {
39+
import jdk.graal.compiler.api.replacements.Fold;
4040

41+
public class GenScavengeMemoryPoolMXBeans {
4142
static final String YOUNG_GEN_SCAVENGER = "young generation scavenger";
4243
static final String COMPLETE_SCAVENGER = "complete scavenger";
4344
static final String EPSILON_SCAVENGER = "epsilon scavenger";
@@ -47,10 +48,10 @@ public class GenScavengeMemoryPoolMXBeans {
4748
static final String OLD_GEN_SPACE = "old generation space";
4849
static final String EPSILON_HEAP = "epsilon heap";
4950

50-
private static AbstractMemoryPoolMXBean[] mxBeans;
51+
private final AbstractMemoryPoolMXBean[] mxBeans;
5152

5253
@Platforms(Platform.HOSTED_ONLY.class)
53-
public static MemoryPoolMXBean[] createMemoryPoolMXBeans() {
54+
public GenScavengeMemoryPoolMXBeans() {
5455
if (SubstrateOptions.UseSerialGC.getValue()) {
5556
mxBeans = new AbstractMemoryPoolMXBean[]{
5657
new EdenMemoryPoolMXBean(YOUNG_GEN_SCAVENGER, COMPLETE_SCAVENGER),
@@ -63,16 +64,24 @@ public static MemoryPoolMXBean[] createMemoryPoolMXBeans() {
6364
new EpsilonMemoryPoolMXBean(EPSILON_SCAVENGER)
6465
};
6566
}
67+
}
68+
69+
@Fold
70+
public static GenScavengeMemoryPoolMXBeans singleton() {
71+
return ImageSingletons.lookup(GenScavengeMemoryPoolMXBeans.class);
72+
}
73+
74+
public AbstractMemoryPoolMXBean[] getMXBeans() {
6675
return mxBeans;
6776
}
6877

69-
public static void notifyBeforeCollection() {
78+
public void notifyBeforeCollection() {
7079
for (AbstractMemoryPoolMXBean mxBean : mxBeans) {
7180
mxBean.beforeCollection();
7281
}
7382
}
7483

75-
public static void notifyAfterCollection() {
84+
public void notifyAfterCollection() {
7685
for (AbstractMemoryPoolMXBean mxBean : mxBeans) {
7786
mxBean.afterCollection();
7887
}
@@ -100,11 +109,6 @@ UnsignedWord computeInitialValue() {
100109
return GCImpl.getPolicy().getInitialEdenSize();
101110
}
102111

103-
@Override
104-
UnsignedWord getMaximumValue() {
105-
return GCImpl.getPolicy().getMaximumEdenSize();
106-
}
107-
108112
@Override
109113
public MemoryUsage getUsage() {
110114
return memoryUsage(getCurrentUsage());
@@ -148,11 +152,6 @@ UnsignedWord computeInitialValue() {
148152
return GCImpl.getPolicy().getInitialSurvivorSize();
149153
}
150154

151-
@Override
152-
UnsignedWord getMaximumValue() {
153-
return GCImpl.getPolicy().getMaximumSurvivorSize();
154-
}
155-
156155
@Override
157156
public MemoryUsage getUsage() {
158157
return getCollectionUsage();
@@ -191,11 +190,6 @@ UnsignedWord computeInitialValue() {
191190
return GCImpl.getPolicy().getInitialOldSize();
192191
}
193192

194-
@Override
195-
UnsignedWord getMaximumValue() {
196-
return GCImpl.getPolicy().getMaximumOldSize();
197-
}
198-
199193
@Override
200194
public MemoryUsage getUsage() {
201195
return getCollectionUsage();
@@ -234,11 +228,6 @@ UnsignedWord computeInitialValue() {
234228
return GCImpl.getPolicy().getMinimumHeapSize();
235229
}
236230

237-
@Override
238-
UnsignedWord getMaximumValue() {
239-
return GCImpl.getPolicy().getMaximumHeapSize();
240-
}
241-
242231
@Override
243232
public MemoryUsage getUsage() {
244233
HeapAccounting accounting = HeapImpl.getAccounting();

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

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

27-
import java.lang.management.MemoryPoolMXBean;
2827
import java.util.Arrays;
2928
import java.util.Collections;
3029
import java.util.List;
3130
import java.util.Map;
3231

33-
import jdk.graal.compiler.graph.Node;
34-
import jdk.graal.compiler.options.OptionValues;
35-
import jdk.graal.compiler.phases.util.Providers;
3632
import org.graalvm.nativeimage.ImageSingletons;
3733
import org.graalvm.nativeimage.hosted.Feature;
3834

@@ -70,6 +66,10 @@
7066
import com.oracle.svm.core.jvmstat.PerfManager;
7167
import com.sun.management.GarbageCollectorMXBean;
7268

69+
import jdk.graal.compiler.graph.Node;
70+
import jdk.graal.compiler.options.OptionValues;
71+
import jdk.graal.compiler.phases.util.Providers;
72+
7373
@AutomaticallyRegisteredFeature
7474
class GenScavengeGCFeature implements InternalFeature {
7575
@Override
@@ -95,7 +95,9 @@ public void duringSetup(DuringSetupAccess access) {
9595
ImageSingletons.add(Heap.class, heap);
9696
ImageSingletons.add(GCAllocationSupport.class, new GenScavengeAllocationSupport());
9797

98-
List<MemoryPoolMXBean> memoryPools = Arrays.asList(GenScavengeMemoryPoolMXBeans.createMemoryPoolMXBeans());
98+
GenScavengeMemoryPoolMXBeans memoryPoolMXBeans = new GenScavengeMemoryPoolMXBeans();
99+
ImageSingletons.add(GenScavengeMemoryPoolMXBeans.class, memoryPoolMXBeans);
100+
99101
List<GarbageCollectorMXBean> garbageCollectors;
100102
if (SubstrateOptions.UseEpsilonGC.getValue()) {
101103
garbageCollectors = Arrays.asList(new EpsilonGarbageCollectorMXBean());
@@ -105,7 +107,7 @@ public void duringSetup(DuringSetupAccess access) {
105107

106108
ManagementSupport managementSupport = ManagementSupport.getSingleton();
107109
managementSupport.addPlatformManagedObjectSingleton(java.lang.management.MemoryMXBean.class, new HeapImplMemoryMXBean());
108-
managementSupport.addPlatformManagedObjectList(java.lang.management.MemoryPoolMXBean.class, memoryPools);
110+
managementSupport.addPlatformManagedObjectList(java.lang.management.MemoryPoolMXBean.class, Arrays.asList(memoryPoolMXBeans.getMXBeans()));
109111
managementSupport.addPlatformManagedObjectList(com.sun.management.GarbageCollectorMXBean.class, garbageCollectors);
110112
/* Not supported yet. */
111113
managementSupport.addPlatformManagedObjectList(java.lang.management.BufferPoolMXBean.class, Collections.emptyList());

substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/substitutions/GraalSubstitutions.java

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,44 +34,9 @@
3434
import java.util.Map;
3535
import java.util.concurrent.ConcurrentHashMap;
3636

37-
import com.oracle.svm.graal.GraalSupport;
38-
import jdk.graal.compiler.core.match.MatchRuleRegistry;
39-
import jdk.graal.compiler.debug.KeyRegistry;
40-
import jdk.graal.compiler.debug.TTY;
41-
import jdk.graal.compiler.nodes.NamedLocationIdentity;
42-
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
43-
import jdk.graal.compiler.phases.common.inlining.info.elem.InlineableGraph;
44-
import jdk.graal.compiler.phases.common.inlining.walker.ComputeInliningRelevance;
45-
import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode;
46-
import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode;
4737
import org.graalvm.collections.EconomicMap;
4838
import org.graalvm.collections.EconomicSet;
4939
import org.graalvm.collections.Equivalence;
50-
import jdk.graal.compiler.core.common.CompilationIdentifier;
51-
import jdk.graal.compiler.core.common.SuppressFBWarnings;
52-
import jdk.graal.compiler.core.gen.NodeLIRBuilder;
53-
import jdk.graal.compiler.core.match.MatchStatement;
54-
import jdk.graal.compiler.debug.DebugContext;
55-
import jdk.graal.compiler.debug.DebugHandlersFactory;
56-
import jdk.graal.compiler.debug.MetricKey;
57-
import jdk.graal.compiler.debug.TimeSource;
58-
import jdk.graal.compiler.graph.Node;
59-
import jdk.graal.compiler.graph.NodeClass;
60-
import jdk.graal.compiler.lir.CompositeValue;
61-
import jdk.graal.compiler.lir.CompositeValueClass;
62-
import jdk.graal.compiler.lir.LIRInstruction;
63-
import jdk.graal.compiler.lir.LIRInstructionClass;
64-
import jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool;
65-
import jdk.graal.compiler.lir.phases.LIRPhase;
66-
import jdk.graal.compiler.nodes.Invoke;
67-
import jdk.graal.compiler.nodes.StructuredGraph;
68-
import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool;
69-
import jdk.graal.compiler.options.OptionValues;
70-
import jdk.graal.compiler.phases.BasePhase;
71-
import jdk.graal.compiler.phases.common.CanonicalizerPhase;
72-
import jdk.graal.compiler.phases.tiers.HighTierContext;
73-
import jdk.graal.compiler.printer.NoDeadCodeVerifyHandler;
74-
import jdk.graal.compiler.serviceprovider.GlobalAtomicLong;
7540
import org.graalvm.nativeimage.CurrentIsolate;
7641
import org.graalvm.nativeimage.ImageSingletons;
7742
import org.graalvm.nativeimage.hosted.FieldValueTransformer;
@@ -94,11 +59,46 @@
9459
import com.oracle.svm.core.log.Log;
9560
import com.oracle.svm.core.option.HostedOptionValues;
9661
import com.oracle.svm.core.util.VMError;
62+
import com.oracle.svm.graal.GraalSupport;
9763
import com.oracle.svm.graal.hosted.FieldsOffsetsFeature;
9864
import com.oracle.svm.graal.hosted.RuntimeCompilationFeature;
9965
import com.oracle.svm.graal.meta.SubstrateMethod;
10066
import com.oracle.svm.util.ReflectionUtil;
10167

68+
import jdk.graal.compiler.core.common.CompilationIdentifier;
69+
import jdk.graal.compiler.core.common.SuppressFBWarnings;
70+
import jdk.graal.compiler.core.gen.NodeLIRBuilder;
71+
import jdk.graal.compiler.core.match.MatchRuleRegistry;
72+
import jdk.graal.compiler.core.match.MatchStatement;
73+
import jdk.graal.compiler.debug.DebugContext;
74+
import jdk.graal.compiler.debug.DebugHandlersFactory;
75+
import jdk.graal.compiler.debug.KeyRegistry;
76+
import jdk.graal.compiler.debug.MetricKey;
77+
import jdk.graal.compiler.debug.TTY;
78+
import jdk.graal.compiler.debug.TimeSource;
79+
import jdk.graal.compiler.graph.Node;
80+
import jdk.graal.compiler.graph.NodeClass;
81+
import jdk.graal.compiler.lir.CompositeValue;
82+
import jdk.graal.compiler.lir.CompositeValueClass;
83+
import jdk.graal.compiler.lir.LIRInstruction;
84+
import jdk.graal.compiler.lir.LIRInstructionClass;
85+
import jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool;
86+
import jdk.graal.compiler.lir.phases.LIRPhase;
87+
import jdk.graal.compiler.nodes.Invoke;
88+
import jdk.graal.compiler.nodes.NamedLocationIdentity;
89+
import jdk.graal.compiler.nodes.StructuredGraph;
90+
import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins;
91+
import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool;
92+
import jdk.graal.compiler.options.OptionValues;
93+
import jdk.graal.compiler.phases.BasePhase;
94+
import jdk.graal.compiler.phases.common.CanonicalizerPhase;
95+
import jdk.graal.compiler.phases.common.inlining.info.elem.InlineableGraph;
96+
import jdk.graal.compiler.phases.common.inlining.walker.ComputeInliningRelevance;
97+
import jdk.graal.compiler.phases.tiers.HighTierContext;
98+
import jdk.graal.compiler.printer.NoDeadCodeVerifyHandler;
99+
import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode;
100+
import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode;
101+
import jdk.graal.compiler.serviceprovider.GlobalAtomicLong;
102102
import jdk.vm.ci.code.TargetDescription;
103103
import jdk.vm.ci.meta.ResolvedJavaMethod;
104104

@@ -235,7 +235,7 @@ class GlobalAtomicLongAddressProvider implements FieldValueTransformer {
235235
@Override
236236
public Object transform(Object receiver, Object originalValue) {
237237
long initialValue = ((GlobalAtomicLong) receiver).getInitialValue();
238-
return CGlobalDataFactory.createWord((Pointer) WordFactory.unsigned(initialValue), null, true);
238+
return CGlobalDataFactory.createWord(WordFactory.unsigned(initialValue), null, true);
239239
}
240240
}
241241

0 commit comments

Comments
 (0)