Skip to content

Commit 5d6ccf7

Browse files
committed
Improve comments.
1 parent 07e85b1 commit 5d6ccf7

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/ReachabilitySimplifier.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,18 +283,26 @@ protected String location(Node node) {
283283
return "method " + StrengthenGraphs.getQualifiedName(graph) + ", node " + node;
284284
}
285285

286+
/**
287+
* Tries to improve the stamp based on reachability information. It only handles
288+
* {@link AbstractObjectStamp object stamps} as all primitives types are considered implicitly
289+
* reachable and the analysis (reachability or points-to) doesn't track primitive ranges.
290+
* <p>
291+
* Returns a new {@link Stamp} if the input stamp can be improved, or {@code null} otherwise.
292+
*/
286293
private Stamp strengthenStamp(Stamp s) {
287294
if (!(s instanceof AbstractObjectStamp stamp)) {
295+
/* We can only strengthen object types. */
288296
return null;
289297
}
290298
AnalysisType originalType = (AnalysisType) stamp.type();
291299
if (originalType == null) {
300+
/* The stamp is either empty or a non-exact java.lang.Object; nothing to strengthen. */
292301
return null;
293302
}
294303

295304
/* In open world the type may become reachable later. */
296305
if (strengthenGraphs.isClosedTypeWorld && !originalType.isReachable()) {
297-
/* We must be in dead code. */
298306
if (stamp.nonNull()) {
299307
/* We must be in dead code. */
300308
return StampFactory.empty(JavaKind.Object);

substratevm/src/com.oracle.graal.pointsto/src/com/oracle/graal/pointsto/results/StrengthenGraphs.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,23 +243,26 @@ public final void applyResults(AnalysisMethod method) {
243243

244244
protected abstract void persistStrengthenGraph(AnalysisMethod method);
245245

246-
/*
246+
/**
247247
* Returns a type that can replace the original type in stamps as an exact type. When the
248248
* returned type is the original type itself, the original type has no subtype and can be used
249249
* as an exact type.
250-
*
251-
* Returns null if there is no single implementor type.
250+
* <p>
251+
* Returns {@code null} if there is no optimization potential, i.e., if the original type
252+
* doesn't have a unique implementor type, or we cannot prove that it has a unique implementor
253+
* type due to open-world analysis.
252254
*/
253255
protected abstract AnalysisType getSingleImplementorType(AnalysisType originalType);
254256

255-
/*
257+
/**
256258
* Returns a type that can replace the original type in stamps.
257-
*
258-
* Returns null if the original type has no assignable type that is instantiated, i.e., the code
259-
* using the type is unreachable.
260-
*
259+
* <p>
260+
* Returns {@code null} if the original type has no assignable type that is instantiated, i.e.,
261+
* the code using the type is unreachable.
262+
* <p>
261263
* Returns the original type itself if there is no optimization potential, i.e., if the original
262-
* type itself is instantiated or has more than one instantiated direct subtype.
264+
* type itself is instantiated or has more than one instantiated direct subtype, or we cannot
265+
* prove that it doesn't have any instantiated subtype due to open-world analysis.
263266
*/
264267
protected abstract AnalysisType getStrengthenStampType(AnalysisType originalType);
265268

substratevm/src/com.oracle.svm.hosted/src/com/oracle/svm/hosted/meta/HostedType.java

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ public abstract class HostedType extends HostedElement implements SharedType, Wr
6565

6666
boolean loadedFromPriorLayer;
6767
protected int typeID;
68-
protected HostedType uniqueConcreteImplementation;
6968
protected HostedMethod[] allDeclaredMethods;
7069

7170
// region closed-world only fields
@@ -140,13 +139,27 @@ public abstract class HostedType extends HostedElement implements SharedType, Wr
140139
// endregion open-world only fields
141140

142141
/**
143-
* A more precise subtype that can replace this type as the declared type of values. Null if
144-
* this type is never instantiated and does not have any instantiated subtype, i.e., if no value
145-
* of this type can ever exist. Equal to this type if this type is instantiated, i.e, this type
146-
* cannot be strengthened.
147-
*
148-
* For open world the strengthen stamp type is equal to this type itself if the type is not a
149-
* leaf type, i.e., it cannot be extended.
142+
* The unique implementor of this type that can replace it in stamps as an exact type.
143+
* <p>
144+
* A {@code null} value means there is no unique implementor that can replace this type. The
145+
* field is set to this type itself if it has no instantiated subtypes to enable its usage as an
146+
* exact type, e.g., in places where the original stamp was non-exact.
147+
* <p>
148+
* In open-world analysis the field is set to {@code null} for non-leaf types since we have to
149+
* assume that there may be some instantiated subtypes that we haven't seen yet.
150+
*/
151+
protected HostedType uniqueConcreteImplementation;
152+
153+
/**
154+
* A more precise subtype that can replace this type as the declared type of values.
155+
* <p>
156+
* A {@code null} value means that this type is never instantiated and does not have any
157+
* instantiated subtype, i.e., no value of this type can ever exist and the code using this type
158+
* is unreachable. It is set to this type if this type is itself instantiated or has more than
159+
* one instantiated direct subtype, i.e, this type cannot be strengthened.
160+
* <p>
161+
* In open-world analysis the field is set to this type itself for non-leaf types since we have
162+
* to assume that there may be some instantiated subtypes that we haven't seen yet.
150163
*/
151164
protected HostedType strengthenStampType;
152165

0 commit comments

Comments
 (0)