Skip to content

Commit 6eb6663

Browse files
Support jvmstat on Windows if no memory-mapped file is needed.
1 parent f0c8789 commit 6eb6663

File tree

4 files changed

+31
-16
lines changed

4 files changed

+31
-16
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/VMInspectionOptions.java

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

27+
import static com.oracle.svm.core.jvmstat.PerfManager.Options.PerfDataMemoryMappedFile;
28+
2729
import java.io.IOException;
2830
import java.util.HashSet;
2931
import java.util.List;
@@ -78,14 +80,14 @@ public final class VMInspectionOptions {
7880
", '" + MONITORING_JCMD_NAME + "' (experimental)" +
7981
", or '" + MONITORING_ALL_NAME + "' (deprecated behavior: defaults to '" + MONITORING_ALL_NAME + "' if no argument is provided)";
8082

81-
@APIOption(name = ENABLE_MONITORING_OPTION, defaultValue = MONITORING_DEFAULT_NAME) //
83+
@APIOption(name = ENABLE_MONITORING_OPTION, defaultValue = MONITORING_DEFAULT_NAME)//
8284
@Option(help = "Enable monitoring features that allow the VM to be inspected at run time. Comma-separated list can contain " + MONITORING_ALLOWED_VALUES_TEXT + ". " +
83-
"For example: '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_HEAPDUMP_NAME + "," + MONITORING_JFR_NAME + "'.", type = OptionType.User) //
85+
"For example: '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_HEAPDUMP_NAME + "," + MONITORING_JFR_NAME + "'.", type = OptionType.User)//
8486
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> EnableMonitoringFeatures = new HostedOptionKey<>(
8587
AccumulatingLocatableMultiOptionValue.Strings.buildWithCommaDelimiter(),
8688
VMInspectionOptions::validateEnableMonitoringFeatures);
8789

88-
@Option(help = "Dumps all runtime compiled methods on SIGUSR2.", type = OptionType.User) //
90+
@Option(help = "Dumps all runtime compiled methods on SIGUSR2.", type = OptionType.User)//
8991
public static final HostedOptionKey<Boolean> DumpRuntimeCompilationOnSignal = new HostedOptionKey<>(false, VMInspectionOptions::notSupportedOnWindows);
9092

9193
static {
@@ -100,7 +102,7 @@ private static void notSupportedOnWindows(HostedOptionKey<Boolean> optionKey) {
100102
}
101103
}
102104

103-
@Option(help = "Print native memory tracking statistics on shutdown if native memory tracking is enabled.", type = OptionType.User) //
105+
@Option(help = "Print native memory tracking statistics on shutdown if native memory tracking is enabled.", type = OptionType.User)//
104106
public static final RuntimeOptionKey<Boolean> PrintNMTStatistics = new RuntimeOptionKey<>(false);
105107

106108
@Platforms(Platform.HOSTED_ONLY.class)
@@ -122,6 +124,11 @@ public static void validateEnableMonitoringFeatures(@SuppressWarnings("unused")
122124
if (Platform.includedIn(WINDOWS_BASE.class)) {
123125
Set<String> notSupported = getEnabledMonitoringFeatures();
124126
notSupported.retainAll(NOT_SUPPORTED_ON_WINDOWS);
127+
if (!PerfDataMemoryMappedFile.getValue()) {
128+
/* Only not supported on Windows, if a memory-mapped file is needed. */
129+
notSupported.remove(MONITORING_JVMSTAT_NAME);
130+
}
131+
125132
if (!notSupported.isEmpty()) {
126133
String msg = String.format("the option '%s' contains value(s) that are not supported on Windows: %s. Those values will be ignored.", getDefaultMonitoringCommandArgument(),
127134
String.join(", ", notSupported));
@@ -191,7 +198,8 @@ public static boolean hasJfrSupport() {
191198

192199
@Fold
193200
public static boolean hasJvmstatSupport() {
194-
return hasAllOrKeywordMonitoringSupport(MONITORING_JVMSTAT_NAME) && !Platform.includedIn(WINDOWS_BASE.class);
201+
/* Only not supported on Windows, if a memory-mapped file is needed. */
202+
return hasAllOrKeywordMonitoringSupport(MONITORING_JVMSTAT_NAME) && (!Platform.includedIn(WINDOWS_BASE.class) || !PerfDataMemoryMappedFile.getValue());
195203
}
196204

197205
@Fold
@@ -221,7 +229,7 @@ public static boolean hasJCmdSupport() {
221229

222230
static class DeprecatedOptions {
223231
@Option(help = "Enables features that allow the VM to be inspected during run time.", type = OptionType.User, //
224-
deprecated = true, deprecationMessage = "Please use '--" + ENABLE_MONITORING_OPTION + "'") //
232+
deprecated = true, deprecationMessage = "Please use '--" + ENABLE_MONITORING_OPTION + "'")//
225233
static final HostedOptionKey<Boolean> AllowVMInspection = new HostedOptionKey<>(false) {
226234
@Override
227235
protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean oldValue, Boolean newValue) {
@@ -232,7 +240,7 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
232240
};
233241

234242
@Option(help = "Dumps all thread stacktraces on SIGQUIT/SIGBREAK.", type = OptionType.User, //
235-
deprecated = true, deprecationMessage = "Please use '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_THREADDUMP_NAME + "'") //
243+
deprecated = true, deprecationMessage = "Please use '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_THREADDUMP_NAME + "'")//
236244
public static final HostedOptionKey<Boolean> DumpThreadStacksOnSignal = new HostedOptionKey<>(false);
237245
}
238246

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfDataSupport.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,19 @@
2626

2727
import java.nio.ByteBuffer;
2828

29+
import org.graalvm.nativeimage.ImageSingletons;
2930
import org.graalvm.nativeimage.Platform;
3031
import org.graalvm.nativeimage.Platforms;
3132
import org.graalvm.nativeimage.c.type.CLongPointer;
3233

34+
import jdk.graal.compiler.api.replacements.Fold;
35+
3336
public interface PerfDataSupport {
37+
@Fold
38+
static PerfDataSupport singleton() {
39+
return ImageSingletons.lookup(PerfDataSupport.class);
40+
}
41+
3442
ByteBuffer attach(int lvmid);
3543

3644
void detach(ByteBuffer bb);

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/PerfManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import com.oracle.svm.core.option.HostedOptionKey;
4646
import com.oracle.svm.core.option.RuntimeOptionKey;
4747
import com.oracle.svm.core.thread.RecurringCallbackSupport;
48+
import com.oracle.svm.core.util.ImageHeapMap;
4849
import com.oracle.svm.core.util.VMError;
4950

5051
import jdk.graal.compiler.options.Option;
@@ -65,7 +66,7 @@ public class PerfManager {
6566
public PerfManager() {
6667
perfDataHolders = new ArrayList<>();
6768
mutablePerfDataEntries = new ArrayList<>();
68-
longEntries = EconomicMap.create();
69+
longEntries = ImageHeapMap.createNonLayeredMap();
6970
perfDataThread = new PerfDataThread(this);
7071
}
7172

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jvmstat/Target_jdk_internal_perf_Perf.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
import java.nio.ByteBuffer;
2828

29-
import org.graalvm.nativeimage.ImageSingletons;
30-
3129
import com.oracle.svm.core.annotate.Substitute;
3230
import com.oracle.svm.core.annotate.TargetClass;
3331

@@ -36,32 +34,32 @@
3634
public final class Target_jdk_internal_perf_Perf {
3735
@Substitute
3836
public ByteBuffer attach(int lvmid) {
39-
return ImageSingletons.lookup(PerfDataSupport.class).attach(lvmid);
37+
return PerfDataSupport.singleton().attach(lvmid);
4038
}
4139

4240
@Substitute
4341
public void detach(ByteBuffer bb) {
44-
ImageSingletons.lookup(PerfDataSupport.class).detach(bb);
42+
PerfDataSupport.singleton().detach(bb);
4543
}
4644

4745
@Substitute
4846
public long highResCounter() {
49-
return ImageSingletons.lookup(PerfDataSupport.class).highResCounter();
47+
return PerfDataSupport.singleton().highResCounter();
5048
}
5149

5250
@Substitute
5351
public long highResFrequency() {
54-
return ImageSingletons.lookup(PerfDataSupport.class).highResFrequency();
52+
return PerfDataSupport.singleton().highResFrequency();
5553
}
5654

5755
@Substitute
5856
public ByteBuffer createLong(String name, int variability, int units, long value) {
59-
return ImageSingletons.lookup(PerfDataSupport.class).createLong(name, variability, units, value);
57+
return PerfDataSupport.singleton().createLong(name, variability, units, value);
6058
}
6159

6260
@Substitute
6361
public ByteBuffer createByteArray(String name, int variability, int units, byte[] value, int maxLength) {
64-
return ImageSingletons.lookup(PerfDataSupport.class).createByteArray(name, variability, units, value, maxLength);
62+
return PerfDataSupport.singleton().createByteArray(name, variability, units, value, maxLength);
6563
}
6664

6765
@Substitute

0 commit comments

Comments
 (0)