Skip to content

Commit

Permalink
[GR-22304] Do not keep Graal graphs reachable during static analysis.
Browse files Browse the repository at this point in the history
PullRequest: graal/5911
  • Loading branch information
Christian Wimmer committed Apr 10, 2020
2 parents 277c777 + 80d5b3d commit ed1e408
Show file tree
Hide file tree
Showing 50 changed files with 429 additions and 447 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,7 @@
import org.graalvm.compiler.debug.DebugContext.Builder;
import org.graalvm.compiler.debug.DebugHandlersFactory;
import org.graalvm.compiler.debug.Indent;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeSourcePosition;
import org.graalvm.compiler.nodes.CallTargetNode;
import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.nodes.spi.Replacements;
import org.graalvm.compiler.options.OptionValues;
import org.graalvm.compiler.printer.GraalDebugHandlersFactory;
Expand Down Expand Up @@ -85,6 +82,7 @@
import com.oracle.graal.pointsto.util.Timer.StopTimer;
import com.oracle.svm.util.ImageGeneratorThreadMarker;

import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.common.JVMCIError;
import jdk.vm.ci.meta.ConstantReflectionProvider;
import jdk.vm.ci.meta.JavaConstant;
Expand Down Expand Up @@ -209,8 +207,8 @@ public void registerUnsafeStore(AbstractUnsafeStoreTypeFlow unsafeStore) {
unsafeStores.putIfAbsent(unsafeStore, true);
}

public void reportIllegalUnknownUse(AnalysisMethod method, Node source, String message) {
String trace = "Location: " + (source.getNodeSourcePosition() == null ? "[unknown]" : method.asStackTraceElement(source.getNodeSourcePosition().getBCI()).toString()) + "\n";
public void reportIllegalUnknownUse(AnalysisMethod method, BytecodePosition source, String message) {
String trace = "Location: " + (source == null ? "[unknown]" : source.getMethod().asStackTraceElement(source.getBCI()).toString()) + "\n";
trace += "Call path:";
getUnsupportedFeatures().addMessage(method.format("%H.%n(%p)"), method, message, trace);
}
Expand Down Expand Up @@ -593,16 +591,6 @@ public boolean doTypeflow() throws InterruptedException {
return didSomeWork;
}

/**
* Check if the type is allowed to be used for synchronization.
*
* @param method - the method location of the synchronization
* @param bci - the bci location of the synchronization
* @param aType - the type that is synchronized on
*/
public void checkUnsupportedSynchronization(AnalysisMethod method, int bci, AnalysisType aType) {
}

private ReusableSet scannedObjects = new ReusableSet();

@SuppressWarnings("try")
Expand Down Expand Up @@ -768,12 +756,6 @@ public void addCompleted(DebugContextRunnable r, long nanos) {
if (nanos > 500_000_000L && r instanceof TypeFlowRunnable) {
TypeFlow<?> tf = ((TypeFlowRunnable) r).getTypeFlow();
String source = String.valueOf(tf.getSource());
if (tf.getSource() instanceof ValueNode) {
source = ((ValueNode) tf.getSource()).graph().method().format("%h.%n") + "@" + tf.getSource();
if (tf.getSource() instanceof CallTargetNode) {
source += "=" + ((CallTargetNode) tf.getSource()).targetName();
}
}
System.out.format("LONG RUNNING %.2f %s %x %s state %s %x uses %d observers %d%n", (double) nanos / 1_000_000_000, tf.getClass().getSimpleName(), System.identityHashCode(tf),
source, PointsToStats.asString(tf.getState()), System.identityHashCode(tf.getState()), tf.getUses().size(), tf.getObservers().size());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.concurrent.ConcurrentMap;

import org.graalvm.compiler.nodes.Invoke;
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
import org.graalvm.compiler.options.OptionValues;

import com.oracle.graal.pointsto.api.PointstoOptions;
Expand Down Expand Up @@ -59,6 +58,7 @@
import com.oracle.graal.pointsto.typestore.UnifiedArrayElementsTypeStore;
import com.oracle.graal.pointsto.typestore.UnifiedFieldTypeStore;

import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.meta.JavaConstant;

public class BytecodeSensitiveAnalysisPolicy extends AnalysisPolicy {
Expand Down Expand Up @@ -206,7 +206,7 @@ protected BytecodeSensitiveVirtualInvokeTypeFlow(BigBang bb, MethodFlowsGraph me
}

@Override
public TypeFlow<MethodCallTargetNode> copy(BigBang bb, MethodFlowsGraph methodFlows) {
public TypeFlow<BytecodePosition> copy(BigBang bb, MethodFlowsGraph methodFlows) {
return new BytecodeSensitiveVirtualInvokeTypeFlow(bb, methodFlows, this);
}

Expand Down Expand Up @@ -287,7 +287,7 @@ private BytecodeSensitiveSpecialInvokeTypeFlow(BigBang bb, MethodFlowsGraph meth
}

@Override
public TypeFlow<MethodCallTargetNode> copy(BigBang bb, MethodFlowsGraph methodFlows) {
public TypeFlow<BytecodePosition> copy(BigBang bb, MethodFlowsGraph methodFlows) {
return new BytecodeSensitiveSpecialInvokeTypeFlow(bb, methodFlows, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.util.List;

import org.graalvm.compiler.nodes.Invoke;
import org.graalvm.compiler.nodes.java.MethodCallTargetNode;
import org.graalvm.compiler.options.OptionValues;

import com.oracle.graal.pointsto.flow.AbstractSpecialInvokeTypeFlow;
Expand All @@ -54,6 +53,7 @@
import com.oracle.graal.pointsto.typestore.UnifiedArrayElementsTypeStore;
import com.oracle.graal.pointsto.typestore.UnifiedFieldTypeStore;

import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.meta.JavaConstant;

public class DefaultAnalysisPolicy extends AnalysisPolicy {
Expand Down Expand Up @@ -163,7 +163,7 @@ protected DefaultVirtualInvokeTypeFlow(BigBang bb, MethodFlowsGraph methodFlows,
}

@Override
public TypeFlow<MethodCallTargetNode> copy(BigBang bb, MethodFlowsGraph methodFlows) {
public TypeFlow<BytecodePosition> copy(BigBang bb, MethodFlowsGraph methodFlows) {
return new DefaultVirtualInvokeTypeFlow(bb, methodFlows, this);
}

Expand Down Expand Up @@ -245,7 +245,7 @@ private DefaultSpecialInvokeTypeFlow(BigBang bb, MethodFlowsGraph methodFlows, D
}

@Override
public TypeFlow<MethodCallTargetNode> copy(BigBang bb, MethodFlowsGraph methodFlows) {
public TypeFlow<BytecodePosition> copy(BigBang bb, MethodFlowsGraph methodFlows) {
return new DefaultSpecialInvokeTypeFlow(bb, methodFlows, this);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.MapCursor;
import org.graalvm.compiler.debug.DebugContext;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.graph.NodeSourcePosition;
import org.graalvm.compiler.nodes.ConstantNode;
import org.graalvm.word.WordBase;

import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException;
Expand All @@ -48,6 +47,7 @@
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.graal.pointsto.util.CompletionExecutor;

import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;

Expand Down Expand Up @@ -119,22 +119,20 @@ public void run(DebugContext debug) {
methods = methodsList;
}
for (AnalysisMethod method : methods) {
if (method.getTypeFlow().getGraph() != null) {
if (exec != null) {
workInProgressCount.incrementAndGet();
exec.execute(new CompletionExecutor.DebugContextRunnable() {
@Override
public void run(DebugContext debug) {
try {
scanMethod(method);
} finally {
workInProgressCount.decrementAndGet();
}
if (exec != null) {
workInProgressCount.incrementAndGet();
exec.execute(new CompletionExecutor.DebugContextRunnable() {
@Override
public void run(DebugContext debug) {
try {
scanMethod(method);
} finally {
workInProgressCount.decrementAndGet();
}
});
} else {
scanMethod(method);
}
}
});
} else {
scanMethod(method);
}
}

Expand Down Expand Up @@ -392,13 +390,11 @@ assert checkCorrectClassloaders(entry, valueObj) : "Invalid classloader " + valu

private void scanMethod(AnalysisMethod method) {
try {
for (Node n : method.getTypeFlow().getGraph().getNodes()) {
if (n instanceof ConstantNode) {
ConstantNode cn = (ConstantNode) n;
JavaConstant c = (JavaConstant) cn.getValue();
if (c.getJavaKind() == JavaKind.Object) {
scanConstant(c, new MethodScan(method, cn.getNodeSourcePosition()));
}
EconomicMap<JavaConstant, BytecodePosition> objectConstants = method.getTypeFlow().getObjectConstants();
if (objectConstants != null) {
MapCursor<JavaConstant, BytecodePosition> cursor = objectConstants.getEntries();
while (cursor.advance()) {
scanConstant(cursor.getKey(), new MethodScan(method, cursor.getValue()));
}
}
} catch (UnsupportedFeatureException ex) {
Expand Down Expand Up @@ -560,9 +556,9 @@ public String toString() {

protected static class MethodScan implements ScanReason {
final AnalysisMethod method;
final NodeSourcePosition sourcePosition;
final BytecodePosition sourcePosition;

MethodScan(AnalysisMethod method, NodeSourcePosition nodeSourcePosition) {
MethodScan(AnalysisMethod method, BytecodePosition nodeSourcePosition) {
this.method = method;
this.sourcePosition = nodeSourcePosition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import com.oracle.graal.pointsto.flow.InvokeTypeFlow;
import com.oracle.graal.pointsto.meta.AnalysisMethod;

import jdk.vm.ci.code.BytecodePosition;

public final class ShortestInvokeChainPrinter {

static class Element {
Expand Down Expand Up @@ -95,7 +97,8 @@ private static void printPath(Element start, PrintStream out) {
Element cur = start;
out.print("\tat " + cur.method.asStackTraceElement(0));
while (cur.parent != null) {
out.print("\n\tat " + cur.parent.method.asStackTraceElement(cur.invoke.getSource().invoke().bci()));
BytecodePosition source = cur.invoke.getSource();
out.print("\n\tat " + source.getMethod().asStackTraceElement(source.getBCI()));
cur = cur.parent;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ protected AbstractVirtualInvokeTypeFlow(BigBang bb, MethodFlowsGraph methodFlows
super(bb, methodFlows, original);
}

@Override
public final boolean isDirectInvoke() {
return false;
}

@Override
public boolean addState(BigBang bb, TypeState add, boolean postFlow) {
throw AnalysisError.shouldNotReachHere("The VirtualInvokeTypeFlow should not be updated directly.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,21 @@
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.typestate.TypeState;

import jdk.vm.ci.code.BytecodePosition;

/** The base class for a field store or load operation type flow. */
public abstract class AccessFieldTypeFlow<T extends AccessFieldNode> extends TypeFlow<T> {
public abstract class AccessFieldTypeFlow extends TypeFlow<BytecodePosition> {

/** The field that this flow stores into or loads from. */
protected final AnalysisField field;

protected AccessFieldTypeFlow(T node) {
protected AccessFieldTypeFlow(AccessFieldNode node) {
/* The declared type of a field access node is the field declared type. */
super(node, ((AnalysisField) node.field()).getType());
super(node.getNodeSourcePosition(), ((AnalysisField) node.field()).getType());
this.field = (AnalysisField) node.field();
}

protected AccessFieldTypeFlow(AccessFieldTypeFlow<T> original, MethodFlowsGraph methodFlows) {
protected AccessFieldTypeFlow(AccessFieldTypeFlow original, MethodFlowsGraph methodFlows) {
super(original, methodFlows);
this.field = original.field;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@
package com.oracle.graal.pointsto.flow;

import org.graalvm.compiler.nodes.ValueNode;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.meta.AnalysisType;

public class ActualReturnTypeFlow extends TypeFlow<ValueNode> {
import jdk.vm.ci.code.BytecodePosition;

public class ActualReturnTypeFlow extends TypeFlow<BytecodePosition> {
private InvokeTypeFlow invokeFlow;

public ActualReturnTypeFlow(ValueNode source, AnalysisType declaredType) {
super(source, declaredType);
assert this.source != null : this;
super(source.getNodeSourcePosition(), declaredType);
}

public ActualReturnTypeFlow(ActualReturnTypeFlow original, MethodFlowsGraph methodFlows) {
Expand All @@ -43,7 +45,7 @@ public ActualReturnTypeFlow(ActualReturnTypeFlow original, MethodFlowsGraph meth
}

@Override
public TypeFlow<ValueNode> copy(BigBang bb, MethodFlowsGraph methodFlows) {
public TypeFlow<BytecodePosition> copy(BigBang bb, MethodFlowsGraph methodFlows) {
return new ActualReturnTypeFlow(this, methodFlows);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,29 @@
package com.oracle.graal.pointsto.flow;

import org.graalvm.compiler.nodes.ValueNode;
import org.graalvm.compiler.replacements.nodes.ArrayCopy;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.api.PointstoOptions;
import com.oracle.graal.pointsto.flow.context.object.AnalysisObject;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.typestate.TypeState;

import org.graalvm.compiler.replacements.nodes.ArrayCopy;
import jdk.vm.ci.code.BytecodePosition;

/**
* Models the flow transfer of an {@link ArrayCopy} node which intrinsifies calls to
* System.arraycopy(). This flow registers itself as an observer for both the source and the
* destination. When either the source or the destination elements change the element flows from
* source are passed to destination.
*/
public class ArrayCopyTypeFlow extends TypeFlow<ValueNode> {
public class ArrayCopyTypeFlow extends TypeFlow<BytecodePosition> {

TypeFlow<?> srcArrayFlow;
TypeFlow<?> dstArrayFlow;

public ArrayCopyTypeFlow(ValueNode source, AnalysisType declaredType, TypeFlow<?> srcArrayFlow, TypeFlow<?> dstArrayFlow) {
super(source, declaredType);
super(source.getNodeSourcePosition(), declaredType);
this.srcArrayFlow = srcArrayFlow;
this.dstArrayFlow = dstArrayFlow;
}
Expand All @@ -57,7 +59,7 @@ public ArrayCopyTypeFlow(BigBang bb, ArrayCopyTypeFlow original, MethodFlowsGrap
}

@Override
public TypeFlow<ValueNode> copy(BigBang bb, MethodFlowsGraph methodFlows) {
public TypeFlow<BytecodePosition> copy(BigBang bb, MethodFlowsGraph methodFlows) {
return new ArrayCopyTypeFlow(bb, this, methodFlows);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
package com.oracle.graal.pointsto.flow;

import org.graalvm.compiler.nodes.ValueNode;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.flow.context.BytecodeLocation;
import com.oracle.graal.pointsto.meta.AnalysisType;

import jdk.vm.ci.code.BytecodePosition;

public class BoxTypeFlow extends NewInstanceTypeFlow {

public BoxTypeFlow(ValueNode node, AnalysisType type, BytecodeLocation boxSite) {
Expand All @@ -40,7 +43,7 @@ public BoxTypeFlow(BigBang bb, BoxTypeFlow original, MethodFlowsGraph methodFlow
}

@Override
public TypeFlow<ValueNode> copy(BigBang bb, MethodFlowsGraph methodFlows) {
public TypeFlow<BytecodePosition> copy(BigBang bb, MethodFlowsGraph methodFlows) {
return new BoxTypeFlow(bb, this, methodFlows);
}

Expand Down
Loading

0 comments on commit ed1e408

Please sign in to comment.