Re: [cp-patches] Changes to ThreadLocal

2007-08-22 Thread Ian Rogers
Jeroen Frijters wrote: No, any VM that implements the spec is vulnerable. Here's an example of a possible attack: class Attacker { static ArrayListThreadLocal resurrected; ArrayListThreadLocal list = new ArrayListThreadLocal(); Attacker() { for (int i = 0; i 1000; i++) {

RE: [cp-patches] Changes to ThreadLocal

2007-08-22 Thread Jeroen Frijters
Ian Rogers wrote: Thanks Jeroen, it's clear now. The problem with a phantom reference is that when we collect the thread local we should also really make collectable all of the values set to thread locals. A phantom reference won't do this and so introduces a memory leak until something can

RE: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Jeroen Frijters
Ian Rogers wrote: the attached patch modifies ThreadLocal to use an array of Objects hung off Thread rather than a weak hash map hung off Thread. On DaCapo's Jython benchmark this can improve the performance of the Jikes RVM by more than 10%. It also improves other DaCapo benchmark

Re: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Ian Rogers
Jeroen Frijters wrote: Ian Rogers wrote: the attached patch modifies ThreadLocal to use an array of Objects hung off Thread rather than a weak hash map hung off Thread. On DaCapo's Jython benchmark this can improve the performance of the Jikes RVM by more than 10%. It also improves other

Re: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Andrew Haley
Ian Rogers writes: Jeroen Frijters wrote: Ian Rogers wrote: the attached patch modifies ThreadLocal to use an array of Objects hung off Thread rather than a weak hash map hung off Thread. On DaCapo's Jython benchmark this can improve the performance of the Jikes RVM by more

Re: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Ian Rogers
Andrew Haley wrote: Ian Rogers writes: Jeroen Frijters wrote: Ian Rogers wrote: the attached patch modifies ThreadLocal to use an array of Objects hung off Thread rather than a weak hash map hung off Thread. On DaCapo's Jython benchmark this can improve the performance of

RE: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Jeroen Frijters
Ian Rogers wrote: One bug in the current implementation is that if the thread local overrides hashcode and/or equal it can be made to collide with other thread locals. No, it uses an Weak*Identity*HashMap. Regards, Jeroen

RE: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Jeroen Frijters
Ian Rogers wrote: here is the revised patch. + int arraySize = group.activeCount(); + Thread[] threadList = new Thread[arraySize]; + int filled = group.enumerate(threadList); + while (filled == arraySize) + { +arraySize *= 2; +threadList = new

Re: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Ian Rogers
Jeroen Frijters wrote: Ian Rogers wrote: here is the revised patch. + int arraySize = group.activeCount(); + Thread[] threadList = new Thread[arraySize]; + int filled = group.enumerate(threadList); + while (filled == arraySize) + { +arraySize *= 2; +

RE: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Jeroen Frijters
Ian Rogers wrote: How can then the thread local be resurrected after the finalizer is run? All the references in ThreadLocal and InheritableThreadLocal are weak and will be atomically cleared prior to the finalizer being run. All other references must be dead for the finalizer to have been

Re: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Ian Rogers
Jeroen Frijters wrote: This is not true. Once an object becomes finalizer reachable the finalizer can run, but that doesn't mean all references are gone. Any object with a finalizer can still have references to objects that have already been finalized. In its finalizer it will be able to

Re: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Ian Rogers
Ian Rogers wrote: Jeroen Frijters wrote: This is not true. Once an object becomes finalizer reachable the finalizer can run, but that doesn't mean all references are gone. Any object with a finalizer can still have references to objects that have already been finalized. In its finalizer it

RE: [cp-patches] Changes to ThreadLocal

2007-08-21 Thread Jeroen Frijters
Ian Rogers wrote: Anyway, this design decision seems to hang off how weak references are finalized. If they are finalized on their own finalizer thread then the final local index design is fine and preferable imo to the volatile design or a weak identity hash map (however cached or stream