From 0d355cf973a80a3d15132ceabd55f6510f729d88 Mon Sep 17 00:00:00 2001 From: Matthew Fortune Date: Wed, 13 Jul 2016 21:34:52 +0000 Subject: [PATCH] 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 --- libjava/ChangeLog | 12 ++++++++ libjava/java/lang/reflect/natVMProxy.cc | 10 +++---- .../libjava.jar/ReturnInvocationHandler.java | 24 ++++++++++++++++ .../testsuite/libjava.jar/ReturnProxyTest.jar | Bin 0 -> 2671 bytes .../libjava.jar/ReturnProxyTest.java | 27 ++++++++++++++++++ .../testsuite/libjava.jar/ReturnProxyTest.out | 12 ++++++++ .../libjava.jar/ReturnProxyTest.xfail | 1 + .../testsuite/libjava.jar/ReturnTypes.java | 9 ++++++ .../libjava.jar/ReturnTypesImpl.java | 27 ++++++++++++++++++ 9 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 libjava/testsuite/libjava.jar/ReturnInvocationHandler.java create mode 100644 libjava/testsuite/libjava.jar/ReturnProxyTest.jar create mode 100644 libjava/testsuite/libjava.jar/ReturnProxyTest.java create mode 100644 libjava/testsuite/libjava.jar/ReturnProxyTest.out create mode 100644 libjava/testsuite/libjava.jar/ReturnProxyTest.xfail create mode 100644 libjava/testsuite/libjava.jar/ReturnTypes.java create mode 100644 libjava/testsuite/libjava.jar/ReturnTypesImpl.java 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 0000000000000000000000000000000000000000..00daabeccc8f28d1ccde9d8bea763874ab9351a7 GIT binary patch literal 2671 zcma);3p`Y5AIA^Ir7`3-xs*_u#$_}mvr!Cf_&zw1{9|G6S5%flTu|LZO@ZF2O!ncL}s?seNT#a+=fkH>}m-yRCVy zMu(*#Z5{%oRicwlsPBfXT!fFHE`Z#>uBLF+j1GUG)n2&s%_8z~iB^)Uin?job8c8S zi`#X7;V=1U{I23eIoPCQ;}i3JT?PA0kKYf+5Q;`JvZ46gMzU8{LE-osPDBN}e9llP z={8xqF(u2GV=*j!p>jY8ZFmCZ4iT2s_$~xWW{!7FW=cs=9#l9f?4BNX&~>~ro*4^~ z%g5nUtV?~i(~H9W9fKcMXQgFhl$|w+xE)5^*86?f&}T*odI0(6aCsPLTkfUIG~&d2)a4UknWmWlt#itxnRZ-h&D6y_GMCY8tYP?>C35U3)tip9@cK z=tSE8xL!qo)Uk~VmDGCb<&XbUxpMEz6-Pr~OO$N)mz4S?eL}ikP1I-sgSm43N#yf$ z45S}ddjOFc1tO>J=0#{j48j@A-?l-Q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61mU6j+

o6cy&M7>Jj zou86#u?{KmU)fK;u_5cU5!SNKt?u!jqn2wFXUaEBqY~L{gZ;w0K;+VQUWGzmY&P>g!D%}@zweIHBMYj ze8hoX2J%nhmgB^<#s4FJIYPuG!6!qP$U`9c8v+5G;(v&PkH&wQLj06kK1DGYrC%wQ zPZ9d>(Bk>N9L<;hgci&Ge}@&%qUG3YGGf@}IrUFyX>bSt$bh#dxLj+wrLVsMqYL[] { 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; + } +} -- 2.30.2