* src/lib/vm: Removed.
* src/lib/gnu: Added.
* src/lib/gnu/java: Likewise.
* src/lib/gnu/gnu: Likewise.
--HG--
rename : src/lib/vm/reference/gnu/classpath/VMStackWalker.java => src/lib/gnu/gnu/classpath/VMStackWalker.java
rename : src/lib/vm/reference/gnu/classpath/VMSystemProperties.java => src/lib/gnu/gnu/classpath/VMSystemProperties.java
rename : src/lib/vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java => src/lib/gnu/gnu/java/lang/management/VMMemoryMXBeanImpl.java
rename : src/lib/vm/reference/gnu/java/lang/management/VMRuntimeMXBeanImpl.java => src/lib/gnu/gnu/java/lang/management/VMRuntimeMXBeanImpl.java
rename : src/lib/vm/reference/java/lang/VMClassLoader.java => src/lib/gnu/java/lang/VMClassLoader.java
rename : src/lib/vm/reference/java/lang/VMString.java => src/lib/gnu/java/lang/VMString.java
rename : src/lib/vm/reference/java/lang/VMThread.java => src/lib/gnu/java/lang/VMThread.java
rename : src/lib/vm/reference/java/lang/VMThrowable.java => src/lib/gnu/java/lang/VMThrowable.java
rename : src/lib/vm/reference/java/security/VMAccessController.java => src/lib/gnu/java/security/VMAccessController.java
## Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
## 02110-1301, USA.
##
-## $Id: Makefile.am 7235 2007-01-22 17:22:28Z twisti $
+## $Id: Makefile.am 7890 2007-05-09 16:05:58Z twisti $
## Process this file with automake to produce Makefile.in
CLEANFILES = vm.zip
VM_JAVA_FILES = \
- $(top_srcdir)/src/lib/vm/reference/gnu/classpath/VMStackWalker.java \
- $(top_srcdir)/src/lib/vm/reference/gnu/classpath/VMSystemProperties.java \
- $(top_srcdir)/src/lib/vm/reference/gnu/java/lang/management/VMMemoryMXBeanImpl.java \
- $(top_srcdir)/src/lib/vm/reference/gnu/java/lang/management/VMRuntimeMXBeanImpl.java \
- $(top_srcdir)/src/lib/vm/reference/java/lang/VMClassLoader.java \
- $(top_srcdir)/src/lib/vm/reference/java/lang/VMString.java \
- $(top_srcdir)/src/lib/vm/reference/java/lang/VMThread.java \
- $(top_srcdir)/src/lib/vm/reference/java/lang/VMThrowable.java \
- $(top_srcdir)/src/lib/vm/reference/java/security/VMAccessController.java
+ $(top_srcdir)/src/lib/gnu/gnu/classpath/VMStackWalker.java \
+ $(top_srcdir)/src/lib/gnu/gnu/classpath/VMSystemProperties.java \
+ $(top_srcdir)/src/lib/gnu/gnu/java/lang/management/VMMemoryMXBeanImpl.java \
+ $(top_srcdir)/src/lib/gnu/gnu/java/lang/management/VMRuntimeMXBeanImpl.java \
+ $(top_srcdir)/src/lib/gnu/java/lang/VMClassLoader.java \
+ $(top_srcdir)/src/lib/gnu/java/lang/VMString.java \
+ $(top_srcdir)/src/lib/gnu/java/lang/VMThread.java \
+ $(top_srcdir)/src/lib/gnu/java/lang/VMThrowable.java \
+ $(top_srcdir)/src/lib/gnu/java/security/VMAccessController.java
VM_CLASS_FILES = \
classes/gnu/classpath/VMStackWalker.class \
--- /dev/null
+/* 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., 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;
+
+/**
+ * This class provides access to the classes on the Java stack
+ * for reflection and security purposes.
+ *
+ * <p>
+ * This class is only available to privileged 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];
+// }
+ public static native Class getCallingClass();
+
+ /**
+ * 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>VMStackWalker.getClassLoader(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 ClassLoader getCallingClassLoader()
+// {
+// Class[] ctx = getClassContext();
+// if (ctx.length < 3)
+// return null;
+// return getClassLoader(ctx[2]);
+// }
+ public static native ClassLoader getCallingClassLoader();
+
+
+ /**
+ * Retrieve the class's ClassLoader, or <code>null</code> if loaded
+ * by the bootstrap loader. I.e., this should return the same thing
+ * as {@link java.lang.VMClass#getClassLoader}. This duplicate version
+ * is here to work around access permissions.
+ */
+// public static native ClassLoader getClassLoader(Class cl);
+
+ /**
+ * Walk up the stack and return the first non-null class loader.
+ * If there aren't any non-null class loaders on the stack, return null.
+ */
+// public static ClassLoader firstNonNullClassLoader()
+// {
+// Class[] stack = getClassContext();
+// for (int i = 0; i < stack.length; i++)
+// {
+// ClassLoader loader = getClassLoader(stack[i]);
+// if (loader != null)
+// return loader;
+// }
+// return null;
+// }
+ public static native ClassLoader firstNonNullClassLoader();
+}
--- /dev/null
+/* 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., 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.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 properties 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)
+// {
+// }
+ static native void postInit(Properties properties);
+}
--- /dev/null
+/* VMMemoryMXBeanImpl.java - VM impl. of a memory bean
+ 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.java.lang.management;
+
+import java.lang.management.MemoryUsage;
+
+/**
+ * Provides access to information about the memory
+ * management of the current invocation of the virtual
+ * machine. Instances of this bean are obtained by calling
+ * {@link ManagementFactory#getMemoryMXBean()}.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+final class VMMemoryMXBeanImpl
+{
+
+ /**
+ * Returns an instance of {@link java.lang.management.MemoryUsage}
+ * with appropriate initial, used, committed and maximum values
+ * for the heap. By default, this uses the methods of
+ * {@link java.lang.Runtime} to provide some of the values.
+ *
+ * @return an {@link java.lang.management.MemoryUsage} instance
+ * for the heap.
+ */
+// static MemoryUsage getHeapMemoryUsage()
+// {
+// Runtime runtime = Runtime.getRuntime();
+// long totalMem = runtime.totalMemory();
+// return new MemoryUsage(-1, totalMem - runtime.freeMemory(),
+// totalMem, runtime.maxMemory());
+// }
+ static native MemoryUsage getHeapMemoryUsage();
+
+ /**
+ * Returns an instance of {@link java.lang.management.MemoryUsage}
+ * with appropriate initial, used, committed and maximum values
+ * for non-heap memory.
+ *
+ * @return an {@link java.lang.management.MemoryUsage} instance
+ * for non-heap memory.
+ */
+ static native MemoryUsage getNonHeapMemoryUsage();
+
+ /**
+ * Returns the number of objects ready to be garbage collected.
+ *
+ * @return the number of finalizable objects.
+ */
+ static native int getObjectPendingFinalizationCount();
+
+ /**
+ * Returns true if the virtual machine will emit additional
+ * information when memory is allocated and deallocated. The
+ * format of the output is left up to the virtual machine.
+ *
+ * @return true if verbose class loading output is on.
+ */
+ static native boolean isVerbose();
+
+ /**
+ * Turns on or off the emission of additional information
+ * when memory is allocated and deallocated. The format of the
+ * output is left up to the virtual machine. This method
+ * may be called by multiple threads concurrently, but there
+ * is only one global setting of verbosity that is affected.
+ *
+ * @param verbose the new setting for verbose class loading
+ * output.
+ */
+ static native void setVerbose(boolean verbose);
+
+}
--- /dev/null
+/* VMRuntimeMXBeanImpl.java - VM implementation of an runtime bean
+ 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.java.lang.management;
+
+import gnu.classpath.SystemProperties;
+
+/**
+ * Provides access to information about the virtual machine.
+ *
+ * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
+ * @since 1.5
+ */
+final class VMRuntimeMXBeanImpl
+{
+
+ /**
+ * Returns the command-line arguments supplied
+ * to the virtual machine, excluding those supplied
+ * to <code>main()</code>.
+ *
+ * @return the command-line arguments.
+ */
+ static native String[] getInputArguments();
+
+ /**
+ * Returns a developer-chosen name for the virtual
+ * machine, which may differ over different running
+ * instances of the same virtual machine binary.
+ * For example, this may include the particular
+ * process identifier used by this instance or
+ * the host name of the machine on which it is
+ * running. The intention is that this name refers
+ * to the precise entity that the other data supplied
+ * by the bean refers to, rather than the VM in general.
+ *
+ * @return the custom name of the VM.
+ */
+ static String getName()
+ {
+ return SystemProperties.getProperty("java.vm.name") + " " +
+ SystemProperties.getProperty("java.vm.version");
+ }
+
+ /**
+ * The time in milliseconds at which the virtual
+ * machine was started. This method is only executed
+ * once (for efficency), as the value is not expected
+ * to change.
+ *
+ * @return the VM start time.
+ */
+ static native long getStartTime();
+
+}
--- /dev/null
+/* VMClassLoader.java -- Reference implementation of native interface
+ required by ClassLoader
+ Copyright (C) 1998, 2001, 2002, 2004, 2005, 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 java.lang;
+
+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;
+
+/**
+ * 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)
+ */
+final class VMClassLoader
+{
+
+
+ /** packages loaded by the bootstrap class loader */
+ static final HashMap definedPackages = new HashMap();
+
+ /** jars from property java.boot.class.path */
+ static final HashMap bootjars = new HashMap();
+
+
+ /**
+ * Converts the array string of native package names to
+ * Packages. The packages are then put into the
+ * definedPackages hashMap
+ */
+ static
+ {
+ String[] packages = getBootPackages();
+
+ if( packages != null)
+ {
+ String specName =
+ SystemProperties.getProperty("java.specification.name");
+ String vendor =
+ SystemProperties.getProperty("java.specification.vendor");
+ String version =
+ SystemProperties.getProperty("java.specification.version");
+
+ Package p;
+
+ for(int i = 0; i < packages.length; i++)
+ {
+ p = new Package(packages[i],
+ specName,
+ vendor,
+ version,
+ "GNU Classpath",
+ "GNU",
+ Configuration.CLASSPATH_VERSION,
+ null,
+ null);
+
+ definedPackages.put(packages[i], p);
+ }
+ }
+ }
+
+
+ /**
+ * Helper to define a class using a string of bytes. This assumes that
+ * the security checks have already been performed, if necessary.
+ *
+ * Implementations of this method are advised to consider the
+ * situation where user code modifies the byte array after it has
+ * been passed to defineClass. This can be handled by making a
+ * private copy of the array, or arranging to only read any given
+ * byte a single time.
+ *
+ * @param name the name to give the class, or null if unknown
+ * @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 class that was defined
+ * @throws ClassFormatError if data is not in proper classfile format
+ */
+ static final native Class defineClass(ClassLoader cl, String name,
+ byte[] data, int offset, int len,
+ ProtectionDomain pd)
+ throws ClassFormatError;
+
+ /**
+ * Helper to resolve all references to other classes from this class.
+ *
+ * @param c the class to resolve
+ */
+ static final native void resolveClass(Class c);
+
+ /**
+ * Helper to load a class from the bootstrap class loader.
+ *
+ * @param name the class name to load
+ * @param resolve whether to resolve it
+ * @return the class, loaded by the bootstrap classloader or null
+ * if the class wasn't found. Returning null is equivalent to throwing
+ * a ClassNotFoundException (but a possible performance optimization).
+ */
+ static final native Class loadClass(String name, boolean resolve)
+ throws ClassNotFoundException;
+
+ /**
+ * Helper to load a resource from the bootstrap class loader.
+ *
+ * @param name the resource to find
+ * @return the URL to the resource
+ */
+ static URL getResource(String name)
+ {
+ Enumeration e = getResources(name);
+ if (e.hasMoreElements())
+ return (URL)e.nextElement();
+ return null;
+ }
+ /**
+ * Helper to get a list of resources from the bootstrap class loader.
+ *
+ * @param name the resource to find
+ * @return an enumeration of resources
+ */
+ static Enumeration getResources(String name)
+ {
+// StringTokenizer st = new StringTokenizer(
+// SystemProperties.getProperty("java.boot.class.path", "."),
+// File.pathSeparator);
+// Vector v = new Vector();
+// while (st.hasMoreTokens())
+// {
+// File file = new File(st.nextToken());
+// if (file.isDirectory())
+// {
+// try
+// {
+// File f = new File(file, name);
+// if (!f.exists()) continue;
+// v.add(new URL("file://" + f.getAbsolutePath()));
+// }
+// catch (MalformedURLException e)
+// {
+// throw new Error(e);
+// }
+// }
+// else if (file.isFile())
+// {
+// ZipFile zip;
+// synchronized(bootjars)
+// {
+// zip = (ZipFile) bootjars.get(file.getName());
+// }
+// if(zip == null)
+// {
+// try
+// {
+// zip = new ZipFile(file);
+// synchronized(bootjars)
+// {
+// bootjars.put(file.getName(), zip);
+// }
+// }
+// catch (IOException e)
+// {
+// continue;
+// }
+// }
+// String zname = name.startsWith("/") ? name.substring(1) : name;
+// if (zip.getEntry(zname) == null)
+// continue;
+// try
+// {
+// v.add(new URL("jar:file://"
+// + file.getAbsolutePath() + "!/" + zname));
+// }
+// catch (MalformedURLException e)
+// {
+// throw new Error(e);
+// }
+// }
+// }
+// return v.elements();
+// }
+ Vector urls = nativeGetResources(name);
+ Vector v = new Vector();
+ for (Enumeration en = urls.elements(); en.hasMoreElements();)
+ {
+ try
+ {
+ v.add(new URL((String) en.nextElement()));
+ }
+ catch (MalformedURLException e)
+ {
+ throw new Error(e);
+ }
+ }
+ return v.elements();
+ }
+
+ private native static final Vector nativeGetResources(String name);
+
+
+ /**
+ * Returns a String[] of native package names. The default
+ * 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()
+ {
+ try
+ {
+ Enumeration indexListEnumeration = getResources("META-INF/INDEX.LIST");
+ Set packageSet = new HashSet();
+
+ while (indexListEnumeration.hasMoreElements())
+ {
+ try
+ {
+ String line;
+ int lineToSkip = 3;
+ BufferedReader reader = new BufferedReader(
+ new InputStreamReader(
+ ((URL) indexListEnumeration.nextElement()).openStream()));
+ while ((line = reader.readLine()) != null)
+ {
+ if (lineToSkip == 0)
+ {
+ if (line.length() == 0)
+ lineToSkip = 1;
+ else
+ packageSet.add(line.replace('/', '.'));
+ }
+ else
+ lineToSkip--;
+ }
+ reader.close();
+ }
+ catch (IOException e)
+ {
+ // Empty catch block on purpose
+ }
+ }
+ return (String[]) packageSet.toArray(new String[packageSet.size()]);
+ }
+ catch (Exception e)
+ {
+ return new String[0];
+ }
+ }
+
+
+ /**
+ * Helper to get a package from the bootstrap class loader.
+ *
+ * @param name the name to find
+ * @return the named package, if it exists
+ */
+ static Package getPackage(String name)
+ {
+ return (Package)definedPackages.get(name);
+ }
+
+
+
+ /**
+ * Helper to get all packages from the bootstrap class loader.
+ *
+ * @return all named packages, if any exist
+ */
+ static Package[] getPackages()
+ {
+ Package[] packages = new Package[definedPackages.size()];
+ definedPackages.values().toArray(packages);
+ return packages;
+ }
+
+ /**
+ * Helper for java.lang.Integer, Byte, etc to get the TYPE class
+ * at initialization time. The type code is one of the chars that
+ * represents the primitive type as in JNI.
+ *
+ * <ul>
+ * <li>'Z' - boolean</li>
+ * <li>'B' - byte</li>
+ * <li>'C' - char</li>
+ * <li>'D' - double</li>
+ * <li>'F' - float</li>
+ * <li>'I' - int</li>
+ * <li>'J' - long</li>
+ * <li>'S' - short</li>
+ * <li>'V' - void</li>
+ * </ul>
+ *
+ * @param type the primitive type
+ * @return a "bogus" class representing the primitive type
+ */
+ static final native Class getPrimitiveClass(char type);
+
+ /**
+ * The system default for assertion status. This is used for all system
+ * classes (those with a null ClassLoader), as well as the initial value for
+ * every ClassLoader's default assertion status.
+ *
+ * XXX - Not implemented yet; this requires native help.
+ *
+ * @return the system-wide default assertion status
+ */
+// static final boolean defaultAssertionStatus()
+// {
+// return true;
+// }
+ static native final boolean defaultAssertionStatus();
+
+ /**
+ * The system default for package assertion status. This is used for all
+ * ClassLoader's packageAssertionStatus defaults. It must be a map of
+ * package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package
+ * represented as a null key.
+ *
+ * XXX - Not implemented yet; this requires native help.
+ *
+ * @return a (read-only) map for the default packageAssertionStatus
+ */
+ static final Map packageAssertionStatus()
+ {
+ return new HashMap();
+ }
+
+ /**
+ * The system default for class assertion status. This is used for all
+ * ClassLoader's classAssertionStatus defaults. It must be a map of
+ * class names to Boolean.TRUE or Boolean.FALSE
+ *
+ * XXX - Not implemented yet; this requires native help.
+ *
+ * @return a (read-only) map for the default classAssertionStatus
+ */
+ static final Map classAssertionStatus()
+ {
+ return new HashMap();
+ }
+
+ static ClassLoader getSystemClassLoader()
+ {
+ return ClassLoader.defaultGetSystemClassLoader();
+ }
+
+ /**
+ * Find the class if this class loader previously defined this class
+ * or if this class loader has been recorded as the initiating class loader
+ * 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);
+ }
+ }
+}
--- /dev/null
+/* VMString.java -- VM Specific String methods
+ Copyright (C) 2003 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 java.lang;
+
+import java.lang.ref.WeakReference;
+import java.util.WeakHashMap;
+
+/*
+ * This class is a reference version, mainly for compiling a class library
+ * jar. It is likely that VM implementers replace this with their own
+ * version that can communicate effectively with the VM.
+ */
+
+/**
+ * Code relocated from java.lang.String by
+ * @author Dave Grove <groved@us.ibm.com>
+ */
+final class VMString
+{
+
+ /**
+ * Holds the references for each intern()'d String. If all references to
+ * the string disappear, and the VM properly supports weak references,
+ * the String will be GC'd.
+ */
+// private static final WeakHashMap internTable = new WeakHashMap();
+
+ /**
+ * Fetches this String from the intern hashtable. If two Strings are
+ * considered equal, by the equals() method, then intern() will return the
+ * same String instance. ie. if (s1.equals(s2)) then
+ * (s1.intern() == s2.intern()). All string literals and string-valued
+ * constant expressions are already interned.
+ *
+ * @param str the String to intern
+ * @return the interned String
+ */
+// static String intern(String str)
+// {
+// synchronized (internTable)
+// {
+// WeakReference ref = (WeakReference) internTable.get(str);
+// if (ref != null)
+// {
+// String s = (String) ref.get();
+// // If s is null, then no strong references exist to the String;
+// // the weak hash map will soon delete the key.
+// if (s != null)
+// return s;
+// }
+// internTable.put(str, new WeakReference(str));
+// }
+// return str;
+// }
+
+ /**
+ * this one is native in CACAO
+ */
+ static native String intern(String str);
+
+} // class VMString
--- /dev/null
+/* VMThread -- VM interface for Thread of executable code
+ Copyright (C) 2003, 2004, 2005, 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 java.lang;
+
+/**
+ * VM interface for Thread of executable code. Holds VM dependent state.
+ * It is deliberately package local and final and should only be accessed
+ * by the Thread class.
+ * <p>
+ * This is the GNU Classpath reference implementation, it should be adapted
+ * for a specific VM.
+ * <p>
+ * The following methods must be implemented:
+ * <ul>
+ * <li>native void start(long stacksize);
+ * <li>native void interrupt();
+ * <li>native boolean isInterrupted();
+ * <li>native void suspend();
+ * <li>native void resume();
+ * <li>native void nativeSetPriority(int priority);
+ * <li>native void nativeStop(Throwable t);
+ * <li>native static Thread currentThread();
+ * <li>static native void yield();
+ * <li>static native boolean interrupted();
+ * </ul>
+ * All other methods may be implemented to make Thread handling more efficient
+ * or to implement some optional (and sometimes deprecated) behaviour. Default
+ * implementations are provided but it is highly recommended to optimize them
+ * for a specific VM.
+ *
+ * @author Jeroen Frijters (jeroen@frijters.net)
+ * @author Dalibor Topic (robilad@kaffe.org)
+ */
+final class VMThread
+{
+ /**
+ * The Thread object that this VM state belongs to.
+ * Used in currentThread() and start().
+ * Note: when this thread dies, this reference is *not* cleared
+ */
+ volatile Thread thread;
+
+ /**
+ * Flag that is set when the thread runs, used by stop() to protect against
+ * stop's getting lost.
+ */
+ private volatile boolean running;
+
+ /**
+ * VM private data.
+ */
+ private transient Object vmdata;
+
+ /**
+ * Private constructor, create VMThreads with the static create method.
+ *
+ * @param thread The Thread object that was just created.
+ */
+ private VMThread(Thread thread)
+ {
+ this.thread = thread;
+ }
+
+ /**
+ * This method is the initial Java code that gets executed when a native
+ * thread starts. It's job is to coordinate with the rest of the VMThread
+ * logic and to start executing user code and afterwards handle clean up.
+ */
+ private void run()
+ {
+ try
+ {
+ try
+ {
+ running = true;
+ synchronized(thread)
+ {
+ Throwable t = thread.stillborn;
+ if(t != null)
+ {
+ thread.stillborn = null;
+ throw t;
+ }
+ }
+ thread.run();
+ }
+ catch(Throwable t)
+ {
+ try
+ {
+ Thread.UncaughtExceptionHandler handler;
+ handler = thread.getUncaughtExceptionHandler();
+ handler.uncaughtException(thread, t);
+ }
+ catch(Throwable ignore)
+ {
+ }
+ }
+ }
+ finally
+ {
+ // Setting runnable to false is partial protection against stop
+ // being called while we're cleaning up. To be safe all code in
+ // VMThread be unstoppable.
+ running = false;
+ thread.die();
+ synchronized(this)
+ {
+ // release the threads waiting to join us
+ notifyAll();
+ }
+ }
+ }
+
+ /**
+ * Creates a native Thread. This is called from the start method of Thread.
+ * The Thread is started.
+ *
+ * @param thread The newly created Thread object
+ * @param stacksize Indicates the requested stacksize. Normally zero,
+ * non-zero values indicate requested stack size in bytes but it is up
+ * to the specific VM implementation to interpret them and may be ignored.
+ */
+ static void create(Thread thread, long stacksize)
+ {
+ VMThread vmThread = new VMThread(thread);
+ thread.vmThread = vmThread;
+ vmThread.start(stacksize);
+ }
+
+ /**
+ * Gets the name of the thread. Usually this is the name field of the
+ * associated Thread object, but some implementation might choose to
+ * return the name of the underlying platform thread.
+ */
+ String getName()
+ {
+ return thread.name;
+ }
+
+ /**
+ * Set the name of the thread. Usually this sets the name field of the
+ * associated Thread object, but some implementations might choose to
+ * set the name of the underlying platform thread.
+ * @param name The new name
+ */
+ void setName(String name)
+ {
+ thread.name = name;
+ }
+
+ /**
+ * Set the thread priority field in the associated Thread object and
+ * calls the native method to set the priority of the underlying
+ * platform thread.
+ * @param priority The new priority
+ */
+ void setPriority(int priority)
+ {
+ thread.priority = priority;
+ nativeSetPriority(priority);
+ }
+
+ /**
+ * Returns the priority. Usually this is the priority field from the
+ * associated Thread object, but some implementation might choose to
+ * return the priority of the underlying platform thread.
+ * @return this Thread's priority
+ */
+ int getPriority()
+ {
+ return thread.priority;
+ }
+
+ /**
+ * Returns true if the thread is a daemon thread. Usually this is the
+ * daemon field from the associated Thread object, but some
+ * implementation might choose to return the daemon state of the underlying
+ * platform thread.
+ * @return whether this is a daemon Thread or not
+ */
+ boolean isDaemon()
+ {
+ return thread.daemon;
+ }
+
+ /**
+ * Returns the number of stack frames in this Thread.
+ * Will only be called when when a previous call to suspend() returned true.
+ *
+ * @deprecated unsafe operation
+ */
+ native int countStackFrames();
+
+ /**
+ * Wait the specified amount of time for the Thread in question to die.
+ *
+ * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
+ * not offer that fine a grain of timing resolution. Besides, there is
+ * no guarantee that this thread can start up immediately when time expires,
+ * because some other thread may be active. So don't expect real-time
+ * performance.
+ *
+ * @param ms the number of milliseconds to wait, or 0 for forever
+ * @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
+ */
+ synchronized void join(long ms, int ns) throws InterruptedException
+ {
+ // Round up
+ ms += (ns != 0) ? 1 : 0;
+
+ // 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.
+ while(thread.vmThread != null)
+ {
+ // We use the VMThread object to wait on, because this is a private
+ // object, so client code cannot call notify on us.
+ wait(ms);
+ if(ms != 0)
+ {
+ now = System.currentTimeMillis();
+ ms = end - now;
+ if(ms <= 0)
+ {
+ break;
+ }
+ }
+ }
+ }
+
+ /**
+ * Cause this Thread to stop abnormally and throw the specified exception.
+ * If you stop a Thread that has not yet started, the stop is ignored
+ * (contrary to what the JDK documentation says).
+ * <b>WARNING</b>This bypasses Java security, and can throw a checked
+ * exception which the call stack is unprepared to handle. Do not abuse
+ * this power.
+ *
+ * <p>This is inherently unsafe, as it can interrupt synchronized blocks and
+ * leave data in bad states.
+ *
+ * <p><b>NOTE</b> stop() should take care not to stop a thread if it is
+ * executing code in this class.
+ *
+ * @param t the Throwable to throw when the Thread dies
+ * @deprecated unsafe operation, try not to use
+ */
+ void stop(Throwable t)
+ {
+ // Note: we assume that we own the lock on thread
+ // (i.e. that Thread.stop() is synchronized)
+ if(running)
+ nativeStop(t);
+ else
+ thread.stillborn = t;
+ }
+
+ /**
+ * Create a native thread on the underlying platform and start it executing
+ * on the run method of this object.
+ * @param stacksize the requested size of the native thread stack
+ */
+ native void start(long stacksize);
+
+ /**
+ * Interrupt this thread.
+ */
+ native void interrupt();
+
+ /**
+ * Determine whether this Thread has been interrupted, but leave
+ * the <i>interrupted status</i> alone in the process.
+ *
+ * @return whether the Thread has been interrupted
+ */
+ native boolean isInterrupted();
+
+ /**
+ * Suspend this Thread. It will not come back, ever, unless it is resumed.
+ */
+ native void suspend();
+
+ /**
+ * Resume this Thread. If the thread is not suspended, this method does
+ * nothing.
+ */
+ native void resume();
+
+ /**
+ * Set the priority of the underlying platform thread.
+ *
+ * @param priority the new priority
+ */
+ native void nativeSetPriority(int priority);
+
+ /**
+ * Asynchronously throw the specified throwable in this Thread.
+ *
+ * @param t the exception to throw
+ */
+ native void nativeStop(Throwable t);
+
+ /**
+ * Return the Thread object associated with the currently executing
+ * thread.
+ *
+ * @return the currently executing Thread
+ */
+ static native Thread currentThread();
+
+ /**
+ * Yield to another thread. The Thread will not lose any locks it holds
+ * during this time. There are no guarantees which thread will be
+ * next to run, and it could even be this one, but most VMs will choose
+ * the highest priority thread that has been waiting longest.
+ */
+ static native void yield();
+
+ /**
+ * Suspend the current Thread's execution for the specified amount of
+ * time. The Thread will not lose any locks it has during this time. There
+ * are no guarantees which thread will be next to run, but most VMs will
+ * choose the highest priority thread that has been waiting longest.
+ *
+ * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
+ * not offer that fine a grain of timing resolution. Besides, there is
+ * no guarantee that this thread can start up immediately when time expires,
+ * because some other thread may be active. So don't expect real-time
+ * performance.
+ *
+ * @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 (or was) interrupted;
+ * it's <i>interrupted status</i> will be cleared
+ */
+ static void sleep(long ms, int ns) throws InterruptedException
+ {
+ // 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 && ns == 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, ns);
+ now = System.currentTimeMillis();
+ if (now >= end)
+ break;
+ ms = end - now;
+ ns = 0;
+ }
+ }
+ }
+
+ /**
+ * Determine whether the current Thread has been interrupted, and clear
+ * the <i>interrupted status</i> in the process.
+ *
+ * @return whether the current Thread has been interrupted
+ */
+ static native boolean interrupted();
+
+ /**
+ * Checks whether the current thread holds the monitor on a given object.
+ * This allows you to do <code>assert Thread.holdsLock(obj)</code>.
+ *
+ * @param obj the object to check
+ * @return true if the current thread is currently synchronized on obj
+ * @throws NullPointerException if obj is null
+ */
+// static boolean holdsLock(Object obj)
+// {
+// /* Use obj.notify to check if the current thread holds
+// * the monitor of the object.
+// * If it doesn't, notify will throw an exception.
+// */
+// try
+// {
+// obj.notify();
+// // okay, current thread holds lock
+// return true;
+// }
+// catch (IllegalMonitorStateException e)
+// {
+// // it doesn't hold the lock
+// return false;
+// }
+// }
+ static native boolean holdsLock(Object obj);
+
+ /**
+ * Returns the current state of the thread.
+ * The value must be one of "BLOCKED", "NEW",
+ * "RUNNABLE", "TERMINATED", "TIMED_WAITING" or
+ * "WAITING".
+ *
+ * @return a string corresponding to one of the
+ * thread enumeration states specified above.
+ */
+ native String getState();
+
+}
--- /dev/null
+/* java.lang.VMThrowable -- VM support methods for Throwable.
+ Copyright (C) 1998, 1999, 2002 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;
+
+import gnu.classpath.Pointer;
+
+/**
+ * VM dependant state and support methods for Throwable.
+ * It is deliberately package local and final and should only be accessed
+ * by the Throwable class.
+ * <p>
+ * This is the GNU Classpath reference implementation, it should be adapted
+ * for a specific VM. The reference implementation does nothing.
+ *
+ * @author Mark Wielaard (mark@klomp.org)
+ */
+final class VMThrowable
+{
+ /* IMPORTANT: the rawdata field is not a java object */
+ private final Pointer vmData;
+
+ /**
+ * VM private data.
+ */
+ private transient Object vmdata;
+
+ /**
+ * Private contructor, create VMThrowables with fillInStackTrace();
+ */
+// private VMThrowable() { }
+ private VMThrowable()
+ {
+ vmData = null;
+ }
+
+ /**
+ * Fill in the stack trace with the current execution stack.
+ * Called by <code>Throwable.fillInStackTrace()</code> to get the state of
+ * the VM. Can return null when the VM does not support caputing the VM
+ * execution state.
+ *
+ * @return a new VMThrowable containing the current execution stack trace.
+ * @see Throwable#fillInStackTrace()
+ */
+ static native VMThrowable fillInStackTrace(Throwable t);
+
+ /**
+ * Returns an <code>StackTraceElement</code> array based on the execution
+ * state of the VM as captured by <code>fillInStackTrace</code>.
+ * Called by <code>Throwable.getStackTrace()</code>.
+ *
+ * @return a non-null but possible zero length array of StackTraceElement.
+ * @see Throwable#getStackTrace()
+ */
+ native StackTraceElement[] getStackTrace(Throwable t);
+}
--- /dev/null
+/* VMAccessController.java -- VM-specific access controller methods.
+ 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
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+This program 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 this program; 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.security;
+
+import java.util.HashSet;
+import java.util.LinkedList;
+
+final class VMAccessController
+{
+
+ // Fields.
+ // -------------------------------------------------------------------------
+
+ /**
+ * This is a per-thread stack of AccessControlContext objects (which can
+ * be null) for each call to AccessController.doPrivileged in each thread's
+ * call stack. We use this to remember which context object corresponds to
+ * which call.
+ */
+ private static final ThreadLocal contexts = new ThreadLocal();
+
+ /**
+ * This is a Boolean that, if set, tells getContext that it has already
+ * been called once, allowing us to handle recursive permission checks
+ * caused by methods getContext calls.
+ */
+ private static final ThreadLocal inGetContext = new ThreadLocal();
+
+ /**
+ * And we return this all-permissive context to ensure that privileged
+ * methods called from getContext succeed.
+ */
+ private static final AccessControlContext DEFAULT_CONTEXT;
+ static
+ {
+ CodeSource source = new CodeSource(null, null);
+ Permissions permissions = new Permissions();
+ permissions.add(new AllPermission());
+ ProtectionDomain[] domain = new ProtectionDomain[] {
+ new ProtectionDomain(source, permissions)
+ };
+ DEFAULT_CONTEXT = new AccessControlContext(domain);
+ }
+
+ private static final boolean DEBUG = gnu.classpath.Configuration.DEBUG;
+ private static void debug(String msg)
+ {
+ System.err.print(">>> VMAccessController: ");
+ System.err.println(msg);
+ }
+
+ // Constructors.
+ // -------------------------------------------------------------------------
+
+ private VMAccessController() { }
+
+ // Class methods.
+ // -------------------------------------------------------------------------
+
+ /**
+ * Relate a class (which should be an instance of {@link PrivilegedAction}
+ * with an access control context. This method is used by {@link
+ * AccessController#doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)}
+ * to set up the context that will be returned by {@link #getContext()}.
+ * This method relates the class to the current thread, so contexts
+ * pushed from one thread will not be available to another.
+ *
+ * @param acc The access control context.
+ */
+ static void pushContext (AccessControlContext acc)
+ {
+ if (DEBUG)
+ debug("pushing " + acc);
+ LinkedList stack = (LinkedList) contexts.get();
+ if (stack == null)
+ {
+ if (DEBUG)
+ debug("no stack... creating ");
+ stack = new LinkedList();
+ contexts.set(stack);
+ }
+ stack.addFirst(acc);
+ }
+
+ /**
+ * Removes the relation of a class to an {@link AccessControlContext}.
+ * This method is used by {@link AccessController} when exiting from a
+ * call to {@link
+ * AccessController#doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)}.
+ */
+ static void popContext()
+ {
+ if (DEBUG)
+ debug("popping context");
+
+ // Stack should never be null, nor should it be empty, if this method
+ // and its counterpart has been called properly.
+ LinkedList stack = (LinkedList) contexts.get();
+ if (stack != null)
+ {
+ stack.removeFirst();
+ if (stack.isEmpty())
+ contexts.set(null);
+ }
+ else if (DEBUG)
+ {
+ debug("no stack during pop?????");
+ }
+ }
+
+ /**
+ * Examine the method stack of the currently running thread, and create
+ * an {@link AccessControlContext} filled in with the appropriate {@link
+ * ProtectionDomain} objects given this stack.
+ *
+ * @return The context.
+ */
+ static AccessControlContext getContext()
+ {
+ // If we are already in getContext, but called a method that needs
+ // a permission check, return the all-permissive context so methods
+ // called from here succeed.
+ //
+ // XXX is this necessary? We should verify if there are any calls in
+ // the stack below this method that require permission checks.
+ Boolean inCall = (Boolean) inGetContext.get();
+ if (inCall != null && inCall.booleanValue())
+ {
+ if (DEBUG)
+ debug("already in getContext");
+ return DEFAULT_CONTEXT;
+ }
+
+ inGetContext.set(Boolean.TRUE);
+
+ Object[][] stack = getStack();
+ Class[] classes = (Class[]) stack[0];
+ String[] methods = (String[]) stack[1];
+
+ if (DEBUG)
+ debug("got trace of length " + classes.length);
+
+ HashSet domains = new HashSet();
+ HashSet seenDomains = new HashSet();
+ AccessControlContext context = null;
+ int privileged = 0;
+
+ // We walk down the stack, adding each ProtectionDomain for each
+ // class in the call stack. If we reach a call to doPrivileged,
+ // we don't add any more stack frames. We skip the first three stack
+ // frames, since they comprise the calls to getStack, getContext,
+ // and AccessController.getContext.
+ for (int i = 3; i < classes.length && privileged < 2; i++)
+ {
+ Class clazz = classes[i];
+ String method = methods[i];
+
+ if (DEBUG)
+ {
+ debug("checking " + clazz + "." + method);
+ // subject to getClassLoader RuntimePermission
+ debug("loader = " + clazz.getClassLoader());
+ }
+
+ // If the previous frame was a call to doPrivileged, then this is
+ // the last frame we look at.
+ if (privileged == 1)
+ privileged = 2;
+
+ if (clazz.equals (AccessController.class)
+ && method.equals ("doPrivileged"))
+ {
+ // If there was a call to doPrivileged with a supplied context,
+ // return that context. If using JAAS doAs*, it should be
+ // a context with a SubjectDomainCombiner
+ LinkedList l = (LinkedList) contexts.get();
+ if (l != null)
+ context = (AccessControlContext) l.getFirst();
+ privileged = 1;
+ }
+
+ // subject to getProtectionDomain RuntimePermission
+ ProtectionDomain domain = clazz.getProtectionDomain();
+
+ if (domain == null)
+ continue;
+ if (seenDomains.contains(domain))
+ continue;
+ seenDomains.add(domain);
+
+ // Create a static snapshot of this domain, which may change over time
+ // if the current policy changes.
+ domains.add(new ProtectionDomain(domain.getCodeSource(),
+ domain.getPermissions()));
+ }
+
+ if (DEBUG)
+ debug("created domains: " + domains);
+
+ ProtectionDomain[] result = (ProtectionDomain[])
+ domains.toArray(new ProtectionDomain[domains.size()]);
+
+ if (context != null)
+ {
+ DomainCombiner dc = context.getDomainCombiner ();
+ // If the supplied context had no explicit DomainCombiner, use
+ // our private version, which computes the intersection of the
+ // context's domains with the derived set.
+ if (dc == null)
+ context = new AccessControlContext
+ (IntersectingDomainCombiner.SINGLETON.combine
+ (result, context.getProtectionDomains ()));
+ // Use the supplied DomainCombiner. This should be secure,
+ // because only trusted code may create an
+ // AccessControlContext with a custom DomainCombiner.
+ else
+ context = new AccessControlContext (result, context, dc);
+ }
+ // No context was supplied. Return the derived one.
+ else
+ context = new AccessControlContext (result);
+
+ inGetContext.set(Boolean.FALSE);
+ return context;
+ }
+
+ /**
+ * Returns a snapshot of the current call stack as a pair of arrays:
+ * the first an array of classes in the call stack, the second an array
+ * of strings containing the method names in the call stack. The two
+ * arrays match up, meaning that method <i>i</i> is declared in class
+ * <i>i</i>. The arrays are clean; it will only contain Java methods,
+ * and no element of the list should be null.
+ *
+ * <p>The default implementation returns an empty stack, which will be
+ * interpreted as having no permissions whatsoever.
+ *
+ * @return A pair of arrays describing the current call stack. The first
+ * element is an array of Class objects, and the second is an array
+ * of Strings comprising the method names.
+ */
+// private static Object[][] getStack()
+// {
+// return new Object[][] { new Class[0], new String[0] };
+// }
+ private native static Object[][] getStack();
+}
+++ /dev/null
-/* 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., 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;
-
-/**
- * This class provides access to the classes on the Java stack
- * for reflection and security purposes.
- *
- * <p>
- * This class is only available to privileged 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];
-// }
- public static native Class getCallingClass();
-
- /**
- * 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>VMStackWalker.getClassLoader(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 ClassLoader getCallingClassLoader()
-// {
-// Class[] ctx = getClassContext();
-// if (ctx.length < 3)
-// return null;
-// return getClassLoader(ctx[2]);
-// }
- public static native ClassLoader getCallingClassLoader();
-
-
- /**
- * Retrieve the class's ClassLoader, or <code>null</code> if loaded
- * by the bootstrap loader. I.e., this should return the same thing
- * as {@link java.lang.VMClass#getClassLoader}. This duplicate version
- * is here to work around access permissions.
- */
-// public static native ClassLoader getClassLoader(Class cl);
-
- /**
- * Walk up the stack and return the first non-null class loader.
- * If there aren't any non-null class loaders on the stack, return null.
- */
-// public static ClassLoader firstNonNullClassLoader()
-// {
-// Class[] stack = getClassContext();
-// for (int i = 0; i < stack.length; i++)
-// {
-// ClassLoader loader = getClassLoader(stack[i]);
-// if (loader != null)
-// return loader;
-// }
-// return null;
-// }
- public static native ClassLoader firstNonNullClassLoader();
-}
+++ /dev/null
-/* 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., 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.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 properties 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)
-// {
-// }
- static native void postInit(Properties properties);
-}
+++ /dev/null
-/* VMMemoryMXBeanImpl.java - VM impl. of a memory bean
- 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.java.lang.management;
-
-import java.lang.management.MemoryUsage;
-
-/**
- * Provides access to information about the memory
- * management of the current invocation of the virtual
- * machine. Instances of this bean are obtained by calling
- * {@link ManagementFactory#getMemoryMXBean()}.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
-final class VMMemoryMXBeanImpl
-{
-
- /**
- * Returns an instance of {@link java.lang.management.MemoryUsage}
- * with appropriate initial, used, committed and maximum values
- * for the heap. By default, this uses the methods of
- * {@link java.lang.Runtime} to provide some of the values.
- *
- * @return an {@link java.lang.management.MemoryUsage} instance
- * for the heap.
- */
-// static MemoryUsage getHeapMemoryUsage()
-// {
-// Runtime runtime = Runtime.getRuntime();
-// long totalMem = runtime.totalMemory();
-// return new MemoryUsage(-1, totalMem - runtime.freeMemory(),
-// totalMem, runtime.maxMemory());
-// }
- static native MemoryUsage getHeapMemoryUsage();
-
- /**
- * Returns an instance of {@link java.lang.management.MemoryUsage}
- * with appropriate initial, used, committed and maximum values
- * for non-heap memory.
- *
- * @return an {@link java.lang.management.MemoryUsage} instance
- * for non-heap memory.
- */
- static native MemoryUsage getNonHeapMemoryUsage();
-
- /**
- * Returns the number of objects ready to be garbage collected.
- *
- * @return the number of finalizable objects.
- */
- static native int getObjectPendingFinalizationCount();
-
- /**
- * Returns true if the virtual machine will emit additional
- * information when memory is allocated and deallocated. The
- * format of the output is left up to the virtual machine.
- *
- * @return true if verbose class loading output is on.
- */
- static native boolean isVerbose();
-
- /**
- * Turns on or off the emission of additional information
- * when memory is allocated and deallocated. The format of the
- * output is left up to the virtual machine. This method
- * may be called by multiple threads concurrently, but there
- * is only one global setting of verbosity that is affected.
- *
- * @param verbose the new setting for verbose class loading
- * output.
- */
- static native void setVerbose(boolean verbose);
-
-}
+++ /dev/null
-/* VMRuntimeMXBeanImpl.java - VM implementation of an runtime bean
- 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.java.lang.management;
-
-import gnu.classpath.SystemProperties;
-
-/**
- * Provides access to information about the virtual machine.
- *
- * @author Andrew John Hughes (gnu_andrew@member.fsf.org)
- * @since 1.5
- */
-final class VMRuntimeMXBeanImpl
-{
-
- /**
- * Returns the command-line arguments supplied
- * to the virtual machine, excluding those supplied
- * to <code>main()</code>.
- *
- * @return the command-line arguments.
- */
- static native String[] getInputArguments();
-
- /**
- * Returns a developer-chosen name for the virtual
- * machine, which may differ over different running
- * instances of the same virtual machine binary.
- * For example, this may include the particular
- * process identifier used by this instance or
- * the host name of the machine on which it is
- * running. The intention is that this name refers
- * to the precise entity that the other data supplied
- * by the bean refers to, rather than the VM in general.
- *
- * @return the custom name of the VM.
- */
- static String getName()
- {
- return SystemProperties.getProperty("java.vm.name") + " " +
- SystemProperties.getProperty("java.vm.version");
- }
-
- /**
- * The time in milliseconds at which the virtual
- * machine was started. This method is only executed
- * once (for efficency), as the value is not expected
- * to change.
- *
- * @return the VM start time.
- */
- static native long getStartTime();
-
-}
+++ /dev/null
-/* VMClassLoader.java -- Reference implementation of native interface
- required by ClassLoader
- Copyright (C) 1998, 2001, 2002, 2004, 2005, 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 java.lang;
-
-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;
-
-/**
- * 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)
- */
-final class VMClassLoader
-{
-
-
- /** packages loaded by the bootstrap class loader */
- static final HashMap definedPackages = new HashMap();
-
- /** jars from property java.boot.class.path */
- static final HashMap bootjars = new HashMap();
-
-
- /**
- * Converts the array string of native package names to
- * Packages. The packages are then put into the
- * definedPackages hashMap
- */
- static
- {
- String[] packages = getBootPackages();
-
- if( packages != null)
- {
- String specName =
- SystemProperties.getProperty("java.specification.name");
- String vendor =
- SystemProperties.getProperty("java.specification.vendor");
- String version =
- SystemProperties.getProperty("java.specification.version");
-
- Package p;
-
- for(int i = 0; i < packages.length; i++)
- {
- p = new Package(packages[i],
- specName,
- vendor,
- version,
- "GNU Classpath",
- "GNU",
- Configuration.CLASSPATH_VERSION,
- null,
- null);
-
- definedPackages.put(packages[i], p);
- }
- }
- }
-
-
- /**
- * Helper to define a class using a string of bytes. This assumes that
- * the security checks have already been performed, if necessary.
- *
- * Implementations of this method are advised to consider the
- * situation where user code modifies the byte array after it has
- * been passed to defineClass. This can be handled by making a
- * private copy of the array, or arranging to only read any given
- * byte a single time.
- *
- * @param name the name to give the class, or null if unknown
- * @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 class that was defined
- * @throws ClassFormatError if data is not in proper classfile format
- */
- static final native Class defineClass(ClassLoader cl, String name,
- byte[] data, int offset, int len,
- ProtectionDomain pd)
- throws ClassFormatError;
-
- /**
- * Helper to resolve all references to other classes from this class.
- *
- * @param c the class to resolve
- */
- static final native void resolveClass(Class c);
-
- /**
- * Helper to load a class from the bootstrap class loader.
- *
- * @param name the class name to load
- * @param resolve whether to resolve it
- * @return the class, loaded by the bootstrap classloader or null
- * if the class wasn't found. Returning null is equivalent to throwing
- * a ClassNotFoundException (but a possible performance optimization).
- */
- static final native Class loadClass(String name, boolean resolve)
- throws ClassNotFoundException;
-
- /**
- * Helper to load a resource from the bootstrap class loader.
- *
- * @param name the resource to find
- * @return the URL to the resource
- */
- static URL getResource(String name)
- {
- Enumeration e = getResources(name);
- if (e.hasMoreElements())
- return (URL)e.nextElement();
- return null;
- }
- /**
- * Helper to get a list of resources from the bootstrap class loader.
- *
- * @param name the resource to find
- * @return an enumeration of resources
- */
- static Enumeration getResources(String name)
- {
-// StringTokenizer st = new StringTokenizer(
-// SystemProperties.getProperty("java.boot.class.path", "."),
-// File.pathSeparator);
-// Vector v = new Vector();
-// while (st.hasMoreTokens())
-// {
-// File file = new File(st.nextToken());
-// if (file.isDirectory())
-// {
-// try
-// {
-// File f = new File(file, name);
-// if (!f.exists()) continue;
-// v.add(new URL("file://" + f.getAbsolutePath()));
-// }
-// catch (MalformedURLException e)
-// {
-// throw new Error(e);
-// }
-// }
-// else if (file.isFile())
-// {
-// ZipFile zip;
-// synchronized(bootjars)
-// {
-// zip = (ZipFile) bootjars.get(file.getName());
-// }
-// if(zip == null)
-// {
-// try
-// {
-// zip = new ZipFile(file);
-// synchronized(bootjars)
-// {
-// bootjars.put(file.getName(), zip);
-// }
-// }
-// catch (IOException e)
-// {
-// continue;
-// }
-// }
-// String zname = name.startsWith("/") ? name.substring(1) : name;
-// if (zip.getEntry(zname) == null)
-// continue;
-// try
-// {
-// v.add(new URL("jar:file://"
-// + file.getAbsolutePath() + "!/" + zname));
-// }
-// catch (MalformedURLException e)
-// {
-// throw new Error(e);
-// }
-// }
-// }
-// return v.elements();
-// }
- Vector urls = nativeGetResources(name);
- Vector v = new Vector();
- for (Enumeration en = urls.elements(); en.hasMoreElements();)
- {
- try
- {
- v.add(new URL((String) en.nextElement()));
- }
- catch (MalformedURLException e)
- {
- throw new Error(e);
- }
- }
- return v.elements();
- }
-
- private native static final Vector nativeGetResources(String name);
-
-
- /**
- * Returns a String[] of native package names. The default
- * 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()
- {
- try
- {
- Enumeration indexListEnumeration = getResources("META-INF/INDEX.LIST");
- Set packageSet = new HashSet();
-
- while (indexListEnumeration.hasMoreElements())
- {
- try
- {
- String line;
- int lineToSkip = 3;
- BufferedReader reader = new BufferedReader(
- new InputStreamReader(
- ((URL) indexListEnumeration.nextElement()).openStream()));
- while ((line = reader.readLine()) != null)
- {
- if (lineToSkip == 0)
- {
- if (line.length() == 0)
- lineToSkip = 1;
- else
- packageSet.add(line.replace('/', '.'));
- }
- else
- lineToSkip--;
- }
- reader.close();
- }
- catch (IOException e)
- {
- // Empty catch block on purpose
- }
- }
- return (String[]) packageSet.toArray(new String[packageSet.size()]);
- }
- catch (Exception e)
- {
- return new String[0];
- }
- }
-
-
- /**
- * Helper to get a package from the bootstrap class loader.
- *
- * @param name the name to find
- * @return the named package, if it exists
- */
- static Package getPackage(String name)
- {
- return (Package)definedPackages.get(name);
- }
-
-
-
- /**
- * Helper to get all packages from the bootstrap class loader.
- *
- * @return all named packages, if any exist
- */
- static Package[] getPackages()
- {
- Package[] packages = new Package[definedPackages.size()];
- definedPackages.values().toArray(packages);
- return packages;
- }
-
- /**
- * Helper for java.lang.Integer, Byte, etc to get the TYPE class
- * at initialization time. The type code is one of the chars that
- * represents the primitive type as in JNI.
- *
- * <ul>
- * <li>'Z' - boolean</li>
- * <li>'B' - byte</li>
- * <li>'C' - char</li>
- * <li>'D' - double</li>
- * <li>'F' - float</li>
- * <li>'I' - int</li>
- * <li>'J' - long</li>
- * <li>'S' - short</li>
- * <li>'V' - void</li>
- * </ul>
- *
- * @param type the primitive type
- * @return a "bogus" class representing the primitive type
- */
- static final native Class getPrimitiveClass(char type);
-
- /**
- * The system default for assertion status. This is used for all system
- * classes (those with a null ClassLoader), as well as the initial value for
- * every ClassLoader's default assertion status.
- *
- * XXX - Not implemented yet; this requires native help.
- *
- * @return the system-wide default assertion status
- */
-// static final boolean defaultAssertionStatus()
-// {
-// return true;
-// }
- static native final boolean defaultAssertionStatus();
-
- /**
- * The system default for package assertion status. This is used for all
- * ClassLoader's packageAssertionStatus defaults. It must be a map of
- * package names to Boolean.TRUE or Boolean.FALSE, with the unnamed package
- * represented as a null key.
- *
- * XXX - Not implemented yet; this requires native help.
- *
- * @return a (read-only) map for the default packageAssertionStatus
- */
- static final Map packageAssertionStatus()
- {
- return new HashMap();
- }
-
- /**
- * The system default for class assertion status. This is used for all
- * ClassLoader's classAssertionStatus defaults. It must be a map of
- * class names to Boolean.TRUE or Boolean.FALSE
- *
- * XXX - Not implemented yet; this requires native help.
- *
- * @return a (read-only) map for the default classAssertionStatus
- */
- static final Map classAssertionStatus()
- {
- return new HashMap();
- }
-
- static ClassLoader getSystemClassLoader()
- {
- return ClassLoader.defaultGetSystemClassLoader();
- }
-
- /**
- * Find the class if this class loader previously defined this class
- * or if this class loader has been recorded as the initiating class loader
- * 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);
- }
- }
-}
+++ /dev/null
-/* VMString.java -- VM Specific String methods
- Copyright (C) 2003 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 java.lang;
-
-import java.lang.ref.WeakReference;
-import java.util.WeakHashMap;
-
-/*
- * This class is a reference version, mainly for compiling a class library
- * jar. It is likely that VM implementers replace this with their own
- * version that can communicate effectively with the VM.
- */
-
-/**
- * Code relocated from java.lang.String by
- * @author Dave Grove <groved@us.ibm.com>
- */
-final class VMString
-{
-
- /**
- * Holds the references for each intern()'d String. If all references to
- * the string disappear, and the VM properly supports weak references,
- * the String will be GC'd.
- */
-// private static final WeakHashMap internTable = new WeakHashMap();
-
- /**
- * Fetches this String from the intern hashtable. If two Strings are
- * considered equal, by the equals() method, then intern() will return the
- * same String instance. ie. if (s1.equals(s2)) then
- * (s1.intern() == s2.intern()). All string literals and string-valued
- * constant expressions are already interned.
- *
- * @param str the String to intern
- * @return the interned String
- */
-// static String intern(String str)
-// {
-// synchronized (internTable)
-// {
-// WeakReference ref = (WeakReference) internTable.get(str);
-// if (ref != null)
-// {
-// String s = (String) ref.get();
-// // If s is null, then no strong references exist to the String;
-// // the weak hash map will soon delete the key.
-// if (s != null)
-// return s;
-// }
-// internTable.put(str, new WeakReference(str));
-// }
-// return str;
-// }
-
- /**
- * this one is native in CACAO
- */
- static native String intern(String str);
-
-} // class VMString
+++ /dev/null
-/* VMThread -- VM interface for Thread of executable code
- Copyright (C) 2003, 2004, 2005, 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 java.lang;
-
-/**
- * VM interface for Thread of executable code. Holds VM dependent state.
- * It is deliberately package local and final and should only be accessed
- * by the Thread class.
- * <p>
- * This is the GNU Classpath reference implementation, it should be adapted
- * for a specific VM.
- * <p>
- * The following methods must be implemented:
- * <ul>
- * <li>native void start(long stacksize);
- * <li>native void interrupt();
- * <li>native boolean isInterrupted();
- * <li>native void suspend();
- * <li>native void resume();
- * <li>native void nativeSetPriority(int priority);
- * <li>native void nativeStop(Throwable t);
- * <li>native static Thread currentThread();
- * <li>static native void yield();
- * <li>static native boolean interrupted();
- * </ul>
- * All other methods may be implemented to make Thread handling more efficient
- * or to implement some optional (and sometimes deprecated) behaviour. Default
- * implementations are provided but it is highly recommended to optimize them
- * for a specific VM.
- *
- * @author Jeroen Frijters (jeroen@frijters.net)
- * @author Dalibor Topic (robilad@kaffe.org)
- */
-final class VMThread
-{
- /**
- * The Thread object that this VM state belongs to.
- * Used in currentThread() and start().
- * Note: when this thread dies, this reference is *not* cleared
- */
- volatile Thread thread;
-
- /**
- * Flag that is set when the thread runs, used by stop() to protect against
- * stop's getting lost.
- */
- private volatile boolean running;
-
- /**
- * VM private data.
- */
- private transient Object vmdata;
-
- /**
- * Private constructor, create VMThreads with the static create method.
- *
- * @param thread The Thread object that was just created.
- */
- private VMThread(Thread thread)
- {
- this.thread = thread;
- }
-
- /**
- * This method is the initial Java code that gets executed when a native
- * thread starts. It's job is to coordinate with the rest of the VMThread
- * logic and to start executing user code and afterwards handle clean up.
- */
- private void run()
- {
- try
- {
- try
- {
- running = true;
- synchronized(thread)
- {
- Throwable t = thread.stillborn;
- if(t != null)
- {
- thread.stillborn = null;
- throw t;
- }
- }
- thread.run();
- }
- catch(Throwable t)
- {
- try
- {
- Thread.UncaughtExceptionHandler handler;
- handler = thread.getUncaughtExceptionHandler();
- handler.uncaughtException(thread, t);
- }
- catch(Throwable ignore)
- {
- }
- }
- }
- finally
- {
- // Setting runnable to false is partial protection against stop
- // being called while we're cleaning up. To be safe all code in
- // VMThread be unstoppable.
- running = false;
- thread.die();
- synchronized(this)
- {
- // release the threads waiting to join us
- notifyAll();
- }
- }
- }
-
- /**
- * Creates a native Thread. This is called from the start method of Thread.
- * The Thread is started.
- *
- * @param thread The newly created Thread object
- * @param stacksize Indicates the requested stacksize. Normally zero,
- * non-zero values indicate requested stack size in bytes but it is up
- * to the specific VM implementation to interpret them and may be ignored.
- */
- static void create(Thread thread, long stacksize)
- {
- VMThread vmThread = new VMThread(thread);
- thread.vmThread = vmThread;
- vmThread.start(stacksize);
- }
-
- /**
- * Gets the name of the thread. Usually this is the name field of the
- * associated Thread object, but some implementation might choose to
- * return the name of the underlying platform thread.
- */
- String getName()
- {
- return thread.name;
- }
-
- /**
- * Set the name of the thread. Usually this sets the name field of the
- * associated Thread object, but some implementations might choose to
- * set the name of the underlying platform thread.
- * @param name The new name
- */
- void setName(String name)
- {
- thread.name = name;
- }
-
- /**
- * Set the thread priority field in the associated Thread object and
- * calls the native method to set the priority of the underlying
- * platform thread.
- * @param priority The new priority
- */
- void setPriority(int priority)
- {
- thread.priority = priority;
- nativeSetPriority(priority);
- }
-
- /**
- * Returns the priority. Usually this is the priority field from the
- * associated Thread object, but some implementation might choose to
- * return the priority of the underlying platform thread.
- * @return this Thread's priority
- */
- int getPriority()
- {
- return thread.priority;
- }
-
- /**
- * Returns true if the thread is a daemon thread. Usually this is the
- * daemon field from the associated Thread object, but some
- * implementation might choose to return the daemon state of the underlying
- * platform thread.
- * @return whether this is a daemon Thread or not
- */
- boolean isDaemon()
- {
- return thread.daemon;
- }
-
- /**
- * Returns the number of stack frames in this Thread.
- * Will only be called when when a previous call to suspend() returned true.
- *
- * @deprecated unsafe operation
- */
- native int countStackFrames();
-
- /**
- * Wait the specified amount of time for the Thread in question to die.
- *
- * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
- * not offer that fine a grain of timing resolution. Besides, there is
- * no guarantee that this thread can start up immediately when time expires,
- * because some other thread may be active. So don't expect real-time
- * performance.
- *
- * @param ms the number of milliseconds to wait, or 0 for forever
- * @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
- */
- synchronized void join(long ms, int ns) throws InterruptedException
- {
- // Round up
- ms += (ns != 0) ? 1 : 0;
-
- // 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.
- while(thread.vmThread != null)
- {
- // We use the VMThread object to wait on, because this is a private
- // object, so client code cannot call notify on us.
- wait(ms);
- if(ms != 0)
- {
- now = System.currentTimeMillis();
- ms = end - now;
- if(ms <= 0)
- {
- break;
- }
- }
- }
- }
-
- /**
- * Cause this Thread to stop abnormally and throw the specified exception.
- * If you stop a Thread that has not yet started, the stop is ignored
- * (contrary to what the JDK documentation says).
- * <b>WARNING</b>This bypasses Java security, and can throw a checked
- * exception which the call stack is unprepared to handle. Do not abuse
- * this power.
- *
- * <p>This is inherently unsafe, as it can interrupt synchronized blocks and
- * leave data in bad states.
- *
- * <p><b>NOTE</b> stop() should take care not to stop a thread if it is
- * executing code in this class.
- *
- * @param t the Throwable to throw when the Thread dies
- * @deprecated unsafe operation, try not to use
- */
- void stop(Throwable t)
- {
- // Note: we assume that we own the lock on thread
- // (i.e. that Thread.stop() is synchronized)
- if(running)
- nativeStop(t);
- else
- thread.stillborn = t;
- }
-
- /**
- * Create a native thread on the underlying platform and start it executing
- * on the run method of this object.
- * @param stacksize the requested size of the native thread stack
- */
- native void start(long stacksize);
-
- /**
- * Interrupt this thread.
- */
- native void interrupt();
-
- /**
- * Determine whether this Thread has been interrupted, but leave
- * the <i>interrupted status</i> alone in the process.
- *
- * @return whether the Thread has been interrupted
- */
- native boolean isInterrupted();
-
- /**
- * Suspend this Thread. It will not come back, ever, unless it is resumed.
- */
- native void suspend();
-
- /**
- * Resume this Thread. If the thread is not suspended, this method does
- * nothing.
- */
- native void resume();
-
- /**
- * Set the priority of the underlying platform thread.
- *
- * @param priority the new priority
- */
- native void nativeSetPriority(int priority);
-
- /**
- * Asynchronously throw the specified throwable in this Thread.
- *
- * @param t the exception to throw
- */
- native void nativeStop(Throwable t);
-
- /**
- * Return the Thread object associated with the currently executing
- * thread.
- *
- * @return the currently executing Thread
- */
- static native Thread currentThread();
-
- /**
- * Yield to another thread. The Thread will not lose any locks it holds
- * during this time. There are no guarantees which thread will be
- * next to run, and it could even be this one, but most VMs will choose
- * the highest priority thread that has been waiting longest.
- */
- static native void yield();
-
- /**
- * Suspend the current Thread's execution for the specified amount of
- * time. The Thread will not lose any locks it has during this time. There
- * are no guarantees which thread will be next to run, but most VMs will
- * choose the highest priority thread that has been waiting longest.
- *
- * <p>Note that 1,000,000 nanoseconds == 1 millisecond, but most VMs do
- * not offer that fine a grain of timing resolution. Besides, there is
- * no guarantee that this thread can start up immediately when time expires,
- * because some other thread may be active. So don't expect real-time
- * performance.
- *
- * @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 (or was) interrupted;
- * it's <i>interrupted status</i> will be cleared
- */
- static void sleep(long ms, int ns) throws InterruptedException
- {
- // 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 && ns == 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, ns);
- now = System.currentTimeMillis();
- if (now >= end)
- break;
- ms = end - now;
- ns = 0;
- }
- }
- }
-
- /**
- * Determine whether the current Thread has been interrupted, and clear
- * the <i>interrupted status</i> in the process.
- *
- * @return whether the current Thread has been interrupted
- */
- static native boolean interrupted();
-
- /**
- * Checks whether the current thread holds the monitor on a given object.
- * This allows you to do <code>assert Thread.holdsLock(obj)</code>.
- *
- * @param obj the object to check
- * @return true if the current thread is currently synchronized on obj
- * @throws NullPointerException if obj is null
- */
-// static boolean holdsLock(Object obj)
-// {
-// /* Use obj.notify to check if the current thread holds
-// * the monitor of the object.
-// * If it doesn't, notify will throw an exception.
-// */
-// try
-// {
-// obj.notify();
-// // okay, current thread holds lock
-// return true;
-// }
-// catch (IllegalMonitorStateException e)
-// {
-// // it doesn't hold the lock
-// return false;
-// }
-// }
- static native boolean holdsLock(Object obj);
-
- /**
- * Returns the current state of the thread.
- * The value must be one of "BLOCKED", "NEW",
- * "RUNNABLE", "TERMINATED", "TIMED_WAITING" or
- * "WAITING".
- *
- * @return a string corresponding to one of the
- * thread enumeration states specified above.
- */
- native String getState();
-
-}
+++ /dev/null
-/* java.lang.VMThrowable -- VM support methods for Throwable.
- Copyright (C) 1998, 1999, 2002 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;
-
-import gnu.classpath.Pointer;
-
-/**
- * VM dependant state and support methods for Throwable.
- * It is deliberately package local and final and should only be accessed
- * by the Throwable class.
- * <p>
- * This is the GNU Classpath reference implementation, it should be adapted
- * for a specific VM. The reference implementation does nothing.
- *
- * @author Mark Wielaard (mark@klomp.org)
- */
-final class VMThrowable
-{
- /* IMPORTANT: the rawdata field is not a java object */
- private final Pointer vmData;
-
- /**
- * VM private data.
- */
- private transient Object vmdata;
-
- /**
- * Private contructor, create VMThrowables with fillInStackTrace();
- */
-// private VMThrowable() { }
- private VMThrowable()
- {
- vmData = null;
- }
-
- /**
- * Fill in the stack trace with the current execution stack.
- * Called by <code>Throwable.fillInStackTrace()</code> to get the state of
- * the VM. Can return null when the VM does not support caputing the VM
- * execution state.
- *
- * @return a new VMThrowable containing the current execution stack trace.
- * @see Throwable#fillInStackTrace()
- */
- static native VMThrowable fillInStackTrace(Throwable t);
-
- /**
- * Returns an <code>StackTraceElement</code> array based on the execution
- * state of the VM as captured by <code>fillInStackTrace</code>.
- * Called by <code>Throwable.getStackTrace()</code>.
- *
- * @return a non-null but possible zero length array of StackTraceElement.
- * @see Throwable#getStackTrace()
- */
- native StackTraceElement[] getStackTrace(Throwable t);
-}
+++ /dev/null
-/* VMAccessController.java -- VM-specific access controller methods.
- 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
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-This program 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 this program; 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.security;
-
-import java.util.HashSet;
-import java.util.LinkedList;
-
-final class VMAccessController
-{
-
- // Fields.
- // -------------------------------------------------------------------------
-
- /**
- * This is a per-thread stack of AccessControlContext objects (which can
- * be null) for each call to AccessController.doPrivileged in each thread's
- * call stack. We use this to remember which context object corresponds to
- * which call.
- */
- private static final ThreadLocal contexts = new ThreadLocal();
-
- /**
- * This is a Boolean that, if set, tells getContext that it has already
- * been called once, allowing us to handle recursive permission checks
- * caused by methods getContext calls.
- */
- private static final ThreadLocal inGetContext = new ThreadLocal();
-
- /**
- * And we return this all-permissive context to ensure that privileged
- * methods called from getContext succeed.
- */
- private static final AccessControlContext DEFAULT_CONTEXT;
- static
- {
- CodeSource source = new CodeSource(null, null);
- Permissions permissions = new Permissions();
- permissions.add(new AllPermission());
- ProtectionDomain[] domain = new ProtectionDomain[] {
- new ProtectionDomain(source, permissions)
- };
- DEFAULT_CONTEXT = new AccessControlContext(domain);
- }
-
- private static final boolean DEBUG = gnu.classpath.Configuration.DEBUG;
- private static void debug(String msg)
- {
- System.err.print(">>> VMAccessController: ");
- System.err.println(msg);
- }
-
- // Constructors.
- // -------------------------------------------------------------------------
-
- private VMAccessController() { }
-
- // Class methods.
- // -------------------------------------------------------------------------
-
- /**
- * Relate a class (which should be an instance of {@link PrivilegedAction}
- * with an access control context. This method is used by {@link
- * AccessController#doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)}
- * to set up the context that will be returned by {@link #getContext()}.
- * This method relates the class to the current thread, so contexts
- * pushed from one thread will not be available to another.
- *
- * @param acc The access control context.
- */
- static void pushContext (AccessControlContext acc)
- {
- if (DEBUG)
- debug("pushing " + acc);
- LinkedList stack = (LinkedList) contexts.get();
- if (stack == null)
- {
- if (DEBUG)
- debug("no stack... creating ");
- stack = new LinkedList();
- contexts.set(stack);
- }
- stack.addFirst(acc);
- }
-
- /**
- * Removes the relation of a class to an {@link AccessControlContext}.
- * This method is used by {@link AccessController} when exiting from a
- * call to {@link
- * AccessController#doPrivileged(java.security.PrivilegedAction,java.security.AccessControlContext)}.
- */
- static void popContext()
- {
- if (DEBUG)
- debug("popping context");
-
- // Stack should never be null, nor should it be empty, if this method
- // and its counterpart has been called properly.
- LinkedList stack = (LinkedList) contexts.get();
- if (stack != null)
- {
- stack.removeFirst();
- if (stack.isEmpty())
- contexts.set(null);
- }
- else if (DEBUG)
- {
- debug("no stack during pop?????");
- }
- }
-
- /**
- * Examine the method stack of the currently running thread, and create
- * an {@link AccessControlContext} filled in with the appropriate {@link
- * ProtectionDomain} objects given this stack.
- *
- * @return The context.
- */
- static AccessControlContext getContext()
- {
- // If we are already in getContext, but called a method that needs
- // a permission check, return the all-permissive context so methods
- // called from here succeed.
- //
- // XXX is this necessary? We should verify if there are any calls in
- // the stack below this method that require permission checks.
- Boolean inCall = (Boolean) inGetContext.get();
- if (inCall != null && inCall.booleanValue())
- {
- if (DEBUG)
- debug("already in getContext");
- return DEFAULT_CONTEXT;
- }
-
- inGetContext.set(Boolean.TRUE);
-
- Object[][] stack = getStack();
- Class[] classes = (Class[]) stack[0];
- String[] methods = (String[]) stack[1];
-
- if (DEBUG)
- debug("got trace of length " + classes.length);
-
- HashSet domains = new HashSet();
- HashSet seenDomains = new HashSet();
- AccessControlContext context = null;
- int privileged = 0;
-
- // We walk down the stack, adding each ProtectionDomain for each
- // class in the call stack. If we reach a call to doPrivileged,
- // we don't add any more stack frames. We skip the first three stack
- // frames, since they comprise the calls to getStack, getContext,
- // and AccessController.getContext.
- for (int i = 3; i < classes.length && privileged < 2; i++)
- {
- Class clazz = classes[i];
- String method = methods[i];
-
- if (DEBUG)
- {
- debug("checking " + clazz + "." + method);
- // subject to getClassLoader RuntimePermission
- debug("loader = " + clazz.getClassLoader());
- }
-
- // If the previous frame was a call to doPrivileged, then this is
- // the last frame we look at.
- if (privileged == 1)
- privileged = 2;
-
- if (clazz.equals (AccessController.class)
- && method.equals ("doPrivileged"))
- {
- // If there was a call to doPrivileged with a supplied context,
- // return that context. If using JAAS doAs*, it should be
- // a context with a SubjectDomainCombiner
- LinkedList l = (LinkedList) contexts.get();
- if (l != null)
- context = (AccessControlContext) l.getFirst();
- privileged = 1;
- }
-
- // subject to getProtectionDomain RuntimePermission
- ProtectionDomain domain = clazz.getProtectionDomain();
-
- if (domain == null)
- continue;
- if (seenDomains.contains(domain))
- continue;
- seenDomains.add(domain);
-
- // Create a static snapshot of this domain, which may change over time
- // if the current policy changes.
- domains.add(new ProtectionDomain(domain.getCodeSource(),
- domain.getPermissions()));
- }
-
- if (DEBUG)
- debug("created domains: " + domains);
-
- ProtectionDomain[] result = (ProtectionDomain[])
- domains.toArray(new ProtectionDomain[domains.size()]);
-
- if (context != null)
- {
- DomainCombiner dc = context.getDomainCombiner ();
- // If the supplied context had no explicit DomainCombiner, use
- // our private version, which computes the intersection of the
- // context's domains with the derived set.
- if (dc == null)
- context = new AccessControlContext
- (IntersectingDomainCombiner.SINGLETON.combine
- (result, context.getProtectionDomains ()));
- // Use the supplied DomainCombiner. This should be secure,
- // because only trusted code may create an
- // AccessControlContext with a custom DomainCombiner.
- else
- context = new AccessControlContext (result, context, dc);
- }
- // No context was supplied. Return the derived one.
- else
- context = new AccessControlContext (result);
-
- inGetContext.set(Boolean.FALSE);
- return context;
- }
-
- /**
- * Returns a snapshot of the current call stack as a pair of arrays:
- * the first an array of classes in the call stack, the second an array
- * of strings containing the method names in the call stack. The two
- * arrays match up, meaning that method <i>i</i> is declared in class
- * <i>i</i>. The arrays are clean; it will only contain Java methods,
- * and no element of the list should be null.
- *
- * <p>The default implementation returns an empty stack, which will be
- * interpreted as having no permissions whatsoever.
- *
- * @return A pair of arrays describing the current call stack. The first
- * element is an array of Class objects, and the second is an array
- * of Strings comprising the method names.
- */
-// private static Object[][] getStack()
-// {
-// return new Object[][] { new Class[0], new String[0] };
-// }
- private native static Object[][] getStack();
-}