From 4176509fc8031410f5e533dc79b76bd0433d72dd Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Fri, 11 Aug 2023 19:01:06 +0200 Subject: [PATCH 01/24] Add new dependencies after graal-sdk split (cherry picked from commit c6bdbb641019107fd415f5d461caac6952e2b64f) --- .../src/com/oracle/svm/driver/NativeImage.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index e2b63567ea1e..90a15e820417 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -561,10 +561,12 @@ public List getBuilderJavaArgs() { */ public List getBuilderModulePath() { List result = new ArrayList<>(); - // Non-jlinked JDKs need truffle and graal-sdk on the module path since they - // don't have those modules as part of the JDK. + // Non-jlinked JDKs need truffle and word, collections, nativeimage on the + // module path since they don't have those modules as part of the JDK. Note + // that graal-sdk is now obsolete after the split in GR-43819 (#7171) if (libJvmciDir != null) { - result.addAll(getJars(libJvmciDir, "graal-sdk", "enterprise-graal")); + result.addAll(getJars(libJvmciDir, "enterprise-graal")); + result.addAll(getJars(libJvmciDir, "word", "collections", "nativeimage")); } if (modulePathBuild) { result.addAll(createTruffleBuilderModulePath()); @@ -587,6 +589,13 @@ private List createTruffleBuilderModulePath() { jars.addAll(getJars(builderPath, "truffle-runtime-svm", "truffle-enterprise-svm")); } } + /* + * Non-Jlinked JDKs don't have truffle-compiler as part of the JDK, however the native + * image builder still needs it + */ + if (libJvmciDir != null) { + jars.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-compiler")); + } return jars; } From 91f74ce894c3dc556492f2b882ef62ed684aa876 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Mon, 14 Aug 2023 10:48:09 +0200 Subject: [PATCH 02/24] Drop polyglot.jar and truffle-api.jar from native-image launcher (cherry picked from commit 261dd42a8fcb1ad381cd4885f8fc77c7e5a012a3) --- sdk/mx.sdk/mx_sdk_vm_impl.py | 8 ++------ .../src/com/oracle/svm/driver/NativeImage.java | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/sdk/mx.sdk/mx_sdk_vm_impl.py b/sdk/mx.sdk/mx_sdk_vm_impl.py index b86b3f13f1e6..e8c8c4bc763f 100644 --- a/sdk/mx.sdk/mx_sdk_vm_impl.py +++ b/sdk/mx.sdk/mx_sdk_vm_impl.py @@ -2180,13 +2180,9 @@ def _get_extra_jvm_args(): extra_jvm_args = mx.list_to_cmd_line(image_config.extra_jvm_args) if not _jlink_libraries(): if mx.is_windows(): - extra_jvm_args = ' '.join([extra_jvm_args, r'--upgrade-module-path "%location%\..\..\jvmci\graal.jar"', - r'--add-modules org.graalvm.polyglot', - r'--module-path "%location%\..\..\truffle\truffle-api.jar:%location%\..\..\jvmci\polyglot.jar"']) + extra_jvm_args = ' '.join([extra_jvm_args, r'--upgrade-module-path "%location%\..\..\jvmci\graal.jar"']) else: - extra_jvm_args = ' '.join([extra_jvm_args, '--upgrade-module-path "${location}/../../jvmci/graal.jar"', - '--add-modules org.graalvm.polyglot', - '--module-path "${location}/../../truffle/truffle-api.jar:${location}/../../jvmci/polyglot.jar"']) + extra_jvm_args = ' '.join([extra_jvm_args, '--upgrade-module-path "${location}/../../jvmci/graal.jar"']) return extra_jvm_args def _get_option_vars(): diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index 90a15e820417..aaebee78abdf 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -576,17 +576,27 @@ public List getBuilderModulePath() { } private List createTruffleBuilderModulePath() { - List jars = getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-api", "truffle-runtime", "truffle-enterprise"); + Path libTruffleDir = rootDir.resolve(Paths.get("lib", "truffle")); + List jars = getJars(libTruffleDir, "truffle-api", "truffle-runtime", "truffle-enterprise"); if (!jars.isEmpty()) { /* * If Truffle is installed as part of the JDK we always add the builder modules of * Truffle to the builder module path. This is legacy support and should in the * future no longer be needed. */ - jars.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-compiler")); + jars.addAll(getJars(libTruffleDir, "truffle-compiler")); Path builderPath = rootDir.resolve(Paths.get("lib", "truffle", "builder")); if (Files.exists(builderPath)) { jars.addAll(getJars(builderPath, "truffle-runtime-svm", "truffle-enterprise-svm")); + if (libJvmciDir != null) { + // truffle-runtime-svm depends on polyglot, which is not part of non-jlinked + // JDKs + jars.addAll(getJars(libJvmciDir, "polyglot")); + } + } + if (libJvmciDir != null) { + // truffle-runtime depends on polyglot, which is not part of non-jlinked JDKs + jars.addAll(getJars(libTruffleDir, "jniutils")); } } /* @@ -594,7 +604,7 @@ private List createTruffleBuilderModulePath() { * image builder still needs it */ if (libJvmciDir != null) { - jars.addAll(getJars(rootDir.resolve(Paths.get("lib", "truffle")), "truffle-compiler")); + jars.addAll(getJars(libTruffleDir, "truffle-compiler")); } return jars; From 583e1d76bc97c131f35224f5acfbbd21df516301 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Wed, 18 Oct 2023 10:20:51 +0200 Subject: [PATCH 03/24] Add polyglot.jar only if truffle-runtime-svm is there as well (cherry picked from commit 0c518c76252cc597c265bf11916a84f7de415492) --- .../src/com/oracle/svm/driver/NativeImage.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java index aaebee78abdf..81012e52fd3c 100644 --- a/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java +++ b/substratevm/src/com.oracle.svm.driver/src/com/oracle/svm/driver/NativeImage.java @@ -587,8 +587,9 @@ private List createTruffleBuilderModulePath() { jars.addAll(getJars(libTruffleDir, "truffle-compiler")); Path builderPath = rootDir.resolve(Paths.get("lib", "truffle", "builder")); if (Files.exists(builderPath)) { - jars.addAll(getJars(builderPath, "truffle-runtime-svm", "truffle-enterprise-svm")); - if (libJvmciDir != null) { + List truffleRuntimeSVMJars = getJars(builderPath, "truffle-runtime-svm", "truffle-enterprise-svm"); + jars.addAll(truffleRuntimeSVMJars); + if (libJvmciDir != null && !truffleRuntimeSVMJars.isEmpty()) { // truffle-runtime-svm depends on polyglot, which is not part of non-jlinked // JDKs jars.addAll(getJars(libJvmciDir, "polyglot")); From 64184d3a0b39b0e9ac62e9c575b92b52f6001dfe Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Wed, 12 Jul 2023 18:31:57 +0300 Subject: [PATCH 04/24] Throw exception for null in RuntimeJNIAccess/RuntimeReflection reg. Don't allow null values to be passed to the `register` method of `RuntimeJNIAccess` and `RuntimeReflection`. Since these are public APIs GraalVM should either handle null values (by ignoring them in this case) or throw a `NullPointerException` before creating an asynchronous task to perform the registration in the analysis, which then results in `NullPointerException`s being thrown later when it's no longer possible to understand where the null value originate from. (cherry picked from commit e6c12dd389609f0eac07aa93d085fa33dd21bce0) --- .../nativeimage/impl/ReflectionRegistry.java | 8 +- substratevm/mx.substratevm/mx_substratevm.py | 4 +- .../ConditionalConfigurationRegistry.java | 8 ++ .../hosted/reflect/ReflectionDataBuilder.java | 8 ++ .../svm/test/ReflectionRegistrationTest.java | 120 ++++++++++++++++++ 5 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ReflectionRegistrationTest.java diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java index 4198a895ec06..7f1141b6435d 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java @@ -46,7 +46,13 @@ public interface ReflectionRegistry { default void register(ConfigurationCondition condition, Class... classes) { - Arrays.stream(classes).forEach(clazz -> register(condition, false, clazz)); + Arrays.stream(classes).forEach(clazz -> { + if (clazz == null) { + throw new NullPointerException("Cannot register null value as class for reflection. " + + "Please ensure that all values you register are not null."); + } + register(condition, false, clazz); + }); } void register(ConfigurationCondition condition, boolean unsafeAllocated, Class clazz); diff --git a/substratevm/mx.substratevm/mx_substratevm.py b/substratevm/mx.substratevm/mx_substratevm.py index 44940e208f86..c2b60e1f5d06 100644 --- a/substratevm/mx.substratevm/mx_substratevm.py +++ b/substratevm/mx.substratevm/mx_substratevm.py @@ -1,7 +1,7 @@ # # ---------------------------------------------------------------------------------------------------- # -# Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. # # This code is free software; you can redistribute it and/or modify it @@ -296,7 +296,7 @@ def native_image_func(args, **kwargs): yield native_image_func native_image_context.hosted_assertions = ['-J-ea', '-J-esa'] -_native_unittest_features = '--features=com.oracle.svm.test.ImageInfoTest$TestFeature,com.oracle.svm.test.ServiceLoaderTest$TestFeature,com.oracle.svm.test.SecurityServiceTest$TestFeature' +_native_unittest_features = '--features=com.oracle.svm.test.ImageInfoTest$TestFeature,com.oracle.svm.test.ServiceLoaderTest$TestFeature,com.oracle.svm.test.SecurityServiceTest$TestFeature,com.oracle.svm.test.ReflectionRegistrationTest$TestFeature' IMAGE_ASSERTION_FLAGS = svm_experimental_options(['-H:+VerifyGraalGraphs', '-H:+VerifyPhases']) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java index dab90726dfbf..e696f21e3031 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java @@ -38,6 +38,14 @@ public abstract class ConditionalConfigurationRegistry { private final Map> pendingReachabilityHandlers = new ConcurrentHashMap<>(); protected void registerConditionalConfiguration(ConfigurationCondition condition, Runnable runnable) { + if (condition == null) { + throw new NullPointerException("Cannot use null value as condition for conditional configuration. " + + "Please ensure that you register a non-null condition."); + } + if (runnable == null) { + throw new NullPointerException("Cannot use null value as runnable for conditional configuration. " + + "Please ensure that you register a non-null runnable."); + } if (ConfigurationCondition.alwaysTrue().equals(condition)) { /* analysis optimization to include new types as early as possible */ runnable.run(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java index 64283d256c84..488c8a4e994c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java @@ -284,6 +284,10 @@ public void register(ConfigurationCondition condition, boolean queriedOnly, Exec checkNotSealed(); register(analysisUniverse -> registerConditionalConfiguration(condition, () -> { for (Executable executable : executables) { + if (executable == null) { + throw new NullPointerException("Cannot register null value as executable for reflection. " + + "Please ensure that all values you register are not null."); + } analysisUniverse.getBigbang().postTask(debug -> registerMethod(queriedOnly, executable)); } })); @@ -416,6 +420,10 @@ public void register(ConfigurationCondition condition, boolean finalIsWritable, private void registerInternal(ConfigurationCondition condition, Field... fields) { register(analysisUniverse -> registerConditionalConfiguration(condition, () -> { for (Field field : fields) { + if (field == null) { + throw new NullPointerException("Cannot register null value as field for reflection. " + + "Please ensure that all values you register are not null."); + } analysisUniverse.getBigbang().postTask(debug -> registerField(field)); } })); diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ReflectionRegistrationTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ReflectionRegistrationTest.java new file mode 100644 index 000000000000..555cc683657d --- /dev/null +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/ReflectionRegistrationTest.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2023, 2023, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2023, 2023, Red Hat Inc. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Oracle designates this + * particular file as subject to the "Classpath" exception as provided + * by Oracle in the LICENSE file that accompanied this code. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ +package com.oracle.svm.test; + +import com.oracle.svm.hosted.FeatureImpl; +import com.oracle.svm.hosted.substitute.SubstitutionReflectivityFilter; +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeReflection; +import org.graalvm.nativeimage.impl.RuntimeReflectionSupport; +import org.junit.Test; + +import java.lang.reflect.Executable; +import java.lang.reflect.Field; + +/** + * Tests the {@link RuntimeReflection}. + */ +public class ReflectionRegistrationTest { + + public static class TestFeature implements Feature { + + @SuppressWarnings("unused")// + int unusedVariableOne = 1; + @SuppressWarnings("unused")// + int unusedVariableTwo = 2; + + @Override + public void beforeAnalysis(final BeforeAnalysisAccess access) { + try { + RuntimeReflection.register((Class) null); + assert false; + } catch (NullPointerException e) { + assert e.getMessage().startsWith("Cannot register null value"); + } + try { + RuntimeReflection.register((Executable) null); + assert false; + } catch (NullPointerException e) { + assert e.getMessage().startsWith("Cannot register null value"); + } + try { + RuntimeReflection.register((Field) null); + assert false; + } catch (NullPointerException e) { + assert e.getMessage().startsWith("Cannot register null value"); + } + + try { + ImageSingletons.lookup(RuntimeReflectionSupport.class).register(null, this.getClass()); + assert false; + } catch (NullPointerException e) { + assert e.getMessage().startsWith("Cannot use null value"); + } + + try { + ImageSingletons.lookup(RuntimeReflectionSupport.class).register(null, true, this.getClass().getMethods()); + assert false; + } catch (NullPointerException e) { + assert e.getMessage().startsWith("Cannot use null value"); + } + + try { + ImageSingletons.lookup(RuntimeReflectionSupport.class).register(null, true, this.getClass().getFields()); + assert false; + } catch (NullPointerException e) { + assert e.getMessage().startsWith("Cannot use null value"); + } + + FeatureImpl.BeforeAnalysisAccessImpl impl = (FeatureImpl.BeforeAnalysisAccessImpl) access; + try { + SubstitutionReflectivityFilter.shouldExclude((Class) null, impl.getMetaAccess(), impl.getUniverse()); + assert false; + } catch (NullPointerException e) { + // expected + } + try { + SubstitutionReflectivityFilter.shouldExclude((Executable) null, impl.getMetaAccess(), impl.getUniverse()); + assert false; + } catch (NullPointerException e) { + // expected + } + try { + SubstitutionReflectivityFilter.shouldExclude((Field) null, impl.getMetaAccess(), impl.getUniverse()); + assert false; + } catch (NullPointerException e) { + // expected + } + } + + } + + @Test + public void test() { + // nothing to do + } +} From 1d0bab4379040cf60e57ac329dad5d859eb75fe8 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Wed, 1 Nov 2023 17:43:25 +0100 Subject: [PATCH 05/24] Fix style. (cherry picked from commit d621dbd5b1e9f3e3095e05b062b39afc4c6f3588) --- .../src/org/graalvm/nativeimage/impl/ReflectionRegistry.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java index 7f1141b6435d..0179e2db9a95 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java @@ -49,7 +49,7 @@ default void register(ConfigurationCondition condition, Class... classes) { Arrays.stream(classes).forEach(clazz -> { if (clazz == null) { throw new NullPointerException("Cannot register null value as class for reflection. " + - "Please ensure that all values you register are not null."); + "Please ensure that all values you register are not null."); } register(condition, false, clazz); }); From 373204c2b418096cff678a08b405b9e0983b0100 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Thu, 2 Nov 2023 14:26:29 +0100 Subject: [PATCH 06/24] Move null checks to the beginning of register methods. Not before the register methods, which can miss cases, nor later on in a runnable. (cherry picked from commit f94551abad61ae492d9a0b266a07564ab8aff92e) --- .../nativeimage/impl/ReflectionRegistry.java | 8 +------ .../hosted/reflect/ReflectionDataBuilder.java | 22 ++++++++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java index 0179e2db9a95..4198a895ec06 100644 --- a/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java +++ b/sdk/src/org.graalvm.nativeimage/src/org/graalvm/nativeimage/impl/ReflectionRegistry.java @@ -46,13 +46,7 @@ public interface ReflectionRegistry { default void register(ConfigurationCondition condition, Class... classes) { - Arrays.stream(classes).forEach(clazz -> { - if (clazz == null) { - throw new NullPointerException("Cannot register null value as class for reflection. " + - "Please ensure that all values you register are not null."); - } - register(condition, false, clazz); - }); + Arrays.stream(classes).forEach(clazz -> register(condition, false, clazz)); } void register(ConfigurationCondition condition, boolean unsafeAllocated, Class clazz); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java index 488c8a4e994c..0c7148455340 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java @@ -56,6 +56,7 @@ import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.concurrent.Callable; @@ -166,6 +167,7 @@ private void setQueryFlag(Class clazz, int flag) { @Override public void register(ConfigurationCondition condition, boolean unsafeInstantiated, Class clazz) { + Objects.requireNonNull(clazz, () -> nullErrorMessage("class")); checkNotSealed(); register(analysisUniverse -> registerConditionalConfiguration(condition, () -> analysisUniverse.getBigbang().postTask(debug -> registerClass(clazz, unsafeInstantiated)))); @@ -281,13 +283,10 @@ public void registerAllSignersQuery(ConfigurationCondition condition, Class c @Override public void register(ConfigurationCondition condition, boolean queriedOnly, Executable... executables) { + requireNonNull(executables, "executable"); checkNotSealed(); register(analysisUniverse -> registerConditionalConfiguration(condition, () -> { for (Executable executable : executables) { - if (executable == null) { - throw new NullPointerException("Cannot register null value as executable for reflection. " + - "Please ensure that all values you register are not null."); - } analysisUniverse.getBigbang().postTask(debug -> registerMethod(queriedOnly, executable)); } })); @@ -413,6 +412,7 @@ public void registerConstructorLookup(ConfigurationCondition condition, Class @Override public void register(ConfigurationCondition condition, boolean finalIsWritable, Field... fields) { + requireNonNull(fields, "field"); checkNotSealed(); registerInternal(condition, fields); } @@ -420,10 +420,6 @@ public void register(ConfigurationCondition condition, boolean finalIsWritable, private void registerInternal(ConfigurationCondition condition, Field... fields) { register(analysisUniverse -> registerConditionalConfiguration(condition, () -> { for (Field field : fields) { - if (field == null) { - throw new NullPointerException("Cannot register null value as field for reflection. " + - "Please ensure that all values you register are not null."); - } analysisUniverse.getBigbang().postTask(debug -> registerField(field)); } })); @@ -1080,4 +1076,14 @@ public int getReflectionMethodsCount() { public int getReflectionFieldsCount() { return registeredFields.size(); } + + private static void requireNonNull(Object[] values, String kind) { + for (Object value : values) { + Objects.requireNonNull(value, () -> nullErrorMessage(kind)); + } + } + + private static String nullErrorMessage(String kind) { + return "Cannot register null value as " + kind + " for reflection. Please ensure that all values you register are not null."; + } } From 6af144fce4e6e541164082918070b29ce8111481 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Thu, 2 Nov 2023 14:27:00 +0100 Subject: [PATCH 07/24] Apply non-null strategy to `JNIAccessFeature`. (cherry picked from commit d996f323b7c6ce796caccff6ae50bd1c2fa5a81f) --- .../oracle/svm/hosted/jni/JNIAccessFeature.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIAccessFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIAccessFeature.java index 2f1dfeb40bf1..37bf159f74b7 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIAccessFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIAccessFeature.java @@ -34,6 +34,7 @@ import java.util.IdentityHashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Predicate; @@ -202,18 +203,21 @@ private class JNIRuntimeAccessibilitySupportImpl extends ConditionalConfiguratio @Override public void register(ConfigurationCondition condition, boolean unsafeAllocated, Class clazz) { assert !unsafeAllocated : "unsafeAllocated can be only set via Unsafe.allocateInstance, not via JNI."; + Objects.requireNonNull(clazz, () -> nullErrorMessage("class")); abortIfSealed(); registerConditionalConfiguration(condition, () -> newClasses.add(clazz)); } @Override public void register(ConfigurationCondition condition, boolean queriedOnly, Executable... methods) { + requireNonNull(methods, "methods"); abortIfSealed(); registerConditionalConfiguration(condition, () -> newMethods.addAll(Arrays.asList(methods))); } @Override public void register(ConfigurationCondition condition, boolean finalIsWritable, Field... fields) { + requireNonNull(fields, "field"); abortIfSealed(); registerConditionalConfiguration(condition, () -> registerFields(finalIsWritable, fields)); } @@ -622,4 +626,14 @@ private static boolean anyFieldMatches(ResolvedJavaType sub, String name) { return false; } } + + private static void requireNonNull(Object[] values, String kind) { + for (Object value : values) { + Objects.requireNonNull(value, () -> nullErrorMessage(kind)); + } + } + + private static String nullErrorMessage(String kind) { + return "Cannot register null value as " + kind + " for JNI access. Please ensure that all values you register are not null."; + } } From 9980fdfc9a92b73adb467e9c867c5ddfc1c1b9a1 Mon Sep 17 00:00:00 2001 From: Fabio Niephaus Date: Thu, 2 Nov 2023 14:35:01 +0100 Subject: [PATCH 08/24] Use `Objects.requireNonNull()` in `ConditionalConfigurationRegistry`. (cherry picked from commit 0ba6cc2c33725a482e190525c6f2bd153ec82b2b) --- .../svm/hosted/ConditionalConfigurationRegistry.java | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java index e696f21e3031..8af9e717078f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -38,14 +39,8 @@ public abstract class ConditionalConfigurationRegistry { private final Map> pendingReachabilityHandlers = new ConcurrentHashMap<>(); protected void registerConditionalConfiguration(ConfigurationCondition condition, Runnable runnable) { - if (condition == null) { - throw new NullPointerException("Cannot use null value as condition for conditional configuration. " + - "Please ensure that you register a non-null condition."); - } - if (runnable == null) { - throw new NullPointerException("Cannot use null value as runnable for conditional configuration. " + - "Please ensure that you register a non-null runnable."); - } + Objects.requireNonNull(condition, "Cannot use null value as condition for conditional configuration. Please ensure that you register a non-null condition."); + Objects.requireNonNull(runnable, "Cannot use null value as runnable for conditional configuration. Please ensure that you register a non-null runnable."); if (ConfigurationCondition.alwaysTrue().equals(condition)) { /* analysis optimization to include new types as early as possible */ runnable.run(); From 31573c1fb3b0c26900725e99a67d0a85c27b4df3 Mon Sep 17 00:00:00 2001 From: Vojin Jovanovic Date: Wed, 13 Sep 2023 12:58:43 +0200 Subject: [PATCH 09/24] Fail on missing API options (cherry picked from commit c949f3e77137b3ac0adb763719cee527a07ae4f4) --- .../com/oracle/svm/core/option/SubstrateOptionsParser.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/option/SubstrateOptionsParser.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/option/SubstrateOptionsParser.java index baaa69e0ec52..6247d2331dce 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/option/SubstrateOptionsParser.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/option/SubstrateOptionsParser.java @@ -195,7 +195,9 @@ public static String commandArgument(OptionKey option, String value, String a } } } - return HOSTED_OPTION_PREFIX + value + option; + String optionString = HOSTED_OPTION_PREFIX + value + option; + assert apiOptionName == null : "The API option " + apiOptionName + " not found for " + optionString; + return optionString; } else { String apiOptionWithValue = null; for (APIOption apiOption : apiOptions) { From dd8e47c3363d4d3aed847dad78f3c0040d0b5555 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Tue, 27 Aug 2024 15:11:36 +0200 Subject: [PATCH 10/24] New dev cycle GraalVM Community 23.1.5 --- compiler/mx.compiler/suite.py | 4 ++-- espresso/mx.espresso/suite.py | 4 ++-- regex/mx.regex/suite.py | 4 ++-- sdk/mx.sdk/suite.py | 4 ++-- substratevm/mx.substratevm/suite.py | 4 ++-- tools/mx.tools/suite.py | 4 ++-- truffle/external_repos/simplelanguage/pom.xml | 2 +- truffle/external_repos/simplelanguage/sl | 2 +- truffle/external_repos/simpletool/pom.xml | 2 +- truffle/mx.truffle/suite.py | 4 ++-- vm/mx.vm/suite.py | 4 ++-- wasm/mx.wasm/suite.py | 2 +- 12 files changed, 20 insertions(+), 20 deletions(-) diff --git a/compiler/mx.compiler/suite.py b/compiler/mx.compiler/suite.py index 90fa7e545205..afefef8fbc99 100644 --- a/compiler/mx.compiler/suite.py +++ b/compiler/mx.compiler/suite.py @@ -4,8 +4,8 @@ "sourceinprojectwhitelist" : [], "groupId" : "org.graalvm.compiler", - "version" : "23.1.3", - "release" : True, + "version" : "23.1.5", + "release" : False, "url" : "http://www.graalvm.org/", "developer" : { "name" : "GraalVM Development", diff --git a/espresso/mx.espresso/suite.py b/espresso/mx.espresso/suite.py index 4a9d87814a0b..15b839216aa2 100644 --- a/espresso/mx.espresso/suite.py +++ b/espresso/mx.espresso/suite.py @@ -23,8 +23,8 @@ suite = { "mxversion": "6.44.0", "name": "espresso", - "version" : "23.1.3", - "release" : True, + "version" : "23.1.5", + "release" : False, "groupId" : "org.graalvm.espresso", "url" : "https://www.graalvm.org/reference-manual/java-on-truffle/", "developer" : { diff --git a/regex/mx.regex/suite.py b/regex/mx.regex/suite.py index df4e8fbc1138..18b63f812a86 100644 --- a/regex/mx.regex/suite.py +++ b/regex/mx.regex/suite.py @@ -43,8 +43,8 @@ "name" : "regex", - "version" : "23.1.3", - "release" : True, + "version" : "23.1.5", + "release" : False, "groupId" : "org.graalvm.regex", "url" : "http://www.graalvm.org/", "developer" : { diff --git a/sdk/mx.sdk/suite.py b/sdk/mx.sdk/suite.py index 995839bfa0fe..bdc521a137c3 100644 --- a/sdk/mx.sdk/suite.py +++ b/sdk/mx.sdk/suite.py @@ -41,8 +41,8 @@ suite = { "mxversion": "6.39.0", "name" : "sdk", - "version" : "23.1.3", - "release" : True, + "version" : "23.1.5", + "release" : False, "sourceinprojectwhitelist" : [], "url" : "https://github.com/oracle/graal", "groupId" : "org.graalvm.sdk", diff --git a/substratevm/mx.substratevm/suite.py b/substratevm/mx.substratevm/suite.py index dff8038e3030..405da9538582 100644 --- a/substratevm/mx.substratevm/suite.py +++ b/substratevm/mx.substratevm/suite.py @@ -2,8 +2,8 @@ suite = { "mxversion": "6.27.1", "name": "substratevm", - "version" : "23.1.3", - "release" : True, + "version" : "23.1.5", + "release" : False, "url" : "https://github.com/oracle/graal/tree/master/substratevm", "groupId" : "org.graalvm.nativeimage", diff --git a/tools/mx.tools/suite.py b/tools/mx.tools/suite.py index 6a7f4b91feb9..d2ab31125dca 100644 --- a/tools/mx.tools/suite.py +++ b/tools/mx.tools/suite.py @@ -26,8 +26,8 @@ "defaultLicense" : "GPLv2-CPE", "groupId" : "org.graalvm.tools", - "version" : "23.1.3", - "release" : True, + "version" : "23.1.5", + "release" : False, "url" : "http://openjdk.java.net/projects/graal", "developer" : { "name" : "GraalVM Development", diff --git a/truffle/external_repos/simplelanguage/pom.xml b/truffle/external_repos/simplelanguage/pom.xml index 7fdaa6fc37d8..5d9545a123bf 100644 --- a/truffle/external_repos/simplelanguage/pom.xml +++ b/truffle/external_repos/simplelanguage/pom.xml @@ -48,7 +48,7 @@ UTF-8 jdt_apt - 23.1.3-dev + 23.1.5-dev 11 11 diff --git a/truffle/external_repos/simplelanguage/sl b/truffle/external_repos/simplelanguage/sl index 59f10a39e513..df434100a8da 100755 --- a/truffle/external_repos/simplelanguage/sl +++ b/truffle/external_repos/simplelanguage/sl @@ -41,7 +41,7 @@ # # If you update this number make sure the graalvm.version value in ./pom.xml matches -VERSION="23.1.3-dev" +VERSION="23.1.5-dev" # If you update this number make sure the antlr.version value in language/pom.xml matches ANTLR_VERSION="4.12.0" diff --git a/truffle/external_repos/simpletool/pom.xml b/truffle/external_repos/simpletool/pom.xml index 5b591cc00542..810e6ab33d87 100644 --- a/truffle/external_repos/simpletool/pom.xml +++ b/truffle/external_repos/simpletool/pom.xml @@ -49,7 +49,7 @@ UTF-8 1.8 1.8 - 23.1.3-dev + 23.1.5-dev diff --git a/truffle/mx.truffle/suite.py b/truffle/mx.truffle/suite.py index 8808019f129b..c54ff1f1acfe 100644 --- a/truffle/mx.truffle/suite.py +++ b/truffle/mx.truffle/suite.py @@ -41,8 +41,8 @@ suite = { "mxversion": "6.39.0", "name" : "truffle", - "version" : "23.1.3", - "release" : True, + "version" : "23.1.5", + "release" : False, "groupId" : "org.graalvm.truffle", "sourceinprojectwhitelist" : [], "url" : "http://openjdk.java.net/projects/graal", diff --git a/vm/mx.vm/suite.py b/vm/mx.vm/suite.py index 1853c8663ba2..3e1226aef96a 100644 --- a/vm/mx.vm/suite.py +++ b/vm/mx.vm/suite.py @@ -1,8 +1,8 @@ suite = { "name": "vm", - "version" : "23.1.3", + "version" : "23.1.5", "mxversion": "6.41.0", - "release" : True, + "release" : False, "groupId" : "org.graalvm", "url" : "http://www.graalvm.org/", diff --git a/wasm/mx.wasm/suite.py b/wasm/mx.wasm/suite.py index f9e89c44b467..1dab86c25de2 100644 --- a/wasm/mx.wasm/suite.py +++ b/wasm/mx.wasm/suite.py @@ -42,7 +42,7 @@ "mxversion": "6.41.0", "name" : "wasm", "groupId" : "org.graalvm.wasm", - "version" : "23.1.3", + "version" : "23.1.5", "versionConflictResolution" : "latest", "url" : "http://graalvm.org/", "developer" : { From 3194b7a5eecf1d1131cdbef9e7684e759e789fcd Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Tue, 27 Aug 2024 15:24:36 +0200 Subject: [PATCH 11/24] GHA: Bump to newer upload/download-artifact actions --- .github/workflows/quarkus.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/quarkus.yml b/.github/workflows/quarkus.yml index 5a92174e957c..ec3e1a33dda4 100644 --- a/.github/workflows/quarkus.yml +++ b/.github/workflows/quarkus.yml @@ -84,7 +84,7 @@ jobs: shell: bash run: tar -czvf graalvm.tgz -C $(dirname ${GRAALVM_HOME}) $(basename ${GRAALVM_HOME}) - name: Persist GraalVM build - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 with: name: graalvm path: graalvm.tgz @@ -102,7 +102,7 @@ jobs: shell: bash run: tar -czvf maven-repo.tgz -C ~ .m2/repository - name: Persist Maven Repo - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 with: name: maven-repo path: maven-repo.tgz @@ -120,7 +120,7 @@ jobs: steps: - name: Download GraalVM build if: startsWith(matrix.os-name, 'ubuntu') - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v3 with: name: graalvm path: . @@ -141,7 +141,7 @@ jobs: run: ${QUARKUS_PATH}/.github/ci-prerequisites.sh - name: Download Maven Repo if: startsWith(matrix.os-name, 'ubuntu') - uses: actions/download-artifact@v1 + uses: actions/download-artifact@v3 with: name: maven-repo path: . @@ -168,7 +168,7 @@ jobs: shell: bash run: find . -type d -name '*-reports' -o -wholename '*/build/reports/tests/functionalTest' | tar -czf test-reports.tgz -T - - name: Upload failure Archive (if maven failed) - uses: actions/upload-artifact@v1 + uses: actions/upload-artifact@v3 if: failure() with: name: test-reports-native-${{matrix.category}} From dced1b1b412b48d961b3898616f29803c5e682e7 Mon Sep 17 00:00:00 2001 From: Severin Gehwolf Date: Tue, 27 Aug 2024 15:44:31 +0200 Subject: [PATCH 12/24] GHA: Bump action versions to avoid deprecation warnings --- .github/workflows/main.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e3449828a294..1c3006176117 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -119,25 +119,25 @@ jobs: MX_RUNS_STYLE: ${{ contains(matrix.env.GATE_TAGS, 'style') || matrix.env.GATE_TAGS == '' }} steps: - name: Checkout oracle/graal - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: ref: ${{ github.ref }} # Lock ref to current branch to avoid fetching others fetch-depth: "${{ env.MX_RUNS_STYLE && '0' || '1' }}" # The style gate needs the full commit history for checking copyright years - name: Determine mx version run: echo "MX_VERSION=$(jq -r '.mx_version' common.json)" >> ${GITHUB_ENV} - name: Checkout graalvm/mx - uses: actions/checkout@v3 + uses: actions/checkout@v4 with: repository: graalvm/mx.git ref: ${{ env.MX_VERSION }} fetch-depth: 1 path: ${{ env.MX_PATH }} - name: Set up Python - uses: actions/setup-python@v4 + uses: actions/setup-python@v5 with: python-version: '3.8' - name: Update mx cache - uses: actions/cache@v3 + uses: actions/cache@v4 with: path: ~/.mx key: ${{ runner.os }}-mx-${{ hashFiles('**/suite.py') }} From d93665fbd4e9edb28858a3a5552badd7daf47071 Mon Sep 17 00:00:00 2001 From: Volker Simonis Date: Wed, 28 Aug 2024 11:32:04 +0200 Subject: [PATCH 13/24] [GR-51529] FileSystemsTest#testSetAttribute() fails on JDK-23-linux. (cherry picked from commit 433b90a318293d446cb913ce1c59d77721c16f98) --- .../api/test/polyglot/FileSystemsTest.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/FileSystemsTest.java b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/FileSystemsTest.java index 1c46f71b41be..631a8ceb1264 100644 --- a/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/FileSystemsTest.java +++ b/truffle/src/com.oracle.truffle.api.test/src/com/oracle/truffle/api/test/polyglot/FileSystemsTest.java @@ -2044,7 +2044,7 @@ public void testSetAttribute() throws IOException { boolean canRead = cfg.canRead(); boolean canWrite = cfg.canWrite(); AbstractExecutableTestLanguage.evalTestLanguage(ctx, TestSetAttributeLanguage.class, "", configuration, path, usePublicFile, canRead, canWrite, supportsUnixAttributes(), - supportsSetLastAccessTime()); + supportsSetLastAccessTime(), supportsSetCreationTime()); } @Registration @@ -2059,6 +2059,7 @@ protected Object execute(RootNode node, Env env, Object[] contextArguments, Obje boolean canWrite = (boolean) contextArguments[4]; boolean supportsUnixAttributes = (boolean) contextArguments[5]; boolean supportsSetLastAccessTime = (boolean) contextArguments[6]; + boolean supportsSetCreationTime = (boolean) contextArguments[7]; TruffleFile root = resolve(env, usePublicFile, path); try { TruffleFile file = root.resolve(FILE_CHANGE_ATTRS); @@ -2067,14 +2068,18 @@ protected Object execute(RootNode node, Env env, Object[] contextArguments, Obje Assert.assertTrue(formatErrorMessage("Expected SecurityException", configurationName, path), canWrite); Assert.assertEquals(time, file.getAttribute(TruffleFile.LAST_MODIFIED_TIME)); Assert.assertTrue(formatErrorMessage("Expected SecurityException", configurationName, path), canRead); + file.setAttribute(TruffleFile.LAST_ACCESS_TIME, time); + FileTime lastAccessTime = file.getAttribute(TruffleFile.LAST_ACCESS_TIME); // Workaround for issue JDK-8298187: The file last access time does not work on // JDK-20 on macOS with the hfs file system. if (supportsSetLastAccessTime) { - file.setAttribute(TruffleFile.LAST_ACCESS_TIME, time); - Assert.assertEquals(time, file.getAttribute(TruffleFile.LAST_ACCESS_TIME)); + Assert.assertEquals(time, lastAccessTime); } file.setAttribute(TruffleFile.CREATION_TIME, time); - Assert.assertEquals(time, file.getAttribute(TruffleFile.CREATION_TIME)); + FileTime creationTime = file.getAttribute(TruffleFile.CREATION_TIME); + if (supportsSetCreationTime) { + Assert.assertEquals(time, creationTime); + } file.setAttribute(TruffleFile.UNIX_PERMISSIONS, EnumSet.of(PosixFilePermission.OWNER_READ)); Assert.assertEquals(EnumSet.of(PosixFilePermission.OWNER_READ), file.getAttribute(TruffleFile.UNIX_PERMISSIONS)); file.setAttribute(TruffleFile.UNIX_PERMISSIONS, EnumSet.of(PosixFilePermission.OWNER_READ)); @@ -2106,6 +2111,17 @@ private boolean supportsSetLastAccessTime() throws IOException { return true; } + /** + * Returns {@code true} if the operating system supports file creation time modification. Note: + * Posix does not support setting a file's creation time directly. MacOS and BSD Unix, however, + * provide an additional system call {@code fsetattrlist} utilized by Java NIO to set the + * creation time. On Linux, the Posix functions {@code utimes}, {@code futimens}, or + * {@code utimensat} are employed, allowing modification only of access and modification times. + */ + private static boolean supportsSetCreationTime() { + return OSUtils.isWindows() || OSUtils.getCurrent() == OSUtils.OS.Darwin; + } + @Test public void testGetAttributes() throws IOException { Context ctx = cfg.getContext(); From b3480b482a9686bf6f6a5075d95d7f2e5c226af6 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Mon, 25 Mar 2024 16:43:34 -0400 Subject: [PATCH 14/24] Add correct values to GCHeapSummary (cherry picked from commit f0a6a9c57a81292bc66f5998d8249c90a55727da) --- .../svm/core/genscavenge/JfrGCHeapSummaryEvent.java | 9 +++++---- .../oracle/svm/test/jfr/TestGCHeapSummaryEvent.java | 12 ++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCHeapSummaryEvent.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCHeapSummaryEvent.java index 232456a9fc29..76194023be8d 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCHeapSummaryEvent.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/JfrGCHeapSummaryEvent.java @@ -55,11 +55,12 @@ private static void emit0(UnsignedWord gcEpoch, long start, UnsignedWord committ JfrNativeEventWriter.putLong(data, gcWhen.getId()); // VirtualSpace - JfrNativeEventWriter.putLong(data, 0L); // start - JfrNativeEventWriter.putLong(data, 0L); // committedEnd + JfrNativeEventWriter.putLong(data, -1); // start + JfrNativeEventWriter.putLong(data, -1); // committedEnd JfrNativeEventWriter.putLong(data, committedSize.rawValue()); - JfrNativeEventWriter.putLong(data, 0L); // reservedEnd - JfrNativeEventWriter.putLong(data, 0L); // reservedSize + JfrNativeEventWriter.putLong(data, -1); // reservedEnd + // Reserved heap size matches committed size + JfrNativeEventWriter.putLong(data, committedSize.rawValue()); // reservedSize JfrNativeEventWriter.putLong(data, heapUsed.rawValue()); JfrNativeEventWriter.endSmallEvent(data); diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java index b0f457a73446..95ba749f82e2 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java @@ -29,6 +29,7 @@ import java.util.List; +import jdk.jfr.consumer.RecordedObject; import org.junit.Test; import com.oracle.svm.core.jfr.JfrEvent; @@ -49,5 +50,16 @@ public void test() throws Throwable { private static void validateEvents(List events) { assertTrue(events.size() > 0); + for (RecordedEvent event : events) { + RecordedObject heapSpace = event.getValue("heapSpace"); + assertTrue(heapSpace.getLong("start") == -1); + assertTrue(heapSpace.getLong("committedEnd") == -1); + assertTrue(heapSpace.getLong("reservedEnd") == -1); + assertTrue(heapSpace.getLong("committedSize") > 0); + assertTrue(heapSpace.getLong("reservedSize") >= heapSpace.getLong("committedSize")); + assertTrue(event.getLong("gcId") >= 0); + assertTrue(event.getString("when").equals("Before GC") || event.getString("when").equals("After GC")); + assertTrue(event.getLong("heapUsed") > 0); + } } } From 9045610a308f82338667760345bab401cc6c30cd Mon Sep 17 00:00:00 2001 From: Christian Haeubl Date: Wed, 27 Mar 2024 11:23:56 +0100 Subject: [PATCH 15/24] Minor cleanups. (cherry picked from commit 83b936ab7b8a9cde9532f5778eabbe19939a131f) --- .../svm/test/jfr/TestGCHeapSummaryEvent.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java index 95ba749f82e2..627cb16d4083 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/TestGCHeapSummaryEvent.java @@ -25,17 +25,18 @@ package com.oracle.svm.test.jfr; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import java.util.List; -import jdk.jfr.consumer.RecordedObject; import org.junit.Test; import com.oracle.svm.core.jfr.JfrEvent; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; +import jdk.jfr.consumer.RecordedObject; public class TestGCHeapSummaryEvent extends JfrRecordingTest { @Test @@ -52,11 +53,13 @@ private static void validateEvents(List events) { assertTrue(events.size() > 0); for (RecordedEvent event : events) { RecordedObject heapSpace = event.getValue("heapSpace"); - assertTrue(heapSpace.getLong("start") == -1); - assertTrue(heapSpace.getLong("committedEnd") == -1); - assertTrue(heapSpace.getLong("reservedEnd") == -1); - assertTrue(heapSpace.getLong("committedSize") > 0); - assertTrue(heapSpace.getLong("reservedSize") >= heapSpace.getLong("committedSize")); + assertEquals(-1, heapSpace.getLong("start")); + assertEquals(-1, heapSpace.getLong("committedEnd")); + assertEquals(-1, heapSpace.getLong("reservedEnd")); + + long committedSize = heapSpace.getLong("committedSize"); + assertTrue(committedSize > 0); + assertTrue(heapSpace.getLong("reservedSize") >= committedSize); assertTrue(event.getLong("gcId") >= 0); assertTrue(event.getString("when").equals("Before GC") || event.getString("when").equals("After GC")); assertTrue(event.getLong("heapUsed") > 0); From 810bf87705db7e172edb4c92f6ebebabcc8f8a01 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Tue, 20 Aug 2024 15:40:49 -0400 Subject: [PATCH 16/24] add JFR test proxy configuration. --- .../com/oracle/svm/test/jfr/AbstractJfrTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/AbstractJfrTest.java b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/AbstractJfrTest.java index ffde76ad560e..73b95ece753e 100644 --- a/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/AbstractJfrTest.java +++ b/substratevm/src/com.oracle.svm.test/src/com/oracle/svm/test/jfr/AbstractJfrTest.java @@ -41,6 +41,7 @@ import org.graalvm.nativeimage.ImageInfo; import org.graalvm.nativeimage.hosted.Feature; +import org.graalvm.nativeimage.hosted.RuntimeProxyCreation; import org.junit.After; import org.junit.Assert; import org.junit.BeforeClass; @@ -54,6 +55,7 @@ import jdk.jfr.Configuration; import jdk.jfr.consumer.RecordedEvent; import jdk.jfr.consumer.RecordingFile; +import jdk.jfr.Unsigned; /** Base class for JFR unit tests. */ public abstract class AbstractJfrTest { @@ -196,4 +198,16 @@ public void afterRegistration(AfterRegistrationAccess access) { */ ModuleSupport.accessPackagesToClass(ModuleSupport.Access.OPEN, JfrTestFeature.class, false, "jdk.internal.vm.compiler", "org.graalvm.compiler.serviceprovider"); } + + @Override + public void beforeAnalysis(BeforeAnalysisAccess access) { + /* + * Register proxies for event data assertion + * + * Unsigned added to be able to query RecordedObject.getLong() method, and this method + * checks if the value returned has the jdk.jfr.Unsigned. The jfr layer in HotSpot creates a + * proxy to query this information. + */ + RuntimeProxyCreation.register(Unsigned.class); + } } From 12f891c595cadffdc8b1eda80c9110b34eb33501 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Fri, 1 Mar 2024 14:14:37 -0500 Subject: [PATCH 17/24] add exit handlers if jfr or nmt is in the image (cherry picked from commit 581c88fde056c6b831a59658e01ec95e59033760) --- .../src/com/oracle/svm/core/SubstrateExitHandlerFeature.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java index d1ff3cac988b..d64cf6d42d17 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java @@ -34,7 +34,7 @@ public class SubstrateExitHandlerFeature implements InternalFeature { @Override public void beforeAnalysis(BeforeAnalysisAccess access) { - if (SubstrateOptions.InstallExitHandlers.getValue()) { + if (SubstrateOptions.InstallExitHandlers.getValue() || VMInspectionOptions.hasJfrSupport() || VMInspectionOptions.hasNativeMemoryTrackingSupport()) { RuntimeSupport.getRuntimeSupport().addStartupHook(new SubstrateExitHandlerStartupHook()); } } From f407f33df62fd106e1108341f13c175c98b5ca79 Mon Sep 17 00:00:00 2001 From: Robert Toyonaga Date: Tue, 20 Aug 2024 14:40:05 -0400 Subject: [PATCH 18/24] remove check for NMT since it does not exist in GraalVM for JDK21 --- .../src/com/oracle/svm/core/SubstrateExitHandlerFeature.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java index d64cf6d42d17..173c7e5436f1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateExitHandlerFeature.java @@ -34,7 +34,7 @@ public class SubstrateExitHandlerFeature implements InternalFeature { @Override public void beforeAnalysis(BeforeAnalysisAccess access) { - if (SubstrateOptions.InstallExitHandlers.getValue() || VMInspectionOptions.hasJfrSupport() || VMInspectionOptions.hasNativeMemoryTrackingSupport()) { + if (SubstrateOptions.InstallExitHandlers.getValue() || VMInspectionOptions.hasJfrSupport()) { RuntimeSupport.getRuntimeSupport().addStartupHook(new SubstrateExitHandlerStartupHook()); } } From ab24a74e281e2f67b983c90245334cbdd4029d9c Mon Sep 17 00:00:00 2001 From: Tom Shull Date: Thu, 25 Apr 2024 13:10:23 +0200 Subject: [PATCH 19/24] Fix AArch64AtomicMove. (cherry picked from commit b6e870a4990eb200497abcd59a9b8197e00377dd) --- .../lir/aarch64/AArch64AtomicMove.java | 105 +++++++++--------- 1 file changed, 54 insertions(+), 51 deletions(-) diff --git a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/lir/aarch64/AArch64AtomicMove.java b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/lir/aarch64/AArch64AtomicMove.java index af073574594c..ed8196c63223 100644 --- a/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/lir/aarch64/AArch64AtomicMove.java +++ b/compiler/src/jdk.internal.vm.compiler/src/org/graalvm/compiler/lir/aarch64/AArch64AtomicMove.java @@ -112,7 +112,7 @@ public CompareAndSwapOp(AArch64Kind accessKind, MemoryOrderMode memoryOrder, boo } /** - * Both cas and ld(a)xr produce a zero-extended value. Since comparisons must be at minimum + * Both cas and ldxr produce a zero-extended value. Since comparisons must be at minimum * 32-bits, the expected value must also be zero-extended to produce an accurate comparison. */ private static void emitCompare(AArch64MacroAssembler masm, int memAccessSize, Register result, Register expected) { @@ -169,8 +169,9 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) { throw GraalError.shouldNotReachHereUnexpectedValue(memoryOrder); // ExcludeFromJacocoGeneratedReport } + int moveSize = Math.max(memAccessSize, 32); if (AArch64LIRFlags.useLSE(masm)) { - masm.mov(Math.max(memAccessSize, 32), result, expected); + masm.mov(moveSize, result, expected); moveSPAndEmitCode(masm, asRegister(newValue), newVal -> { masm.cas(memAccessSize, result, newVal, address, acquire, release); }); @@ -178,44 +179,54 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) { emitCompare(masm, memAccessSize, result, expected); } } else { + + try (ScratchRegister scratchRegister1 = masm.getScratchRegister(); ScratchRegister scratchRegister2 = masm.getScratchRegister()) { + Label retry = new Label(); + masm.bind(retry); + Register scratch2 = scratchRegister2.getRegister(); + Register newValueReg = asRegister(newValue); + if (newValueReg.equals(sp)) { + /* + * SP cannot be used in csel or stl(x)r. + * + * Since csel overwrites scratch2, newValue must be newly loaded each loop + * iteration. However, unless under heavy contention, the storeExclusive + * should rarely fail. + */ + masm.mov(moveSize, scratch2, newValueReg); + newValueReg = scratch2; + } + masm.loadExclusive(memAccessSize, result, address, false); + + emitCompare(masm, memAccessSize, result, expected); + masm.csel(moveSize, scratch2, newValueReg, result, AArch64Assembler.ConditionFlag.EQ); + + /* + * STLXR must be used also if acquire is set to ensure prior ldaxr/stlxr + * instructions are not reordered after it. + */ + Register scratch1 = scratchRegister1.getRegister(); + masm.storeExclusive(memAccessSize, scratch1, scratch2, address, acquire || release); + // if scratch1 == 0 then write successful, else retry. + masm.cbnz(32, scratch1, retry); + } + /* - * Because the store is only conditionally emitted, a dmb is needed for performing a - * release. - * - * Furthermore, even if the stlxr is emitted, if both acquire and release semantics - * are required, then a dmb is anyways needed to ensure that the instruction - * sequence: + * From the Java perspective, the (ldxr, cmp, csel, stl(x)r) is a single atomic + * operation which must abide by all requested semantics. Therefore, when acquire + * semantics are needed, we use a full barrier after the store to guarantee that + * instructions following the store cannot execute before it and violate acquire + * semantics. * - * A -> ldaxr -> stlxr -> B - * - * cannot be executed as: - * - * ldaxr -> B -> A -> stlxr + * Note we could instead perform a conditional branch and when the comparison fails + * skip the store, but this introduces an opportunity for branch mispredictions, and + * also, when release semantics are needed, requires a barrier to be inserted before + * the operation. */ - if (release) { + + if (acquire) { masm.dmb(AArch64Assembler.BarrierKind.ANY_ANY); } - - moveSPAndEmitCode(masm, asRegister(newValue), newVal -> { - try (ScratchRegister scratchRegister = masm.getScratchRegister()) { - Register scratch = scratchRegister.getRegister(); - Label retry = new Label(); - Label fail = new Label(); - masm.bind(retry); - masm.loadExclusive(memAccessSize, result, address, acquire); - emitCompare(masm, memAccessSize, result, expected); - masm.branchConditionally(AArch64Assembler.ConditionFlag.NE, fail); - /* - * Even with the prior dmb, for releases it is still necessary to use stlxr - * instead of stxr to guarantee subsequent lda(x)r/stl(x)r cannot be hoisted - * above this instruction and thereby violate volatile semantics. - */ - masm.storeExclusive(memAccessSize, scratch, newVal, address, release); - // if scratch == 0 then write successful, else retry. - masm.cbnz(32, scratch, retry); - masm.bind(fail); - } - }); } } } @@ -291,14 +302,10 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) { } } /* - * Use a full barrier for the acquire semantics instead of ldaxr to guarantee that the - * instruction sequence: - * - * A -> ldaxr -> stlxr -> B - * - * cannot be executed as: - * - * ldaxr -> B -> A -> stlxr + * From the Java perspective, the (ldxr, add, stlxr) is a single atomic operation which + * must abide by both acquire and release semantics. Therefore, we use a full barrier + * after the store to guarantee that instructions following the store cannot execute + * before it and violate acquire semantics. */ masm.dmb(AArch64Assembler.BarrierKind.ANY_ANY); } @@ -406,14 +413,10 @@ public void emitCode(CompilationResultBuilder crb, AArch64MacroAssembler masm) { // if scratch == 0 then write successful, else retry masm.cbnz(32, scratch, retry); /* - * Use a full barrier for the acquire semantics instead of ldaxr to - * guarantee that the instruction sequence: - * - * A -> ldaxr -> stlxr -> B - * - * cannot be executed as: - * - * ldaxr -> B -> A -> stlxr + * From the Java perspective, the (ldxr, stlxr) is a single atomic operation + * which must abide by both acquire and release semantics. Therefore, we use + * a full barrier after the store to guarantee that instructions following + * the store cannot execute before it and violate acquire semantics. */ masm.dmb(AArch64Assembler.BarrierKind.ANY_ANY); } From 56ae8739bfeb99d9be601a298a985ee14c6ae950 Mon Sep 17 00:00:00 2001 From: Foivos Zakkak Date: Mon, 17 Jun 2024 12:18:09 +0300 Subject: [PATCH 20/24] Update LIBFFI to 3.4.6 Fixes https://github.com/oracle/graal/issues/9123 (cherry picked from commit dc03de27e69ffb0a0cf61ea522dcbb67f58fc9a7) --- truffle/mx.truffle/mx_truffle.py | 4 ++-- truffle/mx.truffle/suite.py | 4 ++-- .../0001-Preconfigure-sources-for-x64-Windows-build.patch | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/truffle/mx.truffle/mx_truffle.py b/truffle/mx.truffle/mx_truffle.py index 15358b7738cc..e6696b0a2f91 100644 --- a/truffle/mx.truffle/mx_truffle.py +++ b/truffle/mx.truffle/mx_truffle.py @@ -1036,7 +1036,7 @@ def __init__(self, suite, name, deps, workingSets, **kwargs): self.out_dir = self.get_output_root() if mx.get_os() == 'windows': self.delegate = mx_native.DefaultNativeProject(suite, name, subDir, [], [], None, - mx.join(self.out_dir, 'libffi-3.4.4'), + mx.join(self.out_dir, 'libffi-3.4.6'), 'static_lib', deliverable='ffi', cflags=['-MD', '-O2', '-DFFI_BUILDING_DLL']) @@ -1073,7 +1073,7 @@ def getArchivableResults(self, use_relpath=True, single=False): 'include/ffi.h', 'include/ffitarget.h'], mx.join(self.out_dir, 'libffi-build'), - mx.join(self.out_dir, 'libffi-3.4.4')) + mx.join(self.out_dir, 'libffi-3.4.6')) configure_args = ['--disable-dependency-tracking', '--disable-shared', '--with-pic', diff --git a/truffle/mx.truffle/suite.py b/truffle/mx.truffle/suite.py index c54ff1f1acfe..7f1c7ca62bea 100644 --- a/truffle/mx.truffle/suite.py +++ b/truffle/mx.truffle/suite.py @@ -72,12 +72,12 @@ "LIBFFI_SOURCES" : { "resource" : True, - "version" : "3.4.4", + "version" : "3.4.6", "urls" : [ "https://lafo.ssw.uni-linz.ac.at/pub/graal-external-deps/libffi-{version}.tar.gz", "https://github.com/libffi/libffi/releases/download/v{version}/libffi-{version}.tar.gz", ], - "digest" : "sha512:88680aeb0fa0dc0319e5cd2ba45b4b5a340bc9b4bcf20b1e0613b39cd898f177a3863aa94034d8e23a7f6f44d858a53dcd36d1bb8dee13b751ef814224061889", + "digest" : "sha512:033d2600e879b83c6bce0eb80f69c5f32aa775bf2e962c9d39fbd21226fa19d1e79173d8eaa0d0157014d54509ea73315ad86842356fc3a303c0831c94c6ab39", }, "ANTLR4": { diff --git a/truffle/src/libffi/patches/windows-amd64/0001-Preconfigure-sources-for-x64-Windows-build.patch b/truffle/src/libffi/patches/windows-amd64/0001-Preconfigure-sources-for-x64-Windows-build.patch index cdbab9f6f261..69b9cb79847b 100644 --- a/truffle/src/libffi/patches/windows-amd64/0001-Preconfigure-sources-for-x64-Windows-build.patch +++ b/truffle/src/libffi/patches/windows-amd64/0001-Preconfigure-sources-for-x64-Windows-build.patch @@ -231,7 +231,7 @@ index d38b781..6284190 100644 /* Define to the full name and version of this package. */ -#undef PACKAGE_STRING -+#define PACKAGE_STRING "libffi 3.4.4" ++#define PACKAGE_STRING "libffi 3.4.6" /* Define to the one symbol short name of this package. */ -#undef PACKAGE_TARNAME @@ -243,7 +243,7 @@ index d38b781..6284190 100644 /* Define to the version of this package. */ -#undef PACKAGE_VERSION -+#define PACKAGE_VERSION "3.4.4" ++#define PACKAGE_VERSION "3.4.6" /* The size of `double', as computed by sizeof. */ -#undef SIZEOF_DOUBLE @@ -283,7 +283,7 @@ index d38b781..6284190 100644 /* Version number of package */ -#undef VERSION -+#define VERSION "3.4.4" ++#define VERSION "3.4.6" /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ @@ -312,7 +312,7 @@ index 227ac79..6318a33 100644 @@ -1,5 +1,5 @@ /* -----------------------------------------------------------------*-C-*- - libffi @VERSION@ -+ libffi 3.4.4 ++ libffi 3.4.6 - Copyright (c) 2011, 2014, 2019, 2021, 2022 Anthony Green - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. From bab7110d7b468c3d5e589d36778728f6ca8fe6c6 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Mon, 8 Jul 2024 14:28:56 +0200 Subject: [PATCH 21/24] Fix windows patches. (cherry picked from commit 4668982e8c7fb5f1a7d12db5c56acafa09f479a9) --- ...figure-sources-for-x64-Windows-build.patch | 108 ++++-------------- ...-Adjust-sources-for-building-with-mx.patch | 13 +-- 2 files changed, 26 insertions(+), 95 deletions(-) diff --git a/truffle/src/libffi/patches/windows-amd64/0001-Preconfigure-sources-for-x64-Windows-build.patch b/truffle/src/libffi/patches/windows-amd64/0001-Preconfigure-sources-for-x64-Windows-build.patch index 69b9cb79847b..884695dac285 100644 --- a/truffle/src/libffi/patches/windows-amd64/0001-Preconfigure-sources-for-x64-Windows-build.patch +++ b/truffle/src/libffi/patches/windows-amd64/0001-Preconfigure-sources-for-x64-Windows-build.patch @@ -1,10 +1,11 @@ -From dcbda6eaf27ea03dd09b0d7edf67351c07209f2f Mon Sep 17 00:00:00 2001 +From fd913e2cce4901c12be4b6e0d88a1a719cc3a8fb Mon Sep 17 00:00:00 2001 From: Roland Schatz -Date: Thu, 7 Apr 2022 18:09:05 +0200 +Date: Mon, 8 Jul 2024 14:18:28 +0200 Subject: [PATCH 1/2] Preconfigure sources for x64 Windows build -The configuration was done using Git for Windows to run -`configure` from Developer Command Prompt: +The configuration was done using the x64 Native Tools Command Prompt for +VS 2022, with Git for Windows on the PATH. To reproduce run this +command: > sh configure --disable-builddir ^ --disable-dependency-tracking ^ @@ -16,22 +17,22 @@ The configuration was done using Git for Windows to run CXXCPP="cl -nologo -EP" ^ --build=amd64-mingw64 --- - fficonfig.h.in => fficonfig.h | 125 ++++++++++++++++--------------- - include/{ffi.h.in => ffi.h} | 18 ++--- + fficonfig.h.in => fficonfig.h | 103 ++++++++++++++++--------------- + include/{ffi.h.in => ffi.h} | 14 ++--- {src/x86 => include}/ffitarget.h | 0 - 3 files changed, 72 insertions(+), 71 deletions(-) - rename fficonfig.h.in => fficonfig.h (71%) + 3 files changed, 59 insertions(+), 58 deletions(-) + rename fficonfig.h.in => fficonfig.h (70%) rename include/{ffi.h.in => ffi.h} (98%) rename {src/x86 => include}/ffitarget.h (100%) diff --git a/fficonfig.h.in b/fficonfig.h -similarity index 71% +similarity index 70% rename from fficonfig.h.in rename to fficonfig.h -index d38b781..6284190 100644 +index 2e4aac6..59723f3 100644 --- a/fficonfig.h.in +++ b/fficonfig.h -@@ -1,171 +1,172 @@ +@@ -1,159 +1,160 @@ +/* fficonfig.h. Generated from fficonfig.h.in by configure. */ /* fficonfig.h.in. Generated from configure.ac by autoheader. */ @@ -39,10 +40,6 @@ index d38b781..6284190 100644 -#undef AC_APPLE_UNIVERSAL_BUILD +/* #undef AC_APPLE_UNIVERSAL_BUILD */ - /* Define to 1 if using 'alloca.c'. */ --#undef C_ALLOCA -+/* #undef C_ALLOCA */ - /* Define to the flags needed for the .section .eh_frame directive. */ -#undef EH_FRAME_FLAGS +/* #undef EH_FRAME_FLAGS */ @@ -76,11 +73,7 @@ index d38b781..6284190 100644 -#undef FFI_NO_STRUCTS +/* #undef FFI_NO_STRUCTS */ - /* Define to 1 if you have 'alloca', as a function or macro. */ --#undef HAVE_ALLOCA -+#define HAVE_ALLOCA 1 - - /* Define to 1 if works. */ + /* Define to 1 if you have the header file. */ -#undef HAVE_ALLOCA_H +/* #undef HAVE_ALLOCA_H */ @@ -137,30 +130,6 @@ index d38b781..6284190 100644 -#undef HAVE_MEMFD_CREATE +/* #undef HAVE_MEMFD_CREATE */ - /* Define to 1 if you have the `mkostemp' function. */ --#undef HAVE_MKOSTEMP -+/* #undef HAVE_MKOSTEMP */ - - /* Define to 1 if you have the `mkstemp' function. */ --#undef HAVE_MKSTEMP -+/* #undef HAVE_MKSTEMP */ - - /* Define to 1 if you have the `mmap' function. */ --#undef HAVE_MMAP -+/* #undef HAVE_MMAP */ - - /* Define if mmap with MAP_ANON(YMOUS) works. */ --#undef HAVE_MMAP_ANON -+/* #undef HAVE_MMAP_ANON */ - - /* Define if mmap of /dev/zero works. */ --#undef HAVE_MMAP_DEV_ZERO -+/* #undef HAVE_MMAP_DEV_ZERO */ - - /* Define if read-only mmap of a plain file works. */ --#undef HAVE_MMAP_FILE -+/* #undef HAVE_MMAP_FILE */ - /* Define if your compiler supports pointer authentication. */ -#undef HAVE_PTRAUTH +/* #undef HAVE_PTRAUTH */ @@ -193,10 +162,6 @@ index d38b781..6284190 100644 -#undef HAVE_SYS_MEMFD_H +/* #undef HAVE_SYS_MEMFD_H */ - /* Define to 1 if you have the header file. */ --#undef HAVE_SYS_MMAN_H -+/* #undef HAVE_SYS_MMAN_H */ - /* Define to 1 if you have the header file. */ -#undef HAVE_SYS_STAT_H +#define HAVE_SYS_STAT_H 1 @@ -257,15 +222,6 @@ index d38b781..6284190 100644 -#undef SIZEOF_SIZE_T +#define SIZEOF_SIZE_T 8 - /* If using the C implementation of alloca, define if you know the - direction of stack growth for your system; otherwise it will be -@@ -173,22 +174,22 @@ - STACK_DIRECTION > 0 => grows toward higher addresses - STACK_DIRECTION < 0 => grows toward lower addresses - STACK_DIRECTION = 0 => direction of growth unknown */ --#undef STACK_DIRECTION -+/* #undef STACK_DIRECTION */ - /* Define to 1 if all of the C90 standard headers exist (not just the ones required in a freestanding environment). This macro is provided for backward compatibility; new code need not use it. */ @@ -287,7 +243,7 @@ index d38b781..6284190 100644 /* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most significant byte first (like Motorola and SPARC, unlike Intel). */ -@@ -198,12 +199,12 @@ +@@ -163,7 +164,7 @@ # endif #else # ifndef WORDS_BIGENDIAN @@ -296,24 +252,18 @@ index d38b781..6284190 100644 # endif #endif - /* Define to `unsigned int' if does not define. */ --#undef size_t -+/* #undef size_t */ - - - #ifdef HAVE_HIDDEN_VISIBILITY_ATTRIBUTE diff --git a/include/ffi.h.in b/include/ffi.h similarity index 98% rename from include/ffi.h.in rename to include/ffi.h -index 227ac79..6318a33 100644 +index e5c1dae..ef012e2 100644 --- a/include/ffi.h.in +++ b/include/ffi.h @@ -1,5 +1,5 @@ /* -----------------------------------------------------------------*-C-*- - libffi @VERSION@ + libffi 3.4.6 - - Copyright (c) 2011, 2014, 2019, 2021, 2022 Anthony Green + - Copyright (c) 2011, 2014, 2019, 2021, 2022, 2024 Anthony Green - Copyright (c) 1996-2003, 2007, 2008 Red Hat, Inc. @@ -50,8 +50,8 @@ extern "C" { @@ -336,25 +286,7 @@ index 227ac79..6318a33 100644 #define FFI_TYPE_LONGDOUBLE 4 #else #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE -@@ -223,7 +223,7 @@ FFI_EXTERN ffi_type ffi_type_float; - FFI_EXTERN ffi_type ffi_type_double; - FFI_EXTERN ffi_type ffi_type_pointer; - --#if @HAVE_LONG_DOUBLE@ -+#if 0 - FFI_EXTERN ffi_type ffi_type_longdouble; - #else - #define ffi_type_longdouble ffi_type_double -@@ -232,7 +232,7 @@ FFI_EXTERN ffi_type ffi_type_longdouble; - #ifdef FFI_TARGET_HAS_COMPLEX_TYPE - FFI_EXTERN ffi_type ffi_type_complex_float; - FFI_EXTERN ffi_type ffi_type_complex_double; --#if @HAVE_LONG_DOUBLE@ -+#if 0 - FFI_EXTERN ffi_type ffi_type_complex_longdouble; - #else - #define ffi_type_complex_longdouble ffi_type_complex_double -@@ -333,7 +333,7 @@ size_t ffi_java_raw_size (ffi_cif *cif) __attribute__((deprecated)); +@@ -322,7 +322,7 @@ size_t ffi_java_raw_size (ffi_cif *cif) __attribute__((deprecated)); __declspec(align(8)) #endif typedef struct { @@ -363,7 +295,7 @@ index 227ac79..6318a33 100644 void *trampoline_table; void *trampoline_table_entry; #else -@@ -394,7 +394,7 @@ ffi_prep_closure_loc (ffi_closure*, +@@ -375,7 +375,7 @@ ffi_prep_closure_loc (ffi_closure*, # pragma pack 8 #endif typedef struct { @@ -372,7 +304,7 @@ index 227ac79..6318a33 100644 void *trampoline_table; void *trampoline_table_entry; #else -@@ -419,7 +419,7 @@ typedef struct { +@@ -400,7 +400,7 @@ typedef struct { } ffi_raw_closure; typedef struct { @@ -386,5 +318,5 @@ similarity index 100% rename from src/x86/ffitarget.h rename to include/ffitarget.h -- -2.38.4 +2.44.1 diff --git a/truffle/src/libffi/patches/windows-amd64/0002-Adjust-sources-for-building-with-mx.patch b/truffle/src/libffi/patches/windows-amd64/0002-Adjust-sources-for-building-with-mx.patch index 5446e46a2201..f9148d673830 100644 --- a/truffle/src/libffi/patches/windows-amd64/0002-Adjust-sources-for-building-with-mx.patch +++ b/truffle/src/libffi/patches/windows-amd64/0002-Adjust-sources-for-building-with-mx.patch @@ -1,14 +1,14 @@ -From e5a5380862ea8e92c3e0c1634c5f305c8648425b Mon Sep 17 00:00:00 2001 +From 9601e9219678f2a1ad628ae78e4d8c11c27217a9 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Wed, 17 May 2023 16:10:46 +0200 Subject: [PATCH 2/2] Adjust sources for building with mx --- include/Makefile.am | 9 - - include/Makefile.in | 610 --------------------------------- + include/Makefile.in | 609 --------------------------------- {include => src}/ffi_common.h | 0 fficonfig.h => src/fficonfig.h | 0 - 4 files changed, 619 deletions(-) + 4 files changed, 618 deletions(-) delete mode 100644 include/Makefile.am delete mode 100644 include/Makefile.in rename {include => src}/ffi_common.h (100%) @@ -31,10 +31,10 @@ index 5f0d406..0000000 -nodist_include_HEADERS = ffi.h ffitarget.h diff --git a/include/Makefile.in b/include/Makefile.in deleted file mode 100644 -index 7e3bbf0..0000000 +index ae3ad01..0000000 --- a/include/Makefile.in +++ /dev/null -@@ -1,610 +0,0 @@ +@@ -1,609 +0,0 @@ -# Makefile.in generated by automake 1.16.5 from Makefile.am. -# @configure_input@ - @@ -219,7 +219,6 @@ index 7e3bbf0..0000000 -am__DIST_COMMON = $(srcdir)/Makefile.in $(srcdir)/ffi.h.in -DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) -ACLOCAL = @ACLOCAL@ --ALLOCA = @ALLOCA@ -AMTAR = @AMTAR@ -AM_DEFAULT_VERBOSITY = @AM_DEFAULT_VERBOSITY@ -AM_LTLDFLAGS = @AM_LTLDFLAGS@ @@ -654,5 +653,5 @@ similarity index 100% rename from fficonfig.h rename to src/fficonfig.h -- -2.38.4 +2.44.1 From 2d5a5793a1abce2e033b56eadd9ffd93cba8d7b1 Mon Sep 17 00:00:00 2001 From: Roland Schatz Date: Tue, 9 Jul 2024 10:49:56 +0200 Subject: [PATCH 22/24] Fix libffi build on windows. (cherry picked from commit c208addf7ed1cef3c6347b0da5dc38faa5b7a9e6) --- truffle/mx.truffle/mx_truffle.py | 2 +- truffle/src/com.oracle.truffle.nfi.native/src/closure.c | 2 +- truffle/src/com.oracle.truffle.nfi.native/src/jni.c | 2 +- truffle/src/com.oracle.truffle.nfi.native/src/signature.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/truffle/mx.truffle/mx_truffle.py b/truffle/mx.truffle/mx_truffle.py index e6696b0a2f91..9df3b85bb8d3 100644 --- a/truffle/mx.truffle/mx_truffle.py +++ b/truffle/mx.truffle/mx_truffle.py @@ -1039,7 +1039,7 @@ def __init__(self, suite, name, deps, workingSets, **kwargs): mx.join(self.out_dir, 'libffi-3.4.6'), 'static_lib', deliverable='ffi', - cflags=['-MD', '-O2', '-DFFI_BUILDING_DLL']) + cflags=['-MD', '-O2', '-DFFI_STATIC_BUILD']) self.delegate._source = dict(tree=['include', 'src', mx.join('src', 'x86')], diff --git a/truffle/src/com.oracle.truffle.nfi.native/src/closure.c b/truffle/src/com.oracle.truffle.nfi.native/src/closure.c index 792c3dc55722..cbc9653c4357 100644 --- a/truffle/src/com.oracle.truffle.nfi.native/src/closure.c +++ b/truffle/src/com.oracle.truffle.nfi.native/src/closure.c @@ -40,7 +40,7 @@ */ #if defined(_WIN32) // Workaround for static linking. See comment in ffi.h, line 115. -#define FFI_BUILDING +#define FFI_STATIC_BUILD #endif #include "trufflenfi.h" diff --git a/truffle/src/com.oracle.truffle.nfi.native/src/jni.c b/truffle/src/com.oracle.truffle.nfi.native/src/jni.c index c50d5291b8bd..0e7259c49d8c 100644 --- a/truffle/src/com.oracle.truffle.nfi.native/src/jni.c +++ b/truffle/src/com.oracle.truffle.nfi.native/src/jni.c @@ -40,7 +40,7 @@ */ #if defined(_WIN32) // Workaround for static linking. See comment in ffi.h, line 115. -#define FFI_BUILDING +#define FFI_STATIC_BUILD #endif #include "native.h" diff --git a/truffle/src/com.oracle.truffle.nfi.native/src/signature.c b/truffle/src/com.oracle.truffle.nfi.native/src/signature.c index 351f85507a89..23bddd6a5853 100644 --- a/truffle/src/com.oracle.truffle.nfi.native/src/signature.c +++ b/truffle/src/com.oracle.truffle.nfi.native/src/signature.c @@ -40,7 +40,7 @@ */ #if defined(_WIN32) // Workaround for static linking. See comment in ffi.h, line 115. -#define FFI_BUILDING +#define FFI_STATIC_BUILD #endif #include "native.h" From 7127f4aff58b28ab77133def0eeafcfe5061955b Mon Sep 17 00:00:00 2001 From: Loic Ottet Date: Tue, 29 Aug 2023 11:35:31 +0200 Subject: [PATCH 23/24] Correctly handle resource include patterns (cherry picked from commit 2368a2f047ee917660055d3d994a6195334bb725) --- .../com/oracle/svm/core/jdk/Resources.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java index 28bfec77f7e2..15963c1437ef 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Resources.java @@ -280,10 +280,28 @@ public void registerIncludePattern(String module, String pattern) { assert MissingRegistrationUtils.throwMissingRegistrationErrors(); synchronized (includePatterns) { updateTimeStamp(); - includePatterns.add(new ModuleResourcePair(module, pattern)); + includePatterns.add(new ModuleResourcePair(module, handleEscapedCharacters(pattern))); } } + @Platforms(Platform.HOSTED_ONLY.class)// + private static final String BEGIN_ESCAPED_SEQUENCE = "\\Q"; + + @Platforms(Platform.HOSTED_ONLY.class)// + private static final String END_ESCAPED_SEQUENCE = "\\E"; + + /* + * This handles generated include patterns which start and end with \Q and \E. The actual + * resource name is located inbetween those tags. + */ + @Platforms(Platform.HOSTED_ONLY.class) + private static String handleEscapedCharacters(String pattern) { + if (pattern.startsWith(BEGIN_ESCAPED_SEQUENCE) && pattern.endsWith(END_ESCAPED_SEQUENCE)) { + return pattern.substring(BEGIN_ESCAPED_SEQUENCE.length(), pattern.length() - END_ESCAPED_SEQUENCE.length()); + } + return pattern; + } + /** * Avoid pulling native file system by using {@link NativeImageResourcePath} implementation to * convert resourceName to canonical variant. From 1b0c49c9095928e5303793e24df1eb345e7ed3c6 Mon Sep 17 00:00:00 2001 From: Vojin Jovanovic Date: Tue, 11 Jun 2024 14:42:13 +0200 Subject: [PATCH 24/24] Allow custom constructors for arrays and enums (cherry picked from commit 55a34e736625de367f92f0ebd2e8b3800b3558a1) --- .../serialize/MissingSerializationRegistrationUtils.java | 9 +++------ .../svm/core/reflect/serialize/SerializationSupport.java | 2 +- .../hosted/reflect/serialize/SerializationFeature.java | 3 --- 3 files changed, 4 insertions(+), 10 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/MissingSerializationRegistrationUtils.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/MissingSerializationRegistrationUtils.java index 049df6208a9d..9d0bc4926866 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/MissingSerializationRegistrationUtils.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/MissingSerializationRegistrationUtils.java @@ -39,7 +39,9 @@ public final class MissingSerializationRegistrationUtils { public static void missingSerializationRegistration(Class cl, String... msg) { - report(new MissingSerializationRegistrationError(errorMessage(msg), cl)); + MissingSerializationRegistrationError exception = new MissingSerializationRegistrationError(errorMessage(msg), cl); + StackTraceElement responsibleClass = getResponsibleClass(exception); + MissingRegistrationUtils.report(exception, responsibleClass); } private static String errorMessage(String... type) { @@ -55,11 +57,6 @@ private static String errorMessage(String... type) { .formatted(typeStr); } - private static void report(MissingSerializationRegistrationError exception) { - StackTraceElement responsibleClass = getResponsibleClass(exception); - MissingRegistrationUtils.report(exception, responsibleClass); - } - /* * This is a list of all public JDK methods that end up potentially throwing missing * registration errors. This should be implemented using wrapping substitutions once they are diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/SerializationSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/SerializationSupport.java index ae07d0cd589b..d338b2461bbe 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/SerializationSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/reflect/serialize/SerializationSupport.java @@ -158,7 +158,7 @@ public Object getSerializationConstructorAccessor(Class rawDeclaringClass, Cl String targetConstructorClassName = targetConstructorClass.getName(); if (ThrowMissingRegistrationErrors.hasBeenSet()) { MissingSerializationRegistrationUtils.missingSerializationRegistration(declaringClass, - "type " + declaringClass.getName() + " with target constructor class: " + targetConstructorClassName); + "type " + declaringClass.getTypeName() + " with target constructor class: " + targetConstructorClassName); } else { throw VMError.unsupportedFeature("SerializationConstructorAccessor class not found for declaringClass: " + declaringClass.getName() + " (targetConstructorClass: " + targetConstructorClassName + "). Usually adding " + declaringClass.getName() + diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java index c665eeff3124..32a4813ca802 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/serialize/SerializationFeature.java @@ -669,9 +669,6 @@ private static Constructor getExternalizableConstructor(Class serializatio Class addConstructorAccessor(Class serializationTargetClass, Class customTargetConstructorClass) { serializationSupport.registerSerializationTargetClass(serializationTargetClass); - if (serializationTargetClass.isArray() || Enum.class.isAssignableFrom(serializationTargetClass)) { - return null; - } // Don't generate SerializationConstructorAccessor class for Externalizable case if (Externalizable.class.isAssignableFrom(serializationTargetClass)) {