This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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/


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