[kaffe] libraries/clib/native/Field.c

Jukka Santala jsantala at tml.hut.fi
Tue May 7 05:13:11 PDT 2002


static
void*
//getFieldAddress(Hjava_lang_reflect_Field* this, struct
Hjava_lang_Object* obj)
getFieldAddress(struct Hjava_lang_Object* obj, Hjava_lang_reflect_Field*
this)
{

I could not yet determine why exactly (not being able to run with debugger
does that to you), but getFieldAddress() in Field.c for some reason gets
the incoming parameters to it reversed. Since it's called by 

jint
Java_java_lang_reflect_Field_getInt0(struct Hjava_lang_reflect_Field *
this, struct Hjava_lang_Object* obj) 
{
        return (*(jint*)getFieldAddress(this, obj));
}

I don't immediately see why this should happen, but it does seem to
happen. Swapping the parameters aroudn as above seems to solve the
problem, but it's perhaps a good diea to figure out what's going on. It
seems the swapping-around only works for static fields; could it be the VM
is trying to pass the JNI environment or similiar first in the stack
bumping the rest of the addresses?

Attached a regression-test with some of the most basic Field tricks. The
variety of alternatives with different combinations to test is ofcourse
infinite, but I believe these are the ones Kaffe right now has most
potential trouble with. The expected results are from JDK 1.4, and I
notice Kaffe doesn't do as detailed exception reporting, so either the
expected outputs or exception reporting needs to be adjusted. Completely
untested remain inheritance, interfaces and reflection access control.

 -Jukka Santala
-------------- next part --------------
import java.lang.reflect.Field;

class SomeFields {
	public int SOME = 10;
	protected int PSOME = 20;
}

class GetField {
	public int TEST = 10;
	public static int STEST = 20;
	private static int PSTEST = 30;
	public static void main(String args[]) {
		Field fld;
		Class cls = GetField.class;
		try {
			fld = cls.getField("TEST");
			System.out.println("public: "+fld.getInt(cls));
		} catch (Exception e) {
			System.out.println(e);
		}

		try {
			fld = cls.getField("STEST");
			System.out.println("public static: "+fld.getInt(cls));
		} catch (Exception e) {
			System.out.println(e);
		}

		try {
			fld = cls.getField("PSTEST");
			System.out.println("private: "+fld.getInt(cls));
		} catch (Exception e) {
			System.out.println(e);
		}

		try {
			fld = cls.getField("TEST");
			System.out.println("public from null: "+fld.getInt(null));
		} catch (Exception e) {
			System.out.println(e);
		}

		try {
			fld = cls.getField("STEST");
			System.out.println("public static from null: "+fld.getInt(null));
		} catch (Exception e) {
			System.out.println(e);
		}

		SomeFields sFields = new SomeFields();
		cls = SomeFields.class;
		try {
			fld = cls.getField("SOME");
			System.out.println("SomeFields public: "+fld.getInt(sFields));
		} catch (Exception e) {
			System.out.println(e);
		}

		try {
			fld = cls.getField("PSOME");
			System.out.println("SomeFields protected: "+fld.getInt(sFields));
		} catch (Exception e) {
			System.out.println(e);
		}
	}
}

/* Expected Output:
java.lang.IllegalArgumentException
public static: 20
java.lang.NoSuchFieldException: PSTEST
java.lang.NullPointerException
public static from null: 20
SomeFields public: 10
java.lang.NoSuchFieldException: PSOME
*/


More information about the kaffe mailing list