[concurrency-interest] MORE ON: Re[2]: RFC -- Java7 java.util.concurrent plans

Roman Elizarov elizarov at devexperts.com
Thu Dec 11 13:10:26 EST 2008


Hello Doug!

>> It would be utterly cool for certain algorithms if this class also
>> contains a method with the following signature:
>>   void set(int[] a, int index, int value0, int value1);
>> which atomically does:
>>   a[index] = value0;
>>   a[index+1] = value1;

DL> Assuming you mean "int" only, you are probably better off manually
DL> packing into longs. Most machines require 8byte alignment of
DL> CAS/atomic-set of 64bit locations, which packing into longs would
DL> automatically provide.

In my case there is mostly int-sized data that I often access which is
interspersed with some "long" items which I want to change atomically.
It will be slow to unpack a long each time I need an int from it. You
can see that this is just a poor-man's replacement for a struct[].
That is our Javish way to do array of structs that contain just
primite data. Since most of our data is int-sized, we pack an array of
structs into int[].

Unfortunately, alignment spoils the idea of doing it that way. Thanks
for pointing it out!

>> This will close yet another Java vs native performance gap. Actually,
>> there are only few places left where Java algorithm running on HotSpot
>> significantly underperform compared to C/C++. One place is related to
>> high-performance/concurrent data strucutures. Consider a hash map from
>> int to Object. In C++ you would implement it as an array of structs.
>> But in Java the only way to implement it is to have a separate int[]
>> and a separate Object[]. Makes it twice as slow in practice, since
>> there are twice as many cache rows to load. We badly need
>> heterogenous/struct arrays. 

DL> I completely agree. I've been arguing for this for years.
DL> If anyone is looking for a good JVM project (on openJDK or elsewhere)
DL> to sink a lot of time into, this is among the most needed for
DL> supporting higher-performance data structures and algorithms
DL> (not just parallel ones).

The effort will be enourmous... I doubt that it can really payoff for
any one particular business project. In my case I'd rather buy faster
hardware that invest time into this project. Even though many people
will obvously benefit, it is not clear how to "pool" the resource they
could contribute (Create a fund? "Donate $1000 for structs in Java!"
;)

Sincerely,
Roman Elizarov



More information about the Concurrency-interest mailing list