Skip to content

Commit

Permalink
Fix problems after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophTF committed Aug 7, 2024
1 parent 02a487d commit 1e8ea17
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -118,7 +117,7 @@ public void addVirtualInvokeTypeFlow(AbstractVirtualInvokeTypeFlow invocation) {
originalInvokeReceivers.put(invocation, invocation.getReceiver());
}

protected void forEachTypeflow(Consumer<TypeFlow<?>> callback) {
private void forEachTypeflow(Consumer<TypeFlow<?>> callback) {
for (var e : interflows.keySet()) {
callback.accept(e.getLeft());
callback.accept(e.getRight());
Expand All @@ -132,7 +131,7 @@ protected void forEachEvent(Consumer<CausalityEvent> 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 -> {
Expand Down Expand Up @@ -243,7 +242,7 @@ protected Graph createCausalityGraph(PointsToAnalysis bb) {
HashMap<TypeFlow<?>, Graph.RealFlowNode> flowMapping = new HashMap<>();

Function<TypeFlow<?>, Graph.RealFlowNode> flowMapper = flow -> {
if (flow.getState().typesCount() == 0 && !flow.isSaturated()) {
if (flow.getState().isPrimitive() || flow.getState().typesCount() == 0 && !flow.isSaturated()) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private static <T1, T2> EventFactory2<T1, T2> factory(BiFunction<T1, T2, Causali
public static final EventFactory<Consumer<DuringAnalysisAccess>> ReachabilityNotificationCallback = factory(ReachabilityNotificationCallback::new);
public static final EventFactory<BiConsumer<DuringAnalysisAccess, Class<?>>> SubtypeReachableNotificationCallback = factory(SubtypeReachableNotificationCallback::new);
public static final EventFactory<BiConsumer<DuringAnalysisAccess, Executable>> OverrideReachableNotificationCallback = factory(OverrideReachableNotificationCallback::new);
public static final EventFactory<String> ConfigurationCondition = factory(ConfigurationCondition::new);
public static final EventFactory<Class<?>> ConfigurationCondition = factory(ConfigurationCondition::new);
public static final EventFactory<URI> ConfigurationFile = factory(ConfigurationFile::new);
public static final EventFactory<Class<?>> UnknownHeapObject = factory(UnknownHeapObject::new);
public static final EventFactory<Class<?>> BuildTimeClassInitialization = factory(BuildTimeClassInitialization::new);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,9 +38,4 @@ public boolean essential() {
public EventKinds typeDescriptor() {
return EventKinds.ConfigurationCondition;
}

@Override
public String toString() {
return typeName + typeDescriptor().suffix;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -66,7 +66,7 @@ protected void registerConditionalConfiguration(ConfigurationCondition condition
}
if (beforeAnalysisAccess == null) {
Collection<Runnable> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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));
}

Expand Down Expand Up @@ -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);
}
}
}

Expand Down

0 comments on commit 1e8ea17

Please sign in to comment.