8020860: cluster Hashtable/Vector field updates for better transactional memory behaviour

Paul Sandoz paul.sandoz at oracle.com
Wed Mar 26 09:02:26 UTC 2014

On Mar 26, 2014, at 5:21 AM, David Holmes <david.holmes at oracle.com> wrote:

> Mike,
> On 26/03/2014 6:37 AM, Mike Duigou wrote:
>> Hello all;
>> Recently HotSpot gained additional support for transactional memory, <https://bugs.openjdk.java.net/browse/JDK-8031320>. This patch is a libraries followon to that change. RTM and other transactional memory implementations benefit from clustering writes towards the end of the transaction whenever possible. This change optimizes the behaviour of two collection classes, Hashtable and Vector by moving several field updates to cluster them together near the end of the transaction. Yes, we know, these are obsolete collections but these two classes were used as the basis for the original benchmarking and evaluation during the development of the transactional memory JVM features. Future changes providing similar optimizations to other collections will be pursued when it can be shown they offer value and don't add a cost to non TM performance (TM is not yet a mainstream feature).
>> https://bugs.openjdk.java.net/browse/JDK-8020860
>> http://cr.openjdk.java.net/~mduigou/JDK-8020860/0/webrev/
>> It is not expected that this change will have any meaningful impact upon performance (either positive or negative) outside of TM-enabled configurations. The main change is to move existing field updates towards the end of the transaction and avoid conditionals between field updates.
>> There is a slight behaviour change introduced in this changeset. Previously some methods updated the modcount unconditionally updated even when an ArrayIndexOutOfBoundsException was subsequently thrown for an invalid index and the Vector was not modified. With this change the modcount will only be updated if the Vector is actually changed. It is not expected that applications will have relied or should have relied on this behaviour.
> I could live with that change in behaviour, but this change completely breaks the fail-fast semantics of the iterators in some cases! If you don't update modCount until after the change is complete, the iterator may access the updated state and not throw CME!.

There is a possibility that a method could barf before the modCount is updated e.g. before the fix the modCount was aggressively updated, but now it is possible to say throw an exception and the modCount will not be updated (see addAll if the collection is null or the index is out of bounds).

> I think this change is misguided.

I too share concerns about this. 

I would have hoped that the compiler (both javac and the runtime) might be able to automatically move code around to group writes. In the interim of getting such good compiler support i can understand the need for certain updates to improve performance. 

Do we have access to the perf results?


More information about the core-libs-dev mailing list