From 554fd8c5195424bdbcabf5de30fdc183aba391bd Mon Sep 17 00:00:00 2001 From: upstream source tree Date: Sun, 15 Mar 2015 20:14:05 -0400 Subject: obtained gcc-4.6.4.tar.bz2 from upstream website; verified gcc-4.6.4.tar.bz2.sig; imported gcc-4.6.4 source tree from verified upstream tarball. downloading a git-generated archive based on the 'upstream' tag should provide you with a source tree that is binary identical to the one extracted from the above tarball. if you have obtained the source via the command 'git clone', however, do note that line-endings of files in your working directory might differ from line-endings of the respective files in the upstream repository. --- .../classpath/vm/reference/java/lang/VMClass.java | 469 ++++++++++++++++++ .../vm/reference/java/lang/VMClassLoader.java | 431 ++++++++++++++++ .../vm/reference/java/lang/VMCompiler.java | 112 +++++ .../classpath/vm/reference/java/lang/VMDouble.java | 115 +++++ .../classpath/vm/reference/java/lang/VMFloat.java | 118 +++++ .../classpath/vm/reference/java/lang/VMMath.java | 493 ++++++++++++++++++ .../classpath/vm/reference/java/lang/VMObject.java | 105 ++++ .../vm/reference/java/lang/VMProcess.java | 402 +++++++++++++++ .../vm/reference/java/lang/VMRuntime.java | 192 +++++++ .../classpath/vm/reference/java/lang/VMString.java | 91 ++++ .../classpath/vm/reference/java/lang/VMSystem.java | 220 +++++++++ .../classpath/vm/reference/java/lang/VMThread.java | 461 +++++++++++++++++ .../vm/reference/java/lang/VMThrowable.java | 82 +++ .../java/lang/management/VMManagementFactory.java | 75 +++ .../vm/reference/java/lang/reflect/VMArray.java | 65 +++ .../reference/java/lang/reflect/VMConstructor.java | 169 +++++++ .../vm/reference/java/lang/reflect/VMField.java | 549 +++++++++++++++++++++ .../vm/reference/java/lang/reflect/VMMethod.java | 208 ++++++++ .../vm/reference/java/lang/reflect/VMProxy.java | 135 +++++ 19 files changed, 4492 insertions(+) create mode 100644 libjava/classpath/vm/reference/java/lang/VMClass.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMClassLoader.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMCompiler.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMDouble.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMFloat.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMMath.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMObject.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMProcess.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMRuntime.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMString.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMSystem.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMThread.java create mode 100644 libjava/classpath/vm/reference/java/lang/VMThrowable.java create mode 100644 libjava/classpath/vm/reference/java/lang/management/VMManagementFactory.java create mode 100644 libjava/classpath/vm/reference/java/lang/reflect/VMArray.java create mode 100644 libjava/classpath/vm/reference/java/lang/reflect/VMConstructor.java create mode 100644 libjava/classpath/vm/reference/java/lang/reflect/VMField.java create mode 100644 libjava/classpath/vm/reference/java/lang/reflect/VMMethod.java create mode 100644 libjava/classpath/vm/reference/java/lang/reflect/VMProxy.java (limited to 'libjava/classpath/vm/reference/java/lang') diff --git a/libjava/classpath/vm/reference/java/lang/VMClass.java b/libjava/classpath/vm/reference/java/lang/VMClass.java new file mode 100644 index 000000000..a0091c073 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMClass.java @@ -0,0 +1,469 @@ +/* VMClass.java -- VM Specific Class methods + 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; + +import java.lang.annotation.Annotation; +import java.lang.reflect.Array; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.lang.reflect.Modifier; + +/* + * 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. + */ + +/** + * + * @author Etienne Gagnon (etienne.gagnon@uqam.ca) + * @author Archie Cobbs (archie@dellroad.org) + * @author C. Brian Jones (cbj@gnu.org) + * @author Tom Tromey (tromey@cygnus.com) + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + */ +final class VMClass +{ + + // Only static methods. Cannot be instantiated. + private VMClass() + { + } + + /** + * Discover whether an Object is an instance of this Class. Think of it + * as almost like o instanceof (this class). + * + * @param klass the Class object that's calling us + * @param o the Object to check + * @return whether o is an instance of this class + * @since 1.1 + */ + static native boolean isInstance(Class klass, Object o); + + /** + * Discover whether an instance of the Class parameter would be an + * instance of this Class as well. Think of doing + * isInstance(c.newInstance()) or even + * c.newInstance() instanceof (this class). While this + * checks widening conversions for objects, it must be exact for primitive + * types. + * + * @param klass the Class object that's calling us + * @param c the class to check + * @return whether an instance of c would be an instance of this class + * as well + * @throws NullPointerException if c is null + * @since 1.1 + */ + static native boolean isAssignableFrom(Class klass, Class c); + + /** + * Check whether this class is an interface or not. Array types are not + * interfaces. + * + * @param klass the Class object that's calling us + * @return whether this class is an interface or not + */ + static native boolean isInterface(Class klass); + + /** + * Return whether this class is a primitive type. A primitive type class + * is a class representing a kind of "placeholder" for the various + * primitive types, or void. You can access the various primitive type + * classes through java.lang.Boolean.TYPE, java.lang.Integer.TYPE, etc., + * or through boolean.class, int.class, etc. + * + * @param klass the Class object that's calling us + * @return whether this class is a primitive type + * @see Boolean#TYPE + * @see Byte#TYPE + * @see Character#TYPE + * @see Short#TYPE + * @see Integer#TYPE + * @see Long#TYPE + * @see Float#TYPE + * @see Double#TYPE + * @see Void#TYPE + * @since 1.1 + */ + static native boolean isPrimitive(Class klass); + + /** + * Get the name of this class, separated by dots for package separators. + * Primitive types and arrays are encoded as: + *
+   * boolean             Z
+   * byte                B
+   * char                C
+   * short               S
+   * int                 I
+   * long                J
+   * float               F
+   * double              D
+   * void                V
+   * array type          [element type
+   * class or interface, alone: <dotted name>
+   * class or interface, as element type: L<dotted name>;
+   *
+   * @param klass the Class object that's calling us
+   * @return the name of this class
+   */
+  static native String getName(Class klass);
+
+  /**
+   * Get the direct superclass of this class.  If this is an interface,
+   * Object, a primitive type, or void, it will return null. If this is an
+   * array type, it will return Object.
+   *
+   * @param klass the Class object that's calling us
+   * @return the direct superclass of this class
+   */
+  static native Class getSuperclass(Class klass);
+
+  /**
+   * Get the interfaces this class directly implements, in the
+   * order that they were declared. This returns an empty array, not null,
+   * for Object, primitives, void, and classes or interfaces with no direct
+   * superinterface. Array types return Cloneable and Serializable.
+   *
+   * @param klass the Class object that's calling us
+   * @return the interfaces this class directly implements
+   */
+  static native Class[] getInterfaces(Class klass);
+
+  /**
+   * If this is an array, get the Class representing the type of array.
+   * Examples: "[[Ljava.lang.String;" would return "[Ljava.lang.String;", and
+   * calling getComponentType on that would give "java.lang.String".  If
+   * this is not an array, returns null.
+   *
+   * @param klass the Class object that's calling us
+   * @return the array type of this class, or null
+   * @see Array
+   * @since 1.1
+   */
+  static native Class getComponentType(Class klass);
+
+  /**
+   * Get the modifiers of this class.  These can be decoded using Modifier,
+   * and is limited to one of public, protected, or private, and any of
+   * final, static, abstract, or interface. An array class has the same
+   * public, protected, or private modifier as its component type, and is
+   * marked final but not an interface. Primitive types and void are marked
+   * public and final, but not an interface.
+   *
+   * @param klass the Class object that's calling us
+   * @param ignoreInnerClassesAttrib if set, return the real modifiers, not
+   * the ones specified in the InnerClasses attribute.
+   * @return the modifiers of this class
+   * @see Modifier
+   * @since 1.1
+   */
+  static native int getModifiers(Class klass, boolean ignoreInnerClassesAttrib);
+
+  /**
+   * If this is a nested or inner class, return the class that declared it.
+   * If not, return null.
+   *
+   * @param klass the Class object that's calling us
+   * @return the declaring class of this class
+   * @since 1.1
+   */
+  static native Class getDeclaringClass(Class klass);
+
+  /**
+   * Like getDeclaredClasses() but without the security checks.
+   *
+   * @param klass the Class object that's calling us
+   * @param publicOnly Only public classes should be returned
+   */
+  static native Class[] getDeclaredClasses(Class klass, boolean publicOnly);
+
+  /**
+   * Like getDeclaredFields() but without the security checks.
+   *
+   * @param klass the Class object that's calling us
+   * @param publicOnly Only public fields should be returned
+   */
+  static native Field[] getDeclaredFields(Class klass, boolean publicOnly);
+
+  /**
+   * Like getDeclaredMethods() but without the security checks.
+   *
+   * @param klass the Class object that's calling us
+   * @param publicOnly Only public methods should be returned
+   */
+  static native Method[] getDeclaredMethods(Class klass, boolean publicOnly);
+
+  /**
+   * Like getDeclaredConstructors() but without
+   * the security checks.
+   *
+   * @param klass the Class object that's calling us
+   * @param publicOnly Only public constructors should be returned
+   */
+  static native Constructor[] getDeclaredConstructors(Class klass, boolean publicOnly);
+
+  /**
+   * Return the class loader of this class.
+   *
+   * @param klass the Class object that's calling us
+   * @return the class loader
+   */
+  static native ClassLoader getClassLoader(Class klass);
+
+  /**
+   * Load the requested class and record the specified loader as the
+   * initiating class loader.
+   *
+   * @param name the name of the class to find
+   * @param initialize should the class initializer be run?
+   * @param loader the class loader to use (or null for the bootstrap loader)
+   * @return the Class object representing the class or null for noop
+   * @throws ClassNotFoundException if the class was not found by the
+   *         class loader
+   * @throws LinkageError if linking the class fails
+   * @throws ExceptionInInitializerError if the class loads, but an exception
+   *         occurs during initialization
+   */
+  static native Class forName(String name, boolean initialize,
+                              ClassLoader loader)
+    throws ClassNotFoundException;
+
+  /**
+   * Return whether this class is an array type.
+   *
+   * @param klass the Class object that's calling us
+   * @return true if this class is an array type
+   * operation
+   */
+  static native boolean isArray(Class klass);
+
+  /**
+   * Throw a checked exception without declaring it.
+   */
+  static native void throwException(Throwable t);
+
+  /**
+   * Returns the simple name for the specified class, as used in the source
+   * code.  For normal classes, this is the content returned by
+   * getName() which follows the last ".".  Anonymous
+   * classes have no name, and so the result of calling this method is
+   * "".  The simple name of an array consists of the simple name of
+   * its component type, followed by "[]".  Thus, an array with the
+   * component type of an anonymous class has a simple name of simply
+   * "[]".
+   *
+   * @param klass the class whose simple name should be returned.
+   * @return the simple name for this class.
+   */
+  static String getSimpleName(Class klass)
+  {
+    if (isAnonymousClass(klass))
+      return "";
+    if (isArray(klass))
+      {
+        return getComponentType(klass).getSimpleName() + "[]";
+      }
+    String fullName = getName(klass);
+    int pos = fullName.lastIndexOf("$");
+    if (pos == -1)
+      pos = 0;
+    else
+      {
+        ++pos;
+        while (Character.isDigit(fullName.charAt(pos)))
+          ++pos;
+      }
+    int packagePos = fullName.lastIndexOf(".", pos);
+    if (packagePos == -1)
+      return fullName.substring(pos);
+    else
+      return fullName.substring(packagePos + 1);
+  }
+
+  /**
+   * Returns all annotations directly defined by the specified class.  If
+   * there are no annotations associated with this class, then a zero-length
+   * array will be returned.  The returned array may be modified by the client
+   * code, but this will have no effect on the annotation content of this
+   * class, and hence no effect on the return value of this method for
+   * future callers.
+   *
+   * @param klass the class whose annotations should be returned.
+   * @return the annotations directly defined by the specified class.
+   * @since 1.5
+   */
+  static native Annotation[] getDeclaredAnnotations(Class klass);
+
+  /**
+   * 

+ * Returns the canonical name of the specified class, as defined by section + * 6.7 of the Java language specification. Each package, top-level class, + * top-level interface and primitive type has a canonical name. A member + * class has a canonical name, if its parent class has one. Likewise, + * an array type has a canonical name, if its component type does. + * Local or anonymous classes do not have canonical names. + *

+ *

+ * The canonical name for top-level classes, top-level interfaces and + * primitive types is always the same as the fully-qualified name. + * For array types, the canonical name is the canonical name of its + * component type with `[]' appended. + *

+ *

+ * The canonical name of a member class always refers to the place where + * the class was defined, and is composed of the canonical name of the + * defining class and the simple name of the member class, joined by `.'. + * For example, if a Person class has an inner class, + * M, then both its fully-qualified name and canonical name + * is Person.M. A subclass, Staff, of + * Person refers to the same inner class by the fully-qualified + * name of Staff.M, but its canonical name is still + * Person.M. + *

+ *

+ * Where no canonical name is present, null is returned. + *

+ * + * @param klass the class whose canonical name should be retrieved. + * @return the canonical name of the class, or null if the + * class doesn't have a canonical name. + * @since 1.5 + */ + static String getCanonicalName(Class klass) + { + if (isLocalClass(klass) || isAnonymousClass(klass)) + return null; + if (isArray(klass)) + { + String componentName = getComponentType(klass).getCanonicalName(); + if (componentName != null) + return componentName + "[]"; + } + if (isMemberClass(klass)) + { + String memberName = getDeclaringClass(klass).getCanonicalName(); + if (memberName != null) + return memberName + "." + getSimpleName(klass); + else + return memberName; + } + return getName(klass); + } + + /** + * Returns the class which immediately encloses the specified class. If + * the class is a top-level class, this method returns null. + * + * @param klass the class whose enclosing class should be returned. + * @return the immediate enclosing class, or null if this is + * a top-level class. + * @since 1.5 + */ + static native Class getEnclosingClass(Class klass); + + /** + * Returns the constructor which immediately encloses the specified class. + * If the class is a top-level class, or a local or anonymous class + * immediately enclosed by a type definition, instance initializer + * or static initializer, then null is returned. + * + * @param klass the class whose enclosing constructor should be returned. + * @return the immediate enclosing constructor if the specified class is + * declared within a constructor. Otherwise, null + * is returned. + * @since 1.5 + */ + static native Constructor getEnclosingConstructor(Class klass); + + /** + * Returns the method which immediately encloses the specified class. If + * the class is a top-level class, or a local or anonymous class + * immediately enclosed by a type definition, instance initializer + * or static initializer, then null is returned. + * + * @param klass the class whose enclosing method should be returned. + * @return the immediate enclosing method if the specified class is + * declared within a method. Otherwise, null + * is returned. + * @since 1.5 + */ + static native Method getEnclosingMethod(Class klass); + + /** + * Returns the class signature as specified in Class File Format + * chapter in the VM specification, or null if the class is not + * generic. + * + * @param klass the klass to test. + * @return a ClassSignature string. + * @since 1.5 + */ + static native String getClassSignature(Class klass); + + /** + * Returns true if the specified class represents an anonymous class. + * + * @param klass the klass to test. + * @return true if the specified class represents an anonymous class. + * @since 1.5 + */ + static native boolean isAnonymousClass(Class klass); + + /** + * Returns true if the specified class represents an local class. + * + * @param klass the klass to test. + * @return true if the specified class represents an local class. + * @since 1.5 + */ + static native boolean isLocalClass(Class klass); + + /** + * Returns true if the specified class represents an member class. + * + * @param klass the klass to test. + * @return true if the specified class represents an member class. + * @since 1.5 + */ + static native boolean isMemberClass(Class klass); + +} // class VMClass diff --git a/libjava/classpath/vm/reference/java/lang/VMClassLoader.java b/libjava/classpath/vm/reference/java/lang/VMClassLoader.java new file mode 100644 index 000000000..c1d462588 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMClassLoader.java @@ -0,0 +1,431 @@ +/* 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(); + } + + + /** + * 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() + { + URL indexList = getResource("META-INF/INDEX.LIST"); + if (indexList != null) + { + try + { + Set packageSet = new HashSet(); + String line; + int lineToSkip = 3; + BufferedReader reader = new BufferedReader( + new InputStreamReader( + indexList.openStream())); + while ((line = reader.readLine()) != null) + { + if (lineToSkip == 0) + { + if (line.length() == 0) + lineToSkip = 1; + else + packageSet.add(line.replace('/', '.')); + } + else + lineToSkip--; + } + reader.close(); + return (String[]) packageSet.toArray(new String[packageSet.size()]); + } + catch (IOException e) + { + return new String[0]; + } + } + else + return new String[0]; + } + + + /** + * 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. + * + * + * + * @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; + } + + /** + * 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 + * InstrumentationImpl object. VM implementors would + * have to redefine this method if they provide their own implementation + * of the Instrumentation 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); + String jvmName = name.replace('.', '/'); + modifiedData = + ((InstrumentationImpl)instrumenter).callTransformers(loader, jvmName, + null, pd, modifiedData); + + return defineClass(loader, name, modifiedData, 0, modifiedData.length, + pd); + } + else + { + return defineClass(loader, name, data, offset, len, pd); + } + } +} diff --git a/libjava/classpath/vm/reference/java/lang/VMCompiler.java b/libjava/classpath/vm/reference/java/lang/VMCompiler.java new file mode 100644 index 000000000..fe7400756 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMCompiler.java @@ -0,0 +1,112 @@ +/* VMClassLoader.java -- Reference implementation of compiler interface + 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 java.lang; + +/** + * This class is just a per-VM reflection of java.lang.Compiler. + * All methods are defined identically. + */ +final class VMCompiler +{ + /** + * Don't allow new `Compiler's to be made. + */ + private VMCompiler() + { + } + + /** + * Compile the class named by oneClass. + * + * @param oneClass the class to compile + * @return false if no compiler is available or + * compilation failed, true if compilation succeeded + * @throws NullPointerException if oneClass is null + */ + public static boolean compileClass(Class oneClass) + { + // Never succeed. + return false; + } + + /** + * Compile the classes whose name matches classNames. + * + * @param classNames the name of classes to compile + * @return false if no compiler is available or + * compilation failed, true if compilation succeeded + * @throws NullPointerException if classNames is null + */ + public static boolean compileClasses(String classNames) + { + // Note the incredibly lame interface. Always fail. + return false; + } + + /** + * This method examines the argument and performs an operation + * according to the compilers documentation. No specific operation + * is required. + * + * @param arg a compiler-specific argument + * @return a compiler-specific value, including null + * @throws NullPointerException if the compiler doesn't like a null arg + */ + public static Object command(Object arg) + { + // Our implementation defines this to a no-op. + return null; + } + + /** + * Calling Compiler.enable() will cause the compiler + * to resume operation if it was previously disabled; provided that a + * compiler even exists. + */ + public static void enable() + { + } + + /** + * Calling Compiler.disable() will cause the compiler + * to be suspended; provided that a compiler even exists. + */ + public static void disable() + { + } +} diff --git a/libjava/classpath/vm/reference/java/lang/VMDouble.java b/libjava/classpath/vm/reference/java/lang/VMDouble.java new file mode 100644 index 000000000..8e523cd2e --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMDouble.java @@ -0,0 +1,115 @@ +/* VMDouble.java -- VM Specific Double methods + Copyright (C) 2003, 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 java.lang; + +import gnu.classpath.Configuration; + +/* + * 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.Double by + * @author Dave Grove (groved@us.ibm.com) + */ +final class VMDouble +{ + + /** + * Load native routines necessary for this class. + */ + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javalang"); + } + + initIDs(); + } + + /** + * Convert the double to the IEEE 754 floating-point "double format" bit + * layout. Bit 63 (the most significant) is the sign bit, bits 62-52 + * (masked by 0x7ff0000000000000L) represent the exponent, and bits 51-0 + * (masked by 0x000fffffffffffffL) are the mantissa. This function + * leaves NaN alone, rather than collapsing to a canonical value. The + * result of this function can be used as the argument to + * Double.longBitsToDouble(long) to obtain the original + * double value. + * + * @param value the double to convert + * @return the bits of the double + * @see #longBitsToDouble(long) + */ + public static native long doubleToRawLongBits(double value); + + /** + * Convert the argument in IEEE 754 floating-point "double format" bit + * layout to the corresponding float. Bit 63 (the most significant) is the + * sign bit, bits 62-52 (masked by 0x7ff0000000000000L) represent the + * exponent, and bits 51-0 (masked by 0x000fffffffffffffL) are the mantissa. + * This function leaves NaN alone, so that you can recover the bit pattern + * with Double.doubleToRawLongBits(double). + * + * @param bits the bits to convert + * @return the double represented by the bits + * @see #doubleToLongBits(double) + * @see #doubleToRawLongBits(double) + */ + public static native double longBitsToDouble(long bits); + + /** + * Helper method to convert to string. + * + * @param d the double to convert + * @param isFloat true if the conversion is requested by Float (results in + * fewer digits) + */ + public static native String toString(double d, boolean isFloat); + + /** + * Initialize JNI cache. This method is called only by the + * static initializer when using JNI. + */ + public static native void initIDs(); + + public static native double parseDouble(String str); +} diff --git a/libjava/classpath/vm/reference/java/lang/VMFloat.java b/libjava/classpath/vm/reference/java/lang/VMFloat.java new file mode 100644 index 000000000..ba523d697 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMFloat.java @@ -0,0 +1,118 @@ +/* VMFloat.java -- VM Specific Float 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 gnu.classpath.Configuration; + +/* + * 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.Float by + * @author Dave Grove + */ +final class VMFloat +{ + + /** + * Load native routines necessary for this class. + */ + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javalang"); + } + } + + /** + * Convert the float to the IEEE 754 floating-point "single format" bit + * layout. Bit 31 (the most significant) is the sign bit, bits 30-23 + * (masked by 0x7f800000) represent the exponent, and bits 22-0 + * (masked by 0x007fffff) are the mantissa. This function leaves NaN alone, + * rather than collapsing to a canonical value. The result of this function + * can be used as the argument to Float.intBitsToFloat(int) to + * obtain the original float value. + * + * @param value the float to convert + * @return the bits of the float + * @see #intBitsToFloat(int) + */ + static native int floatToRawIntBits(float value); + + /** + * Convert the argument in IEEE 754 floating-point "single format" bit + * layout to the corresponding float. Bit 31 (the most significant) is the + * sign bit, bits 30-23 (masked by 0x7f800000) represent the exponent, and + * bits 22-0 (masked by 0x007fffff) are the mantissa. This function leaves + * NaN alone, so that you can recover the bit pattern with + * Float.floatToRawIntBits(float). + * + * @param bits the bits to convert + * @return the float represented by the bits + * @see #floatToIntBits(float) + * @see #floatToRawIntBits(float) + */ + static native float intBitsToFloat(int bits); + + /** + * @param f the float to convert + * @return the String representing the float + */ + static String toString(float f) + { + return VMDouble.toString(f, true); + } + + /** + * @param str the String to convert + * @return the float value of s + * @throws NumberFormatException if str cannot be parsed as a + * float + * @throws NullPointerException if str is null + */ + static float parseFloat(String str) + { + // XXX Rounding parseDouble() causes some errors greater than 1 ulp from + // the infinitely precise decimal. + return (float) Double.parseDouble(str); + } +} // class VMFloat diff --git a/libjava/classpath/vm/reference/java/lang/VMMath.java b/libjava/classpath/vm/reference/java/lang/VMMath.java new file mode 100644 index 000000000..dc5fd4207 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMMath.java @@ -0,0 +1,493 @@ +/* VMMath.java -- Common mathematical functions. + Copyright (C) 2006 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang; + +import gnu.classpath.Configuration; + +class VMMath +{ + + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javalang"); + } + } + + /** + * The trigonometric function sin. The sine of NaN or infinity is + * NaN, and the sine of 0 retains its sign. This is accurate within 1 ulp, + * and is semi-monotonic. + * + * @param a the angle (in radians) + * @return sin(a) + */ + public static native double sin(double a); + + /** + * The trigonometric function cos. The cosine of NaN or infinity is + * NaN. This is accurate within 1 ulp, and is semi-monotonic. + * + * @param a the angle (in radians) + * @return cos(a) + */ + public static native double cos(double a); + + /** + * The trigonometric function tan. The tangent of NaN or infinity + * is NaN, and the tangent of 0 retains its sign. This is accurate within 1 + * ulp, and is semi-monotonic. + * + * @param a the angle (in radians) + * @return tan(a) + */ + public static native double tan(double a); + + /** + * The trigonometric function arcsin. The range of angles returned + * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN or + * its absolute value is beyond 1, the result is NaN; and the arcsine of + * 0 retains its sign. This is accurate within 1 ulp, and is semi-monotonic. + * + * @param a the sin to turn back into an angle + * @return arcsin(a) + */ + public static native double asin(double a); + + /** + * The trigonometric function arccos. The range of angles returned + * is 0 to pi radians (0 to 180 degrees). If the argument is NaN or + * its absolute value is beyond 1, the result is NaN. This is accurate + * within 1 ulp, and is semi-monotonic. + * + * @param a the cos to turn back into an angle + * @return arccos(a) + */ + public static native double acos(double a); + + /** + * The trigonometric function arcsin. The range of angles returned + * is -pi/2 to pi/2 radians (-90 to 90 degrees). If the argument is NaN, the + * result is NaN; and the arctangent of 0 retains its sign. This is accurate + * within 1 ulp, and is semi-monotonic. + * + * @param a the tan to turn back into an angle + * @return arcsin(a) + * @see #atan2(double, double) + */ + public static native double atan(double a); + + /** + * A special version of the trigonometric function arctan, for + * converting rectangular coordinates (x, y) to polar + * (r, theta). This computes the arctangent of x/y in the range + * of -pi to pi radians (-180 to 180 degrees). Special cases:
    + *
  • If either argument is NaN, the result is NaN.
  • + *
  • If the first argument is positive zero and the second argument is + * positive, or the first argument is positive and finite and the second + * argument is positive infinity, then the result is positive zero.
  • + *
  • If the first argument is negative zero and the second argument is + * positive, or the first argument is negative and finite and the second + * argument is positive infinity, then the result is negative zero.
  • + *
  • If the first argument is positive zero and the second argument is + * negative, or the first argument is positive and finite and the second + * argument is negative infinity, then the result is the double value + * closest to pi.
  • + *
  • If the first argument is negative zero and the second argument is + * negative, or the first argument is negative and finite and the second + * argument is negative infinity, then the result is the double value + * closest to -pi.
  • + *
  • If the first argument is positive and the second argument is + * positive zero or negative zero, or the first argument is positive + * infinity and the second argument is finite, then the result is the + * double value closest to pi/2.
  • + *
  • If the first argument is negative and the second argument is + * positive zero or negative zero, or the first argument is negative + * infinity and the second argument is finite, then the result is the + * double value closest to -pi/2.
  • + *
  • If both arguments are positive infinity, then the result is the + * double value closest to pi/4.
  • + *
  • If the first argument is positive infinity and the second argument + * is negative infinity, then the result is the double value closest to + * 3*pi/4.
  • + *
  • If the first argument is negative infinity and the second argument + * is positive infinity, then the result is the double value closest to + * -pi/4.
  • + *
  • If both arguments are negative infinity, then the result is the + * double value closest to -3*pi/4.
  • + * + *

This is accurate within 2 ulps, and is semi-monotonic. To get r, + * use sqrt(x*x+y*y). + * + * @param y the y position + * @param x the x position + * @return theta in the conversion of (x, y) to (r, theta) + * @see #atan(double) + */ + public static native double atan2(double y, double x); + + /** + * Take ea. The opposite of log(). If the + * argument is NaN, the result is NaN; if the argument is positive infinity, + * the result is positive infinity; and if the argument is negative + * infinity, the result is positive zero. This is accurate within 1 ulp, + * and is semi-monotonic. + * + * @param a the number to raise to the power + * @return the number raised to the power of e + * @see #log(double) + * @see #pow(double, double) + */ + public static native double exp(double a); + + /** + * Take ln(a) (the natural log). The opposite of exp(). If the + * argument is NaN or negative, the result is NaN; if the argument is + * positive infinity, the result is positive infinity; and if the argument + * is either zero, the result is negative infinity. This is accurate within + * 1 ulp, and is semi-monotonic. + * + *

Note that the way to get logb(a) is to do this: + * ln(a) / ln(b). + * + * @param a the number to take the natural log of + * @return the natural log of a + * @see #exp(double) + */ + public static native double log(double a); + + /** + * Take a square root. If the argument is NaN or negative, the result is + * NaN; if the argument is positive infinity, the result is positive + * infinity; and if the result is either zero, the result is the same. + * This is accurate within the limits of doubles. + * + *

For other roots, use pow(a, 1 / rootNumber). + * + * @param a the numeric argument + * @return the square root of the argument + * @see #pow(double, double) + */ + public static native double sqrt(double a); + + /** + * Raise a number to a power. Special cases:

    + *
  • If the second argument is positive or negative zero, then the result + * is 1.0.
  • + *
  • If the second argument is 1.0, then the result is the same as the + * first argument.
  • + *
  • If the second argument is NaN, then the result is NaN.
  • + *
  • If the first argument is NaN and the second argument is nonzero, + * then the result is NaN.
  • + *
  • If the absolute value of the first argument is greater than 1 and + * the second argument is positive infinity, or the absolute value of the + * first argument is less than 1 and the second argument is negative + * infinity, then the result is positive infinity.
  • + *
  • If the absolute value of the first argument is greater than 1 and + * the second argument is negative infinity, or the absolute value of the + * first argument is less than 1 and the second argument is positive + * infinity, then the result is positive zero.
  • + *
  • If the absolute value of the first argument equals 1 and the second + * argument is infinite, then the result is NaN.
  • + *
  • If the first argument is positive zero and the second argument is + * greater than zero, or the first argument is positive infinity and the + * second argument is less than zero, then the result is positive zero.
  • + *
  • If the first argument is positive zero and the second argument is + * less than zero, or the first argument is positive infinity and the + * second argument is greater than zero, then the result is positive + * infinity.
  • + *
  • If the first argument is negative zero and the second argument is + * greater than zero but not a finite odd integer, or the first argument is + * negative infinity and the second argument is less than zero but not a + * finite odd integer, then the result is positive zero.
  • + *
  • If the first argument is negative zero and the second argument is a + * positive finite odd integer, or the first argument is negative infinity + * and the second argument is a negative finite odd integer, then the result + * is negative zero.
  • + *
  • If the first argument is negative zero and the second argument is + * less than zero but not a finite odd integer, or the first argument is + * negative infinity and the second argument is greater than zero but not a + * finite odd integer, then the result is positive infinity.
  • + *
  • If the first argument is negative zero and the second argument is a + * negative finite odd integer, or the first argument is negative infinity + * and the second argument is a positive finite odd integer, then the result + * is negative infinity.
  • + *
  • If the first argument is less than zero and the second argument is a + * finite even integer, then the result is equal to the result of raising + * the absolute value of the first argument to the power of the second + * argument.
  • + *
  • If the first argument is less than zero and the second argument is a + * finite odd integer, then the result is equal to the negative of the + * result of raising the absolute value of the first argument to the power + * of the second argument.
  • + *
  • If the first argument is finite and less than zero and the second + * argument is finite and not an integer, then the result is NaN.
  • + *
  • If both arguments are integers, then the result is exactly equal to + * the mathematical result of raising the first argument to the power of + * the second argument if that result can in fact be represented exactly as + * a double value.
  • + * + *

(In the foregoing descriptions, a floating-point value is + * considered to be an integer if and only if it is a fixed point of the + * method {@link #ceil(double)} or, equivalently, a fixed point of the + * method {@link #floor(double)}. A value is a fixed point of a one-argument + * method if and only if the result of applying the method to the value is + * equal to the value.) This is accurate within 1 ulp, and is semi-monotonic. + * + * @param a the number to raise + * @param b the power to raise it to + * @return ab + */ + public static native double pow(double a, double b); + + /** + * Get the IEEE 754 floating point remainder on two numbers. This is the + * value of x - y * n, where n is the closest + * double to x / y (ties go to the even n); for a zero + * remainder, the sign is that of x. If either argument is NaN, + * the first argument is infinite, or the second argument is zero, the result + * is NaN; if x is finite but y is infinite, the result is x. This is + * accurate within the limits of doubles. + * + * @param x the dividend (the top half) + * @param y the divisor (the bottom half) + * @return the IEEE 754-defined floating point remainder of x/y + * @see #rint(double) + */ + public static native double IEEEremainder(double x, double y); + + /** + * Take the nearest integer that is that is greater than or equal to the + * argument. If the argument is NaN, infinite, or zero, the result is the + * same; if the argument is between -1 and 0, the result is negative zero. + * Note that Math.ceil(x) == -Math.floor(-x). + * + * @param a the value to act upon + * @return the nearest integer >= a + */ + public static native double ceil(double a); + + /** + * Take the nearest integer that is that is less than or equal to the + * argument. If the argument is NaN, infinite, or zero, the result is the + * same. Note that Math.ceil(x) == -Math.floor(-x). + * + * @param a the value to act upon + * @return the nearest integer <= a + */ + public static native double floor(double a); + + /** + * Take the nearest integer to the argument. If it is exactly between + * two integers, the even integer is taken. If the argument is NaN, + * infinite, or zero, the result is the same. + * + * @param a the value to act upon + * @return the nearest integer to a + */ + public static native double rint(double a); + + /** + *

+ * Take a cube root. If the argument is NaN, an infinity or zero, then + * the original value is returned. The returned result must be within 1 ulp + * of the exact result. For a finite value, x, the cube root + * of -x is equal to the negation of the cube root + * of x. + *

+ *

+ * For a square root, use sqrt. For other roots, use + * pow(a, 1 / rootNumber). + *

+ * + * @param a the numeric argument + * @return the cube root of the argument + * @see #sqrt(double) + * @see #pow(double, double) + */ + public static native double cbrt(double a); + + /** + *

+ * Returns the hyperbolic cosine of the given value. For a value, + * x, the hyperbolic cosine is (ex + + * e-x)/2 + * with e being Euler's number. The returned + * result must be within 2.5 ulps of the exact result. + *

+ *

+ * If the supplied value is NaN, then the original value is + * returned. For either infinity, positive infinity is returned. + * The hyperbolic cosine of zero must be 1.0. + *

+ * + * @param a the numeric argument + * @return the hyperbolic cosine of a. + * @since 1.5 + */ + public static native double cosh(double a); + + /** + *

+ * Returns ea - 1. For values close to 0, the + * result of expm1(a) + 1 tend to be much closer to the + * exact result than simply exp(x). The result must be within + * 1 ulp of the exact result, and results must be semi-monotonic. For finite + * inputs, the returned value must be greater than or equal to -1.0. Once + * a result enters within half a ulp of this limit, the limit is returned. + *

+ *

+ * For NaN, positive infinity and zero, the original value + * is returned. Negative infinity returns a result of -1.0 (the limit). + *

+ * + * @param a the numeric argument + * @return ea - 1 + * @since 1.5 + */ + public static native double expm1(double a); + + /** + *

+ * Returns the hypotenuse, a2 + b2, + * without intermediate overflow or underflow. The returned result must be + * within 1 ulp of the exact result. If one parameter is held constant, + * then the result in the other parameter must be semi-monotonic. + *

+ *

+ * If either of the arguments is an infinity, then the returned result + * is positive infinity. Otherwise, if either argument is NaN, + * then NaN is returned. + *

+ * + * @param a the first parameter. + * @param b the second parameter. + * @return the hypotenuse matching the supplied parameters. + * @since 1.5 + */ + public static native double hypot(double a, double b); + + /** + *

+ * Returns the base 10 logarithm of the supplied value. The returned + * result must within 1 ulp of the exact result, and the results must be + * semi-monotonic. + *

+ *

+ * Arguments of either NaN or less than zero return + * NaN. An argument of positive infinity returns positive + * infinity. Negative infinity is returned if either positive or negative + * zero is supplied. Where the argument is the result of + * 10n, then n is returned. + *

+ * + * @param a the numeric argument. + * @return the base 10 logarithm of a. + * @since 1.5 + */ + public static native double log10(double a); + + /** + *

+ * Returns the natural logarithm resulting from the sum of the argument, + * a and 1. For values close to 0, the + * result of log1p(a) tend to be much closer to the + * exact result than simply log(1.0+a). The returned + * result must be within 1 ulp of the exact result, and the results must be + * semi-monotonic. + *

+ *

+ * Arguments of either NaN or less than -1 return + * NaN. An argument of positive infinity or zero + * returns the original argument. Negative infinity is returned from an + * argument of -1. + *

+ * + * @param a the numeric argument. + * @return the natural logarithm of a + 1. + * @since 1.5 + */ + public static native double log1p(double a); + + /** + *

+ * Returns the hyperbolic sine of the given value. For a value, + * x, the hyperbolic sine is (ex - + * e-x)/2 + * with e being Euler's number. The returned + * result must be within 2.5 ulps of the exact result. + *

+ *

+ * If the supplied value is NaN, an infinity or a zero, then the + * original value is returned. + *

+ * + * @param a the numeric argument + * @return the hyperbolic sine of a. + * @since 1.5 + */ + public static native double sinh(double a); + + /** + *

+ * Returns the hyperbolic tangent of the given value. For a value, + * x, the hyperbolic tangent is (ex - + * e-x)/(ex + e-x) + * (i.e. sinh(a)/cosh(a)) + * with e being Euler's number. The returned + * result must be within 2.5 ulps of the exact result. The absolute value + * of the exact result is always less than 1. Computed results are thus + * less than or equal to 1 for finite arguments, with results within + * half a ulp of either positive or negative 1 returning the appropriate + * limit value (i.e. as if the argument was an infinity). + *

+ *

+ * If the supplied value is NaN or zero, then the original + * value is returned. Positive infinity returns +1.0 and negative infinity + * returns -1.0. + *

+ * + * @param a the numeric argument + * @return the hyperbolic tangent of a. + * @since 1.5 + */ + public static native double tanh(double a); + +} diff --git a/libjava/classpath/vm/reference/java/lang/VMObject.java b/libjava/classpath/vm/reference/java/lang/VMObject.java new file mode 100644 index 000000000..279f250c0 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMObject.java @@ -0,0 +1,105 @@ +/* VMObject.java -- Reference implementation for VM hooks used by Object + Copyright (C) 1998, 2002, 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 java.lang; + +/** + * Object is the ultimate superclass of every class (excepting interfaces). + * As such, it needs help from the VM. + * + * @author John Keiser + * @author Eric Blake (ebb9@email.byu.edu) + */ +final class VMObject +{ + /** + * Returns the runtime {@link Class} of a given Object. + * + * @param obj the object to return the class for. + * + * @return the class of the Object. + */ + static native Class getClass(Object obj); + + /** + * The VM is expected to make a field-for-field shallow copy of the + * argument. Thus, the copy has the same runtime type as the argument. + * Note, however, that the cloned object must still be finalizable, even + * if the original has already had finalize() invoked on it. + * + * @param c the Cloneable to clone + * @return the clone + */ + static native Object clone(Cloneable c); + + /** + * Wakes up one of the threads that is waiting on this Object's monitor. + * Only the owner of a lock on the Object may call this method. The Thread + * to wake up is chosen arbitrarily. + * + * @param o the object doing the notify + * @throw IllegalMonitorStateException if this Thread does not own the + * lock on the Object + */ + static native void notify(Object o) throws IllegalMonitorStateException; + + /** + * Wakes up all of the threads waiting on this Object's monitor. Only + * the owner of the lock on this Object may call this method. + * + * @param o the object doing the notifyAll + * @throws IllegalMonitorStateException if this Thread does not own the + * lock on the Object + */ + static native void notifyAll(Object o) throws IllegalMonitorStateException; + + /** + * Waits a specified amount of time for notify() or notifyAll() to be + * called on this Object. The VM does not have to pay attention to the + * ns argument, if it does not have that much granularity. + * + * @param o the object to suspend on + * @param ms milliseconds to wait (1,000 milliseconds = 1 second) + * @param ns nanoseconds to wait beyond ms (1,000,000 nanoseconds + * == 1 millisecond) + * @throws IllegalMonitorStateException if this Thread does not own the + * lock on the Object + * @throws InterruptedException if some other Thread interrupts this Thread + */ + static native void wait(Object o, long ms, int ns) + throws IllegalMonitorStateException, InterruptedException; +} diff --git a/libjava/classpath/vm/reference/java/lang/VMProcess.java b/libjava/classpath/vm/reference/java/lang/VMProcess.java new file mode 100644 index 000000000..c41d7cc0c --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMProcess.java @@ -0,0 +1,402 @@ +/* java.lang.VMProcess -- VM implementation of java.lang.Process + Copyright (C) 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 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.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + +/** + * Represents one external process. Each instance of this class is in + * one of three states: INITIAL, RUNNING, or TERMINATED. The instance + * is {@link Object#notifyAll notifyAll()}'d each time the state changes. + * The state of all instances is managed by a single dedicated thread + * which does the actual fork()/exec() and wait() system calls. User + * threads {@link Object#wait()} on the instance when creating the + * process or waiting for it to terminate. + * + *

+ * See + * GCC bug + * #11801 for the motivation behind the design of this class. + * + * @author Archie Cobbs + * @see Process + * @see Runtime#exec(String) + */ +final class VMProcess extends Process +{ + + // Possible states for a VMProcess + private static final int INITIAL = 0; + private static final int RUNNING = 1; + private static final int TERMINATED = 2; + + // Dedicated thread that does all the fork()'ing and wait()'ing. + static Thread processThread; + + // New processes waiting to be spawned by processThread. + static final LinkedList workList = new LinkedList(); + + // Return values set by nativeReap() when a child is reaped. + // These are only accessed by processThread so no locking required. + static long reapedPid; + static int reapedExitValue; + + // Information about this process + int state; // current state of process + final String[] cmd; // copied from Runtime.exec() + final String[] env; // copied from Runtime.exec() + final File dir; // copied from Runtime.exec() + Throwable exception; // if process failed to start + long pid; // process id + OutputStream stdin; // process input stream + InputStream stdout; // process output stream + InputStream stderr; // process error stream + int exitValue; // process exit value + boolean redirect; // redirect stderr -> stdout + + // + // Dedicated thread that does all the fork()'ing and wait()'ing + // for external processes. This is needed because some systems like + // Linux use a process-per-thread model, which means the same thread + // that did the fork()/exec() must also do the wait(). + // + private static class ProcessThread extends Thread + { + + // Max time (in ms) we'll delay before trying to reap another child. + private static final int MAX_REAP_DELAY = 1000; + + // Processes created but not yet terminated; maps Long(pid) -> VMProcess + // Only used in run() and spawn() method from this Thread, so no locking. + private final HashMap activeMap = new HashMap(); + + // We have an explicit constructor, because the default + // constructor will be private, which means the compiler will have + // to generate a second package-private constructor, which is + // bogus. + ProcessThread () + { + } + + public void run() + { + final LinkedList workList = VMProcess.workList; + while (true) + { + + // Get the next process to spawn (if any) and spawn it. Spawn + // at most one at a time before checking for reapable children. + VMProcess process = null; + synchronized (workList) + { + if (!workList.isEmpty()) + process = (VMProcess)workList.removeFirst(); + } + + if (process != null) + spawn(process); + + + // Check for termination of active child processes + while (!activeMap.isEmpty() && VMProcess.nativeReap()) + { + long pid = VMProcess.reapedPid; + int exitValue = VMProcess.reapedExitValue; + process = (VMProcess)activeMap.remove(new Long(pid)); + if (process != null) + { + synchronized (process) + { + process.exitValue = exitValue; + process.state = TERMINATED; + process.notify(); + } + } + else + System.err.println("VMProcess WARNING reaped unknown process: " + + pid); + } + + + // If there are more new processes to create, go do that now. + // If there is nothing left to do, exit this thread. Otherwise, + // sleep a little while, and then check again for reapable children. + // We will get woken up immediately if there are new processes to + // spawn, but not if there are new children to reap. So we only + // sleep a short time, in effect polling while processes are active. + synchronized (workList) + { + if (!workList.isEmpty()) + continue; + if (activeMap.isEmpty()) + { + processThread = null; + break; + } + + try + { + workList.wait(MAX_REAP_DELAY); + } + catch (InterruptedException e) + { + /* ignore */ + } + } + } + } + + // Spawn a process + private void spawn(VMProcess process) + { + + // Spawn the process and put it in our active map indexed by pid. + // If the spawn operation fails, store the exception with the process. + // In either case, wake up thread that created the process. + synchronized (process) + { + try + { + process.nativeSpawn(process.cmd, process.env, process.dir, + process.redirect); + process.state = RUNNING; + activeMap.put(new Long(process.pid), process); + } + catch (ThreadDeath death) + { + throw death; + } + catch (Throwable t) + { + process.state = TERMINATED; + process.exception = t; + } + process.notify(); + } + } + } + + // Constructor + private VMProcess(String[] cmd, String[] env, File dir, boolean redirect) + throws IOException + { + + // Initialize this process + this.state = INITIAL; + this.cmd = cmd; + this.env = env; + this.dir = dir; + this.redirect = redirect; + + // Add process to the new process work list and wakeup processThread + synchronized (workList) + { + workList.add(this); + if (processThread == null) + { + processThread = new ProcessThread(); + processThread.setDaemon(true); + processThread.start(); + } + else + { + workList.notify(); + } + } + + // Wait for processThread to spawn this process and update its state + synchronized (this) + { + while (state == INITIAL) + { + try + { + wait(); + } + catch (InterruptedException e) + { + /* ignore */ + } + } + } + + // If spawning failed, rethrow the exception in this thread + if (exception != null) + { + exception.fillInStackTrace(); + if (exception instanceof IOException) + throw (IOException)exception; + + if (exception instanceof Error) + throw (Error)exception; + + if (exception instanceof RuntimeException) + throw (RuntimeException)exception; + + throw new RuntimeException(exception); + } + } + + // Invoked by native code (from nativeSpawn()) to record process info. + private void setProcessInfo(OutputStream stdin, + InputStream stdout, InputStream stderr, long pid) + { + this.stdin = stdin; + this.stdout = stdout; + if (stderr == null) + this.stderr = new InputStream() + { + public int read() throws IOException + { + return -1; + } + }; + else + this.stderr = stderr; + this.pid = pid; + } + + /** + * Entry point from Runtime.exec(). + */ + static Process exec(String[] cmd, String[] env, File dir) throws IOException + { + return new VMProcess(cmd, env, dir, false); + } + + static Process exec(List cmd, Map env, + File dir, boolean redirect) throws IOException + { + String[] acmd = (String[]) cmd.toArray(new String[cmd.size()]); + String[] aenv = new String[env.size()]; + + int i = 0; + Iterator iter = env.entrySet().iterator(); + while (iter.hasNext()) + { + Map.Entry entry = (Map.Entry) iter.next(); + aenv[i++] = entry.getKey() + "=" + entry.getValue(); + } + + return new VMProcess(acmd, aenv, dir, redirect); + } + + public OutputStream getOutputStream() + { + return stdin; + } + + public InputStream getInputStream() + { + return stdout; + } + + public InputStream getErrorStream() + { + return stderr; + } + + public synchronized int waitFor() throws InterruptedException + { + while (state != TERMINATED) + wait(); + return exitValue; + } + + public synchronized int exitValue() + { + if (state != TERMINATED) + throw new IllegalThreadStateException(); + return exitValue; + } + + public synchronized void destroy() + { + if (state == TERMINATED) + return; + + nativeKill(pid); + + while (state != TERMINATED) + { + try + { + wait(); + } + catch (InterruptedException e) + { + /* ignore */ + } + } + } + + /** + * Does the fork()/exec() thing to create the O/S process. + * Must invoke setProcessInfo() before returning successfully. + * This method is only invoked by processThread. + * + * @throws IOException if the O/S process could not be created. + */ + native void nativeSpawn(String[] cmd, String[] env, File dir, + boolean redirect) + throws IOException; + + /** + * Test for a reapable child process, and reap if so. Does not block. + * If a child was reaped, this method must set reapedPid and + * reapedExitValue appropriately before returning. + * This method is only invoked by processThread. + * + * @return true if a child was reaped, otherwise false + */ + // This is not private as it is called from an inner class. + static native boolean nativeReap(); + + /** + * Kill a process. This sends it a fatal signal but does not reap it. + */ + private static native void nativeKill(long pid); +} diff --git a/libjava/classpath/vm/reference/java/lang/VMRuntime.java b/libjava/classpath/vm/reference/java/lang/VMRuntime.java new file mode 100644 index 000000000..0b58d5f44 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMRuntime.java @@ -0,0 +1,192 @@ +/* VMRuntime.java -- VM interface to Runtime + 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.io.File; +import java.io.IOException; + +/** + * VMRuntime represents the interface to the Virtual Machine. + * + * @author Jeroen Frijters + */ +final class VMRuntime +{ + /** + * No instance is ever created. + */ + private VMRuntime() + { + } + + /** + * Returns the number of available processors currently available to the + * virtual machine. This number may change over time; so a multi-processor + * program want to poll this to determine maximal resource usage. + * + * @return the number of processors available, at least 1 + */ + static native int availableProcessors(); + + /** + * Find out how much memory is still free for allocating Objects on the heap. + * + * @return the number of bytes of free memory for more Objects + */ + static native long freeMemory(); + + /** + * Find out how much memory total is available on the heap for allocating + * Objects. + * + * @return the total number of bytes of memory for Objects + */ + static native long totalMemory(); + + /** + * Returns the maximum amount of memory the virtual machine can attempt to + * use. This may be Long.MAX_VALUE if there is no inherent + * limit (or if you really do have a 8 exabyte memory!). + * + * @return the maximum number of bytes the virtual machine will attempt + * to allocate + */ + static native long maxMemory(); + + /** + * Run the garbage collector. This method is more of a suggestion than + * anything. All this method guarantees is that the garbage collector will + * have "done its best" by the time it returns. Notice that garbage + * collection takes place even without calling this method. + */ + static native void gc(); + + /** + * Run finalization on all Objects that are waiting to be finalized. Again, + * a suggestion, though a stronger one than {@link #gc()}. This calls the + * finalize method of all objects waiting to be collected. + * + * @see #finalize() + */ + static native void runFinalization(); + + /** + * Run finalization on all finalizable Objects (even live ones). This + * should only be called immediately prior to VM termination. + * + * @see #finalize() + */ + static native void runFinalizationForExit(); + + /** + * Tell the VM to trace every bytecode instruction that executes (print out + * a trace of it). No guarantees are made as to where it will be printed, + * and the VM is allowed to ignore this request. + * + * @param on whether to turn instruction tracing on + */ + static native void traceInstructions(boolean on); + + /** + * Tell the VM to trace every method call that executes (print out a trace + * of it). No guarantees are made as to where it will be printed, and the + * VM is allowed to ignore this request. + * + * @param on whether to turn method tracing on + */ + static native void traceMethodCalls(boolean on); + + /** + * Native method that actually sets the finalizer setting. + * + * @param value whether to run finalizers on exit + */ + static native void runFinalizersOnExit(boolean value); + + /** + * Native method that actually shuts down the virtual machine. + * + * @param status the status to end the process with + */ + static native void exit(int status); + + /** + * Load a file. If it has already been loaded, do nothing. The name has + * already been mapped to a true filename. + * + * @param filename the file to load + * @param loader class loader, or null for the boot loader + * @return 0 on failure, nonzero on success + */ + static native int nativeLoad(String filename, ClassLoader loader); + + /** + * Map a system-independent "short name" to the full file name. + * + * @param libname the short version of the library name + * @return the full filename + */ + static native String mapLibraryName(String libname); + + /** + * Execute a process. The command line has already been tokenized, and + * the environment should contain name=value mappings. If directory is null, + * use the current working directory; otherwise start the process in that + * directory. If env is null, then the new process should inherit + * the environment of this process. + * + * @param cmd the non-null command tokens + * @param env the environment setup + * @param dir the directory to use, may be null + * @return the newly created process + * @throws NullPointerException if cmd or env have null elements + */ + static Process exec(String[] cmd, String[] env, File dir) + throws IOException { + return VMProcess.exec(cmd, env, dir); + } + + /** + * This method is called by Runtime.addShutdownHook() when it is + * called for the first time. It enables the VM to lazily setup + * an exit handler, should it so desire. + */ + static void enableShutdownHooks() + { + } +} // class VMRuntime diff --git a/libjava/classpath/vm/reference/java/lang/VMString.java b/libjava/classpath/vm/reference/java/lang/VMString.java new file mode 100644 index 000000000..e1fbf8390 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMString.java @@ -0,0 +1,91 @@ +/* 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 + */ +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; + } + +} // class VMString diff --git a/libjava/classpath/vm/reference/java/lang/VMSystem.java b/libjava/classpath/vm/reference/java/lang/VMSystem.java new file mode 100644 index 000000000..52a3c1c9f --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMSystem.java @@ -0,0 +1,220 @@ +/* VMSystem.java -- helper for java.lang.system + Copyright (C) 1998, 2002, 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 java.lang; + +import java.util.List; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.FileDescriptor; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.PrintStream; + +/** + * VMSystem is a package-private helper class for System that the + * VM must implement. + * + * @author John Keiser + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + */ +final class VMSystem +{ + /** + * Copy one array onto another from src[srcStart] ... + * src[srcStart+len-1] to dest[destStart] ... + * dest[destStart+len-1]. First, the arguments are validated: + * neither array may be null, they must be of compatible types, and the + * start and length must fit within both arrays. Then the copying starts, + * and proceeds through increasing slots. If src and dest are the same + * array, this will appear to copy the data to a temporary location first. + * An ArrayStoreException in the middle of copying will leave earlier + * elements copied, but later elements unchanged. + * + * @param src the array to copy elements from + * @param srcStart the starting position in src + * @param dest the array to copy elements to + * @param destStart the starting position in dest + * @param len the number of elements to copy + * @throws NullPointerException if src or dest is null + * @throws ArrayStoreException if src or dest is not an array, if they are + * not compatible array types, or if an incompatible runtime type + * is stored in dest + * @throws IndexOutOfBoundsException if len is negative, or if the start or + * end copy position in either array is out of bounds + */ + static native void arraycopy(Object src, int srcStart, + Object dest, int destStart, int len); + + /** + * Get a hash code computed by the VM for the Object. This hash code will + * be the same as Object's hashCode() method. It is usually some + * convolution of the pointer to the Object internal to the VM. It + * follows standard hash code rules, in that it will remain the same for a + * given Object for the lifetime of that Object. + * + * @param o the Object to get the hash code for + * @return the VM-dependent hash code for this Object + */ + static native int identityHashCode(Object o); + + /** + * Convert a library name to its platform-specific variant. + * + * @param libname the library name, as used in loadLibrary + * @return the platform-specific mangling of the name + * @XXX Add this method + static native String mapLibraryName(String libname); + */ + + /** + * Set {@link System#in} to a new InputStream. + * + * @param in the new InputStream + * @see #setIn(InputStream) + */ + static native void setIn(InputStream in); + + /** + * Set {@link System#out} to a new PrintStream. + * + * @param out the new PrintStream + * @see #setOut(PrintStream) + */ + static native void setOut(PrintStream out); + + /** + * Set {@link System#err} to a new PrintStream. + * + * @param err the new PrintStream + * @see #setErr(PrintStream) + */ + static native void setErr(PrintStream err); + + /** + * Get the current time, measured in the number of milliseconds from the + * beginning of Jan. 1, 1970. This is gathered from the system clock, with + * any attendant incorrectness (it may be timezone dependent). + * + * @return the current time + * @see java.util.Date + */ + public static long currentTimeMillis() + { + return nanoTime() / 1000000L; + } + + /** + *

+ * Returns the current value of a nanosecond-precise system timer. + * The value of the timer is an offset relative to some arbitrary fixed + * time, which may be in the future (making the value negative). This + * method is useful for timing events where nanosecond precision is + * required. This is achieved by calling this method before and after the + * event, and taking the difference betweent the two times: + *

+ *

+ * long startTime = System.nanoTime();
+ * ... event code ...
+ * long endTime = System.nanoTime();
+ * long duration = endTime - startTime;
+ *

+ *

+ * Note that the value is only nanosecond-precise, and not accurate; there + * is no guarantee that the difference between two values is really a + * nanosecond. Also, the value is prone to overflow if the offset + * exceeds 2^63. + *

+ * + * @return the time of a system timer in nanoseconds. + * @since 1.5 + */ + public static native long nanoTime(); + + /** + * Returns a list of 'name=value' pairs representing the current environment + * variables. + * + * @return a list of 'name=value' pairs. + */ + static native List environ(); + + /** + * Helper method which creates the standard input stream. + * VM implementors may choose to construct these streams differently. + * This method can also return null if the stream is created somewhere + * else in the VM startup sequence. + */ + static InputStream makeStandardInputStream() + { + return new BufferedInputStream(new FileInputStream(FileDescriptor.in)); + } + + /** + * Helper method which creates the standard output stream. + * VM implementors may choose to construct these streams differently. + * This method can also return null if the stream is created somewhere + * else in the VM startup sequence. + */ + static PrintStream makeStandardOutputStream() + { + return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true); + } + + /** + * Helper method which creates the standard error stream. + * VM implementors may choose to construct these streams differently. + * This method can also return null if the stream is created somewhere + * else in the VM startup sequence. + */ + static PrintStream makeStandardErrorStream() + { + return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true); + } + + /** + * Gets the value of an environment variable. + * Always returning null is a valid (but not very useful) implementation. + * + * @param name The name of the environment variable (will not be null). + * @return The string value of the variable or null when the + * environment variable is not defined. + */ + static native String getenv(String name); +} diff --git a/libjava/classpath/vm/reference/java/lang/VMThread.java b/libjava/classpath/vm/reference/java/lang/VMThread.java new file mode 100644 index 000000000..1b461a694 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMThread.java @@ -0,0 +1,461 @@ +/* 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. + *

+ * This is the GNU Classpath reference implementation, it should be adapted + * for a specific VM. + *

+ * The following methods must be implemented: + *

    + *
  • native void start(long stacksize); + *
  • native void interrupt(); + *
  • native boolean isInterrupted(); + *
  • native void suspend(); + *
  • native void resume(); + *
  • native void nativeSetPriority(int priority); + *
  • native void nativeStop(Throwable t); + *
  • native static Thread currentThread(); + *
  • static native void yield(); + *
  • static native boolean interrupted(); + *
+ * 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); + vmThread.start(stacksize); + thread.vmThread = vmThread; + } + + /** + * 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. + * + *

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 + * interrupted status 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). + * WARNINGThis bypasses Java security, and can throw a checked + * exception which the call stack is unprepared to handle. Do not abuse + * this power. + * + *

This is inherently unsafe, as it can interrupt synchronized blocks and + * leave data in bad states. + * + *

NOTE 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 interrupted status 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. + * + *

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 interrupted status 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 interrupted status 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 assert Thread.holdsLock(obj). + * + * @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; + } + } + + /** + * 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(); + +} diff --git a/libjava/classpath/vm/reference/java/lang/VMThrowable.java b/libjava/classpath/vm/reference/java/lang/VMThrowable.java new file mode 100644 index 000000000..19a204e88 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/VMThrowable.java @@ -0,0 +1,82 @@ +/* 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; + +/** + * VM dependant state and support methods for Throwable. + * It is deliberately package local and final and should only be accessed + * by the Throwable class. + *

+ * 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 +{ + /** + * VM private data. + */ + private transient Object vmdata; + + /** + * Private contructor, create VMThrowables with fillInStackTrace(); + */ + private VMThrowable() { } + + /** + * Fill in the stack trace with the current execution stack. + * Called by Throwable.fillInStackTrace() 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 StackTraceElement array based on the execution + * state of the VM as captured by fillInStackTrace. + * Called by Throwable.getStackTrace(). + * + * @return a non-null but possible zero length array of StackTraceElement. + * @see Throwable#getStackTrace() + */ + native StackTraceElement[] getStackTrace(Throwable t); +} diff --git a/libjava/classpath/vm/reference/java/lang/management/VMManagementFactory.java b/libjava/classpath/vm/reference/java/lang/management/VMManagementFactory.java new file mode 100644 index 000000000..f10497014 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/management/VMManagementFactory.java @@ -0,0 +1,75 @@ +/* VMManagementFactory.java - VM interface for obtaining system beans. + 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 java.lang.management; + +/** + * Provides lists of resources required by the + * {@link java.lang.management.ManagementFactory} for + * creating beans. + * + * @author Andrew John Hughes (gnu_andrew@member.fsf.org) + * @since 1.5 + */ +final class VMManagementFactory +{ + + /** + * Return a list of the names of the currently available + * memory pools within the virtual machine. + * + * @return a list of memory pool names. + */ + static native String[] getMemoryPoolNames(); + + /** + * Return a list of the names of the currently available + * memory managers within the virtual machine. This should + * not include the garbage collectors listed below. + * + * @return a list of memory manager names. + */ + static native String[] getMemoryManagerNames(); + + /** + * Return a list of the names of the currently available + * garbage collectors within the virtual machine. + * + * @return a list of garbage collector names. + */ + static native String[] getGarbageCollectorNames(); +} diff --git a/libjava/classpath/vm/reference/java/lang/reflect/VMArray.java b/libjava/classpath/vm/reference/java/lang/reflect/VMArray.java new file mode 100644 index 000000000..d6277aebd --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/reflect/VMArray.java @@ -0,0 +1,65 @@ +/* java.lang.reflect.VMArray - VM class for array manipulation by reflection. + Copyright (C) 1998, 1999, 2001, 2003, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang.reflect; + +import gnu.classpath.Configuration; + +class VMArray +{ + + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javalangreflect"); + } + } + + /** + * Dynamically create an array of objects. + * + * @param type guaranteed to be a valid object type + * @param dim the length of the array + * @return the new array + * @throws NegativeArraySizeException if dim is negative + * @throws OutOfMemoryError if memory allocation fails + */ + static native Object createObjectArray(Class type, int dim); + +} diff --git a/libjava/classpath/vm/reference/java/lang/reflect/VMConstructor.java b/libjava/classpath/vm/reference/java/lang/reflect/VMConstructor.java new file mode 100644 index 000000000..c6f319026 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/reflect/VMConstructor.java @@ -0,0 +1,169 @@ +/* java.lang.reflect.VMConstructor - VM interface for reflection of Java constructors + Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang.reflect; + +import java.lang.annotation.Annotation; + +import java.util.Arrays; + +final class VMConstructor +{ + Class clazz; + int slot; + + /** + * This field allows us to refer back to the main constructor instance. + * It is set by the constructor of Constructor. + */ + Constructor cons; + + VMConstructor(Class clazz, int slot) + { + this.clazz = clazz; + this.slot = slot; + } + + public Class getDeclaringClass() + { + return clazz; + } + + /** + * Return the raw modifiers for this constructor. In particular + * this will include the synthetic and varargs bits. + * @return the constructor's modifiers + */ + native int getModifiersInternal(); + + /** + * Get the parameter list for this constructor, in declaration order. If the + * constructor takes no parameters, returns a 0-length array (not null). + * + * @return a list of the types of the constructor's parameters + */ + native Class[] getParameterTypes(); + + /** + * Get the exception types this constructor says it throws, in no particular + * order. If the constructor has no throws clause, returns a 0-length array + * (not null). + * + * @return a list of the types in the constructor's throws clause + */ + native Class[] getExceptionTypes(); + + native Object construct(Object[] args) + throws InstantiationException, IllegalAccessException, + InvocationTargetException; + + /** + * Return the String in the Signature attribute for this constructor. If there + * is no Signature attribute, return null. + */ + native String getSignature(); + + /** + *

+ * Return an array of arrays representing the annotations on each + * of the constructor's parameters. The outer array is aligned against + * the parameters of the constructors and is thus equal in length to + * the number of parameters (thus having a length zero if there are none). + * Each array element in the outer array contains an inner array which + * holds the annotations. This array has a length of zero if the parameter + * has no annotations. + *

+ *

+ * The returned annotations are serialized. Changing the annotations has + * no affect on the return value of future calls to this method. + *

+ * + * @return an array of arrays which represents the annotations used on the + * parameters of this constructor. The order of the array elements + * matches the declaration order of the parameters. + * @since 1.5 + */ + native Annotation[][] getParameterAnnotations(); + + /** + * Compare two objects to see if they are semantically equivalent. + * Two Constructors are semantically equivalent if they have the same + * declaring class and the same parameter list. This ignores different + * exception clauses, but since you can't create a Method except through the + * VM, this is just the == relation. + * + * @param o the object to compare to + * @return true if they are equal; false if not. + */ + public boolean equals(Object o) + { + if (!(o instanceof Constructor)) + return false; + Constructor that = (Constructor)o; + if (clazz != that.getDeclaringClass()) + return false; + if (!Arrays.equals(getParameterTypes(), that.getParameterTypes())) + return false; + return true; + } + + /** + * Returns the element's annotation for the specified annotation type, + * or null if no such annotation exists. + * + * @param annotationClass the type of annotation to look for. + * @return this element's annotation for the specified type, or + * null if no such annotation exists. + * @throws NullPointerException if the annotation class is null. + */ + native Annotation getAnnotation(Class annotationClass); + + /** + * Returns all annotations directly defined by the element. If there are + * no annotations directly associated with the element, then a zero-length + * array will be returned. The returned array may be modified by the client + * code, but this will have no effect on the annotation content of this + * class, and hence no effect on the return value of this method for + * future callers. + * + * @return the annotations directly defined by the element. + * @since 1.5 + */ + native Annotation[] getDeclaredAnnotations(); + +} diff --git a/libjava/classpath/vm/reference/java/lang/reflect/VMField.java b/libjava/classpath/vm/reference/java/lang/reflect/VMField.java new file mode 100644 index 000000000..ee9239a8e --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/reflect/VMField.java @@ -0,0 +1,549 @@ +/* java.lang.reflect.Field - VM interface for reflection of Java fields + Copyright (C) 1998, 2001, 2005, 2008 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang.reflect; + +import java.lang.annotation.Annotation; + +final class VMField +{ + Class clazz; + String name; + int slot; + + /** + * This field allows us to refer back to the main constructor instance. + * It is set by the constructor of Field. + */ + Field f; + + VMField(Class clazz, String name, int slot) + { + this.clazz = clazz; + this.name = name; + this.slot = slot; + } + + public Class getDeclaringClass() + { + return clazz; + } + + public String getName() + { + return name; + } + + /** + * Return the raw modifiers for this field. + * @return the field's modifiers + */ + native int getModifiersInternal(); + + /** + * Gets the type of this field. + * @return the type of this field + */ + native Class getType(); + + /** + * Get the value of this Field. If it is primitive, it will be wrapped + * in the appropriate wrapper type (boolean = java.lang.Boolean).

+ * + * If the field is static, o will be ignored. Otherwise, if + * o is null, you get a NullPointerException, + * and if it is incompatible with the declaring class of the field, you + * get an IllegalArgumentException.

+ * + * Next, if this Field enforces access control, your runtime context is + * evaluated, and you may have an IllegalAccessException if + * you could not access this field in similar compiled code. If the field + * is static, and its class is uninitialized, you trigger class + * initialization, which may end in a + * ExceptionInInitializerError.

+ * + * Finally, the field is accessed, and primitives are wrapped (but not + * necessarily in new objects). This method accesses the field of the + * declaring class, even if the instance passed in belongs to a subclass + * which declares another field to hide this one. + * + * @param o the object to get the value of this Field from + * @return the value of the Field + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if o is not an instance of + * the class or interface declaring this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #getBoolean(Object) + * @see #getByte(Object) + * @see #getChar(Object) + * @see #getShort(Object) + * @see #getInt(Object) + * @see #getLong(Object) + * @see #getFloat(Object) + * @see #getDouble(Object) + */ + native Object get(Object o) + throws IllegalAccessException; + + /** + * Get the value of this boolean Field. If the field is static, + * o will be ignored. + * + * @param o the object to get the value of this Field from + * @return the value of the Field + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a boolean field of + * o, or if o is not an instance of the + * declaring class of this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #get(Object) + */ + native boolean getBoolean(Object o) + throws IllegalAccessException; + + /** + * Get the value of this byte Field. If the field is static, + * o will be ignored. + * + * @param o the object to get the value of this Field from + * @return the value of the Field + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte field of + * o, or if o is not an instance of the + * declaring class of this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #get(Object) + */ + native byte getByte(Object o) + throws IllegalAccessException; + + /** + * Get the value of this Field as a char. If the field is static, + * o will be ignored. + * + * @param o the object to get the value of this Field from + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a char field of + * o, or if o is not an instance + * of the declaring class of this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #get(Object) + */ + native char getChar(Object o) + throws IllegalAccessException; + + /** + * Get the value of this Field as a short. If the field is static, + * o will be ignored. + * + * @param o the object to get the value of this Field from + * @return the value of the Field + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte or short + * field of o, or if o is not an instance + * of the declaring class of this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #get(Object) + */ + native short getShort(Object o) + throws IllegalAccessException; + + /** + * Get the value of this Field as an int. If the field is static, + * o will be ignored. + * + * @param o the object to get the value of this Field from + * @return the value of the Field + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, char, or + * int field of o, or if o is not an + * instance of the declaring class of this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #get(Object) + */ + native int getInt(Object o) + throws IllegalAccessException; + + /** + * Get the value of this Field as a long. If the field is static, + * o will be ignored. + * + * @param o the object to get the value of this Field from + * @return the value of the Field + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, char, int, + * or long field of o, or if o is not an + * instance of the declaring class of this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #get(Object) + */ + native long getLong(Object o) + throws IllegalAccessException; + + /** + * Get the value of this Field as a float. If the field is static, + * o will be ignored. + * + * @param o the object to get the value of this Field from + * @return the value of the Field + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, char, int, + * long, or float field of o, or if o is + * not an instance of the declaring class of this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #get(Object) + */ + native float getFloat(Object o) + throws IllegalAccessException; + + /** + * Get the value of this Field as a double. If the field is static, + * o will be ignored. + * + * @param o the object to get the value of this Field from + * @return the value of the Field + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, char, int, + * long, float, or double field of o, or if + * o is not an instance of the declaring class of this + * field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #get(Object) + */ + native double getDouble(Object o) + throws IllegalAccessException; + + /** + * Set the value of this Field. If it is a primitive field, the value + * will be unwrapped from the passed object (boolean = java.lang.Boolean).

+ * + * If the field is static, o will be ignored. Otherwise, if + * o is null, you get a NullPointerException, + * and if it is incompatible with the declaring class of the field, you + * get an IllegalArgumentException.

+ * + * Next, if this Field enforces access control, your runtime context is + * evaluated, and you may have an IllegalAccessException if + * you could not access this field in similar compiled code. This also + * occurs whether or not there is access control if the field is final. + * If the field is primitive, and unwrapping your argument fails, you will + * get an IllegalArgumentException; likewise, this error + * happens if value cannot be cast to the correct object type. + * If the field is static, and its class is uninitialized, you trigger class + * initialization, which may end in a + * ExceptionInInitializerError.

+ * + * Finally, the field is set with the widened value. This method accesses + * the field of the declaring class, even if the instance passed in belongs + * to a subclass which declares another field to hide this one. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if value cannot be + * converted by a widening conversion to the underlying type of + * the Field, or if o is not an instance of the class + * declaring this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #setBoolean(Object, boolean) + * @see #setByte(Object, byte) + * @see #setChar(Object, char) + * @see #setShort(Object, short) + * @see #setInt(Object, int) + * @see #setLong(Object, long) + * @see #setFloat(Object, float) + * @see #setDouble(Object, double) + */ + native void set(Object o, Object value) + throws IllegalAccessException; + + /** + * Set this boolean Field. If the field is static, o will be + * ignored. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a boolean field, or if + * o is not an instance of the class declaring this + * field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #set(Object, Object) + */ + native void setBoolean(Object o, boolean value) + throws IllegalAccessException; + + /** + * Set this byte Field. If the field is static, o will be + * ignored. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a byte, short, int, long, + * float, or double field, or if o is not an instance + * of the class declaring this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #set(Object, Object) + */ + native void setByte(Object o, byte value) + throws IllegalAccessException; + + /** + * Set this char Field. If the field is static, o will be + * ignored. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a char, int, long, + * float, or double field, or if o is not an instance + * of the class declaring this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #set(Object, Object) + */ + native void setChar(Object o, char value) + throws IllegalAccessException; + + /** + * Set this short Field. If the field is static, o will be + * ignored. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a short, int, long, + * float, or double field, or if o is not an instance + * of the class declaring this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #set(Object, Object) + */ + native void setShort(Object o, short value) + throws IllegalAccessException; + + /** + * Set this int Field. If the field is static, o will be + * ignored. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not an int, long, float, or + * double field, or if o is not an instance of the + * class declaring this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #set(Object, Object) + */ + native void setInt(Object o, int value) + throws IllegalAccessException; + + /** + * Set this long Field. If the field is static, o will be + * ignored. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a long, float, or double + * field, or if o is not an instance of the class + * declaring this field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #set(Object, Object) + */ + native void setLong(Object o, long value) + throws IllegalAccessException; + + /** + * Set this float Field. If the field is static, o will be + * ignored. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a float or long field, or + * if o is not an instance of the class declaring this + * field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #set(Object, Object) + */ + native void setFloat(Object o, float value) + throws IllegalAccessException; + + /** + * Set this double Field. If the field is static, o will be + * ignored. + * + * @param o the object to set this Field on + * @param value the value to set this Field to + * @throws IllegalAccessException if you could not normally access this field + * (i.e. it is not public) + * @throws IllegalArgumentException if this is not a double field, or if + * o is not an instance of the class declaring this + * field + * @throws NullPointerException if o is null and this field + * requires an instance + * @throws ExceptionInInitializerError if accessing a static field triggered + * class initialization, which then failed + * @see #set(Object, Object) + */ + native void setDouble(Object o, double value) + throws IllegalAccessException; + + /** + * Return the String in the Signature attribute for this field. If there + * is no Signature attribute, return null. + * + */ + native String getSignature(); + + /** + * Compare two objects to see if they are semantically equivalent. + * Two Fields are semantically equivalent if they have the same declaring + * class, name, and type. Since you can't create a Field except through + * the VM, this is just the == relation. + * + * @param o the object to compare to + * @return true if they are equal; false if not + */ + public boolean equals(Object o) + { + if (!(o instanceof Field)) + return false; + Field that = (Field)o; + if (clazz != that.getDeclaringClass()) + return false; + if (!name.equals(that.getName())) + return false; + if (getType() != that.getType()) + return false; + return true; + } + + /** + * Returns the element's annotation for the specified annotation type, + * or null if no such annotation exists. + * + * @param annotationClass the type of annotation to look for. + * @return this element's annotation for the specified type, or + * null if no such annotation exists. + * @throws NullPointerException if the annotation class is null. + */ + native Annotation getAnnotation(Class annotationClass); + + /** + * Returns all annotations directly defined by the element. If there are + * no annotations directly associated with the element, then a zero-length + * array will be returned. The returned array may be modified by the client + * code, but this will have no effect on the annotation content of this + * class, and hence no effect on the return value of this method for + * future callers. + * + * @return the annotations directly defined by the element. + * @since 1.5 + */ + native Annotation[] getDeclaredAnnotations(); + +} diff --git a/libjava/classpath/vm/reference/java/lang/reflect/VMMethod.java b/libjava/classpath/vm/reference/java/lang/reflect/VMMethod.java new file mode 100644 index 000000000..d8bb8b4a3 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/reflect/VMMethod.java @@ -0,0 +1,208 @@ +/* java.lang.reflect.VMMethod - VM interface for reflection of Java methods + Copyright (C) 1998, 2001, 2002, 2005, 2007, 2008 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang.reflect; + +import java.lang.annotation.Annotation; + +import java.util.Arrays; + +final class VMMethod +{ + Class clazz; + String name; + int slot; + + /** + * This field allows us to refer back to the main constructor instance. + * It is set by the constructor of Field. + */ + Method m; + + public Class getDeclaringClass() + { + return clazz; + } + + public String getName() + { + return name; + } + + /** + * Return the raw modifiers for this method. + * @return the method's modifiers + */ + native int getModifiersInternal(); + + /** + * Gets the return type of this method. + * @return the type of this method + */ + native Class getReturnType(); + + /** + * Get the parameter list for this method, in declaration order. If the + * method takes no parameters, returns a 0-length array (not null). + * + * @return a list of the types of the method's parameters + */ + native Class[] getParameterTypes(); + + /** + * Get the exception types this method says it throws, in no particular + * order. If the method has no throws clause, returns a 0-length array + * (not null). + * + * @return a list of the types in the method's throws clause + */ + native Class[] getExceptionTypes(); + + native Object invoke(Object o, Object[] args) + throws IllegalAccessException, InvocationTargetException; + + /** + * Return the String in the Signature attribute for this method. If there + * is no Signature attribute, return null. + */ + native String getSignature(); + + /** + * If this method is an annotation method, returns the default + * value for the method. If there is no default value, or if the + * method is not a member of an annotation type, returns null. + * Primitive types are wrapped. + * + * @throws TypeNotPresentException if the method returns a Class, + * and the class cannot be found + * + * @since 1.5 + */ + native Object getDefaultValue(); + + /** + *

+ * Return an array of arrays representing the annotations on each + * of the method's parameters. The outer array is aligned against + * the parameters of the method and is thus equal in length to + * the number of parameters (thus having a length zero if there are none). + * Each array element in the outer array contains an inner array which + * holds the annotations. This array has a length of zero if the parameter + * has no annotations. + *

+ *

+ * The returned annotations are serialized. Changing the annotations has + * no affect on the return value of future calls to this method. + *

+ * + * @return an array of arrays which represents the annotations used on the + * parameters of this method. The order of the array elements + * matches the declaration order of the parameters. + * @since 1.5 + */ + native Annotation[][] getParameterAnnotations(); + + /** + * Compare two objects to see if they are semantically equivalent. + * Two Methods are semantically equivalent if they have the same declaring + * class, name, parameter list, and return type. + * + * @param o the object to compare to + * @return true if they are equal; false if not + */ + public boolean equals(Object o) + { + // Implementation note: + // The following is a correct but possibly slow implementation. + // + // This class has a private field 'slot' that could be used by + // the VM implementation to "link" a particular method to a Class. + // In that case equals could be simply implemented as: + // + // if (o instanceof Method) + // { + // Method m = (Method)o; + // return m.declaringClass == this.declaringClass + // && m.slot == this.slot; + // } + // return false; + // + // If a VM uses the Method class as their native/internal representation + // then just using the following would be optimal: + // + // return this == o; + // + if (!(o instanceof Method)) + return false; + Method that = (Method)o; + if (clazz != that.getDeclaringClass()) + return false; + if (!name.equals(that.getName())) + return false; + if (getReturnType() != that.getReturnType()) + return false; + if (!Arrays.equals(getParameterTypes(), that.getParameterTypes())) + return false; + return true; + } + + /** + * Returns the element's annotation for the specified annotation type, + * or null if no such annotation exists. + * + * @param annotationClass the type of annotation to look for. + * @return this element's annotation for the specified type, or + * null if no such annotation exists. + * @throws NullPointerException if the annotation class is null. + */ + native Annotation getAnnotation(Class annotationClass); + + /** + * Returns all annotations directly defined by the element. If there are + * no annotations directly associated with the element, then a zero-length + * array will be returned. The returned array may be modified by the client + * code, but this will have no effect on the annotation content of this + * class, and hence no effect on the return value of this method for + * future callers. + * + * @return the annotations directly defined by the element. + * @since 1.5 + */ + native Annotation[] getDeclaredAnnotations(); + +} diff --git a/libjava/classpath/vm/reference/java/lang/reflect/VMProxy.java b/libjava/classpath/vm/reference/java/lang/reflect/VMProxy.java new file mode 100644 index 000000000..8c7b67a72 --- /dev/null +++ b/libjava/classpath/vm/reference/java/lang/reflect/VMProxy.java @@ -0,0 +1,135 @@ +/* VMProxy.java -- VM interface for proxy class + Copyright (C) 2005 Free Software Foundation, Inc. + +This file is part of GNU Classpath. + +GNU Classpath is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2, or (at your option) +any later version. + +GNU Classpath is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License +along with GNU Classpath; see the file COPYING. If not, write to the +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +02110-1301 USA. + +Linking this library statically or dynamically with other modules is +making a combined work based on this library. Thus, the terms and +conditions of the GNU General Public License cover the whole +combination. + +As a special exception, the copyright holders of this library give you +permission to link this library with independent modules to produce an +executable, regardless of the license terms of these independent +modules, and to copy and distribute the resulting executable under +terms of your choice, provided that you also meet, for each linked +independent module, the terms and conditions of the license of that +module. An independent module is a module which is not derived from +or based on this library. If you modify this library, you may extend +this exception to your version of the library, but you are not +obligated to do so. If you do not wish to do so, delete this +exception statement from your version. */ + + +package java.lang.reflect; + +final class VMProxy +{ + /** + * Set to true if the VM provides a native method to implement + * Proxy.getProxyClass completely, including argument verification. + * If this is true, HAVE_NATIVE_GET_PROXY_DATA and + * HAVE_NATIVE_GENERATE_PROXY_CLASS should be false. + * @see java.lang.reflect.Proxy + */ + static boolean HAVE_NATIVE_GET_PROXY_CLASS = false; + + /** + * Set to true if the VM provides a native method to implement + * the first part of Proxy.getProxyClass: generation of the array + * of methods to convert, and verification of the arguments. + * If this is true, HAVE_NATIVE_GET_PROXY_CLASS should be false. + * @see java.lang.reflect.Proxy + */ + static boolean HAVE_NATIVE_GET_PROXY_DATA = false; + + /** + * Set to true if the VM provides a native method to implement + * the second part of Proxy.getProxyClass: conversion of an array of + * methods into an actual proxy class. + * If this is true, HAVE_NATIVE_GET_PROXY_CLASS should be false. + * @see java.lang.reflect.Proxy + */ + static boolean HAVE_NATIVE_GENERATE_PROXY_CLASS = false; + + /** + * Optional native method to replace (and speed up) the pure Java + * implementation of getProxyClass. Only needed if + * VMProxy.HAVE_NATIVE_GET_PROXY_CLASS is true, this does the + * work of both getProxyData and generateProxyClass with no + * intermediate form in Java. The native code may safely assume that + * this class must be created, and does not already exist. + * + * @param loader the class loader to define the proxy class in; null + * implies the bootstrap class loader + * @param interfaces the interfaces the class will extend + * @return the generated proxy class + * @throws IllegalArgumentException if the constraints for getProxyClass + * were violated, except for problems with null + * @throws NullPointerException if `interfaces' is null or contains + * a null entry, or if handler is null + * @see #HAVE_NATIVE_GET_PROXY_CLASS + * @see #getProxyClass(ClassLoader, Class[]) + * @see #getProxyData(ClassLoader, Class[]) + * @see #generateProxyClass(ClassLoader, Proxy.ProxyData) + */ + static native Class getProxyClass(ClassLoader loader, Class[] interfaces); + + /** + * Optional native method to replace (and speed up) the pure Java + * implementation of getProxyData. Only needed if + * Configuration.HAVE_NATIVE_GET_PROXY_DATA is true. The native code + * may safely assume that a new ProxyData object must be created which + * does not duplicate any existing ones. + * + * @param loader the class loader to define the proxy class in; null + * implies the bootstrap class loader + * @param interfaces the interfaces the class will extend + * @return all data that is required to make this proxy class + * @throws IllegalArgumentException if the constraints for getProxyClass + * were violated, except for problems with null + * @throws NullPointerException if `interfaces' is null or contains + * a null entry, or if handler is null + * @see #HAVE_NATIVE_GET_PROXY_DATA + * @see #getProxyClass(ClassLoader, Class[]) + * @see #getProxyClass(ClassLoader, Class[]) + * @see Proxy.ProxyData#getProxyData(Proxy.ProxyType) + */ + static native Proxy.ProxyData getProxyData(ClassLoader loader, + Class[] interfaces); + + /** + * Optional native method to replace (and speed up) the pure Java + * implementation of generateProxyClass. Only needed if + * Configuration.HAVE_NATIVE_GENERATE_PROXY_CLASS is true. The native + * code may safely assume that a new Class must be created, and that + * the ProxyData object does not describe any existing class. + * + * @param loader the class loader to define the proxy class in; null + * implies the bootstrap class loader + * @param data the struct of information to convert to a Class. This + * has already been verified for all problems except exceeding + * VM limitations + * @return the newly generated class + * @throws IllegalArgumentException if VM limitations are exceeded + * @see #getProxyClass(ClassLoader, Class[]) + * @see #getProxyClass(ClassLoader, Class[]) + */ + static native Class generateProxyClass(ClassLoader loader, + Proxy.ProxyData data); +} -- cgit v1.2.3