gcj uses reflection for every INVOKEINTERFACE?

Adam Megacz adam@megacz.com
Fri Feb 27 04:46:00 GMT 2004


Bryce McKinlay <bryce@mckinlay.net.nz> writes:
> Interface calls without reflection data are tricky. However, if you are 
> doing a static, complete-application compilation - such that given an 
> interface, at compile time you have complete knowledge of all classes 
> that implement that interface, then you can build the interface 
> dispatch tables at compile time thus eliminating the need for 
> reflection data.

Actually, I was thinking about this.  I think even in the separate
compilation (but not late-bound as in the case of indirect-dispatch),
we could use symbols rather than utf8-strings.

In other words, what if instead of using the method name, signature,
and interface-name to identify the method when building the
constant-time tables, we instead use the address of the _Jv_Method of
the interface's method?

For example:

  package com.megacz;
  interface A { abstract void foo(); }
  class B implements A { void foo() { ... } }

The code

  ((A)something).foo();

Gets written as something like (pseudocode)

  JvInvokeInterface(something, &__ZN_com_megacz_A_foo_V, args)

JvInvokeInterface then checks something->class, which has a jmethod[]
associated with it.  It scans through that array to find an 'i' such
that

  something->class->methods[i]->overrides == &__ZN_com_megacz_A_foo_V

  or

  something->class->methods[i]->overrides->overrides == &__ZN_com_megacz_A_foo_V

  or

  something->class->methods[i]->overrides->overrides->overrides == &__ZN_com_megacz_A_foo_V

  and so on...

This would require adding an 'overrides' member to jmethod, which
contains a reloc for the jmethod that this jmethod overrides.

Again, this won't work for indirect dispatch, but it should work for
static dispatch and free us from the utf8's.

  - a



More information about the Java mailing list