Skip to content

Commit

Permalink
Add CausalityExporter without JVMTI Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristophTF committed Oct 30, 2024
1 parent 4e691ab commit 619c754
Show file tree
Hide file tree
Showing 91 changed files with 5,744 additions and 242 deletions.
2 changes: 2 additions & 0 deletions substratevm/mx.substratevm/suite.py
Original file line number Diff line number Diff line change
Expand Up @@ -2103,6 +2103,8 @@
"com.oracle.graal.pointsto.heap",
"com.oracle.graal.pointsto.heap.value",
"com.oracle.graal.pointsto.reports",
"com.oracle.graal.pointsto.reports.causality",
"com.oracle.graal.pointsto.reports.causality.facts",
"com.oracle.graal.pointsto.constraints",
"com.oracle.graal.pointsto.util",
"com.oracle.graal.pointsto.meta",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
package com.oracle.graal.pointsto;

import com.oracle.graal.pointsto.ObjectScanner.ScanReason;
import com.oracle.graal.pointsto.reports.causality.Causality;
import com.oracle.graal.pointsto.reports.causality.facts.Facts;
import com.oracle.graal.pointsto.flow.ArrayElementsTypeFlow;
import com.oracle.graal.pointsto.flow.FieldTypeFlow;
import com.oracle.graal.pointsto.flow.context.object.AnalysisObject;
Expand Down Expand Up @@ -73,6 +75,7 @@ public boolean forNonNullFieldValue(JavaConstant receiver, AnalysisField field,
/* Add the constant value object to the field's type flow. */
FieldTypeFlow fieldTypeFlow = getFieldTypeFlow(field, receiver);
/* Add the new constant to the field's flow state. */
Causality.registerTypeEntering(analysis, Causality.getHeapFieldAssigner(analysis, receiver, field, fieldValue), fieldTypeFlow, fieldType);
return fieldTypeFlow.addState(analysis, bb.analysisPolicy().constantTypeState(analysis, fieldValue, fieldType));
}

Expand Down Expand Up @@ -121,6 +124,7 @@ public boolean forNonNullArrayElement(JavaConstant array, AnalysisType arrayType
ArrayElementsTypeFlow arrayObjElementsFlow = getArrayElementsFlow(array, arrayType);
PointsToAnalysis analysis = getAnalysis();
/* Add the constant element to the constant's array type flow. */
Causality.registerTypeEntering(analysis, Causality.getHeapArrayAssigner(analysis, array, elementIndex, elementConstant), arrayObjElementsFlow, elementType);
return arrayObjElementsFlow.addState(analysis, bb.analysisPolicy().constantTypeState(analysis, elementConstant, elementType));
}

Expand All @@ -134,12 +138,17 @@ private ArrayElementsTypeFlow getArrayElementsFlow(JavaConstant array, AnalysisT
}

@Override
@SuppressWarnings("try")
public void forScannedConstant(JavaConstant value, ScanReason reason) {
PointsToAnalysis analysis = getAnalysis();
Object valueObj = analysis.getSnippetReflectionProvider().asObject(Object.class, value);
AnalysisType type = bb.getMetaAccess().lookupJavaType(valueObj.getClass());

type.registerAsInstantiated(reason);
var inHeap = Facts.TypeInHeap.create(type);
Causality.registerEdgeFromHeapObject(analysis, value, reason, inHeap);
try (var ignored = Causality.setCause(inHeap)) {
type.registerAsInstantiated(reason);
}
}

private PointsToAnalysis getAnalysis() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.atomic.AtomicInteger;

import com.oracle.graal.pointsto.reports.causality.Causality;
import com.oracle.graal.pointsto.reports.causality.facts.Facts;
import org.graalvm.word.WordBase;

import com.oracle.graal.pointsto.constraints.UnsupportedFeatureException;
Expand Down Expand Up @@ -441,10 +443,15 @@ public static String limit(String value, int length) {
* using the constant as a receiver. If the constant has an array class then it scans the array
* element constants.
*/
@SuppressWarnings("try")
private void doScan(WorklistEntry entry) {
try {
AnalysisType type = bb.getMetaAccess().lookupJavaType(entry.constant);
type.registerAsReachable(entry.reason);
var inHeap = Facts.TypeInHeap.create(type);
Causality.registerEdgeFromHeapObject(bb, entry.constant, entry.reason, inHeap);
try (var ignored = Causality.setCause(inHeap)) {
type.registerAsReachable(entry.reason);
}

if (type.isInstanceClass()) {
/* Scan constant's instance fields. */
Expand Down Expand Up @@ -535,6 +542,10 @@ public ScanReason getPrevious() {
return previous;
}

public JavaConstant getConstant() {
return constant;
}

@SuppressWarnings("unused")
public String toString(BigBang bb) {
return toString();
Expand Down Expand Up @@ -701,6 +712,10 @@ public ArrayScan(AnalysisType arrayType, JavaConstant array, ScanReason previous
this.idx = idx;
}

public int getIndex() {
return idx;
}

@Override
public String toString(BigBang bb) {
return "indexing into array " + asString(bb, constant) + (idx != -1 ? " at index " + idx : "");
Expand Down Expand Up @@ -744,6 +759,10 @@ public AnalysisMethod getMethod() {
return method;
}

public BytecodePosition getPosition() {
return position;
}

@Override
public String toString(BigBang bb) {
return "scanning root " + asString(bb, constant) + " embedded in" + System.lineSeparator() + INDENTATION_AFTER_NEWLINE + asStackTraceElement();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
import com.oracle.graal.pointsto.meta.PointsToAnalysisField;
import com.oracle.graal.pointsto.meta.PointsToAnalysisMethod;
import com.oracle.graal.pointsto.reports.StatisticsPrinter;
import com.oracle.graal.pointsto.reports.causality.Causality;
import com.oracle.graal.pointsto.reports.causality.facts.Facts;
import com.oracle.graal.pointsto.typestate.AnyPrimitiveTypeState;
import com.oracle.graal.pointsto.typestate.PointsToStats;
import com.oracle.graal.pointsto.typestate.TypeState;
Expand Down Expand Up @@ -367,13 +369,15 @@ public AnalysisMethod addRootMethod(AnalysisMethod aMethod, boolean invokeSpecia
int paramCount = aMethod.getSignature().getParameterCount(!isStatic);
PointsToAnalysisMethod originalPTAMethod = assertPointsToAnalysisMethod(aMethod);

Causality.registerConsequence(Facts.RootMethodRegistration.create(aMethod));
if (isStatic) {
/*
* For static methods trigger analysis in the empty context. This will trigger parsing
* and return the method flows graph. Then the method parameter type flows are
* initialized with the corresponding parameter declared type.
*/
Consumer<PointsToAnalysisMethod> triggerStaticMethodFlow = (pointsToMethod) -> {
Causality.registerConsequence(Facts.MethodImplementationInvoked.create(pointsToMethod));
postTask(() -> {
pointsToMethod.registerAsDirectRootMethod(reason);
pointsToMethod.registerAsImplementationInvoked(reason.toString());
Expand Down Expand Up @@ -416,6 +420,9 @@ public AnalysisMethod addRootMethod(AnalysisMethod aMethod, boolean invokeSpecia
* (currently) used for runtime compilation; in this use case, all necessary linking
* will be done during callee resolution.
*/
if (invokeSpecial) {
Causality.registerConsequence(Facts.MethodReachable.create(originalPTAMethod));
}
postTask(() -> {
if (invokeSpecial) {
originalPTAMethod.registerAsDirectRootMethod(reason);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.oracle.graal.pointsto.flow;

import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.reports.causality.Causality;
import com.oracle.graal.pointsto.flow.context.AnalysisContext;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.typestate.TypeState;
Expand All @@ -43,10 +44,12 @@ public class CloneTypeFlow extends TypeFlow<BytecodePosition> {
/** The allocation context for the generated clone object. Null if this is not a clone. */
protected final AnalysisContext allocationContext;

@SuppressWarnings("this-escape")
public CloneTypeFlow(BytecodePosition cloneLocation, AnalysisType inputType, TypeFlow<?> input) {
super(cloneLocation, inputType);
this.allocationContext = null;
this.input = input;
Causality.registerTypeFlowEdge(input, this);
}

public CloneTypeFlow(PointsToAnalysis bb, CloneTypeFlow original, MethodFlowsGraph methodFlows, AnalysisContext allocationContext) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
package com.oracle.graal.pointsto.flow;

import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.reports.causality.Causality;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.typestate.TypeState;

Expand Down Expand Up @@ -64,6 +65,7 @@ public void initFlow(PointsToAnalysis bb) {
* sensitivity is enabled the default graph is kept clean and used as a template for clones.
*/
addState(bb, constantState);
Causality.registerTypeFlowEdge(null, this);
}

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

import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.reports.causality.Causality;
import com.oracle.graal.pointsto.flow.context.AnalysisContext;
import com.oracle.graal.pointsto.meta.AnalysisType;
import com.oracle.graal.pointsto.typestate.TypeState;
Expand Down Expand Up @@ -70,6 +71,7 @@ public void initFlow(PointsToAnalysis bb) {
assert !bb.usePredicates() || newTypeFlow.getPredicate() != null || MethodFlowsGraph.nonMethodFlow(newTypeFlow) : "Missing predicate for the flow " + newTypeFlow + ", which is input for " +
this;
newTypeFlow.addObserver(bb, this);
Causality.registerTypeFlowEdge(newTypeFlow, this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.PointsToAnalysis;
import com.oracle.graal.pointsto.reports.causality.Causality;
import com.oracle.graal.pointsto.flow.context.object.AnalysisObject;
import com.oracle.graal.pointsto.meta.AnalysisMethod;
import com.oracle.graal.pointsto.meta.AnalysisType;
Expand Down Expand Up @@ -210,6 +211,7 @@ protected void updateReceiver(PointsToAnalysis bb, MethodFlowsGraphInfo calleeFl
FormalReceiverTypeFlow formalReceiverFlow = calleeFlows.getFormalReceiver();
if (formalReceiverFlow != null) {
formalReceiverFlow.addReceiverState(bb, receiverTypeState);
Causality.registerTypeFlowEdge(getReceiver(), formalReceiverFlow);
}
}

Expand All @@ -222,6 +224,7 @@ protected void updateReceiver(PointsToAnalysis bb, MethodFlowsGraphInfo calleeFl
* See also InvokeTypeFlow#linkReturn() for more details.
*/
actualReturn.addState(bb, receiverTypeState);
Causality.registerTypeFlowEdge(getReceiver(), actualReturn);
}
}
}
Expand Down
Loading

0 comments on commit 619c754

Please sign in to comment.