1 @LATTICE("testL<testM,testM<testH")
2 @METHODDEFAULT("methodL<methodH,methodH<methodT,THISLOC=methodT,GLOBALLOC=methodT")
5 @LOC("testH") int fieldH;
6 @LOC("testM") int fieldM;
7 @LOC("testL") int fieldL;
8 @LOC("testM") Foo fooM;
9 @LOC("testH") static int globalH;
10 @LOC("testH") static Foo globalFoo;
11 @LOC("testH") static final String finalValue="FINAL";
14 public static void main (@LOC("methodH") String args[]){
15 @LOC("methodH") test t=new test();
20 @LOC("methodH") int localH; // LOC=[local.methodH]
21 fooM=new Foo(); // LOC=[local.methodT, field.testM]
24 // here, callee expects that arg1 is higher than arg2
25 // so caller should respects callee's constraints
26 fooM.doSomethingArgs(fieldH,fieldM);
34 @LOC("methodH,testL") int localVarL;
35 // value flows from the field [local.methodH,field.testH]
36 // to the local variable [local.methodL]
41 @LOC("methodT,testL")int localVar=fooM.a+fooM.b;
42 // GLB(fooM.a,fooM.b)=LOC[methodT,testM,FB]
43 // LOC[lovalVar]=[methodT,testL] < GLB(fooM.a,fooM.b)
46 // creating composite location by object references
48 @LOC("methodT,testM,FC,BB") int localVar=fooM.bar.a;
49 //LOC(fooM.bar.a)=[methodT,testM,FC,BA]
50 //localVar can flow into lower location of fooM.bar.a
51 fooM.bar.c=localVar; //[methodT,testM,FC,BB] < [methodT,testM,FC,BA]
54 // method has its own local variable lattice
55 @LATTICE("mL<mH,THISLOC=mH")
56 public void doOwnLattice(){
63 @LATTICE("mL<mH,THISLOC=mH")
64 public void doDelta(){
65 @LOC("DELTA(mH,testH)") int varDelta;
66 // LOC(varDelta) is slightly lower than [mH, testH]
68 @LOC("DELTA(DELTA(mH,testH))") int varDeltax2;
69 // applying double delta to [mH,testH]
71 varDelta=fieldH; // [mH,testH] -> DELTA[mh,testH]
72 varDeltax2=varDelta; //DELTA[mh,testH] -> DELTA[DELTA[mh,testH]]
74 fieldM=varDeltax2; // DELTA[DELTA[mh,testH]] -> [mH,testM]
77 @LATTICE("mL<mSpin,mSpin<mH,mSpin*")
78 public void doSpinLoc(){
79 // if loc is defined with the suffix *,
80 //value can be flowing around the same location
83 @LOC("mSpin") int varSpin;
88 // value can be flowing back to the varSpin
89 // since 'varSpin' is location allowing value to move within
90 // the same abstract location
96 @LATTICE("mL<mH,THISLOC=mL")
97 public void doSpinField(){
98 //only last element of the composite location can be the spinning loc
103 @LOC("mH") Bar localBar=new Bar();
105 localBar.b2=localBar.b1;
106 // LOC(localBar.b1)=[mH,BB]
107 // LOC(localBar.b2)=[mH,BB]
108 // b1 and b2 share the same abstract loc BB
109 // howerver, location BB allows values to be moving within itself
111 localBar.b1++; // value can be moving among the same location
114 public void uniqueReference(){
116 @LOC("methodH") Foo f_1=new Foo();
118 @LOC("methodL") Bar newBar_2;
120 f_1.bar=null; // should assign null here
124 @LATTICE("mL<mM,mM<mH,GLOBALLOC=mH,THISLOC=mL")
125 public void globalField(){
126 @LOC("DELTA(mH,testH,FA)") int value=globalFoo.a; // LOC(globalFoo.a)=[mH,testH,FA]
130 public void globalTopField(){
131 @LOC("methodH") String valueH;
132 valueH=finalValue; // LOC(finalVAlue)=[TOP,testH]
135 public void globalCopy(){
136 // do not allow the below case
137 // it copies something from one calss global variable
138 // to another class global variable
146 @LATTICE("FD<FC,FC<FB,FB<FA")
147 @METHODDEFAULT("fm_L<fm_M1,fm_L<fm_M2,fm_M1<fm_H,fm_M2<fm_H,THISLOC=fm_H")
154 @LOC("FA") static int d;
159 public void doSomething(){
160 b=a; // value flows from [fm_H,FA] to [fm_H,FB]
163 // callee has a constraint that arg1 is higher than arg2
164 public int doSomethingArgs(@LOC("fm_H")int argH,
165 @LOC("fm_M1")int argL){
170 public int doSomethingRtn(){
171 return a+b; // going to return LOC[local.t,field.FB]
176 @LATTICE("BC<BB,BB<BA,BB*")
177 @METHODDEFAULT("BARMD_L<BARMD_H,THISLOC=BARMD_H")
183 @LOC("BC") static int d;