aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/vm
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2006-05-18 17:29:21 +0000
committerMark Wielaard <mark@klomp.org>2006-05-18 17:29:21 +0000
commit3511394ff70f9d961622c14ca4aef175561dc5d3 (patch)
tree9f9c470de62ee62fba1331a396450d728d2b1fad /libjava/classpath/vm
parent8551e6d83c5686adda9ec0bb27597ba76d00798a (diff)
Imported GNU Classpath 0.90
* scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale. * sources.am: Regenerated. * gcj/javaprims.h: Regenerated. * Makefile.in: Regenerated. * gcj/Makefile.in: Regenerated. * include/Makefile.in: Regenerated. * testsuite/Makefile.in: Regenerated. * gnu/java/lang/VMInstrumentationImpl.java: New override. * gnu/java/net/local/LocalSocketImpl.java: Likewise. * gnu/classpath/jdwp/VMMethod.java: Likewise. * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest interface. * java/lang/Thread.java: Add UncaughtExceptionHandler. * java/lang/reflect/Method.java: Implements GenericDeclaration and isSynthetic(), * java/lang/reflect/Field.java: Likewise. * java/lang/reflect/Constructor.java * java/lang/Class.java: Implements Type, GenericDeclaration, getSimpleName() and getEnclosing*() methods. * java/lang/Class.h: Add new public methods. * java/lang/Math.java: Add signum(), ulp() and log10(). * java/lang/natMath.cc (log10): New function. * java/security/VMSecureRandom.java: New override. * java/util/logging/Logger.java: Updated to latest classpath version. * java/util/logging/LogManager.java: New override. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@113887 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/vm')
-rw-r--r--libjava/classpath/vm/reference/gnu/classpath/Unsafe.java328
-rw-r--r--libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java6
-rw-r--r--libjava/classpath/vm/reference/gnu/classpath/jdwp/VMMethod.java178
-rw-r--r--libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java68
-rw-r--r--libjava/classpath/vm/reference/gnu/java/lang/VMInstrumentationImpl.java108
-rw-r--r--libjava/classpath/vm/reference/java/lang/VMClass.java181
-rw-r--r--libjava/classpath/vm/reference/java/lang/VMClassLoader.java92
-rw-r--r--libjava/classpath/vm/reference/java/lang/VMProcess.java46
-rw-r--r--libjava/classpath/vm/reference/java/lang/VMSystem.java71
-rw-r--r--libjava/classpath/vm/reference/java/lang/VMThread.java6
-rw-r--r--libjava/classpath/vm/reference/java/lang/reflect/Constructor.java163
-rw-r--r--libjava/classpath/vm/reference/java/lang/reflect/Field.java81
-rw-r--r--libjava/classpath/vm/reference/java/lang/reflect/Method.java213
-rw-r--r--libjava/classpath/vm/reference/java/lang/reflect/VMArray.java65
-rw-r--r--libjava/classpath/vm/reference/java/security/VMSecureRandom.java134
15 files changed, 1604 insertions, 136 deletions
diff --git a/libjava/classpath/vm/reference/gnu/classpath/Unsafe.java b/libjava/classpath/vm/reference/gnu/classpath/Unsafe.java
new file mode 100644
index 00000000000..6e4ec98027f
--- /dev/null
+++ b/libjava/classpath/vm/reference/gnu/classpath/Unsafe.java
@@ -0,0 +1,328 @@
+/* Unsafe.java - Unsafe operations needed for concurrency
+ Copyright (C) 2006 Free Software Foundation
+
+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;
+
+import java.lang.reflect.Field;
+
+/**
+ * This class should provide access to low-level operations and its
+ * use should be limited to trusted code. Fields can be accessed using
+ * memory addresses, with undefined behaviour occurring if invalid memory
+ * addresses are given.
+ *
+ * @author Tom Tromey (tromey@redhat.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ */
+public final class Unsafe
+{
+ // Singleton class.
+ private static Unsafe unsafe = new Unsafe();
+
+ /**
+ * Private default constructor to prevent creation of an arbitrary
+ * number of instances.
+ */
+ private Unsafe()
+ {
+ }
+
+ /**
+ * Retrieve the singleton instance of <code>Unsafe</code>. The calling
+ * method should guard this instance from untrusted code, as it provides
+ * access to low-level operations such as direct memory access.
+ *
+ * @throws SecurityException if a security manager exists and prevents
+ * access to the system properties.
+ */
+ public static Unsafe getUnsafe()
+ {
+ SecurityManager sm = System.getSecurityManager();
+ if (sm != null)
+ sm.checkPropertiesAccess();
+ return unsafe;
+ }
+
+ /**
+ * Returns the memory address offset of the given static field.
+ * The offset is merely used as a means to access a particular field
+ * in the other methods of this class. The value is unique to the given
+ * field and the same value should be returned on each subsequent call.
+ *
+ * @param field the field whose offset should be returned.
+ * @return the offset of the given field.
+ */
+ public native long objectFieldOffset(Field field);
+
+ /**
+ * Compares the value of the integer field at the specified offset
+ * in the supplied object with the given expected value, and updates
+ * it if they match. The operation of this method should be atomic,
+ * thus providing an uninterruptible way of updating an integer field.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the integer field within <code>obj</code>.
+ * @param expect the expected value of the field.
+ * @param update the new value of the field if it equals <code>expect</code>.
+ * @return true if the field was changed.
+ */
+ public native boolean compareAndSwapInt(Object obj, long offset,
+ int expect, int update);
+
+ /**
+ * Compares the value of the long field at the specified offset
+ * in the supplied object with the given expected value, and updates
+ * it if they match. The operation of this method should be atomic,
+ * thus providing an uninterruptible way of updating a long field.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the long field within <code>obj</code>.
+ * @param expect the expected value of the field.
+ * @param update the new value of the field if it equals <code>expect</code>.
+ * @return true if the field was changed.
+ */
+ public native boolean compareAndSwapLong(Object obj, long offset,
+ long expect, long update);
+
+ /**
+ * Compares the value of the object field at the specified offset
+ * in the supplied object with the given expected value, and updates
+ * it if they match. The operation of this method should be atomic,
+ * thus providing an uninterruptible way of updating an object field.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the object field within <code>obj</code>.
+ * @param expect the expected value of the field.
+ * @param update the new value of the field if it equals <code>expect</code>.
+ * @return true if the field was changed.
+ */
+ public native boolean compareAndSwapObject(Object obj, long offset,
+ Object expect, Object update);
+
+ /**
+ * Sets the value of the integer field at the specified offset in the
+ * supplied object to the given value. This is an ordered or lazy
+ * version of <code>putIntVolatile(Object,long,int)</code>, which
+ * doesn't guarantee the immediate visibility of the change to other
+ * threads. It is only really useful where the integer field is
+ * <code>volatile</code>, and is thus expected to change unexpectedly.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the integer field within <code>obj</code>.
+ * @param value the new value of the field.
+ * @see #putIntVolatile(Object,long,int)
+ */
+ public native void putOrderedInt(Object obj, long offset, int value);
+
+ /**
+ * Sets the value of the long field at the specified offset in the
+ * supplied object to the given value. This is an ordered or lazy
+ * version of <code>putLongVolatile(Object,long,long)</code>, which
+ * doesn't guarantee the immediate visibility of the change to other
+ * threads. It is only really useful where the long field is
+ * <code>volatile</code>, and is thus expected to change unexpectedly.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the long field within <code>obj</code>.
+ * @param value the new value of the field.
+ * @see #putLongVolatile(Object,long,long)
+ */
+ public native void putOrderedLong(Object obj, long offset, long value);
+
+ /**
+ * Sets the value of the object field at the specified offset in the
+ * supplied object to the given value. This is an ordered or lazy
+ * version of <code>putObjectVolatile(Object,long,Object)</code>, which
+ * doesn't guarantee the immediate visibility of the change to other
+ * threads. It is only really useful where the object field is
+ * <code>volatile</code>, and is thus expected to change unexpectedly.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the object field within <code>obj</code>.
+ * @param value the new value of the field.
+ */
+ public native void putOrderedObject(Object obj, long offset, Object value);
+
+ /**
+ * Sets the value of the integer field at the specified offset in the
+ * supplied object to the given value, with volatile store semantics.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the integer field within <code>obj</code>.
+ * @param value the new value of the field.
+ */
+ public native void putIntVolatile(Object obj, long offset, int value);
+
+ /**
+ * Retrieves the value of the integer field at the specified offset in the
+ * supplied object with volatile load semantics.
+ *
+ * @param obj the object containing the field to read.
+ * @param offset the offset of the integer field within <code>obj</code>.
+ */
+ public native int getIntVolatile(Object obj, long offset);
+
+ /**
+ * Sets the value of the long field at the specified offset in the
+ * supplied object to the given value, with volatile store semantics.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the long field within <code>obj</code>.
+ * @param value the new value of the field.
+ * @see #putLong(Object,long,long)
+ */
+ public native void putLongVolatile(Object obj, long offset, long value);
+
+ /**
+ * Sets the value of the long field at the specified offset in the
+ * supplied object to the given value.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the long field within <code>obj</code>.
+ * @param value the new value of the field.
+ * @see #putLongVolatile(Object,long,long)
+ */
+ public native void putLong(Object obj, long offset, long value);
+
+ /**
+ * Retrieves the value of the long field at the specified offset in the
+ * supplied object with volatile load semantics.
+ *
+ * @param obj the object containing the field to read.
+ * @param offset the offset of the long field within <code>obj</code>.
+ * @see #getLong(Object,long)
+ */
+ public native long getLongVolatile(Object obj, long offset);
+
+ /**
+ * Retrieves the value of the long field at the specified offset in the
+ * supplied object.
+ *
+ * @param obj the object containing the field to read.
+ * @param offset the offset of the long field within <code>obj</code>.
+ * @see #getLongVolatile(Object,long)
+ */
+ public native long getLong(Object obj, long offset);
+
+ /**
+ * Sets the value of the object field at the specified offset in the
+ * supplied object to the given value, with volatile store semantics.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the object field within <code>obj</code>.
+ * @param value the new value of the field.
+ * @see #putObject(Object,long,Object)
+ */
+ public native void putObjectVolatile(Object obj, long offset, Object value);
+
+ /**
+ * Sets the value of the object field at the specified offset in the
+ * supplied object to the given value.
+ *
+ * @param obj the object containing the field to modify.
+ * @param offset the offset of the object field within <code>obj</code>.
+ * @param value the new value of the field.
+ * @see #putObjectVolatile(Object,long,Object)
+ */
+ public native void putObject(Object obj, long offset, Object value);
+
+ /**
+ * Retrieves the value of the object field at the specified offset in the
+ * supplied object with volatile load semantics.
+ *
+ * @param obj the object containing the field to read.
+ * @param offset the offset of the object field within <code>obj</code>.
+ */
+ public native Object getObjectVolatile(Object obj, long offset);
+
+ /**
+ * Returns the offset of the first element for a given array class.
+ * To access elements of the array class, this value may be used along
+ * with that returned by
+ * <a href="#arrayIndexScale"><code>arrayIndexScale</code></a>,
+ * if non-zero.
+ *
+ * @param arrayClass the class for which the first element's address should
+ * be obtained.
+ * @return the offset of the first element of the array class.
+ * @see #arrayIndexScale(Class)
+ */
+ public native int arrayBaseOffset(Class arrayClass);
+
+ /**
+ * Returns the scale factor used for addressing elements of the supplied
+ * array class. Where a suitable scale factor can not be returned (e.g.
+ * for primitive types), zero should be returned. The returned value
+ * can be used with
+ * <a href="#arrayBaseOffset"><code>arrayBaseOffset</code></a>
+ * to access elements of the class.
+ *
+ * @param arrayClass the class whose scale factor should be returned.
+ * @return the scale factor, or zero if not supported for this array class.
+ */
+ public native int arrayIndexScale(Class arrayClass);
+
+ /**
+ * Releases the block on a thread created by
+ * <a href="#park"><code>park</code></a>. This method can also be used
+ * to terminate a blockage caused by a prior call to <code>park</code>.
+ * This operation is unsafe, as the thread must be guaranteed to be
+ * live. This is true of Java, but not native code.
+ *
+ * @param thread the thread to unblock.
+ */
+ public native void unpark(Thread thread);
+
+ /**
+ * Blocks the thread until a matching
+ * <a href="#unpark"><code>unpark</code></a> occurs, the thread is
+ * interrupted or the optional timeout expires. If an <code>unpark</code>
+ * call has already occurred, this also counts. A timeout value of zero
+ * is defined as no timeout. When <code>isAbsolute</code> is
+ * <code>true</code>, the timeout is in milliseconds relative to the
+ * epoch. Otherwise, the value is the number of nanoseconds which must
+ * occur before timeout. This call may also return spuriously (i.e.
+ * for no apparent reason).
+ *
+ * @param isAbsolute true if the timeout is specified in milliseconds from
+ * the epoch.
+ * @param time either the number of nanoseconds to wait, or a time in
+ * milliseconds from the epoch to wait for.
+ */
+ public native void park(boolean isAbsolute, long time);
+
+}
diff --git a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java
index 6a8be10145f..8d423e9b0d6 100644
--- a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java
+++ b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java
@@ -48,11 +48,9 @@ import gnu.classpath.jdwp.id.*;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
-import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashMap;
import java.util.Hashtable;
-import java.util.Iterator;
/**
* This class manages objects and referencetypes that are reported
@@ -111,7 +109,7 @@ public class VMIdManager
/**
* Returns a new id for the given object
*
- * @param object the object for which an id is desired
+ * @param obj SoftReference of the object for which an id is desired
* @returns a suitable object id
*/
public static ObjectId newObjectId (SoftReference obj)
@@ -171,7 +169,7 @@ public class VMIdManager
/**
* Returns a new reference type id for the given class
*
- * @param clazz the <code>Class</code> for which an id is desired
+ * @param ref SoftReference to the desired type
* @returns a suitable reference type id or null when the
* reference is cleared.
*/
diff --git a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMMethod.java b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMMethod.java
new file mode 100644
index 00000000000..d345bc1b515
--- /dev/null
+++ b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMMethod.java
@@ -0,0 +1,178 @@
+/* VMMethod.java -- a method in a virtual machine
+ 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
+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.jdwp;
+
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import gnu.classpath.jdwp.exception.JdwpException;
+import gnu.classpath.jdwp.util.LineTable;
+import gnu.classpath.jdwp.util.VariableTable;
+
+/**
+ * This class is really an amalgamation of two classes: one class
+ * represents a virtual machine method and the other represents
+ * the JDWP back-end's ID for the method.
+ *
+ * @author Keith Seitz (keiths@redhat.com)
+ */
+public class VMMethod
+{
+ /**
+ * Returns the size of a JDWP method ID
+ * @see gnu.classpath.jdwp.id.JdwpId#SIZE
+ */
+ public static final int SIZE = 8;
+
+ // The class in which this method is declared
+ private Class _class;
+
+ // The method's ID
+ private long _methodId;
+
+ /**
+ * Constructs a new VMMethod object. This constructor is protected
+ * so that only the factory methods of VMVirtualMachine can be used
+ * to create VMMethods.
+ *
+ * @param klass the method's containing class
+ * @param id method identifier, e.g., jmethodID
+ * @see gnu.classpath.jdwp.VMVirtualMachine#getAllClassMethods
+ * @see gnu.classpath.jdwp.VMVirtualMachine#getClassMethod
+ */
+ protected VMMethod(Class klass, long id)
+ {
+ _class = klass;
+ _methodId = id;
+ }
+
+ /**
+ * Returns the internal method ID for this method
+ */
+ public long getId()
+ {
+ return _methodId;
+ }
+
+ /**
+ * Returns the method's declaring class
+ */
+ public Class getDeclaringClass()
+ {
+ return _class;
+ }
+
+ /**
+ * Returns the name of this method
+ */
+ public native String getName();
+
+ /**
+ * Returns the signature of this method
+ */
+ public native String getSignature();
+
+ /**
+ * Returns the method's modifier flags
+ */
+ public native int getModifiers();
+
+ /**
+ * "Returns line number information for the method, if present. The line
+ * table maps source line numbers to the initial code index of the line.
+ * The line table is ordered by code index (from lowest to highest). The
+ * line number information is constant unless a new class definition is
+ * installed using RedefineClasses."
+ *
+ * @return the line table
+ * @throws JdwpException
+ */
+ public native LineTable getLineTable()
+ throws JdwpException;
+
+ /**
+ * "Returns variable information for the method. The variable table
+ * includes arguments and locals declared within the method. For instance
+ * methods, the "this" reference is included in the table. Also, synthetic
+ * variables may be present."
+ *
+ * @return the variable table
+ * @throws JdwpException
+ */
+ public native VariableTable getVariableTable()
+ throws JdwpException;
+
+ /**
+ * Returns a string representation of this method (not
+ * required but nice for debugging).
+ */
+ public String toString()
+ {
+ return getDeclaringClass().getName() + "." + getName();
+ }
+
+ /**
+ * Writes the method's ID to the output stream
+ *
+ * @param ostream the output stream to which to write
+ * @throws IOException for any errors writing to the stream
+ * @see gnu.classpath.jdwp.id.JdwpId#write
+ */
+ public void writeId(DataOutputStream ostream)
+ throws IOException
+ {
+ ostream.writeLong(getId());
+ }
+
+ /**
+ * Returns a VMMethod from the ID in the byte buffer
+ *
+ * @param klass the method's declaring class
+ * @param bb a ByteBuffer containing the method's ID
+ * @throws JdwpException for any errors creating the method
+ * @throws IOException for any errors reading from the buffer
+ */
+ public static VMMethod readId(Class klass, ByteBuffer bb)
+ throws JdwpException, IOException
+ {
+ return VMVirtualMachine.getClassMethod(klass, bb.getLong());
+ }
+}
diff --git a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java
index aa285cb58a6..d8616063d19 100644
--- a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java
+++ b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMVirtualMachine.java
@@ -1,7 +1,7 @@
/* VMVirtualMachine.java -- A reference implementation of a JDWP virtual
machine
- Copyright (C) 2005 Free Software Foundation
+ Copyright (C) 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -42,16 +42,9 @@ exception statement from your version. */
package gnu.classpath.jdwp;
import gnu.classpath.jdwp.event.EventRequest;
+import gnu.classpath.jdwp.exception.InvalidMethodException;
import gnu.classpath.jdwp.exception.JdwpException;
-import gnu.classpath.jdwp.exception.InvalidClassException;
-import gnu.classpath.jdwp.exception.InvalidObjectException;
-import gnu.classpath.jdwp.id.ObjectId;
-import gnu.classpath.jdwp.id.ReferenceTypeId;
-import gnu.classpath.jdwp.util.LineTable;
import gnu.classpath.jdwp.util.MethodResult;
-import gnu.classpath.jdwp.util.VariableTable;
-
-import java.io.IOException;
import java.lang.reflect.Method;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@@ -80,7 +73,7 @@ public class VMVirtualMachine
{
// Our JDWP thread group -- don't suspend any of those threads
Thread current = Thread.currentThread ();
- ThreadGroup jdwpGroup = current.getThreadGroup ();
+ ThreadGroup jdwpGroup = Jdwp.getDefault().getJdwpThreadGroup();
// Find the root ThreadGroup
ThreadGroup group = jdwpGroup;
@@ -112,7 +105,8 @@ public class VMVirtualMachine
}
// Now suspend the current thread
- suspendThread (current);
+ if (current.getThreadGroup() != jdwpGroup)
+ suspendThread (current);
}
/**
@@ -197,6 +191,29 @@ public class VMVirtualMachine
public static native int getClassStatus (Class clazz)
throws JdwpException;
+ /**
+ * Returns all of the methods defined in the given class. This
+ * includes all methods, constructors, and class initializers.
+ *
+ * @param klass the class whose methods are desired
+ * @return an array of virtual machine methods
+ */
+ public static native VMMethod[] getAllClassMethods (Class klass)
+ { return null; }
+
+ /**
+ * A factory method for getting valid virtual machine methods
+ * which may be passed to/from the debugger.
+ *
+ * @param klass the class in which the method is defined
+ * @param id the ID of the desired method
+ * @return the desired internal representation of the method
+ * @throws InvalidMethodException if the method is not defined
+ * in the class
+ * @throws JdwpException for any other error
+ */
+ public static native VMMethod getClassMethod(Class klass, long id)
+ { return null; }
/**
* Returns the thread's call stack
@@ -206,7 +223,7 @@ public class VMVirtualMachine
* @param length number of frames to return (-1 for all frames)
* @return a list of frames
*/
- public static native ArrayList getFrames (Thread thread, int strart,
+ public static native ArrayList getFrames (Thread thread, int start,
int length)
throws JdwpException;
@@ -272,33 +289,6 @@ public class VMVirtualMachine
throws JdwpException;
/**
- * "Returns variable information for the method. The variable table
- * includes arguments and locals declared within the method. For instance
- * methods, the "this" reference is included in the table. Also, synthetic
- * variables may be present."
- *
- * @param clazz the class in which the method is defined
- * @param method the method for which variable information is desired
- * @return a result object containing the information
- */
- public static native VariableTable getVarTable (Class clazz, Method method)
- throws JdwpException;
-
- /**
- * "Returns line number information for the method, if present. The line
- * table maps source line numbers to the initial code index of the line.
- * The line table is ordered by code index (from lowest to highest). The
- * line number information is constant unless a new class definition is
- * installed using RedefineClasses."
- *
- * @param clazz the class in which the method is defined
- * @param method the method whose line table is desired
- * @return a result object containing the line table
- */
- public static native LineTable getLineTable (Class clazz, Method method)
- throws JdwpException;
-
- /**
* "Returns the name of source file in which a reference type was declared"
*
* @param clazz the class for which to return a source file
diff --git a/libjava/classpath/vm/reference/gnu/java/lang/VMInstrumentationImpl.java b/libjava/classpath/vm/reference/gnu/java/lang/VMInstrumentationImpl.java
new file mode 100644
index 00000000000..eee94702d35
--- /dev/null
+++ b/libjava/classpath/vm/reference/gnu/java/lang/VMInstrumentationImpl.java
@@ -0,0 +1,108 @@
+/* VMInstrumentationImpl.java -- interface for the GNU implementation
+ of InstrumentationImpl
+ Copyright (C) 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., 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.java.lang;
+
+import java.lang.instrument.ClassDefinition;
+import java.lang.instrument.Instrumentation;
+
+/**
+ * @author Nicolas Geoffray (nicolas.geoffray@menlina.com)
+ * @since 1.5
+ */
+final class VMInstrumentationImpl
+{
+
+ /**
+ * Returns if the current JVM supports class redefinition
+ *
+ * @return true if the current JVM supports class redefinition
+ */
+ static native boolean isRedefineClassesSupported();
+
+ /**
+ * Redefines classes given as parameters. The method has to call
+ * the callTransformers from InstrumentationImpl
+ *
+ * @param inst an instrumentation object
+ * @param definitions an array of bytecode<->class correspondance
+ *
+ * @throws ClassNotFoundException if a class cannot be found
+ * @throws UnmodifiableClassException if a class cannot be modified
+ * @throws UnsupportedOperationException if the JVM does not support
+ * redefinition or the redefinition made unsupported changes
+ * @throws ClassFormatError if a class file is not valid
+ * @throws NoClassDefFoundError if a class name is not equal to the name
+ * in the class file specified
+ * @throws UnsupportedClassVersionError if the class file version numbers
+ * are unsupported
+ * @throws ClassCircularityError if circularity occured with the new
+ * classes
+ * @throws LinkageError if a linkage error occurs
+ */
+ static native void redefineClasses(Instrumentation inst,
+ ClassDefinition[] definitions);
+
+ /**
+ * Get all the classes loaded by the JVM.
+ *
+ * @return an array containing all the classes loaded by the JVM. The array
+ * is empty if no class is loaded.
+ */
+ static native Class[] getAllLoadedClasses();
+
+ /**
+ * Get all the classes loaded by a given class loader
+ *
+ * @param loader the loader
+ *
+ * @return an array containing all the classes loaded by the given loader.
+ * The array is empty if no class was loaded by the loader.
+ */
+ static native Class[] getInitiatedClasses(ClassLoader loader);
+
+ /**
+ * Get the size of an object. The object is not null
+ *
+ * @param objectToSize the object
+ * @return the size of the object
+ */
+ static native long getObjectSize(Object objectToSize);
+
+}
diff --git a/libjava/classpath/vm/reference/java/lang/VMClass.java b/libjava/classpath/vm/reference/java/lang/VMClass.java
index 1b4c13e6b5a..25965068daf 100644
--- a/libjava/classpath/vm/reference/java/lang/VMClass.java
+++ b/libjava/classpath/vm/reference/java/lang/VMClass.java
@@ -1,5 +1,5 @@
/* VMClass.java -- VM Specific Class methods
- Copyright (C) 2003, 2004 Free Software Foundation
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -37,11 +37,14 @@ exception statement from your version. */
package java.lang;
+import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
/*
* This class is a reference version, mainly for compiling a class library
@@ -51,9 +54,11 @@ import java.lang.reflect.Modifier;
/**
*
- * @author Etienne Gagnon <etienne.gagnon@uqam.ca>
- * @author Archie Cobbs <archie@dellroad.org>
- * @author C. Brian Jones <cbj@gnu.org>
+ * @author Etienne Gagnon (etienne.gagnon@uqam.ca)
+ * @author Archie Cobbs (archie@dellroad.org)
+ * @author C. Brian Jones (cbj@gnu.org)
+ * @author Tom Tromey (tromey@cygnus.com)
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
final class VMClass
{
@@ -278,4 +283,172 @@ final class VMClass
*/
static native void throwException(Throwable t);
+ /**
+ * Returns the simple name for the specified class, as used in the source
+ * code. For normal classes, this is the content returned by
+ * <code>getName()</code> which follows the last ".". Anonymous
+ * classes have no name, and so the result of calling this method is
+ * "". The simple name of an array consists of the simple name of
+ * its component type, followed by "[]". Thus, an array with the
+ * component type of an anonymous class has a simple name of simply
+ * "[]".
+ *
+ * @param klass the class whose simple name should be returned.
+ * @return the simple name for this class.
+ */
+ static String getSimpleName(Class klass)
+ {
+ if (isArray(klass))
+ {
+ return getComponentType(klass).getSimpleName() + "[]";
+ }
+ String fullName = getName(klass);
+ return fullName.substring(fullName.lastIndexOf(".") + 1);
+ }
+
+ /**
+ * Returns all annotations directly defined by the specified class. If
+ * there are no annotations associated with this class, then a zero-length
+ * array will be returned. The returned array may be modified by the client
+ * code, but this will have no effect on the annotation content of this
+ * class, and hence no effect on the return value of this method for
+ * future callers.
+ *
+ * @param klass the class whose annotations should be returned.
+ * @return the annotations directly defined by the specified class.
+ * @since 1.5
+ */
+ static native Annotation[] getDeclaredAnnotations(Class klass);
+
+ /**
+ * <p>
+ * Returns the canonical name of the specified class, as defined by section
+ * 6.7 of the Java language specification. Each package, top-level class,
+ * top-level interface and primitive type has a canonical name. A member
+ * class has a canonical name, if its parent class has one. Likewise,
+ * an array type has a canonical name, if its component type does.
+ * Local or anonymous classes do not have canonical names.
+ * </p>
+ * <p>
+ * The canonical name for top-level classes, top-level interfaces and
+ * primitive types is always the same as the fully-qualified name.
+ * For array types, the canonical name is the canonical name of its
+ * component type with `[]' appended.
+ * </p>
+ * <p>
+ * The canonical name of a member class always refers to the place where
+ * the class was defined, and is composed of the canonical name of the
+ * defining class and the simple name of the member class, joined by `.'.
+ * For example, if a <code>Person</code> class has an inner class,
+ * <code>M</code>, then both its fully-qualified name and canonical name
+ * is <code>Person.M</code>. A subclass, <code>Staff</code>, of
+ * <code>Person</code> refers to the same inner class by the fully-qualified
+ * name of <code>Staff.M</code>, but its canonical name is still
+ * <code>Person.M</code>.
+ * </p>
+ * <p>
+ * Where no canonical name is present, <code>null</code> is returned.
+ * </p>
+ *
+ * @param klass the class whose canonical name should be retrieved.
+ * @return the canonical name of the class, or <code>null</code> if the
+ * class doesn't have a canonical name.
+ * @since 1.5
+ */
+ static String getCanonicalName(Class klass)
+ {
+ if (isArray(klass))
+ {
+ String componentName = getComponentType(klass).getCanonicalName();
+ if (componentName != null)
+ return componentName + "[]";
+ }
+ if (isMemberClass(klass))
+ {
+ String memberName = getDeclaringClass(klass).getCanonicalName();
+ if (memberName != null)
+ return memberName + "." + getSimpleName(klass);
+ }
+ if (isLocalClass(klass) || isAnonymousClass(klass))
+ return null;
+ return getName(klass);
+ }
+
+ /**
+ * Returns the class which immediately encloses the specified class. If
+ * the class is a top-level class, this method returns <code>null</code>.
+ *
+ * @param klass the class whose enclosing class should be returned.
+ * @return the immediate enclosing class, or <code>null</code> if this is
+ * a top-level class.
+ * @since 1.5
+ */
+ static native Class getEnclosingClass(Class klass);
+
+ /**
+ * Returns the constructor which immediately encloses the specified class.
+ * If the class is a top-level class, or a local or anonymous class
+ * immediately enclosed by a type definition, instance initializer
+ * or static initializer, then <code>null</code> is returned.
+ *
+ * @param klass the class whose enclosing constructor should be returned.
+ * @return the immediate enclosing constructor if the specified class is
+ * declared within a constructor. Otherwise, <code>null</code>
+ * is returned.
+ * @since 1.5
+ */
+ static native Constructor getEnclosingConstructor(Class klass);
+
+ /**
+ * Returns the method which immediately encloses the specified class. If
+ * the class is a top-level class, or a local or anonymous class
+ * immediately enclosed by a type definition, instance initializer
+ * or static initializer, then <code>null</code> is returned.
+ *
+ * @param klass the class whose enclosing method should be returned.
+ * @return the immediate enclosing method if the specified class is
+ * declared within a method. Otherwise, <code>null</code>
+ * is returned.
+ * @since 1.5
+ */
+ static native Method getEnclosingMethod(Class klass);
+
+ /**
+ * Returns the class signature as specified in Class File Format
+ * chapter in the VM specification, or null if the class is not
+ * generic.
+ *
+ * @param klass the klass to test.
+ * @return a ClassSignature string.
+ * @since 1.5
+ */
+ static native String getClassSignature(Class klass);
+
+ /**
+ * Returns true if the specified class represents an anonymous class.
+ *
+ * @param klass the klass to test.
+ * @return true if the specified class represents an anonymous class.
+ * @since 1.5
+ */
+ static native boolean isAnonymousClass(Class klass);
+
+ /**
+ * Returns true if the specified class represents an local class.
+ *
+ * @param klass the klass to test.
+ * @return true if the specified class represents an local class.
+ * @since 1.5
+ */
+ static native boolean isLocalClass(Class klass);
+
+ /**
+ * Returns true if the specified class represents an member class.
+ *
+ * @param klass the klass to test.
+ * @return true if the specified class represents an member class.
+ * @since 1.5
+ */
+ static native boolean isMemberClass(Class klass);
+
} // class VMClass
diff --git a/libjava/classpath/vm/reference/java/lang/VMClassLoader.java b/libjava/classpath/vm/reference/java/lang/VMClassLoader.java
index 7412afecc3a..4caa58c2ae6 100644
--- a/libjava/classpath/vm/reference/java/lang/VMClassLoader.java
+++ b/libjava/classpath/vm/reference/java/lang/VMClassLoader.java
@@ -1,6 +1,6 @@
/* VMClassLoader.java -- Reference implementation of native interface
required by ClassLoader
- Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation
+ Copyright (C) 1998, 2001, 2002, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -39,17 +39,23 @@ exception statement from your version. */
package java.lang;
-import gnu.classpath.SystemProperties;
import gnu.classpath.Configuration;
+import gnu.classpath.SystemProperties;
+import gnu.java.lang.InstrumentationImpl;
+import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
+import java.io.InputStreamReader;
+import java.lang.instrument.Instrumentation;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.Enumeration;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
+import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.zip.ZipFile;
@@ -98,6 +104,7 @@ final class VMClassLoader
"GNU Classpath",
"GNU",
Configuration.CLASSPATH_VERSION,
+ null,
null);
definedPackages.put(packages[i], p);
@@ -235,12 +242,46 @@ final class VMClassLoader
/**
* Returns a String[] of native package names. The default
- * implementation returns an empty array, or you may decide
- * this needs native help.
+ * implementation tries to load a list of package from
+ * the META-INF/INDEX.LIST file in the boot jar file.
+ * If not found or if any exception is raised, it returns
+ * an empty array. You may decide this needs native help.
*/
private static String[] getBootPackages()
{
- return new String[0];
+ URL indexList = getResource("META-INF/INDEX.LIST");
+ if (indexList != null)
+ {
+ try
+ {
+ Set packageSet = new HashSet();
+ String line;
+ int lineToSkip = 3;
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(
+ indexList.openStream()));
+ while ((line = reader.readLine()) != null)
+ {
+ if (lineToSkip == 0)
+ {
+ if (line.length() == 0)
+ lineToSkip = 1;
+ else
+ packageSet.add(line.replace('/', '.'));
+ }
+ else
+ lineToSkip--;
+ }
+ reader.close();
+ return (String[]) packageSet.toArray(new String[packageSet.size()]);
+ }
+ catch (IOException e)
+ {
+ return new String[0];
+ }
+ }
+ else
+ return new String[0];
}
@@ -345,4 +386,45 @@ final class VMClassLoader
* for this class.
*/
static native Class findLoadedClass(ClassLoader cl, String name);
+
+ /**
+ * The Instrumentation object created by the vm when agents are defined.
+ */
+ static final Instrumentation instrumenter = null;
+
+ /**
+ * Call the transformers of the possible Instrumentation object. This
+ * implementation assumes the instrumenter is a
+ * <code>InstrumentationImpl</code> object. VM implementors would
+ * have to redefine this method if they provide their own implementation
+ * of the <code>Instrumentation</code> interface.
+ *
+ * @param loader the initiating loader
+ * @param name the name of the class
+ * @param data the data representing the classfile, in classfile format
+ * @param offset the offset into the data where the classfile starts
+ * @param len the length of the classfile data in the array
+ * @param pd the protection domain
+ * @return the new data representing the classfile
+ */
+ static final Class defineClassWithTransformers(ClassLoader loader,
+ String name, byte[] data, int offset, int len, ProtectionDomain pd)
+ {
+
+ if (instrumenter != null)
+ {
+ byte[] modifiedData = new byte[len];
+ System.arraycopy(data, offset, modifiedData, 0, len);
+ modifiedData =
+ ((InstrumentationImpl)instrumenter).callTransformers(loader, name,
+ null, pd, modifiedData);
+
+ return defineClass(loader, name, modifiedData, 0, modifiedData.length,
+ pd);
+ }
+ else
+ {
+ return defineClass(loader, name, data, offset, len, pd);
+ }
+ }
}
diff --git a/libjava/classpath/vm/reference/java/lang/VMProcess.java b/libjava/classpath/vm/reference/java/lang/VMProcess.java
index 26cfcc9bc1b..076e5999d60 100644
--- a/libjava/classpath/vm/reference/java/lang/VMProcess.java
+++ b/libjava/classpath/vm/reference/java/lang/VMProcess.java
@@ -42,7 +42,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
+import java.util.Iterator;
import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
/**
* Represents one external process. Each instance of this class is in
@@ -92,6 +95,7 @@ final class VMProcess extends Process
InputStream stdout; // process output stream
InputStream stderr; // process error stream
int exitValue; // process exit value
+ boolean redirect; // redirect stderr -> stdout
//
// Dedicated thread that does all the fork()'ing and wait()'ing
@@ -196,7 +200,8 @@ final class VMProcess extends Process
{
try
{
- process.nativeSpawn(process.cmd, process.env, process.dir);
+ process.nativeSpawn(process.cmd, process.env, process.dir,
+ process.redirect);
process.state = RUNNING;
activeMap.put(new Long(process.pid), process);
}
@@ -215,7 +220,8 @@ final class VMProcess extends Process
}
// Constructor
- private VMProcess(String[] cmd, String[] env, File dir) throws IOException
+ private VMProcess(String[] cmd, String[] env, File dir, boolean redirect)
+ throws IOException
{
// Initialize this process
@@ -223,6 +229,7 @@ final class VMProcess extends Process
this.cmd = cmd;
this.env = env;
this.dir = dir;
+ this.redirect = redirect;
// Add process to the new process work list and wakeup processThread
synchronized (workList)
@@ -275,11 +282,20 @@ final class VMProcess extends Process
// Invoked by native code (from nativeSpawn()) to record process info.
private void setProcessInfo(OutputStream stdin,
- InputStream stdout, InputStream stderr, long pid)
+ InputStream stdout, InputStream stderr, long pid)
{
this.stdin = stdin;
this.stdout = stdout;
- this.stderr = stderr;
+ if (stderr == null)
+ this.stderr = new InputStream()
+ {
+ public int read() throws IOException
+ {
+ return -1;
+ }
+ };
+ else
+ this.stderr = stderr;
this.pid = pid;
}
@@ -288,7 +304,24 @@ final class VMProcess extends Process
*/
static Process exec(String[] cmd, String[] env, File dir) throws IOException
{
- return new VMProcess(cmd, env, dir);
+ return new VMProcess(cmd, env, dir, false);
+ }
+
+ static Process exec(List cmd, Map env,
+ File dir, boolean redirect) throws IOException
+ {
+ String[] acmd = (String[]) cmd.toArray(new String[cmd.size()]);
+ String[] aenv = new String[env.size()];
+
+ int i = 0;
+ Iterator iter = env.entrySet().iterator();
+ while (iter.hasNext())
+ {
+ Map.Entry entry = (Map.Entry) iter.next();
+ aenv[i++] = entry.getKey() + "=" + entry.getValue();
+ }
+
+ return new VMProcess(acmd, aenv, dir, redirect);
}
public OutputStream getOutputStream()
@@ -347,7 +380,8 @@ final class VMProcess extends Process
*
* @throws IOException if the O/S process could not be created.
*/
- native void nativeSpawn(String[] cmd, String[] env, File dir)
+ native void nativeSpawn(String[] cmd, String[] env, File dir,
+ boolean redirect)
throws IOException;
/**
diff --git a/libjava/classpath/vm/reference/java/lang/VMSystem.java b/libjava/classpath/vm/reference/java/lang/VMSystem.java
index 8a83cad92ff..f96986df373 100644
--- a/libjava/classpath/vm/reference/java/lang/VMSystem.java
+++ b/libjava/classpath/vm/reference/java/lang/VMSystem.java
@@ -37,6 +37,8 @@ exception statement from your version. */
package java.lang;
+import java.util.List;
+
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileDescriptor;
@@ -50,6 +52,7 @@ import java.io.PrintStream;
* VM must implement.
*
* @author John Keiser
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
final class VMSystem
{
@@ -135,40 +138,76 @@ final class VMSystem
public static native long currentTimeMillis();
/**
+ * <p>
+ * Returns the current value of a nanosecond-precise system timer.
+ * The value of the timer is an offset relative to some arbitrary fixed
+ * time, which may be in the future (making the value negative). This
+ * method is useful for timing events where nanosecond precision is
+ * required. This is achieved by calling this method before and after the
+ * event, and taking the difference betweent the two times:
+ * </p>
+ * <p>
+ * <code>long startTime = System.nanoTime();</code><br />
+ * <code>... <emph>event code</emph> ...</code><br />
+ * <code>long endTime = System.nanoTime();</code><br />
+ * <code>long duration = endTime - startTime;</code><br />
+ * </p>
+ * <p>
+ * Note that the value is only nanosecond-precise, and not accurate; there
+ * is no guarantee that the difference between two values is really a
+ * nanosecond. Also, the value is prone to overflow if the offset
+ * exceeds 2^63.
+ * </p>
+ *
+ * @return the time of a system timer in nanoseconds.
+ * @since 1.5
+ */
+ public static long nanoTime()
+ {
+ return currentTimeMillis() * 1000;
+ }
+
+ /**
+ * Returns a list of 'name=value' pairs representing the current environment
+ * variables.
+ *
+ * @return a list of 'name=value' pairs.
+ */
+ static native List environ();
+
+ /**
* Helper method which creates the standard input stream.
* VM implementors may choose to construct these streams differently.
* This method can also return null if the stream is created somewhere
* else in the VM startup sequence.
*/
-
- static InputStream makeStandardInputStream()
- {
- return new BufferedInputStream(new FileInputStream(FileDescriptor.in));
- }
-
+ static InputStream makeStandardInputStream()
+ {
+ return new BufferedInputStream(new FileInputStream(FileDescriptor.in));
+ }
+
/**
* Helper method which creates the standard output stream.
* VM implementors may choose to construct these streams differently.
* This method can also return null if the stream is created somewhere
* else in the VM startup sequence.
*/
+ static PrintStream makeStandardOutputStream()
+ {
+ return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true);
+ }
- static PrintStream makeStandardOutputStream()
- {
- return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true);
- }
/**
* Helper method which creates the standard error stream.
* VM implementors may choose to construct these streams differently.
* This method can also return null if the stream is created somewhere
* else in the VM startup sequence.
*/
-
- static PrintStream makeStandardErrorStream()
- {
- return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true);
- }
-
+ static PrintStream makeStandardErrorStream()
+ {
+ return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true);
+ }
+
/**
* Gets the value of an environment variable.
* Always returning null is a valid (but not very useful) implementation.
diff --git a/libjava/classpath/vm/reference/java/lang/VMThread.java b/libjava/classpath/vm/reference/java/lang/VMThread.java
index aa0b8347a73..302de6c35a8 100644
--- a/libjava/classpath/vm/reference/java/lang/VMThread.java
+++ b/libjava/classpath/vm/reference/java/lang/VMThread.java
@@ -1,5 +1,5 @@
/* VMThread -- VM interface for Thread of executable code
- Copyright (C) 2003, 2004, 2005 Free Software Foundation
+ Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@@ -123,7 +123,9 @@ final class VMThread
{
try
{
- thread.group.uncaughtException(thread, t);
+ Thread.UncaughtExceptionHandler handler;
+ handler = thread.getUncaughtExceptionHandler();
+ handler.uncaughtException(thread, t);
}
catch(Throwable ignore)
{
diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Constructor.java b/libjava/classpath/vm/reference/java/lang/reflect/Constructor.java
index cb633db115c..521190b6656 100644
--- a/libjava/classpath/vm/reference/java/lang/reflect/Constructor.java
+++ b/libjava/classpath/vm/reference/java/lang/reflect/Constructor.java
@@ -1,5 +1,5 @@
/* java.lang.reflect.Constructor - reflection of Java constructors
- Copyright (C) 1998, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +38,10 @@ exception statement from your version. */
package java.lang.reflect;
+import gnu.java.lang.ClassHelper;
+
+import gnu.java.lang.reflect.MethodSignatureParser;
+
import java.util.Arrays;
/**
@@ -74,11 +78,15 @@ import java.util.Arrays;
* @status updated to 1.4
*/
public final class Constructor
-extends AccessibleObject implements Member
+ extends AccessibleObject
+ implements GenericDeclaration, Member
{
private Class clazz;
private int slot;
+ private static final int CONSTRUCTOR_MODIFIERS
+ = Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC;
+
/**
* This class is uninstantiable except from native code.
*/
@@ -112,6 +120,13 @@ extends AccessibleObject implements Member
}
/**
+ * Return the raw modifiers for this constructor. In particular
+ * this will include the synthetic and varargs bits.
+ * @return the constructor's modifiers
+ */
+ private native int getModifiersInternal();
+
+ /**
* Gets the modifiers this constructor uses. Use the <code>Modifier</code>
* class to interpret the values. A constructor can only have a subset of the
* following modifiers: public, private, protected.
@@ -119,7 +134,31 @@ extends AccessibleObject implements Member
* @return an integer representing the modifiers to this Member
* @see Modifier
*/
- public native int getModifiers();
+ public int getModifiers()
+ {
+ return getModifiersInternal() & CONSTRUCTOR_MODIFIERS;
+ }
+
+ /**
+ * Return true if this constructor is synthetic, false otherwise.
+ * A synthetic member is one which is created by the compiler,
+ * and which does not appear in the user's source code.
+ * @since 1.5
+ */
+ public boolean isSynthetic()
+ {
+ return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
+ }
+
+ /**
+ * Return true if this is a varargs constructor, that is if
+ * the constructor takes a variable number of arguments.
+ * @since 1.5
+ */
+ public boolean isVarArgs()
+ {
+ return (getModifiersInternal() & Modifier.VARARGS) != 0;
+ }
/**
* Get the parameter list for this constructor, in declaration order. If the
@@ -184,15 +223,15 @@ extends AccessibleObject implements Member
public String toString()
{
// 128 is a reasonable buffer initial size for constructor
- StringBuffer sb = new StringBuffer(128);
+ StringBuilder sb = new StringBuilder(128);
Modifier.toString(getModifiers(), sb).append(' ');
sb.append(getDeclaringClass().getName()).append('(');
Class[] c = getParameterTypes();
if (c.length > 0)
{
- sb.append(c[0].getName());
+ sb.append(ClassHelper.getUserName(c[0]));
for (int i = 1; i < c.length; i++)
- sb.append(',').append(c[i].getName());
+ sb.append(',').append(ClassHelper.getUserName(c[i]));
}
sb.append(')');
c = getExceptionTypes();
@@ -204,7 +243,46 @@ extends AccessibleObject implements Member
}
return sb.toString();
}
-
+
+ /* FIXME[GENERICS]: Add X extends GenericDeclaration and TypeVariable<X> */
+ static void addTypeParameters(StringBuilder sb, TypeVariable[] typeArgs)
+ {
+ if (typeArgs.length == 0)
+ return;
+ sb.append('<');
+ for (int i = 0; i < typeArgs.length; ++i)
+ {
+ if (i > 0)
+ sb.append(',');
+ sb.append(typeArgs[i]);
+ }
+ sb.append("> ");
+ }
+
+ public String toGenericString()
+ {
+ StringBuilder sb = new StringBuilder(128);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ addTypeParameters(sb, getTypeParameters());
+ sb.append(getDeclaringClass().getName()).append('(');
+ Type[] types = getGenericParameterTypes();
+ if (types.length > 0)
+ {
+ sb.append(types[0]);
+ for (int i = 1; i < types.length; ++i)
+ sb.append(',').append(types[i]);
+ }
+ sb.append(')');
+ types = getGenericExceptionTypes();
+ if (types.length > 0)
+ {
+ sb.append(" throws ").append(types[0]);
+ for (int i = 1; i < types.length; i++)
+ sb.append(',').append(types[i]);
+ }
+ return sb.toString();
+ }
+
/**
* Create a new instance by invoking the constructor. Arguments are
* automatically unwrapped and widened, if needed.<p>
@@ -246,4 +324,75 @@ extends AccessibleObject implements Member
int slot)
throws InstantiationException, IllegalAccessException,
InvocationTargetException;
+
+ /**
+ * Returns an array of <code>TypeVariable</code> objects that represents
+ * the type variables declared by this constructor, in declaration order.
+ * An array of size zero is returned if this constructor has no type
+ * variables.
+ *
+ * @return the type variables associated with this constructor.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ /* FIXME[GENERICS]: Add <Constructor<T>> */
+ public TypeVariable[] getTypeParameters()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return new TypeVariable[0];
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getTypeParameters();
+ }
+
+ /**
+ * Return the String in the Signature attribute for this constructor. If there
+ * is no Signature attribute, return null.
+ */
+ private native String getSignature();
+
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the exception types declared by this constructor, in declaration order.
+ * An array of size zero is returned if this constructor declares no
+ * exceptions.
+ *
+ * @return the exception types declared by this constructor.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericExceptionTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getExceptionTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericExceptionTypes();
+ }
+
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the parameter list for this constructor, in declaration order.
+ * An array of size zero is returned if this constructor takes no
+ * parameters.
+ *
+ * @return a list of the types of the constructor's parameters
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericParameterTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getParameterTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericParameterTypes();
+ }
}
+
diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Field.java b/libjava/classpath/vm/reference/java/lang/reflect/Field.java
index 85e76d63479..5121700fede 100644
--- a/libjava/classpath/vm/reference/java/lang/reflect/Field.java
+++ b/libjava/classpath/vm/reference/java/lang/reflect/Field.java
@@ -1,5 +1,5 @@
/* java.lang.reflect.Field - reflection of Java fields
- Copyright (C) 1998, 2001 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +38,10 @@ exception statement from your version. */
package java.lang.reflect;
+import gnu.java.lang.ClassHelper;
+
+import gnu.java.lang.reflect.FieldSignatureParser;
+
/**
* The Field class represents a member variable of a class. It also allows
* dynamic access to a member, via reflection. This works for both
@@ -78,6 +82,11 @@ extends AccessibleObject implements Member
private String name;
private int slot;
+ private static final int FIELD_MODIFIERS
+ = Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED
+ | Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT
+ | Modifier.VOLATILE;
+
/**
* This class is uninstantiable except natively.
*/
@@ -108,6 +117,12 @@ extends AccessibleObject implements Member
}
/**
+ * Return the raw modifiers for this field.
+ * @return the field's modifiers
+ */
+ private native int getModifiersInternal();
+
+ /**
* Gets the modifiers this field uses. Use the <code>Modifier</code>
* class to interpret the values. A field can only have a subset of the
* following modifiers: public, private, protected, static, final,
@@ -116,7 +131,29 @@ extends AccessibleObject implements Member
* @return an integer representing the modifiers to this Member
* @see Modifier
*/
- public native int getModifiers();
+ public int getModifiers()
+ {
+ return getModifiersInternal() & FIELD_MODIFIERS;
+ }
+
+ /**
+ * Return true if this field is synthetic, false otherwise.
+ * @since 1.5
+ */
+ public boolean isSynthetic()
+ {
+ return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
+ }
+
+ /**
+ * Return true if this field represents an enum constant,
+ * false otherwise.
+ * @since 1.5
+ */
+ public boolean isEnumConstant()
+ {
+ return (getModifiersInternal() & Modifier.ENUM) != 0;
+ }
/**
* Gets the type of this field.
@@ -169,14 +206,24 @@ extends AccessibleObject implements Member
public String toString()
{
// 64 is a reasonable buffer initial size for field
- StringBuffer sb = new StringBuffer(64);
+ StringBuilder sb = new StringBuilder(64);
Modifier.toString(getModifiers(), sb).append(' ');
- sb.append(getType().getName()).append(' ');
+ sb.append(ClassHelper.getUserName(getType())).append(' ');
sb.append(getDeclaringClass().getName()).append('.');
sb.append(getName());
return sb.toString();
}
+ public String toGenericString()
+ {
+ StringBuilder sb = new StringBuilder(64);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ sb.append(getGenericType()).append(' ');
+ sb.append(getDeclaringClass().getName()).append('.');
+ sb.append(getName());
+ return sb.toString();
+ }
+
/**
* Get the value of this Field. If it is primitive, it will be wrapped
* in the appropriate wrapper type (boolean = java.lang.Boolean).<p>
@@ -586,4 +633,30 @@ extends AccessibleObject implements Member
*/
public native void setDouble(Object o, double value)
throws IllegalAccessException;
+
+ /**
+ * Return the generic type of the field. If the field type is not a generic
+ * type, the method returns the same as <code>getType()</code>.
+ *
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type getGenericType()
+ {
+ String signature = getSignature();
+ if (signature == null)
+ return getType();
+ FieldSignatureParser p = new FieldSignatureParser(getDeclaringClass(),
+ signature);
+ return p.getFieldType();
+ }
+
+ /**
+ * Return the String in the Signature attribute for this field. If there
+ * is no Signature attribute, return null.
+ */
+ private native String getSignature();
+
}
diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Method.java b/libjava/classpath/vm/reference/java/lang/reflect/Method.java
index 27256770e52..a9920241b17 100644
--- a/libjava/classpath/vm/reference/java/lang/reflect/Method.java
+++ b/libjava/classpath/vm/reference/java/lang/reflect/Method.java
@@ -1,5 +1,5 @@
/* java.lang.reflect.Method - reflection of Java methods
- Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,6 +38,10 @@ exception statement from your version. */
package java.lang.reflect;
+import gnu.java.lang.ClassHelper;
+
+import gnu.java.lang.reflect.MethodSignatureParser;
+
import java.util.Arrays;
/**
@@ -74,12 +78,17 @@ import java.util.Arrays;
* @status updated to 1.4
*/
public final class Method
-extends AccessibleObject implements Member
+extends AccessibleObject implements Member, GenericDeclaration
{
Class declaringClass;
String name;
int slot;
+ private static final int METHOD_MODIFIERS
+ = Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE
+ | Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC
+ | Modifier.STATIC | Modifier.STRICT | Modifier.SYNCHRONIZED;
+
/**
* This class is uninstantiable.
*/
@@ -110,6 +119,12 @@ extends AccessibleObject implements Member
}
/**
+ * Return the raw modifiers for this method.
+ * @return the method's modifiers
+ */
+ private native int getModifiersInternal();
+
+ /**
* Gets the modifiers this method uses. Use the <code>Modifier</code>
* class to interpret the values. A method can only have a subset of the
* following modifiers: public, private, protected, abstract, static,
@@ -118,7 +133,40 @@ extends AccessibleObject implements Member
* @return an integer representing the modifiers to this Member
* @see Modifier
*/
- public native int getModifiers();
+ public int getModifiers()
+ {
+ return getModifiersInternal() & METHOD_MODIFIERS;
+ }
+
+ /**
+ * Return true if this method is a bridge method. A bridge method
+ * is generated by the compiler in some situations involving
+ * generics and inheritance.
+ * @since 1.5
+ */
+ public boolean isBridge()
+ {
+ return (getModifiersInternal() & Modifier.BRIDGE) != 0;
+ }
+
+ /**
+ * Return true if this method is synthetic, false otherwise.
+ * @since 1.5
+ */
+ public boolean isSynthetic()
+ {
+ return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
+ }
+
+ /**
+ * Return true if this is a varargs method, that is if
+ * the method takes a variable number of arguments.
+ * @since 1.5
+ */
+ public boolean isVarArgs()
+ {
+ return (getModifiersInternal() & Modifier.VARARGS) != 0;
+ }
/**
* Gets the return type of this method.
@@ -210,17 +258,17 @@ extends AccessibleObject implements Member
public String toString()
{
// 128 is a reasonable buffer initial size for constructor
- StringBuffer sb = new StringBuffer(128);
+ StringBuilder sb = new StringBuilder(128);
Modifier.toString(getModifiers(), sb).append(' ');
- sb.append(getUserTypeName(getReturnType().getName())).append(' ');
+ sb.append(ClassHelper.getUserName(getReturnType())).append(' ');
sb.append(getDeclaringClass().getName()).append('.');
sb.append(getName()).append('(');
Class[] c = getParameterTypes();
if (c.length > 0)
{
- sb.append(getUserTypeName(c[0].getName()));
+ sb.append(ClassHelper.getUserName(c[0]));
for (int i = 1; i < c.length; i++)
- sb.append(',').append(getUserTypeName(c[i].getName()));
+ sb.append(',').append(ClassHelper.getUserName(c[i]));
}
sb.append(')');
c = getExceptionTypes();
@@ -233,53 +281,31 @@ extends AccessibleObject implements Member
return sb.toString();
}
- private static String getUserTypeName(String typeSpec)
+ public String toGenericString()
{
- int pos = 0;
- String typeName = "";
- String arrayPart = "";
-
- while (typeSpec.charAt(pos) == '[')
+ // 128 is a reasonable buffer initial size for constructor
+ StringBuilder sb = new StringBuilder(128);
+ Modifier.toString(getModifiers(), sb).append(' ');
+ Constructor.addTypeParameters(sb, getTypeParameters());
+ sb.append(getGenericReturnType()).append(' ');
+ sb.append(getDeclaringClass().getName()).append('.');
+ sb.append(getName()).append('(');
+ Type[] types = getGenericParameterTypes();
+ if (types.length > 0)
{
- arrayPart += "[]";
- ++pos;
+ sb.append(types[0]);
+ for (int i = 1; i < types.length; i++)
+ sb.append(',').append(types[i]);
}
-
- switch (typeSpec.charAt(pos))
+ sb.append(')');
+ types = getGenericExceptionTypes();
+ if (types.length > 0)
{
- case 'Z':
- typeName = "boolean";
- break;
- case 'B':
- typeName = "byte";
- break;
- case 'C':
- typeName = "char";
- break;
- case 'D':
- typeName = "double";
- break;
- case 'F':
- typeName = "float";
- break;
- case 'I':
- typeName = "int";
- break;
- case 'J':
- typeName = "long";
- break;
- case 'S':
- typeName = "short";
- break;
- case 'L':
- typeName = typeSpec.substring(pos + 1, typeSpec.length() - 1);
- break;
- default:
- typeName = typeSpec;
- break;
+ sb.append(" throws ").append(types[0]);
+ for (int i = 1; i < types.length; i++)
+ sb.append(',').append(types[i]);
}
-
- return typeName + arrayPart;
+ return sb.toString();
}
/**
@@ -336,4 +362,93 @@ extends AccessibleObject implements Member
private native Object invokeNative(Object o, Object[] args,
Class declaringClass, int slot)
throws IllegalAccessException, InvocationTargetException;
+
+ /**
+ * Returns an array of <code>TypeVariable</code> objects that represents
+ * the type variables declared by this constructor, in declaration order.
+ * An array of size zero is returned if this class has no type
+ * variables.
+ *
+ * @return the type variables associated with this class.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ /* FIXME[GENERICS]: Should be TypeVariable<Method>[] */
+ public TypeVariable[] getTypeParameters()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return new TypeVariable[0];
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getTypeParameters();
+ }
+
+ /**
+ * Return the String in the Signature attribute for this method. If there
+ * is no Signature attribute, return null.
+ */
+ private native String getSignature();
+
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the exception types declared by this method, in declaration order.
+ * An array of size zero is returned if this method declares no
+ * exceptions.
+ *
+ * @return the exception types declared by this method.
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericExceptionTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getExceptionTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericExceptionTypes();
+ }
+
+ /**
+ * Returns an array of <code>Type</code> objects that represents
+ * the parameter list for this method, in declaration order.
+ * An array of size zero is returned if this method takes no
+ * parameters.
+ *
+ * @return a list of the types of the method's parameters
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type[] getGenericParameterTypes()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getParameterTypes();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericParameterTypes();
+ }
+
+ /**
+ * Returns the return type of this method.
+ *
+ * @return the return type of this method
+ * @throws GenericSignatureFormatError if the generic signature does
+ * not conform to the format specified in the Virtual Machine
+ * specification, version 3.
+ * @since 1.5
+ */
+ public Type getGenericReturnType()
+ {
+ String sig = getSignature();
+ if (sig == null)
+ return getReturnType();
+ MethodSignatureParser p = new MethodSignatureParser(this, sig);
+ return p.getGenericReturnType();
+ }
}
+
diff --git a/libjava/classpath/vm/reference/java/lang/reflect/VMArray.java b/libjava/classpath/vm/reference/java/lang/reflect/VMArray.java
new file mode 100644
index 00000000000..d6277aebdbd
--- /dev/null
+++ b/libjava/classpath/vm/reference/java/lang/reflect/VMArray.java
@@ -0,0 +1,65 @@
+/* java.lang.reflect.VMArray - VM class for array manipulation by reflection.
+ Copyright (C) 1998, 1999, 2001, 2003, 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., 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 java.lang.reflect;
+
+import gnu.classpath.Configuration;
+
+class VMArray
+{
+
+ static
+ {
+ if (Configuration.INIT_LOAD_LIBRARY)
+ {
+ System.loadLibrary("javalangreflect");
+ }
+ }
+
+ /**
+ * Dynamically create an array of objects.
+ *
+ * @param type guaranteed to be a valid object type
+ * @param dim the length of the array
+ * @return the new array
+ * @throws NegativeArraySizeException if dim is negative
+ * @throws OutOfMemoryError if memory allocation fails
+ */
+ static native Object createObjectArray(Class type, int dim);
+
+}
diff --git a/libjava/classpath/vm/reference/java/security/VMSecureRandom.java b/libjava/classpath/vm/reference/java/security/VMSecureRandom.java
new file mode 100644
index 00000000000..dc67d871968
--- /dev/null
+++ b/libjava/classpath/vm/reference/java/security/VMSecureRandom.java
@@ -0,0 +1,134 @@
+/* VMSecureRandom.java -- random seed generator.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is a 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 of the License, 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; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, 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 java.security;
+
+import gnu.classpath.SystemProperties;
+import gnu.java.security.action.GetSecurityPropertyAction;
+
+import java.net.URL;
+
+/**
+ * VM-specific methods for generating real (or almost real) random
+ * seeds. VM implementors should write a version of this class that
+ * reads random bytes from some system source.
+ *
+ * <p>The default implementation of this class runs eight threads that
+ * increment counters in a tight loop, and XORs each counter to
+ * produce one byte of seed data. This is not very efficient, and is
+ * not guaranteed to be random (the thread scheduler is probably
+ * deterministic, after all). If possible, VM implementors should
+ * reimplement this class so it obtains a random seed from a system
+ * facility, such as a system entropy gathering device or hardware
+ * random number generator.
+ */
+final class VMSecureRandom
+{
+
+ /**
+ * Generate a random seed. Implementations are free to generate
+ * fewer random bytes than are requested, and leave the remaining
+ * bytes of the destination buffer as zeros. Implementations SHOULD,
+ * however, make a best-effort attempt to satisfy the request.
+ *
+ * @param buffer The destination buffer.
+ * @param offset The offset in the buffer to start putting bytes.
+ * @param length The number of random bytes to generate.
+ */
+ static int generateSeed(byte[] buffer, int offset, int length)
+ {
+ if (length < 0)
+ throw new IllegalArgumentException("length must be nonnegative");
+ if (offset < 0 || offset + length > buffer.length)
+ throw new IndexOutOfBoundsException();
+
+ Spinner[] spinners = new Spinner[8];
+ int n = 0x1;
+ for (int i = 0; i < spinners.length; i++)
+ {
+ spinners[i] = new Spinner((byte) n);
+ Thread t = new Thread(spinners[i]);
+ t.start();
+ n <<= 1;
+ }
+
+ // Wait until at least one spinner has started.
+ while (!(spinners[0].running || spinners[1].running || spinners[2].running
+ || spinners[3].running || spinners[4].running || spinners[5].running
+ || spinners[6].running || spinners[7].running))
+ {
+ Thread.yield();
+ }
+
+ for (int i = offset; i < length; i++)
+ {
+ buffer[i] = (byte) (spinners[0].value ^ spinners[1].value ^ spinners[2].value
+ ^ spinners[3].value ^ spinners[4].value ^ spinners[5].value
+ ^ spinners[6].value ^ spinners[7].value);
+ Thread.yield();
+ }
+
+ for (int i = 0; i < spinners.length; i++)
+ spinners[i].stop();
+
+ return length;
+ }
+
+ static class Spinner implements Runnable
+ {
+ volatile byte value;
+ volatile boolean running;
+
+ Spinner(final byte initial)
+ {
+ value = initial;
+ }
+
+ public void run()
+ {
+ running = true;
+ while (running)
+ value++;
+ }
+
+ private void stop()
+ {
+ running = false;
+ }
+ }
+} \ No newline at end of file