From 1ffdb08e472dadefff2db4c8e30b0619cd3ea99a Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Tue, 17 Jan 2023 14:22:22 -0800 Subject: [PATCH 1/4] Check Graal invariants also in pointsto project --- .../org/graalvm/compiler/core/test/VerifyDebugUsage.java | 1 + .../com/oracle/graal/pointsto/flow/MethodFlowsGraph.java | 2 +- .../src/com/oracle/graal/pointsto/flow/MethodTypeFlow.java | 2 +- .../oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java | 2 +- .../oracle/graal/pointsto/heap/HeapSnapshotVerifier.java | 2 +- .../com/oracle/graal/pointsto/heap/ImageHeapScanner.java | 6 +++--- 6 files changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsage.java b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsage.java index 0f6cb9b8e083..a3bc8c0f91c3 100644 --- a/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsage.java +++ b/compiler/src/org.graalvm.compiler.core.test/src/org/graalvm/compiler/core/test/VerifyDebugUsage.java @@ -121,6 +121,7 @@ protected void verify(StructuredGraph graph, CoreProviders context) { "org.graalvm.compiler.core.test.VerifyDebugUsageTest$InvalidConcatDumpUsagePhase.run", "org.graalvm.compiler.core.test.VerifyDebugUsageTest$InvalidDumpUsagePhase.run", "org.graalvm.compiler.hotspot.SymbolicSnippetEncoder.verifySnippetEncodeDecode", + "com.oracle.graal.pointsto.phases.InlineBeforeAnalysis.decodeGraph", "org.graalvm.compiler.truffle.compiler.phases.inlining.CallTree.dumpBasic")); /** diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodFlowsGraph.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodFlowsGraph.java index 2388293618f2..962e3a3ccbb9 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodFlowsGraph.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodFlowsGraph.java @@ -182,7 +182,7 @@ private synchronized void linearizeGraph(boolean isRedo) { int slotNum = flow.getSlot(); if (slotNum != -1) { assert flow instanceof FormalParamTypeFlow || flow instanceof FormalReturnTypeFlow : "Unexpected flow " + flow; - AnalysisError.guarantee(isRedo && flow.getSlot() == resultFlows.size(), "Flow already discovered: " + flow); + AnalysisError.guarantee(isRedo && flow.getSlot() == resultFlows.size(), "Flow already discovered: %s", flow); } else { flow.setSlot(resultFlows.size()); } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlow.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlow.java index 90eea115cfc1..1aa8efde45e0 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlow.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlow.java @@ -158,7 +158,7 @@ public void ensureFlowsGraphCreated(PointsToAnalysis bb, InvokeTypeFlow reason) private synchronized void createFlowsGraph(PointsToAnalysis bb, InvokeTypeFlow reason) { if (flowsGraph == null) { AnalysisError.guarantee(reason == null || reason.getSource() == null || - !reason.getSource().getMethod().equals(method), "Parsing reason cannot be in the target method itself " + method.format("%H.%n")); + !reason.getSource().getMethod().equals(method), "Parsing reason cannot be in the target method itself: %s", method); parsingReason = reason; try { diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java index 7fe8081bec29..fa20b6f108ab 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/flow/MethodTypeFlowBuilder.java @@ -453,7 +453,7 @@ private void insertPlaceholderParamAndReturnFlows() { AnalysisType paramType = (AnalysisType) paramTypes[index]; FormalParamTypeFlow parameter; if (!isStatic && index == 0) { - assert paramType == method.getDeclaringClass(); + assert paramType.equals(method.getDeclaringClass()); parameter = new FormalReceiverTypeFlow(position, paramType); } else { parameter = new FormalParamTypeFlow(position, paramType, index); diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/HeapSnapshotVerifier.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/HeapSnapshotVerifier.java index 28f6a09c7269..548aa82d7cd6 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/HeapSnapshotVerifier.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/HeapSnapshotVerifier.java @@ -298,7 +298,7 @@ private void ensureTypeScanned(JavaConstant typeConstant, AnalysisType type, Sca @SuppressWarnings({"unchecked", "rawtypes"}) private void ensureTypeScanned(JavaConstant value, JavaConstant typeConstant, AnalysisType type, ScanReason reason) { - AnalysisError.guarantee(type.isReachable(), "The heap snapshot verifier discovered a type not marked as reachable " + type.toJavaName()); + AnalysisError.guarantee(type.isReachable(), "The heap snapshot verifier discovered a type not marked as reachable: %s", type); Object task = imageHeap.getTask(typeConstant); /* Make sure the DynamicHub value is scanned. */ if (task == null) { diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapScanner.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapScanner.java index 7a60ee977423..e84035f7c2b2 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapScanner.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapScanner.java @@ -435,14 +435,14 @@ JavaConstant onFieldValueReachable(AnalysisField field, ImageHeapInstance receiv } JavaConstant onFieldValueReachable(AnalysisField field, ImageHeapInstance receiver, ValueSupplier rawValue, ScanReason reason, Consumer onAnalysisModified) { - AnalysisError.guarantee(field.isReachable(), "Field value is only reachable when field is reachable " + field.format("%H.%n")); + AnalysisError.guarantee(field.isReachable(), "Field value is only reachable when field is reachable: %s", field); /* * Check if the field value is available. If not, trying to access it is an error. This * forces the callers to only trigger the execution of the future task when the value is * ready to be materialized. */ - AnalysisError.guarantee(rawValue.isAvailable(), "Value not yet available for " + field.format("%H.%n")); + AnalysisError.guarantee(rawValue.isAvailable(), "Value not yet available for %s", field); JavaConstant transformedValue; try { @@ -544,7 +544,7 @@ public boolean isValueAvailable(@SuppressWarnings("unused") AnalysisField field) @SuppressWarnings({"unchecked", "rawtypes"}) private void snapshotFieldValue(AnalysisField field, Object fieldTask) { if (fieldTask instanceof AnalysisFuture) { - AnalysisError.guarantee(field.isReachable(), "Field value snapshot computed for field not reachable " + field.format("%H.%n")); + AnalysisError.guarantee(field.isReachable(), "Field value snapshot computed for field not reachable: %s", field); postTask((AnalysisFuture) fieldTask); } } From f5981d22d1a2af6a335624f0cda1fa32532fa17b Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Tue, 17 Jan 2023 15:27:40 -0800 Subject: [PATCH 2/4] Avoid converting methods/fields/types to String --- .../graal/pointsto/meta/AnalysisMethod.java | 6 +-- .../graal/pointsto/meta/AnalysisType.java | 8 +-- .../pointsto/results/StrengthenGraphs.java | 7 +-- .../svm/hosted/c/info/InfoTreeVisitor.java | 14 ++++- .../oracle/svm/hosted/code/CompileQueue.java | 2 +- .../phases/SubstrateGraphBuilderPhase.java | 4 +- .../UnsafeAutomaticSubstitutionProcessor.java | 51 ++++++++++--------- 7 files changed, 53 insertions(+), 39 deletions(-) diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java index 2d64cf32b8ed..ea00cfbb7fa9 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java @@ -348,7 +348,7 @@ public boolean registerAsImplementationInvoked(Object reason) { * the method as invoked, it would have an unwanted side effect, where this method could * return before the class gets marked as reachable. */ - getDeclaringClass().registerAsReachable("declared method " + this.format("%H.%n(%p)") + " is registered as implementation invoked"); + getDeclaringClass().registerAsReachable("declared method " + qualifiedName + " is registered as implementation invoked"); return AtomicUtils.atomicSetAndRun(this, reason, isImplementationInvokedUpdater, this::onReachable); } @@ -387,7 +387,7 @@ public boolean isIntrinsicMethod() { * as in {@link AnalysisMethod#registerAsImplementationInvoked(Object)}. */ public boolean registerAsVirtualRootMethod() { - getDeclaringClass().registerAsReachable("declared method " + this.format("%H.%n(%p)") + " is registered as virtual root"); + getDeclaringClass().registerAsReachable("declared method " + qualifiedName + " is registered as virtual root"); return AtomicUtils.atomicMark(this, isVirtualRootMethodUpdater); } @@ -395,7 +395,7 @@ public boolean registerAsVirtualRootMethod() { * Registers this method as a direct (special or static) root for the analysis. */ public boolean registerAsDirectRootMethod() { - getDeclaringClass().registerAsReachable("declared method " + this.format("%H.%n(%p)") + " is registered as direct root"); + getDeclaringClass().registerAsReachable("declared method " + qualifiedName + " is registered as direct root"); return AtomicUtils.atomicMark(this, isDirectRootMethodUpdater); } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java index 9e4fe89e971a..74f88aae4cff 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java @@ -1124,11 +1124,11 @@ private AnalysisField[] initializeInstanceFields(boolean includeSuperclasses) { return result; } - private AnalysisField[] convertFields(ResolvedJavaField[] original, List list, boolean listIncludesSuperClassesFields) { - for (int i = 0; i < original.length; i++) { - if (!original[i].isInternal()) { + private AnalysisField[] convertFields(ResolvedJavaField[] originals, List list, boolean listIncludesSuperClassesFields) { + for (ResolvedJavaField original : originals) { + if (!original.isInternal() && universe.hostVM.platformSupported(original)) { try { - AnalysisField aField = universe.lookup(original[i]); + AnalysisField aField = universe.lookup(original); if (aField != null) { if (listIncludesSuperClassesFields || aField.isStatic()) { /* diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java index 6a080f212838..f3b965048dff 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java @@ -530,8 +530,8 @@ private void unreachableInvoke(Invoke invoke, SimplifierTool tool) { InliningUtil.nonNullReceiver(invoke); } - makeUnreachable(invoke.asFixedNode(), tool, () -> "method " + graph.method().format("%H.%n(%p)") + ", node " + invoke + - ": empty list of callees for call to " + invoke.callTarget().targetMethod().format("%H.%n(%P)")); + makeUnreachable(invoke.asFixedNode(), tool, () -> "method " + ((AnalysisMethod) graph.method()).getQualifiedName() + ", node " + invoke + + ": empty list of callees for call to " + ((AnalysisMethod) invoke.callTarget().targetMethod()).getQualifiedName()); } /** @@ -675,7 +675,8 @@ private Object strengthenStampFromTypeFlow(ValueNode node, TypeFlow nodeFlow, if (typeStateTypes.size() == 0) { if (nonNull) { - makeUnreachable(anchorPoint.next(), tool, () -> "method " + graph.method().format("%H.%n(%p)") + ", node " + node + ": empty stamp when strengthening oldStamp " + oldStamp); + makeUnreachable(anchorPoint.next(), tool, + () -> "method " + ((AnalysisMethod) graph.method()).getQualifiedName() + ", node " + node + ": empty stamp when strengthening oldStamp " + oldStamp); return null; } else { return StampFactory.alwaysNull(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/info/InfoTreeVisitor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/info/InfoTreeVisitor.java index f4ee75c71ff8..68e15c2fa498 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/info/InfoTreeVisitor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/c/info/InfoTreeVisitor.java @@ -28,6 +28,8 @@ import java.util.Comparator; import java.util.List; +import com.oracle.graal.pointsto.meta.AnalysisMethod; +import com.oracle.graal.pointsto.meta.AnalysisType; import com.oracle.svm.core.util.UserError; public abstract class InfoTreeVisitor { @@ -48,7 +50,17 @@ public abstract class InfoTreeVisitor { /* Defining the comparator chain on multiple lines requires less type annotations. */ Comparator classNameComparator = Comparator.comparing(e -> e.getClass().getName()); Comparator nameComparator = classNameComparator.thenComparing(e -> e.getName()); - elementInfoComparator = nameComparator.thenComparing(e -> e.getAnnotatedElement().toString()); + elementInfoComparator = nameComparator.thenComparing(e -> asString(e.getAnnotatedElement())); + } + + private static String asString(Object annotatedElement) { + if (annotatedElement instanceof AnalysisMethod) { + return ((AnalysisMethod) annotatedElement).getQualifiedName(); + } else if (annotatedElement instanceof AnalysisType) { + return ((AnalysisType) annotatedElement).getName(); + } else { + return annotatedElement.toString(); + } } protected final void processChildren(ElementInfo info) { 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 62b26abd3f14..f6cee933eba7 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 @@ -1196,7 +1196,7 @@ private CompilationResult defaultCompileFunction(DebugContext debug, HostedMetho Suites suites = method.isDeoptTarget() ? deoptTargetSuites : regularSuites; LIRSuites lirSuites = method.isDeoptTarget() ? deoptTargetLIRSuites : regularLIRSuites; - CompilationResult result = backend.newCompilationResult(compilationIdentifier, method.format("%H.%n(%p)")); + CompilationResult result = backend.newCompilationResult(compilationIdentifier, method.getQualifiedName()); try (Indent indent = debug.logAndIndent("compile %s", method); DebugCloseable l = graph.getOptimizationLog().listen(new StableMethodNameFormatter(graph, backend.getProviders()))) { GraalCompiler.compileGraph(graph, method, backend.getProviders(), backend, null, getOptimisticOpts(), method.getProfilingInfo(), suites, lirSuites, result, diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SubstrateGraphBuilderPhase.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SubstrateGraphBuilderPhase.java index bc9967895c0b..c32756e8785a 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SubstrateGraphBuilderPhase.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SubstrateGraphBuilderPhase.java @@ -36,7 +36,6 @@ import org.graalvm.compiler.word.WordTypes; import com.oracle.graal.pointsto.meta.AnalysisMethod; -import com.oracle.graal.pointsto.meta.AnalysisType; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -68,7 +67,8 @@ protected InlineInfo tryInline(ValueNode[] args, ResolvedJavaMethod targetMethod * InvocationPlugins.resolvedRegistrations map reachable from * SubstrateReplacements.snippetInvocationPlugins. */ - ((AnalysisType) targetMethod.getDeclaringClass()).registerAsReachable("declared method " + targetMethod.format("%H.%n(%p)") + " is inlined"); + AnalysisMethod aTargetMethod = (AnalysisMethod) targetMethod; + aTargetMethod.getDeclaringClass().registerAsReachable("declared method " + aTargetMethod.getQualifiedName() + " is inlined"); } return inlineInfo; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java index 2b0fee132b98..a4a9f4ea5807 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/UnsafeAutomaticSubstitutionProcessor.java @@ -423,7 +423,7 @@ public void computeSubstitutions(SVMHost hostVM, ResolvedJavaType hostType) { * static final long fieldOffset = Unsafe.getUnsafe().staticFieldBase(X.class.getDeclaredField("f")); */ private void processUnsafeFieldComputation(ResolvedJavaType type, Invoke invoke, Kind kind) { - List unsuccessfulReasons = new ArrayList<>(); + List> unsuccessfulReasons = new ArrayList<>(); Class targetFieldHolder = null; String targetFieldName = null; @@ -438,7 +438,7 @@ private void processUnsafeFieldComputation(ResolvedJavaType type, Invoke invoke, targetFieldName = targetField.getName(); } } else { - unsuccessfulReasons.add("The argument of " + methodFormat + " is not a constant value or a field load that can be constant-folded."); + unsuccessfulReasons.add(() -> "The argument of " + methodFormat + " is not a constant value or a field load that can be constant-folded."); } processUnsafeFieldComputation(type, invoke, kind, unsuccessfulReasons, targetFieldHolder, targetFieldName); } @@ -473,9 +473,9 @@ private JavaConstant nodeAsConstant(ValueNode node) { return null; } - private boolean isValidField(Invoke invoke, Field field, List unsuccessfulReasons, String methodFormat) { + private boolean isValidField(Invoke invoke, Field field, List> unsuccessfulReasons, String methodFormat) { if (field == null) { - unsuccessfulReasons.add("The argument of " + methodFormat + " is a null constant."); + unsuccessfulReasons.add(() -> "The argument of " + methodFormat + " is a null constant."); return false; } @@ -483,11 +483,11 @@ private boolean isValidField(Invoke invoke, Field field, List unsuccessf if (JavaVersionUtil.JAVA_SPEC >= 17 && isInvokeTo(invoke, sunMiscUnsafeObjectFieldOffsetMethod)) { Class declaringClass = field.getDeclaringClass(); if (RecordSupport.singleton().isRecord(declaringClass)) { - unsuccessfulReasons.add("The argument to " + methodFormat + " is a field of a record."); + unsuccessfulReasons.add(() -> "The argument to " + methodFormat + " is a field of a record."); valid = false; } if (SubstrateUtil.isHiddenClass(declaringClass)) { - unsuccessfulReasons.add("The argument to " + methodFormat + " is a field of a hidden class."); + unsuccessfulReasons.add(() -> "The argument to " + methodFormat + " is a field of a hidden class."); valid = false; } } @@ -501,7 +501,7 @@ private boolean isValidField(Invoke invoke, Field field, List unsuccessf * static final long fieldOffset = Unsafe.getUnsafe().objectFieldOffset(X.class, "f"); */ private void processUnsafeObjectFieldOffsetClassStringInvoke(ResolvedJavaType type, Invoke unsafeObjectFieldOffsetInvoke) { - List unsuccessfulReasons = new ArrayList<>(); + List> unsuccessfulReasons = new ArrayList<>(); Class targetFieldHolder = null; String targetFieldName = null; @@ -510,29 +510,29 @@ private void processUnsafeObjectFieldOffsetClassStringInvoke(ResolvedJavaType ty if (classArgument.isConstant()) { Class clazz = snippetReflection.asObject(Class.class, classArgument.asJavaConstant()); if (clazz == null) { - unsuccessfulReasons.add("The Class argument of Unsafe.objectFieldOffset(Class, String) is a null constant."); + unsuccessfulReasons.add(() -> "The Class argument of Unsafe.objectFieldOffset(Class, String) is a null constant."); } else { targetFieldHolder = clazz; } } else { - unsuccessfulReasons.add("The Class argument of Unsafe.objectFieldOffset(Class, String) is not a constant class."); + unsuccessfulReasons.add(() -> "The Class argument of Unsafe.objectFieldOffset(Class, String) is not a constant class."); } ValueNode nameArgument = unsafeObjectFieldOffsetInvoke.callTarget().arguments().get(2); if (nameArgument.isConstant()) { String fieldName = snippetReflection.asObject(String.class, nameArgument.asJavaConstant()); if (fieldName == null) { - unsuccessfulReasons.add("The String argument of Unsafe.objectFieldOffset(Class, String) is a null String."); + unsuccessfulReasons.add(() -> "The String argument of Unsafe.objectFieldOffset(Class, String) is a null String."); } else { targetFieldName = fieldName; } } else { - unsuccessfulReasons.add("The name argument of Unsafe.objectFieldOffset(Class, String) is not a constant String."); + unsuccessfulReasons.add(() -> "The name argument of Unsafe.objectFieldOffset(Class, String) is not a constant String."); } processUnsafeFieldComputation(type, unsafeObjectFieldOffsetInvoke, FieldOffset, unsuccessfulReasons, targetFieldHolder, targetFieldName); } - private void processUnsafeFieldComputation(ResolvedJavaType type, Invoke invoke, Kind kind, List unsuccessfulReasons, Class targetFieldHolder, String targetFieldName) { + private void processUnsafeFieldComputation(ResolvedJavaType type, Invoke invoke, Kind kind, List> unsuccessfulReasons, Class targetFieldHolder, String targetFieldName) { assert kind == FieldOffset || kind == StaticFieldBase; /* * If the value returned by the call to Unsafe.objectFieldOffset() is stored into a field @@ -569,7 +569,7 @@ private void processUnsafeFieldComputation(ResolvedJavaType type, Invoke invoke, private void processUnsafeArrayBaseOffsetInvoke(ResolvedJavaType type, Invoke unsafeArrayBaseOffsetInvoke) { SnippetReflectionProvider snippetReflectionProvider = GraalAccess.getOriginalSnippetReflection(); - List unsuccessfulReasons = new ArrayList<>(); + List> unsuccessfulReasons = new ArrayList<>(); Class arrayClass = null; @@ -577,7 +577,7 @@ private void processUnsafeArrayBaseOffsetInvoke(ResolvedJavaType type, Invoke un if (arrayClassArgument.isJavaConstant()) { arrayClass = snippetReflectionProvider.asObject(Class.class, arrayClassArgument.asJavaConstant()); } else { - unsuccessfulReasons.add("The argument of the call to Unsafe.arrayBaseOffset() is not a constant."); + unsuccessfulReasons.add(() -> "The argument of the call to Unsafe.arrayBaseOffset() is not a constant."); } /* @@ -610,7 +610,7 @@ private void processUnsafeArrayBaseOffsetInvoke(ResolvedJavaType type, Invoke un private void processUnsafeArrayIndexScaleInvoke(ResolvedJavaType type, Invoke unsafeArrayIndexScale, StructuredGraph clinitGraph) { SnippetReflectionProvider snippetReflectionProvider = GraalAccess.getOriginalSnippetReflection(); - List unsuccessfulReasons = new ArrayList<>(); + List> unsuccessfulReasons = new ArrayList<>(); Class arrayClass = null; @@ -618,7 +618,7 @@ private void processUnsafeArrayIndexScaleInvoke(ResolvedJavaType type, Invoke un if (arrayClassArgument.isJavaConstant()) { arrayClass = snippetReflectionProvider.asObject(Class.class, arrayClassArgument.asJavaConstant()); } else { - unsuccessfulReasons.add("The argument of the call to Unsafe.arrayIndexScale() is not a constant."); + unsuccessfulReasons.add(() -> "The argument of the call to Unsafe.arrayIndexScale() is not a constant."); } /* @@ -732,7 +732,7 @@ private boolean processArrayIndexShift(ResolvedJavaType type, Class arrayClas SearchResult result = null; ResolvedJavaField indexShiftField = null; - List unsuccessfulReasons = new ArrayList<>(); + List> unsuccessfulReasons = new ArrayList<>(); Invoke numberOfLeadingZerosInvoke = methodCallTarget.invoke(); NodeIterable numberOfLeadingZerosInvokeSubUsages = numberOfLeadingZerosInvoke.asNode().usages().filter(SubNode.class); if (numberOfLeadingZerosInvokeSubUsages.count() == 1) { @@ -745,10 +745,10 @@ private boolean processArrayIndexShift(ResolvedJavaType type, Class arrayClas result = extractValueStoreField(subNode, ArrayIndexShift, unsuccessfulReasons); indexShiftField = result.valueStoreField; } else { - unsuccessfulReasons.add("The index array scale value provided by " + indexScaleValue + " is not used to calculate the array index shift."); + unsuccessfulReasons.add(() -> "The index array scale value provided by " + indexScaleValue + " is not used to calculate the array index shift."); } } else { - unsuccessfulReasons.add("The call to " + methodCallTarget.targetMethod().format("%H.%n(%p)") + " has multiple uses."); + unsuccessfulReasons.add(() -> "The call to " + methodCallTarget.targetMethod().format("%H.%n(%p)") + " has multiple uses."); } if (indexShiftField != null) { @@ -838,7 +838,7 @@ static SearchResult didNotFindIllegalUse() { * returned. If the field is either not static or not final the method returns null and the * reason is recorded in the unsuccessfulReasons parameter. */ - private static SearchResult extractValueStoreField(ValueNode valueNode, Kind substitutionKind, List unsuccessfulReasons) { + private static SearchResult extractValueStoreField(ValueNode valueNode, Kind substitutionKind, List> unsuccessfulReasons) { ResolvedJavaField valueStoreField = null; boolean illegalUseFound = false; @@ -874,8 +874,9 @@ private static SearchResult extractValueStoreField(ValueNode valueNode, Kind sub /* Success! We found the static final field where this value is stored. */ return SearchResult.foundField(valueStoreField); } else { - String message = "The field " + valueStoreField.format("%H.%n") + ", where the value produced by the " + kindAsString(substitutionKind) + - " computation is stored, is not" + (!valueStoreField.isStatic() ? " static" : "") + (!valueStoreField.isFinal() ? " final" : "") + "."; + ResolvedJavaField valueStoreFieldFinal = valueStoreField; + Supplier message = () -> "The field " + valueStoreFieldFinal.format("%H.%n") + ", where the value produced by the " + kindAsString(substitutionKind) + + " computation is stored, is not" + (!valueStoreFieldFinal.isStatic() ? " static" : "") + (!valueStoreFieldFinal.isFinal() ? " final" : "") + "."; unsuccessfulReasons.add(message); /* Value is stored to a non static final field. */ return SearchResult.foundIllegalUse(); @@ -896,7 +897,7 @@ private static SearchResult extractValueStoreField(ValueNode valueNode, Kind sub } else { throw VMError.shouldNotReachHere(); } - String message = "Could not determine the field where the value produced by the " + producer + + Supplier message = () -> "Could not determine the field where the value produced by the " + producer + " for the " + kindAsString(substitutionKind) + " computation is stored. The " + operation + " is not directly followed by a field store or by a sign extend node followed directly by a field store. "; unsuccessfulReasons.add(message); @@ -1078,7 +1079,7 @@ private static void reportSkippedSubstitution(ResolvedJavaField field, Kind subs } } - private void reportUnsuccessfulAutomaticRecomputation(ResolvedJavaType type, ResolvedJavaField computedField, Invoke invoke, Kind substitutionKind, List reasons) { + private void reportUnsuccessfulAutomaticRecomputation(ResolvedJavaType type, ResolvedJavaField computedField, Invoke invoke, Kind substitutionKind, List> reasons) { String msg = ""; if (Options.UnsafeAutomaticSubstitutionsLogLevel.getValue() >= BASIC_LEVEL) { if (!suppressWarningsFor(type) || Options.UnsafeAutomaticSubstitutionsLogLevel.getValue() >= DEBUG_LEVEL) { @@ -1097,7 +1098,7 @@ private void reportUnsuccessfulAutomaticRecomputation(ResolvedJavaType type, Res /* If the computed field is null then reasons will contain the details. */ msg += "Add a " + substitutionKindStr + " manual substitution for " + computedField.format("%H.%n") + ". "; } - msg += "Detailed failure reason(s): " + reasons.stream().collect(Collectors.joining(", ")); + msg += "Detailed failure reason(s): " + reasons.stream().map(s -> s.get()).collect(Collectors.joining(", ")); } } From b321c4c80a652ada79a05b4a5a8bfbc97a327569 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Tue, 17 Jan 2023 15:54:09 -0800 Subject: [PATCH 3/4] GraalAccess.getOriginalSnippetReflectionProvider does not need to be passed methods around or cached in fields --- .../graal/pointsto/standalone/PointsToAnalyzer.java | 2 +- .../infrastructure/OriginalClassProvider.java | 6 +++--- .../infrastructure/OriginalFieldProvider.java | 6 +++--- .../infrastructure/OriginalMethodProvider.java | 6 +++--- .../oracle/graal/pointsto/meta/AnalysisField.java | 2 +- .../oracle/graal/pointsto/meta/AnalysisMethod.java | 2 +- .../oracle/graal/pointsto/meta/AnalysisType.java | 2 +- .../graal/pointsto/meta/AnalysisUniverse.java | 13 ++++--------- .../com/oracle/svm/hosted/HostedConfiguration.java | 4 ++-- .../com/oracle/svm/hosted/NativeImageGenerator.java | 6 +++--- .../src/com/oracle/svm/hosted/SVMHost.java | 9 +++------ .../svm/hosted/SubstitutionReportFeature.java | 5 ++--- .../svm/hosted/annotation/AnnotationSupport.java | 3 +-- .../ConstantAnnotationMarkerSubstitutionType.java | 3 +-- .../hosted/annotation/CustomSubstitutionMethod.java | 3 +-- .../hosted/annotation/CustomSubstitutionType.java | 3 +-- .../annotation/SubstrateAnnotationExtractor.java | 7 +++---- .../ClassInitializationSupport.java | 3 +-- .../EarlyClassInitializerAnalysis.java | 2 +- .../oracle/svm/hosted/jfr/JfrEventSubstitution.java | 3 +-- .../svm/hosted/lambda/LambdaSubstitutionType.java | 3 +-- .../src/com/oracle/svm/hosted/meta/HostedField.java | 2 +- .../com/oracle/svm/hosted/meta/HostedMethod.java | 2 +- .../src/com/oracle/svm/hosted/meta/HostedType.java | 2 +- .../phases/EarlyConstantFoldLoadFieldPlugin.java | 8 ++------ .../IntrinsifyMethodHandlesInvocationPlugin.java | 4 ++-- .../svm/hosted/phases/SharedGraphBuilderPhase.java | 7 +++---- .../svm/hosted/snippets/ReflectionPlugins.java | 5 ++--- .../svm/hosted/substitute/AnnotatedField.java | 2 +- .../svm/hosted/substitute/AnnotatedMethod.java | 3 +-- .../svm/hosted/substitute/ComputedValueField.java | 2 +- .../svm/hosted/substitute/InjectedFieldsType.java | 3 +-- .../svm/hosted/substitute/SubstitutionField.java | 2 +- .../svm/hosted/substitute/SubstitutionMethod.java | 3 +-- .../svm/hosted/substitute/SubstitutionType.java | 3 +-- .../com/oracle/svm/truffle/TruffleBaseFeature.java | 3 +-- 36 files changed, 58 insertions(+), 86 deletions(-) diff --git a/substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java b/substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java index 339e2927d5f4..bd76a4ce8959 100644 --- a/substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java +++ b/substratevm/src/com.oracle.graal.pointsto.standalone/src/com/oracle/graal/pointsto/standalone/PointsToAnalyzer.java @@ -135,7 +135,7 @@ private PointsToAnalyzer(String mainEntryClass, OptionValues options) { JavaKind wordKind = JavaKind.fromWordSize(wordSize); AnalysisUniverse aUniverse = new AnalysisUniverse(standaloneHost, wordKind, - analysisPolicy, SubstitutionProcessor.IDENTITY, originalMetaAccess, snippetReflection, snippetReflection, new PointsToAnalysisFactory(), null); + analysisPolicy, SubstitutionProcessor.IDENTITY, originalMetaAccess, snippetReflection, new PointsToAnalysisFactory(), null); AnalysisMetaAccess aMetaAccess = new AnalysisMetaAccess(aUniverse, originalMetaAccess); StandaloneConstantReflectionProvider aConstantReflection = new StandaloneConstantReflectionProvider(aUniverse, HotSpotJVMCIRuntime.runtime()); StandaloneConstantFieldProvider aConstantFieldProvider = new StandaloneConstantFieldProvider(aMetaAccess); diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalClassProvider.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalClassProvider.java index 25f4ab632e3c..0ab1fa98113d 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalClassProvider.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalClassProvider.java @@ -24,17 +24,17 @@ */ package com.oracle.graal.pointsto.infrastructure; -import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; +import com.oracle.graal.pointsto.util.GraalAccess; import jdk.vm.ci.meta.ResolvedJavaType; public interface OriginalClassProvider { - static Class getJavaClass(SnippetReflectionProvider reflectionProvider, ResolvedJavaType javaType) { + static Class getJavaClass(ResolvedJavaType javaType) { if (javaType instanceof OriginalClassProvider) { return ((OriginalClassProvider) javaType).getJavaClass(); } else { - return reflectionProvider.originalClass(javaType); + return GraalAccess.getOriginalSnippetReflection().originalClass(javaType); } } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalFieldProvider.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalFieldProvider.java index 7b2ff5b3dfab..af61a8a685eb 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalFieldProvider.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalFieldProvider.java @@ -26,17 +26,17 @@ import java.lang.reflect.Field; -import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; +import com.oracle.graal.pointsto.util.GraalAccess; import jdk.vm.ci.meta.ResolvedJavaField; public interface OriginalFieldProvider { - static Field getJavaField(SnippetReflectionProvider reflectionProvider, ResolvedJavaField field) { + static Field getJavaField(ResolvedJavaField field) { if (field instanceof OriginalFieldProvider) { return ((OriginalFieldProvider) field).getJavaField(); } else { - return reflectionProvider.originalField(field); + return GraalAccess.getOriginalSnippetReflection().originalField(field); } } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalMethodProvider.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalMethodProvider.java index 51d444062f95..123cd9c9bcd9 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalMethodProvider.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/OriginalMethodProvider.java @@ -26,17 +26,17 @@ import java.lang.reflect.Executable; -import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; +import com.oracle.graal.pointsto.util.GraalAccess; import jdk.vm.ci.meta.ResolvedJavaMethod; public interface OriginalMethodProvider { - static Executable getJavaMethod(SnippetReflectionProvider reflectionProvider, ResolvedJavaMethod method) { + static Executable getJavaMethod(ResolvedJavaMethod method) { if (method instanceof OriginalMethodProvider) { return ((OriginalMethodProvider) method).getJavaMethod(); } else { - return reflectionProvider.originalMethod(method); + return GraalAccess.getOriginalSnippetReflection().originalMethod(method); } } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisField.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisField.java index bb83eb936e73..ca5ea8bbaac9 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisField.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisField.java @@ -530,7 +530,7 @@ public boolean isUsedInComparison() { @Override public Field getJavaField() { - return OriginalFieldProvider.getJavaField(getUniverse().getOriginalSnippetReflection(), wrapped); + return OriginalFieldProvider.getJavaField(wrapped); } public void addAnalysisFieldObserver(AnalysisFieldObserver observer) { diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java index ea00cfbb7fa9..3d2437fa16f2 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java @@ -730,7 +730,7 @@ public boolean equals(Object obj) { @Override public Executable getJavaMethod() { - return OriginalMethodProvider.getJavaMethod(getUniverse().getOriginalSnippetReflection(), wrapped); + return OriginalMethodProvider.getJavaMethod(wrapped); } /** diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java index 74f88aae4cff..f4ea19cf6988 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java @@ -854,7 +854,7 @@ public ResolvedJavaType getWrappedWithoutResolve() { @Override public Class getJavaClass() { - return OriginalClassProvider.getJavaClass(universe.getOriginalSnippetReflection(), wrapped); + return OriginalClassProvider.getJavaClass(wrapped); } @Override diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java index 602ada76a42a..444ecba09dd5 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java @@ -59,6 +59,7 @@ import com.oracle.graal.pointsto.meta.AnalysisType.UsageKind; import com.oracle.graal.pointsto.util.AnalysisError; import com.oracle.graal.pointsto.util.AnalysisFuture; +import com.oracle.graal.pointsto.util.GraalAccess; import jdk.vm.ci.code.BytecodePosition; import jdk.vm.ci.common.JVMCIError; @@ -113,7 +114,6 @@ public class AnalysisUniverse implements Universe { private SubstitutionProcessor[] featureNativeSubstitutions; private final MetaAccessProvider originalMetaAccess; - private final SnippetReflectionProvider originalSnippetReflection; private final SnippetReflectionProvider snippetReflection; private final AnalysisFactory analysisFactory; private final AnnotationExtractor annotationExtractor; @@ -135,13 +135,12 @@ public JavaKind getWordKind() { @SuppressWarnings("unchecked") public AnalysisUniverse(HostVM hostVM, JavaKind wordKind, AnalysisPolicy analysisPolicy, SubstitutionProcessor substitutions, MetaAccessProvider originalMetaAccess, - SnippetReflectionProvider originalSnippetReflection, SnippetReflectionProvider snippetReflection, AnalysisFactory analysisFactory, AnnotationExtractor annotationExtractor) { + SnippetReflectionProvider snippetReflection, AnalysisFactory analysisFactory, AnnotationExtractor annotationExtractor) { this.hostVM = hostVM; this.wordKind = wordKind; this.analysisPolicy = analysisPolicy; this.substitutions = substitutions; this.originalMetaAccess = originalMetaAccess; - this.originalSnippetReflection = originalSnippetReflection; this.snippetReflection = snippetReflection; this.analysisFactory = analysisFactory; this.annotationExtractor = annotationExtractor; @@ -505,7 +504,7 @@ public JavaConstant lookup(JavaConstant constant) { if (constant == null) { return null; } else if (constant.getJavaKind().isObject() && !constant.isNull()) { - Object original = originalSnippetReflection.asObject(Object.class, constant); + Object original = GraalAccess.getOriginalSnippetReflection().asObject(Object.class, constant); if (original instanceof ImageHeapConstant) { /* * The value is an ImageHeapObject, i.e., it already has a build time @@ -526,7 +525,7 @@ public JavaConstant toHosted(JavaConstant constant) { if (constant == null) { return null; } else if (constant.getJavaKind().isObject() && !constant.isNull()) { - return originalSnippetReflection.forObject(snippetReflection.asObject(Object.class, constant)); + return GraalAccess.getOriginalSnippetReflection().forObject(snippetReflection.asObject(Object.class, constant)); } else { return constant; } @@ -683,10 +682,6 @@ public SnippetReflectionProvider getSnippetReflection() { return snippetReflection; } - public SnippetReflectionProvider getOriginalSnippetReflection() { - return originalSnippetReflection; - } - @Override public ResolvedJavaMethod resolveSubstitution(ResolvedJavaMethod method) { return substitutions.resolve(method); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HostedConfiguration.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HostedConfiguration.java index 233b0af0fe71..e6fdddaf8205 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HostedConfiguration.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/HostedConfiguration.java @@ -144,8 +144,8 @@ public static ObjectLayout createObjectLayout(JavaKind referenceKind) { } public SVMHost createHostVM(OptionValues options, ClassLoader classLoader, ClassInitializationSupport classInitializationSupport, - UnsafeAutomaticSubstitutionProcessor automaticSubstitutions, Platform platform, SnippetReflectionProvider originalSnippetReflection) { - return new SVMHost(options, classLoader, classInitializationSupport, automaticSubstitutions, platform, originalSnippetReflection); + UnsafeAutomaticSubstitutionProcessor automaticSubstitutions, Platform platform) { + return new SVMHost(options, classLoader, classInitializationSupport, automaticSubstitutions, platform); } public CompileQueue createCompileQueue(DebugContext debug, FeatureHandler featureHandler, HostedUniverse hostedUniverse, 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 f71c712f7332..f7140e96ae2b 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 @@ -998,7 +998,7 @@ public static AnalysisUniverse createAnalysisUniverse(OptionValues options, Targ SubstitutionProcessor aSubstitutions = createAnalysisSubstitutionProcessor(originalMetaAccess, originalSnippetReflection, cEnumProcessor, automaticSubstitutions, annotationSubstitutions, additionalSubstitutions); - SVMHost hostVM = HostedConfiguration.instance().createHostVM(options, loader.getClassLoader(), classInitializationSupport, automaticSubstitutions, loader.platform, originalSnippetReflection); + SVMHost hostVM = HostedConfiguration.instance().createHostVM(options, loader.getClassLoader(), classInitializationSupport, automaticSubstitutions, loader.platform); automaticSubstitutions.init(loader, originalMetaAccess); AnalysisPolicy analysisPolicy = PointstoOptions.AllocationSiteSensitiveHeap.getValue(options) ? new BytecodeSensitiveAnalysisPolicy(options) @@ -1009,7 +1009,7 @@ public static AnalysisUniverse createAnalysisUniverse(OptionValues options, Targ } else { analysisFactory = new PointsToAnalysisFactory(); } - return new AnalysisUniverse(hostVM, target.wordJavaKind, analysisPolicy, aSubstitutions, originalMetaAccess, originalSnippetReflection, + return new AnalysisUniverse(hostVM, target.wordJavaKind, analysisPolicy, aSubstitutions, originalMetaAccess, new SubstrateSnippetReflectionProvider(new SubstrateWordTypes(originalMetaAccess, FrameAccess.getWordKind())), analysisFactory, loader.classLoaderSupport.annotationExtractor); } @@ -1282,7 +1282,7 @@ public static void registerGraphBuilderPlugins(FeatureHandler featureHandler, Ru plugins.appendNodePlugin(new IntrinsifyMethodHandlesInvocationPlugin(reason, providers, aUniverse, hUniverse)); plugins.appendNodePlugin(new DeletedFieldsPlugin()); plugins.appendNodePlugin(new InjectedAccessorsPlugin()); - plugins.appendNodePlugin(new EarlyConstantFoldLoadFieldPlugin(providers.getMetaAccess(), providers.getSnippetReflection())); + plugins.appendNodePlugin(new EarlyConstantFoldLoadFieldPlugin(providers.getMetaAccess())); plugins.appendNodePlugin(new ConstantFoldLoadFieldPlugin(reason)); plugins.appendNodePlugin(new CInterfaceInvocationPlugin(providers.getMetaAccess(), providers.getWordTypes(), nativeLibs)); plugins.appendNodePlugin(new LocalizationFeature.CharsetNodePlugin()); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java index e0a03705aa0f..619803e28a6c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SVMHost.java @@ -46,7 +46,6 @@ import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.BiPredicate; -import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; import org.graalvm.compiler.core.common.spi.ForeignCallDescriptor; import org.graalvm.compiler.core.common.spi.ForeignCallsProvider; import org.graalvm.compiler.debug.MethodFilter; @@ -146,7 +145,6 @@ public class SVMHost extends HostVM { private final LinkAtBuildTimeSupport linkAtBuildTimeSupport; private final HostedStringDeduplication stringTable; private final UnsafeAutomaticSubstitutionProcessor automaticSubstitutions; - private final SnippetReflectionProvider originalSnippetReflection; /** * Optionally keep the Graal graphs alive during analysis. This increases the memory footprint @@ -166,10 +164,9 @@ public class SVMHost extends HostVM { private final Set finalFieldsInitializedOutsideOfConstructor = ConcurrentHashMap.newKeySet(); public SVMHost(OptionValues options, ClassLoader classLoader, ClassInitializationSupport classInitializationSupport, - UnsafeAutomaticSubstitutionProcessor automaticSubstitutions, Platform platform, SnippetReflectionProvider originalSnippetReflection) { + UnsafeAutomaticSubstitutionProcessor automaticSubstitutions, Platform platform) { super(options, classLoader); this.classInitializationSupport = classInitializationSupport; - this.originalSnippetReflection = originalSnippetReflection; this.stringTable = HostedStringDeduplication.singleton(); this.forbiddenTypes = setupForbiddenTypes(options); this.automaticSubstitutions = automaticSubstitutions; @@ -519,7 +516,7 @@ private static ReferenceType computeReferenceType(AnalysisType type) { @Override public void checkType(ResolvedJavaType type, AnalysisUniverse universe) { - Class originalClass = OriginalClassProvider.getJavaClass(originalSnippetReflection, type); + Class originalClass = OriginalClassProvider.getJavaClass(type); ClassLoader originalClassLoader = originalClass.getClassLoader(); if (NativeImageSystemClassLoader.singleton().isDisallowedClassLoader(originalClassLoader)) { String message = "Class " + originalClass.getName() + " was loaded by " + originalClassLoader + " and not by the current image class loader " + classLoader + ". "; @@ -745,7 +742,7 @@ public boolean skipInterface(AnalysisUniverse universe, ResolvedJavaType interfa @Override public boolean platformSupported(AnnotatedElement element) { if (element instanceof ResolvedJavaType) { - Package p = OriginalClassProvider.getJavaClass(originalSnippetReflection, (ResolvedJavaType) element).getPackage(); + Package p = OriginalClassProvider.getJavaClass((ResolvedJavaType) element).getPackage(); if (p != null && !platformSupported(p)) { return false; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstitutionReportFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstitutionReportFeature.java index e50bd780f9f7..b6cf469d9ba3 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstitutionReportFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstitutionReportFeature.java @@ -37,11 +37,10 @@ import com.oracle.graal.pointsto.meta.AnalysisMethod; import com.oracle.graal.pointsto.meta.AnalysisType; import com.oracle.graal.pointsto.reports.ReportUtils; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.SubstrateOptions; +import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; import com.oracle.svm.core.option.HostedOptionKey; -import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.hosted.substitute.SubstitutionField; import com.oracle.svm.hosted.substitute.SubstitutionMethod; import com.oracle.svm.hosted.substitute.SubstitutionType; @@ -147,7 +146,7 @@ private static String formatField(ResolvedJavaField field) { } private static String getTypeClassFileLocation(ResolvedJavaType type) { - Class annotatedClass = OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), type); + Class annotatedClass = OriginalClassProvider.getJavaClass(type); CodeSource source = annotatedClass.getProtectionDomain().getCodeSource(); return source == null ? "unknown" : source.getLocation().toString(); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSupport.java index 019ae1dc9508..17216027d79f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/AnnotationSupport.java @@ -64,7 +64,6 @@ import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException; import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.meta.HostedProviders; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.SubstrateAnnotationInvocationHandler; import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature; import com.oracle.svm.core.feature.InternalFeature; @@ -605,7 +604,7 @@ public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, } private static Class getJavaClass(ResolvedJavaType type) { - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), type); + return OriginalClassProvider.getJavaClass(type); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/ConstantAnnotationMarkerSubstitutionType.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/ConstantAnnotationMarkerSubstitutionType.java index 1d568e8f8aa2..6c6c00b0a3fe 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/ConstantAnnotationMarkerSubstitutionType.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/ConstantAnnotationMarkerSubstitutionType.java @@ -28,7 +28,6 @@ import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor; -import com.oracle.graal.pointsto.util.GraalAccess; import jdk.vm.ci.meta.Assumptions; import jdk.vm.ci.meta.JavaConstant; @@ -70,7 +69,7 @@ public boolean isAssignableFrom(ResolvedJavaType other) { @Override public Class getJavaClass() { - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalClassProvider.getJavaClass(original); } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/CustomSubstitutionMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/CustomSubstitutionMethod.java index 1835db16b855..ec3b8fa48ef1 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/CustomSubstitutionMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/CustomSubstitutionMethod.java @@ -33,7 +33,6 @@ import com.oracle.graal.pointsto.infrastructure.GraphProvider; import com.oracle.graal.pointsto.infrastructure.OriginalMethodProvider; -import com.oracle.graal.pointsto.util.GraalAccess; import jdk.vm.ci.meta.Constant; import jdk.vm.ci.meta.ConstantPool; @@ -235,6 +234,6 @@ public SpeculationLog getSpeculationLog() { @Override public Executable getJavaMethod() { - return OriginalMethodProvider.getJavaMethod(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalMethodProvider.getJavaMethod(original); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/CustomSubstitutionType.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/CustomSubstitutionType.java index 2a4ed74943e2..a356e1a68da8 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/CustomSubstitutionType.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/CustomSubstitutionType.java @@ -31,7 +31,6 @@ import java.util.Map; import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; -import com.oracle.graal.pointsto.util.GraalAccess; import jdk.vm.ci.common.JVMCIError; import jdk.vm.ci.meta.Assumptions.AssumptionResult; @@ -289,7 +288,7 @@ public ResolvedJavaType getHostClass() { @Override public Class getJavaClass() { - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalClassProvider.getJavaClass(original); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java index 5d598299f4e8..0d62cb19bae0 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java @@ -49,7 +49,6 @@ import com.oracle.graal.pointsto.infrastructure.OriginalFieldProvider; import com.oracle.graal.pointsto.infrastructure.OriginalMethodProvider; import com.oracle.graal.pointsto.infrastructure.WrappedElement; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.hosted.annotation.AnnotationMetadata.AnnotationExtractionError; import com.oracle.svm.util.ReflectionUtil; @@ -449,11 +448,11 @@ private static AnnotatedElement findRoot(AnnotatedElement element) { assert !(element instanceof WrappedElement || element instanceof AnnotationWrapper); try { if (element instanceof ResolvedJavaType) { - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), (ResolvedJavaType) element); + return OriginalClassProvider.getJavaClass((ResolvedJavaType) element); } else if (element instanceof ResolvedJavaMethod) { - return OriginalMethodProvider.getJavaMethod(GraalAccess.getOriginalSnippetReflection(), (ResolvedJavaMethod) element); + return OriginalMethodProvider.getJavaMethod((ResolvedJavaMethod) element); } else if (element instanceof ResolvedJavaField) { - return OriginalFieldProvider.getJavaField(GraalAccess.getOriginalSnippetReflection(), (ResolvedJavaField) element); + return OriginalFieldProvider.getJavaField((ResolvedJavaField) element); } else if (element instanceof Package) { return (Class) packageGetPackageInfo.invoke(element); } else { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationSupport.java index d51e413e946f..406be2ad4968 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/ClassInitializationSupport.java @@ -43,7 +43,6 @@ import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; import com.oracle.graal.pointsto.meta.AnalysisUniverse; import com.oracle.graal.pointsto.reports.ReportUtils; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.option.LocatableMultiOptionValue; import com.oracle.svm.core.option.SubstrateOptionsParser; @@ -210,7 +209,7 @@ private static String instructionsToInitializeAtRuntime(Class clazz) { } static Class getJavaClass(ResolvedJavaType type) { - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), type); + return OriginalClassProvider.getJavaClass(type); } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/EarlyClassInitializerAnalysis.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/EarlyClassInitializerAnalysis.java index 4d69f787d86b..51bc43061517 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/EarlyClassInitializerAnalysis.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/EarlyClassInitializerAnalysis.java @@ -165,7 +165,7 @@ private boolean canInitializeWithoutSideEffects(ResolvedJavaMethod clinit, Set newEventClass = OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), eventType).asSubclass(Event.class); + Class newEventClass = OriginalClassProvider.getJavaClass(eventType).asSubclass(Event.class); eventType.initialize(); SecuritySupport.registerEvent(newEventClass); JfrJavaEvents.registerEventClass(newEventClass); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/lambda/LambdaSubstitutionType.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/lambda/LambdaSubstitutionType.java index 700be6f7e3a3..01349aca0bb6 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/lambda/LambdaSubstitutionType.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/lambda/LambdaSubstitutionType.java @@ -28,7 +28,6 @@ import java.lang.reflect.AnnotatedElement; import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.jdk.LambdaFormHiddenMethod; import com.oracle.svm.hosted.annotation.AnnotationValue; import com.oracle.svm.hosted.annotation.AnnotationWrapper; @@ -406,6 +405,6 @@ public ResolvedJavaType getOriginal() { @Override public Class getJavaClass() { - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalClassProvider.getJavaClass(original); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedField.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedField.java index f9a2627b321a..523543150ae8 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedField.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedField.java @@ -200,6 +200,6 @@ public JavaKind getStorageKind() { @Override public Field getJavaField() { - return OriginalFieldProvider.getJavaField(getDeclaringClass().universe.getSnippetReflection(), wrapped); + return wrapped.getJavaField(); } } 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 fcca5e314bc9..c7992477c38a 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 @@ -506,7 +506,7 @@ public int hashCode() { @Override public Executable getJavaMethod() { - return OriginalMethodProvider.getJavaMethod(getDeclaringClass().universe.getSnippetReflection(), wrapped); + return wrapped.getJavaMethod(); } @Override 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 f70d48b0e456..22616a5da712 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 @@ -415,6 +415,6 @@ public ResolvedJavaType getHostClass() { @Override public Class getJavaClass() { - return OriginalClassProvider.getJavaClass(universe.getSnippetReflection(), wrapped); + return wrapped.getJavaClass(); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/EarlyConstantFoldLoadFieldPlugin.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/EarlyConstantFoldLoadFieldPlugin.java index ddcccce3c61c..de9c78dd4ad0 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/EarlyConstantFoldLoadFieldPlugin.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/EarlyConstantFoldLoadFieldPlugin.java @@ -27,7 +27,6 @@ import java.util.HashMap; import java.util.Map; -import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; import org.graalvm.compiler.nodes.ConstantNode; import org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext; import org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin; @@ -47,14 +46,11 @@ */ public class EarlyConstantFoldLoadFieldPlugin implements NodePlugin { - private final SnippetReflectionProvider snippetReflection; - private final Map primitiveTypes; private static final String SYNTHETIC_ASSERTIONS_DISABLED_FIELD_NAME = "$assertionsDisabled"; - public EarlyConstantFoldLoadFieldPlugin(MetaAccessProvider metaAccess, SnippetReflectionProvider snippetReflection) { - this.snippetReflection = snippetReflection; + public EarlyConstantFoldLoadFieldPlugin(MetaAccessProvider metaAccess) { primitiveTypes = new HashMap<>(); for (JavaKind kind : JavaKind.values()) { @@ -72,7 +68,7 @@ public boolean handleLoadStaticField(GraphBuilderContext b, ResolvedJavaField fi * matter at all (because it is the hosted assertion status), we instead return the * appropriate runtime assertion status. */ - Class javaClass = OriginalClassProvider.getJavaClass(snippetReflection, field.getDeclaringClass()); + Class javaClass = OriginalClassProvider.getJavaClass(field.getDeclaringClass()); boolean assertionsEnabled = RuntimeAssertionsSupport.singleton().desiredAssertionStatus(javaClass); b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(!assertionsEnabled)); return true; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/IntrinsifyMethodHandlesInvocationPlugin.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/IntrinsifyMethodHandlesInvocationPlugin.java index 48cafcbbd481..76ef116d1c91 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/IntrinsifyMethodHandlesInvocationPlugin.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/IntrinsifyMethodHandlesInvocationPlugin.java @@ -501,7 +501,7 @@ private static ResolvedJavaField findField(ResolvedJavaType type, String name) { throw GraalError.shouldNotReachHere("Required field " + name + " not found in " + type); } - private void registerInvocationPlugins(InvocationPlugins plugins, Replacements replacements) { + private static void registerInvocationPlugins(InvocationPlugins plugins, Replacements replacements) { Registration r = new Registration(plugins, "java.lang.invoke.DirectMethodHandle", replacements); r.register(new RequiredInvocationPlugin("ensureInitialized", Receiver.class) { @Override @@ -557,7 +557,7 @@ public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Rec * If both, the MethodHandle and the MethodType are constant, we can evaluate * asType eagerly and embed the result as a constant in the graph. */ - SnippetReflectionProvider snippetReflection = aUniverse.getOriginalSnippetReflection(); + SnippetReflectionProvider snippetReflection = GraalAccess.getOriginalSnippetReflection(); MethodHandle mh = snippetReflection.asObject(MethodHandle.class, methodHandleNode.asJavaConstant()); MethodType mt = snippetReflection.asObject(MethodType.class, newTypeNode.asJavaConstant()); if (mh == null || mt == null) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SharedGraphBuilderPhase.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SharedGraphBuilderPhase.java index 6f1696c9c440..8d64bf96575b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SharedGraphBuilderPhase.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/SharedGraphBuilderPhase.java @@ -70,7 +70,6 @@ import com.oracle.graal.pointsto.constraints.UnresolvedElementException; import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.common.meta.MultiMethod; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.SubstrateUtil; @@ -462,10 +461,10 @@ private static Class findResolutionError Class[] searchSignature = signatureToClasses(searchMethod); Class searchReturnType = null; if (searchMethod.getSignature().getReturnType(null) instanceof ResolvedJavaType) { - searchReturnType = OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), (ResolvedJavaType) searchMethod.getSignature().getReturnType(null)); + searchReturnType = OriginalClassProvider.getJavaClass((ResolvedJavaType) searchMethod.getSignature().getReturnType(null)); } - Class declaringClass = OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), declaringType); + Class declaringClass = OriginalClassProvider.getJavaClass(declaringType); for (Class cur = declaringClass; cur != null; cur = cur.getSuperclass()) { Executable[] methods = null; try { @@ -506,7 +505,7 @@ private static Class[] signatureToClasses(JavaMethod method) { for (int i = 0; i < paramCount; i++) { JavaType parameterType = method.getSignature().getParameterType(0, null); if (parameterType instanceof ResolvedJavaType) { - result[i] = OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), (ResolvedJavaType) parameterType); + result[i] = OriginalClassProvider.getJavaClass((ResolvedJavaType) parameterType); } } return result; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/ReflectionPlugins.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/ReflectionPlugins.java index f54f800a9c58..6ad220d42234 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/ReflectionPlugins.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/snippets/ReflectionPlugins.java @@ -64,7 +64,6 @@ import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.meta.AnalysisUniverse; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.ParsingReason; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.TypeResult; @@ -299,7 +298,7 @@ private boolean processMethodHandlesLookup(GraphBuilderContext b, ResolvedJavaMe */ return false; } - Class callerClass = OriginalClassProvider.getJavaClass(snippetReflection, b.getMethod().getDeclaringClass()); + Class callerClass = OriginalClassProvider.getJavaClass(b.getMethod().getDeclaringClass()); MethodHandles.Lookup lookup; try { /* The constructor of Lookup is not public, so we need to invoke it via reflection. */ @@ -521,7 +520,7 @@ private Object unboxObjectConstant(GraphBuilderContext b, JavaConstant argConsta * reflective call will yield the original member, which will be intrinsified, and * subsequent phases are responsible for getting the right substitution. */ - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), javaType); + return OriginalClassProvider.getJavaClass(javaType); } /* Any other object that is not a Class. */ diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedField.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedField.java index 6f6b3fe66911..35a59441e7a3 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedField.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedField.java @@ -124,6 +124,6 @@ public String toString() { @Override public Field getJavaField() { - return OriginalFieldProvider.getJavaField(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalFieldProvider.getJavaField(original); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedMethod.java index 7152830e6c6b..db8cd8ce8825 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotatedMethod.java @@ -37,7 +37,6 @@ import com.oracle.graal.pointsto.infrastructure.GraphProvider; import com.oracle.graal.pointsto.infrastructure.OriginalMethodProvider; import com.oracle.graal.pointsto.meta.HostedProviders; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.annotation.AnnotationValue; import com.oracle.svm.hosted.annotation.AnnotationWrapper; @@ -257,6 +256,6 @@ public SpeculationLog getSpeculationLog() { @Override public Executable getJavaMethod() { - return OriginalMethodProvider.getJavaMethod(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalMethodProvider.getJavaMethod(original); } } 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 34377a6754c4..d30228cd286f 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 @@ -549,6 +549,6 @@ public String toString() { @Override public Field getJavaField() { - return OriginalFieldProvider.getJavaField(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalFieldProvider.getJavaField(original); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/InjectedFieldsType.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/InjectedFieldsType.java index 5a19e0299fd7..567e4a5e0dfb 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/InjectedFieldsType.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/InjectedFieldsType.java @@ -28,7 +28,6 @@ import java.util.Arrays; import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.hosted.annotation.AnnotationWrapper; import jdk.vm.ci.common.JVMCIError; @@ -276,7 +275,7 @@ public ResolvedJavaType getHostClass() { @Override public Class getJavaClass() { - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalClassProvider.getJavaClass(original); } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionField.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionField.java index 3f59e3bf8cd2..1aaf25a6145f 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionField.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionField.java @@ -133,6 +133,6 @@ public AnnotatedElement getAnnotationRoot() { @Override public Field getJavaField() { - return OriginalFieldProvider.getJavaField(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalFieldProvider.getJavaField(original); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionMethod.java index 2d1c49ed08f1..523b65c62069 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionMethod.java @@ -38,7 +38,6 @@ import com.oracle.graal.pointsto.infrastructure.GraphProvider; import com.oracle.graal.pointsto.infrastructure.OriginalMethodProvider; import com.oracle.graal.pointsto.meta.HostedProviders; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.hosted.annotation.AnnotationWrapper; import jdk.vm.ci.meta.Constant; @@ -286,6 +285,6 @@ public SpeculationLog getSpeculationLog() { @Override public Executable getJavaMethod() { - return OriginalMethodProvider.getJavaMethod(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalMethodProvider.getJavaMethod(original); } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionType.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionType.java index e34e70b54a7a..647c49e64841 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionType.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/SubstitutionType.java @@ -29,7 +29,6 @@ import java.util.Arrays; import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.hosted.annotation.AnnotationWrapper; import jdk.vm.ci.common.JVMCIError; @@ -316,7 +315,7 @@ public ResolvedJavaType getHostClass() { @Override public Class getJavaClass() { - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), original); + return OriginalClassProvider.getJavaClass(original); } @Override 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 54324eb63d56..7eb34666ee30 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 @@ -88,7 +88,6 @@ import com.oracle.graal.pointsto.infrastructure.OriginalClassProvider; import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; import com.oracle.graal.pointsto.meta.AnalysisType; -import com.oracle.graal.pointsto.util.GraalAccess; import com.oracle.svm.core.BuildArtifacts; import com.oracle.svm.core.NeverInline; import com.oracle.svm.core.ParsingReason; @@ -764,7 +763,7 @@ static void duringAnalysis(DuringAnalysisAccess access) { private static Class getArgumentClass(GraphBuilderContext b, ResolvedJavaMethod targetMethod, int parameterIndex, ValueNode arg) { SubstrateGraphBuilderPlugins.checkParameterUsage(arg.isConstant(), b, targetMethod, parameterIndex, "parameter is not a compile time constant"); - return OriginalClassProvider.getJavaClass(GraalAccess.getOriginalSnippetReflection(), b.getConstantReflection().asJavaType(arg.asJavaConstant())); + return OriginalClassProvider.getJavaClass(b.getConstantReflection().asJavaType(arg.asJavaConstant())); } private static boolean validateClasses(Class storageSuperClass, Class factoryInterface) { From 4e6be5ec6162fc2fe0ab6f0368dca128db14c5d8 Mon Sep 17 00:00:00 2001 From: Christian Wimmer Date: Wed, 18 Jan 2023 13:39:32 -0800 Subject: [PATCH 4/4] AnalysisType.getWrapped should not resolve the wrapped type by default --- .../infrastructure/AnalysisConstantPool.java | 3 +- .../pointsto/infrastructure/Universe.java | 4 +- .../infrastructure/WrappedConstantPool.java | 4 +- .../infrastructure/WrappedElement.java | 4 -- .../infrastructure/WrappedSignature.java | 4 +- .../graal/pointsto/meta/AnalysisElement.java | 14 ++--- .../graal/pointsto/meta/AnalysisMethod.java | 4 +- .../graal/pointsto/meta/AnalysisType.java | 13 ++--- .../graal/pointsto/meta/AnalysisUniverse.java | 15 ++--- .../oracle/svm/hosted/NativeImageUtil.java | 57 ------------------- .../svm/hosted/SubstitutionReportFeature.java | 2 +- .../analysis/NativeImagePointsToAnalysis.java | 4 +- .../SubstrateAnnotationExtractor.java | 2 +- .../TypeInitializerGraph.java | 2 +- .../svm/hosted/code/FactoryMethodSupport.java | 6 +- .../image/NativeImageDebugInfoProvider.java | 2 +- .../jni/JNIJavaCallVariantWrapperMethod.java | 5 +- .../hosted/jni/JNIJavaCallWrapperMethod.java | 5 +- .../svm/hosted/meta/HostedUniverse.java | 5 +- .../svm/hosted/meta/UniverseBuilder.java | 19 +++---- ...trinsifyMethodHandlesInvocationPlugin.java | 28 ++++++++- .../svm/truffle/tck/PermissionsFeature.java | 4 +- .../svm/truffle/tck/WhiteListParser.java | 2 +- 23 files changed, 77 insertions(+), 131 deletions(-) delete mode 100644 substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageUtil.java diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/AnalysisConstantPool.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/AnalysisConstantPool.java index 59b84628ff20..95f8e143959f 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/AnalysisConstantPool.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/AnalysisConstantPool.java @@ -27,10 +27,11 @@ import jdk.vm.ci.meta.ConstantPool; import jdk.vm.ci.meta.JavaField; import jdk.vm.ci.meta.ResolvedJavaMethod; +import jdk.vm.ci.meta.ResolvedJavaType; public class AnalysisConstantPool extends WrappedConstantPool { - public AnalysisConstantPool(Universe universe, ConstantPool wrapped, WrappedJavaType defaultAccessingClass) { + public AnalysisConstantPool(Universe universe, ConstantPool wrapped, ResolvedJavaType defaultAccessingClass) { super(universe, wrapped, defaultAccessingClass); } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/Universe.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/Universe.java index dad144e75aad..33c51291532e 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/Universe.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/Universe.java @@ -55,9 +55,9 @@ public interface Universe { JavaMethod lookupAllowUnresolved(JavaMethod method); - WrappedSignature lookup(Signature signature, WrappedJavaType defaultAccessingClass); + WrappedSignature lookup(Signature signature, ResolvedJavaType defaultAccessingClass); - WrappedConstantPool lookup(ConstantPool constantPool, WrappedJavaType defaultAccessingClass); + WrappedConstantPool lookup(ConstantPool constantPool, ResolvedJavaType defaultAccessingClass); JavaConstant lookup(JavaConstant constant); diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedConstantPool.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedConstantPool.java index e1be0fa80e39..cc02539ddff0 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedConstantPool.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedConstantPool.java @@ -50,9 +50,9 @@ public class WrappedConstantPool implements ConstantPool, ConstantPoolPatch { protected final Universe universe; protected final ConstantPool wrapped; - private final WrappedJavaType defaultAccessingClass; + private final ResolvedJavaType defaultAccessingClass; - public WrappedConstantPool(Universe universe, ConstantPool wrapped, WrappedJavaType defaultAccessingClass) { + public WrappedConstantPool(Universe universe, ConstantPool wrapped, ResolvedJavaType defaultAccessingClass) { this.universe = universe; this.wrapped = wrapped; this.defaultAccessingClass = defaultAccessingClass; diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedElement.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedElement.java index bf5a86a07c58..729fa8e98f5c 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedElement.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedElement.java @@ -29,8 +29,4 @@ public interface WrappedElement { AnnotatedElement getWrapped(); - - default AnnotatedElement getWrappedWithoutResolve() { - return getWrapped(); - } } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedSignature.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedSignature.java index 359c96c86e74..c685e57bd57e 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedSignature.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/infrastructure/WrappedSignature.java @@ -34,10 +34,10 @@ public class WrappedSignature implements Signature { private final Signature wrapped; private final ResolvedJavaType defaultAccessingClass; - public WrappedSignature(Universe universe, Signature wrapped, WrappedJavaType defaultAccessingClass) { + public WrappedSignature(Universe universe, Signature wrapped, ResolvedJavaType defaultAccessingClass) { this.universe = universe; this.wrapped = wrapped; - this.defaultAccessingClass = defaultAccessingClass.getWrapped(); + this.defaultAccessingClass = defaultAccessingClass; } @Override diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisElement.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisElement.java index 6b6ac965ba7d..2ed848305ddb 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisElement.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisElement.java @@ -49,35 +49,31 @@ public abstract class AnalysisElement implements AnnotatedElement { public abstract AnnotatedElement getWrapped(); - public AnnotatedElement getWrappedWithoutResolve() { - return getWrapped(); - } - protected abstract AnalysisUniverse getUniverse(); @Override public final boolean isAnnotationPresent(Class annotationClass) { - return getUniverse().getAnnotationExtractor().hasAnnotation(getWrappedWithoutResolve(), annotationClass); + return getUniverse().getAnnotationExtractor().hasAnnotation(getWrapped(), annotationClass); } @Override public final T getAnnotation(Class annotationClass) { - return getUniverse().getAnnotationExtractor().extractAnnotation(getWrappedWithoutResolve(), annotationClass, false); + return getUniverse().getAnnotationExtractor().extractAnnotation(getWrapped(), annotationClass, false); } @Override public final T getDeclaredAnnotation(Class annotationClass) { - return getUniverse().getAnnotationExtractor().extractAnnotation(getWrappedWithoutResolve(), annotationClass, true); + return getUniverse().getAnnotationExtractor().extractAnnotation(getWrapped(), annotationClass, true); } @Override public final Annotation[] getAnnotations() { - return getUniverse().getAnnotationExtractor().extractAnnotations(getWrappedWithoutResolve(), false); + return getUniverse().getAnnotationExtractor().extractAnnotations(getWrapped(), false); } @Override public final Annotation[] getDeclaredAnnotations() { - return getUniverse().getAnnotationExtractor().extractAnnotations(getWrappedWithoutResolve(), true); + return getUniverse().getAnnotationExtractor().extractAnnotations(getWrapped(), true); } /** diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java index 3d2437fa16f2..5d2cd064d645 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisMethod.java @@ -534,7 +534,7 @@ public String getName() { @Override public WrappedSignature getSignature() { - return getUniverse().lookup(wrapped.getSignature(), getDeclaringClass()); + return getUniverse().lookup(wrapped.getSignature(), getDeclaringClass().getWrappedWithResolve()); } @Override @@ -650,7 +650,7 @@ public ProfilingInfo getProfilingInfo(boolean includeNormal, boolean includeOSR) @Override public ConstantPool getConstantPool() { - return getUniverse().lookup(wrapped.getConstantPool(), getDeclaringClass()); + return getUniverse().lookup(wrapped.getConstantPool(), getDeclaringClass().getWrappedWithResolve()); } @Override diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java index f4ea19cf6988..a79846eae6df 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java @@ -844,12 +844,11 @@ public boolean isWordType() { @Override public ResolvedJavaType getWrapped() { - return universe.substitutions.resolve(wrapped); + return wrapped; } - @Override - public ResolvedJavaType getWrappedWithoutResolve() { - return wrapped; + public ResolvedJavaType getWrappedWithResolve() { + return universe.substitutions.resolve(wrapped); } @Override @@ -938,8 +937,7 @@ public int getModifiers() { @Override public boolean isAssignableFrom(ResolvedJavaType other) { - ResolvedJavaType subst = universe.substitutions.resolve(((AnalysisType) other).wrapped); - return wrapped.isAssignableFrom(subst); + return wrapped.isAssignableFrom(((AnalysisType) other).getWrappedWithResolve()); } @Override @@ -1000,8 +998,7 @@ private static void collectSubtypes(AnalysisType baseType, Set res @Override public AnalysisType findLeastCommonAncestor(ResolvedJavaType otherType) { - ResolvedJavaType subst = universe.substitutions.resolve(((AnalysisType) otherType).wrapped); - return universe.lookup(wrapped.findLeastCommonAncestor(subst)); + return universe.lookup(wrapped.findLeastCommonAncestor(((AnalysisType) otherType).getWrappedWithResolve())); } @Override diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java index 444ecba09dd5..5efcc177140d 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisUniverse.java @@ -277,7 +277,7 @@ private AnalysisType createType(ResolvedJavaType type) { } try { - JavaKind storageKind = getStorageKind(type, originalMetaAccess); + JavaKind storageKind = originalMetaAccess.lookupJavaType(WordBase.class).isAssignableFrom(substitutions.resolve(type)) ? wordKind : type.getJavaKind(); AnalysisType newValue = analysisFactory.createType(this, type, storageKind, objectClass, cloneableClass); synchronized (this) { @@ -332,13 +332,6 @@ private AnalysisType createType(ResolvedJavaType type) { } } - public JavaKind getStorageKind(ResolvedJavaType type, MetaAccessProvider metaAccess) { - if (metaAccess.lookupJavaType(WordBase.class).isAssignableFrom(substitutions.resolve(type))) { - return wordKind; - } - return type.getJavaKind(); - } - @Override public AnalysisField lookup(JavaField field) { JavaField result = lookupAllowUnresolved(field); @@ -476,8 +469,9 @@ public AnalysisMethod[] lookup(JavaMethod[] inputs) { } @Override - public WrappedSignature lookup(Signature signature, WrappedJavaType defaultAccessingClass) { + public WrappedSignature lookup(Signature signature, ResolvedJavaType defaultAccessingClass) { assert !(signature instanceof WrappedSignature); + assert !(defaultAccessingClass instanceof WrappedJavaType); WrappedSignature result = signatures.get(signature); if (result == null) { WrappedSignature newValue = new WrappedSignature(this, signature, defaultAccessingClass); @@ -488,8 +482,9 @@ public WrappedSignature lookup(Signature signature, WrappedJavaType defaultAcces } @Override - public WrappedConstantPool lookup(ConstantPool constantPool, WrappedJavaType defaultAccessingClass) { + public WrappedConstantPool lookup(ConstantPool constantPool, ResolvedJavaType defaultAccessingClass) { assert !(constantPool instanceof WrappedConstantPool); + assert !(defaultAccessingClass instanceof WrappedJavaType); WrappedConstantPool result = constantPools.get(constantPool); if (result == null) { WrappedConstantPool newValue = new AnalysisConstantPool(this, constantPool, defaultAccessingClass); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageUtil.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageUtil.java deleted file mode 100644 index a9f619a95397..000000000000 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageUtil.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2019, 2019, 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 - * 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.hosted; - -import com.oracle.graal.pointsto.meta.AnalysisMethod; -import com.oracle.graal.pointsto.meta.AnalysisType; -import com.oracle.svm.hosted.meta.HostedMethod; -import com.oracle.svm.hosted.meta.HostedType; - -import jdk.vm.ci.meta.ResolvedJavaMethod; -import jdk.vm.ci.meta.ResolvedJavaType; - -public class NativeImageUtil { - - public static ResolvedJavaMethod toOriginal(ResolvedJavaMethod method) { - if (method instanceof HostedMethod) { - return ((HostedMethod) method).wrapped.wrapped; - } else if (method instanceof AnalysisMethod) { - return ((AnalysisMethod) method).wrapped; - } else { - return method; - } - } - - public static ResolvedJavaType toOriginal(ResolvedJavaType type) { - if (type instanceof HostedType) { - return ((HostedType) type).getWrapped().getWrapped(); - } else if (type instanceof AnalysisType) { - return ((AnalysisType) type).getWrapped(); - } else { - return type; - } - } - -} diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstitutionReportFeature.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstitutionReportFeature.java index b6cf469d9ba3..5b26353be5a8 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstitutionReportFeature.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/SubstitutionReportFeature.java @@ -77,7 +77,7 @@ public void afterAnalysis(AfterAnalysisAccess access) { private void findSubstitutedTypes(FeatureImpl.AfterAnalysisAccessImpl access) { for (AnalysisType type : access.getUniverse().getTypes()) { if (type.isReachable() && !type.isArray()) { - ResolvedJavaType t = type.getWrappedWithoutResolve(); + ResolvedJavaType t = type.getWrapped(); if (t instanceof SubstitutionType) { SubstitutionType subType = (SubstitutionType) t; if (subType.isUserSubstitution()) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/NativeImagePointsToAnalysis.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/NativeImagePointsToAnalysis.java index 6ee6be5530d4..05ad7e224b92 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/NativeImagePointsToAnalysis.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/analysis/NativeImagePointsToAnalysis.java @@ -119,9 +119,9 @@ public void initializeMetaData(AnalysisType type) { public static ResolvedJavaType toWrappedType(ResolvedJavaType type) { if (type instanceof AnalysisType) { - return ((AnalysisType) type).getWrappedWithoutResolve(); + return ((AnalysisType) type).getWrapped(); } else if (type instanceof HostedType) { - return ((HostedType) type).getWrapped().getWrappedWithoutResolve(); + return ((HostedType) type).getWrapped().getWrapped(); } else { return type; } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java index 0d62cb19bae0..3eeb2ce548e4 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/annotation/SubstrateAnnotationExtractor.java @@ -176,7 +176,7 @@ public AnnotationValue[] getDeclaredAnnotationData(AnnotatedElement element) { private AnnotationValue[] getAnnotationData(AnnotatedElement element, boolean declaredOnly) { AnnotatedElement cur = element; while (cur instanceof WrappedElement) { - cur = ((WrappedElement) cur).getWrappedWithoutResolve(); + cur = ((WrappedElement) cur).getWrapped(); } AnnotationValue[] result = NO_ANNOTATIONS; while (cur instanceof AnnotationWrapper) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java index 774cfcdf4027..f520e58aa87c 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/classinitialization/TypeInitializerGraph.java @@ -246,7 +246,7 @@ private boolean isInvokeUnsafeIterative(InvokeInfo i) { } private void addInitializer(AnalysisType t) { - ResolvedJavaType rt = t.getWrappedWithoutResolve(); + ResolvedJavaType rt = t.getWrapped(); boolean isSubstituted = false; if (rt instanceof SubstitutionType) { SubstitutionType substitutionType = (SubstitutionType) rt; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/FactoryMethodSupport.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/FactoryMethodSupport.java index 79ac8efb8946..31c6e9342c7b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/FactoryMethodSupport.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/code/FactoryMethodSupport.java @@ -88,12 +88,12 @@ public ResolvedJavaMethod lookup(UniverseMetaAccess metaAccess, ResolvedJavaMeth */ ResolvedJavaType[] unwrappedParameterTypes = new ResolvedJavaType[aConstructor.getSignature().getParameterCount(false)]; for (int i = 0; i < unwrappedParameterTypes.length; i++) { - unwrappedParameterTypes[i] = ((AnalysisType) aConstructor.getSignature().getParameterType(i, null)).getWrappedWithoutResolve(); + unwrappedParameterTypes[i] = ((AnalysisType) aConstructor.getSignature().getParameterType(i, null)).getWrapped(); } - ResolvedJavaType unwrappedReturnType = (throwAllocatedObject ? aMetaAccess.lookupJavaType(void.class) : aConstructor.getDeclaringClass()).getWrappedWithoutResolve(); + ResolvedJavaType unwrappedReturnType = (throwAllocatedObject ? aMetaAccess.lookupJavaType(void.class) : aConstructor.getDeclaringClass()).getWrapped(); Signature unwrappedSignature = new SimpleSignature(unwrappedParameterTypes, unwrappedReturnType); ResolvedJavaMethod unwrappedConstructor = aConstructor.getWrapped(); - ResolvedJavaType unwrappedDeclaringClass = (aMetaAccess.lookupJavaType(throwAllocatedObject ? FactoryThrowMethodHolder.class : FactoryMethodHolder.class)).getWrappedWithoutResolve(); + ResolvedJavaType unwrappedDeclaringClass = (aMetaAccess.lookupJavaType(throwAllocatedObject ? FactoryThrowMethodHolder.class : FactoryMethodHolder.class)).getWrapped(); ConstantPool unwrappedConstantPool = unwrappedConstructor.getConstantPool(); return new FactoryMethod(name, unwrappedConstructor, unwrappedDeclaringClass, unwrappedSignature, unwrappedConstantPool, throwAllocatedObject); }); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java index a895475ee2a4..a21757cb4a97 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/image/NativeImageDebugInfoProvider.java @@ -293,7 +293,7 @@ protected static ResolvedJavaType getDeclaringClass(HostedField hostedField, boo private static ResolvedJavaType getOriginal(HostedType hostedType) { /* partially unwrap then traverse through substitutions to the original */ - ResolvedJavaType javaType = hostedType.getWrapped().getWrappedWithoutResolve(); + ResolvedJavaType javaType = hostedType.getWrapped().getWrapped(); if (javaType instanceof SubstitutionType) { return ((SubstitutionType) javaType).getOriginal(); } else if (javaType instanceof CustomSubstitutionType) { diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIJavaCallVariantWrapperMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIJavaCallVariantWrapperMethod.java index d4a6e45abfbd..b8863ddba00b 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIJavaCallVariantWrapperMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIJavaCallVariantWrapperMethod.java @@ -53,7 +53,6 @@ import org.graalvm.word.LocationIdentity; import com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess; -import com.oracle.graal.pointsto.infrastructure.WrappedJavaType; import com.oracle.graal.pointsto.infrastructure.WrappedSignature; import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; import com.oracle.graal.pointsto.meta.HostedProviders; @@ -146,10 +145,10 @@ public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, JNIGraphKit kit = new JNIGraphKit(debug, providers, method); AnalysisMetaAccess aMetaAccess = (AnalysisMetaAccess) ((metaAccess instanceof AnalysisMetaAccess) ? metaAccess : metaAccess.getWrapped()); - Signature invokeSignature = aMetaAccess.getUniverse().lookup(callWrapperSignature, aMetaAccess.getUniverse().lookup(getDeclaringClass())); + Signature invokeSignature = aMetaAccess.getUniverse().lookup(callWrapperSignature, getDeclaringClass()); if (metaAccess instanceof HostedMetaAccess) { // signature might not exist in the hosted universe because it does not match any method - invokeSignature = new WrappedSignature(metaAccess.getUniverse(), invokeSignature, (WrappedJavaType) method.getDeclaringClass()); + invokeSignature = new WrappedSignature(metaAccess.getUniverse(), invokeSignature, getDeclaringClass()); } JavaKind wordKind = providers.getWordTypes().getWordKind(); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIJavaCallWrapperMethod.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIJavaCallWrapperMethod.java index f997ee6fbf65..a821fd718acb 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIJavaCallWrapperMethod.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/jni/JNIJavaCallWrapperMethod.java @@ -52,7 +52,6 @@ import org.graalvm.compiler.word.WordTypes; import com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess; -import com.oracle.graal.pointsto.infrastructure.WrappedJavaType; import com.oracle.graal.pointsto.infrastructure.WrappedSignature; import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; import com.oracle.graal.pointsto.meta.HostedProviders; @@ -166,10 +165,10 @@ public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, JNIGraphKit kit = new JNIGraphKit(debug, providers, method); AnalysisMetaAccess aMetaAccess = (AnalysisMetaAccess) ((metaAccess instanceof AnalysisMetaAccess) ? metaAccess : metaAccess.getWrapped()); - Signature invokeSignature = aMetaAccess.getUniverse().lookup(targetSignature, aMetaAccess.getUniverse().lookup(getDeclaringClass())); + Signature invokeSignature = aMetaAccess.getUniverse().lookup(targetSignature, getDeclaringClass()); if (metaAccess instanceof HostedMetaAccess) { // signature might not exist in the hosted universe because it does not match any method - invokeSignature = new WrappedSignature(metaAccess.getUniverse(), invokeSignature, (WrappedJavaType) method.getDeclaringClass()); + invokeSignature = new WrappedSignature(metaAccess.getUniverse(), invokeSignature, getDeclaringClass()); } JavaKind wordKind = providers.getWordTypes().getWordKind(); 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 29f50bb3132f..106ccabbd2e2 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 @@ -49,7 +49,6 @@ import com.oracle.graal.pointsto.infrastructure.SubstitutionProcessor; import com.oracle.graal.pointsto.infrastructure.Universe; import com.oracle.graal.pointsto.infrastructure.WrappedConstantPool; -import com.oracle.graal.pointsto.infrastructure.WrappedJavaType; import com.oracle.graal.pointsto.infrastructure.WrappedSignature; import com.oracle.graal.pointsto.meta.AnalysisField; import com.oracle.graal.pointsto.meta.AnalysisMethod; @@ -413,13 +412,13 @@ public HostedMethod[] lookup(JavaMethod[] inputs) { } @Override - public WrappedSignature lookup(Signature signature, WrappedJavaType defaultAccessingClass) { + public WrappedSignature lookup(Signature signature, ResolvedJavaType defaultAccessingClass) { assert signatures.containsKey(signature) : signature; return signatures.get(signature); } @Override - public WrappedConstantPool lookup(ConstantPool constantPool, WrappedJavaType defaultAccessingClass) { + public WrappedConstantPool lookup(ConstantPool constantPool, ResolvedJavaType defaultAccessingClass) { assert constantPools.containsKey(constantPool) : constantPool; return constantPools.get(constantPool); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/UniverseBuilder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/UniverseBuilder.java index 6dd5b9299ab5..462b765c1378 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/UniverseBuilder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/UniverseBuilder.java @@ -55,7 +55,6 @@ import com.oracle.graal.pointsto.BigBang; import com.oracle.graal.pointsto.constraints.UnsupportedFeatures; import com.oracle.graal.pointsto.infrastructure.WrappedConstantPool; -import com.oracle.graal.pointsto.infrastructure.WrappedJavaType; import com.oracle.graal.pointsto.infrastructure.WrappedSignature; import com.oracle.graal.pointsto.meta.AnalysisField; import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; @@ -289,10 +288,10 @@ private static boolean sameObject(Object x, Object y) { } private HostedMethod makeMethod(AnalysisMethod aMethod) { - HostedType holder; - holder = lookupType(aMethod.getDeclaringClass()); - Signature signature = makeSignature(aMethod.getSignature(), holder); - ConstantPool constantPool = makeConstantPool(aMethod.getConstantPool(), holder); + AnalysisType aDeclaringClass = aMethod.getDeclaringClass(); + HostedType hDeclaringClass = lookupType(aDeclaringClass); + Signature signature = makeSignature(aMethod.getSignature(), aDeclaringClass); + ConstantPool constantPool = makeConstantPool(aMethod.getConstantPool(), aDeclaringClass); ExceptionHandler[] aHandlers = aMethod.getExceptionHandlers(); ExceptionHandler[] sHandlers = new ExceptionHandler[aHandlers.length]; @@ -307,7 +306,7 @@ private HostedMethod makeMethod(AnalysisMethod aMethod) { sHandlers[i] = new ExceptionHandler(h.getStartBCI(), h.getEndBCI(), h.getHandlerBCI(), h.catchTypeCPI(), catchType); } - HostedMethod hMethod = HostedMethod.create(hUniverse, aMethod, holder, signature, constantPool, sHandlers); + HostedMethod hMethod = HostedMethod.create(hUniverse, aMethod, hDeclaringClass, signature, constantPool, sHandlers); boolean isCFunction = aMethod.getAnnotation(CFunction.class) != null; boolean hasCFunctionOptions = aMethod.getAnnotation(CFunctionOptions.class) != null; @@ -329,10 +328,10 @@ private HostedMethod makeMethod(AnalysisMethod aMethod) { return hMethod; } - private Signature makeSignature(Signature aSignature, WrappedJavaType defaultAccessingClass) { + private Signature makeSignature(Signature aSignature, AnalysisType aDefaultAccessingClass) { WrappedSignature hSignature = hUniverse.signatures.get(aSignature); if (hSignature == null) { - hSignature = new WrappedSignature(hUniverse, aSignature, defaultAccessingClass); + hSignature = new WrappedSignature(hUniverse, aSignature, aDefaultAccessingClass); hUniverse.signatures.put(aSignature, hSignature); for (int i = 0; i < aSignature.getParameterCount(false); i++) { @@ -343,10 +342,10 @@ private Signature makeSignature(Signature aSignature, WrappedJavaType defaultAcc return hSignature; } - private ConstantPool makeConstantPool(ConstantPool aConstantPool, WrappedJavaType defaultAccessingClass) { + private ConstantPool makeConstantPool(ConstantPool aConstantPool, AnalysisType aDefaultAccessingClass) { WrappedConstantPool hConstantPool = hUniverse.constantPools.get(aConstantPool); if (hConstantPool == null) { - hConstantPool = new WrappedConstantPool(hUniverse, aConstantPool, defaultAccessingClass); + hConstantPool = new WrappedConstantPool(hUniverse, aConstantPool, aDefaultAccessingClass); hUniverse.constantPools.put(aConstantPool, hConstantPool); } return hConstantPool; diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/IntrinsifyMethodHandlesInvocationPlugin.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/IntrinsifyMethodHandlesInvocationPlugin.java index 76ef116d1c91..561c3ff7ff7d 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/IntrinsifyMethodHandlesInvocationPlugin.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/phases/IntrinsifyMethodHandlesInvocationPlugin.java @@ -110,6 +110,8 @@ import org.graalvm.nativeimage.ImageSingletons; import com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess; +import com.oracle.graal.pointsto.meta.AnalysisMethod; +import com.oracle.graal.pointsto.meta.AnalysisType; import com.oracle.graal.pointsto.meta.AnalysisUniverse; import com.oracle.graal.pointsto.meta.HostedProviders; import com.oracle.graal.pointsto.phases.NoClassInitializationPlugin; @@ -121,8 +123,8 @@ import com.oracle.svm.core.jdk.VarHandleFeature; import com.oracle.svm.core.meta.SubstrateObjectConstant; import com.oracle.svm.core.util.VMError; -import com.oracle.svm.hosted.NativeImageUtil; import com.oracle.svm.hosted.SVMHost; +import com.oracle.svm.hosted.meta.HostedMethod; import com.oracle.svm.hosted.meta.HostedType; import com.oracle.svm.hosted.meta.HostedUniverse; import com.oracle.svm.hosted.snippets.IntrinsificationPluginRegistry; @@ -416,7 +418,7 @@ public FloatingNode interceptParameter(GraphBuilderTool b, int index, StampPair if (argType != null) { // TODO For trustInterfaces = false, we cannot be more specific here // (i.e. we cannot use TypeReference.createExactTrusted here) - TypeReference typeref = TypeReference.createWithoutAssumptions(NativeImageUtil.toOriginal(argType)); + TypeReference typeref = TypeReference.createWithoutAssumptions(toOriginalWithResolve(argType)); argStamp = StampTool.isPointerNonNull(argStamp) ? StampFactory.objectNonNull(typeref) : StampFactory.object(typeref); } return new ParameterNode(index, StampPair.createSingle(argStamp)); @@ -612,7 +614,7 @@ private boolean processInvokeWithMethodHandle(GraphBuilderContext b, Replacement DebugContext debug = b.getDebug(); StructuredGraph graph = new StructuredGraph.Builder(b.getOptions(), debug) - .method(NativeImageUtil.toOriginal(methodHandleMethod)) + .method(toOriginal(methodHandleMethod)) .recordInlinedMethods(false) .build(); try (DebugContext.Scope s = debug.scope("IntrinsifyMethodHandles", graph)) { @@ -1040,6 +1042,26 @@ private JavaConstant lookup(JavaConstant constant) { private JavaConstant toOriginal(JavaConstant constant) { return aUniverse.toHosted(constant); } + + private static ResolvedJavaMethod toOriginal(ResolvedJavaMethod method) { + if (method instanceof HostedMethod) { + return ((HostedMethod) method).wrapped.wrapped; + } else if (method instanceof AnalysisMethod) { + return ((AnalysisMethod) method).wrapped; + } else { + return method; + } + } + + private static ResolvedJavaType toOriginalWithResolve(ResolvedJavaType type) { + if (type instanceof HostedType) { + return ((HostedType) type).getWrapped().getWrappedWithResolve(); + } else if (type instanceof AnalysisType) { + return ((AnalysisType) type).getWrappedWithResolve(); + } else { + return type; + } + } } @NodeInfo(size = NodeSize.SIZE_16, cycles = NodeCycles.CYCLES_2, cyclesRationale = "Class initialization only runs at most once at run time, so the amortized cost is only the is-initialized check") diff --git a/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/PermissionsFeature.java b/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/PermissionsFeature.java index 7af3fa2f4b89..073a2ec49c0a 100644 --- a/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/PermissionsFeature.java +++ b/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/PermissionsFeature.java @@ -540,7 +540,7 @@ private static Set findMethods(BigBang bb, Class owner, P * @return the methods accepted by {@code filter} */ static Set findMethods(BigBang bb, AnalysisType owner, Predicate filter) { - return findImpl(bb, owner.getWrappedWithoutResolve().getDeclaredMethods(), filter); + return findImpl(bb, owner.getWrapped().getDeclaredMethods(), filter); } /** @@ -553,7 +553,7 @@ static Set findMethods(BigBang bb, AnalysisType owner, Predi * @return the constructors accepted by {@code filter} */ static Set findConstructors(BigBang bb, AnalysisType owner, Predicate filter) { - return findImpl(bb, owner.getWrappedWithoutResolve().getDeclaredConstructors(), filter); + return findImpl(bb, owner.getWrapped().getDeclaredConstructors(), filter); } private static Set findImpl(BigBang bb, ResolvedJavaMethod[] methods, Predicate filter) { diff --git a/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/WhiteListParser.java b/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/WhiteListParser.java index 1bfb7fbb1b71..c3f17e34212a 100644 --- a/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/WhiteListParser.java +++ b/substratevm/src/com.oracle.svm.truffle.tck/src/com/oracle/svm/truffle/tck/WhiteListParser.java @@ -269,7 +269,7 @@ private static final class SignaturePredicate implements Predicate params, BigBang bb) { - this.owner = Objects.requireNonNull(owner, "Owner must be non null.").getWrappedWithoutResolve(); + this.owner = Objects.requireNonNull(owner, "Owner must be non null.").getWrapped(); this.params = Objects.requireNonNull(params, "Params must be non null."); this.bb = Objects.requireNonNull(bb, "BigBang must be non null."); }