aboutsummaryrefslogtreecommitdiff
path: root/libjava/java
diff options
context:
space:
mode:
authortromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-28 22:17:37 +0000
committertromey <tromey@138bc75d-0d04-0410-961f-82ee72b054a4>2003-08-28 22:17:37 +0000
commitcadef59253f55d4564de9e11df34be2222521be3 (patch)
treea5d84d77e14c8eed9bc348be5e03ab4e6490a077 /libjava/java
parent8a9af253b42bf90afe7238f6667163a92c92fe96 (diff)
* Makefile.in: Rebuilt.
* Makefile.am (ordinary_java_source_files): Added new files. * java/lang/Class.h (_Jv_sharedlib_register_hook): Declare as friend. * java/net/URLClassLoader.java (findClass): Don't use findURLResource. Use loader's getClass method. (URLLoader.getClass): New method. (addURL): Handle `gcjlib' URLs. (SoURLLoader): New class. (SoResource): Likewise. * gnu/gcj/protocol/gcjlib/Connection.java: New file. * gnu/gcj/protocol/gcjlib/Handler.java: New file. * include/jvm.h (struct _Jv_core_chain): Moved from natCore.cc. (_Jv_RegisterCoreHook): Declare. (_Jv_FindCore): Declare. * gnu/gcj/runtime/SharedLibHelper.java: New file. * gnu/gcj/runtime/natSharedLibLoader.cc (CoreHookFunc): New typedef. (core_hook): New function. (struct SharedLibDummy) [saved_core]: New field. (init): Set _Jv_RegisterCoreHook. Throw exception on failure. (register_hook): Set protection domain and class loader on new class. (finalize): Free core chain. * gnu/gcj/Core.java (Core): New constructor. * gnu/gcj/runtime/SharedLibLoader.java: Rewrote to use SharedLibHelper. * gnu/gcj/natCore.cc (_Jv_RegisterResource): Indentation fixlet. (_Jv_create_core): New function. (create): Use it. (default_register_resource): New function. (_Jv_RegisterCoreHook): New global. (_Jv_RegisterResource): Use it. (core_chain_struct): Removed. (_Jv_FindCore): New function. (_Jv_FreeCoreChain): New function. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@70892 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libjava/java')
-rw-r--r--libjava/java/lang/Class.h2
-rw-r--r--libjava/java/net/URLClassLoader.java121
2 files changed, 105 insertions, 18 deletions
diff --git a/libjava/java/lang/Class.h b/libjava/java/lang/Class.h
index 06c9c804d9e..9bcff6fbb55 100644
--- a/libjava/java/lang/Class.h
+++ b/libjava/java/lang/Class.h
@@ -369,6 +369,8 @@ private:
friend class gnu::gcj::runtime::StackTrace;
friend class java::io::VMObjectStreamClass;
+ friend void _Jv_sharedlib_register_hook (jclass klass);
+
// Chain for class pool.
jclass next;
// Name of class.
diff --git a/libjava/java/net/URLClassLoader.java b/libjava/java/net/URLClassLoader.java
index 9a468bf71af..e1c789ddd64 100644
--- a/libjava/java/net/URLClassLoader.java
+++ b/libjava/java/net/URLClassLoader.java
@@ -1,5 +1,5 @@
/* URLClassLoader.java -- ClassLoader that loads classes from one or more URLs
- Copyright (C) 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -59,6 +59,7 @@ import java.util.jar.Attributes;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
+import gnu.gcj.runtime.SharedLibHelper;
/**
* A secure class loader that can load classes and resources from
@@ -194,6 +195,17 @@ public class URLClassLoader extends SecureClassLoader
}
/**
+ * Returns a <code>Class</code> loaded by this
+ * <code>URLLoader</code>, or <code>null</code> when this loader
+ * either can't load the class or doesn't know how to load classes
+ * at all.
+ */
+ Class getClass(String className)
+ {
+ return null;
+ }
+
+ /**
* Returns a <code>Resource</code> loaded by this
* <code>URLLoader</code>, or <code>null</code> when no
* <code>Resource</code> with the given name exists.
@@ -282,7 +294,7 @@ public class URLClassLoader extends SecureClassLoader
{
super(classloader, baseURL);
- // cache url prefix for all resources in this jar url
+ // Cache url prefix for all resources in this jar url.
String external = baseURL.toExternalForm();
StringBuffer sb = new StringBuffer(external.length() + 6);
sb.append("jar:");
@@ -448,12 +460,12 @@ public class URLClassLoader extends SecureClassLoader
{
return stream;
}
-
+
public int getLength()
{
return length;
}
-
+
public URL getURL()
{
return url;
@@ -461,6 +473,63 @@ public class URLClassLoader extends SecureClassLoader
}
/**
+ * A <code>SoURLLoader</code> is a type of <code>URLLoader</code>
+ * that loads classes and resources from a shared library.
+ */
+ final static class SoURLLoader extends URLLoader
+ {
+ SharedLibHelper helper;
+
+ SoURLLoader(URLClassLoader classloader, URL url)
+ {
+ super(classloader, url);
+ helper = SharedLibHelper.findHelper(classloader, url.getFile(),
+ noCertCodeSource);
+ }
+
+ Class getClass(String className)
+ {
+ return helper.findClass(className);
+ }
+
+ Resource getResource(String name)
+ {
+ URL url = helper.findResource(name);
+ if (url == null)
+ return null;
+ return new SoResource(this, name, url);
+ }
+ }
+
+ final static class SoResource extends Resource
+ {
+ SoResource(SoURLLoader loader, String name, URL url)
+ {
+ super(loader, name);
+ this.url = url;
+ }
+
+ InputStream getInputStream() throws IOException
+ {
+ URLConnection conn = url.openConnection();
+ return conn.getInputStream();
+ }
+
+ public int getLength()
+ {
+ // FIXME we could find this by asking the core object.
+ return -1;
+ }
+
+ public URL getURL ()
+ {
+ return url;
+ }
+
+ final URL url;
+ }
+
+ /**
* A <code>FileURLLoader</code> is a type of <code>URLLoader</code>
* only loading from file url.
*/
@@ -644,7 +713,7 @@ public class URLClassLoader extends SecureClassLoader
// for cache initial size
synchronized(factoryCache)
{
- if(factory != null && factoryCache.get(factory) == null)
+ if (factory != null && factoryCache.get(factory) == null)
factoryCache.put(factory, new HashMap(5));
}
}
@@ -667,21 +736,24 @@ public class URLClassLoader extends SecureClassLoader
if (newUrl == null)
return; // Silently ignore...
- // check global cache to see if there're already url loader
- // for this url
+ // Check global cache to see if there're already url loader
+ // for this url.
URLLoader loader = (URLLoader)urlloaders.get(newUrl);
if (loader == null)
{
String file = newUrl.getFile();
+ String protocol = newUrl.getProtocol();
// Check that it is not a directory
- if (! (file.endsWith("/") || file.endsWith(File.separator)))
+ if ("gcjlib".equals(protocol))
+ loader = new SoURLLoader(this, newUrl);
+ else if (! (file.endsWith("/") || file.endsWith(File.separator)))
loader = new JarURLLoader(this, newUrl);
- else if ("file".equals(newUrl.getProtocol()))
+ else if ("file".equals(protocol))
loader = new FileURLLoader(this, newUrl);
else
loader = new RemoteURLLoader(this, newUrl);
- // cache it
+ // Cache it.
urlloaders.put(newUrl, loader);
}
@@ -764,7 +836,20 @@ public class URLClassLoader extends SecureClassLoader
{
// Just try to find the resource by the (almost) same name
String resourceName = className.replace('.', '/') + ".class";
- Resource resource = findURLResource(resourceName);
+ int max = urls.size();
+ Resource resource = null;
+ for (int i = 0; i < max && resource == null; i++)
+ {
+ URLLoader loader = (URLLoader)urlinfos.elementAt(i);
+ if (loader == null)
+ continue;
+
+ Class k = loader.getClass(className);
+ if (k != null)
+ return k;
+
+ resource = loader.getResource(resourceName);
+ }
if (resource == null)
throw new ClassNotFoundException(className + " not found in " + urls);
@@ -907,12 +992,12 @@ public class URLClassLoader extends SecureClassLoader
URLStreamHandler handler;
synchronized (factoryCache)
{
- // check if there're handler for the same protocol in cache
+ // Check if there're handler for the same protocol in cache.
HashMap cache = (HashMap)factoryCache.get(factory);
handler = (URLStreamHandler)cache.get(protocol);
if(handler == null)
{
- // add it to cache
+ // Add it to cache.
handler = factory.createURLStreamHandler(protocol);
cache.put(protocol, handler);
}
@@ -971,23 +1056,23 @@ public class URLClassLoader extends SecureClassLoader
// First get the permissions that would normally be granted
PermissionCollection permissions = super.getPermissions(source);
- // Now add the any extra permissions depending on the URL location
+ // Now add any extra permissions depending on the URL location.
URL url = source.getLocation();
String protocol = url.getProtocol();
if (protocol.equals("file"))
{
String file = url.getFile();
- // If the file end in / it must be an directory
+ // If the file end in / it must be an directory.
if (file.endsWith("/") || file.endsWith(File.separator))
{
// Grant permission to read everything in that directory and
- // all subdirectories
+ // all subdirectories.
permissions.add(new FilePermission(file + "-", "read"));
}
else
{
- // It is a 'normal' file
- // Grant permission to access that file
+ // It is a 'normal' file.
+ // Grant permission to access that file.
permissions.add(new FilePermission(file, "read"));
}
}