This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: patch to bring java vtables closer to g++ abi conformance
- From: Per Bothner <per at bothner dot com>
- To: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- Cc: gcc-patches at gcc dot gnu dot org, java at gcc dot gnu dot org
- Date: Wed, 23 Jan 2002 17:35:40 -0800
- Subject: Re: patch to bring java vtables closer to g++ abi conformance
- References: <3C4EF937.3060806@bothner.com> <3C4F543C.8090904@waitaki.otago.ac.nz>
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/