Imported GNU Classpath 0.90

Imported GNU Classpath 0.90
       * scripts/makemake.tcl: LocaleData.java moved to gnu/java/locale.

       * sources.am: Regenerated.
       * gcj/javaprims.h: Regenerated.
       * Makefile.in: Regenerated.
       * gcj/Makefile.in: Regenerated.
       * include/Makefile.in: Regenerated.
       * testsuite/Makefile.in: Regenerated.

       * gnu/java/lang/VMInstrumentationImpl.java: New override.
       * gnu/java/net/local/LocalSocketImpl.java: Likewise.
       * gnu/classpath/jdwp/VMMethod.java: Likewise.
       * gnu/classpath/jdwp/VMVirtualMachine.java: Update to latest
       interface.
       * java/lang/Thread.java: Add UncaughtExceptionHandler.
       * java/lang/reflect/Method.java: Implements GenericDeclaration and
       isSynthetic(),
       * java/lang/reflect/Field.java: Likewise.
       * java/lang/reflect/Constructor.java
       * java/lang/Class.java: Implements Type, GenericDeclaration,
       getSimpleName() and getEnclosing*() methods.
       * java/lang/Class.h: Add new public methods.
       * java/lang/Math.java: Add signum(), ulp() and log10().
       * java/lang/natMath.cc (log10): New function.
       * java/security/VMSecureRandom.java: New override.
       * java/util/logging/Logger.java: Updated to latest classpath
       version.
       * java/util/logging/LogManager.java: New override.

From-SVN: r113887
This commit is contained in:
Mark Wielaard 2006-05-18 17:29:21 +00:00
parent eaec4980e1
commit 4f9533c772
1640 changed files with 126485 additions and 104808 deletions

View file

@ -1,5 +1,5 @@
/* VMClass.java -- VM Specific Class methods
Copyright (C) 2003, 2004 Free Software Foundation
Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@ -37,11 +37,14 @@ exception statement from your version. */
package java.lang;
import java.lang.annotation.Annotation;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.Type;
import java.lang.reflect.TypeVariable;
/*
* This class is a reference version, mainly for compiling a class library
@ -51,9 +54,11 @@ import java.lang.reflect.Modifier;
/**
*
* @author Etienne Gagnon <etienne.gagnon@uqam.ca>
* @author Archie Cobbs <archie@dellroad.org>
* @author C. Brian Jones <cbj@gnu.org>
* @author Etienne Gagnon (etienne.gagnon@uqam.ca)
* @author Archie Cobbs (archie@dellroad.org)
* @author C. Brian Jones (cbj@gnu.org)
* @author Tom Tromey (tromey@cygnus.com)
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
final class VMClass
{
@ -278,4 +283,172 @@ final class VMClass
*/
static native void throwException(Throwable t);
/**
* Returns the simple name for the specified class, as used in the source
* code. For normal classes, this is the content returned by
* <code>getName()</code> which follows the last ".". Anonymous
* classes have no name, and so the result of calling this method is
* "". The simple name of an array consists of the simple name of
* its component type, followed by "[]". Thus, an array with the
* component type of an anonymous class has a simple name of simply
* "[]".
*
* @param klass the class whose simple name should be returned.
* @return the simple name for this class.
*/
static String getSimpleName(Class klass)
{
if (isArray(klass))
{
return getComponentType(klass).getSimpleName() + "[]";
}
String fullName = getName(klass);
return fullName.substring(fullName.lastIndexOf(".") + 1);
}
/**
* Returns all annotations directly defined by the specified class. If
* there are no annotations associated with this class, then a zero-length
* array will be returned. The returned array may be modified by the client
* code, but this will have no effect on the annotation content of this
* class, and hence no effect on the return value of this method for
* future callers.
*
* @param klass the class whose annotations should be returned.
* @return the annotations directly defined by the specified class.
* @since 1.5
*/
static native Annotation[] getDeclaredAnnotations(Class klass);
/**
* <p>
* Returns the canonical name of the specified class, as defined by section
* 6.7 of the Java language specification. Each package, top-level class,
* top-level interface and primitive type has a canonical name. A member
* class has a canonical name, if its parent class has one. Likewise,
* an array type has a canonical name, if its component type does.
* Local or anonymous classes do not have canonical names.
* </p>
* <p>
* The canonical name for top-level classes, top-level interfaces and
* primitive types is always the same as the fully-qualified name.
* For array types, the canonical name is the canonical name of its
* component type with `[]' appended.
* </p>
* <p>
* The canonical name of a member class always refers to the place where
* the class was defined, and is composed of the canonical name of the
* defining class and the simple name of the member class, joined by `.'.
* For example, if a <code>Person</code> class has an inner class,
* <code>M</code>, then both its fully-qualified name and canonical name
* is <code>Person.M</code>. A subclass, <code>Staff</code>, of
* <code>Person</code> refers to the same inner class by the fully-qualified
* name of <code>Staff.M</code>, but its canonical name is still
* <code>Person.M</code>.
* </p>
* <p>
* Where no canonical name is present, <code>null</code> is returned.
* </p>
*
* @param klass the class whose canonical name should be retrieved.
* @return the canonical name of the class, or <code>null</code> if the
* class doesn't have a canonical name.
* @since 1.5
*/
static String getCanonicalName(Class klass)
{
if (isArray(klass))
{
String componentName = getComponentType(klass).getCanonicalName();
if (componentName != null)
return componentName + "[]";
}
if (isMemberClass(klass))
{
String memberName = getDeclaringClass(klass).getCanonicalName();
if (memberName != null)
return memberName + "." + getSimpleName(klass);
}
if (isLocalClass(klass) || isAnonymousClass(klass))
return null;
return getName(klass);
}
/**
* Returns the class which immediately encloses the specified class. If
* the class is a top-level class, this method returns <code>null</code>.
*
* @param klass the class whose enclosing class should be returned.
* @return the immediate enclosing class, or <code>null</code> if this is
* a top-level class.
* @since 1.5
*/
static native Class getEnclosingClass(Class klass);
/**
* Returns the constructor which immediately encloses the specified class.
* If the class is a top-level class, or a local or anonymous class
* immediately enclosed by a type definition, instance initializer
* or static initializer, then <code>null</code> is returned.
*
* @param klass the class whose enclosing constructor should be returned.
* @return the immediate enclosing constructor if the specified class is
* declared within a constructor. Otherwise, <code>null</code>
* is returned.
* @since 1.5
*/
static native Constructor getEnclosingConstructor(Class klass);
/**
* Returns the method which immediately encloses the specified class. If
* the class is a top-level class, or a local or anonymous class
* immediately enclosed by a type definition, instance initializer
* or static initializer, then <code>null</code> is returned.
*
* @param klass the class whose enclosing method should be returned.
* @return the immediate enclosing method if the specified class is
* declared within a method. Otherwise, <code>null</code>
* is returned.
* @since 1.5
*/
static native Method getEnclosingMethod(Class klass);
/**
* Returns the class signature as specified in Class File Format
* chapter in the VM specification, or null if the class is not
* generic.
*
* @param klass the klass to test.
* @return a ClassSignature string.
* @since 1.5
*/
static native String getClassSignature(Class klass);
/**
* Returns true if the specified class represents an anonymous class.
*
* @param klass the klass to test.
* @return true if the specified class represents an anonymous class.
* @since 1.5
*/
static native boolean isAnonymousClass(Class klass);
/**
* Returns true if the specified class represents an local class.
*
* @param klass the klass to test.
* @return true if the specified class represents an local class.
* @since 1.5
*/
static native boolean isLocalClass(Class klass);
/**
* Returns true if the specified class represents an member class.
*
* @param klass the klass to test.
* @return true if the specified class represents an member class.
* @since 1.5
*/
static native boolean isMemberClass(Class klass);
} // class VMClass

View file

@ -1,6 +1,6 @@
/* VMClassLoader.java -- Reference implementation of native interface
required by ClassLoader
Copyright (C) 1998, 2001, 2002, 2004, 2005 Free Software Foundation
Copyright (C) 1998, 2001, 2002, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@ -39,17 +39,23 @@ exception statement from your version. */
package java.lang;
import gnu.classpath.SystemProperties;
import gnu.classpath.Configuration;
import gnu.classpath.SystemProperties;
import gnu.java.lang.InstrumentationImpl;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.instrument.Instrumentation;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.ProtectionDomain;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.Vector;
import java.util.zip.ZipFile;
@ -98,6 +104,7 @@ final class VMClassLoader
"GNU Classpath",
"GNU",
Configuration.CLASSPATH_VERSION,
null,
null);
definedPackages.put(packages[i], p);
@ -235,12 +242,46 @@ final class VMClassLoader
/**
* Returns a String[] of native package names. The default
* implementation returns an empty array, or you may decide
* this needs native help.
* implementation tries to load a list of package from
* the META-INF/INDEX.LIST file in the boot jar file.
* If not found or if any exception is raised, it returns
* an empty array. You may decide this needs native help.
*/
private static String[] getBootPackages()
{
return new String[0];
URL indexList = getResource("META-INF/INDEX.LIST");
if (indexList != null)
{
try
{
Set packageSet = new HashSet();
String line;
int lineToSkip = 3;
BufferedReader reader = new BufferedReader(
new InputStreamReader(
indexList.openStream()));
while ((line = reader.readLine()) != null)
{
if (lineToSkip == 0)
{
if (line.length() == 0)
lineToSkip = 1;
else
packageSet.add(line.replace('/', '.'));
}
else
lineToSkip--;
}
reader.close();
return (String[]) packageSet.toArray(new String[packageSet.size()]);
}
catch (IOException e)
{
return new String[0];
}
}
else
return new String[0];
}
@ -345,4 +386,45 @@ final class VMClassLoader
* for this class.
*/
static native Class findLoadedClass(ClassLoader cl, String name);
/**
* The Instrumentation object created by the vm when agents are defined.
*/
static final Instrumentation instrumenter = null;
/**
* Call the transformers of the possible Instrumentation object. This
* implementation assumes the instrumenter is a
* <code>InstrumentationImpl</code> object. VM implementors would
* have to redefine this method if they provide their own implementation
* of the <code>Instrumentation</code> interface.
*
* @param loader the initiating loader
* @param name the name of the class
* @param data the data representing the classfile, in classfile format
* @param offset the offset into the data where the classfile starts
* @param len the length of the classfile data in the array
* @param pd the protection domain
* @return the new data representing the classfile
*/
static final Class defineClassWithTransformers(ClassLoader loader,
String name, byte[] data, int offset, int len, ProtectionDomain pd)
{
if (instrumenter != null)
{
byte[] modifiedData = new byte[len];
System.arraycopy(data, offset, modifiedData, 0, len);
modifiedData =
((InstrumentationImpl)instrumenter).callTransformers(loader, name,
null, pd, modifiedData);
return defineClass(loader, name, modifiedData, 0, modifiedData.length,
pd);
}
else
{
return defineClass(loader, name, data, offset, len, pd);
}
}
}

View file

@ -42,7 +42,10 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
/**
* Represents one external process. Each instance of this class is in
@ -92,6 +95,7 @@ final class VMProcess extends Process
InputStream stdout; // process output stream
InputStream stderr; // process error stream
int exitValue; // process exit value
boolean redirect; // redirect stderr -> stdout
//
// Dedicated thread that does all the fork()'ing and wait()'ing
@ -196,7 +200,8 @@ final class VMProcess extends Process
{
try
{
process.nativeSpawn(process.cmd, process.env, process.dir);
process.nativeSpawn(process.cmd, process.env, process.dir,
process.redirect);
process.state = RUNNING;
activeMap.put(new Long(process.pid), process);
}
@ -215,7 +220,8 @@ final class VMProcess extends Process
}
// Constructor
private VMProcess(String[] cmd, String[] env, File dir) throws IOException
private VMProcess(String[] cmd, String[] env, File dir, boolean redirect)
throws IOException
{
// Initialize this process
@ -223,6 +229,7 @@ final class VMProcess extends Process
this.cmd = cmd;
this.env = env;
this.dir = dir;
this.redirect = redirect;
// Add process to the new process work list and wakeup processThread
synchronized (workList)
@ -275,11 +282,20 @@ final class VMProcess extends Process
// Invoked by native code (from nativeSpawn()) to record process info.
private void setProcessInfo(OutputStream stdin,
InputStream stdout, InputStream stderr, long pid)
InputStream stdout, InputStream stderr, long pid)
{
this.stdin = stdin;
this.stdout = stdout;
this.stderr = stderr;
if (stderr == null)
this.stderr = new InputStream()
{
public int read() throws IOException
{
return -1;
}
};
else
this.stderr = stderr;
this.pid = pid;
}
@ -288,7 +304,24 @@ final class VMProcess extends Process
*/
static Process exec(String[] cmd, String[] env, File dir) throws IOException
{
return new VMProcess(cmd, env, dir);
return new VMProcess(cmd, env, dir, false);
}
static Process exec(List cmd, Map env,
File dir, boolean redirect) throws IOException
{
String[] acmd = (String[]) cmd.toArray(new String[cmd.size()]);
String[] aenv = new String[env.size()];
int i = 0;
Iterator iter = env.entrySet().iterator();
while (iter.hasNext())
{
Map.Entry entry = (Map.Entry) iter.next();
aenv[i++] = entry.getKey() + "=" + entry.getValue();
}
return new VMProcess(acmd, aenv, dir, redirect);
}
public OutputStream getOutputStream()
@ -347,7 +380,8 @@ final class VMProcess extends Process
*
* @throws IOException if the O/S process could not be created.
*/
native void nativeSpawn(String[] cmd, String[] env, File dir)
native void nativeSpawn(String[] cmd, String[] env, File dir,
boolean redirect)
throws IOException;
/**

View file

@ -37,6 +37,8 @@ exception statement from your version. */
package java.lang;
import java.util.List;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileDescriptor;
@ -50,6 +52,7 @@ import java.io.PrintStream;
* VM must implement.
*
* @author John Keiser
* @author Andrew John Hughes (gnu_andrew@member.fsf.org)
*/
final class VMSystem
{
@ -134,41 +137,77 @@ final class VMSystem
*/
public static native long currentTimeMillis();
/**
* <p>
* Returns the current value of a nanosecond-precise system timer.
* The value of the timer is an offset relative to some arbitrary fixed
* time, which may be in the future (making the value negative). This
* method is useful for timing events where nanosecond precision is
* required. This is achieved by calling this method before and after the
* event, and taking the difference betweent the two times:
* </p>
* <p>
* <code>long startTime = System.nanoTime();</code><br />
* <code>... <emph>event code</emph> ...</code><br />
* <code>long endTime = System.nanoTime();</code><br />
* <code>long duration = endTime - startTime;</code><br />
* </p>
* <p>
* Note that the value is only nanosecond-precise, and not accurate; there
* is no guarantee that the difference between two values is really a
* nanosecond. Also, the value is prone to overflow if the offset
* exceeds 2^63.
* </p>
*
* @return the time of a system timer in nanoseconds.
* @since 1.5
*/
public static long nanoTime()
{
return currentTimeMillis() * 1000;
}
/**
* Returns a list of 'name=value' pairs representing the current environment
* variables.
*
* @return a list of 'name=value' pairs.
*/
static native List environ();
/**
* Helper method which creates the standard input stream.
* VM implementors may choose to construct these streams differently.
* This method can also return null if the stream is created somewhere
* else in the VM startup sequence.
*/
static InputStream makeStandardInputStream()
{
return new BufferedInputStream(new FileInputStream(FileDescriptor.in));
}
static InputStream makeStandardInputStream()
{
return new BufferedInputStream(new FileInputStream(FileDescriptor.in));
}
/**
* Helper method which creates the standard output stream.
* VM implementors may choose to construct these streams differently.
* This method can also return null if the stream is created somewhere
* else in the VM startup sequence.
*/
static PrintStream makeStandardOutputStream()
{
return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true);
}
static PrintStream makeStandardOutputStream()
{
return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)), true);
}
/**
* Helper method which creates the standard error stream.
* VM implementors may choose to construct these streams differently.
* This method can also return null if the stream is created somewhere
* else in the VM startup sequence.
*/
static PrintStream makeStandardErrorStream()
{
return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true);
}
static PrintStream makeStandardErrorStream()
{
return new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.err)), true);
}
/**
* Gets the value of an environment variable.
* Always returning null is a valid (but not very useful) implementation.

View file

@ -1,5 +1,5 @@
/* VMThread -- VM interface for Thread of executable code
Copyright (C) 2003, 2004, 2005 Free Software Foundation
Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation
This file is part of GNU Classpath.
@ -123,7 +123,9 @@ final class VMThread
{
try
{
thread.group.uncaughtException(thread, t);
Thread.UncaughtExceptionHandler handler;
handler = thread.getUncaughtExceptionHandler();
handler.uncaughtException(thread, t);
}
catch(Throwable ignore)
{

View file

@ -1,5 +1,5 @@
/* java.lang.reflect.Constructor - reflection of Java constructors
Copyright (C) 1998, 2001 Free Software Foundation, Inc.
Copyright (C) 1998, 2001, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -38,6 +38,10 @@ exception statement from your version. */
package java.lang.reflect;
import gnu.java.lang.ClassHelper;
import gnu.java.lang.reflect.MethodSignatureParser;
import java.util.Arrays;
/**
@ -74,11 +78,15 @@ import java.util.Arrays;
* @status updated to 1.4
*/
public final class Constructor
extends AccessibleObject implements Member
extends AccessibleObject
implements GenericDeclaration, Member
{
private Class clazz;
private int slot;
private static final int CONSTRUCTOR_MODIFIERS
= Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC;
/**
* This class is uninstantiable except from native code.
*/
@ -111,6 +119,13 @@ extends AccessibleObject implements Member
return getDeclaringClass().getName();
}
/**
* Return the raw modifiers for this constructor. In particular
* this will include the synthetic and varargs bits.
* @return the constructor's modifiers
*/
private native int getModifiersInternal();
/**
* Gets the modifiers this constructor uses. Use the <code>Modifier</code>
* class to interpret the values. A constructor can only have a subset of the
@ -119,7 +134,31 @@ extends AccessibleObject implements Member
* @return an integer representing the modifiers to this Member
* @see Modifier
*/
public native int getModifiers();
public int getModifiers()
{
return getModifiersInternal() & CONSTRUCTOR_MODIFIERS;
}
/**
* Return true if this constructor is synthetic, false otherwise.
* A synthetic member is one which is created by the compiler,
* and which does not appear in the user's source code.
* @since 1.5
*/
public boolean isSynthetic()
{
return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
}
/**
* Return true if this is a varargs constructor, that is if
* the constructor takes a variable number of arguments.
* @since 1.5
*/
public boolean isVarArgs()
{
return (getModifiersInternal() & Modifier.VARARGS) != 0;
}
/**
* Get the parameter list for this constructor, in declaration order. If the
@ -184,15 +223,15 @@ extends AccessibleObject implements Member
public String toString()
{
// 128 is a reasonable buffer initial size for constructor
StringBuffer sb = new StringBuffer(128);
StringBuilder sb = new StringBuilder(128);
Modifier.toString(getModifiers(), sb).append(' ');
sb.append(getDeclaringClass().getName()).append('(');
Class[] c = getParameterTypes();
if (c.length > 0)
{
sb.append(c[0].getName());
sb.append(ClassHelper.getUserName(c[0]));
for (int i = 1; i < c.length; i++)
sb.append(',').append(c[i].getName());
sb.append(',').append(ClassHelper.getUserName(c[i]));
}
sb.append(')');
c = getExceptionTypes();
@ -204,7 +243,46 @@ extends AccessibleObject implements Member
}
return sb.toString();
}
/* FIXME[GENERICS]: Add X extends GenericDeclaration and TypeVariable<X> */
static void addTypeParameters(StringBuilder sb, TypeVariable[] typeArgs)
{
if (typeArgs.length == 0)
return;
sb.append('<');
for (int i = 0; i < typeArgs.length; ++i)
{
if (i > 0)
sb.append(',');
sb.append(typeArgs[i]);
}
sb.append("> ");
}
public String toGenericString()
{
StringBuilder sb = new StringBuilder(128);
Modifier.toString(getModifiers(), sb).append(' ');
addTypeParameters(sb, getTypeParameters());
sb.append(getDeclaringClass().getName()).append('(');
Type[] types = getGenericParameterTypes();
if (types.length > 0)
{
sb.append(types[0]);
for (int i = 1; i < types.length; ++i)
sb.append(',').append(types[i]);
}
sb.append(')');
types = getGenericExceptionTypes();
if (types.length > 0)
{
sb.append(" throws ").append(types[0]);
for (int i = 1; i < types.length; i++)
sb.append(',').append(types[i]);
}
return sb.toString();
}
/**
* Create a new instance by invoking the constructor. Arguments are
* automatically unwrapped and widened, if needed.<p>
@ -246,4 +324,75 @@ extends AccessibleObject implements Member
int slot)
throws InstantiationException, IllegalAccessException,
InvocationTargetException;
/**
* Returns an array of <code>TypeVariable</code> objects that represents
* the type variables declared by this constructor, in declaration order.
* An array of size zero is returned if this constructor has no type
* variables.
*
* @return the type variables associated with this constructor.
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
/* FIXME[GENERICS]: Add <Constructor<T>> */
public TypeVariable[] getTypeParameters()
{
String sig = getSignature();
if (sig == null)
return new TypeVariable[0];
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getTypeParameters();
}
/**
* Return the String in the Signature attribute for this constructor. If there
* is no Signature attribute, return null.
*/
private native String getSignature();
/**
* Returns an array of <code>Type</code> objects that represents
* the exception types declared by this constructor, in declaration order.
* An array of size zero is returned if this constructor declares no
* exceptions.
*
* @return the exception types declared by this constructor.
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type[] getGenericExceptionTypes()
{
String sig = getSignature();
if (sig == null)
return getExceptionTypes();
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getGenericExceptionTypes();
}
/**
* Returns an array of <code>Type</code> objects that represents
* the parameter list for this constructor, in declaration order.
* An array of size zero is returned if this constructor takes no
* parameters.
*
* @return a list of the types of the constructor's parameters
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type[] getGenericParameterTypes()
{
String sig = getSignature();
if (sig == null)
return getParameterTypes();
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getGenericParameterTypes();
}
}

View file

@ -1,5 +1,5 @@
/* java.lang.reflect.Field - reflection of Java fields
Copyright (C) 1998, 2001 Free Software Foundation, Inc.
Copyright (C) 1998, 2001, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -38,6 +38,10 @@ exception statement from your version. */
package java.lang.reflect;
import gnu.java.lang.ClassHelper;
import gnu.java.lang.reflect.FieldSignatureParser;
/**
* The Field class represents a member variable of a class. It also allows
* dynamic access to a member, via reflection. This works for both
@ -78,6 +82,11 @@ extends AccessibleObject implements Member
private String name;
private int slot;
private static final int FIELD_MODIFIERS
= Modifier.FINAL | Modifier.PRIVATE | Modifier.PROTECTED
| Modifier.PUBLIC | Modifier.STATIC | Modifier.TRANSIENT
| Modifier.VOLATILE;
/**
* This class is uninstantiable except natively.
*/
@ -107,6 +116,12 @@ extends AccessibleObject implements Member
return name;
}
/**
* Return the raw modifiers for this field.
* @return the field's modifiers
*/
private native int getModifiersInternal();
/**
* Gets the modifiers this field uses. Use the <code>Modifier</code>
* class to interpret the values. A field can only have a subset of the
@ -116,7 +131,29 @@ extends AccessibleObject implements Member
* @return an integer representing the modifiers to this Member
* @see Modifier
*/
public native int getModifiers();
public int getModifiers()
{
return getModifiersInternal() & FIELD_MODIFIERS;
}
/**
* Return true if this field is synthetic, false otherwise.
* @since 1.5
*/
public boolean isSynthetic()
{
return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
}
/**
* Return true if this field represents an enum constant,
* false otherwise.
* @since 1.5
*/
public boolean isEnumConstant()
{
return (getModifiersInternal() & Modifier.ENUM) != 0;
}
/**
* Gets the type of this field.
@ -169,14 +206,24 @@ extends AccessibleObject implements Member
public String toString()
{
// 64 is a reasonable buffer initial size for field
StringBuffer sb = new StringBuffer(64);
StringBuilder sb = new StringBuilder(64);
Modifier.toString(getModifiers(), sb).append(' ');
sb.append(getType().getName()).append(' ');
sb.append(ClassHelper.getUserName(getType())).append(' ');
sb.append(getDeclaringClass().getName()).append('.');
sb.append(getName());
return sb.toString();
}
public String toGenericString()
{
StringBuilder sb = new StringBuilder(64);
Modifier.toString(getModifiers(), sb).append(' ');
sb.append(getGenericType()).append(' ');
sb.append(getDeclaringClass().getName()).append('.');
sb.append(getName());
return sb.toString();
}
/**
* Get the value of this Field. If it is primitive, it will be wrapped
* in the appropriate wrapper type (boolean = java.lang.Boolean).<p>
@ -586,4 +633,30 @@ extends AccessibleObject implements Member
*/
public native void setDouble(Object o, double value)
throws IllegalAccessException;
/**
* Return the generic type of the field. If the field type is not a generic
* type, the method returns the same as <code>getType()</code>.
*
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type getGenericType()
{
String signature = getSignature();
if (signature == null)
return getType();
FieldSignatureParser p = new FieldSignatureParser(getDeclaringClass(),
signature);
return p.getFieldType();
}
/**
* Return the String in the Signature attribute for this field. If there
* is no Signature attribute, return null.
*/
private native String getSignature();
}

View file

@ -1,5 +1,5 @@
/* java.lang.reflect.Method - reflection of Java methods
Copyright (C) 1998, 2001, 2002 Free Software Foundation, Inc.
Copyright (C) 1998, 2001, 2002, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@ -38,6 +38,10 @@ exception statement from your version. */
package java.lang.reflect;
import gnu.java.lang.ClassHelper;
import gnu.java.lang.reflect.MethodSignatureParser;
import java.util.Arrays;
/**
@ -74,12 +78,17 @@ import java.util.Arrays;
* @status updated to 1.4
*/
public final class Method
extends AccessibleObject implements Member
extends AccessibleObject implements Member, GenericDeclaration
{
Class declaringClass;
String name;
int slot;
private static final int METHOD_MODIFIERS
= Modifier.ABSTRACT | Modifier.FINAL | Modifier.NATIVE
| Modifier.PRIVATE | Modifier.PROTECTED | Modifier.PUBLIC
| Modifier.STATIC | Modifier.STRICT | Modifier.SYNCHRONIZED;
/**
* This class is uninstantiable.
*/
@ -109,6 +118,12 @@ extends AccessibleObject implements Member
return name;
}
/**
* Return the raw modifiers for this method.
* @return the method's modifiers
*/
private native int getModifiersInternal();
/**
* Gets the modifiers this method uses. Use the <code>Modifier</code>
* class to interpret the values. A method can only have a subset of the
@ -118,7 +133,40 @@ extends AccessibleObject implements Member
* @return an integer representing the modifiers to this Member
* @see Modifier
*/
public native int getModifiers();
public int getModifiers()
{
return getModifiersInternal() & METHOD_MODIFIERS;
}
/**
* Return true if this method is a bridge method. A bridge method
* is generated by the compiler in some situations involving
* generics and inheritance.
* @since 1.5
*/
public boolean isBridge()
{
return (getModifiersInternal() & Modifier.BRIDGE) != 0;
}
/**
* Return true if this method is synthetic, false otherwise.
* @since 1.5
*/
public boolean isSynthetic()
{
return (getModifiersInternal() & Modifier.SYNTHETIC) != 0;
}
/**
* Return true if this is a varargs method, that is if
* the method takes a variable number of arguments.
* @since 1.5
*/
public boolean isVarArgs()
{
return (getModifiersInternal() & Modifier.VARARGS) != 0;
}
/**
* Gets the return type of this method.
@ -210,17 +258,17 @@ extends AccessibleObject implements Member
public String toString()
{
// 128 is a reasonable buffer initial size for constructor
StringBuffer sb = new StringBuffer(128);
StringBuilder sb = new StringBuilder(128);
Modifier.toString(getModifiers(), sb).append(' ');
sb.append(getUserTypeName(getReturnType().getName())).append(' ');
sb.append(ClassHelper.getUserName(getReturnType())).append(' ');
sb.append(getDeclaringClass().getName()).append('.');
sb.append(getName()).append('(');
Class[] c = getParameterTypes();
if (c.length > 0)
{
sb.append(getUserTypeName(c[0].getName()));
sb.append(ClassHelper.getUserName(c[0]));
for (int i = 1; i < c.length; i++)
sb.append(',').append(getUserTypeName(c[i].getName()));
sb.append(',').append(ClassHelper.getUserName(c[i]));
}
sb.append(')');
c = getExceptionTypes();
@ -233,53 +281,31 @@ extends AccessibleObject implements Member
return sb.toString();
}
private static String getUserTypeName(String typeSpec)
public String toGenericString()
{
int pos = 0;
String typeName = "";
String arrayPart = "";
while (typeSpec.charAt(pos) == '[')
// 128 is a reasonable buffer initial size for constructor
StringBuilder sb = new StringBuilder(128);
Modifier.toString(getModifiers(), sb).append(' ');
Constructor.addTypeParameters(sb, getTypeParameters());
sb.append(getGenericReturnType()).append(' ');
sb.append(getDeclaringClass().getName()).append('.');
sb.append(getName()).append('(');
Type[] types = getGenericParameterTypes();
if (types.length > 0)
{
arrayPart += "[]";
++pos;
sb.append(types[0]);
for (int i = 1; i < types.length; i++)
sb.append(',').append(types[i]);
}
switch (typeSpec.charAt(pos))
sb.append(')');
types = getGenericExceptionTypes();
if (types.length > 0)
{
case 'Z':
typeName = "boolean";
break;
case 'B':
typeName = "byte";
break;
case 'C':
typeName = "char";
break;
case 'D':
typeName = "double";
break;
case 'F':
typeName = "float";
break;
case 'I':
typeName = "int";
break;
case 'J':
typeName = "long";
break;
case 'S':
typeName = "short";
break;
case 'L':
typeName = typeSpec.substring(pos + 1, typeSpec.length() - 1);
break;
default:
typeName = typeSpec;
break;
sb.append(" throws ").append(types[0]);
for (int i = 1; i < types.length; i++)
sb.append(',').append(types[i]);
}
return typeName + arrayPart;
return sb.toString();
}
/**
@ -336,4 +362,93 @@ extends AccessibleObject implements Member
private native Object invokeNative(Object o, Object[] args,
Class declaringClass, int slot)
throws IllegalAccessException, InvocationTargetException;
/**
* Returns an array of <code>TypeVariable</code> objects that represents
* the type variables declared by this constructor, in declaration order.
* An array of size zero is returned if this class has no type
* variables.
*
* @return the type variables associated with this class.
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
/* FIXME[GENERICS]: Should be TypeVariable<Method>[] */
public TypeVariable[] getTypeParameters()
{
String sig = getSignature();
if (sig == null)
return new TypeVariable[0];
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getTypeParameters();
}
/**
* Return the String in the Signature attribute for this method. If there
* is no Signature attribute, return null.
*/
private native String getSignature();
/**
* Returns an array of <code>Type</code> objects that represents
* the exception types declared by this method, in declaration order.
* An array of size zero is returned if this method declares no
* exceptions.
*
* @return the exception types declared by this method.
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type[] getGenericExceptionTypes()
{
String sig = getSignature();
if (sig == null)
return getExceptionTypes();
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getGenericExceptionTypes();
}
/**
* Returns an array of <code>Type</code> objects that represents
* the parameter list for this method, in declaration order.
* An array of size zero is returned if this method takes no
* parameters.
*
* @return a list of the types of the method's parameters
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type[] getGenericParameterTypes()
{
String sig = getSignature();
if (sig == null)
return getParameterTypes();
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getGenericParameterTypes();
}
/**
* Returns the return type of this method.
*
* @return the return type of this method
* @throws GenericSignatureFormatError if the generic signature does
* not conform to the format specified in the Virtual Machine
* specification, version 3.
* @since 1.5
*/
public Type getGenericReturnType()
{
String sig = getSignature();
if (sig == null)
return getReturnType();
MethodSignatureParser p = new MethodSignatureParser(this, sig);
return p.getGenericReturnType();
}
}

View file

@ -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);
}

View file

@ -0,0 +1,134 @@
/* VMSecureRandom.java -- random seed generator.
Copyright (C) 2006 Free Software Foundation, Inc.
This file is a part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or (at
your option) any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
USA
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version. */
package java.security;
import gnu.classpath.SystemProperties;
import gnu.java.security.action.GetSecurityPropertyAction;
import java.net.URL;
/**
* VM-specific methods for generating real (or almost real) random
* seeds. VM implementors should write a version of this class that
* reads random bytes from some system source.
*
* <p>The default implementation of this class runs eight threads that
* increment counters in a tight loop, and XORs each counter to
* produce one byte of seed data. This is not very efficient, and is
* not guaranteed to be random (the thread scheduler is probably
* deterministic, after all). If possible, VM implementors should
* reimplement this class so it obtains a random seed from a system
* facility, such as a system entropy gathering device or hardware
* random number generator.
*/
final class VMSecureRandom
{
/**
* Generate a random seed. Implementations are free to generate
* fewer random bytes than are requested, and leave the remaining
* bytes of the destination buffer as zeros. Implementations SHOULD,
* however, make a best-effort attempt to satisfy the request.
*
* @param buffer The destination buffer.
* @param offset The offset in the buffer to start putting bytes.
* @param length The number of random bytes to generate.
*/
static int generateSeed(byte[] buffer, int offset, int length)
{
if (length < 0)
throw new IllegalArgumentException("length must be nonnegative");
if (offset < 0 || offset + length > buffer.length)
throw new IndexOutOfBoundsException();
Spinner[] spinners = new Spinner[8];
int n = 0x1;
for (int i = 0; i < spinners.length; i++)
{
spinners[i] = new Spinner((byte) n);
Thread t = new Thread(spinners[i]);
t.start();
n <<= 1;
}
// Wait until at least one spinner has started.
while (!(spinners[0].running || spinners[1].running || spinners[2].running
|| spinners[3].running || spinners[4].running || spinners[5].running
|| spinners[6].running || spinners[7].running))
{
Thread.yield();
}
for (int i = offset; i < length; i++)
{
buffer[i] = (byte) (spinners[0].value ^ spinners[1].value ^ spinners[2].value
^ spinners[3].value ^ spinners[4].value ^ spinners[5].value
^ spinners[6].value ^ spinners[7].value);
Thread.yield();
}
for (int i = 0; i < spinners.length; i++)
spinners[i].stop();
return length;
}
static class Spinner implements Runnable
{
volatile byte value;
volatile boolean running;
Spinner(final byte initial)
{
value = initial;
}
public void run()
{
running = true;
while (running)
value++;
}
private void stop()
{
running = false;
}
}
}