Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,18 @@ public interface CompressibleConstant extends JavaConstant {
JavaConstant compress();

JavaConstant uncompress();

static JavaConstant uncompress(JavaConstant constant) {
if (constant instanceof CompressibleConstant compressible && compressible.isCompressed()) {
return compressible.uncompress();
}
return constant;
}

static boolean isCompressed(JavaConstant constant) {
if (constant instanceof CompressibleConstant compressible) {
return compressible.isCompressed();
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

package com.oracle.graal.pointsto.standalone;

import java.util.function.Predicate;

import com.oracle.graal.pointsto.BigBang;
import com.oracle.graal.pointsto.ObjectScanner;
import com.oracle.graal.pointsto.ObjectScanningObserver;
import com.oracle.graal.pointsto.meta.AnalysisField;
import com.oracle.graal.pointsto.util.CompletionExecutor;
import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.meta.JavaConstant;

import java.util.function.Predicate;
import jdk.vm.ci.meta.JavaConstant;

public class StandaloneObjectScanner extends ObjectScanner {

Expand All @@ -49,7 +49,7 @@ public StandaloneObjectScanner(BigBang bb, CompletionExecutor executor, Reusable
}

@Override
protected void scanEmbeddedRoot(JavaConstant root, BytecodePosition position) {
protected void scanEmbeddedRoot(JavaConstant root, Object position) {
if (shouldScanConstant.test(root)) {
super.scanEmbeddedRoot(root, position);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private boolean analysisModified() {
* checkHeapSnapshot returns all heap scanning and verification tasks are completed.
*/
assert executor.isBeforeStart() : executor.getState();
analysisModified = universe.getHeapVerifier().checkHeapSnapshot(metaAccess, executor, "during analysis", true);
analysisModified = universe.getHeapVerifier().checkHeapSnapshot(metaAccess, executor, "during analysis", true, universe.getEmbeddedRoots());
}
/* Initialize for the next iteration. */
executor.init(getTiming());
Expand Down Expand Up @@ -363,6 +363,10 @@ public static BytecodePosition sourcePosition(ValueNode node) {
}

/** Creates a synthetic position for the node in the given method. */
public static BytecodePosition syntheticSourcePosition(ResolvedJavaMethod method) {
return syntheticSourcePosition(null, method);
}

public static BytecodePosition syntheticSourcePosition(Node node, ResolvedJavaMethod method) {
int bci = BytecodeFrame.UNKNOWN_BCI;
if (node instanceof DeoptBciSupplier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
import com.oracle.graal.pointsto.util.AnalysisError;
import com.oracle.graal.pointsto.util.CompletionExecutor;

import jdk.graal.compiler.graph.NodeSourcePosition;
import jdk.vm.ci.code.BytecodePosition;
import jdk.vm.ci.meta.Constant;
import jdk.vm.ci.meta.JavaConstant;
import jdk.vm.ci.meta.JavaKind;
import jdk.vm.ci.meta.ResolvedJavaField;
Expand Down Expand Up @@ -85,10 +87,18 @@ public ObjectScanner(BigBang bb, CompletionExecutor executor, ReusableSet scanne
}

public void scanBootImageHeapRoots() {
scanBootImageHeapRoots(null, null);
scanBootImageHeapRoots(bb.getUniverse().getEmbeddedRoots());
}

public void scanBootImageHeapRoots(Comparator<AnalysisField> fieldComparator, Comparator<BytecodePosition> embeddedRootComparator) {
public void scanBootImageHeapRoots(Map<Constant, Object> embeddedConstants) {
scanBootImageHeapRoots(null, null, embeddedConstants);
}

public void scanBootImageHeapRoots(Comparator<AnalysisField> fieldComparator, Comparator<Object> embeddedRootComparator) {
scanBootImageHeapRoots(fieldComparator, embeddedRootComparator, bb.getUniverse().getEmbeddedRoots());
}

public void scanBootImageHeapRoots(Comparator<AnalysisField> fieldComparator, Comparator<Object> embeddedRootComparator, Map<Constant, Object> embeddedRoots) {
// scan the original roots
// the original roots are all the static fields, of object type, that were accessed
Collection<AnalysisField> fields = bb.getUniverse().getFields();
Expand All @@ -104,13 +114,15 @@ public void scanBootImageHeapRoots(Comparator<AnalysisField> fieldComparator, Co
}

// scan the constant nodes
Map<JavaConstant, BytecodePosition> embeddedRoots = bb.getUniverse().getEmbeddedRoots();
if (embeddedRootComparator != null) {
embeddedRoots.entrySet().stream()
.sorted(Map.Entry.comparingByValue(embeddedRootComparator))
.forEach(entry -> execute(() -> scanEmbeddedRoot(entry.getKey(), entry.getValue())));
.filter(entry -> entry.getKey() instanceof JavaConstant)
.forEach(entry -> execute(() -> scanEmbeddedRoot((JavaConstant) entry.getKey(), entry.getValue())));
} else {
embeddedRoots.forEach((key, value) -> execute(() -> scanEmbeddedRoot(key, value)));
embeddedRoots.entrySet().stream()
.filter(entry -> entry.getKey() instanceof JavaConstant)
.forEach(entry -> execute(() -> scanEmbeddedRoot((JavaConstant) entry.getKey(), entry.getValue())));
}

finish();
Expand All @@ -124,18 +136,17 @@ private void execute(Runnable runnable) {
}
}

protected void scanEmbeddedRoot(JavaConstant root, BytecodePosition position) {
protected void scanEmbeddedRoot(JavaConstant root, Object position) {
if (root instanceof ImageHeapConstant ihc && ihc.getHostedObject() == null) {
/* Skip embedded simulated constants. */
return;
}
EmbeddedRootScan reason = new EmbeddedRootScan(position, root);
try {
EmbeddedRootScan reason = new EmbeddedRootScan(position, root);
scanningObserver.forEmbeddedRoot(root, reason);
scanConstant(root, reason);
} catch (UnsupportedFeatureException ex) {
AnalysisMethod method = (AnalysisMethod) position.getMethod();
bb.getUnsupportedFeatures().addMessage(method.format("%H.%n(%p)"), method, ex.getMessage(), null, ex);
bb.getUnsupportedFeatures().addMessage(reason.toString(), reason.getMethod(), ex.getMessage(), null, ex);
}
}

Expand Down Expand Up @@ -520,6 +531,7 @@ public String toString(BigBang bb) {
}

public static class OtherReason extends ScanReason {
public static final ScanReason LATE_SCAN = new OtherReason("late scan, after sealing heap");
public static final ScanReason UNKNOWN = new OtherReason("manually created constant");
public static final ScanReason RESCAN = new OtherReason("manually triggered rescan");
public static final ScanReason HUB = new OtherReason("scanning a class constant");
Expand Down Expand Up @@ -673,29 +685,62 @@ public String toString() {
}

public static class EmbeddedRootScan extends ScanReason {
final BytecodePosition position;
private final BytecodePosition position;
private final AnalysisMethod method;
private final Object reason;

public EmbeddedRootScan(BytecodePosition nodeSourcePosition, JavaConstant root) {
this(nodeSourcePosition, root, new MethodParsing((AnalysisMethod) nodeSourcePosition.getMethod()));
public EmbeddedRootScan(Object reason, JavaConstant root) {
this(root, reason, rootScanReason(reason));
}

public EmbeddedRootScan(BytecodePosition nodeSourcePosition, JavaConstant root, ScanReason previous) {
private EmbeddedRootScan(JavaConstant root, Object reason, ScanReason previous) {
super(previous, root);
this.position = nodeSourcePosition;
this.reason = reason;
if (reason instanceof NodeSourcePosition src) {
this.position = src;
this.method = (AnalysisMethod) src.getMethod();
} else if (reason instanceof AnalysisMethod met) {
this.method = met;
this.position = null;
} else {
this.method = null;
this.position = null;
}
}

public Object getReason() {
return reason;
}

public AnalysisMethod getMethod() {
return (AnalysisMethod) position.getMethod();
return method;
}

@Override
public String toString(BigBang bb) {
return "scanning root " + asString(bb, constant) + " embedded in " + System.lineSeparator() + INDENTATION_AFTER_NEWLINE + position.getMethod().asStackTraceElement(position.getBCI());
return "scanning root " + asString(bb, constant) + " embedded in " + System.lineSeparator() + INDENTATION_AFTER_NEWLINE + asStackTraceElement();
}

@Override
public String toString() {
return position.getMethod().asStackTraceElement(position.getBCI()).toString();
return asStackTraceElement();
}

private static ScanReason rootScanReason(Object reason) {
if (reason instanceof NodeSourcePosition position) {
return new MethodParsing((AnalysisMethod) position.getMethod());
}
return new OtherReason(reason.toString());
}

private String asStackTraceElement() {
if (position != null) {
return String.valueOf(method.asStackTraceElement(position.getBCI()));
} else if (method != null) {
return String.valueOf(method.asStackTraceElement(0));
} else {
return "<unknown>";
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,15 +228,15 @@ private boolean parse(Object reason, boolean forceReparse) {
}

// Do it again after canonicalization changed type checks and field accesses.
registerUsedElements(bb, graph, true);
registerUsedElements(bb, graph);

return true;
} catch (Throwable ex) {
throw graph.getDebug().handle(ex);
}
}

protected static void registerUsedElements(PointsToAnalysis bb, StructuredGraph graph, boolean registerEmbeddedRoots) {
protected static void registerUsedElements(PointsToAnalysis bb, StructuredGraph graph) {
PointsToAnalysisMethod method = (PointsToAnalysisMethod) graph.method();
HostedProviders providers = bb.getProviders(method);
for (Node n : graph.getNodes()) {
Expand Down Expand Up @@ -310,7 +310,7 @@ protected static void registerUsedElements(PointsToAnalysis bb, StructuredGraph
assert StampTool.isExactType(cn) : cn;
AnalysisType type = (AnalysisType) StampTool.typeOrNull(cn, bb.getMetaAccess());
type.registerAsInHeap(new EmbeddedRootScan(AbstractAnalysisEngine.sourcePosition(cn), root));
if (registerEmbeddedRoots && !ignoreConstant(bb, cn)) {
if (!ignoreConstant(bb, cn)) {
registerEmbeddedRoot(bb, cn);
}
}
Expand Down
Loading