PR 13948 and Miranda Methods

Tom Tromey tromey@redhat.com
Mon May 3 17:19:00 GMT 2004


>>>>> "Ranjit" == Ranjit Mathew <rmathew@gmail.com> writes:

Ranjit>     I was trying my bit to track down the cause
Ranjit> of PR 13948 this weekend and I am a bit confused
Ranjit> by some things. It'll be really nice if someone
Ranjit> can throw some light on these.

Offhand I don't know all the answers, maybe Bryce or Andrew does, or
perhaps you'll just need to go in with a debugger.

Ranjit>   1. In line 2057 of class.c (add_miranda_methods), why do
Ranjit>      we start searching from index 1 and not 0?

My recollection is that index 0 is always the super class, and for
interfaces this slot is either NULL or Object (I forget which).

Ranjit>   2. Miranda methods are needed to work with older buggy VMs
Ranjit>      that need an implicit method declaration in an abstract
Ranjit>      class for a method from an implemented interface (right?).

An abstract class isn't required to declare methods inherited from
interfaces.  However, when we build vtables these methods have to
come from somewhere.  So, we introduce these fake Miranda methods to
make vtable construction work out right.  We do this in the compiler
when generating .o files and in the runtime for other classes.  So,
it isn't a compatibility thing -- it is really needed.

Ranjit>      AFAICT, Andrew's patch above was needed because GCJ treats
Ranjit>      interfaces like abstract classes - but shouldn't it
Ranjit>      create problems with other JVMs that don't?

As long as we don't emit these fake methods for class files, I think
we're ok.  As I recall, we should only emit these for object code,
and then we emit them with a special flag so that they aren't visible
to reflection.

This probably should change with the BC ABI.  There's no point
emitting them if we're already doing all the class construction at
runtime anyway.

Ranjit>      However, layout_class_methods() calls add_miranda_methods()
Ranjit>      anyways - so isn't the call on line 2097 made redundant by his
Ranjit>      patch?

I don't know, but it would appear so.

Ranjit>   4. Line 2076 says:
Ranjit>        /* An interface can have <clinit>.  */
Ranjit>      How? A naive attempt to write one fails as I had thought.
Ranjit>      So what gives?

public interface X
{
  public static final Object val = new Object ();
}

In other words, you'll get a <clinit> method for an interface if it
contains any field that isn't a compile-time constant.

Tom



More information about the Java mailing list