|
From: <ls...@us...> - 2007-01-07 08:26:38
|
Revision: 3008
http://jnode.svn.sourceforge.net/jnode/?rev=3008&view=rev
Author: lsantha
Date: 2007-01-07 00:26:36 -0800 (Sun, 07 Jan 2007)
Log Message:
-----------
Classpath patches.
Modified Paths:
--------------
trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Creator.java
trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Indexer.java
trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Main.java
trunk/core/src/classpath/tools/gnu/classpath/tools/jar/WorkSet.java
trunk/core/src/classpath/tools/gnu/classpath/tools/jarsigner/Main.java
trunk/core/src/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
trunk/core/src/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java
Modified: trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Creator.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Creator.java 2007-01-07 08:25:33 UTC (rev 3007)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Creator.java 2007-01-07 08:26:36 UTC (rev 3008)
@@ -60,7 +60,7 @@
extends Action
{
JarOutputStream outputStream;
- HashSet writtenItems = new HashSet();
+ HashSet<String> writtenItems = new HashSet<String>();
// The manifest to use, or null if we don't want a manifest.
Manifest manifest;
@@ -142,18 +142,21 @@
throws IOException
{
boolean isDirectory = file.isDirectory();
- InputStream inputStream = null;
if (isDirectory)
{
if (filename.charAt(filename.length() - 1) != '/')
filename += '/';
+ writeFile(isDirectory, null, filename, verbose);
}
else
- inputStream = new FileInputStream(file);
+ {
+ InputStream inputStream = new FileInputStream(file);
writeFile(isDirectory, inputStream, filename, verbose);
+ inputStream.close();
+ }
}
- private void addEntries(ArrayList result, Entry entry)
+ private void addEntries(ArrayList<Entry> result, Entry entry)
{
if (entry.file.isDirectory())
{
@@ -173,10 +176,10 @@
result.add(entry);
}
- private ArrayList getAllEntries(Main parameters)
+ private ArrayList<Entry> getAllEntries(Main parameters)
{
Iterator it = parameters.entries.iterator();
- ArrayList allEntries = new ArrayList();
+ ArrayList<Entry> allEntries = new ArrayList<Entry>();
while (it.hasNext())
{
Entry entry = (Entry) it.next();
Modified: trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Indexer.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Indexer.java 2007-01-07 08:25:33 UTC (rev 3007)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Indexer.java 2007-01-07 08:26:36 UTC (rev 3008)
@@ -72,7 +72,7 @@
// Index the files in this jar.
// The results look a little better if we keep them
// in insertion order.
- LinkedHashSet entries = new LinkedHashSet();
+ LinkedHashSet<String> entries = new LinkedHashSet<String>();
Enumeration e = jf.entries();
while (e.hasMoreElements())
{
Modified: trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Main.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Main.java 2007-01-07 08:25:33 UTC (rev 3007)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/jar/Main.java 2007-01-07 08:26:36 UTC (rev 3008)
@@ -78,7 +78,7 @@
File manifestFile;
/** A list of Entry objects, each describing a file to write. */
- ArrayList entries = new ArrayList();
+ ArrayList<Entry> entries = new ArrayList<Entry>();
/** Used only while parsing, holds the first argument for -C. */
String changedDirectory;
Modified: trunk/core/src/classpath/tools/gnu/classpath/tools/jar/WorkSet.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/jar/WorkSet.java 2007-01-07 08:25:33 UTC (rev 3007)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/jar/WorkSet.java 2007-01-07 08:26:36 UTC (rev 3008)
@@ -44,13 +44,13 @@
public class WorkSet
{
- private HashSet allItems;
+ private HashSet<String> allItems;
private void initSet(ArrayList entries)
{
if (entries == null || entries.isEmpty())
return;
- allItems = new HashSet();
+ allItems = new HashSet<String>();
Iterator it = entries.iterator();
while (it.hasNext())
{
Modified: trunk/core/src/classpath/tools/gnu/classpath/tools/jarsigner/Main.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/jarsigner/Main.java 2007-01-07 08:25:33 UTC (rev 3007)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/jarsigner/Main.java 2007-01-07 08:26:36 UTC (rev 3008)
@@ -123,7 +123,7 @@
private CallbackHandler handler;
/** The command line parser. */
private ToolParser cmdLineParser;
- protected ArrayList fileAndAlias = new ArrayList();;
+ protected ArrayList fileAndAlias = new ArrayList();
private Main()
{
Modified: trunk/core/src/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java 2007-01-07 08:25:33 UTC (rev 3007)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java 2007-01-07 08:26:36 UTC (rev 3008)
@@ -180,6 +180,5 @@
public static void main(String[] args)
{
new Native2ASCII().run(args);
- String encoding = System.getProperty("file.encoding"); //$NON-NLS-1$
}
}
Modified: trunk/core/src/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java 2007-01-07 08:25:33 UTC (rev 3007)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/serialver/SerialVer.java 2007-01-07 08:26:36 UTC (rev 3008)
@@ -45,12 +45,12 @@
public class SerialVer
{
// List of classes to load.
- ArrayList classes = new ArrayList();
+ ArrayList<String> classes = new ArrayList<String>();
// The class path to use.
String classpath;
// FIXME: taken from ClassLoader, should share it.
- private static void addFileURL(ArrayList list, String file)
+ private static void addFileURL(ArrayList<URL> list, String file)
{
try
{
@@ -72,7 +72,7 @@
{
StringTokenizer tok = new StringTokenizer(classpath,
File.pathSeparator, true);
- ArrayList list = new ArrayList();
+ ArrayList<URL> list = new ArrayList<URL>();
while (tok.hasMoreTokens())
{
String s = tok.nextToken();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <ls...@us...> - 2007-01-07 13:28:26
|
Revision: 3027
http://jnode.svn.sourceforge.net/jnode/?rev=3027&view=rev
Author: lsantha
Date: 2007-01-07 05:28:25 -0800 (Sun, 07 Jan 2007)
Log Message:
-----------
Classpath patches.
Added Paths:
-----------
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/AbstractMethodGenerator.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/CompilationError.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/Generator.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/GiopIo.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/HashFinder.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/Main.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/Messages.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/MethodGenerator.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/RMICException.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/RmiMethodGenerator.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/RmicBackend.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/SourceGiopRmicCompiler.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/SourceRmicCompiler.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/Variables.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/WrapUnWrapper.java
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/messages.properties
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/ImplTie.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/Stub.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/StubMethod.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/StubMethodVoid.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12Method.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/Stub_12MethodVoid.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/Tie.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/TieMethod.jav
trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/templates/TieMethodVoid.jav
Added: trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/AbstractMethodGenerator.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/AbstractMethodGenerator.java (rev 0)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/AbstractMethodGenerator.java 2007-01-07 13:28:25 UTC (rev 3027)
@@ -0,0 +1,53 @@
+/* AbstractMethodGenerator.java -- the abstract method generator
+ Copyright (C) 2006 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., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 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.classpath.tools.rmic;
+
+public interface AbstractMethodGenerator
+{
+ /**
+ * Generate this method for the Stub (remote caller) class.
+ */
+ String generateStubMethod();
+
+ /**
+ * Generate this method for the Tie (remote servant) class.
+ */
+ String generateTieMethod();
+
+}
Added: trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java
===================================================================
--- trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java (rev 0)
+++ trunk/core/src/classpath/tools/gnu/classpath/tools/rmic/ClassRmicCompiler.java 2007-01-07 13:28:25 UTC (rev 3027)
@@ -0,0 +1,1824 @@
+/* ClassRmicCompiler.java --
+ Copyright (c) 1996, 1997, 1998, 1999, 2001, 2002, 2003, 2004, 2005
+ 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. */
+
+package gnu.classpath.tools.rmic;
+
+import gnu.java.rmi.server.RMIHashes;
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+import java.io.PrintWriter;
+import java.lang.reflect.Method;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.rmi.MarshalException;
+import java.rmi.Remote;
+import java.rmi.RemoteException;
+import java.rmi.UnexpectedException;
+import java.rmi.UnmarshalException;
+import java.rmi.server.Operation;
+import java.rmi.server.RemoteCall;
+import java.rmi.server.RemoteObject;
+import java.rmi.server.RemoteRef;
+import java.rmi.server.RemoteStub;
+import java.rmi.server.Skeleton;
+import java.rmi.server.SkeletonMismatchException;
+import java.security.MessageDigest;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import java.util.StringTokenizer;
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.ClassWriter;
+import org.objectweb.asm.MethodVisitor;
+import org.objectweb.asm.Opcodes;
+import org.objectweb.asm.Label;
+import org.objectweb.asm.Type;
+
+public class ClassRmicCompiler
+ implements RmicBackend
+{
+ private String[] args;
+ private int next;
+ private List errors = new ArrayList();
+ private boolean keep = false;
+ private boolean need11Stubs = true;
+ private boolean need12Stubs = true;
+ private boolean compile = true;
+ private boolean verbose;
+ private boolean noWrite;
+ private String destination;
+ private String classpath;
+ private ClassLoader loader;
+ private int errorCount = 0;
+
+ private Class clazz;
+ private String classname;
+ private String classInternalName;
+ private String fullclassname;
+ private MethodRef[] remotemethods;
+ private String stubname;
+ private String skelname;
+ private List mRemoteInterfaces;
+
+ /**
+ * @return true if run was successful
+ */
+ public boolean run(String[] inputFiles)
+ {
+ args = inputFiles;
+
+ if (next >= args.length)
+ return false;
+
+ for (int i = next; i < args.length; i++)
+ {
+ try
+ {
+ if (verbose)
+ System.out.println("[Processing class " + args[i] + ".class]");
+ processClass(args[i].replace(File.separatorChar, '.'));
+ }
+ catch (IOException e)
+ {
+ errors.add(e);
+ }
+ catch (RMICException e)
+ {
+ errors.add(e);
+ }
+ }
+ if (errors.size() > 0)
+ {
+ for (Iterator it = errors.iterator(); it.hasNext(); )
+ {
+ Exception ex = (Exception) it.next();
+ logError(ex);
+ }
+ }
+
+ return errorCount == 0;
+ }
+
+ private void processClass(String cls) throws IOException, RMICException
+ {
+ // reset class specific vars
+ clazz = null;
+ classname = null;
+ classInternalName = null;
+ fullclassname = null;
+ remotemethods = null;
+ stubname = null;
+ skelname = null;
+ mRemoteInterfaces = new ArrayList();
+
+ analyzeClass(cls);
+ generateStub();
+ if (need11Stubs)
+ generateSkel();
+ }
+
+ private void analyzeClass(String cname)
+ throws RMICException
+ {
+ if (verbose)
+ System.out.println("[analyze class " + cname + "]");
+ int p = cname.lastIndexOf('.');
+ if (p != -1)
+ classname = cname.substring(p + 1);
+ else
+ classname = cname;
+ fullclassname = cname;
+
+ findClass();
+ findRemoteMethods();
+ }
+
+ /**
+ * @deprecated
+ */
+ public Exception getException()
+ {
+ return errors.size() == 0 ? null : (Exception) errors.get(0);
+ }
+
+ private void findClass()
+ throws RMICException
+ {
+ ClassLoader cl = (loader == null
+ ? ClassLoader.getSystemClassLoader()
+ : loader);
+ try
+ {
+ clazz = Class.forName(fullclassname, false, cl);
+ }
+ catch (ClassNotFoundException cnfe)
+ {
+ throw new RMICException
+ ("Class " + fullclassname + " not found in classpath", cnfe);
+ }
+
+ if (! Remote.class.isAssignableFrom(clazz))
+ {
+ throw new RMICException
+ ("Class " + clazz.getName()
+ + " does not implement a remote interface.");
+ }
+ }
+
+ private static Type[] typeArray(Class[] cls)
+ {
+ Type[] t = new Type[cls.length];
+ for (int i = 0; i < cls.length; i++)
+ {
+ t[i] = Type.getType(cls[i]);
+ }
+
+ return t;
+ }
+
+ private static String[] internalNameArray(Type[] t)
+ {
+ String[] s = new String[t.length];
+ for (int i = 0; i < t.length; i++)
+ {
+ s[i] = t[i].getInternalName();
+ }
+
+ return s;
+ }
+
+ private static String[] internalNameArray(Class[] c)
+ {
+ return internalNameArray(typeArray(c));
+ }
+
+ private static final String forName = "class$";
+
+ private static Object param(Method m, int argIndex)
+ {
+ List l = new ArrayList();
+ l.add(m);
+ l.add(new Integer(argIndex));
+ return l;
+ }
+
+ private static void generateClassForNamer(ClassVisitor cls)
+ {
+ MethodVisitor cv =
+ cls.visitMethod
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_SYNTHETIC, forName,
+ Type.getMethodDescriptor
+ (Type.getType(Class.class), new Type[] { Type.getType(String.class) }),
+ null, null);
+
+ Label start = new Label();
+ cv.visitLabel(start);
+ cv.visitVarInsn(Opcodes.ALOAD, 0);
+ cv.visitMethodInsn
+ (Opcodes.INVOKESTATIC,
+ Type.getInternalName(Class.class),
+ "forName",
+ Type.getMethodDescriptor
+ (Type.getType(Class.class), new Type[] { Type.getType(String.class) }));
+ cv.visitInsn(Opcodes.ARETURN);
+
+ Label handler = new Label();
+ cv.visitLabel(handler);
+ cv.visitVarInsn(Opcodes.ASTORE, 1);
+ cv.visitTypeInsn(Opcodes.NEW, typeArg(NoClassDefFoundError.class));
+ cv.visitInsn(Opcodes.DUP);
+ cv.visitVarInsn(Opcodes.ALOAD, 1);
+ cv.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL,
+ Type.getInternalName(ClassNotFoundException.class),
+ "getMessage",
+ Type.getMethodDescriptor(Type.getType(String.class), new Type[] {}));
+ cv.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(NoClassDefFoundError.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(String.class) }));
+ cv.visitInsn(Opcodes.ATHROW);
+ cv.visitTryCatchBlock
+ (start, handler, handler,
+ Type.getInternalName(ClassNotFoundException.class));
+ cv.visitMaxs(-1, -1);
+ }
+
+ private void generateClassConstant(MethodVisitor cv, Class cls) {
+ if (cls.isPrimitive())
+ {
+ Class boxCls;
+ if (cls.equals(Boolean.TYPE))
+ boxCls = Boolean.class;
+ else if (cls.equals(Character.TYPE))
+ boxCls = Character.class;
+ else if (cls.equals(Byte.TYPE))
+ boxCls = Byte.class;
+ else if (cls.equals(Short.TYPE))
+ boxCls = Short.class;
+ else if (cls.equals(Integer.TYPE))
+ boxCls = Integer.class;
+ else if (cls.equals(Long.TYPE))
+ boxCls = Long.class;
+ else if (cls.equals(Float.TYPE))
+ boxCls = Float.class;
+ else if (cls.equals(Double.TYPE))
+ boxCls = Double.class;
+ else if (cls.equals(Void.TYPE))
+ boxCls = Void.class;
+ else
+ throw new IllegalArgumentException("unknown primitive type " + cls);
+
+ cv.visitFieldInsn
+ (Opcodes.GETSTATIC, Type.getInternalName(boxCls), "TYPE",
+ Type.getDescriptor(Class.class));
+ return;
+ }
+ cv.visitLdcInsn(cls.getName());
+ cv.visitMethodInsn
+ (Opcodes.INVOKESTATIC, classInternalName, forName,
+ Type.getMethodDescriptor
+ (Type.getType(Class.class),
+ new Type[] { Type.getType(String.class) }));
+ }
+
+ private void generateClassArray(MethodVisitor code, Class[] classes)
+ {
+ code.visitLdcInsn(new Integer(classes.length));
+ code.visitTypeInsn(Opcodes.ANEWARRAY, typeArg(Class.class));
+ for (int i = 0; i < classes.length; i++)
+ {
+ code.visitInsn(Opcodes.DUP);
+ code.visitLdcInsn(new Integer(i));
+ generateClassConstant(code, classes[i]);
+ code.visitInsn(Opcodes.AASTORE);
+ }
+ }
+
+ private void fillOperationArray(MethodVisitor clinit)
+ {
+ // Operations array
+ clinit.visitLdcInsn(new Integer(remotemethods.length));
+ clinit.visitTypeInsn(Opcodes.ANEWARRAY, typeArg(Operation.class));
+ clinit.visitFieldInsn
+ (Opcodes.PUTSTATIC, classInternalName, "operations",
+ Type.getDescriptor(Operation[].class));
+
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ Method m = remotemethods[i].meth;
+
+ StringBuffer desc = new StringBuffer();
+ desc.append(getPrettyName(m.getReturnType()) + " ");
+ desc.append(m.getName() + "(");
+
+ // signature
+ Class[] sig = m.getParameterTypes();
+ for (int j = 0; j < sig.length; j++)
+ {
+ desc.append(getPrettyName(sig[j]));
+ if (j + 1 < sig.length)
+ desc.append(", ");
+ }
+
+ // push operations array
+ clinit.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, "operations",
+ Type.getDescriptor(Operation[].class));
+
+ // push array index
+ clinit.visitLdcInsn(new Integer(i));
+
+ // instantiate operation and leave a copy on the stack
+ clinit.visitTypeInsn(Opcodes.NEW, typeArg(Operation.class));
+ clinit.visitInsn(Opcodes.DUP);
+ clinit.visitLdcInsn(desc.toString());
+ clinit.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(Operation.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] { Type.getType(String.class) }));
+
+ // store in operations array
+ clinit.visitInsn(Opcodes.AASTORE);
+ }
+ }
+
+ private void generateStaticMethodObjs(MethodVisitor clinit)
+ {
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ Method m = remotemethods[i].meth;
+
+ /*
+ * $method_<i>m.getName()</i>_<i>i</i> =
+ * <i>m.getDeclaringClass()</i>.class.getMethod
+ * (m.getName(), m.getParameterType())
+ */
+ String methodVar = "$method_" + m.getName() + "_" + i;
+ generateClassConstant(clinit, m.getDeclaringClass());
+ clinit.visitLdcInsn(m.getName());
+ generateClassArray(clinit, m.getParameterTypes());
+ clinit.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL,
+ Type.getInternalName(Class.class),
+ "getMethod",
+ Type.getMethodDescriptor
+ (Type.getType(Method.class),
+ new Type[] { Type.getType(String.class),
+ Type.getType(Class[].class) }));
+
+ clinit.visitFieldInsn
+ (Opcodes.PUTSTATIC, classInternalName, methodVar,
+ Type.getDescriptor(Method.class));
+ }
+ }
+
+ private void generateStub()
+ throws IOException
+ {
+ stubname = fullclassname + "_Stub";
+ String stubclassname = classname + "_Stub";
+ File file = new File((destination == null ? "." : destination)
+ + File.separator
+ + stubname.replace('.', File.separatorChar)
+ + ".class");
+
+ if (verbose)
+ System.out.println("[Generating class " + stubname + "]");
+
+ final ClassWriter stub = new ClassWriter(true);
+ classInternalName = stubname.replace('.', '/');
+ final String superInternalName =
+ Type.getType(RemoteStub.class).getInternalName();
+
+ String[] remoteInternalNames =
+ internalNameArray((Class[]) mRemoteInterfaces.toArray(new Class[] {}));
+ stub.visit
+ (Opcodes.V1_2, Opcodes.ACC_PUBLIC + Opcodes.ACC_FINAL, classInternalName,
+ null, superInternalName, remoteInternalNames);
+
+ if (need12Stubs)
+ {
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL, "serialVersionUID",
+ Type.LONG_TYPE.getDescriptor(), null, new Long(2L));
+ }
+
+ if (need11Stubs)
+ {
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL,
+ "interfaceHash", Type.LONG_TYPE.getDescriptor(), null,
+ new Long(RMIHashes.getInterfaceHash(clazz)));
+
+ if (need12Stubs)
+ {
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, "useNewInvoke",
+ Type.BOOLEAN_TYPE.getDescriptor(), null, null);
+ }
+
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC + Opcodes.ACC_FINAL,
+ "operations", Type.getDescriptor(Operation[].class), null, null);
+ }
+
+ // Set of method references.
+ if (need12Stubs)
+ {
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ Method m = remotemethods[i].meth;
+ String slotName = "$method_" + m.getName() + "_" + i;
+ stub.visitField
+ (Opcodes.ACC_PRIVATE + Opcodes.ACC_STATIC, slotName,
+ Type.getDescriptor(Method.class), null, null);
+ }
+ }
+
+ MethodVisitor clinit = stub.visitMethod
+ (Opcodes.ACC_STATIC, "<clinit>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}), null, null);
+
+ if (need11Stubs)
+ {
+ fillOperationArray(clinit);
+ if (! need12Stubs)
+ clinit.visitInsn(Opcodes.RETURN);
+ }
+
+ if (need12Stubs)
+ {
+ // begin of try
+ Label begin = new Label();
+
+ // beginning of catch
+ Label handler = new Label();
+ clinit.visitLabel(begin);
+
+ // Initialize the methods references.
+ if (need11Stubs)
+ {
+ /*
+ * RemoteRef.class.getMethod("invoke", new Class[] {
+ * Remote.class, Method.class, Object[].class, long.class })
+ */
+ generateClassConstant(clinit, RemoteRef.class);
+ clinit.visitLdcInsn("invoke");
+ generateClassArray
+ (clinit, new Class[] { Remote.class, Method.class,
+ Object[].class, long.class });
+ clinit.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL,
+ Type.getInternalName(Class.class),
+ "getMethod",
+ Type.getMethodDescriptor
+ (Type.getType(Method.class),
+ new Type[] { Type.getType(String.class),
+ Type.getType(Class[].class) }));
+
+ // useNewInvoke = true
+ clinit.visitInsn(Opcodes.ICONST_1);
+ clinit.visitFieldInsn
+ (Opcodes.PUTSTATIC, classInternalName, "useNewInvoke",
+ Type.BOOLEAN_TYPE.getDescriptor());
+ }
+
+ generateStaticMethodObjs(clinit);
+
+ // jump past handler
+ clinit.visitInsn(Opcodes.RETURN);
+ clinit.visitLabel(handler);
+ if (need11Stubs)
+ {
+ // useNewInvoke = false
+ clinit.visitInsn(Opcodes.ICONST_0);
+ clinit.visitFieldInsn
+ (Opcodes.PUTSTATIC, classInternalName, "useNewInvoke",
+ Type.BOOLEAN_TYPE.getDescriptor());
+ clinit.visitInsn(Opcodes.RETURN);
+ }
+ else
+ {
+ // throw NoSuchMethodError
+ clinit.visitTypeInsn(Opcodes.NEW, typeArg(NoSuchMethodError.class));
+ clinit.visitInsn(Opcodes.DUP);
+ clinit.visitLdcInsn("stub class initialization failed");
+ clinit.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(NoSuchMethodError.class),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(String.class) }));
+ clinit.visitInsn(Opcodes.ATHROW);
+ }
+
+ clinit.visitTryCatchBlock
+ (begin, handler, handler,
+ Type.getInternalName(NoSuchMethodException.class));
+
+ }
+
+ clinit.visitMaxs(-1, -1);
+
+ generateClassForNamer(stub);
+
+ // Constructors
+ if (need11Stubs)
+ {
+ // no arg public constructor
+ MethodVisitor code = stub.visitMethod
+ (Opcodes.ACC_PUBLIC, "<init>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}),
+ null, null);
+ code.visitVarInsn(Opcodes.ALOAD, 0);
+ code.visitMethodInsn
+ (Opcodes.INVOKESPECIAL, superInternalName, "<init>",
+ Type.getMethodDescriptor(Type.VOID_TYPE, new Type[] {}));
+ code.visitInsn(Opcodes.RETURN);
+
+ code.visitMaxs(-1, -1);
+ }
+
+ // public RemoteRef constructor
+ MethodVisitor constructor = stub.visitMethod
+ (Opcodes.ACC_PUBLIC, "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] {Type.getType(RemoteRef.class)}),
+ null, null);
+ constructor.visitVarInsn(Opcodes.ALOAD, 0);
+ constructor.visitVarInsn(Opcodes.ALOAD, 1);
+ constructor.visitMethodInsn
+ (Opcodes.INVOKESPECIAL, superInternalName, "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE, new Type[] {Type.getType(RemoteRef.class)}));
+ constructor.visitInsn(Opcodes.RETURN);
+ constructor.visitMaxs(-1, -1);
+
+ // Method implementations
+ for (int i = 0; i < remotemethods.length; i++)
+ {
+ Method m = remotemethods[i].meth;
+ Class[] sig = m.getParameterTypes();
+ Class returntype = m.getReturnType();
+ Class[] except = sortExceptions
+ ((Class[]) remotemethods[i].exceptions.toArray(new Class[0]));
+
+ MethodVisitor code = stub.visitMethod
+ (Opcodes.ACC_PUBLIC,
+ m.getName(),
+ Type.getMethodDescriptor(Type.getType(returntype), typeArray(sig)),
+ null,
+ internalNameArray(typeArray(except)));
+
+ final Variables var = new Variables();
+
+ // this and parameters are the declared vars
+ var.declare("this");
+ for (int j = 0; j < sig.length; j++)
+ var.declare(param(m, j), size(sig[j]));
+
+ Label methodTryBegin = new Label();
+ code.visitLabel(methodTryBegin);
+
+ if (need12Stubs)
+ {
+ Label oldInvoke = new Label();
+ if (need11Stubs)
+ {
+ // if not useNewInvoke jump to old invoke
+ code.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, "useNewInvoke",
+ Type.getDescriptor(boolean.class));
+ code.visitJumpInsn(Opcodes.IFEQ, oldInvoke);
+ }
+
+ // this.ref
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+ code.visitFieldInsn
+ (Opcodes.GETFIELD, Type.getInternalName(RemoteObject.class),
+ "ref", Type.getDescriptor(RemoteRef.class));
+
+ // "this" is first arg to invoke
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+
+ // method object is second arg to invoke
+ String methName = "$method_" + m.getName() + "_" + i;
+ code.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, methName,
+ Type.getDescriptor(Method.class));
+
+ // args to remote method are third arg to invoke
+ if (sig.length == 0)
+ code.visitInsn(Opcodes.ACONST_NULL);
+ else
+ {
+ // create arg Object[] (with boxed primitives) and push it
+ code.visitLdcInsn(new Integer(sig.length));
+ code.visitTypeInsn(Opcodes.ANEWARRAY, typeArg(Object.class));
+
+ var.allocate("argArray");
+ code.visitVarInsn(Opcodes.ASTORE, var.get("argArray"));
+
+ for (int j = 0; j < sig.length; j++)
+ {
+ int size = size(sig[j]);
+ int insn = loadOpcode(sig[j]);
+ Class box = sig[j].isPrimitive() ? box(sig[j]) : null;
+
+ code.visitVarInsn(Opcodes.ALOAD, var.get("argArray"));
+ code.visitLdcInsn(new Integer(j));
+
+ // put argument on stack
+ if (box != null)
+ {
+ code.visitTypeInsn(Opcodes.NEW, typeArg(box));
+ code.visitInsn(Opcodes.DUP);
+ code.visitVarInsn(insn, var.get(param(m, j)));
+ code.visitMethodInsn
+ (Opcodes.INVOKESPECIAL,
+ Type.getInternalName(box),
+ "<init>",
+ Type.getMethodDescriptor
+ (Type.VOID_TYPE,
+ new Type[] { Type.getType(sig[j]) }));
+ }
+ else
+ code.visitVarInsn(insn, var.get(param(m, j)));
+
+ code.visitInsn(Opcodes.AASTORE);
+ }
+
+ code.visitVarInsn(Opcodes.ALOAD, var.deallocate("argArray"));
+ }
+
+ // push remote operation opcode
+ code.visitLdcInsn(new Long(remotemethods[i].hash));
+ code.visitMethodInsn
+ (Opcodes.INVOKEINTERFACE,
+ Type.getInternalName(RemoteRef.class),
+ "invoke",
+ Type.getMethodDescriptor
+ (Type.getType(Object.class),
+ new Type[] { Type.getType(Remote.class),
+ Type.getType(Method.class),
+ Type.getType(Object[].class),
+ Type.LONG_TYPE }));
+
+ if (! returntype.equals(Void.TYPE))
+ {
+ int retcode = returnOpcode(returntype);
+ Class boxCls =
+ returntype.isPrimitive() ? box(returntype) : null;
+ code.visitTypeInsn
+ (Opcodes.CHECKCAST, typeArg(boxCls == null ? returntype : boxCls));
+ if (returntype.isPrimitive())
+ {
+ // unbox
+ code.visitMethodInsn
+ (Opcodes.INVOKEVIRTUAL,
+ Type.getType(boxCls).getInternalName(),
+ unboxMethod(returntype),
+ Type.getMethodDescriptor
+ (Type.getType(returntype), new Type[] {}));
+ }
+
+ code.visitInsn(retcode);
+ }
+ else
+ code.visitInsn(Opcodes.RETURN);
+
+
+ if (need11Stubs)
+ code.visitLabel(oldInvoke);
+ }
+
+ if (need11Stubs)
+ {
+
+ // this.ref.newCall(this, operations, index, interfaceHash)
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+ code.visitFieldInsn
+ (Opcodes.GETFIELD,
+ Type.getInternalName(RemoteObject.class),
+ "ref",
+ Type.getDescriptor(RemoteRef.class));
+
+ // "this" is first arg to newCall
+ code.visitVarInsn(Opcodes.ALOAD, var.get("this"));
+
+ // operations is second arg to newCall
+ code.visitFieldInsn
+ (Opcodes.GETSTATIC, classInternalName, "operations",
+ ...
[truncated message content] |
|
From: <ls...@us...> - 2007-06-25 11:24:42
|
Revision: 3313
http://jnode.svn.sourceforge.net/jnode/?rev=3313&view=rev
Author: lsantha
Date: 2007-06-25 04:24:41 -0700 (Mon, 25 Jun 2007)
Log Message:
-----------
Openjdk integration.
Removed Paths:
-------------
trunk/core/src/classpath/tools/gnu/classpath/tools/orbd/
trunk/core/src/classpath/tools/gnu/classpath/tools/tnameserv/
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|