diff options
| author | Cliff Click <cliffc@acm.org> | 2026-12-06 09:38:15 -0800 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2026-12-06 09:38:15 -0800 |
| commit | 2867cd5bc0536c42ecce233d45598cca9d14b0bd (patch) | |
| tree | 042aaa42d905dfc6f6e6d7f8deffcd63fec050d2 | |
| parent | 1eae653085e812a7a86898196f2f526a474bbd36 (diff) | |
| download | Simple-2867cd5bc0536c42ecce233d45598cca9d14b0bd.tar.gz Simple-2867cd5bc0536c42ecce233d45598cca9d14b0bd.zip | |
Update PointsTo.javach33_try2
| -rw-r--r-- | chapter33/src/main/java/com/seaofnodes/simple/codegen/PointsTo.java | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/chapter33/src/main/java/com/seaofnodes/simple/codegen/PointsTo.java b/chapter33/src/main/java/com/seaofnodes/simple/codegen/PointsTo.java index ea4aaefe..d93ad3e3 100644 --- a/chapter33/src/main/java/com/seaofnodes/simple/codegen/PointsTo.java +++ b/chapter33/src/main/java/com/seaofnodes/simple/codegen/PointsTo.java @@ -8,15 +8,18 @@ import java.util.*; /** Flow-insensitive, field-sensitive, inclusion-based points-to analysis. * One abstract site per NewNode; calls share their callee's facts (context - * sensitivity comes from earlier inlining). Fields use weak updates and array - * indices share one field. This pass neither proves ownership nor changes IR. + * sensitivity comes from earlier inlining). Fields use weak updates and array + * indices share one field. * <p></p> - * Facts only grow. Reading a fact registers a dependency; changing it + * This is a Points-To analysis pass: it does not edit the graph; it does not + * decide object lifetimes, nor dictate malloc/free placement - those decisions + * build from this analysis. + * <p></p> + * Points-to facts only grow. Reading a fact registers a dependency; changing it * schedules its readers. Loads/stores discover field dependencies as their - * bases grow. Unknown denotes storage outside the local Site collection. + * bases grow. "Unknown" denotes storage outside the local Site collection. * Unloaded and native callees conservatively escape reference arguments and - * return unknown storage or compatible escaped sites. This is not an ownership - * or lifetime proof and does not authorize storage reclamation. + * return unknown storage or compatible escaped sites. */ public final class PointsTo { private final CodeGen _code; @@ -129,11 +132,13 @@ public final class PointsTo { // Merge Site into our existing Sites, return true if progress boolean merge( Site site ) { return _sites.add(site); } + // Merge and push changes to worklist void merge( Site site, WorkList<Node> work ) { if( merge(site) ) changed(work); } + // Merge all the Points-to with the correct Type, returning progress boolean merge( Points p, Type t ) { boolean progress = !_unknown && p._unknown && (_unknown = true); for( Site site : p._sites ) @@ -142,6 +147,7 @@ public final class PointsTo { return progress; } + // Merge all the Points-to, ignoring Type, returning progress boolean merge( Points p ) { return merge(p,(Type)null); } // Merge Points into self Points; queue readers if progress @@ -150,14 +156,15 @@ public final class PointsTo { changed(work); } + // Queue readers for the worklist void changed( WorkList<Node> work ) { if( _readers != null ) for( Node n : _readers.keySet() ) work.push(n); } + // Do we Point-to this particular site> public boolean contains(Site site) { - // Unknown sites are outside this collection. return _sites.contains(site); } @@ -247,18 +254,23 @@ public final class PointsTo { solve(); } - // Solve the points-to + // Solve the points-to; classic Monotone Analysis Framework private void solve() { Node n; while( (n = _work.pop()) != null ) transfer( n ); } + // Read the Points-to for some other Node, which means we become dependent + // on that other node. private Points read(Node node, Node dep) { return points(node).addDep(dep); } - // Transfer functions only update analysis facts, never IR or its worklist. + // Transfer functions: update the Points-to for `n` by looking at neighbors. + // No IR edits here, this is just an analysis phase. + // Monotonic: only adds edges. + // Updates the worklist for changes. private void transfer(Node n) { switch( n ) { case StoreNode store when store.val()._type instanceof TypeMemPtr -> { |
