mccoyst / tact

Tact automatically adds certain runtime checks to Java bytecode in class files.
0 stars 0 forks source link

Successfully Track Mutable Objects #18

Closed mccoyst closed 12 years ago

mccoyst commented 12 years ago

I almost forgot about this one. Consider this test, which currently fails:

@Test(expected=IllegalAccessError.class)
public void mutableObject(){
    final List<Object> m = new ArrayList<Object>();
    Checker.check(m);
    m.add(new Object());
    doInAnotherThread(new Runnable(){
        public void run(){
            Checker.check(m);
        }
    });
}

Right now the checker uses a WeakHashMap. This won't work, because mutable objects that override hashCode() can return different values, thus Checker.check() will not find the object after the object has already been added to the map. The "ideal" solution may involve some JNI function that gets the raw value of an object reference for use as a hash key, but I will have to implement WeakReference semantics for that somehow.

In the meantime, I'll have to live with an O(n) array lookup.