diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractMemoryPoolMXBean.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractMemoryPoolMXBean.java index 1fc938b07098..d0724fd7b597 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractMemoryPoolMXBean.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AbstractMemoryPoolMXBean.java @@ -45,12 +45,13 @@ public abstract class AbstractMemoryPoolMXBean extends AbstractMXBean implements MemoryPoolMXBean { + protected static final UnsignedWord UNDEFINED = WordFactory.unsigned(UNDEFINED_MEMORY_USAGE); + private final String name; private final String[] managerNames; protected final UninterruptibleUtils.AtomicUnsigned peakUsage = new UninterruptibleUtils.AtomicUnsigned(); - private static final UnsignedWord UNDEFINED = WordFactory.zero(); - protected UnsignedWord initialValue = UNDEFINED; + private UnsignedWord initialValue = UNDEFINED; @Platforms(Platform.HOSTED_ONLY.class) protected AbstractMemoryPoolMXBean(String name, String... managerNames) { @@ -67,8 +68,6 @@ UnsignedWord getInitialValue() { abstract UnsignedWord computeInitialValue(); - abstract UnsignedWord getMaximumValue(); - abstract void beforeCollection(); abstract void afterCollection(); @@ -167,4 +166,9 @@ void updatePeakUsage(UnsignedWord value) { current = peakUsage.get(); } while (value.aboveThan(current) && !peakUsage.compareAndSet(current, value)); } + + protected UnsignedWord getMaximumValue() { + /* Actual usage may temporarily exceed the maximum, so we need to return UNDEFINED. */ + return UNDEFINED; + } } diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java index 3ff352baf538..2ccf9cdea9d0 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java @@ -29,7 +29,6 @@ import java.lang.ref.Reference; -import jdk.graal.compiler.api.replacements.Fold; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.IsolateThread; import org.graalvm.nativeimage.Platform; @@ -97,6 +96,8 @@ import com.oracle.svm.core.util.TimeUtils; import com.oracle.svm.core.util.VMError; +import jdk.graal.compiler.api.replacements.Fold; + /** * Garbage collector (incremental or complete) for {@link HeapImpl}. */ @@ -211,14 +212,14 @@ assert getCollectionEpoch().equal(data.getRequestingEpoch()) || printGCBefore(cause); ThreadLocalAllocation.disableAndFlushForAllThreads(); - GenScavengeMemoryPoolMXBeans.notifyBeforeCollection(); + GenScavengeMemoryPoolMXBeans.singleton().notifyBeforeCollection(); HeapImpl.getAccounting().notifyBeforeCollection(); boolean outOfMemory = collectImpl(cause, data.getRequestingNanoTime(), data.getForceFullGC()); data.setOutOfMemory(outOfMemory); HeapImpl.getAccounting().notifyAfterCollection(); - GenScavengeMemoryPoolMXBeans.notifyAfterCollection(); + GenScavengeMemoryPoolMXBeans.singleton().notifyAfterCollection(); printGCAfter(cause); JfrGCHeapSummaryEvent.emit(JfrGCWhen.AFTER_GC); diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GenScavengeMemoryPoolMXBeans.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GenScavengeMemoryPoolMXBeans.java index c60fce4681b1..0eb785bd61db 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GenScavengeMemoryPoolMXBeans.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GenScavengeMemoryPoolMXBeans.java @@ -25,9 +25,9 @@ */ package com.oracle.svm.core.genscavenge; -import java.lang.management.MemoryPoolMXBean; import java.lang.management.MemoryUsage; +import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.word.UnsignedWord; @@ -36,8 +36,9 @@ import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.util.VMError; -public class GenScavengeMemoryPoolMXBeans { +import jdk.graal.compiler.api.replacements.Fold; +public class GenScavengeMemoryPoolMXBeans { static final String YOUNG_GEN_SCAVENGER = "young generation scavenger"; static final String COMPLETE_SCAVENGER = "complete scavenger"; static final String EPSILON_SCAVENGER = "epsilon scavenger"; @@ -47,10 +48,10 @@ public class GenScavengeMemoryPoolMXBeans { static final String OLD_GEN_SPACE = "old generation space"; static final String EPSILON_HEAP = "epsilon heap"; - private static AbstractMemoryPoolMXBean[] mxBeans; + private final AbstractMemoryPoolMXBean[] mxBeans; @Platforms(Platform.HOSTED_ONLY.class) - public static MemoryPoolMXBean[] createMemoryPoolMXBeans() { + public GenScavengeMemoryPoolMXBeans() { if (SubstrateOptions.UseSerialGC.getValue()) { mxBeans = new AbstractMemoryPoolMXBean[]{ new EdenMemoryPoolMXBean(YOUNG_GEN_SCAVENGER, COMPLETE_SCAVENGER), @@ -63,16 +64,24 @@ public static MemoryPoolMXBean[] createMemoryPoolMXBeans() { new EpsilonMemoryPoolMXBean(EPSILON_SCAVENGER) }; } + } + + @Fold + public static GenScavengeMemoryPoolMXBeans singleton() { + return ImageSingletons.lookup(GenScavengeMemoryPoolMXBeans.class); + } + + public AbstractMemoryPoolMXBean[] getMXBeans() { return mxBeans; } - public static void notifyBeforeCollection() { + public void notifyBeforeCollection() { for (AbstractMemoryPoolMXBean mxBean : mxBeans) { mxBean.beforeCollection(); } } - public static void notifyAfterCollection() { + public void notifyAfterCollection() { for (AbstractMemoryPoolMXBean mxBean : mxBeans) { mxBean.afterCollection(); } @@ -100,11 +109,6 @@ UnsignedWord computeInitialValue() { return GCImpl.getPolicy().getInitialEdenSize(); } - @Override - UnsignedWord getMaximumValue() { - return GCImpl.getPolicy().getMaximumEdenSize(); - } - @Override public MemoryUsage getUsage() { return memoryUsage(getCurrentUsage()); @@ -148,11 +152,6 @@ UnsignedWord computeInitialValue() { return GCImpl.getPolicy().getInitialSurvivorSize(); } - @Override - UnsignedWord getMaximumValue() { - return GCImpl.getPolicy().getMaximumSurvivorSize(); - } - @Override public MemoryUsage getUsage() { return getCollectionUsage(); @@ -191,11 +190,6 @@ UnsignedWord computeInitialValue() { return GCImpl.getPolicy().getInitialOldSize(); } - @Override - UnsignedWord getMaximumValue() { - return GCImpl.getPolicy().getMaximumOldSize(); - } - @Override public MemoryUsage getUsage() { return getCollectionUsage(); @@ -234,11 +228,6 @@ UnsignedWord computeInitialValue() { return GCImpl.getPolicy().getMinimumHeapSize(); } - @Override - UnsignedWord getMaximumValue() { - return GCImpl.getPolicy().getMaximumHeapSize(); - } - @Override public MemoryUsage getUsage() { HeapAccounting accounting = HeapImpl.getAccounting(); diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java index 6d3abab9a557..6727381fad42 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/graal/GenScavengeGCFeature.java @@ -24,15 +24,11 @@ */ package com.oracle.svm.core.genscavenge.graal; -import java.lang.management.MemoryPoolMXBean; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Map; -import jdk.graal.compiler.graph.Node; -import jdk.graal.compiler.options.OptionValues; -import jdk.graal.compiler.phases.util.Providers; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.Feature; @@ -70,6 +66,10 @@ import com.oracle.svm.core.jvmstat.PerfManager; import com.sun.management.GarbageCollectorMXBean; +import jdk.graal.compiler.graph.Node; +import jdk.graal.compiler.options.OptionValues; +import jdk.graal.compiler.phases.util.Providers; + @AutomaticallyRegisteredFeature class GenScavengeGCFeature implements InternalFeature { @Override @@ -95,7 +95,9 @@ public void duringSetup(DuringSetupAccess access) { ImageSingletons.add(Heap.class, heap); ImageSingletons.add(GCAllocationSupport.class, new GenScavengeAllocationSupport()); - List memoryPools = Arrays.asList(GenScavengeMemoryPoolMXBeans.createMemoryPoolMXBeans()); + GenScavengeMemoryPoolMXBeans memoryPoolMXBeans = new GenScavengeMemoryPoolMXBeans(); + ImageSingletons.add(GenScavengeMemoryPoolMXBeans.class, memoryPoolMXBeans); + List garbageCollectors; if (SubstrateOptions.UseEpsilonGC.getValue()) { garbageCollectors = Arrays.asList(new EpsilonGarbageCollectorMXBean()); @@ -105,7 +107,7 @@ public void duringSetup(DuringSetupAccess access) { ManagementSupport managementSupport = ManagementSupport.getSingleton(); managementSupport.addPlatformManagedObjectSingleton(java.lang.management.MemoryMXBean.class, new HeapImplMemoryMXBean()); - managementSupport.addPlatformManagedObjectList(java.lang.management.MemoryPoolMXBean.class, memoryPools); + managementSupport.addPlatformManagedObjectList(java.lang.management.MemoryPoolMXBean.class, Arrays.asList(memoryPoolMXBeans.getMXBeans())); managementSupport.addPlatformManagedObjectList(com.sun.management.GarbageCollectorMXBean.class, garbageCollectors); /* Not supported yet. */ managementSupport.addPlatformManagedObjectList(java.lang.management.BufferPoolMXBean.class, Collections.emptyList()); diff --git a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/substitutions/GraalSubstitutions.java b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/substitutions/GraalSubstitutions.java index 338206c69f9b..29342b33f5a5 100644 --- a/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/substitutions/GraalSubstitutions.java +++ b/substratevm/src/com.oracle.svm.graal/src/com/oracle/svm/graal/substitutions/GraalSubstitutions.java @@ -34,44 +34,9 @@ import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -import com.oracle.svm.graal.GraalSupport; -import jdk.graal.compiler.core.match.MatchRuleRegistry; -import jdk.graal.compiler.debug.KeyRegistry; -import jdk.graal.compiler.debug.TTY; -import jdk.graal.compiler.nodes.NamedLocationIdentity; -import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; -import jdk.graal.compiler.phases.common.inlining.info.elem.InlineableGraph; -import jdk.graal.compiler.phases.common.inlining.walker.ComputeInliningRelevance; -import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode; -import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode; import org.graalvm.collections.EconomicMap; import org.graalvm.collections.EconomicSet; import org.graalvm.collections.Equivalence; -import jdk.graal.compiler.core.common.CompilationIdentifier; -import jdk.graal.compiler.core.common.SuppressFBWarnings; -import jdk.graal.compiler.core.gen.NodeLIRBuilder; -import jdk.graal.compiler.core.match.MatchStatement; -import jdk.graal.compiler.debug.DebugContext; -import jdk.graal.compiler.debug.DebugHandlersFactory; -import jdk.graal.compiler.debug.MetricKey; -import jdk.graal.compiler.debug.TimeSource; -import jdk.graal.compiler.graph.Node; -import jdk.graal.compiler.graph.NodeClass; -import jdk.graal.compiler.lir.CompositeValue; -import jdk.graal.compiler.lir.CompositeValueClass; -import jdk.graal.compiler.lir.LIRInstruction; -import jdk.graal.compiler.lir.LIRInstructionClass; -import jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool; -import jdk.graal.compiler.lir.phases.LIRPhase; -import jdk.graal.compiler.nodes.Invoke; -import jdk.graal.compiler.nodes.StructuredGraph; -import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; -import jdk.graal.compiler.options.OptionValues; -import jdk.graal.compiler.phases.BasePhase; -import jdk.graal.compiler.phases.common.CanonicalizerPhase; -import jdk.graal.compiler.phases.tiers.HighTierContext; -import jdk.graal.compiler.printer.NoDeadCodeVerifyHandler; -import jdk.graal.compiler.serviceprovider.GlobalAtomicLong; import org.graalvm.nativeimage.CurrentIsolate; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.hosted.FieldValueTransformer; @@ -94,11 +59,46 @@ import com.oracle.svm.core.log.Log; import com.oracle.svm.core.option.HostedOptionValues; import com.oracle.svm.core.util.VMError; +import com.oracle.svm.graal.GraalSupport; import com.oracle.svm.graal.hosted.FieldsOffsetsFeature; import com.oracle.svm.graal.hosted.RuntimeCompilationFeature; import com.oracle.svm.graal.meta.SubstrateMethod; import com.oracle.svm.util.ReflectionUtil; +import jdk.graal.compiler.core.common.CompilationIdentifier; +import jdk.graal.compiler.core.common.SuppressFBWarnings; +import jdk.graal.compiler.core.gen.NodeLIRBuilder; +import jdk.graal.compiler.core.match.MatchRuleRegistry; +import jdk.graal.compiler.core.match.MatchStatement; +import jdk.graal.compiler.debug.DebugContext; +import jdk.graal.compiler.debug.DebugHandlersFactory; +import jdk.graal.compiler.debug.KeyRegistry; +import jdk.graal.compiler.debug.MetricKey; +import jdk.graal.compiler.debug.TTY; +import jdk.graal.compiler.debug.TimeSource; +import jdk.graal.compiler.graph.Node; +import jdk.graal.compiler.graph.NodeClass; +import jdk.graal.compiler.lir.CompositeValue; +import jdk.graal.compiler.lir.CompositeValueClass; +import jdk.graal.compiler.lir.LIRInstruction; +import jdk.graal.compiler.lir.LIRInstructionClass; +import jdk.graal.compiler.lir.gen.ArithmeticLIRGeneratorTool; +import jdk.graal.compiler.lir.phases.LIRPhase; +import jdk.graal.compiler.nodes.Invoke; +import jdk.graal.compiler.nodes.NamedLocationIdentity; +import jdk.graal.compiler.nodes.StructuredGraph; +import jdk.graal.compiler.nodes.graphbuilderconf.InvocationPlugins; +import jdk.graal.compiler.nodes.spi.NodeLIRBuilderTool; +import jdk.graal.compiler.options.OptionValues; +import jdk.graal.compiler.phases.BasePhase; +import jdk.graal.compiler.phases.common.CanonicalizerPhase; +import jdk.graal.compiler.phases.common.inlining.info.elem.InlineableGraph; +import jdk.graal.compiler.phases.common.inlining.walker.ComputeInliningRelevance; +import jdk.graal.compiler.phases.tiers.HighTierContext; +import jdk.graal.compiler.printer.NoDeadCodeVerifyHandler; +import jdk.graal.compiler.replacements.nodes.BinaryMathIntrinsicNode; +import jdk.graal.compiler.replacements.nodes.UnaryMathIntrinsicNode; +import jdk.graal.compiler.serviceprovider.GlobalAtomicLong; import jdk.vm.ci.code.TargetDescription; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -235,7 +235,7 @@ class GlobalAtomicLongAddressProvider implements FieldValueTransformer { @Override public Object transform(Object receiver, Object originalValue) { long initialValue = ((GlobalAtomicLong) receiver).getInitialValue(); - return CGlobalDataFactory.createWord((Pointer) WordFactory.unsigned(initialValue), null, true); + return CGlobalDataFactory.createWord(WordFactory.unsigned(initialValue), null, true); } }