From 24c6062daf0ba786e65a3ff157cce44ceb2be283 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 18 Aug 2023 09:18:47 +0200 Subject: [PATCH 1/7] svm: check substitution return type --- .../svm/hosted/substitute/AnnotationSubstitutionProcessor.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java index 79f9461a9837..79dde3f49329 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java @@ -854,6 +854,8 @@ private ResolvedJavaMethod findOriginalMethod(Executable annotatedMethod, Class< Method originalMethod = originalClass.getDeclaredMethod(originalName, originalParams); guarantee(Modifier.isStatic(annotatedMethod.getModifiers()) == Modifier.isStatic(originalMethod.getModifiers()), "Static modifier mismatch: %s, %s", annotatedMethod, originalMethod); + guarantee(getTargetClass(((Method) annotatedMethod).getReturnType()).equals(originalMethod.getReturnType()), + "Return type mismatch:%n %s%n %s", annotatedMethod, originalMethod); return metaAccess.lookupJavaMethod(originalMethod); } else { From 69c5dd71eb3111c65d04920d3a4edae5194295af Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Fri, 18 Aug 2023 10:33:20 +0200 Subject: [PATCH 2/7] svm: fix substitution return types --- .../com/oracle/svm/core/hub/DynamicHub.java | 19 ++++++++++--------- .../com/oracle/svm/core/jdk/JRTSupport.java | 6 +++++- .../svm/core/jdk/JavaLangSubstitutions.java | 7 ++++--- .../svm/core/jdk/SecuritySubstitutions.java | 8 ++++++-- .../jdk/Target_java_lang_ClassLoader.java | 2 +- .../jdk/Target_sun_nio_ch_Util_JDK17.java | 10 ++++++---- .../Target_sun_nio_ch_Util_JDK19OrLater.java | 10 ++++++---- .../Target_java_util_Locale.java | 4 ++-- .../core/jfr/Target_jdk_jfr_internal_JVM.java | 2 +- ...et_java_lang_invoke_BoundMethodHandle.java | 5 +++-- ...get_java_lang_invoke_ClassSpecializer.java | 4 ++-- .../svm/core/thread/LoomVirtualThreads.java | 2 +- .../core/thread/Target_java_lang_Thread.java | 8 ++++++-- .../oracle/svm/truffle/nfi/NativeAPIImpl.java | 9 ++++----- ...ffle_nfi_backend_libffi_LibFFIContext.java | 7 ++----- ...uffle_nfi_backend_libffi_LibFFISymbol.java | 2 +- .../svm/truffle/TruffleBaseFeature.java | 5 +++-- 17 files changed, 63 insertions(+), 47 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index 51388df7948a..9c335571bb22 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -752,12 +752,12 @@ public int getClassAccessFlags() { } @Substitute - private Object getComponentType() { + private DynamicHub getComponentType() { return componentType; } @Substitute - private Object getSuperclass() { + private DynamicHub getSuperclass() { return superHub; } @@ -786,23 +786,24 @@ private boolean isAnnotation() { } @Substitute + @SuppressFBWarnings(value = "EC_UNRELATED_TYPES_USING_POINTER_EQUALITY", justification = "Class is DynamicHub") private boolean isEnum() { /* * We do not do the check "this.getModifiers() & ENUM) != 0" because we do not have the full * modifier bits. */ - return this.getSuperclass() == java.lang.Enum.class; + return (Object) this.getSuperclass() == java.lang.Enum.class; } @KeepOriginal - private native Enum[] getEnumConstants(); + private native Object[] getEnumConstants(); @Substitute - public Enum[] getEnumConstantsShared() { + public Object[] getEnumConstantsShared() { if (enumConstantsReference instanceof LazyFinalReference) { - return (Enum[]) ((LazyFinalReference) enumConstantsReference).get(); + return (Object[]) ((LazyFinalReference) enumConstantsReference).get(); } - return (Enum[]) enumConstantsReference; + return (Object[]) enumConstantsReference; } @KeepOriginal @@ -962,7 +963,7 @@ public T[] getAnnotationsByType(Class annotationClass) T[] result = getDeclaredAnnotationsByType(annotationClass); if (result.length == 0 && AnnotationAccess.isAnnotationPresent(annotationClass, Inherited.class)) { - DynamicHub superClass = (DynamicHub) this.getSuperclass(); + DynamicHub superClass = this.getSuperclass(); if (superClass != null) { /* Determine if the annotation is associated with the superclass. */ result = superClass.getAnnotationsByType(annotationClass); @@ -1378,7 +1379,7 @@ String computePackageName() { String pn = null; DynamicHub me = this; while (me.hubIsArray()) { - me = (DynamicHub) me.getComponentType(); + me = me.getComponentType(); } if (me.isPrimitive()) { pn = "java.lang"; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java index 71e5da517a75..795cd42e1cd9 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JRTSupport.java @@ -154,11 +154,15 @@ final class Target_jdk_internal_jimage_ImageReaderFactory_JRTEnabled { @TargetClass(className = "jdk.internal.module.SystemModuleFinders", innerClass = "SystemImage", onlyWith = JRTDisabled.class) final class Target_jdk_internal_module_SystemModuleFinders_SystemImage_JRTDisabled { @Substitute - static Object reader() { + static Target_jdk_internal_jimage_ImageReader reader() { throw VMError.unsupportedFeature("JRT file system is disabled"); } } +@TargetClass(className = "jdk.internal.jimage.ImageReader", onlyWith = JRTDisabled.class) +final class Target_jdk_internal_jimage_ImageReader { +} + @TargetClass(className = "sun.net.www.protocol.jrt.Handler", onlyWith = JRTDisabled.class) final class Target_sun_net_www_protocol_jrt_Handler_JRTDisabled { @Substitute diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java index c6e75f3d4b8d..b37a0608cd3a 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaLangSubstitutions.java @@ -91,7 +91,7 @@ final class Target_java_lang_Object { @Substitute @TargetElement(name = "getClass") - private Object getClassSubst() { + private DynamicHub getClassSubst() { return readHub(this); } @@ -139,11 +139,12 @@ private static Enum valueOf(Class> enumType, String name) { * The original implementation creates and caches a HashMap to make the lookup faster. For * simplicity, we do a linear search for now. */ - Enum[] enumConstants = DynamicHub.fromClass(enumType).getEnumConstantsShared(); + Object[] enumConstants = DynamicHub.fromClass(enumType).getEnumConstantsShared(); if (enumConstants == null) { throw new IllegalArgumentException(enumType.getName() + " is not an enum type"); } - for (Enum e : enumConstants) { + for (Object o : enumConstants) { + Enum e = (Enum) o; if (e.name().equals(name)) { return e; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java index e799ceaa26d3..3c5f4b493879 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/SecuritySubstitutions.java @@ -169,11 +169,15 @@ protected Class[] getClassContext() { @SuppressWarnings({"static-method", "unused"}) final class Target_javax_crypto_JceSecurityManager { @Substitute - Object getCryptoPermission(String var1) { - return Target_javax_crypto_CryptoAllPermission.INSTANCE; + Target_javax_crypto_CryptoPermission getCryptoPermission(String var1) { + return SubstrateUtil.cast(Target_javax_crypto_CryptoAllPermission.INSTANCE, Target_javax_crypto_CryptoPermission.class); } } +@TargetClass(className = "javax.crypto.CryptoPermission") +final class Target_javax_crypto_CryptoPermission { +} + @TargetClass(className = "javax.crypto.CryptoAllPermission") final class Target_javax_crypto_CryptoAllPermission { @Alias // diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java index 97ca345eeb32..4e4c9fbf35c1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_java_lang_ClassLoader.java @@ -88,7 +88,7 @@ public static ClassLoader getSystemClassLoader() { } @Delete - private static native void initSystemClassLoader(); + private static native ClassLoader initSystemClassLoader(); @Alias public native Enumeration findResources(String name); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java index 51545b000225..e40dad0757b5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK17.java @@ -25,7 +25,9 @@ package com.oracle.svm.core.jdk; import java.io.FileDescriptor; +import java.nio.MappedByteBuffer; +import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; @@ -66,13 +68,13 @@ protected Target_java_nio_DirectByteBufferR_JDK17(int cap, long addr, FileDescri final class Target_sun_nio_ch_Util_JDK17 { @Substitute - private static Target_java_nio_DirectByteBuffer_JDK17 newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return new Target_java_nio_DirectByteBuffer_JDK17(size, addr, fd, unmapper, isSync, null); + private static MappedByteBuffer newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { + return SubstrateUtil.cast(new Target_java_nio_DirectByteBuffer_JDK17(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); } @Substitute - static Target_java_nio_DirectByteBufferR_JDK17 newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return new Target_java_nio_DirectByteBufferR_JDK17(size, addr, fd, unmapper, isSync, null); + static MappedByteBuffer newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { + return SubstrateUtil.cast(new Target_java_nio_DirectByteBufferR_JDK17(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java index 4ec35595d2d8..48b067b164b7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/Target_sun_nio_ch_Util_JDK19OrLater.java @@ -25,7 +25,9 @@ package com.oracle.svm.core.jdk; import java.io.FileDescriptor; +import java.nio.MappedByteBuffer; +import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.Substitute; import com.oracle.svm.core.annotate.TargetClass; @@ -61,13 +63,13 @@ protected Target_java_nio_DirectByteBufferR_JDK19OrLater(int cap, long addr, Fil final class Target_sun_nio_ch_Util_JDK19OrLater { @Substitute - private static Target_java_nio_DirectByteBuffer_JDK19OrLater newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return new Target_java_nio_DirectByteBuffer_JDK19OrLater(size, addr, fd, unmapper, isSync, null); + private static MappedByteBuffer newMappedByteBuffer(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { + return SubstrateUtil.cast(new Target_java_nio_DirectByteBuffer_JDK19OrLater(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); } @Substitute - static Target_java_nio_DirectByteBufferR_JDK19OrLater newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { - return new Target_java_nio_DirectByteBufferR_JDK19OrLater(size, addr, fd, unmapper, isSync, null); + static MappedByteBuffer newMappedByteBufferR(int size, long addr, FileDescriptor fd, Runnable unmapper, boolean isSync) { + return SubstrateUtil.cast(new Target_java_nio_DirectByteBufferR_JDK19OrLater(size, addr, fd, unmapper, isSync, null), MappedByteBuffer.class); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_Locale.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_Locale.java index c8edfaae218e..cb1517ad9ac9 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_Locale.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/localization/substitutions/Target_java_util_Locale.java @@ -43,12 +43,12 @@ final class Target_java_util_Locale { private static Locale defaultFormatLocale; @Substitute - private static Object initDefault() { + private static Locale initDefault() { throw VMError.shouldNotReachHere("The default Locale must be initialized during image generation"); } @Substitute - private static Object initDefault(Locale.Category category) { + private static Locale initDefault(Locale.Category category) { throw VMError.shouldNotReachHere("The default Locale must be initialized during image generation: " + category); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java index e0f307db21fa..896fa341cf48 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java @@ -335,7 +335,7 @@ public static long getTypeId(Class clazz) { /** See {@link JVM#getEventWriter}. */ @Substitute - public static Object getEventWriter() { + public static Target_jdk_jfr_internal_EventWriter getEventWriter() { return SubstrateJVM.get().getEventWriter(); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_BoundMethodHandle.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_BoundMethodHandle.java index 52ef0fa8e796..c7db64d6199c 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_BoundMethodHandle.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_BoundMethodHandle.java @@ -152,7 +152,8 @@ final class BoundMethodHandleUtils { /* Bound method handle constructor */ static Target_java_lang_invoke_BoundMethodHandle make(MethodType type, Target_java_lang_invoke_LambdaForm form, String species, Object... args) { Target_java_lang_invoke_SimpleMethodHandle bmh = new Target_java_lang_invoke_SimpleMethodHandle(type, form); - bmh.speciesData = SubstrateUtil.cast(Target_java_lang_invoke_BoundMethodHandle.SPECIALIZER, Target_java_lang_invoke_ClassSpecializer.class).findSpecies(species); + bmh.speciesData = SubstrateUtil.cast(SubstrateUtil.cast(Target_java_lang_invoke_BoundMethodHandle.SPECIALIZER, Target_java_lang_invoke_ClassSpecializer.class).findSpecies(species), + Target_java_lang_invoke_BoundMethodHandle_SpeciesData.class); bmh.args = (args != null) ? Arrays.copyOf(args, args.length) : new Object[0]; return SubstrateUtil.cast(bmh, Target_java_lang_invoke_BoundMethodHandle.class); } @@ -168,6 +169,6 @@ static Object[] appendArgs(Object[] args, Object newArg) { } static String speciesKey(Target_java_lang_invoke_SimpleMethodHandle bmh) { - return SubstrateUtil.cast(bmh.speciesData(), Target_java_lang_invoke_ClassSpecializer_SpeciesData.class).key(); + return (String) SubstrateUtil.cast(bmh.speciesData(), Target_java_lang_invoke_ClassSpecializer_SpeciesData.class).key(); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_ClassSpecializer.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_ClassSpecializer.java index 1a4f2c2a584a..66dbe75ded04 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_ClassSpecializer.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_ClassSpecializer.java @@ -31,13 +31,13 @@ @TargetClass(className = "java.lang.invoke.ClassSpecializer") final class Target_java_lang_invoke_ClassSpecializer { @Alias - native Target_java_lang_invoke_BoundMethodHandle_SpeciesData findSpecies(Object ll); + native Target_java_lang_invoke_ClassSpecializer_SpeciesData findSpecies(Object ll); } @TargetClass(className = "java.lang.invoke.ClassSpecializer", innerClass = "SpeciesData") final class Target_java_lang_invoke_ClassSpecializer_SpeciesData { @Alias - native String key(); + native Object key(); @Alias protected native String deriveClassName(); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/LoomVirtualThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/LoomVirtualThreads.java index a5cfa666de02..6d93e2b02815 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/LoomVirtualThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/LoomVirtualThreads.java @@ -58,7 +58,7 @@ private static Target_java_lang_VirtualThread cast(Thread thread) { @Override public ThreadFactory createFactory() { - return Target_java_lang_Thread.ofVirtual().factory(); + return SubstrateUtil.cast(Target_java_lang_Thread.ofVirtual(), Target_java_lang_Thread_Builder.class).factory(); } @Override diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java index 38d3b1fb1e52..1ce2a6fd7a41 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/Target_java_lang_Thread.java @@ -668,11 +668,11 @@ private static void clearInterruptEvent() { @Alias @TargetElement(onlyWith = LoomJDK.class) - public static native Target_java_lang_Thread_Builder ofVirtual(); + public static native Target_java_lang_Thread_Builder_OfVirtual ofVirtual(); @Substitute @TargetElement(name = "ofVirtual", onlyWith = {JDK19OrLater.class, NotLoomJDK.class}) - public static Target_java_lang_Thread_Builder ofVirtualWithoutLoom() { + public static Target_java_lang_Thread_Builder_OfVirtual ofVirtualWithoutLoom() { if (Target_jdk_internal_misc_PreviewFeatures.isEnabled()) { if (DeoptimizationSupport.enabled()) { throw new UnsupportedOperationException("Virtual threads are not supported together with Truffle JIT compilation."); @@ -810,6 +810,10 @@ interface Target_java_lang_Thread_Builder { ThreadFactory factory(); } +@TargetClass(value = Thread.class, innerClass = {"Builder", "OfVirtual"}, onlyWith = JDK19OrLater.class) +interface Target_java_lang_Thread_Builder_OfVirtual { +} + @TargetClass(value = Thread.class, innerClass = "Constants", onlyWith = JDK19OrLater.class) final class Target_java_lang_Thread_Constants { // Checkstyle: stop diff --git a/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/NativeAPIImpl.java b/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/NativeAPIImpl.java index 2ac7856000e2..4df127809dd2 100644 --- a/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/NativeAPIImpl.java +++ b/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/NativeAPIImpl.java @@ -24,9 +24,6 @@ */ package com.oracle.svm.truffle.nfi; -import com.oracle.svm.core.c.CGlobalData; -import com.oracle.svm.core.c.CGlobalDataFactory; -import com.oracle.svm.core.c.function.CEntryPointErrors; import org.graalvm.nativeimage.ImageSingletons; import org.graalvm.nativeimage.c.function.CEntryPoint; import org.graalvm.nativeimage.c.function.CEntryPoint.Publish; @@ -36,7 +33,10 @@ import org.graalvm.word.WordFactory; import com.oracle.svm.core.Uninterruptible; +import com.oracle.svm.core.c.CGlobalData; +import com.oracle.svm.core.c.CGlobalDataFactory; import com.oracle.svm.core.c.function.CEntryPointActions; +import com.oracle.svm.core.c.function.CEntryPointErrors; import com.oracle.svm.core.c.function.CEntryPointOptions; import com.oracle.svm.core.c.function.CEntryPointOptions.ReturnNullPointer; import com.oracle.svm.core.c.function.CEntryPointSetup.LeaveDetachThreadEpilogue; @@ -53,7 +53,6 @@ import com.oracle.svm.truffle.nfi.NativeAPI.ReleaseAndReturnFunction; import com.oracle.svm.truffle.nfi.NativeAPI.ReleaseClosureRefFunction; import com.oracle.svm.truffle.nfi.NativeAPI.ReleaseObjectRefFunction; -import com.oracle.truffle.api.interop.TruffleObject; /** * Implementation of the TruffleEnv and TruffleContext native API functions. @@ -138,7 +137,7 @@ static void releaseClosureRef(NativeTruffleEnv env, PointerBase closure) { static TruffleObjectHandle getClosureObject(NativeTruffleEnv env, PointerBase closure) { TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class); Target_com_oracle_truffle_nfi_backend_libffi_LibFFIContext context = lookupContext(env.context()); - TruffleObject ret = context.getClosureObject(closure.rawValue()); + Object ret = context.getClosureObject(closure.rawValue()); return support.createGlobalHandle(ret); } diff --git a/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/Target_com_oracle_truffle_nfi_backend_libffi_LibFFIContext.java b/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/Target_com_oracle_truffle_nfi_backend_libffi_LibFFIContext.java index a8984b31eb53..b91301c8259e 100644 --- a/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/Target_com_oracle_truffle_nfi_backend_libffi_LibFFIContext.java +++ b/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/Target_com_oracle_truffle_nfi_backend_libffi_LibFFIContext.java @@ -49,7 +49,6 @@ import com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif; import com.oracle.truffle.api.CallTarget; import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary; -import com.oracle.truffle.api.interop.TruffleObject; @TargetClass(className = "com.oracle.truffle.nfi.backend.libffi.LibFFIContext", onlyWith = TruffleNFIFeature.IsEnabled.class) final class Target_com_oracle_truffle_nfi_backend_libffi_LibFFIContext { @@ -80,7 +79,7 @@ native Target_com_oracle_truffle_nfi_backend_libffi_ClosureNativePointer createC native void releaseClosureRef(long codePointer); @Alias - native TruffleObject getClosureObject(long codePointer); + native Object getClosureObject(long codePointer); @Alias protected native void initializeSimpleType(Target_com_oracle_truffle_nfi_backend_spi_types_NativeSimpleType simpleType, int size, int alignment, long ffiType); @@ -212,9 +211,7 @@ Object lookupSymbol(Target_com_oracle_truffle_nfi_backend_libffi_LibFFILibrary l if (ImageSingletons.lookup(TruffleNFISupport.class).errnoGetterFunctionName.equals(name)) { return new ErrnoMirror(); } else { - Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol ret = Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol.create(library, name, - lookup(nativeContext, library.handle, name)); - return ret; + return Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol.create(library, name, lookup(nativeContext, library.handle, name)); } } diff --git a/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol.java b/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol.java index 41cdb9a941ee..cb8089fe07dd 100644 --- a/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol.java +++ b/substratevm/src/com.oracle.svm.truffle.nfi/src/com/oracle/svm/truffle/nfi/Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol.java @@ -31,5 +31,5 @@ final class Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol { @Alias - static native Target_com_oracle_truffle_nfi_backend_libffi_LibFFISymbol create(Target_com_oracle_truffle_nfi_backend_libffi_LibFFILibrary library, String name, long address); + static native Object create(Target_com_oracle_truffle_nfi_backend_libffi_LibFFILibrary library, String name, long address); } diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java index 957bbdf32dfc..22e24ff7dbad 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleBaseFeature.java @@ -95,6 +95,7 @@ import com.oracle.svm.core.NeverInline; import com.oracle.svm.core.ParsingReason; import com.oracle.svm.core.RuntimeAssertionsSupport; +import com.oracle.svm.core.SubstrateUtil; import com.oracle.svm.core.annotate.Alias; import com.oracle.svm.core.annotate.AnnotateOriginal; import com.oracle.svm.core.annotate.Delete; @@ -1140,7 +1141,7 @@ final class Target_com_oracle_truffle_api_staticobject_PodBasedShapeGenerator @Substitute @SuppressWarnings("unchecked") - Target_com_oracle_truffle_api_staticobject_PodBasedStaticShape generateShape(Target_com_oracle_truffle_api_staticobject_PodBasedStaticShape parentShape, + StaticShape generateShape(Target_com_oracle_truffle_api_staticobject_PodBasedStaticShape parentShape, Map staticProperties, boolean safetyChecks) { Pod.Builder builder; if (parentShape == null) { @@ -1162,7 +1163,7 @@ Target_com_oracle_truffle_api_staticobject_PodBasedStaticShape generateShape( for (var entry : propertyFields) { entry.getLeft().initOffset(entry.getRight().getOffset()); } - return Target_com_oracle_truffle_api_staticobject_PodBasedStaticShape.create(storageSuperClass, pod.getFactory(), safetyChecks, pod); + return SubstrateUtil.cast(Target_com_oracle_truffle_api_staticobject_PodBasedStaticShape.create(storageSuperClass, pod.getFactory(), safetyChecks, pod), StaticShape.class); } } From d01ff88512e0bc6682cce1ef0912a2678f59c5e5 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Tue, 22 Aug 2023 09:24:35 +0200 Subject: [PATCH 3/7] svm: add DisableSubstitutionReturnTypeCheck option [GR-48152] --- .../src/com/oracle/svm/hosted/NativeImageOptions.java | 3 +++ .../svm/hosted/substitute/AnnotationSubstitutionProcessor.java | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java index fb38e70e3bbf..a46c03f0e023 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageOptions.java @@ -150,6 +150,9 @@ protected void onValueUpdate(EconomicMap, Object> values, Boolean o @Option(help = "Deprecated", type = User)// static final HostedOptionKey AllowIncompleteClasspath = new HostedOptionKey<>(false); + @Option(help = "Disable substitution return type checking", type = Debug, deprecated = true, stability = OptionStability.EXPERIMENTAL, deprecationMessage = "This option will be removed soon and the return type check will be mandatory.")// + public static final HostedOptionKey DisableSubstitutionReturnTypeCheck = new HostedOptionKey<>(false); + @SuppressWarnings("all") private static boolean areAssertionsEnabled() { boolean assertsEnabled = false; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java index 79dde3f49329..84310d0257f6 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java @@ -854,7 +854,8 @@ private ResolvedJavaMethod findOriginalMethod(Executable annotatedMethod, Class< Method originalMethod = originalClass.getDeclaredMethod(originalName, originalParams); guarantee(Modifier.isStatic(annotatedMethod.getModifiers()) == Modifier.isStatic(originalMethod.getModifiers()), "Static modifier mismatch: %s, %s", annotatedMethod, originalMethod); - guarantee(getTargetClass(((Method) annotatedMethod).getReturnType()).equals(originalMethod.getReturnType()), + + guarantee(NativeImageOptions.DisableSubstitutionReturnTypeCheck.getValue() || getTargetClass(((Method) annotatedMethod).getReturnType()).equals(originalMethod.getReturnType()), "Return type mismatch:%n %s%n %s", annotatedMethod, originalMethod); return metaAccess.lookupJavaMethod(originalMethod); From d37d4663a000cf8ee818db9470d65b147aa221b9 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 4 Sep 2023 12:32:20 +0200 Subject: [PATCH 4/7] svm: avoif SuppressFBWarnings in DynamicHub#isEnum --- .../src/com/oracle/svm/core/hub/DynamicHub.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java index 9c335571bb22..238a351ac3b1 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/DynamicHub.java @@ -786,13 +786,12 @@ private boolean isAnnotation() { } @Substitute - @SuppressFBWarnings(value = "EC_UNRELATED_TYPES_USING_POINTER_EQUALITY", justification = "Class is DynamicHub") private boolean isEnum() { /* * We do not do the check "this.getModifiers() & ENUM) != 0" because we do not have the full * modifier bits. */ - return (Object) this.getSuperclass() == java.lang.Enum.class; + return toClass(getSuperclass()) == java.lang.Enum.class; } @KeepOriginal From a2b770563b152bd618f0a648af5aead2807d0d13 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 4 Sep 2023 12:32:36 +0200 Subject: [PATCH 5/7] svm: make BoundMethodHandleUtils#make more readable --- .../Target_java_lang_invoke_BoundMethodHandle.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_BoundMethodHandle.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_BoundMethodHandle.java index c7db64d6199c..cde553877850 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_BoundMethodHandle.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/methodhandles/Target_java_lang_invoke_BoundMethodHandle.java @@ -152,8 +152,8 @@ final class BoundMethodHandleUtils { /* Bound method handle constructor */ static Target_java_lang_invoke_BoundMethodHandle make(MethodType type, Target_java_lang_invoke_LambdaForm form, String species, Object... args) { Target_java_lang_invoke_SimpleMethodHandle bmh = new Target_java_lang_invoke_SimpleMethodHandle(type, form); - bmh.speciesData = SubstrateUtil.cast(SubstrateUtil.cast(Target_java_lang_invoke_BoundMethodHandle.SPECIALIZER, Target_java_lang_invoke_ClassSpecializer.class).findSpecies(species), - Target_java_lang_invoke_BoundMethodHandle_SpeciesData.class); + var specializer = SubstrateUtil.cast(Target_java_lang_invoke_BoundMethodHandle.SPECIALIZER, Target_java_lang_invoke_ClassSpecializer.class); + bmh.speciesData = SubstrateUtil.cast(specializer.findSpecies(species), Target_java_lang_invoke_BoundMethodHandle_SpeciesData.class); bmh.args = (args != null) ? Arrays.copyOf(args, args.length) : new Object[0]; return SubstrateUtil.cast(bmh, Target_java_lang_invoke_BoundMethodHandle.class); } From d73a31055b9a6a63d257b1c67c52a52be1c30d20 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Mon, 4 Sep 2023 12:39:16 +0200 Subject: [PATCH 6/7] vm/ci: add DisableSubstitutionReturnTypeCheck option to quarkus benchmarks [GR-48152] --- java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py | 1 + 1 file changed, 1 insertion(+) diff --git a/java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py b/java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py index 0a75b6cb2d9f..a5ffcf16a7b1 100644 --- a/java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py +++ b/java-benchmarks/mx.java-benchmarks/mx_java_benchmarks.py @@ -375,6 +375,7 @@ def extra_image_build_argument(self, benchmark, args): '-H:+AllowFoldMethods', '-H:-UseServiceLoaderFeature', '-H:+AllowDeprecatedBuilderClassesOnImageClasspath', # needs to be removed once GR-41746 is fixed + '-H:+DisableSubstitutionReturnTypeCheck', # remove once Quarkus fixed their substitutions (GR-48152) ]) + super(BaseQuarkusBenchmarkSuite, self).extra_image_build_argument(benchmark, args) From bcf1261589338210f26d4e4f76d5a87562cea782 Mon Sep 17 00:00:00 2001 From: Josef Eisl Date: Wed, 6 Sep 2023 08:57:41 +0200 Subject: [PATCH 7/7] svm: fix Target_jdk_jfr_internal_JVM after rebase --- .../com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java index 896fa341cf48..38e483e3331b 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jfr/Target_jdk_jfr_internal_JVM.java @@ -335,7 +335,7 @@ public static long getTypeId(Class clazz) { /** See {@link JVM#getEventWriter}. */ @Substitute - public static Target_jdk_jfr_internal_EventWriter getEventWriter() { + public static Target_jdk_jfr_internal_event_EventWriter getEventWriter() { return SubstrateJVM.get().getEventWriter(); }