patch to bring java vtables closer to g++ abi conformance

Bryce McKinlay bryce@waitaki.otago.ac.nz
Wed Jan 23 19:39:00 GMT 2002


Per Bothner wrote:
> 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)" 

This is fine, but I suspect it becomes a little less efficient to have 
to offset the load by a constant value as well as the calculated offset.
My version is something like:
int offset = A[depth] - b->vtbl[0]->depth;
boolean instanceof_result = (offset <= 0 && b->vtbl[offset] == A)
While yours is:
int offset = A->vtable[DEPTH] - b->vtbl[DEPTH] - 4;
boolean instanceof_result = (offset <= -4 && b->vtbl[offset] == A)
Then again it probably doesn't make much difference if the CPU has an 
instruction that can subtract both a constant and a register value from 
another register.
> 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 

For binary compatibility, A.depth isn't known at compile time, because 
inserting new superclasses is an allowable binary compatible change. So, 
the bounds check is required.
Also, If the ancestors were ordered this way, getClass() becomes 
expensive because B.class is _not_ at a fixed offset from the vtable 
pointer, unless we were to have duplicate copies of it. type_info is for 
C++ type info, not the java class object, right?
regards
Bryce.


More information about the Java mailing list

AltStyle によって変換されたページ (->オリジナル) /