Skip to content

Commit 590890d

Browse files
committed
Allow re-scanning after analysis.
1 parent 7863bb3 commit 590890d

File tree

6 files changed

+22
-24
lines changed

6 files changed

+22
-24
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/HeapSnapshotVerifier.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import static com.oracle.graal.pointsto.ObjectScanner.ScanReason;
2828

2929
import java.util.Objects;
30+
import java.util.concurrent.ForkJoinPool;
3031
import java.util.function.Consumer;
3132

3233
import org.graalvm.compiler.options.Option;
@@ -73,6 +74,12 @@ public HeapSnapshotVerifier(BigBang bb, ImageHeap imageHeap, ImageHeapScanner sc
7374
verbosity = Options.HeapVerifierVerbosity.getValue(bb.getOptions());
7475
}
7576

77+
public boolean checkHeapSnapshot(UniverseMetaAccess metaAccess, ForkJoinPool threadPool, String stage) {
78+
CompletionExecutor executor = new CompletionExecutor(bb, threadPool, bb.getHeartbeatCallback());
79+
executor.init();
80+
return checkHeapSnapshot(metaAccess, executor, stage, false);
81+
}
82+
7683
/**
7784
* Heap verification does a complete scan from roots (static fields and embedded constant) and
7885
* compares the object graph against the shadow heap. If any new reachable objects or primitive

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/heap/ImageHeapScanner.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -522,15 +522,7 @@ public JavaConstant readFieldValue(AnalysisField field, JavaConstant receiver) {
522522
return constantReflection.readFieldValue(field, receiver);
523523
}
524524

525-
protected boolean skipScanning() {
526-
return false;
527-
}
528-
529525
public void rescanRoot(Field reflectionField) {
530-
if (skipScanning()) {
531-
return;
532-
}
533-
534526
maybeRunInExecutor(unused -> {
535527
AnalysisType type = metaAccess.lookupJavaType(reflectionField.getDeclaringClass());
536528
if (type.isReachable()) {
@@ -546,9 +538,6 @@ public void rescanRoot(Field reflectionField) {
546538
}
547539

548540
public void rescanField(Object receiver, Field reflectionField) {
549-
if (skipScanning()) {
550-
return;
551-
}
552541
maybeRunInExecutor(unused -> {
553542
AnalysisType type = metaAccess.lookupJavaType(reflectionField.getDeclaringClass());
554543
if (type.isReachable()) {
@@ -618,9 +607,6 @@ public void rescanObject(Object object) {
618607
* Add the object to the image heap.
619608
*/
620609
public void rescanObject(Object object, ScanReason reason) {
621-
if (skipScanning()) {
622-
return;
623-
}
624610
if (object == null) {
625611
return;
626612
}

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/AnalysisType.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ public enum UsageKind {
186186
private final AnalysisFuture<Void> initializeMetaDataTask;
187187

188188
/**
189-
* Additional information that is only available for types that are marked as reachable.
189+
* Additional information that is only available for types that are marked as reachable. It is
190+
* preserved after analysis.
190191
*/
191-
private AnalysisFuture<TypeData> typeData;
192+
private final AnalysisFuture<TypeData> typeData;
192193

193194
/**
194195
* Contains reachability handlers that are notified when any of the subtypes are marked as
@@ -347,7 +348,6 @@ public void cleanupAfterAnalysis() {
347348
constantObjectsCache = null;
348349
uniqueConstant = null;
349350
unsafeAccessedFields = null;
350-
typeData = null;
351351
scheduledTypeReachableNotifications = null;
352352
}
353353

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/meta/PointsToAnalysisMethod.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
public final class PointsToAnalysisMethod extends AnalysisMethod {
5050

5151
private MethodTypeFlow typeFlow;
52+
/** The parsing context in which given method was parsed, preserved after analysis. */
53+
private final Object parsingReason;
5254

5355
private Set<InvokeTypeFlow> invokedBy;
5456
private Set<InvokeTypeFlow> implementationInvokedBy;
@@ -69,11 +71,13 @@ public final class PointsToAnalysisMethod extends AnalysisMethod {
6971
public PointsToAnalysisMethod(AnalysisUniverse universe, ResolvedJavaMethod wrapped) {
7072
super(universe, wrapped, MultiMethod.ORIGINAL_METHOD, null);
7173
typeFlow = declaringClass.universe.analysisPolicy().createMethodTypeFlow(this);
74+
parsingReason = typeFlow.getParsingReason();
7275
}
7376

7477
private PointsToAnalysisMethod(AnalysisMethod original, MultiMethodKey multiMethodKey) {
7578
super(original, multiMethodKey);
7679
typeFlow = declaringClass.universe.analysisPolicy().createMethodTypeFlow(this);
80+
parsingReason = typeFlow.getParsingReason();
7781
}
7882

7983
@Override
@@ -149,7 +153,7 @@ public Iterable<? extends InvokeInfo> getInvokes() {
149153

150154
@Override
151155
public Object getParsingReason() {
152-
return typeFlow.getParsingReason();
156+
return parsingReason;
153157
}
154158

155159
public InvokeTypeFlow initAndGetContextInsensitiveInvoke(PointsToAnalysis bb, BytecodePosition originalLocation, boolean isSpecial, MultiMethodKey callerMultiMethodKey) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/NativeImageGenerator.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,10 @@ protected void doRun(Map<Method, CEntryPointData> entryPoints,
688688
featureHandler.forEachFeature(feature -> feature.afterCompilation(config));
689689
BuildPhaseProvider.markCompilationFinished();
690690
}
691+
692+
/* Re-run shadow heap verification after compilation. */
693+
aUniverse.getHeapVerifier().checkHeapSnapshot(hMetaAccess, compilationExecutor, "after compilation");
694+
691695
CodeCacheProvider codeCacheProvider = runtimeConfiguration.getBackendForNormalMethod().getProviders().getCodeCache();
692696
reporter.printCreationStart();
693697
try (Indent indent = debug.logAndIndent("create native image")) {
@@ -704,6 +708,9 @@ protected void doRun(Map<Method, CEntryPointData> entryPoints,
704708
AfterHeapLayoutAccessImpl config = new AfterHeapLayoutAccessImpl(featureHandler, loader, heap, hMetaAccess, debug);
705709
featureHandler.forEachFeature(feature -> feature.afterHeapLayout(config));
706710

711+
/* Re-run shadow heap verification after heap layout. */
712+
aUniverse.getHeapVerifier().checkHeapSnapshot(hMetaAccess, compilationExecutor, "after heap layout");
713+
707714
createAbstractImage(k, hostedEntryPoints, heap, hMetaAccess, codeCache);
708715

709716
if (ImageSingletons.contains(DynamicMethodAddressResolutionHostedSupport.class)) {

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/heap/SVMImageHeapScanner.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import com.oracle.graal.pointsto.heap.value.ValueSupplier;
4747
import com.oracle.graal.pointsto.meta.AnalysisField;
4848
import com.oracle.graal.pointsto.meta.AnalysisMetaAccess;
49-
import com.oracle.svm.core.BuildPhaseProvider;
5049
import com.oracle.svm.core.hub.DynamicHub;
5150
import com.oracle.svm.core.jdk.VarHandleFeature;
5251
import com.oracle.svm.core.util.VMError;
@@ -135,11 +134,6 @@ protected JavaConstant transformFieldValue(AnalysisField field, JavaConstant rec
135134
return ((AnalysisConstantReflectionProvider) constantReflection).interceptValue(metaAccess, field, originalValueConstant);
136135
}
137136

138-
@Override
139-
protected boolean skipScanning() {
140-
return BuildPhaseProvider.isAnalysisFinished();
141-
}
142-
143137
@Override
144138
protected void rescanEconomicMap(EconomicMap<?, ?> map) {
145139
super.rescanEconomicMap(map);

0 commit comments

Comments
 (0)