Finding the declaring class of a _Jv_Field

Mark Wielaard mark@klomp.org
Sun Oct 29 14:29:00 GMT 2000


Hi,

On Sun, Oct 29, 2000 at 02:52:20PM -0700, Tom Tromey wrote:
> 
> Wouldn't we really want to do `final' checking in the bytecode
> verifier?  Ok, we don't have a verifier, so interpret.cc is the
> logical choice.  But in the long term we'd want to move this check to
> the verifier, right?
If I read the JVM spec right then a final field can actually be assigned
a value multiple times if it is done in the class that declares the field.
But you can never change the value of a final field from another class.
The JSL says that you cannot assign a final field a value twice, but
the JVM spec has no such restriction for byte code. Strange but true!
Try compiling the following with gcj -C (which current has a bug that it
does generate code to change the final field twice) and try running it
with any java interpreter. I haven't found any that would not just print
1 and 2.

public class TestFinal {
    final static Integer i = new Integer(1);

    public static void main(String[] args) {
        System.out.println(i);
        i =  new Integer(2);
        System.out.println(i);
    }
}

(Writing code that changes i from another class should throw an exception
though.)
 
> Mark> But after calling _Jv_ResolvePoolEntry I only have a _Jv_Field
> Mark> and I cannot figure out how to get the declaring class for
> Mark> it. How is that done?
> 
>     _Jv_Field fld;
>     Class k = fld.getClass ();
> 
> Or am I missing something?
I thought that gave you the type of the field. I need the class in which
the field is declared. But it might be that I am missing something myself.

Cheers,

Mark


More information about the Java mailing list