Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-05-13 Thread Martin Buchholz
;> >>>>>>>>>> Hi Martin, >>>>>>>>>> >>>>>>>>>> Thank you for your reply.  If I may, PriorityQueue appears to >>>>>>>>>> employ >>>>>>>>>> the

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-05-13 Thread David Holmes
bug for us? Martin On Wed, Mar 3, 2010 at 17:41, Kevin L. Stern wrote: Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream which arise when the capacities of the data structures reach a particular threshold. More below. When the ca

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-05-12 Thread David Holmes
something near MAX_VALUE on overflow, and throw OutOfMemoryError on next resize. These bugs are not known. Chris Hegarty, could you file a bug for us? Martin On Wed, Mar 3, 2010 at 17:41, Kevin L. Stern wrote: Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable and java.io

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-05-12 Thread Martin Buchholz
t; It might be desirable to set a common strategy for capacity increase >>>>>>> for >>>>>>> all >>>>>>> collections. >>>>>>> >>>>>>> Regards, >>>>>>> >>>>>>>

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-05-12 Thread Martin Buchholz
gt;>>> >>>>>> Kevin >>>>>> >>>>>> On Fri, Mar 5, 2010 at 3:04 AM, Martin Buchholz >>>>>> wrote: >>>>>>> >>>>>>> Hi Kevin, >>>>>>> >>>>

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-05-12 Thread Kelly O'Hair
AX_VALUE on overflow, and throw OutOfMemoryError on next resize. These bugs are not known. Chris Hegarty, could you file a bug for us? Martin On Wed, Mar 3, 2010 at 17:41, Kevin L. Stern > wrote: Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable and java.io

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-05-12 Thread David Holmes
near MAX_VALUE on overflow, and throw OutOfMemoryError on next resize. These bugs are not known. Chris Hegarty, could you file a bug for us? Martin On Wed, Mar 3, 2010 at 17:41, Kevin L. Stern wrote: Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutpu

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-04-16 Thread Martin Buchholz
On Fri, Apr 16, 2010 at 03:17, David Holmes 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 >> AbstractCollection. >> I've put those changes into >> http://cr.openjdk.java.net/~martin/webrevs/

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-04-16 Thread David Holmes
ar MAX_VALUE on overflow, and throw OutOfMemoryError on next resize. These bugs are not known. Chris Hegarty, could you file a bug for us? Martin On Wed, Mar 3, 2010 at 17:41, Kevin L. Stern wrote: Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteA

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-04-16 Thread Chris Hegarty
41, Kevin L. Stern wrote: Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream which arise when the capacities of the data structures reach a particular threshold. More below. When the capacity of an ArrayList reaches (2/3)*Integer.MAX_

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-04-15 Thread Martin Buchholz
an independent buglet in hotspot >>>> that you cannot allocate an array with Integer.MAX_VALUE >>>> elements, but Integer.MAX_VALUE - 5 (or so) works. >>>> >>>> It occurs to me that increasing the size by 50% is better done by >>>> int new

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-10 Thread Martin Buchholz
at you cannot allocate an array with Integer.MAX_VALUE >> >> elements, but Integer.MAX_VALUE - 5 (or so) works. >> >> >> >> It occurs to me that increasing the size by 50% is better done by >> >> int newCapacity = oldCapacity + (oldCapacity >> 1)

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-10 Thread Martin Buchholz
On Wed, Mar 10, 2010 at 09:36, Ulf Zibis wrote: > Am 10.03.2010 00:22, schrieb Martin Buchholz: >> >> On Tue, Mar 9, 2010 at 15:11, Ulf Zibis  wrote: >> >> >>> >>> Can you explain the mystery about "+ 2" ? >>> >> >> It's exactly the same as the old resizing behavior. > > In detail I meant, if you

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-10 Thread Ulf Zibis
Am 10.03.2010 00:22, schrieb Martin Buchholz: On Tue, Mar 9, 2010 at 15:11, Ulf Zibis wrote: Can you explain the mystery about "+ 2" ? It's exactly the same as the old resizing behavior. In detail I meant, if you have any idea, why the original designers could have chosen the "+1

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-10 Thread Goktug Gokdogan
50% is better done by > >> int newCapacity = oldCapacity + (oldCapacity >> 1) + 1; > >> > >> I agree with the plan of setting the capacity to something near > >> MAX_VALUE on overflow, and throw OutOfMemoryError on next resize. > >> > >> T

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Martin Buchholz
On Tue, Mar 9, 2010 at 15:11, Ulf Zibis wrote: > Can you explain the mystery about "+ 2" ? It's exactly the same as the old resizing behavior. Martin

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Ulf Zibis
Am 09.03.2010 23:08, schrieb Martin Buchholz: On Tue, Mar 9, 2010 at 13:08, Ulf Zibis wrote: [1] current PriorityQueue snippet: ... int newCapacity = ((oldCapacity< 64)? ((oldCapacity + 1) * 2): ((oldCapacity / 2) * 3)); ...

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Martin Buchholz
On Tue, Mar 9, 2010 at 13:08, Ulf Zibis wrote: > > [1] current PriorityQueue snippet: > ... >     int newCapacity = ((oldCapacity < 64)? >    ((oldCapacity + 1) * 2): >    ((oldCapacity / 2) * 3)); > ... > [2] new PriorityQueue snippet: > ... >  

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Ulf Zibis
Am 09.03.2010 21:02, schrieb Osvaldo Doederlein: Should we really consider this a VM bug? I'm not sure that it's a good idea to allocate a single object which size exceeds 4Gb (for a byte[] - due to the object header and array size field) - even on a 64-bit VM. An array with 2^32 elements is im

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Ulf Zibis
Am 09.03.2010 20:18, schrieb Martin Buchholz: On Tue, Mar 9, 2010 at 03:59, Ulf Zibis wrote: In PriorityQueue: let's result newCapacity in 0x.FFFC =-4 then "if (newCapacity - MAX_ARRAY_SIZE> 0)" ---> false then Arrays.copyOf(queue, newCapacity) ---> ArrayIndexOutOfBoundsException

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Martin Buchholz
It surely is not a good idea to use a single backing array for huge arrays. As you point out, it's up to 32GB for just one object. But the core JDK doesn't offer a suitable alternative for users who need very large collections. It would have been more in the spirit of Java to have a collection c

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Martin Buchholz
ava spec, or will this break on an >> obscure machine that does not use, say, two's complement arithmetic? >> >> Regards, >> >> Kevin >> >> 2010/3/9 Dmytro Sheyko >>> >>> Is there any reason to use comparison like this

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Osvaldo Doederlein
Should we really consider this a VM bug? I'm not sure that it's a good idea to allocate a single object which size exceeds 4Gb (for a byte[] - due to the object header and array size field) - even on a 64-bit VM. An array with 2^32 elements is impossible, the maximum allowed by the size field is 2^

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Martin Buchholz
On Tue, Mar 9, 2010 at 03:59, Ulf Zibis wrote: > In PriorityQueue: > > let's result newCapacity in 0x.FFFC  =-4 > then "if (newCapacity - MAX_ARRAY_SIZE > 0)" ---> false > then Arrays.copyOf(queue, newCapacity) ---> ArrayIndexOutOfBoundsException How could newCapacity ever become -4? Since gr

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Ulf Zibis
Am 09.03.2010 12:02, schrieb Kevin L. Stern: I did a quick search and it appears that Java is indeed two's complement based. Nonetheless, please allow me to point out that, in general, this type of code worries me since I fully expect that at some point someone will come along and do exactly w

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Kevin L. Stern
>> Kevin >> >> 2010/3/9 Dmytro Sheyko >> >> Is there any reason to use comparison like this >>> >>> if (newCapacity - minCapacity < 0) >>> >>> if (newCapacity - MAX_ARRAY_SIZE > 0) { >>> >>> instead of &

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Christopher Hegarty -Sun Microsystems Ireland
u file a bug for us? Martin On Wed, Mar 3, 2010 at 17:41, Kevin L. Stern wrote: Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream which arise when the capacities of the data structures reach a particular threshold. More below. When th

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Kevin L. Stern
ZE > 0) { >> >> instead of >> >> if (newCapacity < minCapacity) >> >> if (newCapacity > MAX_ARRAY_SIZE) { >> >> Thanks, >> Dmytro >> >> > Date: Mon, 8 Mar 2010 18:10:37 -0800 >> > Subject: Re: Bugs in java.u

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Ulf Zibis
ething near MAX_VALUE on overflow, and throw OutOfMemoryError on next resize. These bugs are not known. Chris Hegarty, could you file a bug for us? Martin On Wed, Mar 3, 2010 at 17:41, Kevin L. Stern wrote: Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable an

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Kevin L. Stern
here any reason to use comparison like this > > if (newCapacity - minCapacity < 0) > > if (newCapacity - MAX_ARRAY_SIZE > 0) { > > instead of > > if (newCapacity < minCapacity) > > if (newCapacity > MAX_ARRAY_SIZE) { > > Thanks, > Dmytro > > >

RE: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-09 Thread Dmytro Sheyko
bject: Re: Bugs in java.util.ArrayList, java.util.Hashtable and > java.io.ByteArrayOutputStream > From: marti...@google.com > To: kevin.l.st...@gmail.com; christopher.hega...@sun.com; alan.bate...@sun.com > CC: core-libs-dev@openjdk.java.net > > [Chris or Alan, please review and file

Re: Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-08 Thread Martin Buchholz
2010/3/5 : > Hello, > > I'm using my own Collections if it's possible so I can add some thoughts: > > 1. I would decrease default array size to 4/6/8, for me it was few Mb more > of free memory ( i suggest testing on application that use at least 300Mb) > > I would test: > > initial size: 4 > long

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-08 Thread Martin Buchholz
On Fri, Mar 5, 2010 at 02:48, Kevin L. Stern wrote: > Hi Martin, > > Thank you for your reply.  If I may, PriorityQueue appears to employ the > simple strategy that I suggested above in its grow method: > >     int newCapacity = ((oldCapacity < 64)? >    ((oldCapacity +

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-08 Thread Martin Buchholz
etter done by >> int newCapacity = oldCapacity + (oldCapacity >> 1) + 1; >> >> I agree with the plan of setting the capacity to something near >> MAX_VALUE on overflow, and throw OutOfMemoryError on next resize. >> >> These bugs are not known. >

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-05 Thread Kevin L. Stern
oldCapacity >> 1) + 1; > > I agree with the plan of setting the capacity to something near > MAX_VALUE on overflow, and throw OutOfMemoryError on next resize. > > These bugs are not known. > Chris Hegarty, could you file a bug for us? > > Martin > > On Wed, Mar 3, 2010

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-05 Thread Kevin L. Stern
FYI, HashMap independently defines a MAXIMUM_CAPACITY variable; it might be a good idea to retrofit this and other such local definitions with any system wide variables that are defined. /** * The maximum capacity, used if a higher value is implicitly specified * by either of the con

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-05 Thread Ulf Zibis
Am 05.03.2010 10:04, schrieb Martin Buchholz: Hi Kevin, As you've noticed, creating objects within a factor of two of their natural limits is a good way to expose lurking bugs. I'm the one responsible for the algorithm in ArrayList. I'm a bit embarrassed, looking at that code today. We could se

Re: Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-05 Thread develop4lasu
t; wrote: > Greetings, > > I've noticed bugs in java.util.ArrayList, java.util.Hashtable and > java.io.ByteArrayOutputStream which arise when the capacities of the data > structures reach a particular threshold. More below. > > When the capacity of an ArrayList r

Re: Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-05 Thread Martin Buchholz
1; I agree with the plan of setting the capacity to something near MAX_VALUE on overflow, and throw OutOfMemoryError on next resize. These bugs are not known. Chris Hegarty, could you file a bug for us? Martin On Wed, Mar 3, 2010 at 17:41, Kevin L. Stern wrote: > Greetings, > > I've

Bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream

2010-03-03 Thread Kevin L. Stern
Greetings, I've noticed bugs in java.util.ArrayList, java.util.Hashtable and java.io.ByteArrayOutputStream which arise when the capacities of the data structures reach a particular threshold. More below. When the capacity of an ArrayList reaches (2/3)*Integer.MAX_VALUE its size reache