summaryrefslogtreecommitdiff
path: root/chapter33/src/main/java/com
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-12-04 14:46:06 -0800
committerCliff Click <cliffc@acm.org>2026-12-04 14:46:06 -0800
commitd9df5cddeaa20045f1194a4b250041cf88bb8845 (patch)
tree493c0ac8fd705032c4fd1bc9618a58d8945228ee /chapter33/src/main/java/com
parent57f2a6b71e449f323fa944b2d3e34e7fadd54e6d (diff)
downloadSimple-d9df5cddeaa20045f1194a4b250041cf88bb8845.tar.gz
Simple-d9df5cddeaa20045f1194a4b250041cf88bb8845.zip
Separate summary call dependencies from function escapes
Restore a discarded private initializer summary when a later inline import reveals its direct call. Keep class-init dependencies for cycle checking without publishing their function pointers. Cover escape separation and unloaded private initializer cycles; full make -k -j8 tests passes.
Diffstat (limited to 'chapter33/src/main/java/com')
-rw-r--r--chapter33/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java17
-rw-r--r--chapter33/src/main/java/com/seaofnodes/simple/codegen/FunctionSummary.java3
-rw-r--r--chapter33/src/main/java/com/seaofnodes/simple/node/CLInitNode.java4
-rw-r--r--chapter33/src/main/java/com/seaofnodes/simple/node/GlobalEscapeNode.java13
4 files changed, 25 insertions, 12 deletions
diff --git a/chapter33/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java b/chapter33/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
index 51a6a197..4b0e7de4 100644
--- a/chapter33/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
+++ b/chapter33/src/main/java/com/seaofnodes/simple/codegen/CodeGen.java
@@ -357,11 +357,26 @@ public class CodeGen {
// Return the <clinit> for a CompUnit
public FunNode link( CompUnit cu ) {
for( FunNode fun : _linker )
- if( fun!=null && fun._compunit == cu && fun.isClz() )
+ if( fun!=null && !fun.isDead() && fun._compunit == cu && fun.isClz() )
return fun;
return null;
}
+ // An inline import can reveal a call to a private initializer whose
+ // unused summary was deleted after SCCP. Recreate the wrapper from its
+ // saved metadata; this is a direct call, not a function-pointer escape.
+ public FunNode restoreClinit(CompUnit cu) {
+ if( cu==null || cu._obj==null ) return null;
+ ElfReader elf = getElf(cu._obj);
+ if( elf._nodes!=null ) return null;
+ for( FunctionSummary summary : elf._functions )
+ if( summary.name().equals(TypeStruct.addClzPrefix(cu._cname)+".<clinit>") ) {
+ if( _stop._inputs.find(cu._stop)==-1 ) _stop.addDef(cu._stop);
+ return summary.install(this,cu);
+ }
+ return null;
+ }
+
// Insert linker mapping from constant function signature to the function
// being called.
public void link(FunNode fun) {
diff --git a/chapter33/src/main/java/com/seaofnodes/simple/codegen/FunctionSummary.java b/chapter33/src/main/java/com/seaofnodes/simple/codegen/FunctionSummary.java
index 6cd4035d..18bd98e3 100644
--- a/chapter33/src/main/java/com/seaofnodes/simple/codegen/FunctionSummary.java
+++ b/chapter33/src/main/java/com/seaofnodes/simple/codegen/FunctionSummary.java
@@ -5,7 +5,7 @@ import com.seaofnodes.simple.type.*;
// The small, eagerly readable part of a function's serialized implementation.
record FunctionSummary(TypeFunPtr sig, TypeTuple state, String name, int size, int[] classDependencyFIDXs) {
- void install(CodeGen code, CompUnit cu) {
+ FunNode install(CodeGen code, CompUnit cu) {
FunNode fun = new FunNode(null,sig,name,cu,null,cu._start);
fun._approxUIDs=size;
fun.init();
@@ -24,5 +24,6 @@ record FunctionSummary(TypeFunPtr sig, TypeTuple state, String name, int size, i
fun.setRet(ret);
cu._stop.addDef(ret);
code.link(fun);
+ return fun;
}
}
diff --git a/chapter33/src/main/java/com/seaofnodes/simple/node/CLInitNode.java b/chapter33/src/main/java/com/seaofnodes/simple/node/CLInitNode.java
index fb762ff3..4a122090 100644
--- a/chapter33/src/main/java/com/seaofnodes/simple/node/CLInitNode.java
+++ b/chapter33/src/main/java/com/seaofnodes/simple/node/CLInitNode.java
@@ -129,6 +129,8 @@ public class CLInitNode extends CFGNode implements MultiNode {
public boolean link() {
if( in(0)._type.isHigh() || ptr()._type.isHigh() || ready()._type.isHigh() || bypass() ) return false;
FunNode target = CodeGen.CODE.link(cu());
+ boolean restored = target==null;
+ if( target==null && !CodeGen.CODE._midAssert ) target = CodeGen.CODE.restoreClinit(cu());
if( target==null ) return false; // Forward class reference during parsing.
assert !target.isDead() : "dead initializer "+target._name;
CProjNode call = cproj(3);
@@ -149,7 +151,7 @@ public class CLInitNode extends CFGNode implements MultiNode {
CodeGen.CODE.add(parm).addDef(arg);
}
if( CodeGen.CODE._phase.ordinal()>CodeGen.Phase.Opto.ordinal() ) {
- boolean repair = !target.compute().isa(target._type);
+ boolean repair = restored || !target.compute().isa(target._type);
for( Node use : target._outputs )
if( use instanceof ParmNode && !use.compute().isa(use._type) ) repair = true;
if( repair ) Iter.repair(CodeGen.CODE);
diff --git a/chapter33/src/main/java/com/seaofnodes/simple/node/GlobalEscapeNode.java b/chapter33/src/main/java/com/seaofnodes/simple/node/GlobalEscapeNode.java
index 4236cb6f..0f0e013c 100644
--- a/chapter33/src/main/java/com/seaofnodes/simple/node/GlobalEscapeNode.java
+++ b/chapter33/src/main/java/com/seaofnodes/simple/node/GlobalEscapeNode.java
@@ -18,18 +18,13 @@ public class GlobalEscapeNode extends Node {
@Override public TypeMem compute() {
TypeMem xmem = TypeMem.START;
for( CallNode call : CodeGen.CODE._calls )
- if( !call.isDead() ) {
+ if( !call.isDead() )
xmem = xmem.escapes(call.exposed(this));
- }
for( FunNode fun : CodeGen.CODE._linker )
- if( fun!=null && fun.summary()!=null && !fun.summary().isDead() ) {
+ if( fun!=null && fun.summary()!=null && !fun.summary().isDead() )
xmem = xmem.escapes(fun.summary().exposed(this));
- // A reachable unloaded body can call these targets, including
- // private initializers. Its arguments are unavailable here.
- if( fun._type==Type.CONTROL )
- for( int fidx : fun.summary()._classDependencyFIDXs )
- if( fidx!=0 ) xmem = xmem.makeFrom(xmem._escFs.meet(TypeSet.of(fidx)),xmem._escAs);
- }
+ // Class-init dependencies describe internal calls, not publication of
+ // function pointers. They remain available for class-init cycle checks.
return xmem;
}
}