commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Sync gnu/java/rmi/server with kaffe (primitive types and void re


From: Mark Wielaard
Subject: [PATCH] Sync gnu/java/rmi/server with kaffe (primitive types and void return values)
Date: Fri, 26 Dec 2003 02:42:26 +0100

Hi,

I am going to apply the following patch to resync with the kaffe version
again.

2003-12-25  Guilhem Lavaux  <address@hidden>
            Mark Wielaard  <address@hidden>
 
        * gnu/java/rmi/server/UnicastConnectionManager.java
        (startScavenger): Set the client connection manager to daemon
        state because it may block clients until TIMEOUT is reached
        when they are exiting.
 
        * gnu/java/rmi/RMIVoidValue.java: New file for a class representing
        a void return.
 
        * gnu/java/rmi/server/UnicastRemoteCall.java
        (DummyOutputStream): Add a boolean before each written field to
        know whether it is a primitive.
        (releaseOutputStream): Flush parameters at write time.
 
        * gnu/java/rmi/server/UnicastServerRef.java
        (incomingMessageCall): Return a RMIVoidValue if no value is to be
        returned.
 
        * gnu/java/rmi/server/UnicastServer.java
        (incomingMessageCall): Do not write a returned object if it is
        a RMIVoidValue.
 
        * gnu/java/rmi/server/Makefile.am (EXTRA_DIST): Add RMIVoidValue.java.

Kaffe hackers, you may want to double check and resync with Classpath
again since I slightly adapted the original patch by Guilhem to not
create new Boolean and RMIVoidValue objects all over the place but reuse
existing instances.

Cheers,

Mark
Index: gnu/java/rmi/server/Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/rmi/server/Makefile.am,v
retrieving revision 1.2
diff -u -r1.2 Makefile.am
--- gnu/java/rmi/server/Makefile.am     21 Mar 2002 05:40:11 -0000      1.2
+++ gnu/java/rmi/server/Makefile.am     26 Dec 2003 01:41:14 -0000
@@ -7,6 +7,7 @@
 RMIHashes.java \
 RMIObjectInputStream.java \
 RMIObjectOutputStream.java \
+RMIVoidValue.java \
 UnicastConnection.java \
 UnicastConnectionManager.java \
 UnicastRef.java        \
Index: gnu/java/rmi/server/RMIVoidValue.java
===================================================================
RCS file: gnu/java/rmi/server/RMIVoidValue.java
diff -N gnu/java/rmi/server/RMIVoidValue.java
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ gnu/java/rmi/server/RMIVoidValue.java       26 Dec 2003 01:41:14 -0000
@@ -0,0 +1,51 @@
+/* RMIVoidValue.java
+  Copyright (c) 2003 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING.  If not, write to the
+Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library.  Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module.  An independent module is a module which is not derived from
+or based on this library.  If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so.  If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.java.rmi.server;
+
+/**
+ * Package private class used to indicate a void return type.
+ * INSTANCE is the only object of this class ever made.
+ */
+final class RMIVoidValue
+{
+  static RMIVoidValue INSTANCE = new RMIVoidValue();
+
+  private RMIVoidValue()
+  {
+  }
+}
Index: gnu/java/rmi/server/UnicastConnectionManager.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/rmi/server/UnicastConnectionManager.java,v
retrieving revision 1.4
diff -u -r1.4 UnicastConnectionManager.java
--- gnu/java/rmi/server/UnicastConnectionManager.java   31 Oct 2002 18:35:21 
-0000      1.4
+++ gnu/java/rmi/server/UnicastConnectionManager.java   26 Dec 2003 01:41:14 
-0000
@@ -152,6 +152,9 @@
             if (debug) System.out.println("************* exit scavenger.");
         }
     });
+    // As it is used for client connection, we may put this thread
+    // in daemon state to prevent the VM from blocking when exiting.
+    scavenger.setDaemon(true);
     scavenger.start();
 }
 
Index: gnu/java/rmi/server/UnicastRemoteCall.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/rmi/server/UnicastRemoteCall.java,v
retrieving revision 1.7
diff -u -r1.7 UnicastRemoteCall.java
--- gnu/java/rmi/server/UnicastRemoteCall.java  10 Jun 2003 19:37:55 -0000      
1.7
+++ gnu/java/rmi/server/UnicastRemoteCall.java  26 Dec 2003 01:41:14 -0000
@@ -65,6 +65,7 @@
   private long hash;
   private Vector vec;
   private int ptr;
+  private ObjID objid;
 
   private ObjectOutput oout;
   private ObjectInput oin;
@@ -86,22 +87,7 @@
     this.conn = conn;
     this.opnum = opnum;
     this.hash = hash;
-    
-    // signal the call when constructing
-    try
-      {
-       DataOutputStream dout = conn.getDataOutputStream();
-       dout.write(MESSAGE_CALL);
-       
-       oout = conn.getObjectOutputStream();
-       objid.write(oout);
-       oout.writeInt(opnum);
-       oout.writeLong(hash);
-      }
-    catch(IOException ex)
-      {
-       throw new MarshalException("Try to write header but failed.", ex);
-      }
+    this.objid = objid;
   }
   
   UnicastConnection getConnection()
@@ -111,22 +97,43 @@
   
   public ObjectOutput getOutputStream() throws IOException
   {
-    if (conn != null)
-      {
-       if(oout == null)
-         return (oout = conn.getObjectOutputStream());
-       else
-         return oout;
-      }
-    else
-      {
-       vec = new Vector();
-       return (new DummyObjectOutputStream());
-      }
+    if (vec == null)
+      vec = new Vector();
+    return (new DummyObjectOutputStream());
   }
 
   public void releaseOutputStream() throws IOException
   {
+    if (vec != null)
+      {
+       oout = conn.getObjectOutputStream();
+       
+       for (int i = 0; i < vec.size(); i += 2)
+         {
+           boolean primitive = ((Boolean)vec.elementAt(i)).booleanValue();
+           Object data = vec.elementAt(i+1);
+
+           // No type, this is
+           if (!primitive)
+             oout.writeObject(data);
+           else
+             {
+               if (data instanceof Boolean)
+                 oout.writeBoolean(((Boolean)data).booleanValue());
+               else if (data instanceof Character)
+                 oout.writeChar(((Character)data).charValue());
+               else if (data instanceof Byte)
+                 oout.writeByte(((Byte)data).byteValue());
+               else if (data instanceof Short)
+                 oout.writeShort(((Short)data).shortValue());
+               else if (data instanceof Integer)
+                 oout.writeInt(((Integer)data).intValue());
+               else if (data instanceof Long)
+                 oout.writeLong(((Long)data).longValue());
+             }
+         }
+       vec = null;
+      }
     if(oout != null)
       oout.flush();
   }
@@ -163,6 +170,23 @@
   {
     byte returncode;
     ObjectInput oin;
+    
+    // signal the call when constructing
+    try
+      {
+       DataOutputStream dout = conn.getDataOutputStream();
+       dout.write(MESSAGE_CALL);
+       
+       oout = conn.getObjectOutputStream();
+       objid.write(oout);
+       oout.writeInt(opnum);
+       oout.writeLong(hash);
+      }
+    catch(IOException ex)
+      {
+       throw new MarshalException("Try to write header but failed.", ex);
+      }
+
     try
       {
        releaseOutputStream();
@@ -211,9 +235,15 @@
     // conn.disconnect();
   }
 
+  boolean isReturnValue()
+  {
+    return vec.size() > 0;
+  }
+  
   Object returnValue()
   {
-    return (vec.size() > 0 ? vec.elementAt(0) : null);
+    // This is not the first one (Boolean) but the second.
+    return vec.elementAt(1);
   }
 
   Object[] getArguments()
@@ -256,46 +286,55 @@
 
     public void writeBoolean(boolean v) throws IOException
     {
-      vec.addElement(new Boolean(v));
+      vec.addElement(Boolean.TRUE);
+      vec.addElement(Boolean.valueOf(v));
     }
 
     public void writeByte(int v) throws IOException
     {
+      vec.addElement(Boolean.TRUE);
       vec.addElement(new Byte((byte) v));
     }
 
     public void writeChar(int v) throws IOException
     {
+      vec.addElement(Boolean.TRUE);
       vec.addElement(new Character((char) v));
     }
 
     public void writeDouble(double v) throws IOException
     {
+      vec.addElement(Boolean.TRUE);
       vec.addElement(new Double(v));
     }
 
     public void writeFloat(float v) throws IOException
     {
+      vec.addElement(Boolean.TRUE);
       vec.addElement(new Float(v));
     }
 
     public void writeInt(int v) throws IOException
     {
+      vec.addElement(Boolean.TRUE);
       vec.addElement(new Integer(v));
     }
 
     public void writeLong(long v) throws IOException
     {
+      vec.addElement(Boolean.TRUE);
       vec.addElement(new Long(v));
     }
 
     public void writeShort(int v) throws IOException
     {
+      vec.addElement(Boolean.TRUE);
       vec.addElement(new Short((short) v));
     }
 
     public void writeObject(Object obj) throws IOException
     {
+      vec.addElement(Boolean.FALSE);
       vec.addElement(obj);
     }
 
Index: gnu/java/rmi/server/UnicastServer.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/java/rmi/server/UnicastServer.java,v
retrieving revision 1.4
diff -u -r1.4 UnicastServer.java
--- gnu/java/rmi/server/UnicastServer.java      31 Oct 2002 18:35:21 -0000      
1.4
+++ gnu/java/rmi/server/UnicastServer.java      26 Dec 2003 01:41:14 -0000
@@ -144,7 +144,7 @@
        (new UID()).write(out);
        if(returnval != null && returncls != null)
            ((RMIObjectOutputStream)out).writeValue(returnval, returncls);
-       else
+       else if (!(returnval instanceof RMIVoidValue))
            out.writeObject(returnval);
 
        out.flush();
Index: gnu/java/rmi/server/UnicastServerRef.java
===================================================================
RCS file: 
/cvsroot/classpath/classpath/gnu/java/rmi/server/UnicastServerRef.java,v
retrieving revision 1.7
diff -u -r1.7 UnicastServerRef.java
--- gnu/java/rmi/server/UnicastServerRef.java   13 Jul 2003 23:19:58 -0000      
1.7
+++ gnu/java/rmi/server/UnicastServerRef.java   26 Dec 2003 01:41:14 -0000
@@ -254,8 +254,11 @@
                        throw new NoSuchMethodException();
                }
                UnicastRemoteCall call = new UnicastRemoteCall(conn);
-               skel.dispatch(myself, call, method, hash);
-               return (call.returnValue());
+               skel.dispatch(myself, call, method, hash);                
+               if (!call.isReturnValue())
+                 return RMIVoidValue.INSTANCE;
+               else
+                 return (call.returnValue());
        }
 }
 

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]