Skip to content

Commit

Permalink
Respect condition in reflection registration
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophTF committed Sep 1, 2024
1 parent f3af70e commit 29166be
Show file tree
Hide file tree
Showing 6 changed files with 161 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@
import com.oracle.graal.pointsto.meta.AnalysisUniverse;
import com.oracle.graal.pointsto.meta.HostedProviders;
import com.oracle.graal.pointsto.reports.StatisticsPrinter;
import com.oracle.graal.pointsto.reports.causality.CausalityExport;
import com.oracle.graal.pointsto.reports.causality.events.CausalityEvent;
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.graal.pointsto.util.CompletionExecutor;
import com.oracle.graal.pointsto.util.Timer;
Expand Down Expand Up @@ -328,7 +330,30 @@ protected void schedule(Runnable task) {

@Override
public final void postTask(CompletionExecutor.DebugContextRunnable task) {
executor.execute(task);
CausalityEvent inheritedCause = CausalityExport.getCause();
if (inheritedCause == null) {
executor.execute(task);
} else {
// This branch would always be correct, but slower.
executor.execute(new CompletionExecutor.DebugContextRunnable() {
@Override
public void run(DebugContext debug) {
try (var ignored = CausalityExport.setCause(inheritedCause)) {
task.run(debug);
}
}

@Override
public DebugContext getDebug(OptionValues opts, List<DebugHandlersFactory> factories) {
return task.getDebug(opts, factories);
}

@Override
public DebugContext.Description getDescription() {
return task.getDescription();
}
});
}
}

public void postTask(final Runnable task) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ private static <T1, T2> EventFactory2<T1, T2> factory(BiFunction<T1, T2, Causali
public static final EventFactory<AnnotatedElement> JNIRegistration = factory(JNIRegistration::new);
public static final EventFactory<AnnotatedElement> ReflectionRegistration = factory(ReflectionRegistration::new);
public static final EventFactory<AnnotatedElement> ReflectionObjectInHeap = factory(ReflectionObjectInHeap::new);
public static final EventFactory<Object> DeferredTask = factory(DeferredTask::new);
public static final CausalityEvent AutomaticFeatureRegistration = new RootEvent(EventKinds.AutomaticFeatureRegistration);
public static final CausalityEvent UserEnabledFeatureRegistration = new RootEvent(EventKinds.UserRequestedFeatureRegistration);
public static final CausalityEvent InitialRegistration = new RootEvent(EventKinds.InitialRegistrations);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.oracle.graal.pointsto.reports.causality.events;

import java.util.Objects;

public final class DeferredTask extends CausalityEvent {
private final Object task;

public DeferredTask(Object task) {
this.task = task;
}

@Override
public String toString() {
return Objects.toIdentityString(task) + typeDescriptor().suffix;
}

@Override
public boolean essential() {
return false;
}

@Override
public EventKinds typeDescriptor() {
return EventKinds.DeferredTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public enum EventKinds {
SubtypeReachableNotificationCallback("Subtype Reachable Callback"),
SubtypeReachableNotificationCallbackInvocation("Subtype Reachable Callback Invocation"),

DeferredTask("Deferred Task"),

AutomaticFeatureRegistration("Automatic Feature Registration"),
UserRequestedFeatureRegistration("User-Requested Feature Registration"),
InitialRegistrations("Initial Registrations"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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.getType()));
handlers.add(() -> consumer.accept(runtimeCondition));
handlers.add(() -> consumer.accept(runtimeCondition));
} else {
beforeAnalysisAccess.registerReachabilityHandler(access -> consumer.accept(runtimeCondition), condition.getType());
}
Expand Down
Loading

0 comments on commit 29166be

Please sign in to comment.