This is the mail archive of the gcc@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]

Re: New vtable ABI (was Re: Strange behaviour in C++...)


"Martin v. Loewis" <martin@mira.isdn.cs.tu-berlin.de> writes:

>> while for Java object the offsets are always zero.
> 
> Is that mandatory?

Yes, keeping the offsets zero is required by the Java Virtual Machine
specification.  (And the Java Virtual machine specification is part
of the Java Language Specification, because a Java program can
dynamically create new classes.)

Of course we could always invoke an "as if rule" - if conforming
programs can't tell the difference, then we are free to implement
things differently.

But certainly there is a wide-spread *presumption* in Java that
neither up-casts and down-casts changes a pointer.

Furhermore, it is not possible to implement a "simple" Java
interpreter if this assumption is violated.  That is because there is
no instruction in the JVM to convert a pointer whose type is a
derived class to a pointer to one of its base classes or interfaces;
this operation is assumed to be a no-op.  The only option would be
a "complex" interpreter, for example a Just-In-Time compiler (JIT),
or something else that analyzes the whole method.  (Such analysis
is done anyway by a bytecoder verifier, for security purposes,
but traditionally only for "untrusted" code.)

> The naïve way of implementing interfaces is to take
> the usual C++ approach: interfaces are virtual classes with pure
> virtual methods.

Yes, that what I have been saying.  My point is that the traditional
way we implement "virtual classes with pure virtual methods and no
fields" in C++ is not the only way to do it.  For Java, it is almost
certainly the *wrong* way to do it.  For C++ too it might be
worth considering alternatives for this quite important special case.
-- 
	--Per Bothner
bothner@pacbell.net  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]