Skip to content

Commit 4784986

Browse files
committed
only set libgraal related image system properties when building libgraal
1 parent 8ac8e30 commit 4784986

File tree

8 files changed

+30
-23
lines changed

8 files changed

+30
-23
lines changed

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/core/common/LibGraalSupport.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import org.graalvm.collections.EconomicMap;
2828
import org.graalvm.nativeimage.Platform;
2929
import org.graalvm.nativeimage.Platforms;
30-
import org.graalvm.nativeimage.hosted.RuntimeSystemProperties;
3130

3231
import java.io.PrintStream;
3332
import java.lang.ref.Reference;
@@ -46,17 +45,11 @@
4645
public interface LibGraalSupport {
4746

4847
/**
49-
* Prefix to be used when {@linkplain RuntimeSystemProperties#register registering} properties
50-
* describing the image configuration for libgraal. This is analogous to the configuration info
51-
* displayed by {@code -XshowSettings}.
52-
* <p>
53-
* For example:
54-
*
55-
* <pre>
56-
* RuntimeSystemProperties.register(NATIVE_IMAGE_SETTING_KEY_PREFIX + "gc", "serial");
57-
* </pre>
48+
* Prefix to use for an image runtime system property describing some aspect of the libgraal
49+
* image configuration. These properties are included in the output of
50+
* {@code -Djdk.graal.ShowConfiguration}.
5851
*/
59-
String NATIVE_IMAGE_SETTING_KEY_PREFIX = "org.graalvm.nativeimage.setting.";
52+
String LIBGRAAL_SETTING_PROPERTY_PREFIX = "libgraal.setting.";
6053

6154
/**
6255
* Called to signal a fatal, non-recoverable error. This method does not return or throw an

compiler/src/jdk.graal.compiler/src/jdk/graal/compiler/hotspot/CompilerConfigurationFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
package jdk.graal.compiler.hotspot;
2626

2727
import static jdk.vm.ci.common.InitTimer.timer;
28-
import static jdk.graal.compiler.core.common.LibGraalSupport.NATIVE_IMAGE_SETTING_KEY_PREFIX;
28+
import static jdk.graal.compiler.core.common.LibGraalSupport.LIBGRAAL_SETTING_PROPERTY_PREFIX;
2929

3030
import java.util.ArrayList;
3131
import java.util.Collections;
@@ -279,9 +279,9 @@ private Object getLoadedFromLocation(boolean verbose) {
279279
String justification = "properties initialized via org.graalvm.nativeimage.hosted.RuntimeSystemProperties " +
280280
"are not accessible via GraalServices.getSavedProperties()";
281281
String settings = GraalServices.getSystemProperties(justification).entrySet().stream()//
282-
.filter(e -> e.getKey().toString().startsWith(NATIVE_IMAGE_SETTING_KEY_PREFIX))//
282+
.filter(e -> e.getKey().toString().startsWith(LIBGRAAL_SETTING_PROPERTY_PREFIX))//
283283
.map(e -> {
284-
String key = e.getKey().toString().substring(NATIVE_IMAGE_SETTING_KEY_PREFIX.length());
284+
String key = e.getKey().toString().substring(LIBGRAAL_SETTING_PROPERTY_PREFIX.length());
285285
String val = e.getValue().toString();
286286
return val.isEmpty() ? key : key + "=" + val;
287287
})//

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import java.util.List;
2929
import java.util.Map;
3030

31-
import jdk.graal.compiler.core.common.LibGraalSupport;
31+
import com.oracle.svm.core.jdk.SystemPropertiesSupport;
3232
import org.graalvm.nativeimage.ImageSingletons;
3333
import org.graalvm.nativeimage.hosted.Feature;
3434

@@ -69,7 +69,6 @@
6969
import jdk.graal.compiler.graph.Node;
7070
import jdk.graal.compiler.options.OptionValues;
7171
import jdk.graal.compiler.phases.util.Providers;
72-
import org.graalvm.nativeimage.hosted.RuntimeSystemProperties;
7372

7473
@AutomaticallyRegisteredFeature
7574
class GenScavengeGCFeature implements InternalFeature {
@@ -131,8 +130,8 @@ public void beforeAnalysis(BeforeAnalysisAccess access) {
131130
ImageSingletons.add(CommittedMemoryProvider.class, createCommittedMemoryProvider());
132131
}
133132

134-
String gcName = Heap.getHeap().getGC().getName();
135-
RuntimeSystemProperties.register(LibGraalSupport.NATIVE_IMAGE_SETTING_KEY_PREFIX + "gc", gcName);
133+
// If building libgraal, set system property showing gc algorithm
134+
SystemPropertiesSupport.singleton().setLibGraalRuntimeProperty("gc", Heap.getHeap().getGC().getName());
136135

137136
// Needed for the barrier set.
138137
access.registerAsUsed(Object[].class);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,4 +1389,7 @@ public static class TruffleStableOptions {
13891389
throw UserError.invalidOptionValue(key, key.getValue(), "Mapping the image heap with mremap() is only supported on Linux.");
13901390
}
13911391
});
1392+
1393+
@Option(help = "file:doc-files/LibGraalClassLoader.txt")//
1394+
public static final HostedOptionKey<String> LibGraalClassLoader = new HostedOptionKey<>("");
13921395
}

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SystemPropertiesSupport.java

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

27+
import static jdk.graal.compiler.core.common.LibGraalSupport.LIBGRAAL_SETTING_PROPERTY_PREFIX;
2728
import static jdk.graal.compiler.nodes.extended.MembarNode.FenceKind.STORE_STORE;
2829

2930
import java.util.ArrayList;
@@ -35,10 +36,12 @@
3536
import java.util.concurrent.ConcurrentHashMap;
3637
import java.util.function.Supplier;
3738

39+
import com.oracle.svm.core.SubstrateOptions;
3840
import org.graalvm.nativeimage.ImageInfo;
3941
import org.graalvm.nativeimage.ImageSingletons;
4042
import org.graalvm.nativeimage.Platform;
4143
import org.graalvm.nativeimage.Platforms;
44+
import org.graalvm.nativeimage.hosted.RuntimeSystemProperties;
4245
import org.graalvm.nativeimage.impl.RuntimeSystemPropertiesSupport;
4346

4447
import com.oracle.svm.core.SubstrateUtil;
@@ -290,6 +293,18 @@ private synchronized void initializeAllProperties() {
290293
allPropertiesInitialized = true;
291294
}
292295

296+
/**
297+
* If the current image being built is libgraal, sets a runtime system property used to describe
298+
* some aspect of the libgraal image configuration.
299+
*
300+
* @see jdk.graal.compiler.core.common.LibGraalSupport#LIBGRAAL_SETTING_PROPERTY_PREFIX
301+
*/
302+
public void setLibGraalRuntimeProperty(String name, String value) {
303+
if (!SubstrateOptions.LibGraalClassLoader.getValue().isEmpty()) {
304+
RuntimeSystemProperties.register(LIBGRAAL_SETTING_PROPERTY_PREFIX + name, value);
305+
}
306+
}
307+
293308
private void ensurePropertyInitialized(String key) {
294309
if (allPropertiesInitialized) {
295310
return;

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageClassLoaderSupport.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,9 +572,9 @@ private Stream<AddExportsAndOpensAndReadsFormatValue> processOption(OptionKey<Ac
572572
}
573573

574574
public void setupLibGraalClassLoader() {
575-
var className = NativeImageOptions.LibGraalClassLoader.getValue(parsedHostedOptions);
575+
var className = SubstrateOptions.LibGraalClassLoader.getValue(parsedHostedOptions);
576576
if (!className.isEmpty()) {
577-
String nameOption = SubstrateOptionsParser.commandArgument(NativeImageOptions.LibGraalClassLoader, className);
577+
String nameOption = SubstrateOptionsParser.commandArgument(SubstrateOptions.LibGraalClassLoader, className);
578578
try {
579579
Class<?> loaderClass = Class.forName(className, true, classLoader);
580580
if (!LibGraalLoader.class.isAssignableFrom(loaderClass)) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,4 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Boolean o
305305
}
306306
}
307307
};
308-
309-
@Option(help = "file:doc-files/LibGraalClassLoader.txt")//
310-
public static final HostedOptionKey<String> LibGraalClassLoader = new HostedOptionKey<>("");
311308
}

0 commit comments

Comments
 (0)