diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java index 960907a0782f..67f563558226 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java @@ -24,6 +24,8 @@ */ package com.oracle.svm.core; +import static com.oracle.svm.core.jvmstat.PerfManager.Options.PerfDataMemoryMappedFile; + import java.io.IOException; import java.util.HashSet; import java.util.List; @@ -78,14 +80,14 @@ public final class VMInspectionOptions { ", '" + MONITORING_JCMD_NAME + "' (experimental)" + ", or '" + MONITORING_ALL_NAME + "' (deprecated behavior: defaults to '" + MONITORING_ALL_NAME + "' if no argument is provided)"; - @APIOption(name = ENABLE_MONITORING_OPTION, defaultValue = MONITORING_DEFAULT_NAME) // + @APIOption(name = ENABLE_MONITORING_OPTION, defaultValue = MONITORING_DEFAULT_NAME)// @Option(help = "Enable monitoring features that allow the VM to be inspected at run time. Comma-separated list can contain " + MONITORING_ALLOWED_VALUES_TEXT + ". " + - "For example: '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_HEAPDUMP_NAME + "," + MONITORING_JFR_NAME + "'.", type = OptionType.User) // + "For example: '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_HEAPDUMP_NAME + "," + MONITORING_JFR_NAME + "'.", type = OptionType.User)// public static final HostedOptionKey EnableMonitoringFeatures = new HostedOptionKey<>( AccumulatingLocatableMultiOptionValue.Strings.buildWithCommaDelimiter(), VMInspectionOptions::validateEnableMonitoringFeatures); - @Option(help = "Dumps all runtime compiled methods on SIGUSR2.", type = OptionType.User) // + @Option(help = "Dumps all runtime compiled methods on SIGUSR2.", type = OptionType.User)// public static final HostedOptionKey DumpRuntimeCompilationOnSignal = new HostedOptionKey<>(false, VMInspectionOptions::notSupportedOnWindows); static { @@ -100,7 +102,7 @@ private static void notSupportedOnWindows(HostedOptionKey optionKey) { } } - @Option(help = "Print native memory tracking statistics on shutdown if native memory tracking is enabled.", type = OptionType.User) // + @Option(help = "Print native memory tracking statistics on shutdown if native memory tracking is enabled.", type = OptionType.User)// public static final RuntimeOptionKey PrintNMTStatistics = new RuntimeOptionKey<>(false); @Platforms(Platform.HOSTED_ONLY.class) @@ -122,6 +124,11 @@ public static void validateEnableMonitoringFeatures(@SuppressWarnings("unused") if (Platform.includedIn(WINDOWS_BASE.class)) { Set notSupported = getEnabledMonitoringFeatures(); notSupported.retainAll(NOT_SUPPORTED_ON_WINDOWS); + if (!PerfDataMemoryMappedFile.getValue()) { + /* Only not supported on Windows, if a memory-mapped file is needed. */ + notSupported.remove(MONITORING_JVMSTAT_NAME); + } + if (!notSupported.isEmpty()) { String msg = String.format("the option '%s' contains value(s) that are not supported on Windows: %s. Those values will be ignored.", getDefaultMonitoringCommandArgument(), String.join(", ", notSupported)); @@ -191,7 +198,8 @@ public static boolean hasJfrSupport() { @Fold public static boolean hasJvmstatSupport() { - return hasAllOrKeywordMonitoringSupport(MONITORING_JVMSTAT_NAME) && !Platform.includedIn(WINDOWS_BASE.class); + /* Only not supported on Windows, if a memory-mapped file is needed. */ + return hasAllOrKeywordMonitoringSupport(MONITORING_JVMSTAT_NAME) && (!Platform.includedIn(WINDOWS_BASE.class) || !PerfDataMemoryMappedFile.getValue()); } @Fold @@ -221,7 +229,7 @@ public static boolean hasJCmdSupport() { static class DeprecatedOptions { @Option(help = "Enables features that allow the VM to be inspected during run time.", type = OptionType.User, // - deprecated = true, deprecationMessage = "Please use '--" + ENABLE_MONITORING_OPTION + "'") // + deprecated = true, deprecationMessage = "Please use '--" + ENABLE_MONITORING_OPTION + "'")// static final HostedOptionKey AllowVMInspection = new HostedOptionKey<>(false) { @Override protected void onValueUpdate(EconomicMap, Object> values, Boolean oldValue, Boolean newValue) { @@ -232,7 +240,7 @@ protected void onValueUpdate(EconomicMap, Object> values, Boolean o }; @Option(help = "Dumps all thread stacktraces on SIGQUIT/SIGBREAK.", type = OptionType.User, // - deprecated = true, deprecationMessage = "Please use '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_THREADDUMP_NAME + "'") // + deprecated = true, deprecationMessage = "Please use '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_THREADDUMP_NAME + "'")// public static final HostedOptionKey DumpThreadStacksOnSignal = new HostedOptionKey<>(false); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java index 9bc11cc3169d..ab9df4e156a4 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java @@ -26,11 +26,19 @@ import java.nio.ByteBuffer; +import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.Platform; import org.graalvm.nativeimage.Platforms; import org.graalvm.nativeimage.c.type.CLongPointer; +import jdk.graal.compiler.api.replacements.Fold; + public interface PerfDataSupport { + @Fold + static PerfDataSupport singleton() { + return ImageSingletons.lookup(PerfDataSupport.class); + } + ByteBuffer attach(int lvmid); void detach(ByteBuffer bb); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfManager.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfManager.java index 6d4d1e52f45b..b11c27f1c2c5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfManager.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfManager.java @@ -45,6 +45,7 @@ import com.oracle.svm.core.option.HostedOptionKey; import com.oracle.svm.core.option.RuntimeOptionKey; import com.oracle.svm.core.thread.RecurringCallbackSupport; +import com.oracle.svm.core.util.ImageHeapMap; import com.oracle.svm.core.util.VMError; import jdk.graal.compiler.options.Option; @@ -65,7 +66,7 @@ public class PerfManager { public PerfManager() { perfDataHolders = new ArrayList<>(); mutablePerfDataEntries = new ArrayList<>(); - longEntries = EconomicMap.create(); + longEntries = ImageHeapMap.createNonLayeredMap(); perfDataThread = new PerfDataThread(this); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java index fdc320804947..e4d134fb0c9b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java @@ -26,8 +26,6 @@ import java.nio.ByteBuffer; -import org.graalvm.nativeimage.ImageSingletons; - import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; @@ -36,32 +34,32 @@ public final class Target_jdk_internal_perf_Perf { @Substitute public ByteBuffer attach(int lvmid) { - return ImageSingletons.lookup(PerfDataSupport.class).attach(lvmid); + return PerfDataSupport.singleton().attach(lvmid); } @Substitute public void detach(ByteBuffer bb) { - ImageSingletons.lookup(PerfDataSupport.class).detach(bb); + PerfDataSupport.singleton().detach(bb); } @Substitute public long highResCounter() { - return ImageSingletons.lookup(PerfDataSupport.class).highResCounter(); + return PerfDataSupport.singleton().highResCounter(); } @Substitute public long highResFrequency() { - return ImageSingletons.lookup(PerfDataSupport.class).highResFrequency(); + return PerfDataSupport.singleton().highResFrequency(); } @Substitute public ByteBuffer createLong(String name, int variability, int units, long value) { - return ImageSingletons.lookup(PerfDataSupport.class).createLong(name, variability, units, value); + return PerfDataSupport.singleton().createLong(name, variability, units, value); } @Substitute public ByteBuffer createByteArray(String name, int variability, int units, byte[] value, int maxLength) { - return ImageSingletons.lookup(PerfDataSupport.class).createByteArray(name, variability, units, value, maxLength); + return PerfDataSupport.singleton().createByteArray(name, variability, units, value, maxLength); } @Substitute