summaryrefslogtreecommitdiff
path: root/vm
diff options
context:
space:
mode:
authorAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-16 15:14:51 +0000
committerAndrew John Hughes <gnu_andrew@member.fsf.org>2005-01-16 15:14:51 +0000
commitf3bca904add8a1e256b2c245c169e8e5a69efcd7 (patch)
tree4b18335ee421c49bcc9a418d9abc4193634986f7 /vm
parente38101c185b90d301bac951b84a77ed711d18e54 (diff)
downloadclasspath-f3bca904add8a1e256b2c245c169e8e5a69efcd7.tar.gz
2005-01-16 Andrew John Hughes <gnu_andrew@member.fsf.org>
Final merge of HEAD patches to generics branch All changes are listed in merged Changelog. In addition, * java/lang/System.java: (getenv()): changed Runtime.securityManager to SecurityManager.current (getenv(String)): likewise (remove(String)): pointed to SystemProperties * gnu/classpath/SystemProperties.java: (remove(String)): implemented and documented
Diffstat (limited to 'vm')
-rw-r--r--vm/reference/gnu/classpath/VMStackWalker.java108
-rw-r--r--vm/reference/gnu/classpath/VMSystemProperties.java97
-rw-r--r--vm/reference/java/lang/VMClassLoader.java24
-rw-r--r--vm/reference/java/lang/VMProcess.java41
-rw-r--r--vm/reference/java/lang/VMRuntime.java57
-rw-r--r--vm/reference/java/lang/VMSecurityManager.java73
-rw-r--r--vm/reference/java/lang/VMSystem.java7
-rw-r--r--vm/reference/java/lang/VMThread.java66
-rw-r--r--vm/reference/java/nio/channels/VMChannels.java116
-rw-r--r--vm/reference/java/security/VMAccessController.java4
10 files changed, 421 insertions, 172 deletions
diff --git a/vm/reference/gnu/classpath/VMStackWalker.java b/vm/reference/gnu/classpath/VMStackWalker.java
new file mode 100644
index 000000000..72e41d8c7
--- /dev/null
+++ b/vm/reference/gnu/classpath/VMStackWalker.java
@@ -0,0 +1,108 @@
+/* VMStackWalker.java -- Reference implementation of VM hooks for stack access
+ Copyright (C) 2005 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.classpath;
+
+/**
+ * This class provides access to the classes on the Java stack
+ * for reflection and security purposes.
+ *
+ * <p>
+ * This class is only available to priviledged code (i.e., code loaded
+ * by the bootstrap loader).
+ *
+ * @author John Keiser
+ * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Archie Cobbs
+ */
+public final class VMStackWalker
+{
+ /**
+ * Get a list of all the classes currently executing methods on the
+ * Java stack. <code>getClassContext()[0]</code> is the class associated
+ * with the currently executing method, i.e., the method that called
+ * <code>VMStackWalker.getClassContext()</code> (possibly through
+ * reflection). So you may need to pop off these stack frames from
+ * the top of the stack:
+ * <ul>
+ * <li><code>VMStackWalker.getClassContext()</code>
+ * <li><code>Method.invoke()</code>
+ * </ul>
+ *
+ * @return an array of the declaring classes of each stack frame
+ */
+ public static native Class[] getClassContext();
+
+ /**
+ * Get the class associated with the method invoking the method
+ * invoking this method, or <code>null</code> if the stack is not
+ * that deep (e.g., invoked via JNI invocation API). This method
+ * is an optimization for the expression <code>getClassContext()[1]</code>
+ * and should return the same result.
+ *
+ * <p>
+ * VM implementers are encouraged to provide a more efficient
+ * version of this method.
+ */
+ public static Class getCallingClass()
+ {
+ Class[] ctx = getClassContext();
+ if (ctx.length < 3)
+ return null;
+ return ctx[2];
+ }
+
+ /**
+ * Get the class loader associated with the Class returned by
+ * <code>getCallingClass()</code>, or <code>null</code> if no
+ * such class exists or it is the boot loader. This method is an optimization
+ * for the expression <code>getClassContext()[1].getClassLoader()</code>
+ * and should return the same result.
+ *
+ * <p>
+ * VM implementers are encouraged to provide a more efficient
+ * version of this method.
+ */
+ public static ClassLoader getCallingClassLoader()
+ {
+ Class[] ctx = getClassContext();
+ if (ctx.length < 3)
+ return null;
+ return ctx[2].getClassLoader();
+ }
+}
+
diff --git a/vm/reference/gnu/classpath/VMSystemProperties.java b/vm/reference/gnu/classpath/VMSystemProperties.java
new file mode 100644
index 000000000..f0bda733a
--- /dev/null
+++ b/vm/reference/gnu/classpath/VMSystemProperties.java
@@ -0,0 +1,97 @@
+/* VMSystemProperties.java -- Allow the VM to set System properties.
+ Copyright (C) 2004 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+package gnu.classpath;
+
+import java.util.Properties;
+
+class VMSystemProperties
+{
+ /**
+ * Get the system properties. This is done here, instead of in System,
+ * because of the bootstrap sequence. Note that the native code should
+ * not try to use the Java I/O classes yet, as they rely on the properties
+ * already existing. The only safe method to use to insert these default
+ * system properties is {@link Properties#setProperty(String, String)}.
+ *
+ * <p>These properties MUST include:
+ * <dl>
+ * <dt>java.version <dd>Java version number
+ * <dt>java.vendor <dd>Java vendor specific string
+ * <dt>java.vendor.url <dd>Java vendor URL
+ * <dt>java.home <dd>Java installation directory
+ * <dt>java.vm.specification.version <dd>VM Spec version
+ * <dt>java.vm.specification.vendor <dd>VM Spec vendor
+ * <dt>java.vm.specification.name <dd>VM Spec name
+ * <dt>java.vm.version <dd>VM implementation version
+ * <dt>java.vm.vendor <dd>VM implementation vendor
+ * <dt>java.vm.name <dd>VM implementation name
+ * <dt>java.specification.version <dd>Java Runtime Environment version
+ * <dt>java.specification.vendor <dd>Java Runtime Environment vendor
+ * <dt>java.specification.name <dd>Java Runtime Environment name
+ * <dt>java.class.version <dd>Java class version number
+ * <dt>java.class.path <dd>Java classpath
+ * <dt>java.library.path <dd>Path for finding Java libraries
+ * <dt>java.io.tmpdir <dd>Default temp file path
+ * <dt>java.compiler <dd>Name of JIT to use
+ * <dt>java.ext.dirs <dd>Java extension path
+ * <dt>os.name <dd>Operating System Name
+ * <dt>os.arch <dd>Operating System Architecture
+ * <dt>os.version <dd>Operating System Version
+ * <dt>file.separator <dd>File separator ("/" on Unix)
+ * <dt>path.separator <dd>Path separator (":" on Unix)
+ * <dt>line.separator <dd>Line separator ("\n" on Unix)
+ * <dt>user.name <dd>User account name
+ * <dt>user.home <dd>User home directory
+ * <dt>user.dir <dd>User's current working directory
+ * <dt>gnu.cpu.endian <dd>"big" or "little"
+ * </dl>
+ *
+ * @param p the Properties object to insert the system properties into
+ */
+ static native void preInit(Properties properties);
+
+ /**
+ * Here you get a chance to overwrite some of the properties set by
+ * the common SystemProperties code. For example, it might be
+ * a good idea to process the properties specified on the command
+ * line here.
+ */
+ static void postInit(Properties properties)
+ {
+ }
+}
diff --git a/vm/reference/java/lang/VMClassLoader.java b/vm/reference/java/lang/VMClassLoader.java
index 4d3a08596..a2ea3ef90 100644
--- a/vm/reference/java/lang/VMClassLoader.java
+++ b/vm/reference/java/lang/VMClassLoader.java
@@ -36,30 +36,32 @@ 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;
-import java.security.ProtectionDomain;
-import java.net.URL;
-import java.net.MalformedURLException;
-import java.io.IOException;
+import gnu.classpath.SystemProperties;
+import gnu.java.lang.SystemClassLoader;
+import gnu.java.util.EmptyEnumeration;
+
import java.io.File;
+import java.io.IOException;
+import java.lang.reflect.Constructor;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.ProtectionDomain;
import java.util.Enumeration;
import java.util.Map;
import java.util.HashMap;
import java.util.StringTokenizer;
import java.util.Vector;
-import java.lang.reflect.Constructor;
-import gnu.java.lang.SystemClassLoader;
-
-import gnu.java.util.EmptyEnumeration;
/**
* java.lang.VMClassLoader is a package-private helper for VMs to implement
* on behalf of java.lang.ClassLoader.
*
* @author John Keiser
- * @author Mark Wielaard <mark@klomp.org>
- * @author Eric Blake <ebb9@email.byu.edu>
+ * @author Mark Wielaard (mark@klomp.org)
+ * @author Eric Blake (ebb9@email.byu.edu)
*/
final class VMClassLoader
{
@@ -161,7 +163,7 @@ final class VMClassLoader
static Enumeration getResources(String name)
{
StringTokenizer st = new StringTokenizer(
- ClassLoader.getSystemProperty("java.boot.class.path", "."),
+ SystemProperties.getProperty("java.boot.class.path", "."),
File.pathSeparator);
Vector v = new Vector();
while (st.hasMoreTokens())
diff --git a/vm/reference/java/lang/VMProcess.java b/vm/reference/java/lang/VMProcess.java
index 51dc0ee84..498b605e3 100644
--- a/vm/reference/java/lang/VMProcess.java
+++ b/vm/reference/java/lang/VMProcess.java
@@ -1,5 +1,5 @@
/* java.lang.VMProcess -- VM implementation of java.lang.Process
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -73,27 +73,27 @@ final class VMProcess extends Process
private static final int TERMINATED = 2;
// Dedicated thread that does all the fork()'ing and wait()'ing.
- private static Thread processThread;
+ static Thread processThread;
// New processes waiting to be spawned by processThread.
- private static final LinkedList workList = new LinkedList();
+ static final LinkedList workList = new LinkedList();
// Return values set by nativeReap() when a child is reaped.
// These are only accessed by processThread so no locking required.
- private static long reapedPid;
- private static int reapedExitValue;
+ static long reapedPid;
+ static int reapedExitValue;
// Information about this process
- private int state; // current state of process
- private final String[] cmd; // copied from Runtime.exec()
- private final String[] env; // copied from Runtime.exec()
- private final File dir; // copied from Runtime.exec()
- private Throwable exception; // if process failed to start
- private long pid; // process id
- private OutputStream stdin; // process input stream
- private InputStream stdout; // process output stream
- private InputStream stderr; // process error stream
- private int exitValue; // process exit value
+ int state; // current state of process
+ final String[] cmd; // copied from Runtime.exec()
+ final String[] env; // copied from Runtime.exec()
+ final File dir; // copied from Runtime.exec()
+ Throwable exception; // if process failed to start
+ long pid; // process id
+ OutputStream stdin; // process input stream
+ InputStream stdout; // process output stream
+ InputStream stderr; // process error stream
+ int exitValue; // process exit value
//
// Dedicated thread that does all the fork()'ing and wait()'ing
@@ -115,7 +115,7 @@ final class VMProcess extends Process
// constructor will be private, which means the compiler will have
// to generate a second package-private constructor, which is
// bogus.
- public ProcessThread ()
+ ProcessThread ()
{
}
@@ -202,6 +202,10 @@ final class VMProcess extends Process
process.state = RUNNING;
activeMap.put(new Long(process.pid), process);
}
+ catch (ThreadDeath death)
+ {
+ throw death;
+ }
catch (Throwable t)
{
process.state = TERMINATED;
@@ -345,7 +349,7 @@ final class VMProcess extends Process
*
* @throws IOException if the O/S process could not be created.
*/
- private native void nativeSpawn(String[] cmd, String[] env, File dir)
+ native void nativeSpawn(String[] cmd, String[] env, File dir)
throws IOException;
/**
@@ -356,7 +360,8 @@ final class VMProcess extends Process
*
* @return true if a child was reaped, otherwise false
*/
- private static native boolean nativeReap();
+ // This is not private as it is called from an inner class.
+ static native boolean nativeReap();
/**
* Kill a process. This sends it a fatal signal but does not reap it.
diff --git a/vm/reference/java/lang/VMRuntime.java b/vm/reference/java/lang/VMRuntime.java
index 4891200de..8da217f15 100644
--- a/vm/reference/java/lang/VMRuntime.java
+++ b/vm/reference/java/lang/VMRuntime.java
@@ -151,20 +151,18 @@ final class VMRuntime
* already been mapped to a true filename.
*
* @param filename the file to load
+ * @param loader class loader, or <code>null</code> for the boot loader
* @return 0 on failure, nonzero on success
*/
- static native int nativeLoad(String filename);
+ static native int nativeLoad(String filename, ClassLoader loader);
/**
- * Map a system-independent "short name" to the full file name, and append
- * it to the path.
- * XXX This method is being replaced by System.mapLibraryName.
+ * Map a system-independent "short name" to the full file name.
*
- * @param pathname the path
* @param libname the short version of the library name
* @return the full filename
*/
- static native String nativeGetLibname(String pathname, String libname);
+ static native String mapLibraryName(String libname);
/**
* Execute a process. The command line has already been tokenized, and
@@ -185,46 +183,11 @@ final class VMRuntime
}
/**
- * Get the system properties. This is done here, instead of in System,
- * because of the bootstrap sequence. Note that the native code should
- * not try to use the Java I/O classes yet, as they rely on the properties
- * already existing. The only safe method to use to insert these default
- * system properties is {@link Properties#setProperty(String, String)}.
- *
- * <p>These properties MUST include:
- * <dl>
- * <dt>java.version <dd>Java version number
- * <dt>java.vendor <dd>Java vendor specific string
- * <dt>java.vendor.url <dd>Java vendor URL
- * <dt>java.home <dd>Java installation directory
- * <dt>java.vm.specification.version <dd>VM Spec version
- * <dt>java.vm.specification.vendor <dd>VM Spec vendor
- * <dt>java.vm.specification.name <dd>VM Spec name
- * <dt>java.vm.version <dd>VM implementation version
- * <dt>java.vm.vendor <dd>VM implementation vendor
- * <dt>java.vm.name <dd>VM implementation name
- * <dt>java.specification.version <dd>Java Runtime Environment version
- * <dt>java.specification.vendor <dd>Java Runtime Environment vendor
- * <dt>java.specification.name <dd>Java Runtime Environment name
- * <dt>java.class.version <dd>Java class version number
- * <dt>java.class.path <dd>Java classpath
- * <dt>java.library.path <dd>Path for finding Java libraries
- * <dt>java.io.tmpdir <dd>Default temp file path
- * <dt>java.compiler <dd>Name of JIT to use
- * <dt>java.ext.dirs <dd>Java extension path
- * <dt>os.name <dd>Operating System Name
- * <dt>os.arch <dd>Operating System Architecture
- * <dt>os.version <dd>Operating System Version
- * <dt>file.separator <dd>File separator ("/" on Unix)
- * <dt>file.encoding <dd>Standard encoding for text (Default 8859_1)
- * <dt>path.separator <dd>Path separator (":" on Unix)
- * <dt>line.separator <dd>Line separator ("\n" on Unix)
- * <dt>user.name <dd>User account name
- * <dt>user.home <dd>User home directory
- * <dt>user.dir <dd>User's current working directory
- * </dl>
- *
- * @param p the Properties object to insert the system properties into
+ * This method is called by Runtime.addShutdownHook() when it is
+ * called for the first time. It enables the VM to lazily setup
+ * an exit handler, should it so desire.
*/
- static native void insertSystemProperties(Properties p);
+ static void enableShutdownHooks()
+ {
+ }
} // class VMRuntime
diff --git a/vm/reference/java/lang/VMSecurityManager.java b/vm/reference/java/lang/VMSecurityManager.java
deleted file mode 100644
index 3d95c8a96..000000000
--- a/vm/reference/java/lang/VMSecurityManager.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/* VMSecurityManager.java -- Reference implementation of VM hooks for security
- Copyright (C) 1998, 2002 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., 59 Temple Place, Suite 330, Boston, MA
-02111-1307 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package java.lang;
-
-/**
- * VMSecurityManager is a helper class for SecurityManager the VM must
- * implement.
- *
- * @author John Keiser
- * @author Eric Blake <ebb9@email.byu.edu>
- */
-final class VMSecurityManager
-{
- /**
- * Get a list of all the classes currently executing methods on the
- * Java stack. getClassContext()[0] is the currently executing method, ie.
- * the method which called SecurityManager.getClassContext(). (Hint: you
- * may need to pop off one or more frames: don't include SecurityManager
- * or VMSecurityManager.getClassContext in your result. Also, be sure that
- * you correctly handle the context if SecurityManager.getClassContext
- * was invoked by reflection).
- *
- * @return an array of the declaring classes of each stack frame
- */
- static native Class[] getClassContext();
-
- /**
- * Get the current ClassLoader. This is the first non-null class loader
- * on the stack, if one exists, stopping either at the end of the stack
- * or the first instance of a PrivilegedAction. In other words, this call
- * automatically unwinds past all classes loaded by the bootstrap loader,
- * where getClassLoader() returns null, to get to the user class that
- * really invoked the call that needs a classloader.
- *
- * @return the current ClassLoader
- */
- static native ClassLoader currentClassLoader();
-}
diff --git a/vm/reference/java/lang/VMSystem.java b/vm/reference/java/lang/VMSystem.java
index a1273cd16..804b408a0 100644
--- a/vm/reference/java/lang/VMSystem.java
+++ b/vm/reference/java/lang/VMSystem.java
@@ -89,13 +89,6 @@ final class VMSystem
static native int identityHashCode(Object o);
/**
- * Detect big-endian systems.
- *
- * @return true if the system is big-endian.
- */
- static native boolean isWordsBigEndian();
-
- /**
* Convert a library name to its platform-specific variant.
*
* @param libname the library name, as used in <code>loadLibrary</code>
diff --git a/vm/reference/java/lang/VMThread.java b/vm/reference/java/lang/VMThread.java
index 1e36668c1..a2e0223be 100644
--- a/vm/reference/java/lang/VMThread.java
+++ b/vm/reference/java/lang/VMThread.java
@@ -1,5 +1,5 @@
/* VMThread -- VM interface for Thread of executable code
- Copyright (C) 2003, 2004 Free Software Foundation
+ Copyright (C) 2003, 2004, 2005 Free Software Foundation
This file is part of GNU Classpath.
@@ -56,7 +56,6 @@ package java.lang;
* <li>native void nativeStop(Throwable t);
* <li>native static Thread currentThread();
* <li>static native void yield();
- * <li>static native void sleep(long ms, int ns) throws InterruptedException;
* <li>static native boolean interrupted();
* </ul>
* All other methods may be implemented to make Thread handling more efficient
@@ -240,14 +239,17 @@ final class VMThread
*/
synchronized void join(long ms, int ns) throws InterruptedException
{
- // round up
+ // Round up
ms += (ns != 0) ? 1 : 0;
- long end = System.currentTimeMillis() + ms;
+ // Compute end time, but don't overflow
+ long now = System.currentTimeMillis();
+ long end = now + ms;
+ if (end < now)
+ end = Long.MAX_VALUE;
- // Apparently, some VMs will return from wait without notify having
- // been called, so we loop and test the vmThread field in our
- // corresponding Thread object.
+ // A VM is allowed to return from wait() without notify() having been
+ // called, so we loop to handle possible spurious wakeups.
while(thread.vmThread != null)
{
// We use the VMThread object to wait on, because this is a private
@@ -255,7 +257,7 @@ final class VMThread
wait(ms);
if(ms != 0)
{
- long now = System.currentTimeMillis();
+ now = System.currentTimeMillis();
ms = end - now;
if(ms <= 0)
{
@@ -343,7 +345,7 @@ final class VMThread
*
* @return the currently executing Thread
*/
- native static Thread currentThread();
+ static native Thread currentThread();
/**
* Yield to another thread. The Thread will not lose any locks it holds
@@ -365,13 +367,49 @@ final class VMThread
* because some other thread may be active. So don't expect real-time
* performance.
*
- * @param ms the number of milliseconds to sleep, or 0 for forever
+ * @param ms the number of milliseconds to sleep.
* @param ns the number of extra nanoseconds to sleep (0-999999)
- * @throws InterruptedException if the Thread is interrupted; it's
- * <i>interrupted status</i> will be cleared
- * @throws IllegalArgumentException if ns is invalid
+ * @throws InterruptedException if the Thread is (or was) interrupted;
+ * it's <i>interrupted status</i> will be cleared
*/
- static native void sleep(long ms, int ns) throws InterruptedException;
+ static void sleep(long ms, int ns) throws InterruptedException
+ {
+
+ // Round up
+ ms += (ns != 0) ? 1 : 0;
+
+ // Note: JDK treats a zero length sleep is like Thread.yield(),
+ // without checking the interrupted status of the thread.
+ // It's unclear if this is a bug in the implementation or the spec.
+ // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203
+ if (ms == 0)
+ {
+ if (Thread.interrupted())
+ throw new InterruptedException();
+ return;
+ }
+
+ // Compute end time, but don't overflow
+ long now = System.currentTimeMillis();
+ long end = now + ms;
+ if (end < now)
+ end = Long.MAX_VALUE;
+
+ // A VM is allowed to return from wait() without notify() having been
+ // called, so we loop to handle possible spurious wakeups.
+ VMThread vt = Thread.currentThread().vmThread;
+ synchronized (vt)
+ {
+ while (true)
+ {
+ vt.wait(ms);
+ now = System.currentTimeMillis();
+ if (now >= end)
+ break;
+ ms = end - now;
+ }
+ }
+ }
/**
* Determine whether the current Thread has been interrupted, and clear
diff --git a/vm/reference/java/nio/channels/VMChannels.java b/vm/reference/java/nio/channels/VMChannels.java
new file mode 100644
index 000000000..04f278f1d
--- /dev/null
+++ b/vm/reference/java/nio/channels/VMChannels.java
@@ -0,0 +1,116 @@
+/* VMChannels.java --
+ 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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package java.nio.channels;
+
+import gnu.java.nio.ChannelInputStream;
+import gnu.java.nio.ChannelOutputStream;
+import gnu.java.nio.channels.FileChannelImpl;
+
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+
+final class VMChannels
+{
+ /**
+ * This class isn't intended to be instantiated.
+ */
+ private VMChannels()
+ {
+ // Do nothing here.
+ }
+
+ private static Object createStream(Class streamClass, Channel ch)
+ {
+ try
+ {
+ Class[] argTypes = new Class[1];
+ argTypes[0] = FileChannelImpl.class;
+ Constructor constructor =
+ streamClass.getDeclaredConstructor(argTypes);
+ constructor.setAccessible(true);
+ Object[] args = new Object[1];
+ args[0] = ch;
+ return constructor.newInstance(args);
+ }
+ catch (IllegalAccessException e)
+ {
+ // Ignored.
+ }
+ catch (InstantiationException e)
+ {
+ // Ignored.
+ }
+ catch (InvocationTargetException e)
+ {
+ // Ignored.
+ }
+ catch (NoSuchMethodException e)
+ {
+ // Ignored.
+ }
+
+ return null;
+ }
+
+ /**
+ * Constructs a stream that reads bytes from the given channel.
+ */
+ static InputStream newInputStream(ReadableByteChannel ch)
+ {
+ if (ch instanceof FileChannelImpl)
+ return (FileInputStream) createStream(FileInputStream.class, ch);
+
+ return new ChannelInputStream(ch);
+ }
+
+ /**
+ * Constructs a stream that writes bytes to the given channel.
+ */
+ static OutputStream newOutputStream(WritableByteChannel ch)
+ {
+ if (ch instanceof FileChannelImpl)
+ return (FileOutputStream) createStream(FileOutputStream.class, ch);
+
+ return new ChannelOutputStream(ch);
+ }
+}
diff --git a/vm/reference/java/security/VMAccessController.java b/vm/reference/java/security/VMAccessController.java
index f4adadeda..fc2410ac8 100644
--- a/vm/reference/java/security/VMAccessController.java
+++ b/vm/reference/java/security/VMAccessController.java
@@ -1,5 +1,5 @@
/* VMAccessController.java -- VM-specific access controller methods.
- Copyright (C) 2004 Free Software Foundation, Inc.
+ Copyright (C) 2004, 2005 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -70,7 +70,7 @@ final class VMAccessController
* And we return this all-permissive context to ensure that privileged
* methods called from getContext succeed.
*/
- private final static AccessControlContext DEFAULT_CONTEXT;
+ private static final AccessControlContext DEFAULT_CONTEXT;
static
{
CodeSource source = new CodeSource(null, null);