[Kaffe] reflection bug found, test case included

Moses DeJong dejong at cs.umn.edu
Mon Mar 22 16:37:26 PST 1999


On Sun, 21 Mar 1999, Archie Cobbs wrote:

> Moses DeJong writes:
> > I have run into an interesting reflection bug in Kaffe. I do not have time
> > to track this one down today so I am going to post the test case in case
> > someone wants to track it down. I was running on a solaris sparc
> > (BigEndian) system when I got these results.
> 
> Mo-

Your patch seems to work. I tested it with char, short, and long
and things seem to work. I think the patch should be added to the
CVS. I also appended the test cases I was using at the bottom
of this email just in case anyone wanted to test them out.

later
mo
 
> Please try the patch below. This is sortof a guess because I didn't
> fully investigate the problem, but this may fix it for you. Either
> way please report back as I don't have a big endian machine handy.
> Also, try the same thing with boolean and char if you can.
> 
> Thanks,
> -Archie
> 
> ___________________________________________________________________________
> Archie Cobbs   *   Whistle Communications, Inc.  *   http://www.whistle.com
> 
> 
> Index: support.c
> ===================================================================
> RCS file: /home/cvspublic/kaffe/kaffe/kaffevm/support.c,v
> retrieving revision 1.25
> diff -u -r1.25 support.c
> --- support.c	1999/02/13 19:08:18	1.25
> +++ support.c	1999/03/22 06:27:27
> @@ -286,12 +286,28 @@
>  	for (; *sig != ')'; i++, sig++) {
>  		call.calltype[i] = *sig;
>  		switch (*sig) {
> -		case 'I':
>  		case 'Z':
> +			call.callsize[i] = 1;
> +			in[i].i = args[i].z;
> +			break;
> +
>  		case 'S':
> +			call.callsize[i] = 1;
> +			in[i].i = args[i].s;
> +			break;
> +
>  		case 'B':
> +			call.callsize[i] = 1;
> +			in[i].i = args[i].b;
> +			break;
> +
>  		case 'C':
> +			call.callsize[i] = 1;
> +			in[i].i = args[i].c;
> +			break;
> +
>  		case 'F':
> +		case 'I':
>  			call.callsize[i] = 1;
>  			in[i] = args[i];
>  			break;
> 
> 
> 




import java.lang.reflect.*;


public class ShortTest {
    final static short tval = 3344;
    int _foo;

    public ShortTest(short f)
    {
	_foo = f;
    }

    public int getFoo()
    {
	return _foo;
    }

    public static void test1() throws Exception {
	ShortTest st = new ShortTest(tval);
	int foo = st.getFoo();
	System.out.println("test1 foo is " + foo);
    }
    
    public static void test2() throws Exception {
	Class mtc = ShortTest.class;
	Class[] sig = {Short.TYPE};
	Constructor mtc_con = mtc.getConstructor(sig);

	Object[] args = {new Short(tval)};
	ShortTest st = (ShortTest) mtc_con.newInstance(args);

	int foo = st.getFoo();
	System.out.println("test2 foo is " + foo);
    }

    public static void main(String[] args) throws Exception {
	test1();
	test2();
    }
}


// JDK
//
// % java ShortTest
// test1 foo is 3344
// test2 foo is 3344


// Kaffe
//
// % kaffe ShortTest
// test1 foo is 3344
// test2 foo is 219152384


// Kaffe after patch
//
// % kaffe ShortTest
// test1 foo is 3344
// test2 foo is 3344




import java.lang.reflect.*;


public class CharTest {
    final static char tval = Character.MAX_VALUE;
    int _foo;

    public CharTest(char f)
    {
	_foo = f;
    }

    public int getFoo()
    {
	return _foo;
    }

    public static void test1() throws Exception {
	CharTest st = new CharTest(tval);
	int foo = st.getFoo();
	System.out.println("test1 foo is " + foo);
    }
    
    public static void test2() throws Exception {
	Class mtc = CharTest.class;
	Class[] sig = {Character.TYPE};
	Constructor mtc_con = mtc.getConstructor(sig);

	Object[] args = {new Character(tval)};
	CharTest st = (CharTest) mtc_con.newInstance(args);

	int foo = st.getFoo();
	System.out.println("test2 foo is " + foo);
    }

    public static void main(String[] args) throws Exception {
	test1();
	test2();
    }
}




import java.lang.reflect.*;


public class IntTest {
    final static int tval = Integer.MAX_VALUE;
    long _foo;

    public IntTest(int f)
    {
	_foo = f;
    }

    public long getFoo()
    {
	return _foo;
    }

    public static void test1() throws Exception {
	IntTest st = new IntTest(tval);
	long foo = st.getFoo();
	System.out.println("test1 foo is " + foo);
    }
    
    public static void test2() throws Exception {
	Class mtc = IntTest.class;
	Class[] sig = {Integer.TYPE};
	Constructor mtc_con = mtc.getConstructor(sig);

	Object[] args = {new Integer(tval)};
	IntTest st = (IntTest) mtc_con.newInstance(args);

	long foo = st.getFoo();
	System.out.println("test2 foo is " + foo);
    }

    public static void main(String[] args) throws Exception {
	test1();
	test2();
    }
}




More information about the kaffe mailing list