RFR: 8196340: (coll) Examine overriding inherited methods in ArrayList and ArrayList.SubList
Ivan Gerasimov
ivan.gerasimov at oracle.com
Tue May 15 01:45:10 UTC 2018
On 5/14/18 5:22 PM, Claes Redestad wrote:
>
>
> I was actually toying with and testing a change to this effect anyway,
> since it's a nice cleanup and might help the JIT somewhat:
>
> http://cr.openjdk.java.net/~redestad/8196340/open.02/
>
> A note on correctness: none of the code in ArrayList that utilize
> modCount is "correct" or accurate in a concurrency or thread-safety
> context where ordering of loads and stores is critical for
> correctness: lacking volatile or other means to ensure correct
> ordering of operations (or atomicity of modCount increments) the
> runtime is given large amounts of freedoms to do as it please to
> optimize things. This is intentional as ArrayList isn't supposed to
> be neither thread-safe nor concurrent on its own. The main utility is
> instead about detecting and avoid coding errors, mainly bugs like
> adding to or removing items from a list you're simultaneously
> iterating over. So what I'm saying is that the ordering of operations
> within a method might not be all that important as long as they are
> sound within the scope of the method execution. Still, making it a bit
> more like correct concurrent code might improve the best effort
> behavior in some circumstances, and costs us nothing.
>
I totally agree with this!
For this reason let's move the line
586 final int otherModCount = other.modCount;
to the beginning of equalsArrayList(ArrayList<?> other), so it is
initialized before other.size is read?
With kind regards,
Ivan
> Thanks - and sorry for dragging you along for a bit longer...
>
> /Claes
>
--
With kind regards,
Ivan Gerasimov
More information about the core-libs-dev
mailing list