diff options
author | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
---|---|---|
committer | Tom Tromey <tromey@gcc.gnu.org> | 2007-01-09 19:58:05 +0000 |
commit | 97b8365cafc3a344a22d3980b8ed885f5c6d8357 (patch) | |
tree | 996a5f57d4a68c53473382e45cb22f574cb3e4db /libjava/classpath/vm/reference/java | |
parent | c648dedbde727ca3f883bb5fd773aa4af70d3369 (diff) | |
download | gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.zip gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.gz gcc-97b8365cafc3a344a22d3980b8ed885f5c6d8357.tar.bz2 |
Merged gcj-eclipse branch to trunk.
From-SVN: r120621
Diffstat (limited to 'libjava/classpath/vm/reference/java')
9 files changed, 199 insertions, 79 deletions
diff --git a/libjava/classpath/vm/reference/java/io/VMFile.java b/libjava/classpath/vm/reference/java/io/VMFile.java index 2f48aad..13d256d 100644 --- a/libjava/classpath/vm/reference/java/io/VMFile.java +++ b/libjava/classpath/vm/reference/java/io/VMFile.java @@ -38,6 +38,9 @@ exception statement from your version. */ package java.io; +import java.net.MalformedURLException; +import java.net.URL; + import gnu.classpath.Configuration; import gnu.java.io.PlatformHelper; @@ -209,6 +212,108 @@ final class VMFile } /** + * Returns the path as an absolute path name. The value returned is the + * current directory plus the separatory string plus the path of the file. + * The current directory is determined from the <code>user.dir</code> system + * property. + * + * @param path the path to convert to absolute path + * + * @return the absolute path that corresponds to <code>path</code> + */ + static String getAbsolutePath(String path) + { + if (File.separatorChar == '\\' + && path.length() > 0 && path.charAt (0) == '\\') + { + // On Windows, even if the path starts with a '\\' it is not + // really absolute until we prefix the drive specifier from + // the current working directory to it. + return System.getProperty ("user.dir").substring (0, 2) + path; + } + else if (File.separatorChar == '\\' + && path.length() > 1 && path.charAt (1) == ':' + && ((path.charAt (0) >= 'a' && path.charAt (0) <= 'z') + || (path.charAt (0) >= 'A' && path.charAt (0) <= 'Z'))) + { + // On Windows, a process has a current working directory for + // each drive and a path like "G:foo\bar" would mean the + // absolute path "G:\wombat\foo\bar" if "\wombat" is the + // working directory on the G drive. + String drvDir = null; + try + { + drvDir = new File (path.substring (0, 2)).getCanonicalPath(); + } + catch (IOException e) + { + drvDir = path.substring (0, 2) + "\\"; + } + + // Note: this would return "C:\\." for the path "C:.", if "\" + // is the working folder on the C drive, but this is + // consistent with what Sun's JRE 1.4.1.01 actually returns! + if (path.length() > 2) + return drvDir + '\\' + path.substring (2, path.length()); + else + return drvDir; + } + else if (path.equals("")) + return System.getProperty ("user.dir"); + else + return System.getProperty ("user.dir") + File.separatorChar + path; + } + + /** + * This method returns true if the path represents an absolute file + * path and false if it does not. The definition of an absolute path varies + * by system. As an example, on GNU systems, a path is absolute if it starts + * with a "/". + * + * @param path the path to check + * + * @return <code>true</code> if path represents an absolute file name, + * <code>false</code> otherwise. + */ + static boolean isAbsolute(String path) + { + if (File.separatorChar == '\\') + return path.startsWith(File.separator + File.separator) + || (path.length() > 2 + && ((path.charAt(0) >= 'a' && path.charAt(0) <= 'z') + || (path.charAt(0) >= 'A' && path.charAt(0) <= 'Z')) + && path.charAt(1) == ':' + && path.charAt(2) == '\\'); + else + return path.startsWith(File.separator); + } + + /** + * Returns a <code>URL</code> with the <code>file:</code> + * protocol that represents this file. The exact form of this URL is + * system dependent. + * + * @param file the file to convert to URL + * + * @return a <code>URL</code> for this object. + * + * @throws MalformedURLException if the URL cannot be created + * successfully. + */ + static URL toURL(File file) + throws MalformedURLException + { + // On Win32, Sun's JDK returns URLs of the form "file:/c:/foo/bar.txt", + // while on UNIX, it returns URLs of the form "file:/foo/bar.txt". + if (File.separatorChar == '\\') + return new URL ("file:/" + file.getAbsolutePath().replace ('\\', '/') + + (file.isDirectory() ? "/" : "")); + else + return new URL ("file:" + file.getAbsolutePath() + + (file.isDirectory() ? "/" : "")); + } + + /** * This method returns a canonical representation of the pathname of * this file. The actual form of the canonical representation is * system-dependent. On the GNU system, conversion to canonical diff --git a/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java b/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java index 5fb56fc..be0f8eb 100644 --- a/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java +++ b/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java @@ -40,10 +40,7 @@ exception statement from your version. */ package java.io; import gnu.classpath.Configuration; -import gnu.classpath.VMStackWalker; import java.lang.reflect.Constructor; -import java.security.AccessController; -import java.security.PrivilegedAction; final class VMObjectInputStream { @@ -56,42 +53,6 @@ final class VMObjectInputStream } /** - * PrivilegedAction needed for Class.getClassLoader() - */ - private static PrivilegedAction loaderAction = new PrivilegedAction() - { - /** - * Returns the first user defined class loader on the call stack, or the - * context class loader of the current thread, when no non-null class loader - * was found. - */ - public Object run() - { - Class[] ctx = VMStackWalker.getClassContext(); - - for (int i = 0; i < ctx.length; i++) - { - ClassLoader cl = ctx[i].getClassLoader(); - if (cl != null) - return cl; - } - return Thread.currentThread().getContextClassLoader(); - } - }; - - /** - * Returns the first user defined class loader on the call stack, or the - * context class loader of the current thread, when no non-null class loader - * was found. - * - * @return the class loader - */ - static ClassLoader currentClassLoader() - { - return (ClassLoader) AccessController.doPrivileged(loaderAction); - } - - /** * Allocates a new Object of type clazz but without running the * default constructor on it. It then calls the given constructor on * it. The given constructor method comes from the constr_clazz diff --git a/libjava/classpath/vm/reference/java/lang/VMClassLoader.java b/libjava/classpath/vm/reference/java/lang/VMClassLoader.java index 897df51..e56152d 100644 --- a/libjava/classpath/vm/reference/java/lang/VMClassLoader.java +++ b/libjava/classpath/vm/reference/java/lang/VMClassLoader.java @@ -415,8 +415,9 @@ final class VMClassLoader { byte[] modifiedData = new byte[len]; System.arraycopy(data, offset, modifiedData, 0, len); + String jvmName = name.replace('.', '/'); modifiedData = - ((InstrumentationImpl)instrumenter).callTransformers(loader, name, + ((InstrumentationImpl)instrumenter).callTransformers(loader, jvmName, null, pd, modifiedData); return defineClass(loader, name, modifiedData, 0, modifiedData.length, diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Constructor.java b/libjava/classpath/vm/reference/java/lang/reflect/Constructor.java index 521190b..eebee5f 100644 --- a/libjava/classpath/vm/reference/java/lang/reflect/Constructor.java +++ b/libjava/classpath/vm/reference/java/lang/reflect/Constructor.java @@ -77,11 +77,11 @@ import java.util.Arrays; * @since 1.1 * @status updated to 1.4 */ -public final class Constructor +public final class Constructor<T> extends AccessibleObject implements GenericDeclaration, Member { - private Class clazz; + private Class<T> clazz; private int slot; private static final int CONSTRUCTOR_MODIFIERS @@ -104,7 +104,7 @@ public final class Constructor * Gets the class that declared this constructor. * @return the class that declared this member */ - public Class getDeclaringClass() + public Class<T> getDeclaringClass() { return clazz; } @@ -166,7 +166,7 @@ public final class Constructor * * @return a list of the types of the constructor's parameters */ - public native Class[] getParameterTypes(); + public native Class<?>[] getParameterTypes(); /** * Get the exception types this constructor says it throws, in no particular @@ -175,7 +175,7 @@ public final class Constructor * * @return a list of the types in the constructor's throws clause */ - public native Class[] getExceptionTypes(); + public native Class<?>[] getExceptionTypes(); /** * Compare two objects to see if they are semantically equivalent. @@ -244,8 +244,8 @@ public final class Constructor return sb.toString(); } - /* FIXME[GENERICS]: Add X extends GenericDeclaration and TypeVariable<X> */ - static void addTypeParameters(StringBuilder sb, TypeVariable[] typeArgs) + static <X extends GenericDeclaration> + void addTypeParameters(StringBuilder sb, TypeVariable<X>[] typeArgs) { if (typeArgs.length == 0) return; @@ -313,15 +313,15 @@ public final class Constructor * @throws ExceptionInInitializerError if construction triggered class * initialization, which then failed */ - public Object newInstance(Object args[]) + public T newInstance(Object... args) throws InstantiationException, IllegalAccessException, InvocationTargetException { return constructNative(args, clazz, slot); } - private native Object constructNative(Object[] args, Class declaringClass, - int slot) + private native T constructNative(Object[] args, Class declaringClass, + int slot) throws InstantiationException, IllegalAccessException, InvocationTargetException; @@ -337,8 +337,7 @@ public final class Constructor * specification, version 3. * @since 1.5 */ - /* FIXME[GENERICS]: Add <Constructor<T>> */ - public TypeVariable[] getTypeParameters() + public TypeVariable<Constructor<T>>[] getTypeParameters() { String sig = getSignature(); if (sig == null) @@ -395,4 +394,3 @@ public final class Constructor return p.getGenericParameterTypes(); } } - diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Field.java b/libjava/classpath/vm/reference/java/lang/reflect/Field.java index 5121700..5db1fa3 100644 --- a/libjava/classpath/vm/reference/java/lang/reflect/Field.java +++ b/libjava/classpath/vm/reference/java/lang/reflect/Field.java @@ -102,7 +102,7 @@ extends AccessibleObject implements Member * is a non-inherited member. * @return the class that declared this member */ - public Class getDeclaringClass() + public Class<?> getDeclaringClass() { return declaringClass; } @@ -159,7 +159,7 @@ extends AccessibleObject implements Member * Gets the type of this field. * @return the type of this field */ - public native Class getType(); + public native Class<?> getType(); /** * Compare two objects to see if they are semantically equivalent. @@ -213,7 +213,7 @@ extends AccessibleObject implements Member sb.append(getName()); return sb.toString(); } - + public String toGenericString() { StringBuilder sb = new StringBuilder(64); @@ -658,5 +658,4 @@ extends AccessibleObject implements Member * is no Signature attribute, return null. */ private native String getSignature(); - } diff --git a/libjava/classpath/vm/reference/java/lang/reflect/Method.java b/libjava/classpath/vm/reference/java/lang/reflect/Method.java index a992024..c520f05 100644 --- a/libjava/classpath/vm/reference/java/lang/reflect/Method.java +++ b/libjava/classpath/vm/reference/java/lang/reflect/Method.java @@ -104,7 +104,7 @@ extends AccessibleObject implements Member, GenericDeclaration * is a non-inherited member. * @return the class that declared this member */ - public Class getDeclaringClass() + public Class<?> getDeclaringClass() { return declaringClass; } @@ -172,7 +172,7 @@ extends AccessibleObject implements Member, GenericDeclaration * Gets the return type of this method. * @return the type of this method */ - public native Class getReturnType(); + public native Class<?> getReturnType(); /** * Get the parameter list for this method, in declaration order. If the @@ -180,7 +180,7 @@ extends AccessibleObject implements Member, GenericDeclaration * * @return a list of the types of the method's parameters */ - public native Class[] getParameterTypes(); + public native Class<?>[] getParameterTypes(); /** * Get the exception types this method says it throws, in no particular @@ -189,7 +189,7 @@ extends AccessibleObject implements Member, GenericDeclaration * * @return a list of the types in the method's throws clause */ - public native Class[] getExceptionTypes(); + public native Class<?>[] getExceptionTypes(); /** * Compare two objects to see if they are semantically equivalent. @@ -349,7 +349,7 @@ extends AccessibleObject implements Member, GenericDeclaration * @throws ExceptionInInitializerError if accessing a static method triggered * class initialization, which then failed */ - public Object invoke(Object o, Object[] args) + public Object invoke(Object o, Object... args) throws IllegalAccessException, InvocationTargetException { return invokeNative(o, args, declaringClass, slot); @@ -375,8 +375,7 @@ extends AccessibleObject implements Member, GenericDeclaration * specification, version 3. * @since 1.5 */ - /* FIXME[GENERICS]: Should be TypeVariable<Method>[] */ - public TypeVariable[] getTypeParameters() + public TypeVariable<Method>[] getTypeParameters() { String sig = getSignature(); if (sig == null) @@ -451,4 +450,3 @@ extends AccessibleObject implements Member, GenericDeclaration return p.getGenericReturnType(); } } - diff --git a/libjava/classpath/vm/reference/java/net/VMInetAddress.java b/libjava/classpath/vm/reference/java/net/VMInetAddress.java index 19f5d7d..a99c216 100644 --- a/libjava/classpath/vm/reference/java/net/VMInetAddress.java +++ b/libjava/classpath/vm/reference/java/net/VMInetAddress.java @@ -84,4 +84,14 @@ class VMInetAddress implements Serializable */ public static native byte[][] getHostByName(String hostname) throws UnknownHostException; + + /** + * Return the IP address represented by a literal address. + * Will return null if the literal address is not valid. + * + * @param address the name of the host + * + * @return The IP address as a byte array + */ + public static native byte[] aton(String address); } diff --git a/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java b/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java index 47f8032..7f1e3ad 100644 --- a/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java +++ b/libjava/classpath/vm/reference/java/net/VMNetworkInterface.java @@ -40,6 +40,9 @@ package java.net; import gnu.classpath.Configuration; +import java.nio.ByteBuffer; +import java.util.HashSet; +import java.util.Set; import java.util.Vector; /** @@ -54,22 +57,67 @@ import java.util.Vector; */ final class VMNetworkInterface { + String name; + Set addresses; + + VMNetworkInterface(String name) + { + this.name = name; + addresses = new HashSet(); + } + + /** + * Creates a dummy instance which represents any network + * interface. + */ + public VMNetworkInterface() + { + addresses = new HashSet(); + try + { + addresses.add(InetAddress.getByName("0.0.0.0")); + } + catch (UnknownHostException _) + { + // Cannot happen. + } + } + static - { - if (Configuration.INIT_LOAD_LIBRARY) - System.loadLibrary("javanet"); - } + { + if (Configuration.INIT_LOAD_LIBRARY) + System.loadLibrary("javanet"); + + initIds(); + } + + private static native void initIds(); /** - * Returns a Vector of InetAddresses. The returned value will be - * 'condensed', meaning that all elements with the same interface - * name will be collapesed into one InetAddress for that name - * containing all addresses before the returning the result to the - * user. This means the native method can be implemented in a naive - * way mapping each address/interface to a name even if that means - * that the Vector contains multiple InetAddresses with the same - * interface name. + * Return a list of VM network interface objects. + * + * @return The list of network interfaces. + * @throws SocketException */ - public static native Vector getInterfaces() + public static native VMNetworkInterface[] getVMInterfaces() throws SocketException; + + private void addAddress(ByteBuffer addr) + throws SocketException, UnknownHostException + { + if (addr.remaining() == 4) + { + byte[] ipv4 = new byte[4]; + addr.get(ipv4); + addresses.add(Inet4Address.getByAddress(ipv4)); + } + else if (addr.remaining() == 16) + { + byte[] ipv6 = new byte[16]; + addr.get(ipv6); + addresses.add(Inet6Address.getByAddress(ipv6)); + } + else + throw new SocketException("invalid interface address"); + } } diff --git a/libjava/classpath/vm/reference/java/nio/channels/VMChannels.java b/libjava/classpath/vm/reference/java/nio/channels/VMChannels.java index e58d7fb..c833b6e 100644 --- a/libjava/classpath/vm/reference/java/nio/channels/VMChannels.java +++ b/libjava/classpath/vm/reference/java/nio/channels/VMChannels.java @@ -40,7 +40,7 @@ package java.nio.channels; import gnu.java.nio.ChannelInputStream; import gnu.java.nio.ChannelOutputStream; -import gnu.java.nio.channels.FileChannelImpl; +import gnu.java.nio.FileChannelImpl; import java.io.FileInputStream; import java.io.FileOutputStream; |