diff options
author | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-15 23:20:01 +0000 |
---|---|---|
committer | mark <mark@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-11-15 23:20:01 +0000 |
commit | 3b3101d8b5ae4f08a16c0b7111da6cad41bbd282 (patch) | |
tree | a5eb7cf42a51869cc8aa1fad7ad6a90cca47fdd8 /libjava/classpath/vm | |
parent | 7e55c49d7d91ef9f09e93c1100119b1ab3652446 (diff) | |
download | gcc-3b3101d8b5ae4f08a16c0b7111da6cad41bbd282.tar.gz |
Imported GNU Classpath 0.19 + gcj-import-20051115.
* sources.am: Regenerated.
* Makefile.in: Likewise.
* scripts/makemake.tcl: Use glob -nocomplain.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107049 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/classpath/vm')
8 files changed, 156 insertions, 59 deletions
diff --git a/libjava/classpath/vm/reference/gnu/classpath/VMStackWalker.java b/libjava/classpath/vm/reference/gnu/classpath/VMStackWalker.java index 28e4ce36443..e995c46341d 100644 --- a/libjava/classpath/vm/reference/gnu/classpath/VMStackWalker.java +++ b/libjava/classpath/vm/reference/gnu/classpath/VMStackWalker.java @@ -88,9 +88,9 @@ public final class VMStackWalker /** * Get the class loader associated with the Class returned by - * <code>getCallingClass()</code>, or <code>null</code> if no - * such class exists or it is the boot loader. This method is an optimization - * for the expression <code>getClassContext()[1].getClassLoader()</code> + * <code>getCallingClass()</code>, or <code>null</code> if no such class + * exists or it is the boot loader. This method is an optimization for the + * expression <code>VMStackWalker.getClassLoader(getClassContext()[1])</code> * and should return the same result. * * <p> @@ -102,7 +102,15 @@ public final class VMStackWalker Class[] ctx = getClassContext(); if (ctx.length < 3) return null; - return ctx[2].getClassLoader(); + return getClassLoader(ctx[2]); } + + /** + * Retrieve the class's ClassLoader, or <code>null</code> if loaded + * by the bootstrap loader. I.e., this should return the same thing + * as {@link java.lang.VMClass#getClassLoader}. This duplicate version + * is here to work around access permissions. + */ + public static native ClassLoader getClassLoader(Class cl); } diff --git a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java index 09173fcf036..23cbb7b8ee3 100644 --- a/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java +++ b/libjava/classpath/vm/reference/gnu/classpath/jdwp/VMIdManager.java @@ -138,6 +138,7 @@ public class VMIdManager { id.setId (++_lastId); } + id.setReference (obj); return id; } catch (InstantiationException ie) @@ -162,7 +163,7 @@ public class VMIdManager { id.setId (++_lastId); } - + id.setReference (obj); return id; } diff --git a/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java b/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java index 7cd97192e74..93a42b1ca9a 100644 --- a/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java +++ b/libjava/classpath/vm/reference/java/io/VMObjectInputStream.java @@ -39,6 +39,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; @@ -46,8 +47,13 @@ import java.security.PrivilegedAction; final class VMObjectInputStream { - private static Class oisClass = ObjectInputStream.class; - private static Class vmoisClass = VMObjectInputStream.class; + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javaio"); + } + } // PrivilegedAction needed for Class.getClassLoader() private static PrivilegedAction loaderAction = new PrivilegedAction() diff --git a/libjava/classpath/vm/reference/java/io/VMObjectStreamClass.java b/libjava/classpath/vm/reference/java/io/VMObjectStreamClass.java index 2aee7a9e6a7..77470fa807f 100644 --- a/libjava/classpath/vm/reference/java/io/VMObjectStreamClass.java +++ b/libjava/classpath/vm/reference/java/io/VMObjectStreamClass.java @@ -1,5 +1,5 @@ /* VMObjectStreamClass.java -- VM helper functions for ObjectStreamClass - Copyright (C) 2003 Free Software Foundation, Inc. + Copyright (C) 2003, 2005 Free Software Foundation, Inc. This file is part of GNU Classpath. @@ -38,10 +38,19 @@ exception statement from your version. */ package java.io; +import gnu.classpath.Configuration; import java.lang.reflect.Field; final class VMObjectStreamClass { + static + { + if (Configuration.INIT_LOAD_LIBRARY) + { + System.loadLibrary("javaio"); + } + } + /** * Returns true if CLAZZ has a static class initializer * (a.k.a. <clinit>). diff --git a/libjava/classpath/vm/reference/java/lang/VMClassLoader.java b/libjava/classpath/vm/reference/java/lang/VMClassLoader.java index 4fe12403622..a777462aa36 100644 --- a/libjava/classpath/vm/reference/java/lang/VMClassLoader.java +++ b/libjava/classpath/vm/reference/java/lang/VMClassLoader.java @@ -40,6 +40,7 @@ exception statement from your version. */ package java.lang; import gnu.classpath.SystemProperties; +import gnu.classpath.Configuration; import java.io.File; import java.io.IOException; @@ -63,6 +64,48 @@ import java.util.zip.ZipFile; */ final class VMClassLoader { + + + /** packages loaded by the bootstrap class loader */ + static final HashMap definedPackages = 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); + + 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. @@ -119,6 +162,9 @@ final class VMClassLoader return null; } + /** jars from property java.boot.class.path */ + static final HashMap bootjars = new HashMap(); + /** * Helper to get a list of resources from the bootstrap class loader. * @@ -139,8 +185,9 @@ final class VMClassLoader { try { - v.add(new URL("file://" - + new File(file, name).getAbsolutePath())); + File f = new File(file, name); + if (!f.exists()) continue; + v.add(new URL("file://" + f.getAbsolutePath())); } catch (MalformedURLException e) { @@ -150,30 +197,28 @@ final class VMClassLoader else if (file.isFile()) { ZipFile zip; - try - { - zip = new ZipFile(file); - } - catch (IOException e) - { - continue; - } - String zname = name.startsWith("/") ? name.substring(1) : name; - try - { - if (zip.getEntry(zname) == null) + 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; - } - finally - { - try - { - zip.close(); - } - catch (IOException e) - { - } - } + } + } + String zname = name.startsWith("/") ? name.substring(1) : name; + if (zip.getEntry(zname) == null) + continue; try { v.add(new URL("jar:file://" @@ -188,29 +233,41 @@ final class VMClassLoader return v.elements(); } + + /** + * Returns a String[] of native package names. The default + * implementation returns an empty array, or you may decide + * this needs native help. + */ + private static String[] getBootPackages() + { + return new String[0]; + } + + /** - * Helper to get a package from the bootstrap class loader. The default - * implementation of returning null may be adequate, or you may decide - * that this needs some native help. + * 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 null; + return (Package)definedPackages.get(name); } + + /** - * Helper to get all packages from the bootstrap class loader. The default - * implementation of returning an empty array may be adequate, or you may - * decide that this needs some native help. + * Helper to get all packages from the bootstrap class loader. * * @return all named packages, if any exist */ static Package[] getPackages() { - return new Package[0]; + Package[] packages = new Package[definedPackages.size()]; + definedPackages.values().toArray(packages); + return packages; } /** diff --git a/libjava/classpath/vm/reference/java/lang/VMThread.java b/libjava/classpath/vm/reference/java/lang/VMThread.java index 6b9102b7071..aa0b8347a73 100644 --- a/libjava/classpath/vm/reference/java/lang/VMThread.java +++ b/libjava/classpath/vm/reference/java/lang/VMThread.java @@ -376,15 +376,11 @@ final class VMThread */ static void sleep(long ms, int ns) throws InterruptedException { - - // Round up - ms += (ns != 0) ? 1 : 0; - // Note: JDK treats a zero length sleep is like Thread.yield(), // without checking the interrupted status of the thread. // It's unclear if this is a bug in the implementation or the spec. // See http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6213203 - if (ms == 0) + if (ms == 0 && ns == 0) { if (Thread.interrupted()) throw new InterruptedException(); @@ -404,11 +400,12 @@ final class VMThread { while (true) { - vt.wait(ms); + vt.wait(ms, ns); now = System.currentTimeMillis(); if (now >= end) break; ms = end - now; + ns = 0; } } } diff --git a/libjava/classpath/vm/reference/java/security/VMAccessController.java b/libjava/classpath/vm/reference/java/security/VMAccessController.java index 7058a5e345c..da13c688946 100644 --- a/libjava/classpath/vm/reference/java/security/VMAccessController.java +++ b/libjava/classpath/vm/reference/java/security/VMAccessController.java @@ -76,7 +76,7 @@ final class VMAccessController DEFAULT_CONTEXT = new AccessControlContext(domain); } - private static final boolean DEBUG = false; + private static final boolean DEBUG = gnu.classpath.Configuration.DEBUG; private static void debug(String msg) { System.err.print(">>> VMAccessController: "); @@ -108,6 +108,8 @@ final class VMAccessController LinkedList stack = (LinkedList) contexts.get(); if (stack == null) { + if (DEBUG) + debug("no stack... creating "); stack = new LinkedList(); contexts.set(stack); } @@ -134,6 +136,10 @@ final class VMAccessController if (stack.isEmpty()) contexts.set(null); } + else if (DEBUG) + { + debug("no stack during pop?????"); + } } /** @@ -166,7 +172,7 @@ final class VMAccessController String[] methods = (String[]) stack[1]; if (DEBUG) - debug(">>> got trace of length " + classes.length); + debug("got trace of length " + classes.length); HashSet domains = new HashSet(); HashSet seenDomains = new HashSet(); @@ -185,8 +191,9 @@ final class VMAccessController if (DEBUG) { - debug(">>> checking " + clazz + "." + method); - debug(">>> loader = " + clazz.getClassLoader()); + debug("checking " + clazz + "." + method); + // subject to getClassLoader RuntimePermission + debug("loader = " + clazz.getClassLoader()); } // If the previous frame was a call to doPrivileged, then this is @@ -198,14 +205,16 @@ final class VMAccessController && method.equals ("doPrivileged")) { // If there was a call to doPrivileged with a supplied context, - // return that context. + // return that context. If using JAAS doAs*, it should be + // a context with a SubjectDomainCombiner LinkedList l = (LinkedList) contexts.get(); if (l != null) context = (AccessControlContext) l.getFirst(); privileged = 1; } - ProtectionDomain domain = clazz.getProtectionDomain(); + // subject to getProtectionDomain RuntimePermission + ProtectionDomain domain = clazz.getProtectionDomain(); if (domain == null) continue; @@ -225,14 +234,25 @@ final class VMAccessController ProtectionDomain[] result = (ProtectionDomain[]) domains.toArray(new ProtectionDomain[domains.size()]); - // Intersect the derived protection domain with the context supplied - // to doPrivileged. if (context != null) - context = new AccessControlContext(result, context, - IntersectingDomainCombiner.SINGLETON); + { + DomainCombiner dc = context.getDomainCombiner (); + // If the supplied context had no explicit DomainCombiner, use + // our private version, which computes the intersection of the + // context's domains with the derived set. + if (dc == null) + context = new AccessControlContext + (IntersectingDomainCombiner.SINGLETON.combine + (result, context.getProtectionDomains ())); + // Use the supplied DomainCombiner. This should be secure, + // because only trusted code may create an + // AccessControlContext with a custom DomainCombiner. + else + context = new AccessControlContext (result, context, dc); + } // No context was supplied. Return the derived one. else - context = new AccessControlContext(result); + context = new AccessControlContext (result); inGetContext.set(Boolean.FALSE); return context; diff --git a/libjava/classpath/vm/reference/standard.omit b/libjava/classpath/vm/reference/standard.omit deleted file mode 100644 index c0499fe053f..00000000000 --- a/libjava/classpath/vm/reference/standard.omit +++ /dev/null @@ -1 +0,0 @@ -gnu/classpath/jdwp |