From c35e8858239d795da36cc5114d029a008ed20f29 Mon Sep 17 00:00:00 2001 From: Codrut Stancu Date: Sat, 18 Jan 2025 15:17:00 +0100 Subject: [PATCH 1/3] BaseLayerMethod doesn't have a java.lang.reflect.Method. --- .../pointsto/infrastructure/OriginalMethodProvider.java | 5 +++++ 1 file changed, 5 insertions(+) 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 8a37bbcdfb3b..059d9317dd7d 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,6 +26,7 @@ import java.lang.reflect.Executable; +import com.oracle.graal.pointsto.meta.BaseLayerMethod; import com.oracle.graal.pointsto.util.GraalAccess; import jdk.vm.ci.meta.ResolvedJavaMethod; @@ -56,6 +57,10 @@ static ResolvedJavaMethod getOriginalMethod(ResolvedJavaMethod method) { */ static Executable getJavaMethod(ResolvedJavaMethod method) { ResolvedJavaMethod originalMethod = getOriginalMethod(method); + if (originalMethod instanceof BaseLayerMethod) { + /* We don't know corresponding java.lang.reflect.Method. */ + return null; + } if (originalMethod != null) { try { return GraalAccess.getOriginalSnippetReflection().originalMethod(originalMethod); From cdb41489de639db00061d3a92bcfd0d4492b0e8f Mon Sep 17 00:00:00 2001 From: Codrut Stancu Date: Tue, 21 Jan 2025 20:16:24 +0100 Subject: [PATCH 2/3] Refactor BaseLayerMethod error reporting. --- .../graal/pointsto/meta/BaseLayerMethod.java | 42 ++++++++++--------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/BaseLayerMethod.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/BaseLayerMethod.java index 444ee03cba85..a53ef3833169 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/BaseLayerMethod.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/BaseLayerMethod.java @@ -116,12 +116,12 @@ public Signature getSignature() { @Override public int getMaxLocals() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public int getMaxStackSize() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override @@ -136,17 +136,17 @@ public boolean isVarArgs() { @Override public boolean isBridge() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public boolean isDefault() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public boolean isClassInitializer() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override @@ -171,42 +171,42 @@ public StackTraceElement asStackTraceElement(int bci) { @Override public ProfilingInfo getProfilingInfo(boolean includeNormal, boolean includeOSR) { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public void reprofile() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public ConstantPool getConstantPool() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public Annotation[][] getParameterAnnotations() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public Type[] getGenericParameterTypes() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public boolean canBeInlined() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public boolean hasNeverInlineDirective() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public boolean shouldBeInlined() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override @@ -221,32 +221,36 @@ public LocalVariableTable getLocalVariableTable() { @Override public Constant getEncoding() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public boolean isInVirtualMethodTable(ResolvedJavaType resolved) { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public SpeculationLog getSpeculationLog() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public T getAnnotation(Class annotationClass) { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public Annotation[] getAnnotations() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); } @Override public Annotation[] getDeclaredAnnotations() { - throw GraalError.unimplemented("This method is incomplete and should not be used."); + throw unimplemented(); + } + + private RuntimeException unimplemented() { + return GraalError.unimplemented("This method is incomplete and should not be used. Base layer method: " + format("%H.%n(%p)")); } @Override From d30565ad8537221dd7f17bc8b7b83d43c1e44653 Mon Sep 17 00:00:00 2001 From: Codrut Stancu Date: Tue, 11 Feb 2025 14:28:25 +0100 Subject: [PATCH 3/3] Add BaseLayerMethod.isBridge. --- .../graal/pointsto/meta/BaseLayerMethod.java | 8 +++-- .../SharedLayerSnapshotCapnProtoSchema.capnp | 33 ++++++++++--------- .../imagelayer/SVMImageLayerLoader.java | 2 +- .../imagelayer/SVMImageLayerWriter.java | 1 + ...redLayerSnapshotCapnProtoSchemaHolder.java | 17 ++++++++-- 5 files changed, 38 insertions(+), 23 deletions(-) diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/BaseLayerMethod.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/BaseLayerMethod.java index a53ef3833169..77257e280599 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/BaseLayerMethod.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/BaseLayerMethod.java @@ -55,6 +55,7 @@ public class BaseLayerMethod extends BaseLayerElement implements ResolvedJavaMet private final ResolvedJavaType declaringClass; private final String name; private final boolean isVarArgs; + private final boolean isBridge; private final ResolvedSignature signature; private final boolean canBeStaticallyBound; private final boolean isConstructor; @@ -64,13 +65,14 @@ public class BaseLayerMethod extends BaseLayerElement implements ResolvedJavaMet private final int codeSize; private final IntrinsicMethod methodHandleIntrinsic; - public BaseLayerMethod(int id, AnalysisType declaringClass, String name, boolean isVarArgs, ResolvedSignature signature, boolean canBeStaticallyBound, boolean isConstructor, - int modifiers, boolean isSynthetic, byte[] code, int codeSize, IntrinsicMethod methodHandleIntrinsic, Annotation[] annotations) { + public BaseLayerMethod(int id, AnalysisType declaringClass, String name, boolean isVarArgs, boolean isBridge, ResolvedSignature signature, boolean canBeStaticallyBound, + boolean isConstructor, int modifiers, boolean isSynthetic, byte[] code, int codeSize, IntrinsicMethod methodHandleIntrinsic, Annotation[] annotations) { super(annotations); this.id = id; this.declaringClass = declaringClass.getWrapped(); this.name = name; this.isVarArgs = isVarArgs; + this.isBridge = isBridge; this.signature = signature; this.canBeStaticallyBound = canBeStaticallyBound; this.isConstructor = isConstructor; @@ -136,7 +138,7 @@ public boolean isVarArgs() { @Override public boolean isBridge() { - throw unimplemented(); + return isBridge; } @Override diff --git a/substratevm/src/com.oracle.svm.hosted/resources/SharedLayerSnapshotCapnProtoSchema.capnp b/substratevm/src/com.oracle.svm.hosted/resources/SharedLayerSnapshotCapnProtoSchema.capnp index ae5d756f6457..422c0adcfd12 100644 --- a/substratevm/src/com.oracle.svm.hosted/resources/SharedLayerSnapshotCapnProtoSchema.capnp +++ b/substratevm/src/com.oracle.svm.hosted/resources/SharedLayerSnapshotCapnProtoSchema.capnp @@ -86,32 +86,33 @@ struct PersistedAnalysisMethod { methodHandleIntrinsicName @19 :Text; annotationList @20 :List(Annotation); isVarArgs @21 :Bool; - analysisGraphLocation @22 :Text; - analysisGraphIsIntrinsic @23 :Bool; - strengthenedGraphLocation @24 :Text; + isBridge @22 :Bool; + analysisGraphLocation @23 :Text; + analysisGraphIsIntrinsic @24 :Bool; + strengthenedGraphLocation @25 :Text; wrappedMethod :union { - none @25 :Void; # default + none @26 :Void; # default factoryMethod :group { - targetConstructorId @26 :MethodId; - throwAllocatedObject @27 :Bool; - instantiatedTypeId @28 :TypeId; + targetConstructorId @27 :MethodId; + throwAllocatedObject @28 :Bool; + instantiatedTypeId @29 :TypeId; } outlinedSB :group { - methodTypeReturn @29 :Text; - methodTypeParameters @30 :List(Text); + methodTypeReturn @30 :Text; + methodTypeParameters @31 :List(Text); } cEntryPointCallStub :group { - originalMethodId @31 :MethodId; - notPublished @32 :Bool; + originalMethodId @32 :MethodId; + notPublished @33 :Bool; } wrappedMember :group { union { - reflectionExpandSignature @33 :Void; - javaCallVariantWrapper @34 :Void; + reflectionExpandSignature @34 :Void; + javaCallVariantWrapper @35 :Void; } - name @35 :Text; - declaringClassName @36 :Text; - argumentTypeNames @37 :List(Text); + name @36 :Text; + declaringClassName @37 :Text; + argumentTypeNames @38 :List(Text); } } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java index ab0906b77370..69728026cb7e 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerLoader.java @@ -773,7 +773,7 @@ private void createBaseLayerMethod(PersistedAnalysisMethod.Reader md, int mid, S Annotation[] annotations = getAnnotations(md.getAnnotationList()); baseLayerMethods.computeIfAbsent(mid, - methodId -> new BaseLayerMethod(mid, type, name, md.getIsVarArgs(), signature, md.getCanBeStaticallyBound(), md.getIsConstructor(), + methodId -> new BaseLayerMethod(mid, type, name, md.getIsVarArgs(), md.getIsBridge(), signature, md.getCanBeStaticallyBound(), md.getIsConstructor(), md.getModifiers(), md.getIsSynthetic(), code, md.getCodeSize(), methodHandleIntrinsic, annotations)); BaseLayerMethod baseLayerMethod = baseLayerMethods.get(mid); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerWriter.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerWriter.java index e94b471eebf6..ced305948fc6 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerWriter.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/imagelayer/SVMImageLayerWriter.java @@ -533,6 +533,7 @@ private void persistMethod(AnalysisMethod method, Supplier