This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: improve core:/ resource searches
- From: Anthony Green <green at redhat dot com>
- To: java-patches at gcc dot gnu dot org
- Date: Wed, 01 Jun 2005 08:57:19 -0700
- Subject: Patch: improve core:/ resource searches
The following patch introduces special handling for core:/ elements in
the classpath. The old code worked, but resulted in a thrown exception
on every failed search. Staring eclipse results in over 10k of these.
This patch sets out to avoid these exceptions and still provide the same
functionality. Thanks to tromey for the idea.
Ok for HEAD?
AG
2005-06-01 Anthony Green <green@redhat.com>
* java/net/URLClassLoader.java: import gnu.gcj.Core,
and gnu.java.net.protocol.core.CoreInputStream.
(CureURLLoader): New class.
(CoreResource): New class.
(addURLImpl): Add special treatment for the "core" protocol.
* gnu/gcj/natCore.cc (find): New method.
* gnu/gcj/Core.java (find): New method.
Index: gnu/gcj/Core.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/Core.java,v
retrieving revision 1.2
diff -u -p -r1.2 Core.java
--- gnu/gcj/Core.java 28 Aug 2003 22:17:35 -0000 1.2
+++ gnu/gcj/Core.java 1 Jun 2005 15:50:53 -0000
@@ -12,6 +12,9 @@ public class Core
{
public native static Core create (String name) throws java.io.IOException;
+ // Same as create, except returns null if not found.
+ public native static Core find (String name);
+
public RawData ptr;
public int length;
Index: gnu/gcj/natCore.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/natCore.cc,v
retrieving revision 1.4
diff -u -p -r1.4 natCore.cc
--- gnu/gcj/natCore.cc 16 Apr 2004 16:27:18 -0000 1.4
+++ gnu/gcj/natCore.cc 1 Jun 2005 15:50:53 -0000
@@ -104,6 +104,13 @@ _Jv_create_core (_Jv_core_chain *node, j
}
gnu::gcj::Core *
+gnu::gcj::Core::find (jstring name)
+{
+ gnu::gcj::Core *core = _Jv_create_core (root, name);
+ return core;
+}
+
+gnu::gcj::Core *
gnu::gcj::Core::create (jstring name)
{
gnu::gcj::Core *core = _Jv_create_core (root, name);
Index: java/net/URLClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/net/URLClassLoader.java,v
retrieving revision 1.27.2.1
diff -u -p -r1.27.2.1 URLClassLoader.java
--- java/net/URLClassLoader.java 9 Mar 2005 19:36:55 -0000 1.27.2.1
+++ java/net/URLClassLoader.java 1 Jun 2005 15:50:53 -0000
@@ -63,7 +63,8 @@ import java.util.jar.JarEntry;
import java.util.jar.JarFile;
import java.util.jar.Manifest;
import gnu.gcj.runtime.SharedLibHelper;
-
+import gnu.gcj.Core;
+import gnu.java.net.protocol.core.CoreInputStream;
/**
* A secure class loader that can load classes and resources from
@@ -652,6 +653,66 @@ public class URLClassLoader extends Secu
}
}
+ /**
+ * A <code>CoreURLLoader</code> is a type of <code>URLLoader</code>
+ * only loading from core url.
+ */
+ static final class CoreURLLoader extends URLLoader
+ {
+ private String dir;
+
+ CoreURLLoader(URLClassLoader classloader, URL url)
+ {
+ super(classloader, url);
+ dir = baseURL.getFile();
+ }
+
+ /** get resource with the name "name" in the core url */
+ Resource getResource(String name)
+ {
+ Core core = Core.find (dir + name);
+ if (core != null)
+ return new CoreResource(this, name, core);
+ return null;
+ }
+ }
+
+ static final class CoreResource extends Resource
+ {
+ final Core core;
+
+ CoreResource(CoreURLLoader loader, String name, Core core)
+ {
+ super(loader, name);
+ this.core = core;
+ }
+
+ InputStream getInputStream() throws IOException
+ {
+ return new CoreInputStream(core);
+ }
+
+ public int getLength()
+ {
+ return core.length;
+ }
+
+ public URL getURL()
+ {
+ try
+ {
+ return new URL(loader.baseURL, name,
+ loader.classloader.getURLStreamHandler("core"));
+ }
+ catch (MalformedURLException e)
+ {
+ InternalError ie = new InternalError();
+ ie.initCause(e);
+ throw ie;
+ }
+ }
+ }
+
// Constructors
/**
@@ -817,6 +878,8 @@ public class URLClassLoader extends Secu
loader = new JarURLLoader(this, newUrl);
else if ("file".equals(protocol))
loader = new FileURLLoader(this, newUrl);
+ else if ("core".equals(protocol))
+ loader = new CoreURLLoader(this, newUrl);
else
loader = new RemoteURLLoader(this, newUrl);