This is the mail archive of the
java@gcc.gnu.org
mailing list for the Java project.
Re: Bug(s) inside IdentityHashMap.java
- To: martin dot kahlert at infineon dot com
- Subject: Re: Bug(s) inside IdentityHashMap.java
- From: Tom Tromey <tromey at redhat dot com>
- Date: 27 Sep 2001 09:16:01 -0600
- Cc: java at gcc dot gnu dot org
- References: <20010927161646.A16908@keksy.muc.infineon.com>
- Reply-To: tromey at redhat dot com
>>>>> "Martin" == Martin Kahlert <martin.kahlert@infineon.com> writes:
Martin> I have some problems with IdentityHashMap.java:
Martin> First: Where is table.length set?
`table' is an array. `table.length' is set when the array is created.
Martin> The file contains a lot of copies of the term
Martin> h = Math.abs (2 * System.identityHashCode (key) % table.length);
Martin> this is the same as
Martin> h = Math.abs ((2 * System.identityHashCode (key)) % table.length);
Martin> thus, h may be table.length - 1;
Martin> but in get() we ask for return table[h + 1];
Martin> which is an memory violation.
Of course. Sorry about this. I'll write a test suite for
IdentityHashMap soon -- something I should have done on day 1.
Meanwhile I think we really need:
h = Math.abs (2 * (System.identityHashCode (key) % (table.length / 2)));
Conceptually table is an array of length L where each entry is a
key/value pair. We want to compute the index based on the conceptual
length, and then double that.
Tom