patch to bring java vtables closer to g++ abi conformance
Boehm, Hans
hans_boehm@hp.com
Wed Jan 23 22:27:00 GMT 2002
Hopefully a minor point:
The garbage collector really likes the GC descriptor at offset 1 from the
vtable pointer. This is an ugly restriction, but it makes things
appreciably easier. (More precisely, it would like to see an appropriate
descriptor, even if it happens to follow a bogus pointer to a free list. If
the descriptor is at offset 1, it sees a zero "descriptor" in this case. If
you put it at offset zero, it sees the free list link. Zero is fine, the
freelist link will result in a SIGSEGV.)
If you put the GC descriptor at location zero, I suspect the GC's free list
link has to move to offset 1. I would be pleasantly surprised if this
turned out to be painless.
But it looks like the depth could just go at offset 0 instead?
Hans
-----Original Message-----
From: Per Bothner
To: Bryce McKinlay
Cc: gcc-patches@gcc.gnu.org; java@gcc.gnu.org
Sent: 1/23/02 5:35 PM
Subject: Re: patch to bring java vtables closer to g++ abi conformance
Bryce McKinlay wrote:
> Given:
>> class A {}
> class B extends A {}
>> Then B would have a vtable which looks something like:
How about:
[-6] &Object.class
[-5] &A.class
[-4] &B.class
[-3] -2 /* depth, negated */
[-2] offset_to_top (always 0)
[-1] type_info
<-- vtable pointer points here
[0] GC descriptor<-- vtable pointer points here
[1] &java.lang.Object.hashCode()
[2] ...etc
>> "b instanceof A" then becomes something like
#define DEPTH (-3)
"(b->vtbl[DEPTH] <= -A.depth) && (b->vtbl[b->vtbl[DEPTH] + (A.depth-4)]
== A)"
Or better order the other way around:
[-7] 0 padding (min(0, a - abs(depth)) words)
[-6] &B.class
[-5] &A.class
[-4] &Object.class
[-3] -2 /* depth, negated */
[-2] offset_to_top (always 0)
[-1] type_info
<-- vtable pointer points here
Assuming A.depth <= 3 (known at compile-time), then b instanceof A
becomes just:
b->vtable[-4 - A.depth] == A
> If it fixes gdb then I certainly have no objection, just that we may
> want to do something else eventually.
>> I think that having fast type checks is more important than having C++
> RTTI info in Java objects, but others might disagree?
I don't think there is a conflict.
Note also that if type_info is placed at a fixed address in the Class,
then x.getClass() is just (x->vptr[-1] + OFFSET).
--
--Per Bothner
per@bothner.com http://www.bothner.com/per/
More information about the Java
mailing list