From 1e8ea175e28b31fdb8ee1cd1a2763e1f87d4cdd8 Mon Sep 17 00:00:00 2001 From: Christoph Blumschein Date: Wed, 7 Aug 2024 19:42:38 +0200 Subject: [PATCH] Fix problems after merge --- .../graal/pointsto/heap/ImageHeapScanner.java | 12 ++++++------ .../pointsto/reports/causality/BasicImpl.java | 5 +++-- .../reports/causality/TypeflowImpl.java | 7 +++---- .../causality/events/CausalityEvents.java | 2 +- .../events/ConfigurationCondition.java | 13 +++---------- .../svm/core/hub/ClassForNameSupport.java | 6 ------ .../ConditionalConfigurationRegistry.java | 6 +++--- .../hosted/reflect/ReflectionDataBuilder.java | 18 +++++++++--------- 8 files changed, 28 insertions(+), 41 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 6c129b276079..a48d464da67f 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 @@ -32,10 +32,6 @@ import java.util.Optional; import java.util.function.Consumer; -import com.oracle.graal.pointsto.reports.causality.CausalityExport; -import com.oracle.graal.pointsto.reports.causality.events.CausalityEvent; -import com.oracle.graal.pointsto.reports.causality.events.CausalityEvents; -import com.oracle.graal.pointsto.reports.causality.events.UnknownHeapObject; import org.graalvm.collections.EconomicMap; import org.graalvm.collections.MapCursor; @@ -55,6 +51,10 @@ import com.oracle.graal.pointsto.meta.AnalysisMetaAccess; import com.oracle.graal.pointsto.meta.AnalysisType; import com.oracle.graal.pointsto.meta.AnalysisUniverse; +import com.oracle.graal.pointsto.reports.causality.CausalityExport; +import com.oracle.graal.pointsto.reports.causality.events.CausalityEvent; +import com.oracle.graal.pointsto.reports.causality.events.CausalityEvents; +import com.oracle.graal.pointsto.reports.causality.events.UnknownHeapObject; import com.oracle.graal.pointsto.util.AnalysisError; import com.oracle.graal.pointsto.util.AnalysisFuture; import com.oracle.graal.pointsto.util.CompletionExecutor; @@ -387,8 +387,8 @@ private ImageHeapInstance createImageHeapInstance(JavaConstant constant, Analysi // Objects created by the analysis itself would add too many types as roots... cause = CausalityEvents.Ignored; } - - CausalityEvent typeObjectInHeap = (asObject(constant) instanceof Class ? CausalityEvents.HeapObjectClass : CausalityEvents.HeapObjectDynamicHub) + + CausalityEvent typeObjectInHeap = (snippetReflection.asObject(Object.class, constant) instanceof Class ? CausalityEvents.HeapObjectClass : CausalityEvents.HeapObjectDynamicHub) .create(typeFromClassConstant.getJavaClass()); CausalityExport.registerEdge(cause, typeObjectInHeap); diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/BasicImpl.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/BasicImpl.java index 03e4c82a62f6..969c252b4d4e 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/BasicImpl.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/BasicImpl.java @@ -44,6 +44,7 @@ import com.oracle.graal.pointsto.heap.ImageHeapConstant; import com.oracle.graal.pointsto.heap.ImageHeapInstance; import com.oracle.graal.pointsto.heap.ImageHeapObjectArray; +import com.oracle.graal.pointsto.infrastructure.OriginalFieldProvider; import com.oracle.graal.pointsto.meta.AnalysisField; import com.oracle.graal.pointsto.meta.AnalysisMethod; import com.oracle.graal.pointsto.meta.AnalysisType; @@ -205,7 +206,7 @@ public CausalityEvent getHeapFieldAssigner(BigBang bb, JavaConstant receiver, An } else { o = asObject(bb, Object.class, value); Object original = originsOfReplacedObjects.getOrDefault(o, o); - java.lang.reflect.Field f = field.getJavaField(); + java.lang.reflect.Field f = OriginalFieldProvider.getJavaField(field.unwrapTowardsOriginalField()); Class declaringClass = f.getDeclaringClass(); responsible = HeapAssignmentTracing.getInstance().getClassResponsibleForStaticFieldWrite(declaringClass, f, original); } @@ -218,7 +219,7 @@ public CausalityEvent getHeapFieldAssigner(BigBang bb, JavaConstant receiver, An o = asObject(bb, Object.class, value); Object original = originsOfReplacedObjects.getOrDefault(o, o); - java.lang.reflect.Field f = field.getJavaField(); + java.lang.reflect.Field f = OriginalFieldProvider.getJavaField(field.unwrapTowardsOriginalField()); if (f.getDeclaringClass().isAssignableFrom(receiverO.getClass())) { responsible = HeapAssignmentTracing.getInstance().getClassResponsibleForNonstaticFieldWrite(receiverO, f, original); } else { diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/TypeflowImpl.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/TypeflowImpl.java index 265e0627cb3e..c3bbf0b3b738 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/TypeflowImpl.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/TypeflowImpl.java @@ -24,7 +24,6 @@ */ package com.oracle.graal.pointsto.reports.causality; -import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@ -118,7 +117,7 @@ public void addVirtualInvokeTypeFlow(AbstractVirtualInvokeTypeFlow invocation) { originalInvokeReceivers.put(invocation, invocation.getReceiver()); } - protected void forEachTypeflow(Consumer> callback) { + private void forEachTypeflow(Consumer> callback) { for (var e : interflows.keySet()) { callback.accept(e.getLeft()); callback.accept(e.getRight()); @@ -132,7 +131,7 @@ protected void forEachEvent(Consumer callback) { flowingFromHeap.keySet().stream().map(Pair::getLeft).forEach(callback); // TODO: Unsure about this - whether it is necessary and whether it is correct/complete - originalInvokeReceivers.keySet().stream().map(InvokeTypeFlow::getTargetMethod).flatMap(targetMethod -> Arrays.stream(targetMethod.getImplementations())) + originalInvokeReceivers.keySet().stream().map(InvokeTypeFlow::getTargetMethod).flatMap(targetMethod -> targetMethod.collectMethodImplementations(false).stream()) .map(CausalityEvents.MethodImplementationInvoked::create).forEach(callback); forEachTypeflow(tf -> { @@ -243,7 +242,7 @@ protected Graph createCausalityGraph(PointsToAnalysis bb) { HashMap, Graph.RealFlowNode> flowMapping = new HashMap<>(); Function, Graph.RealFlowNode> flowMapper = flow -> { - if (flow.getState().typesCount() == 0 && !flow.isSaturated()) { + if (flow.getState().isPrimitive() || flow.getState().typesCount() == 0 && !flow.isSaturated()) { return null; } diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/events/CausalityEvents.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/events/CausalityEvents.java index f742644ac9e2..f809f8d51ae6 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/events/CausalityEvents.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/events/CausalityEvents.java @@ -217,7 +217,7 @@ private static EventFactory2 factory(BiFunction> ReachabilityNotificationCallback = factory(ReachabilityNotificationCallback::new); public static final EventFactory>> SubtypeReachableNotificationCallback = factory(SubtypeReachableNotificationCallback::new); public static final EventFactory> OverrideReachableNotificationCallback = factory(OverrideReachableNotificationCallback::new); - public static final EventFactory ConfigurationCondition = factory(ConfigurationCondition::new); + public static final EventFactory> ConfigurationCondition = factory(ConfigurationCondition::new); public static final EventFactory ConfigurationFile = factory(ConfigurationFile::new); public static final EventFactory> UnknownHeapObject = factory(UnknownHeapObject::new); public static final EventFactory> BuildTimeClassInitialization = factory(BuildTimeClassInitialization::new); diff --git a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/events/ConfigurationCondition.java b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/events/ConfigurationCondition.java index 33edd9cfe285..1e9c7b3a752f 100644 --- a/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/events/ConfigurationCondition.java +++ b/substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/reports/causality/events/ConfigurationCondition.java @@ -24,11 +24,9 @@ */ package com.oracle.graal.pointsto.reports.causality.events; -public final class ConfigurationCondition extends CausalityEvent { - public final String typeName; - - ConfigurationCondition(String typeName) { - this.typeName = typeName; +public final class ConfigurationCondition extends ClassEvent { + ConfigurationCondition(Class type) { + super(type); } @Override @@ -40,9 +38,4 @@ public boolean essential() { public EventKinds typeDescriptor() { return EventKinds.ConfigurationCondition; } - - @Override - public String toString() { - return typeName + typeDescriptor().suffix; - } } diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java index bd835779df73..84ca0c021e61 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/hub/ClassForNameSupport.java @@ -41,8 +41,6 @@ import com.oracle.svm.core.util.ImageHeapMap; import com.oracle.svm.core.util.VMError; -import java.util.stream.StreamSupport; - @AutomaticallyRegisteredImageSingleton public final class ClassForNameSupport { @@ -236,8 +234,4 @@ public boolean canUnsafeInstantiateAsInstance(DynamicHub hub) { var conditionSet = unsafeInstantiatedClasses.get(DynamicHub.toClass(hub)); return conditionSet != null && conditionSet.satisfied(); } - - public static Class[] getSuccessfullyRegisteredClasses() { - return StreamSupport.stream(singleton().knownClasses.getValues().spliterator(), false).filter(o -> o instanceof Class).toArray(Class[]::new); - } } diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java index fb89c4232261..f444c716f164 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/ConditionalConfigurationRegistry.java @@ -31,11 +31,11 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.function.Consumer; -import com.oracle.graal.pointsto.reports.causality.CausalityExport; -import com.oracle.graal.pointsto.reports.causality.events.CausalityEvents; import org.graalvm.nativeimage.hosted.Feature; import org.graalvm.nativeimage.impl.ConfigurationCondition; +import com.oracle.graal.pointsto.reports.causality.CausalityExport; +import com.oracle.graal.pointsto.reports.causality.events.CausalityEvents; import com.oracle.svm.core.util.VMError; import com.oracle.svm.hosted.classinitialization.ClassInitializationSupport; @@ -66,7 +66,7 @@ protected void registerConditionalConfiguration(ConfigurationCondition condition } if (beforeAnalysisAccess == null) { Collection handlers = pendingReachabilityHandlers.computeIfAbsent(condition.getType(), key -> new ConcurrentLinkedQueue<>()); - CausalityExport.registerEvent(CausalityEvents.ConfigurationCondition.create(condition.getTypeName())); + CausalityExport.registerEvent(CausalityEvents.ConfigurationCondition.create(condition.getType())); handlers.add(() -> consumer.accept(runtimeCondition)); } else { beforeAnalysisAccess.registerReachabilityHandler(access -> consumer.accept(runtimeCondition), condition.getType()); diff --git a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java index 5e549ce26507..4e7be01890cb 100644 --- a/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java +++ b/substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/reflect/ReflectionDataBuilder.java @@ -80,11 +80,11 @@ 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.reports.causality.CausalityExport; +import com.oracle.graal.pointsto.reports.causality.events.CausalityEvents; import com.oracle.svm.core.MissingRegistrationUtils; import com.oracle.svm.core.configure.ConditionalRuntimeValue; import com.oracle.svm.core.configure.RuntimeConditionSet; -import com.oracle.graal.pointsto.reports.causality.CausalityExport; -import com.oracle.graal.pointsto.reports.causality.events.CausalityEvents; import com.oracle.svm.core.hub.ClassForNameSupport; import com.oracle.svm.core.hub.DynamicHub; import com.oracle.svm.core.reflect.SubstrateAccessor; @@ -365,10 +365,7 @@ public void register(ConfigurationCondition condition, boolean queriedOnly, Exec for (Executable executable : executables) { CausalityExport.registerEvent(CausalityEvents.ReflectionRegistration.create(executable)); } - runConditionalInAnalysisTask(condition, (cnd) -> { - // Causality-Merge-TODO: try-region for each executable in registerMethods() - registerMethods(cnd, queriedOnly, executables); - }); + runConditionalInAnalysisTask(condition, (cnd) -> registerMethods(cnd, queriedOnly, executables)); } @Override @@ -429,7 +426,9 @@ public void registerAllDeclaredConstructorsQuery(ConfigurationCondition conditio private void registerMethods(ConfigurationCondition cnd, boolean queriedOnly, Executable[] reflectExecutables) { for (Executable reflectExecutable : reflectExecutables) { - registerMethod(cnd, queriedOnly, reflectExecutable); + try (var ignored = CausalityExport.setCause(CausalityEvents.ReflectionRegistration.create(reflectExecutable))) { + registerMethod(cnd, queriedOnly, reflectExecutable); + } } } @@ -543,7 +542,6 @@ public void register(ConfigurationCondition condition, boolean finalIsWritable, for (Field field : fields) { CausalityExport.registerEvent(CausalityEvents.ReflectionRegistration.create(field)); } - // Causality-Merge-TODO: try-region in registerFields() runConditionalInAnalysisTask(condition, (cnd) -> registerFields(cnd, false, fields)); } @@ -584,7 +582,9 @@ public void registerAllDeclaredFieldsQuery(ConfigurationCondition condition, boo private void registerFields(ConfigurationCondition cnd, boolean queriedOnly, Field[] reflectFields) { for (Field reflectField : reflectFields) { - registerField(cnd, queriedOnly, reflectField); + try (var ignored = CausalityExport.setCause(CausalityEvents.ReflectionRegistration.create(reflectField))) { + registerField(cnd, queriedOnly, reflectField); + } } }