From: Matthew Fortune Date: Wed, 13 Jul 2016 21:34:52 +0000 (+0000) Subject: Fix return type handling for Proxy classes X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0d355cf973a80a3d15132ceabd55f6510f729d88;p=gcc.git Fix return type handling for Proxy classes libjava/ * java/lang/reflect/natVMProxy.cc (unbox): Use ffi_arg for integer return types smaller than a word. * testsuite/libjava.jar/ReturnInvocationHandler.java: New file. * testsuite/libjava.jar/ReturnProxyTest.jar: Likewise. * testsuite/libjava.jar/ReturnProxyTest.java: Likewise. * testsuite/libjava.jar/ReturnProxyTest.out: Likewise. * testsuite/libjava.jar/ReturnProxyTest.xfail: Likewise. * testsuite/libjava.jar/ReturnTypes.java: Likewise. * testsuite/libjava.jar/ReturnTypesImpl.java: Likewise. From-SVN: r238312 --- diff --git a/libjava/ChangeLog b/libjava/ChangeLog index 06b354d7777..f7c282f9bd1 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,15 @@ +2016-07-13 Matthew Fortune + + * java/lang/reflect/natVMProxy.cc (unbox): Use ffi_arg for + integer return types smaller than a word. + * testsuite/libjava.jar/ReturnInvocationHandler.java: New file. + * testsuite/libjava.jar/ReturnProxyTest.jar: Likewise. + * testsuite/libjava.jar/ReturnProxyTest.java: Likewise. + * testsuite/libjava.jar/ReturnProxyTest.out: Likewise. + * testsuite/libjava.jar/ReturnProxyTest.xfail: Likewise. + * testsuite/libjava.jar/ReturnTypes.java: Likewise. + * testsuite/libjava.jar/ReturnTypesImpl.java: Likewise. + 2016-07-13 Matthew Fortune * interpret-run.cc: Use ffi_arg for FFI integer return types. diff --git a/libjava/java/lang/reflect/natVMProxy.cc b/libjava/java/lang/reflect/natVMProxy.cc index e46263d858c..19cde207835 100644 --- a/libjava/java/lang/reflect/natVMProxy.cc +++ b/libjava/java/lang/reflect/natVMProxy.cc @@ -272,17 +272,17 @@ unbox (jobject o, jclass klass, void *rvalue, FFI_TYPE type) if (klass == JvPrimClass (byte)) { _Jv_CheckCast (&Byte::class$, o); - *(jbyte*)rvalue = ((Byte*)o)->byteValue(); + *(ffi_arg*)rvalue = ((Byte*)o)->byteValue(); } else if (klass == JvPrimClass (short)) { _Jv_CheckCast (&Short::class$, o); - *(jshort*)rvalue = ((Short*)o)->shortValue(); + *(ffi_arg*)rvalue = ((Short*)o)->shortValue(); } else if (klass == JvPrimClass (int)) { _Jv_CheckCast (&Integer::class$, o); - *(jint*)rvalue = ((Integer*)o)->intValue(); + *(ffi_arg*)rvalue = ((Integer*)o)->intValue(); } else if (klass == JvPrimClass (long)) { @@ -302,12 +302,12 @@ unbox (jobject o, jclass klass, void *rvalue, FFI_TYPE type) else if (klass == JvPrimClass (boolean)) { _Jv_CheckCast (&Boolean::class$, o); - *(jboolean*)rvalue = ((Boolean*)o)->booleanValue(); + *(ffi_arg*)rvalue = ((Boolean*)o)->booleanValue(); } else if (klass == JvPrimClass (char)) { _Jv_CheckCast (&Character::class$, o); - *(jchar*)rvalue = ((Character*)o)->charValue(); + *(ffi_arg*)rvalue = ((Character*)o)->charValue(); } else JvFail ("Bad ffi type in proxy"); diff --git a/libjava/testsuite/libjava.jar/ReturnInvocationHandler.java b/libjava/testsuite/libjava.jar/ReturnInvocationHandler.java new file mode 100644 index 00000000000..18b52b73a55 --- /dev/null +++ b/libjava/testsuite/libjava.jar/ReturnInvocationHandler.java @@ -0,0 +1,24 @@ +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; + +public class ReturnInvocationHandler implements InvocationHandler +{ + private Object obj; + public ReturnInvocationHandler(Object obj) + { + this.obj = obj; + } + public Object invoke(Object proxy, Method m, Object[] args) throws Throwable + { + Object result; + try + { + result = m.invoke(obj, args); + } + catch (Exception e) + { + throw e; + } + return result; + } +} diff --git a/libjava/testsuite/libjava.jar/ReturnProxyTest.jar b/libjava/testsuite/libjava.jar/ReturnProxyTest.jar new file mode 100644 index 00000000000..00daabeccc8 Binary files /dev/null and b/libjava/testsuite/libjava.jar/ReturnProxyTest.jar differ diff --git a/libjava/testsuite/libjava.jar/ReturnProxyTest.java b/libjava/testsuite/libjava.jar/ReturnProxyTest.java new file mode 100644 index 00000000000..bdd0ba93355 --- /dev/null +++ b/libjava/testsuite/libjava.jar/ReturnProxyTest.java @@ -0,0 +1,27 @@ +import java.lang.reflect.Proxy; + +public class ReturnProxyTest +{ + public static void main(String[] args) + { + ReturnTypes orig = new ReturnTypesImpl(); + Object o = Proxy.newProxyInstance(orig.getClass().getClassLoader(), + new Class[] { ReturnTypes.class }, + new ReturnInvocationHandler(orig)); + ReturnTypes rt = (ReturnTypes)o; + + System.out.println(orig.getBoolean()); + System.out.println(orig.getChar()); + System.out.println(orig.getByte()); + System.out.println(orig.getShort()); + System.out.println(orig.getInt()); + System.out.println(orig.getLong()); + + System.out.println(rt.getBoolean()); + System.out.println(rt.getChar()); + System.out.println(rt.getByte()); + System.out.println(rt.getShort()); + System.out.println(rt.getInt()); + System.out.println(rt.getLong()); + } +} diff --git a/libjava/testsuite/libjava.jar/ReturnProxyTest.out b/libjava/testsuite/libjava.jar/ReturnProxyTest.out new file mode 100644 index 00000000000..b141f06fe40 --- /dev/null +++ b/libjava/testsuite/libjava.jar/ReturnProxyTest.out @@ -0,0 +1,12 @@ +false +a +-1 +-1 +-1 +-1 +false +a +-1 +-1 +-1 +-1 diff --git a/libjava/testsuite/libjava.jar/ReturnProxyTest.xfail b/libjava/testsuite/libjava.jar/ReturnProxyTest.xfail new file mode 100644 index 00000000000..73ffe1d5217 --- /dev/null +++ b/libjava/testsuite/libjava.jar/ReturnProxyTest.xfail @@ -0,0 +1 @@ +main=ReturnProxyTest diff --git a/libjava/testsuite/libjava.jar/ReturnTypes.java b/libjava/testsuite/libjava.jar/ReturnTypes.java new file mode 100644 index 00000000000..9fbd6bd1529 --- /dev/null +++ b/libjava/testsuite/libjava.jar/ReturnTypes.java @@ -0,0 +1,9 @@ +public interface ReturnTypes +{ + public short getShort(); + public char getChar(); + public byte getByte(); + public int getInt(); + public long getLong(); + public boolean getBoolean(); +} diff --git a/libjava/testsuite/libjava.jar/ReturnTypesImpl.java b/libjava/testsuite/libjava.jar/ReturnTypesImpl.java new file mode 100644 index 00000000000..33fab1b5dc0 --- /dev/null +++ b/libjava/testsuite/libjava.jar/ReturnTypesImpl.java @@ -0,0 +1,27 @@ +public class ReturnTypesImpl implements ReturnTypes +{ + public short getShort() + { + return -1; + } + public char getChar() + { + return 'a'; + } + public byte getByte() + { + return -1; + } + public int getInt() + { + return -1; + } + public long getLong() + { + return -1; + } + public boolean getBoolean() + { + return false; + } +}