diff --git a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java index 98a5ec4ea37b..b46a471b8f24 100644 --- a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java +++ b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/CheckGraalInvariants.java @@ -47,6 +47,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import java.util.function.Supplier; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -69,11 +70,15 @@ import org.graalvm.compiler.graph.NodeClass; import org.graalvm.compiler.java.GraphBuilderPhase; import org.graalvm.compiler.nodeinfo.NodeInfo; +import org.graalvm.compiler.nodes.FrameState; import org.graalvm.compiler.nodes.PhiNode; import org.graalvm.compiler.nodes.StructuredGraph; import org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions; +import org.graalvm.compiler.nodes.ValueNode; +import org.graalvm.compiler.nodes.graphbuilderconf.ClassInitializationPlugin; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins; +import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; import org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins; import org.graalvm.compiler.nodes.java.LoadFieldNode; import org.graalvm.compiler.nodes.memory.MemoryKill; @@ -101,6 +106,8 @@ import jdk.vm.ci.code.BailoutException; import jdk.vm.ci.code.Register; import jdk.vm.ci.code.Register.RegisterCategory; +import jdk.vm.ci.hotspot.HotSpotConstantPool; +import jdk.vm.ci.meta.ConstantPool; import jdk.vm.ci.meta.JavaField; import jdk.vm.ci.meta.JavaMethod; import jdk.vm.ci.meta.JavaType; @@ -175,36 +182,9 @@ protected boolean shouldLoadClass(String className) { if (className.equals("module-info") || className.startsWith("META-INF.versions.")) { return false; } - // @formatter:off - /* - * Work around to prevent: - * - * org.graalvm.compiler.debug.GraalError: java.lang.IllegalAccessError: class org.graalvm.compiler.serviceprovider.GraalServices$Lazy (in module - * jdk.internal.vm.compiler) cannot access class java.lang.management.ManagementFactory (in module java.management) because module - * jdk.internal.vm.compiler does not read module java.management - * at jdk.internal.vm.compiler/org.graalvm.compiler.debug.GraalError.shouldNotReachHere(GraalError.java:55) - * at org.graalvm.compiler.core.test.CheckGraalInvariants$InvariantsTool.handleClassLoadingException(CheckGraalInvariants.java:149) - * at org.graalvm.compiler.core.test.CheckGraalInvariants.initializeClasses(CheckGraalInvariants.java:321) - * at org.graalvm.compiler.core.test.CheckGraalInvariants.runTest(CheckGraalInvariants.java:239) - * - * which occurs because JDK8 overlays are in modular jars. They are never used normally. - */ - // @formatter:on - if (className.equals("org.graalvm.compiler.serviceprovider.GraalServices$Lazy")) { - return false; - } - return true; } - protected void handleClassLoadingException(Throwable t) { - GraalError.shouldNotReachHere(t); - } - - protected void handleParsingException(Throwable t) { - GraalError.shouldNotReachHere(t); - } - public boolean shouldVerifyFoldableMethods() { return true; } @@ -260,6 +240,7 @@ public static void runTest(InvariantsTool tool) { PhaseSuite graphBuilderSuite = new PhaseSuite<>(); Plugins plugins = new Plugins(new InvocationPlugins()); + plugins.setClassInitializationPlugin(new DoNotInitializeClassInitializationPlugin()); GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true); graphBuilderSuite.appendPhase(new GraphBuilderPhase(config)); HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE); @@ -394,8 +375,7 @@ public static void runTest(InvariantsTool tool) { if (errors.isEmpty()) { // Order outer classes before the inner classes classNames.sort((String a, String b) -> a.compareTo(b)); - // Initialize classes in single thread to avoid deadlocking issues during initialization - List> classes = initializeClasses(tool, classNames); + List> classes = loadClasses(tool, classNames); for (Class c : classes) { String className = c.getName(); executor.execute(() -> { @@ -438,18 +418,12 @@ public static void runTest(InvariantsTool tool) { checkGraph(verifiers, context, graph); } catch (VerificationError e) { errors.add(e.getMessage()); - } catch (LinkageError e) { - // suppress linkages errors resulting from eager resolution } catch (BailoutException e) { // Graal bail outs on certain patterns in Java bytecode // (e.g., // unbalanced monitors introduced by jacoco). } catch (Throwable e) { - try { - tool.handleParsingException(e); - } catch (Throwable t) { - errors.add(String.format("Error while checking %s:%n%s", methodName, printStackTraceToString(e))); - } + errors.add(String.format("Error while checking %s:%n%s", methodName, printStackTraceToString(e))); } } }); @@ -560,27 +534,19 @@ private static boolean isGSON(String className) { return className.contains("com.google.gson"); } - private static List> initializeClasses(InvariantsTool tool, List classNames) { + private static List> loadClasses(InvariantsTool tool, List classNames) { List> classes = new ArrayList<>(classNames.size()); for (String className : classNames) { if (!tool.shouldLoadClass(className)) { continue; } try { - Class c = Class.forName(className, true, CheckGraalInvariants.class.getClassLoader()); + Class c = Class.forName(className, false, CheckGraalInvariants.class.getClassLoader()); classes.add(c); } catch (UnsupportedClassVersionError e) { // graal-test.jar can contain classes compiled for different Java versions - } catch (NoClassDefFoundError e) { - if (!e.getMessage().contains("Could not initialize class")) { - throw e; - } else { - // A second or later attempt to initialize a class - // results in this confusing error where the - // original cause of initialization failure is lost - } } catch (Throwable t) { - tool.handleClassLoadingException(t); + GraalError.shouldNotReachHere(t); } } return classes; @@ -761,3 +727,21 @@ boolean test21(ArithmeticOpTable.Op f) { } } } + +class DoNotInitializeClassInitializationPlugin implements ClassInitializationPlugin { + + @Override + public boolean supportsLazyInitialization(ConstantPool cp) { + return true; + } + + @Override + public void loadReferencedType(GraphBuilderContext builder, ConstantPool cp, int cpi, int bytecode) { + ((HotSpotConstantPool) cp).loadReferencedType(cpi, bytecode, false); + } + + @Override + public boolean apply(GraphBuilderContext builder, ResolvedJavaType type, Supplier frameState, ValueNode[] classInit) { + return false; + } +} diff --git a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyUsageWithEquals.java b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyUsageWithEquals.java index 29fee1d6138b..31a2e27ec497 100644 --- a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyUsageWithEquals.java +++ b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyUsageWithEquals.java @@ -149,8 +149,8 @@ protected void verify(StructuredGraph graph, CoreProviders context) { ResolvedJavaMethod method = graph.method(); ResolvedJavaType restrictedType = context.getMetaAccess().lookupJavaType(restrictedClass); - if (method.getDeclaringClass().equals(restrictedType)) { - // Allow violation in methods of the restricted type itself. + if (restrictedType.isAssignableFrom(method.getDeclaringClass())) { + // Allow violation in methods of the restricted type itself and its subclasses. } else if (isIllegalUsage(method, cn.getX(), cn.getY(), context.getMetaAccess()) || isIllegalUsage(method, cn.getY(), cn.getX(), context.getMetaAccess())) { throw new VerificationError("Verification of " + restrictedClass.getName() + " usage failed: Comparing " + cn.getX() + " and " + cn.getY() + " in " + method + " must use .equals() for object equality, not '==' or '!='"); diff --git a/substratevm/src/com.oracle.svm.agent/src/com/oracle/svm/agent/BreakpointInterceptor.java b/substratevm/src/com.oracle.svm.agent/src/com/oracle/svm/agent/BreakpointInterceptor.java index 3b91b2b29e10..25bfef809fc6 100644 --- a/substratevm/src/com.oracle.svm.agent/src/com/oracle/svm/agent/BreakpointInterceptor.java +++ b/substratevm/src/com.oracle.svm.agent/src/com/oracle/svm/agent/BreakpointInterceptor.java @@ -1571,7 +1571,7 @@ private static Breakpoint installBreakpoint(JNIEnvironment jni, BreakpointSpecif return null; } Breakpoint bp = new Breakpoint(br, clazz, method); - guarantee(map.put(method.rawValue(), bp) == null, "Duplicate breakpoint: " + bp); + guarantee(map.put(method.rawValue(), bp) == null, "Duplicate breakpoint: %s", bp); return bp; } diff --git a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapAllocator.java b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapAllocator.java index 6af9e4b41cd4..4902e85fd9cd 100644 --- a/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapAllocator.java +++ b/substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/ChunkedImageHeapAllocator.java @@ -97,7 +97,7 @@ final class AlignedChunk extends Chunk { public long allocate(ImageHeapObject obj, boolean writable) { long size = obj.getSize(); - VMError.guarantee(size <= getUnallocatedBytes(), "Object of size " + size + " does not fit in the chunk's remaining bytes"); + VMError.guarantee(size <= getUnallocatedBytes(), "Object of size %s does not fit in the chunk's remaining bytes", size); long objStart = getTop(); topOffset += size; objects.add(obj); @@ -226,7 +226,7 @@ public void alignInAlignedChunk(int multiple) { if (!currentAlignedChunk.tryAlignTop(multiple)) { startNewAlignedChunk(); boolean aligned = currentAlignedChunk.tryAlignTop(multiple); - VMError.guarantee(aligned, "Cannot align to " + multiple + " bytes within an aligned chunk's object area"); + VMError.guarantee(aligned, "Cannot align to %s bytes within an aligned chunk's object area", multiple); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/nodes/CEntryPointLeaveNode.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/nodes/CEntryPointLeaveNode.java index 94cc17944217..a29dfe103175 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/nodes/CEntryPointLeaveNode.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/nodes/CEntryPointLeaveNode.java @@ -146,9 +146,9 @@ private void anchorReturnValue() { int nodesAnchored = anchorNodes(this); if (leaveAction == LeaveAction.ExceptionAbort) { - VMError.guarantee(nodesAnchored == 0, "Unexpected values were anchored in method " + graph().method().format("%H.%n(%p)") + " as ExceptionAbort must not have any return value."); + VMError.guarantee(nodesAnchored == 0, "Unexpected values were anchored in method %s as ExceptionAbort must not have any return value.", graph().method()); } else { - VMError.guarantee(nodesAnchored == 1, "An unexpected number of values was anchored in method " + graph().method().format("%H.%n(%p)")); + VMError.guarantee(nodesAnchored == 1, "An unexpected number of values was anchored in method %s", graph().method()); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/NonSnippetLowerings.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/NonSnippetLowerings.java index 158c8f2ed9ea..0376cafe0223 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/NonSnippetLowerings.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/graal/snippets/NonSnippetLowerings.java @@ -211,7 +211,7 @@ private ForeignCallDescriptor lookupBytecodeException(BytecodeExceptionKind exce } outArguments.addAll(exceptionArguments); } - VMError.guarantee(descriptor != null, "No ForeignCallDescriptor for ByteCodeExceptionKind " + exceptionKind); + VMError.guarantee(descriptor != null, "No ForeignCallDescriptor for ByteCodeExceptionKind %s", exceptionKind); assert descriptor.getArgumentTypes().length == outArguments.size(); return descriptor; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/GCCause.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/GCCause.java index d0099aadbf42..a38de7d807ca 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/GCCause.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/GCCause.java @@ -66,7 +66,7 @@ private void addGCCauseMapping() { while (HostedGCCauseList.size() <= id) { HostedGCCauseList.add(null); } - VMError.guarantee(HostedGCCauseList.get(id) == null, name + " and another GCCause have the same id."); + VMError.guarantee(HostedGCCauseList.get(id) == null, "%s and another GCCause have the same id.", name); HostedGCCauseList.set(id, this); } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java index 2248631793a7..ff3b1e047625 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JNIRegistrationUtil.java @@ -74,7 +74,7 @@ protected static void rerunClassInit(FeatureAccess access, String... classNames) protected static Class clazz(FeatureAccess access, String className) { Class classByName = access.findClassByName(className); - VMError.guarantee(classByName != null, "class " + className + " not found"); + VMError.guarantee(classByName != null, "class %s not found", className); return classByName; } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetSubstitutions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetSubstitutions.java index 5c7eddb76a51..9dca4d5a5684 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetSubstitutions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/jdk/JavaNetSubstitutions.java @@ -141,7 +141,7 @@ public void duringSetup(DuringSetupAccess access) { JavaNetSubstitutions.defaultProtocols.forEach(protocol -> { if (!disabledURLProtocols.contains(protocol)) { boolean registered = JavaNetSubstitutions.addURLStreamHandler(protocol); - VMError.guarantee(registered, "The URL protocol " + protocol + " is not available."); + VMError.guarantee(registered, "The URL protocol %s is not available.", protocol); } }); @@ -155,7 +155,7 @@ public void duringSetup(DuringSetupAccess access) { "The option " + JavaNetSubstitutions.enableProtocolsOption + protocol + " is not needed."); } else if (JavaNetSubstitutions.onDemandProtocols.contains(protocol)) { boolean registered = JavaNetSubstitutions.addURLStreamHandler(protocol); - VMError.guarantee(registered, "The URL protocol " + protocol + " is not available."); + VMError.guarantee(registered, "The URL protocol %s is not available.", protocol); } else { printWarning("The URL protocol " + protocol + " is not tested and might not work as expected." + System.lineSeparator() + JavaNetSubstitutions.supportedProtocols()); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/snippets/SnippetRuntime.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/snippets/SnippetRuntime.java index f12e8ea9da49..380e0e1711e2 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/snippets/SnippetRuntime.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/snippets/SnippetRuntime.java @@ -75,7 +75,7 @@ private static SubstrateForeignCallDescriptor findForeignCall(String descriptorN LocationIdentity... additionalKilledLocations) { Method method = findMethod(declaringClass, methodName); SubstrateForeignCallTarget foreignCallTargetAnnotation = AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class); - VMError.guarantee(foreignCallTargetAnnotation != null, "Add missing @SubstrateForeignCallTarget to " + declaringClass.getName() + "." + methodName); + VMError.guarantee(foreignCallTargetAnnotation != null, "Add missing @SubstrateForeignCallTarget to %s.%s", declaringClass.getName(), methodName); boolean isUninterruptible = Uninterruptible.Utils.isUninterruptible(method); boolean isFullyUninterruptible = foreignCallTargetAnnotation.fullyUninterruptible(); @@ -86,7 +86,7 @@ private static SubstrateForeignCallDescriptor findForeignJdkCall(String descript boolean isFullyUninterruptible, LocationIdentity... additionalKilledLocations) { Method method = findMethod(declaringClass, methodName); SubstrateForeignCallTarget foreignCallTargetAnnotation = AnnotationAccess.getAnnotation(method, SubstrateForeignCallTarget.class); - VMError.guarantee(foreignCallTargetAnnotation == null, declaringClass.getName() + "." + methodName + " must not be annotated with @SubstrateForeignCallTarget."); + VMError.guarantee(foreignCallTargetAnnotation == null, "%s.%s must not be annotated with @SubstrateForeignCallTarget.", declaringClass.getName(), methodName); return findForeignCall(descriptorName, method, isReexecutable, isUninterruptible, isFullyUninterruptible, additionalKilledLocations); } @@ -100,7 +100,7 @@ private static SubstrateForeignCallDescriptor findForeignCall(String descriptorN */ LocationIdentity[] killedLocations; if (isFullyUninterruptible) { - VMError.guarantee(isUninterruptible, method.toString() + " is fully uninterruptible but not annotated with @Uninterruptible."); + VMError.guarantee(isUninterruptible, "%s is fully uninterruptible but not annotated with @Uninterruptible.", method); killedLocations = additionalKilledLocations; } else if (additionalKilledLocations.length == 0 || additionalKilledLocations == TLAB_LOCATIONS) { killedLocations = TLAB_LOCATIONS; diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java index 359c03d0aa29..42c9fcaf79a5 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/thread/PlatformThreads.java @@ -568,7 +568,7 @@ public void closeOSThreadHandle(OSThreadHandle threadHandle) { static final Method FORK_JOIN_POOL_TRY_TERMINATE_METHOD; static { - VMError.guarantee(ImageInfo.inImageBuildtimeCode(), PlatformThreads.class.getSimpleName() + " must be initialized at build time."); + VMError.guarantee(ImageInfo.inImageBuildtimeCode(), "PlatformThreads must be initialized at build time."); FORK_JOIN_POOL_TRY_TERMINATE_METHOD = ReflectionUtil.lookupMethod(ForkJoinPool.class, "tryTerminate", boolean.class, boolean.class); } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/UserError.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/UserError.java index a12f03ba01c8..f1be6bac1ab7 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/UserError.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/UserError.java @@ -113,21 +113,8 @@ public static void guarantee(boolean condition, String format, Object... args) { * @param args arguments to process * @return a copy of {@code args} with certain values converted to strings as described above */ - public static Object[] formatArguments(Object... args) { - Object[] newArgs = new Object[args.length]; - for (int i = 0; i < args.length; i++) { - Object arg = args[i]; - if (arg instanceof ResolvedJavaType) { - newArgs[i] = ((ResolvedJavaType) arg).toJavaName(true); - } else if (arg instanceof ResolvedJavaMethod) { - newArgs[i] = ((ResolvedJavaMethod) arg).format("%H.%n(%p)"); - } else if (arg instanceof ResolvedJavaField) { - newArgs[i] = ((ResolvedJavaField) arg).format("%H.%n"); - } else { - newArgs[i] = arg; - } - } - return newArgs; + static Object[] formatArguments(Object... args) { + return VMError.formatArguments(args); } /** diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java index 9adb60847d37..450f38a58e38 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/util/VMError.java @@ -29,6 +29,10 @@ import com.oracle.svm.core.Uninterruptible; +import jdk.vm.ci.meta.ResolvedJavaField; +import jdk.vm.ci.meta.ResolvedJavaMethod; +import jdk.vm.ci.meta.ResolvedJavaType; + /** * A collection of static methods for error reporting of fatal error. A fatal error leaves the VM in * an inconsistent state, so no meaningful recovery is possible. @@ -90,6 +94,40 @@ public static void guarantee(boolean condition, String msg) { } } + public static RuntimeException shouldNotReachHere(String msg, Object... args) { + throw shouldNotReachHere(String.format(msg, formatArguments(args))); + } + + public static void guarantee(boolean condition, String msg, Object arg1) { + if (!condition) { + throw shouldNotReachHere(msg, arg1); + } + } + + public static void guarantee(boolean condition, String msg, Object arg1, Object arg2) { + if (!condition) { + throw shouldNotReachHere(msg, arg1, arg2); + } + } + + public static void guarantee(boolean condition, String msg, Object arg1, Object arg2, Object arg3) { + if (!condition) { + throw shouldNotReachHere(msg, arg1, arg2, arg3); + } + } + + public static void guarantee(boolean condition, String msg, Object arg1, Object arg2, Object arg3, Object arg4) { + if (!condition) { + throw shouldNotReachHere(msg, arg1, arg2, arg3, arg4); + } + } + + public static void guarantee(boolean condition, String msg, Object arg1, Object arg2, Object arg3, Object arg4, Object arg5) { + if (!condition) { + throw shouldNotReachHere(msg, arg1, arg2, arg3, arg4, arg5); + } + } + public static RuntimeException unimplemented() { throw new UnsupportedOperationException("unimplemented"); } @@ -105,4 +143,36 @@ public static RuntimeException unsupportedFeature(String msg) { public static boolean hostedError(Throwable t) { return t instanceof HostedError; } + + /** + * Processes {@code args} to convert selected values to strings. + *
    + *
  • A {@link ResolvedJavaType} is converted with {@link ResolvedJavaType#toJavaName} + * {@code (true)}.
  • + *
  • A {@link ResolvedJavaMethod} is converted with {@link ResolvedJavaMethod#format} + * {@code ("%H.%n($p)")}.
  • + *
  • A {@link ResolvedJavaField} is converted with {@link ResolvedJavaField#format} + * {@code ("%H.%n")}.
  • + *
+ * All other values are copied to the returned array unmodified. + * + * @param args arguments to process + * @return a copy of {@code args} with certain values converted to strings as described above + */ + static Object[] formatArguments(Object... args) { + Object[] newArgs = new Object[args.length]; + for (int i = 0; i < args.length; i++) { + Object arg = args[i]; + if (arg instanceof ResolvedJavaType) { + newArgs[i] = ((ResolvedJavaType) arg).toJavaName(true); + } else if (arg instanceof ResolvedJavaMethod) { + newArgs[i] = ((ResolvedJavaMethod) arg).format("%H.%n(%p)"); + } else if (arg instanceof ResolvedJavaField) { + newArgs[i] = ((ResolvedJavaField) arg).format("%H.%n"); + } else { + newArgs[i] = arg; + } + } + return newArgs; + } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassPredefinitionFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassPredefinitionFeature.java index 78a76133518a..a2547d91af36 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassPredefinitionFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ClassPredefinitionFeature.java @@ -127,7 +127,7 @@ public void add(String nameInfo, String providedHash, URI baseUri) { } UserError.guarantee(!sealed, "Too late to add predefined classes. Registration must happen in a Feature before the analysis has started."); - VMError.guarantee(baseUri != null, "Cannot prepare class with hash " + providedHash + " for predefinition because its location is unknown"); + VMError.guarantee(baseUri != null, "Cannot prepare class with hash %s for predefinition because its location is unknown", providedHash); try { byte[] data; try (InputStream in = PredefinedClassesConfigurationParser.openClassdataStream(baseUri, providedHash)) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ExceptionSynthesizer.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ExceptionSynthesizer.java index b0a5342e2c2f..ad53c576f406 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ExceptionSynthesizer.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ExceptionSynthesizer.java @@ -101,7 +101,9 @@ private ExceptionSynthesizer() { public static Method throwExceptionMethod(Class... methodDescriptor) { Method method = throwExceptionMethodOrNull(methodDescriptor); - VMError.guarantee(method != null, "Exception synthesizer method " + Arrays.toString(methodDescriptor) + " not found."); + if (method == null) { + throw VMError.shouldNotReachHere("Exception synthesizer method " + Arrays.toString(methodDescriptor) + " not found."); + } return method; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java index 64e9b3e6ac73..6809fae5682a 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java @@ -1387,7 +1387,7 @@ private static boolean checkInvocationPluginMethods(SubstrateReplacements replac while (unwrapped instanceof WrappedJavaMethod) { unwrapped = ((WrappedJavaMethod) unwrapped).getWrapped(); } - if (method != unwrapped) { + if (!method.equals(unwrapped)) { String runtimeDescriptor = method.getSignature().toMethodDescriptor(); String hostedDescriptor = unwrapped.getSignature().toMethodDescriptor(); if (!runtimeDescriptor.equals(hostedDescriptor)) { @@ -1400,7 +1400,7 @@ private static boolean checkInvocationPluginMethods(SubstrateReplacements replac name, runtimeDescriptor, hostedDescriptor)); } } - assert method == unwrapped || method.getSignature().toMethodDescriptor().equals(unwrapped.getSignature().toMethodDescriptor()); + assert method.equals(unwrapped) || method.getSignature().toMethodDescriptor().equals(unwrapped.getSignature().toMethodDescriptor()); } return true; } @@ -1814,7 +1814,7 @@ private void printTypes() { } if (type.isInterface()) { for (HostedMethod method : hUniverse.getMethods()) { - if (method.getDeclaringClass() == type) { + if (method.getDeclaringClass().equals(type)) { printMethod(method, -1); } } @@ -1834,7 +1834,7 @@ private void printTypes() { } } for (HostedMethod method : hUniverse.getMethods()) { - if (method.getDeclaringClass() == type && !method.hasVTableIndex()) { + if (method.getDeclaringClass().equals(type) && !method.hasVTableIndex()) { printMethod(method, -1); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java index dd4f9dbf36cb..fffda847cc23 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGeneratorRunner.java @@ -101,7 +101,7 @@ protected void start(String[] args) { int watchPID = extractWatchPID(arguments); TimerTask timerTask = null; if (watchPID >= 0) { - VMError.guarantee(OS.getCurrent().hasProcFS, SubstrateOptions.WATCHPID_PREFIX + " requires system with /proc"); + UserError.guarantee(OS.getCurrent().hasProcFS, "%s requires system with /proc", SubstrateOptions.WATCHPID_PREFIX); timerTask = new TimerTask() { int cmdlineHashCode = 0; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ServiceLoaderFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ServiceLoaderFeature.java index ea99dbca8ea5..06b150233980 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ServiceLoaderFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ServiceLoaderFeature.java @@ -187,7 +187,7 @@ public void duringAnalysis(DuringAnalysisAccess a) { if (workDone) { DebugContext debugContext = access.getDebugContext(); try (DebugContext.Scope s = debugContext.scope("registerResource")) { - debugContext.log("Resources have been added by ServiceLoaderFeature. Automatic registration can be disabled with " + + debugContext.log("Resources have been added by ServiceLoaderFeature. Automatic registration can be disabled with %s", SubstrateOptionsParser.commandArgument(Options.UseServiceLoaderFeature, "-")); } } @@ -355,7 +355,7 @@ private boolean handleType(AnalysisType type, DuringAnalysisAccessImpl access) { DebugContext debugContext = access.getDebugContext(); try (DebugContext.Scope s = debugContext.scope("registerResource")) { - debugContext.log("ServiceLoaderFeature: registerResource: " + serviceResourceLocation); + debugContext.log("ServiceLoaderFeature: registerResource: %s", serviceResourceLocation); } Resources.registerResource(null, serviceResourceLocation, new ByteArrayInputStream(newResourceValue.toString().getBytes(StandardCharsets.UTF_8)), false); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/OffsetOfSupportImpl.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/OffsetOfSupportImpl.java index b85a8d0c67b6..8bd115b1d842 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/OffsetOfSupportImpl.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/OffsetOfSupportImpl.java @@ -49,7 +49,7 @@ public OffsetOfSupportImpl(NativeLibraries nativeLibraries, MetaAccessProvider m public int offsetOf(Class clazz, String fieldName) { ResolvedJavaType type = metaAccess.lookupJavaType(clazz); ElementInfo typeInfo = nativeLibraries.findElementInfo(type); - VMError.guarantee(typeInfo instanceof StructInfo, "Class parameter " + type.toJavaName(true) + " of call to " + SizeOf.class.getSimpleName() + " is not an annotated C struct"); + VMError.guarantee(typeInfo instanceof StructInfo, "Class parameter %s of call to %s is not an annotated C struct", type, SizeOf.class.getSimpleName()); StructInfo structInfo = (StructInfo) typeInfo; for (ElementInfo element : structInfo.getChildren()) { if (element instanceof StructFieldInfo) { @@ -59,6 +59,6 @@ public int offsetOf(Class clazz, String fieldName) { } } } - throw VMError.shouldNotReachHere("Field " + fieldName + " of C struct " + type.toJavaName(true) + " was not found"); + throw VMError.shouldNotReachHere("Field %s of C struct %s was not found", fieldName, type); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointCallStubMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointCallStubMethod.java index ff7f58711adc..3cd6b96f16be 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointCallStubMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CEntryPointCallStubMethod.java @@ -184,13 +184,13 @@ public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, InvokeWithExceptionNode invokeBailoutCustomizer = generatePrologueOrEpilogueInvoke(kit, bailoutMethods[0], invokePrologue); VMError.guarantee(bailoutMethods[0].getSignature().getReturnKind() == method.getSignature().getReturnKind(), - "Return type mismatch: " + bailoutMethods[0] + " is incompatible with " + targetMethod); + "Return type mismatch: %s is incompatible with %s", bailoutMethods[0], targetMethod); kit.createReturn(invokeBailoutCustomizer, targetMethod.getSignature().getReturnKind()); } kit.endIf(); } else { - VMError.guarantee(prologueReturnKind == JavaKind.Void, prologueMethod + " is a prologue method and must therefore either return int or void."); + VMError.guarantee(prologueReturnKind == JavaKind.Void, "%s is a prologue method and must therefore either return int or void.", prologueMethod); } } @@ -252,11 +252,11 @@ private StructuredGraph buildBuiltinGraph(DebugContext debug, ResolvedJavaMethod for (ResolvedJavaMethod candidate : metaAccess.lookupJavaType(CEntryPointBuiltins.class).getDeclaredMethods()) { CEntryPointBuiltinImplementation annotation = candidate.getAnnotation(CEntryPointBuiltinImplementation.class); if (annotation != null && annotation.builtin().equals(builtin)) { - VMError.guarantee(builtinCallee == null, "More than one candidate for @" + CEntryPoint.class.getSimpleName() + " built-in " + builtin); + VMError.guarantee(builtinCallee == null, "More than one candidate for @%s built-in %s", CEntryPoint.class.getSimpleName(), builtin); builtinCallee = candidate; } } - VMError.guarantee(builtinCallee != null, "No candidate for @" + CEntryPoint.class.getSimpleName() + " built-in " + builtin); + VMError.guarantee(builtinCallee != null, "No candidate for @%s built-in %s", CEntryPoint.class.getSimpleName(), builtin); ResolvedJavaType isolateType = providers.getMetaAccess().lookupJavaType(Isolate.class); ResolvedJavaType threadType = providers.getMetaAccess().lookupJavaType(IsolateThread.class); @@ -266,16 +266,16 @@ private StructuredGraph buildBuiltinGraph(DebugContext debug, ResolvedJavaMethod for (int i = 0; i < builtinParamTypes.length; i++) { ResolvedJavaType type = (ResolvedJavaType) builtinParamTypes[i]; if (isolateType.isAssignableFrom(type)) { - VMError.guarantee(builtinIsolateIndex == -1, "@" + CEntryPoint.class.getSimpleName() + " built-in with more than one " + - Isolate.class.getSimpleName() + " parameter: " + builtinCallee.format("%H.%n(%p)")); + VMError.guarantee(builtinIsolateIndex == -1, "@%s built-in with more than one %s parameter: %s", + CEntryPoint.class.getSimpleName(), Isolate.class.getSimpleName(), builtinCallee); builtinIsolateIndex = i; } else if (threadType.isAssignableFrom(type)) { - VMError.guarantee(builtinThreadIndex == -1, "@" + CEntryPoint.class.getSimpleName() + " built-in with more than one " + - IsolateThread.class.getSimpleName() + " parameter: " + builtinCallee.format("%H.%n(%p)")); + VMError.guarantee(builtinThreadIndex == -1, "@%s built-in with more than one %s parameter: %s", + CEntryPoint.class.getSimpleName(), IsolateThread.class.getSimpleName(), builtinCallee); builtinThreadIndex = i; } else { - VMError.shouldNotReachHere("@" + CEntryPoint.class.getSimpleName() + " built-in currently may have only " + Isolate.class.getSimpleName() + - " or " + IsolateThread.class.getSimpleName() + " parameters: " + builtinCallee.format("%H.%n(%p)")); + VMError.shouldNotReachHere("@%s built-in currently may have only %s or %s parameters: %s", + CEntryPoint.class.getSimpleName(), Isolate.class.getSimpleName(), IsolateThread.class.getSimpleName(), builtinCallee); } } @@ -284,15 +284,13 @@ private StructuredGraph buildBuiltinGraph(DebugContext debug, ResolvedJavaMethod ValueNode[] builtinArgs = new ValueNode[builtinParamTypes.length]; if (builtinIsolateIndex != -1) { VMError.guarantee(executionContext.designatedIsolateIndex != -1 || executionContext.isolateCount == 1, - "@" + CEntryPoint.class.getSimpleName() + " built-in " + entryPointData.getBuiltin() + " needs exactly one " + - Isolate.class.getSimpleName() + " parameter: " + builtinCallee.format("%H.%n(%p)")); + "@%s built-in %s needs exactly one %s parameter: %s", CEntryPoint.class.getSimpleName(), entryPointData.getBuiltin(), Isolate.class.getSimpleName(), builtinCallee); int index = (executionContext.designatedIsolateIndex != -1) ? executionContext.designatedIsolateIndex : executionContext.lastIsolateIndex; builtinArgs[builtinIsolateIndex] = args[index]; } if (builtinThreadIndex != -1) { VMError.guarantee(executionContext.designatedThreadIndex != -1 || executionContext.threadCount == 1, - "@" + CEntryPoint.class.getSimpleName() + " built-in " + entryPointData.getBuiltin() + " needs exactly one " + - IsolateThread.class.getSimpleName() + " parameter: " + builtinCallee.format("%H.%n(%p)")); + "@%s built-in %s needs exactly one %s parameter: %s", CEntryPoint.class.getSimpleName(), entryPointData.getBuiltin(), IsolateThread.class.getSimpleName(), builtinCallee); int index = (executionContext.designatedThreadIndex != -1) ? executionContext.designatedThreadIndex : executionContext.lastThreadIndex; builtinArgs[builtinThreadIndex] = args[index]; } @@ -401,7 +399,7 @@ private InvokeWithExceptionNode generatePrologue(HostedProviders providers, Subs } private static InvokeWithExceptionNode generatePrologueOrEpilogueInvoke(SubstrateGraphKit kit, ResolvedJavaMethod method, ValueNode... args) { - VMError.guarantee(Uninterruptible.Utils.isUninterruptible(method), "The method " + method + " must be uninterruptible as it is used for a prologue or epilogue."); + VMError.guarantee(Uninterruptible.Utils.isUninterruptible(method), "The method %s must be uninterruptible as it is used for a prologue or epilogue.", method); InvokeWithExceptionNode invoke = kit.startInvokeWithException(method, InvokeKind.Static, kit.getFrameState(), kit.bci(), args); kit.exceptionPart(); kit.append(new DeadEndNode()); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java index 6eb21aad8d85..11a46df9cd92 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/CompileQueue.java @@ -1161,7 +1161,7 @@ private CompilationResult defaultCompileFunction(DebugContext debug, HostedMetho try { SubstrateBackend backend = config.lookupBackend(method); - VMError.guarantee(method.compilationInfo.getCompilationGraph() != null, "The following method is reachable during compilation, but was not seen during Bytecode parsing: " + method); + VMError.guarantee(method.compilationInfo.getCompilationGraph() != null, "The following method is reachable during compilation, but was not seen during Bytecode parsing: %s", method); StructuredGraph graph = method.compilationInfo.createGraph(debug, compilationIdentifier, true); GraalError.guarantee(graph.getGraphState().getGuardsStage() == GuardsStage.FIXED_DEOPTS, diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/aarch64/AArch64HostedPatcherFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/aarch64/AArch64HostedPatcherFeature.java index f7fe795f6e90..88d6ec876475 100755 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/aarch64/AArch64HostedPatcherFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/aarch64/AArch64HostedPatcherFeature.java @@ -178,7 +178,7 @@ public void relocate(Reference ref, RelocatableBuffer relocs, int compStart) { if (constant instanceof SubstrateMethodPointerConstant) { MethodPointer pointer = ((SubstrateMethodPointerConstant) constant).pointer(); HostedMethod hMethod = (HostedMethod) pointer.getMethod(); - VMError.guarantee(hMethod.isCompiled(), String.format("Method %s is not compiled although there is a method pointer constant created for it.", hMethod.format("%H.%n"))); + VMError.guarantee(hMethod.isCompiled(), "Method %s is not compiled although there is a method pointer constant created for it.", hMethod); relocVal = pointer; } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/amd64/AMD64HostedPatcherFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/amd64/AMD64HostedPatcherFeature.java index 1ff7ee46ee87..6b341a19d53c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/amd64/AMD64HostedPatcherFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/amd64/AMD64HostedPatcherFeature.java @@ -128,7 +128,7 @@ public void relocate(Reference ref, RelocatableBuffer relocs, int compStart) { if (constant instanceof SubstrateMethodPointerConstant) { MethodPointer pointer = ((SubstrateMethodPointerConstant) constant).pointer(); HostedMethod hMethod = (HostedMethod) pointer.getMethod(); - VMError.guarantee(hMethod.isCompiled(), String.format("Method %s is not compiled although there is a method pointer constant created for it.", hMethod.format("%H.%n"))); + VMError.guarantee(hMethod.isCompiled(), "Method %s is not compiled although there is a method pointer constant created for it.", hMethod); relocVal = pointer; } relocs.addRelocationWithoutAddend((int) siteOffset, ObjectFile.RelocationKind.getDirect(annotation.operandSize), relocVal); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java index 74c6a0698225..c6f7a3c0f3df 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java @@ -91,7 +91,7 @@ protected Class getClass(String className) { @Override protected ImageHeapConstant getOrCreateConstantReachableTask(JavaConstant javaConstant, ScanReason reason, Consumer onAnalysisModified) { - VMError.guarantee(javaConstant instanceof TypedConstant, "Not a substrate constant " + javaConstant); + VMError.guarantee(javaConstant instanceof TypedConstant, "Not a substrate constant: %s", javaConstant); return super.getOrCreateConstantReachableTask(javaConstant, reason, onAnalysisModified); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageCodeCache.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageCodeCache.java index 1e42425986c8..5435da0b3bbe 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageCodeCache.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageCodeCache.java @@ -654,7 +654,7 @@ protected boolean isDeoptEntry(ResolvedJavaMethod method, CompilationResult comp /* * During call entrypoints must always be linked to a call. */ - VMError.guarantee(infopoint instanceof Call, String.format("Unexpected infopoint type: %s\nFrame: %s", infopoint, topFrame)); + VMError.guarantee(infopoint instanceof Call, "Unexpected infopoint type: %s%nFrame: %s", infopoint, topFrame); return compilation.isValidCallDeoptimizationState((Call) infopoint); } else { /* diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java index bd3eb5d5cba6..e51510595e50 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jdk/localization/LocalizationFeature.java @@ -252,12 +252,12 @@ public void afterRegistration(AfterRegistrationAccess access) { defaultLocale = LocalizationSupport.parseLocaleFromTag(Options.DefaultLocale.getValue()); UserError.guarantee(defaultLocale != null, "Invalid default locale %s", Options.DefaultLocale.getValue()); } + String defaultCharsetOptionValue = Options.DefaultCharset.getValue(); try { - defaultCharset = Charset.forName(Options.DefaultCharset.getValue()); - VMError.guarantee(defaultCharset.name().equals(Options.DefaultCharset.getValue()), - "Failed to locate charset " + Options.DefaultCharset.getValue() + ", instead " + defaultCharset.name() + " was provided"); + defaultCharset = Charset.forName(defaultCharsetOptionValue); + VMError.guarantee(defaultCharset.name().equals(defaultCharsetOptionValue), "Failed to locate charset %s, instead %s was provided", defaultCharsetOptionValue, defaultCharset.name()); } catch (IllegalCharsetNameException | UnsupportedCharsetException ex) { - throw UserError.abort(ex, "Invalid default charset %s", Options.DefaultCharset.getValue()); + throw UserError.abort(ex, "Invalid default charset %s", defaultCharsetOptionValue); } allLocales.add(defaultLocale); support = selectLocalizationSupport(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethod.java index 1678fb8aaffa..0213c9a1bd5a 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedMethod.java @@ -579,7 +579,7 @@ Pair createNames(Function> nameGen } boolean added = uniqueShortNames.add(result.getRight()); - VMError.guarantee(added, "failed to generate uniqueShortName for HostedMethod: " + result.getRight()); + VMError.guarantee(added, "failed to generate uniqueShortName for HostedMethod: %s", result.getRight()); return result; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedType.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedType.java index 6b4ba966abb6..b504327cba70 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedType.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedType.java @@ -319,12 +319,6 @@ public ResolvedJavaMethod resolveConcreteMethod(ResolvedJavaMethod m, ResolvedJa hResult = universe.lookup(aResult); } - /** - * Check that the SharedType implementation, which is used for JIT compilation, gives the - * same result as the hosted implementation. - */ - assert hResult == null || isWordType() || hResult.equals(SharedType.super.resolveConcreteMethod(method, callerType)); - return hResult; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedUniverse.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedUniverse.java index 2cd1d213e28c..29f50bb3132f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedUniverse.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedUniverse.java @@ -374,7 +374,7 @@ public HostedField optionalLookup(JavaField field) { private static void ensureOriginalMethod(JavaMethod method) { if (method instanceof MultiMethod) { MultiMethod.MultiMethodKey key = ((MultiMethod) method).getMultiMethodKey(); - VMError.guarantee(key == ORIGINAL_METHOD, "looking up method with wrong id: " + key); + VMError.guarantee(key == ORIGINAL_METHOD, "looking up method with wrong id: %s", key); } } @@ -472,21 +472,21 @@ public int compare(HostedType o1, HostedType o2) { if (!o1.getClass().equals(o2.getClass())) { int result = Integer.compare(ordinal(o1), ordinal(o2)); - VMError.guarantee(result != 0, "HostedType objects not distinguishable by ordinal number: " + o1 + ", " + o2); + VMError.guarantee(result != 0, "HostedType objects not distinguishable by ordinal number: %s, %s", o1, o2); return result; } if (o1.isPrimitive() && o2.isPrimitive()) { assert o1 instanceof HostedPrimitiveType && o2 instanceof HostedPrimitiveType; int result = o1.getJavaKind().compareTo(o2.getJavaKind()); - VMError.guarantee(result != 0, "HostedPrimitiveType objects not distinguishable by javaKind: " + o1 + ", " + o2); + VMError.guarantee(result != 0, "HostedPrimitiveType objects not distinguishable by javaKind: %s, %s", o1, o2); return result; } if (o1.isArray() && o2.isArray()) { assert o1 instanceof HostedArrayClass && o2 instanceof HostedArrayClass; int result = compare(o1.getComponentType(), o2.getComponentType()); - VMError.guarantee(result != 0, "HostedArrayClass objects not distinguishable by componentType: " + o1 + ", " + o2); + VMError.guarantee(result != 0, "HostedArrayClass objects not distinguishable by componentType: %s, %s", o1, o2); return result; } @@ -498,7 +498,7 @@ public int compare(HostedType o1, HostedType o2) { ClassLoader l1 = Optional.ofNullable(o1.getJavaClass()).map(Class::getClassLoader).orElse(null); ClassLoader l2 = Optional.ofNullable(o2.getJavaClass()).map(Class::getClassLoader).orElse(null); result = SubstrateUtil.classLoaderNameAndId(l1).compareTo(SubstrateUtil.classLoaderNameAndId(l2)); - VMError.guarantee(result != 0, "HostedType objects not distinguishable by name and classloader: " + o1 + ", " + o2); + VMError.guarantee(result != 0, "HostedType objects not distinguishable by name and classloader: %s, %s", o1, o2); return result; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/ComputedValueField.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/ComputedValueField.java index c1f056b387e3..56c96b23c597 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/ComputedValueField.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/ComputedValueField.java @@ -485,7 +485,7 @@ private JavaConstant translateFieldOffset(MetaAccessProvider metaAccess, JavaCon long fieldOffset = Unsafe.getUnsafe().objectFieldOffset(f); if (fieldOffset == searchOffset) { HostedField sf = (HostedField) metaAccess.lookupJavaField(f); - guarantee(sf.isAccessed() && sf.getLocation() > 0, "Field not marked as accessed: " + sf.format("%H.%n")); + guarantee(sf.isAccessed() && sf.getLocation() > 0, "Field not marked as accessed: %s", sf); return JavaConstant.forLong(sf.getLocation()); } } diff --git a/substratevm/src/com.oracle.svm.jvmtiagentbase/src/com/oracle/svm/jvmtiagentbase/Support.java b/substratevm/src/com.oracle.svm.jvmtiagentbase/src/com/oracle/svm/jvmtiagentbase/Support.java index 5c2aa03112b6..75ed3398a2f8 100644 --- a/substratevm/src/com.oracle.svm.jvmtiagentbase/src/com/oracle/svm/jvmtiagentbase/Support.java +++ b/substratevm/src/com.oracle.svm.jvmtiagentbase/src/com/oracle/svm/jvmtiagentbase/Support.java @@ -446,7 +446,7 @@ public static void checkNoException(JNIEnvironment localEnv) { } public static void check(JvmtiError resultCode) { - guarantee(resultCode.equals(JvmtiError.JVMTI_ERROR_NONE), "JVMTI call failed with " + resultCode.name()); + guarantee(resultCode.equals(JvmtiError.JVMTI_ERROR_NONE), "JVMTI call failed with %s", resultCode); } public static void checkPhase(JvmtiError resultCode) throws WrongPhaseException { diff --git a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java index b6adf26da148..4d8deec0b0e3 100644 --- a/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java +++ b/substratevm/src/com.oracle.svm.truffle/src/com/oracle/svm/truffle/TruffleFeature.java @@ -554,7 +554,7 @@ boolean isBlocklisted(ResolvedJavaMethod method) { boolean isTargetBlocklisted(ResolvedJavaMethod target, ResolvedJavaMethod implementation) { boolean blocklisted = !((AnalysisMethod) target).allowRuntimeCompilation() || blocklistMethods.contains(target); - if (blocklisted && implementation != target && implementationOnlyBlocklist.contains(target)) { + if (blocklisted && !implementation.equals(target) && implementationOnlyBlocklist.contains(target)) { blocklisted = isBlocklisted(implementation); } @@ -887,7 +887,7 @@ public void beforeCompilation(BeforeCompilationAccess config) { Frame.class.getTypeName(), SubstrateOptionsParser.commandArgument(Options.TruffleCheckFrameImplementation, "-"), implementations.stream().map(m -> m.toJavaName(true)).collect(Collectors.joining(", "))); } else { - assert implementations.size() == 0 || implementations.iterator().next() == frameType.getSingleImplementor(); + assert implementations.size() == 0 || implementations.iterator().next().equals(frameType.getSingleImplementor()); } } }