Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/src/org.graalvm.nativeimage/snapshot.sigtest
Original file line number Diff line number Diff line change
Expand Up @@ -1071,6 +1071,10 @@ meth public static void registerLambdaCapturingClass(java.lang.Class<?>)
meth public static void registerWithTargetConstructorClass(java.lang.Class<?>,java.lang.Class<?>)
supr java.lang.Object

CLSS public final org.graalvm.nativeimage.hosted.RuntimeSystemProperties
meth public static void register(java.lang.String,java.lang.String)
supr java.lang.Object

CLSS public abstract interface org.graalvm.nativeimage.impl.InternalPlatform
innr public abstract interface static NATIVE_ONLY
innr public abstract interface static PLATFORM_JNI
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.graalvm.nativeimage.hosted;

import java.util.Objects;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.impl.RuntimeSystemPropertiesSupport;

public final class RuntimeSystemProperties {

/**
* Define a system property setting for image runtime. This ensures a given key has the given
* value at runtime even if no system property is set via command line of the image execution.
*
* @since 23.0
*/
public static void register(String key, String value) {
Objects.requireNonNull(key);
Objects.requireNonNull(value);
ImageSingletons.lookup(RuntimeSystemPropertiesSupport.class).initializeProperty(key, value);
}

private RuntimeSystemProperties() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2022, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* The Universal Permissive License (UPL), Version 1.0
*
* Subject to the condition set forth below, permission is hereby granted to any
* person obtaining a copy of this software, associated documentation and/or
* data (collectively the "Software"), free of charge and under any and all
* copyright rights in the Software, and any and all patent rights owned or
* freely licensable by each licensor hereunder covering either (i) the
* unmodified Software as contributed to or provided by such licensor, or (ii)
* the Larger Works (as defined below), to deal in both
*
* (a) the Software, and
*
* (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
* one is included with the Software each a "Larger Work" to which the Software
* is contributed by such licensors),
*
* without restriction, including without limitation the rights to copy, create
* derivative works of, display, perform, and distribute the Software and make,
* use, sell, offer for sale, import, export, have made, and have sold the
* Software and the Larger Work(s), and to sublicense the foregoing rights on
* either these or other terms.
*
* This license is subject to the following condition:
*
* The above copyright notice and either this complete permission notice or at a
* minimum a reference to the UPL must be included in all copies or substantial
* portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package org.graalvm.nativeimage.impl;

public interface RuntimeSystemPropertiesSupport {
void initializeProperty(String key, String value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;
import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder;
import org.graalvm.nativeimage.impl.RuntimeSystemPropertiesSupport;
import org.graalvm.word.UnsignedWord;
import org.graalvm.word.WordFactory;

Expand Down Expand Up @@ -130,6 +131,8 @@ protected String osVersionValue() {
class DarwinSystemPropertiesFeature implements InternalFeature {
@Override
public void duringSetup(DuringSetupAccess access) {
ImageSingletons.add(SystemPropertiesSupport.class, new DarwinSystemPropertiesSupport());
ImageSingletons.add(RuntimeSystemPropertiesSupport.class, new DarwinSystemPropertiesSupport());
/* GR-42971 - Remove once SystemPropertiesSupport.class ImageSingletons use is gone. */
ImageSingletons.add(SystemPropertiesSupport.class, SystemPropertiesSupport.singleton());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.graalvm.nativeimage.c.type.CCharPointer;
import org.graalvm.nativeimage.c.type.CTypeConversion;
import org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder;
import org.graalvm.nativeimage.impl.RuntimeSystemPropertiesSupport;

import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
Expand Down Expand Up @@ -92,6 +93,8 @@ class LinuxSystemPropertiesFeature implements InternalFeature {

@Override
public void duringSetup(DuringSetupAccess access) {
ImageSingletons.add(SystemPropertiesSupport.class, new LinuxSystemPropertiesSupport());
ImageSingletons.add(RuntimeSystemPropertiesSupport.class, new LinuxSystemPropertiesSupport());
/* GR-42971 - Remove once SystemPropertiesSupport.class ImageSingletons use is gone. */
ImageSingletons.add(SystemPropertiesSupport.class, SystemPropertiesSupport.singleton());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.graalvm.nativeimage.c.type.CTypeConversion;
import org.graalvm.nativeimage.c.type.VoidPointer;
import org.graalvm.nativeimage.c.type.WordPointer;
import org.graalvm.nativeimage.impl.RuntimeSystemPropertiesSupport;
import org.graalvm.word.UnsignedWord;
import org.graalvm.word.WordFactory;

Expand Down Expand Up @@ -390,6 +391,8 @@ public Pair<String, String> getOsNameAndVersion() {
class WindowsSystemPropertiesFeature implements InternalFeature {
@Override
public void duringSetup(DuringSetupAccess access) {
ImageSingletons.add(SystemPropertiesSupport.class, new WindowsSystemPropertiesSupport());
ImageSingletons.add(RuntimeSystemPropertiesSupport.class, new WindowsSystemPropertiesSupport());
/* GR-42971 - Remove once SystemPropertiesSupport.class ImageSingletons use is gone. */
ImageSingletons.add(SystemPropertiesSupport.class, SystemPropertiesSupport.singleton());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ private static synchronized void reinitialize(Target_sun_nio_fs_WindowsFileSyste
return;
}
that.needsReinitialization = NeedsReinitializationProvider.STATUS_IN_REINITIALIZATION;
that.originalConstructor(that.provider, ImageSingletons.lookup(SystemPropertiesSupport.class).userDir());
that.originalConstructor(that.provider, SystemPropertiesSupport.singleton().userDir());
that.needsReinitialization = NeedsReinitializationProvider.STATUS_REINITIALIZED;
}
}
Expand Down Expand Up @@ -433,7 +433,7 @@ static String getUserDir(Target_java_io_FileSystem that) {
*/
return Platform.includedIn(Platform.WINDOWS.class)
? that.normalize(System.getProperty("user.dir"))
: ImageSingletons.lookup(SystemPropertiesSupport.class).userDir();
: SystemPropertiesSupport.singleton().userDir();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Map;
import java.util.function.BooleanSupplier;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

Expand All @@ -54,7 +53,7 @@ public boolean getAsBoolean() {
final class Target_jdk_vm_ci_services_Services {
@Substitute
public static Map<String, String> getSavedProperties() {
return ImageSingletons.lookup(SystemPropertiesSupport.class).getSavedProperties();
return SystemPropertiesSupport.singleton().getSavedProperties();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -305,30 +305,30 @@ private static int identityHashCode(Object obj) {

@Substitute
private static Properties getProperties() {
return ImageSingletons.lookup(SystemPropertiesSupport.class).getProperties();
return SystemPropertiesSupport.singleton().getProperties();
}

@Substitute
private static void setProperties(Properties props) {
ImageSingletons.lookup(SystemPropertiesSupport.class).setProperties(props);
SystemPropertiesSupport.singleton().setProperties(props);
}

@Substitute
public static String setProperty(String key, String value) {
checkKey(key);
return ImageSingletons.lookup(SystemPropertiesSupport.class).setProperty(key, value);
return SystemPropertiesSupport.singleton().setProperty(key, value);
}

@Substitute
private static String getProperty(String key) {
checkKey(key);
return ImageSingletons.lookup(SystemPropertiesSupport.class).getProperty(key);
return SystemPropertiesSupport.singleton().getProperty(key);
}

@Substitute
public static String clearProperty(String key) {
checkKey(key);
return ImageSingletons.lookup(SystemPropertiesSupport.class).clearProperty(key);
return SystemPropertiesSupport.singleton().clearProperty(key);
}

@Substitute
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@
import java.util.Properties;
import java.util.function.Supplier;

import org.graalvm.compiler.api.replacements.Fold;
import org.graalvm.compiler.serviceprovider.JavaVersionUtil;
import org.graalvm.nativeimage.ImageInfo;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.impl.RuntimeSystemPropertiesSupport;

import com.oracle.svm.core.VM;
import com.oracle.svm.core.config.ConfigurationValues;
Expand All @@ -49,7 +51,7 @@
* the current working directory is quite expensive. We initialize such a property either when it is
* explicitly accessed, or when all properties are accessed.
*/
public abstract class SystemPropertiesSupport {
public abstract class SystemPropertiesSupport implements RuntimeSystemPropertiesSupport {

/** System properties that are taken from the VM hosting the image generator. */
private static final String[] HOSTED_PROPERTIES = {
Expand Down Expand Up @@ -88,6 +90,11 @@ public abstract class SystemPropertiesSupport {

private volatile boolean fullyInitialized;

@Fold
public static SystemPropertiesSupport singleton() {
return (SystemPropertiesSupport) ImageSingletons.lookup(RuntimeSystemPropertiesSupport.class);
}

@Platforms(Platform.HOSTED_ONLY.class)
protected SystemPropertiesSupport() {
properties = new Properties();
Expand Down Expand Up @@ -193,8 +200,12 @@ public void setProperties(Properties props) {
* Initializes a property at startup from external input (e.g., command line arguments). This
* must only be called while the runtime is single threaded.
*/
@Override
public void initializeProperty(String key, String value) {
savedProperties.put(key, value);
String prevValue = savedProperties.put(key, value);
if (prevValue != null && !prevValue.equals(value)) {
VMError.shouldNotReachHere("System property " + key + " is initialized to " + value + " but was previously initialized to " + prevValue + ".");
}
properties.setProperty(key, value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,17 @@

import java.util.Map;

import org.graalvm.nativeimage.ImageSingletons;

import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.AnnotateOriginal;
import com.oracle.svm.core.annotate.Delete;
import com.oracle.svm.core.annotate.InjectAccessors;
import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
import com.oracle.svm.core.annotate.RecomputeFieldValue.Kind;
import com.oracle.svm.core.annotate.Substitute;
import com.oracle.svm.core.annotate.TargetClass;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.snippets.KnownIntrinsics;

import jdk.internal.misc.Unsafe;
Expand All @@ -51,7 +49,7 @@ public final class Target_jdk_internal_misc_VM {

@Substitute
public static String getSavedProperty(String name) {
return ImageSingletons.lookup(SystemPropertiesSupport.class).getSavedProperties().get(name);
return SystemPropertiesSupport.singleton().getSavedProperties().get(name);
}

@AnnotateOriginal
Expand Down
Loading