Skip to content
Merged
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
10 changes: 6 additions & 4 deletions docs/reference-manual/native-image/Compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ The `invokedynamic`method and method handles can introduce calls at run time or

Note that `invokedynamic` use cases generated by `javac` for, for example, Java lambda expressions and String concatenation that are supported because they do not change called methods at run time.

### Security Manager

Native Image will not allow a Java Security Manager to be enabled because this functionality has deprecated since Java 17.

## Features That May Operate Differently in a Native Image

Native Image implements some Java features differently to the Java VM.

### Security Manager

`java.lang.System#getSecurityManager()` always returns `null` even if the security manager is set via `-Djava.security.manager` at startup.

`java.lang.System#setSecurityManager(SecurityManager)` invoked with a non-null argument throws a `java.lang.SecurityException` if `-Djava.security.manager` is set to anything but `disallow` at program startup.

### Signal Handlers

Registering a signal handler requires a new thread to start that handles the signal and invokes shutdown hooks.
Expand Down
2 changes: 2 additions & 0 deletions docs/security/native-image.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ The security report section of the native image [build output](../reference-manu

## Miscellaneous

Setting the security manager is not allowed. For more information see the [compatibility documentation](../reference-manual/native-image/Compatibility.md#security-manager).

Native Image provides multiple ways to specify a certificate file used to define the default TrustStore.
While the default behavior for `native-image` is to capture and use the default TrustStore from the build-time host environment, this can be changed at run time by setting the "javax.net.ssl.trustStore\*" system properties.
See the [documentation](../reference-manual/native-image/CertificateManagement.md) for more details.
Expand Down
1 change: 1 addition & 0 deletions substratevm/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ This changelog summarizes major changes to GraalVM Native Image.
* (GR-47937) Make the lambda-class name format in Native-Image consistent with the JDK name format.
* (GR-45651) Methods, fields and constructors of `Object`, primitive classes and array classes are now registered by default for reflection.
* (GR-45651) The Native Image agent now tracks calls to `ClassLoader.findSystemClass`, `ObjectInputStream.resolveClass` and `Bundles.of`, and registers resource bundles as bundle name-locale pairs.
* (GR-49807) Before this change the function `System#setSecurityManager` was always halting program execution with a VM error. This was inconvenient as the VM error prints an uncomprehensible error message and prevents further continuation of the program. For cases where the program is expected to throw an exception when `System#setSecurityManager` is called, execution on Native Image was not possible. Now, `System#setSecurityManager` throws an `java.lang.UnsupportedOperationException` by default. If the property `java.security.manager` is set to anything but `disallow` at program startup this function will throw a `java.lang.SecurityException` according to the Java spec.

## GraalVM for JDK 21 (Internal Version 23.1.0)
* (GR-35746) Lower the default aligned chunk size from 1 MB to 512 KB for the serial and epsilon GCs, reducing memory usage and image size in many cases.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import static com.oracle.svm.core.posix.headers.darwin.DarwinTime.NoTransitions.mach_absolute_time;
import static com.oracle.svm.core.posix.headers.darwin.DarwinTime.NoTransitions.mach_timebase_info;

import java.util.Objects;

import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
Expand All @@ -52,6 +54,7 @@ private static long nanoTime() {

@Substitute
public static String mapLibraryName(String libname) {
Objects.requireNonNull(libname);
return "lib" + libname + ".dylib";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.oracle.svm.core.posix.headers.linux.LinuxTime;
import com.oracle.svm.core.util.TimeUtils;

import java.util.Objects;

@TargetClass(java.lang.System.class)
final class Target_java_lang_System_Linux {

Expand All @@ -48,6 +50,7 @@ private static long nanoTime() {

@Substitute
public static String mapLibraryName(String libname) {
Objects.requireNonNull(libname);
return "lib" + libname + ".so";
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
package com.oracle.svm.core.windows;

import java.io.Console;
import java.util.Objects;

import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.annotate.Alias;
import com.oracle.svm.core.annotate.RecomputeFieldValue;
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.jdk.Jvm;

@TargetClass(java.lang.System.class)
Expand All @@ -51,6 +52,7 @@ protected static long nanoTime() {

@Substitute
public static String mapLibraryName(String libname) {
Objects.requireNonNull(libname);
return libname + ".dll";
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ public static boolean useLIRBackend() {
@Option(help = "Common prefix used by method symbols in image.")//
public static final HostedOptionKey<String> ImageSymbolsPrefix = new HostedOptionKey<>("");

/**
* Needs to be removed as part of GR-50210.
*/
@Option(help = "Fold SecurityManager getter.", stability = OptionStability.EXPERIMENTAL, type = OptionType.Expert) //
public static final HostedOptionKey<Boolean> FoldSecurityManagerGetter = new HostedOptionKey<>(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@
import java.util.Optional;
import java.util.StringJoiner;

import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.core.common.NumUtil;
import jdk.graal.compiler.core.common.SuppressFBWarnings;
import org.graalvm.nativeimage.AnnotationAccess;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
Expand Down Expand Up @@ -119,6 +116,9 @@
import com.oracle.svm.util.ReflectionUtil;
import com.oracle.svm.util.ReflectionUtil.ReflectionUtilError;

import jdk.graal.compiler.api.replacements.Fold;
import jdk.graal.compiler.core.common.NumUtil;
import jdk.graal.compiler.core.common.SuppressFBWarnings;
import jdk.internal.access.JavaLangReflectAccess;
import jdk.internal.misc.Unsafe;
import jdk.internal.reflect.CallerSensitive;
Expand Down Expand Up @@ -1228,6 +1228,14 @@ private void checkPackageAccess(SecurityManager sm, ClassLoader ccl, boolean che
/* No runtime access checks. */
}

/**
* Never called as it is partially evaluated away due to SecurityManager.
*/
@KeepOriginal
@SuppressWarnings({"deprecation", "unused"})
private static native void checkPackageAccessForPermittedSubclasses(@SuppressWarnings("removal") SecurityManager sm,
ClassLoader ccl, Class<?>[] subClasses);

@Substitute
private static ReflectionFactory getReflectionFactory() {
return Target_jdk_internal_reflect_ReflectionFactory.getReflectionFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.io.InputStream;
import java.io.PrintStream;
import java.net.URL;
import java.security.Permission;
import java.util.Arrays;
import java.util.Enumeration;
import java.util.List;
Expand Down Expand Up @@ -407,23 +408,34 @@ private static String getProperty(String key, String def) {
@Alias
private static native void checkKey(String key);

/*
* Note that there is no substitution for getSecurityManager, but instead getSecurityManager it
* is intrinsified in SubstrateGraphBuilderPlugins to always return null. This allows better
* constant folding of SecurityManager code already during static analysis.
/**
* Force System.Never in case it was set at build time via the `-Djava.security.manager=allow`
* passed to the image builder.
*/
@Alias @RecomputeFieldValue(kind = Kind.FromAlias, isFinal = true) //
private static int allowSecurityManager = 1;

/**
* We do not support the {@link SecurityManager} so this method must throw a
* {@link SecurityException} when 'java.security.manager' is set to anything but
* <code>disallow</code>.
*
* @see System#setSecurityManager(SecurityManager)
* @see SecurityManager
*/
@Substitute
private static void setSecurityManager(SecurityManager s) {
if (s != null) {
/*
* We deliberately treat this as a non-recoverable fatal error. We want to prevent bugs
* where an exception is silently ignored by an application and then necessary security
* checks are not in place.
*/
throw VMError.shouldNotReachHere("Installing a SecurityManager is not yet supported");
private static void setSecurityManager(SecurityManager sm) {
if (sm != null) {
/* Read the property collected at isolate creation as that is what happens on the JVM */
String smp = SystemPropertiesSupport.singleton().getSavedProperties().get("java.security.manager");
if (smp != null && !smp.equals("disallow")) {
throw new SecurityException("Setting the SecurityManager is not supported by Native Image");
} else {
throw new UnsupportedOperationException(
"The Security Manager is deprecated and will be removed in a future release");
}
}
}

}

final class NotAArch64 implements BooleanSupplier {
Expand Down Expand Up @@ -629,6 +641,14 @@ public static Enumeration<URL> findResources(String name) {
// Checkstyle: resume
}

@TargetClass(value = jdk.internal.logger.LoggerFinderLoader.class)
final class Target_jdk_internal_logger_LoggerFinderLoader {
// Checkstyle: stop
@Alias @RecomputeFieldValue(kind = RecomputeFieldValue.Kind.Reset, isFinal = true)//
static Permission READ_PERMISSION;
// Checkstyle: resume
}

final class ClassLoaderValueMapFieldValueTransformer implements FieldValueTransformer {
@Override
public Object transform(Object receiver, Object originalValue) {
Expand Down