Skip to content

Commit fc9a0c0

Browse files
committed
Make jvmstat layer aware
1 parent 29a5238 commit fc9a0c0

File tree

11 files changed

+77
-14
lines changed

11 files changed

+77
-14
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,13 +115,12 @@ public void duringSetup(DuringSetupAccess access) {
115115
ImageSingletons.add(TlabOptionCache.class, tlabOptionCache);
116116

117117
ImageSingletons.add(PinnedObjectSupport.class, new PinnedObjectSupportImpl());
118+
if (ImageSingletons.contains(PerfManager.class)) {
119+
ImageSingletons.lookup(PerfManager.class).register(createPerfData());
120+
}
118121
}
119122
TlabOptionCache.validateHostedOptionValues();
120123

121-
if (ImageSingletons.contains(PerfManager.class)) {
122-
ImageSingletons.lookup(PerfManager.class).register(createPerfData());
123-
}
124-
125124
if (SubstrateGCOptions.VerifyHeap.getValue()) {
126125
ImageSingletons.add(HeapVerifier.class, new HeapVerifier());
127126
}

substratevm/src/com.oracle.svm.core.posix/src/com/oracle/svm/core/posix/jvmstat/PosixPerfMemoryProvider.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040

4141
import java.nio.ByteBuffer;
4242

43-
import jdk.graal.compiler.word.Word;
4443
import org.graalvm.nativeimage.ImageSingletons;
4544
import org.graalvm.nativeimage.Platform;
4645
import org.graalvm.nativeimage.Platform.LINUX;
@@ -55,6 +54,7 @@
5554
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
5655
import com.oracle.svm.core.feature.InternalFeature;
5756
import com.oracle.svm.core.headers.LibC;
57+
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
5858
import com.oracle.svm.core.jdk.DirectByteBufferUtil;
5959
import com.oracle.svm.core.jdk.management.Target_jdk_internal_vm_VMSupport;
6060
import com.oracle.svm.core.jvmstat.PerfManager;
@@ -74,15 +74,23 @@
7474
import com.oracle.svm.core.posix.headers.PosixFile;
7575
import com.oracle.svm.core.posix.headers.Signal;
7676
import com.oracle.svm.core.posix.headers.Unistd;
77+
import com.oracle.svm.core.traits.BuiltinTraits.BuildtimeAccessOnly;
78+
import com.oracle.svm.core.traits.BuiltinTraits.RuntimeAccessOnly;
79+
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
80+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
81+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.InitialLayerOnly;
82+
import com.oracle.svm.core.traits.SingletonTraits;
7783
import com.oracle.svm.core.util.BasedOnJDKFile;
7884

7985
import jdk.graal.compiler.core.common.NumUtil;
86+
import jdk.graal.compiler.word.Word;
8087

8188
/**
8289
* This class uses high-level JDK features at the moment. In the future, we will need to rewrite
8390
* this code so that it can be executed during the isolate startup (i.e., in uninterruptible code),
8491
* see GR-40601.
8592
*/
93+
@SingletonTraits(access = RuntimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = InitialLayerOnly.class)
8694
class PosixPerfMemoryProvider implements PerfMemoryProvider {
8795
private static final String PERFDATA_NAME = "hsperfdata";
8896

@@ -539,9 +547,13 @@ public void close() {
539547
}
540548

541549
@AutomaticallyRegisteredFeature
550+
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = Independent.class)
542551
class PosixPerfMemoryFeature implements InternalFeature {
543552
@Override
544553
public boolean isInConfiguration(IsInConfigurationAccess access) {
554+
if (ImageLayerBuildingSupport.buildingExtensionLayer()) {
555+
return false;
556+
}
545557
return VMInspectionOptions.hasJvmstatSupport() && PerfDataMemoryMappedFile.getValue();
546558
}
547559

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import com.oracle.svm.core.option.APIOption;
4242
import com.oracle.svm.core.option.AccumulatingLocatableMultiOptionValue;
4343
import com.oracle.svm.core.option.HostedOptionKey;
44+
import com.oracle.svm.core.option.LayerVerifiedOption;
4445
import com.oracle.svm.core.option.RuntimeOptionKey;
4546
import com.oracle.svm.core.option.SubstrateOptionsParser;
4647
import com.oracle.svm.core.util.UserError;
@@ -83,6 +84,7 @@ public final class VMInspectionOptions {
8384
", or '" + MONITORING_ALL_NAME + "' (deprecated behavior: defaults to '" + MONITORING_ALL_NAME + "' if no argument is provided)";
8485

8586
@APIOption(name = ENABLE_MONITORING_OPTION, defaultValue = MONITORING_DEFAULT_NAME)//
87+
@LayerVerifiedOption(kind = LayerVerifiedOption.Kind.Changed, severity = LayerVerifiedOption.Severity.Error)//
8688
@Option(help = "Enable monitoring features that allow the VM to be inspected at run time. Comma-separated list can contain " + MONITORING_ALLOWED_VALUES_TEXT + ". " +
8789
"For example: '--" + ENABLE_MONITORING_OPTION + "=" + MONITORING_HEAPDUMP_NAME + "," + MONITORING_JFR_NAME + "'.", type = OptionType.User)//
8890
public static final HostedOptionKey<AccumulatingLocatableMultiOptionValue.Strings> EnableMonitoringFeatures = new HostedOptionKey<>(

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/OutOfMemoryUtil.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@
2929
import com.oracle.svm.core.Uninterruptible;
3030
import com.oracle.svm.core.VMInspectionOptions;
3131
import com.oracle.svm.core.headers.LibC;
32+
import com.oracle.svm.core.heap.dump.HeapDumpMetadata;
3233
import com.oracle.svm.core.heap.dump.HeapDumping;
34+
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
3335
import com.oracle.svm.core.jdk.JDKUtils;
3436
import com.oracle.svm.core.log.Log;
3537
import com.oracle.svm.core.stack.StackOverflowCheck;
@@ -68,7 +70,8 @@ private static void reportOutOfMemoryError0(OutOfMemoryError error) {
6870
return;
6971
}
7072

71-
if (VMInspectionOptions.hasHeapDumpSupport() && SubstrateOptions.HeapDumpOnOutOfMemoryError.getValue()) {
73+
if (VMInspectionOptions.hasHeapDumpSupport() && SubstrateOptions.HeapDumpOnOutOfMemoryError.getValue() &&
74+
(!ImageLayerBuildingSupport.buildingImageLayer() || HeapDumpMetadata.isLayeredMetadataAvailable())) {
7275
HeapDumping.singleton().dumpHeapOnOutOfMemoryError();
7376
}
7477

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/dump/HeapDumpMetadata.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,15 @@
3838
import org.graalvm.word.UnsignedWord;
3939

4040
import com.oracle.svm.core.BuildPhaseProvider.AfterCompilation;
41+
import com.oracle.svm.core.SubstrateUtil;
4142
import com.oracle.svm.core.c.NonmovableArrays;
4243
import com.oracle.svm.core.c.struct.PinnedObjectField;
4344
import com.oracle.svm.core.heap.Heap;
4445
import com.oracle.svm.core.heap.ObjectVisitor;
4546
import com.oracle.svm.core.heap.UnknownObjectField;
4647
import com.oracle.svm.core.hub.DynamicHub;
4748
import com.oracle.svm.core.hub.registry.TypeIDs;
49+
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
4850
import com.oracle.svm.core.layeredimagesingleton.LayeredImageSingletonSupport;
4951
import com.oracle.svm.core.layeredimagesingleton.MultiLayeredImageSingleton;
5052
import com.oracle.svm.core.memory.NullableNativeMemory;
@@ -57,6 +59,7 @@
5759
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.InitialLayerOnly;
5860
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.MultiLayer;
5961
import com.oracle.svm.core.traits.SingletonTraits;
62+
import com.oracle.svm.core.util.VMError;
6063
import com.oracle.svm.core.util.coder.ByteStream;
6164
import com.oracle.svm.core.util.coder.ByteStreamAccess;
6265
import com.oracle.svm.core.util.coder.NativeCoder;
@@ -123,6 +126,20 @@ public static HeapDumpMetadata singleton() {
123126
return ImageSingletons.lookup(HeapDumpMetadata.class);
124127
}
125128

129+
/**
130+
* When using layered images we must ensure that metadata has been encoded for all layers.
131+
*/
132+
public static boolean isLayeredMetadataAvailable() {
133+
SubstrateUtil.guaranteeRuntimeOnly();
134+
VMError.guarantee(ImageLayerBuildingSupport.buildingImageLayer());
135+
for (var encodedData : HeapDumpEncodedData.layeredSingletons()) {
136+
if (encodedData.data == null) {
137+
return false;
138+
}
139+
}
140+
return true;
141+
}
142+
126143
public boolean initialize() {
127144
assert classInfos.isNull() && fieldInfoTable.isNull() && fieldNameTable.isNull();
128145

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/dump/HeapDumpSupportImpl.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
import com.oracle.svm.core.heap.Heap;
4444
import com.oracle.svm.core.heap.RestrictHeapAccess;
4545
import com.oracle.svm.core.heap.VMOperationInfos;
46+
import com.oracle.svm.core.imagelayer.ImageLayerBuildingSupport;
4647
import com.oracle.svm.core.locks.VMMutex;
4748
import com.oracle.svm.core.log.Log;
4849
import com.oracle.svm.core.memory.UntrackedNullableNativeMemory;
@@ -138,7 +139,7 @@ private void dumpHeapOnOutOfMemoryError0() {
138139

139140
@Override
140141
public void dumpHeap(String filename, boolean gcBefore, boolean overwrite) throws IOException {
141-
if (!RawFileOperationSupport.isPresent()) {
142+
if (!RawFileOperationSupport.isPresent() || (ImageLayerBuildingSupport.buildingImageLayer() && !HeapDumpMetadata.isLayeredMetadataAvailable())) {
142143
throw new UnsupportedOperationException(VMInspectionOptions.getHeapDumpNotSupportedMessage());
143144
}
144145

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@
3939
import com.oracle.svm.core.jdk.RuntimeSupportFeature;
4040
import com.oracle.svm.core.thread.VMOperationListenerSupport;
4141
import com.oracle.svm.core.thread.VMOperationListenerSupportFeature;
42+
import com.oracle.svm.core.traits.BuiltinTraits.BuildtimeAccessOnly;
43+
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
44+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.Independent;
45+
import com.oracle.svm.core.traits.SingletonTraits;
4246

4347
/**
4448
* The performance data feature (hsperfdata) provides monitoring data that can be access by external
@@ -76,7 +80,14 @@
7680
* </ul>
7781
*/
7882
@AutomaticallyRegisteredFeature
83+
@SingletonTraits(access = BuildtimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = Independent.class)
7984
public class PerfDataFeature implements InternalFeature {
85+
86+
@Override
87+
public boolean isInConfiguration(IsInConfigurationAccess access) {
88+
return ImageLayerBuildingSupport.firstImageBuild();
89+
}
90+
8091
@Override
8192
public List<Class<? extends Feature>> getRequiredFeatures() {
8293
return Arrays.asList(VMOperationListenerSupportFeature.class, RuntimeSupportFeature.class);
@@ -93,13 +104,11 @@ public void afterRegistration(AfterRegistrationAccess access) {
93104

94105
SystemCounters systemCounters = new SystemCounters(manager);
95106
manager.register(systemCounters);
96-
if (ImageLayerBuildingSupport.firstImageBuild()) {
97-
VMOperationListenerSupport.get().register(systemCounters);
107+
VMOperationListenerSupport.get().register(systemCounters);
98108

99-
RuntimeSupport runtime = RuntimeSupport.getRuntimeSupport();
100-
runtime.addInitializationHook(manager.initializationHook());
101-
runtime.addTearDownHook(manager.teardownHook());
102-
}
109+
RuntimeSupport runtime = RuntimeSupport.getRuntimeSupport();
110+
runtime.addInitializationHook(manager.initializationHook());
111+
runtime.addTearDownHook(manager.teardownHook());
103112
} else {
104113
ImageSingletons.add(PerfDataSupport.class, new NoPerfDataSupport());
105114
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@
3232
import org.graalvm.nativeimage.ProcessProperties;
3333
import org.graalvm.nativeimage.c.type.CLongPointer;
3434

35+
import com.oracle.svm.core.traits.BuiltinTraits.AllAccess;
36+
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
37+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.InitialLayerOnly;
38+
import com.oracle.svm.core.traits.SingletonTraits;
39+
40+
@SingletonTraits(access = AllAccess.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = InitialLayerOnly.class)
3541
public class PerfDataSupportImpl implements PerfDataSupport {
3642
@Platforms(Platform.HOSTED_ONLY.class)
3743
PerfDataSupportImpl() {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
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.traits.BuiltinTraits.AllAccess;
49+
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
50+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.InitialLayerOnly;
51+
import com.oracle.svm.core.traits.SingletonTraits;
4852
import com.oracle.svm.core.util.ImageHeapMap;
4953
import com.oracle.svm.core.util.VMError;
5054

@@ -54,6 +58,7 @@
5458
/**
5559
* Used to create and manage performance data entries.
5660
*/
61+
@SingletonTraits(access = AllAccess.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = InitialLayerOnly.class)
5762
public class PerfManager {
5863
private final ArrayList<PerfDataHolder> perfDataHolders;
5964
private final ArrayList<MutablePerfDataEntry> mutablePerfDataEntries;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@
4444
import com.oracle.svm.core.jdk.Target_java_nio_Buffer;
4545
import com.oracle.svm.core.memory.NativeMemory;
4646
import com.oracle.svm.core.nmt.NmtCategory;
47+
import com.oracle.svm.core.traits.BuiltinTraits.RuntimeAccessOnly;
48+
import com.oracle.svm.core.traits.BuiltinTraits.SingleLayer;
49+
import com.oracle.svm.core.traits.SingletonLayeredInstallationKind.InitialLayerOnly;
50+
import com.oracle.svm.core.traits.SingletonTraits;
4751

4852
import jdk.graal.compiler.word.Word;
4953

@@ -55,6 +59,7 @@
5559
* performance data counter (i.e., we read the counter value, increment it, and write it back to the
5660
* same memory location).
5761
*/
62+
@SingletonTraits(access = RuntimeAccessOnly.class, layeredCallbacks = SingleLayer.class, layeredInstallationKind = InitialLayerOnly.class)
5863
public class PerfMemory {
5964
private static final CGlobalData<Pointer> PERF_DATA_ISOLATE = CGlobalDataFactory.createWord();
6065

0 commit comments

Comments
 (0)