This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Bug(s) inside IdentityHashMap.java


>>>>> "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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]