summaryrefslogtreecommitdiff
path: root/chapter33/src/test/java/com/seaofnodes/simple
diff options
context:
space:
mode:
Diffstat (limited to 'chapter33/src/test/java/com/seaofnodes/simple')
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java6
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java4
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java35
3 files changed, 44 insertions, 1 deletions
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java b/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
index 4cacd0e6..999e518d 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/ClassInitDependenciesTest.java
@@ -429,7 +429,11 @@ public class ClassInitDependenciesTest {
if( n instanceof CLInitNode init && init.fun()==fun && init.cu()==b ) {
touches[0]++;
TypeTuple state=(TypeTuple)init._type;
- assertSame(TypeMem.BOT,state._types[1]);
+ // Initialization merges whole memory; its escape sets
+ // can be sharper than the all-escaped MemBot bound.
+ TypeMem memory=(TypeMem)state._types[1];
+ assertEquals(1,memory._alias);
+ assertSame(Type.BOTTOM,memory._t);
TypeMem flag=(TypeMem)state._types[2];
assertEquals(b._clz.field("$init")._alias,flag._alias);
assertSame(TypeInteger.TRUE,flag._t);
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java b/chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java
index d6783380..0163de05 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/StringFormatTest.java
@@ -11,6 +11,10 @@ import org.junit.Test;
import static org.junit.Assert.*;
public class StringFormatTest extends TestC {
+ @Test public void testSingleIntegerInterpolation() throws Exception {
+ runSYS("val main={ -> sys.io.p(\"%(7)\"); return 0; };","singleIntegerInterpolation","7",-1);
+ }
+
// Share a few native programs, retaining a separately reported assertion
// for each case. Blocks isolate locals; the delimiter preserves embedded
// NULs and newlines in the expected output.
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java b/chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java
index 28b6b0fb..fb1834fa 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/TypeTest.java
@@ -1,12 +1,47 @@
package com.seaofnodes.simple;
import com.seaofnodes.simple.type.*;
+import java.util.HashMap;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertSame;
public class TypeTest {
+ @Test public void testSingletonMemoryUpgradeEscapes() {
+ TypeStruct open = TypeStruct.open("class:UpgradeChild");
+ TypeMemPtr ptr = TypeMemPtr.make((byte)2,open,true);
+ TypeFunPtr callback = TypeFunPtr.make1((byte)2,true,TypeFunPtr.TEMPTY,TypeInteger.BOT,11);
+ TypeStruct child = open.add(Field.make("self",ptr,7,true))
+ .add(Field.make("callback",callback,8,true))
+ .add(Field.make("value",TypeInteger.BOT,9,false)).close();
+ HashMap<String,Type> types = new HashMap<>();
+ types.put(child._name,child);
+ TypeMem initial = TypeMem.make(6,ptr,true,true,true,TypeSet.FULL,TypeSet.FULL);
+ TypeMem upgraded = (TypeMem)initial.upgradeType(types);
+ assertSame(child,((TypeMemPtr)upgraded._t)._obj);
+ assertSame(TypeSet.of(11),upgraded._escFs);
+ assertSame(TypeSet.of(7).with(8).with(9),upgraded._escAs);
+ assertSame(upgraded,upgraded.upgradeType(types));
+
+ // Only a final singleton class slot can replace its old escape bound.
+ // Aggregate memory and mutable/non-class slots retain prior escapes.
+ for( TypeMem other : new TypeMem[]{
+ TypeMem.make(6,ptr,true,true,false,TypeSet.FULL,TypeSet.FULL),
+ TypeMem.make(6,ptr,true,false,true,TypeSet.FULL,TypeSet.FULL),
+ TypeMem.make(6,ptr,false,true,true,TypeSet.FULL,TypeSet.FULL),
+ TypeMem.make(1,ptr,true,true,true,TypeSet.FULL,TypeSet.FULL)} ) {
+ TypeMem kept = (TypeMem)other.upgradeType(types);
+ assertSame(TypeSet.FULL,kept._escFs);
+ assertSame(TypeSet.FULL,kept._escAs);
+ }
+ TypeStruct opaque = TypeStruct.forward("ExternalUpgradeChild");
+ types.put(opaque._name,opaque);
+ TypeMem external = TypeMem.make(6,TypeMemPtr.make((byte)2,opaque,true),
+ true,true,true,TypeSet.FULL,TypeSet.FULL);
+ assertSame(external,external.upgradeType(types));
+ }
+
@Test public void testFinalPointerCycles() {
TypeStruct cycle = TypeStruct.open("FinalPointerCycle");
Assert.assertFalse(cycle.isFinal());