From 6f342914c6e63950efea5c2f1f2bece901661f3e Mon Sep 17 00:00:00 2001 From: Loic Ottet Date: Wed, 25 May 2022 16:41:20 +0200 Subject: [PATCH] Debug --- .../graal/pointsto/heap/ImageHeapScanner.java | 17 ++++++++++++++- .../AnalysisConstantReflectionProvider.java | 21 ++++++++++++++++--- .../svm/hosted/heap/SVMImageHeapScanner.java | 3 +++ .../AnnotationSubstitutionProcessor.java | 2 ++ .../util/SubstrateAnnotationExtracter.java | 3 ++- 5 files changed, 41 insertions(+), 5 deletions(-) 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 492823af7c11d..f49557152c81e 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 @@ -31,6 +31,7 @@ import java.util.Optional; import java.util.function.Consumer; +import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException; import org.graalvm.collections.EconomicMap; import org.graalvm.collections.MapCursor; import org.graalvm.compiler.api.replacements.SnippetReflectionProvider; @@ -319,6 +320,9 @@ JavaConstant onFieldValueReachable(AnalysisField field, JavaConstant receiver, J } JavaConstant onFieldValueReachable(AnalysisField field, JavaConstant receiver, ValueSupplier rawValue, ScanReason reason, Consumer onAnalysisModified) { + if (field.format("%H.%n").equals("jdk.vm.ci.runtime.JVMCI.runtime")) { + System.out.println("found"); + } AnalysisError.guarantee(field.isReachable(), "Field value is only reachable when field is reachable " + field.format("%H.%n")); /* @@ -328,7 +332,15 @@ JavaConstant onFieldValueReachable(AnalysisField field, JavaConstant receiver, V */ AnalysisError.guarantee(rawValue.isAvailable(), "Value not yet available for " + field.format("%H.%n")); - JavaConstant transformedValue = transformFieldValue(field, receiver, rawValue.get()); + JavaConstant transformedValue; + try { + transformedValue = transformFieldValue(field, receiver, rawValue.get()); + } catch (UnsupportedFeatureException e) { + for (ScanReason cur = reason; cur != null; cur = cur.getPrevious()) { + System.out.println(cur); + } + throw e; + } /* Add the transformed value to the image heap. */ JavaConstant fieldValue = markConstantReachable(transformedValue, reason, onAnalysisModified); @@ -439,6 +451,9 @@ protected String formatReason(String message, ScanReason reason) { protected ValueSupplier readHostedFieldValue(AnalysisField field, JavaConstant receiver) { // Wrap the hosted constant into a substrate constant + if (field.format("%H.%n").equals("jdk.vm.ci.runtime.JVMCI.runtime")) { + System.out.println("Found"); + } JavaConstant value = universe.lookup(hostedConstantReflection.readFieldValue(field.wrapped, receiver)); return ValueSupplier.eagerValue(value); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ameta/AnalysisConstantReflectionProvider.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ameta/AnalysisConstantReflectionProvider.java index c801b91ea99da..55b748bcb6afd 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ameta/AnalysisConstantReflectionProvider.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ameta/AnalysisConstantReflectionProvider.java @@ -107,9 +107,15 @@ public JavaConstant readValue(MetaAccessProvider suppliedMetaAccess, AnalysisFie /** Read the field value and wrap it in a value supplier without performing any replacements. */ public ValueSupplier readHostedFieldValue(AnalysisField field, HostedMetaAccess hMetaAccess, JavaConstant receiver) { + boolean print = field.format("%H.%n").equals("jdk.vm.ci.runtime.JVMCI.runtime"); + if (print) System.out.println("Reading value for " + field); + if (print) System.out.println("Wrapped: " + field.wrapped); if (classInitializationSupport.shouldInitializeAtRuntime(field.getDeclaringClass())) { + if (print) System.out.println("Should initialize at runtime"); if (field.isStatic()) { - return ValueSupplier.eagerValue(readUninitializedStaticValue(field)); + JavaConstant value = readUninitializedStaticValue(field); + if (print) System.out.println("Returning eager uninitialized " + value); + return ValueSupplier.eagerValue(value); } else { /* * Classes that are initialized at run time must not have instances in the image @@ -122,10 +128,15 @@ public ValueSupplier readHostedFieldValue(AnalysisField field, Hos } if (field.wrapped instanceof ReadableJavaField) { + if (print) System.out.println("Field is readable"); ReadableJavaField readableField = (ReadableJavaField) field.wrapped; if (readableField.isValueAvailableBeforeAnalysis()) { + if (print) System.out.println("Value available before analysis"); /* Materialize and return the value. */ - return ValueSupplier.eagerValue(universe.lookup(readableField.readValue(metaAccess, receiver))); + JavaConstant value = readableField.readValue(metaAccess, receiver); + JavaConstant lookup = universe.lookup(value); + if (print) System.out.println("Value is " + lookup + " from " + value); + return ValueSupplier.eagerValue(lookup); } else { /* * Return a lazy value. This applies to RecomputeFieldValue.Kind.FieldOffset and @@ -134,11 +145,15 @@ public ValueSupplier readHostedFieldValue(AnalysisField field, Hos * ComputedValueField.processSubstrate() or by ComputedValueField.readValue(). * Attempts to materialize the value earlier will result in an error. */ + if (print) System.out.println("Returning lazy value"); return ValueSupplier.lazyValue(() -> universe.lookup(readableField.readValue(hMetaAccess, receiver)), readableField::isValueAvailable); } } - return ValueSupplier.eagerValue(universe.lookup(originalConstantReflection.readFieldValue(field.wrapped, receiver))); + JavaConstant value = originalConstantReflection.readFieldValue(field.wrapped, receiver); + JavaConstant lookup = universe.lookup(value); + if (print) System.out.println("Returning eager value " + lookup + " from " + value); + return ValueSupplier.eagerValue(lookup); } /* diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java index 94625fb2cd9f3..93f6f5f791416 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java @@ -117,6 +117,9 @@ public boolean isValueAvailable(AnalysisField field) { @Override protected ValueSupplier readHostedFieldValue(AnalysisField field, JavaConstant receiver) { + if (field.format("%H.%n").equals("jdk.vm.ci.runtime.JVMCI.runtime")) { + System.out.println("Found"); + } AnalysisConstantReflectionProvider aConstantReflection = (AnalysisConstantReflectionProvider) this.constantReflection; return aConstantReflection.readHostedFieldValue(field, hostedMetaAccess, receiver); } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java index a3cd19c034bde..efaa1972ff325 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/substitute/AnnotationSubstitutionProcessor.java @@ -325,7 +325,9 @@ public void init() { } List annotatedFields = imageClassLoader.findAnnotatedFields(NativeImageReinitialize.class); + System.out.println("Native Image reinitialize fields: "); for (Field annotatedField : annotatedFields) { + System.out.println(annotatedField); reinitializeField(annotatedField); } } diff --git a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/SubstrateAnnotationExtracter.java b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/SubstrateAnnotationExtracter.java index 43dbc67a561f2..4c5c7ffc9ebb8 100644 --- a/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/SubstrateAnnotationExtracter.java +++ b/substratevm/src/com.oracle.svm.util/src/com/oracle/svm/util/SubstrateAnnotationExtracter.java @@ -413,14 +413,15 @@ private static Class extractType(ByteBuffer buf, ConstantPool cp, Class co return null; } Class type; + String signature = cp.getUTF8At(typeIndex); try { - String signature = cp.getUTF8At(typeIndex); type = (Class) annotationParserParseSig.invoke(null, signature, container); } catch (InvocationTargetException e) { Throwable targetException = e.getTargetException(); if (targetException instanceof LinkageError || targetException instanceof TypeNotPresentException) { return null; } + System.out.println("Parsing " + signature + " for container " + container); throw new AnnotationExtractionError(e); } catch (ReflectiveOperationException e) { throw new AnnotationExtractionError(e);