JNI global refs
Tom Tromey
tromey@redhat.com
Tue Jul 24 11:21:00 GMT 2001
>>>>> "Jeff" == Jeff Sturm <jsturm@one-point.com> writes:
Jeff> I suspect the problem is with using a Hashtable. Suppose we
Jeff> have a class:
Jeff> class WillBreakJNI {
Jeff> public int hashCode() { return 0; }
Jeff> public boolean equals(Object o) { return true; }
Jeff> }
Jeff> The ref_table will store only one instance of this class.
Jeff> I think ref_table should hash its objects by address, or something...
I've been thinking about this recently.
I agree with what you say.
We need to use object identity, and not equals() or hashCode(), as the
basis for comparisons here.
One way we could do this is to make a copy of Hashtable which uses,
say, System.identityHashCode and `=='. This would mean copying a lot
of code though. I'm reluctant to do this.
Another way to do it would be to introduce a new wrapper object which
we would use. This means more overhead for each JNI reference.
Yet another way would be to write our own hash table in C++. This has
the benefit that we wouldn't have to have Integer objects floating
around; we could simply use ints in a parallel table. The problem
with this approach is that we'd have to teach the GC how to find this
memory. Hmm -- maybe the best thing to do is use an Object[] as the
underlying hash table. This would accomplish that goal.
Tom
More information about the Java
mailing list