JNI: cannot access member of superclass via subclass

Jules Bean jmlb2 at hermes.cam.ac.uk
Wed May 26 02:46:19 PDT 1999

Godmar Back wrote:
>  Let me follow up with what I learned from Gilad Bracha about field resolution,
> in case anybody is interested.
> 1. The compiler is wrong to compile accesses the way it does.  See
>     http://java.sun.com/docs/books/jls/public-symref-compilation-rules.html
>    The JLS was changed, but no javac compiler implements the change yet.

It has always struck me that one of the worst things about the java
system is that Sun didn't quite seem sure what they wanted to happen at
compile-time, and what at link-time/run-time.

In a system where you are theoretically allowed to replace classes and
re-run, you shouldn't be doing compile-time optimisations of this type. 
The example above was one.  Another is that javac 'knows' whether a
method has been overridden or not, and uses this information, in some
circumstances, to generate a non-virtual method call.  This means that
when someone then overrides the method in the subclass, precompiled code
breaks - and this was a subtle incompatibility between JDK 1.0 code and
JDK 1.1 code.  A program compiled under JDK 1.0 could fail to work with
JDK 1.1 because some functionality had been moved to a subclass, but the
compiled code was automatically only calling the superclass's version
because it *knew* at compile time that that would be good enough.

IMO, the correct way to implement a language like java is to do such
optimisations at class-load time (or JIT-time).  In fact, had I designed
java (and I have designed two, albeit rather simpler, VM systems -
neither of them are in use, though) I wouldn't have distinguished, in
the byte-code, between virtual and non-virtual method calls.

(I hope that made sense, and wasn't ill-informed, since I haven't
actually read the JLS)


|  Jelibean aka  | jules at jellybean.co.uk         |  6 Evelyn Rd        |
|  Jules aka     |                               |  Richmond, Surrey   |
|  Julian Bean   | jmlb2 at hermes.cam.ac.uk        |  TW9 2TF *UK*       |
|  War doesn't demonstrate who's right... just who's left.             |
|  When privacy is outlawed... only the outlaws have privacy.          |

More information about the kaffe mailing list