1 package Analysis.Disjoint.UnitTests;
8 import Analysis.Disjoint.*;
11 public class CanonicalTest {
13 private static void check( String testName, ReachSet actual, ReachSet expected ) {
14 System.out.print( testName + "... " );
15 if( expected.equals( actual ) ) {
16 System.out.println( "passed" );
18 System.out.println( "FAILED:" );
19 System.out.println( " expected = "+expected );
20 System.out.println( " actual = "+actual );
26 private static ReachSet toCallerContext( ReachSet in, AllocSite... sites ) {
28 for( AllocSite as : sites ) {
29 out = Canonical.toCallerContext( out, as );
35 public static void main( String[] args ) {
36 AllocSite as1 = AllocSite.factory( 1, null, "as1", true );
37 as1.setIthOldest( 0, 1 );
40 AllocSite as2 = AllocSite.factory( 1, null, "as2", true );
41 as2.setIthOldest( 0, 3 );
44 ReachTuple rt1 = ReachTuple.factory( 1, false, ReachTuple.ARITY_ONE, false );
45 ReachTuple rt1o = ReachTuple.factory( 1, false, ReachTuple.ARITY_ONE, true );
46 ReachTuple rtm1 = ReachTuple.factory( -1, false, ReachTuple.ARITY_ONE, false );
48 ReachTuple rt2 = ReachTuple.factory( 2, true, ReachTuple.ARITY_ONE, false );
49 ReachTuple rt2s = ReachTuple.factory( 2, true, ReachTuple.ARITY_ZEROORMORE, false );
50 ReachTuple rt2o = ReachTuple.factory( 2, true, ReachTuple.ARITY_ONE, true );
51 ReachTuple rt2so = ReachTuple.factory( 2, true, ReachTuple.ARITY_ZEROORMORE, true );
52 ReachTuple rtm2 = ReachTuple.factory( -2, true, ReachTuple.ARITY_ONE, false );
53 ReachTuple rtm2s = ReachTuple.factory( -2, true, ReachTuple.ARITY_ZEROORMORE, false );
55 ReachTuple rt3 = ReachTuple.factory( 3, false, ReachTuple.ARITY_ONE, false );
56 ReachTuple rt3o = ReachTuple.factory( 3, false, ReachTuple.ARITY_ONE, true );
57 ReachTuple rtm3 = ReachTuple.factory( -3, false, ReachTuple.ARITY_ONE, false );
59 ReachTuple rt4 = ReachTuple.factory( 4, true, ReachTuple.ARITY_ONE, false );
60 ReachTuple rt4s = ReachTuple.factory( 4, true, ReachTuple.ARITY_ZEROORMORE, false );
61 ReachTuple rt4o = ReachTuple.factory( 4, true, ReachTuple.ARITY_ONE, true );
62 ReachTuple rt4so = ReachTuple.factory( 4, true, ReachTuple.ARITY_ZEROORMORE, true );
63 ReachTuple rtm4 = ReachTuple.factory( -4, true, ReachTuple.ARITY_ONE, false );
64 ReachTuple rtm4s = ReachTuple.factory( -4, true, ReachTuple.ARITY_ZEROORMORE, false );
66 // [1, 4?*] to caller context, with respect to AS1(1,2S), should be [-1, 4?*]
67 check( "change just 0th",
68 toCallerContext( ReachSet.factory( ReachState.factory( rt1, rt4so ) ), as1 ),
69 ReachSet.factory( ReachState.factory( rtm1, rt4so ) )
72 // [1, 3?] to caller context should be [-1, 3]
73 check( "against both allocation sites",
74 toCallerContext( ReachSet.factory( ReachState.factory( rt1, rt3o ) ), as1, as2 ),
75 ReachSet.factory( ReachState.factory( rtm1, rt3 ) )
78 // [1?, 2S, 3, 4S*] -> [1, -2S, -3, -4S*]
79 check( "all 1-to-1 translations",
80 toCallerContext( ReachSet.factory( ReachState.factory( rt1o,
84 ReachSet.factory( ReachState.factory( rt1, rtm2, rtm3, rtm4s ) )
87 // [2S?, 3] -> [2S, -3], [1?, -3], [2S?, -3]
88 check( "Out-of-context summary becomes three things",
89 toCallerContext( ReachSet.factory( ReachState.factory( rt2o, rt3 ) ), as1, as2 ),
90 ReachSet.factory( ReachState.factory( rt2, rtm3 ),
91 ReachState.factory( rt1o, rtm3 ),
92 ReachState.factory( rt2o, rtm3 ) )
95 // [2S?, 1?] -> [2S, 1], [1?, 1], [2S?, 1]
96 check( "Out-of-context summary becomes three things",
97 toCallerContext( ReachSet.factory( ReachState.factory( rt2o, rt1o ) ), as1, as2 ),
98 ReachSet.factory( ReachState.factory( rt2, rt1 ),
99 ReachState.factory( rt1o, rt1 ),
100 ReachState.factory( rt2o, rt1 ) )
103 // [2S?*, 1?] -> [2S*, 2S?*, 1]
104 check( "* Out-of-context summary becomes two tokens in one state",
105 toCallerContext( ReachSet.factory( ReachState.factory( rt2so, rt1o ) ), as1, as2 ),
106 ReachSet.factory( ReachState.factory( rt2s, rt2so, rt1 ) )