Finding the declaring class of a _Jv_Field

Mark Wielaard mark@klomp.org
Tue Oct 31 08:46:00 GMT 2000


Hi,

On Mon, Oct 30, 2000 at 05:11:22PM -0700, Tom Tromey wrote:
> >>>>> "Mark" == Mark Wielaard <mark@klomp.org> writes:
> 
> Mark>  - Checks that the currently executing method has access to the
> Mark>  referenced method or field."
> 
> Mark> But does not specify 'has access to'.
> 
> I'm sure this means access in terms of private/protected/public.
Yes, but that is precisely the problem the JVM spec seems to have
added the descriptions of the final modifier as an afterthought :(

> Mark> I would conclude that the description of putfield and putstatic
> Mark> is not strict enough but that almost all JVMs currently
> Mark> implement what it says and that the Microsoft VM is (the only)
> Mark> correct JVM when it throws the IllegalAccessError.
> 
> Mark> It is interesting to know if that is indeed how one should
> Mark> interpret the spec because it makes it easier to implement final
> Mark> field checking in gij
I think I can now come up with a patch to gij that implements this
behaviour. I will try to post it later this night to java-patches.

> Mark> and it indicates that one may do some
> Mark> optimalisations on final fields because they really are not
> Mark> suppost to change ever.
> 
> A long time ago I did some work on java.lang.System.  I found that
> some versions of the JDK (the newer ones) did in fact reassign the
> final fields `in', `out', and `err'.
> 
> That is why I implemented the setIn/setOut/setErr methods the way that
> I did.  ISTR that gcj wouldn't accept a direct reassignment from Java
> so I did it in C++ (eww).
> 
> Before I ran these tests I had more complex machinery in System.java
> (I had a private subclass of PrintStream that let you reassign the
> underlying stream).  However, experimentation (and an email discussion
> with Per) convinced me that this wasn't required.
I could not find such a discussion in the archives. Is there really no
way to make a pure Java implementation?
 
> It sucks that this isn't well specified.  Maybe the only thing to do
> is file a bug report with Sun and hope that they respond to it
> someday.
I looked at the bug database and it seems that even Sun admits that it
was a bad design choice. They even indicate that a JIT compiler should
have a special case for the System in/out/err fields. Yuck. But in 
general it seems to be legal to optimise the access to final fields.

Cheers,

Mark


More information about the Java mailing list