Fix return type handling for Proxy classes
authorMatthew Fortune <matthew.fortune@imgtec.com>
Wed, 13 Jul 2016 21:34:52 +0000 (21:34 +0000)
committerMatthew Fortune <mpf@gcc.gnu.org>
Wed, 13 Jul 2016 21:34:52 +0000 (21:34 +0000)
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
libjava/java/lang/reflect/natVMProxy.cc
libjava/testsuite/libjava.jar/ReturnInvocationHandler.java [new file with mode: 0644]
libjava/testsuite/libjava.jar/ReturnProxyTest.jar [new file with mode: 0644]
libjava/testsuite/libjava.jar/ReturnProxyTest.java [new file with mode: 0644]
libjava/testsuite/libjava.jar/ReturnProxyTest.out [new file with mode: 0644]
libjava/testsuite/libjava.jar/ReturnProxyTest.xfail [new file with mode: 0644]
libjava/testsuite/libjava.jar/ReturnTypes.java [new file with mode: 0644]
libjava/testsuite/libjava.jar/ReturnTypesImpl.java [new file with mode: 0644]

index 06b354d7777cbdedac8d3b8f7254fb385eab9e1d..f7c282f9bd1cfc0c130ef8e155c3e585a9356888 100644 (file)
@@ -1,3 +1,15 @@
+2016-07-13  Matthew Fortune  <matthew.fortune@imgtec.com>
+
+       * 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  <matthew.fortune@imgtec.com>
 
        * interpret-run.cc: Use ffi_arg for FFI integer return types.
index e46263d858cfb50447e1559cf2977c03524fdc18..19cde207835c116acf5e40e198f7d5c86cc22e0e 100644 (file)
@@ -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 (file)
index 0000000..18b52b7
--- /dev/null
@@ -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 (file)
index 0000000..00daabe
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 (file)
index 0000000..bdd0ba9
--- /dev/null
@@ -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 (file)
index 0000000..b141f06
--- /dev/null
@@ -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 (file)
index 0000000..73ffe1d
--- /dev/null
@@ -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 (file)
index 0000000..9fbd6bd
--- /dev/null
@@ -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 (file)
index 0000000..33fab1b
--- /dev/null
@@ -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;
+  }
+}