Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream
martinrb at google.com
Fri Apr 16 19:03:33 UTC 2010
On Fri, Apr 16, 2010 at 03:17, David Holmes <David.Holmes at oracle.com> wrote:
> Hi Martin,
> Martin Buchholz said the following on 04/16/10 16:09:
>> I recently discovered another place to handle huge arrays better - in
>> I've put those changes into
> I don't understand what you are doing here:
> 194 * The maximum size of array to allocate.
> 195 * Some VMs reserve some header words in an array.
> 196 * Attempts to allocate larger arrays may result in
> 197 * OutOfMemoryError: Requested array size exceeds VM limit
> 198 */
> 199 private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;
> On 32-bit you can't get anywhere near this limit. On 64-bit Hotspot
> currently allows you to allocate the entire array up to Integer.MAX_VALUE
> elements for types <= 32-bit; and MAX_VALUE-3 for 64-bit.
> Regardless this is VM specific and I don't see what purpose this serves.
I'm trying to avoid OOME due to exceeding the MAX_VALUE-3 limit
on a 64-bit VM,
when the number of actual elements is far smaller,
say 75% of MAX_VALUE.
Yes, you can think of this as a VM-specific bug workaround.
More information about the core-libs-dev