CSE526: Programming Languages Scott Stoller project testcases version: 2pm,3may2004 1. the first test program ("program 1") is: class I extends Object { int fi guarded_by this = 0 } class A extends Object { I fa = new I } class C extends Object { atomic int m(I i) { synchronized i i.fi } cmpd int n(A a) { let I i = a.fa in synchronized a this.m(i) } let C c = new C in c.n(new A) type checker should report that the program is well typed. -------------------- 2. modify program 1 by replacing the line atomic int m(I i) { synchronized i i.fi } with atomic int m(I i) { i.fi } type checker should report an error, because the lock on i is not held when i.fi is accessed. (note that field fi should be guarded_by "this".) -------------------- 3. modify program 1 by replacing the line synchronized a this.m(i) with synchronized a.fa this.m(i) type checker should report an error, because a.f1 does not have atomicity const, because field fa is not final. -------------------- 4. modify program 1 by replacing the line cmpd int n(A a) { with atomic int n(A a) { type checker should report an error, because atomic;atomic equals cmpd. -------------------- 5. modify program 1 by replacing the line atomic int m(I i) { synchronized i i.fi } with atomic int m(I i) { synchronized i let int j = i.fi in i.fi } type checker should report that the program is well typed (because mover;mover equals mover). -------------------- 6. modify program 1 by replacing the line atomic int m(I i) { synchronized i i.fi } with atomic int m(I i) { synchronized i i.fi=1 } type checker should report that the program is well typed. -------------------- 7. modify program 1 by replacing the line atomic int m(I i) { synchronized i i.fi } with i?mover:atomic int m(I i) { synchronized i i.fi } type checker should report that the program is well typed. -------------------- 8. modify program 1 by replacing the line atomic int m(I i) { synchronized i i.fi } with i?mover:atomic int m(I i) { synchronized i while i.fi i.fi } type checker should report that the program is well typed, because mover;(mover;mover)* equals mover. -------------------- 9. modify program 1 by replacing the line synchronized a this.m(i) with synchronized i while i.fi this.m(i) type checker should report that the program is well typed. -------------------- 10. modify program 1 by replacing the line let C c = new C in c.n(new A) with let I i = new I in synchronized i i.fi the type checker should report that the program is well typed. this requires using the subtype rule to change the atomicity of (synchronized i i.fi) from i?mover:atomic to atomic. otherwise, the substitution [i := new I] produces an invalid atomicity. -------------------- untested: if, write_guarded_by