This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: Make parent of bootstrap classloader NULL


This patch fixes a potential classloading deadlock which Tromey identified. The bootstrap classloader should be at the top of the delegation chain, ie it should have no parent. In libgcj however, because of the way the bootstrap classloader is created, it is given a parent - the default/system class loader. In general this isn't a problem because we have special cases to look for a "null" parent classloader and then do the bootstrap classloader's work, rather that relying on "real" delegation.

However, if loadClass() is called on the bootstrap classloader itself, then the bootstrap classloader will first delegate back to the system ClassLoader. If another thread happens to already be in loadClass() on the system classloader, and waiting to lock the bootstrap classloader, then we have a classic deadlock. We've actually seen this in practice with Jonas.

This patch resolves the issue by ensuring that the bootstrap classloader is created with a null parent. I'm checking it in.

Bryce


2005-09-21  Bryce McKinlay  <mckinlay@redhat.com>

	* gnu/gcj/runtime/BootClassLoader.java (BootClassLoader): Pass
	`null' parent ClassLoader to parent constructor.
	* gnu/gcj/runtime/HelperClassLoader.java (HelperClassLoader): New
	constructor.

Index: gnu/gcj/runtime/BootClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/BootClassLoader.java,v
retrieving revision 1.3
diff -u -r1.3 BootClassLoader.java
--- gnu/gcj/runtime/BootClassLoader.java	29 Mar 2005 21:47:03 -0000	1.3
+++ gnu/gcj/runtime/BootClassLoader.java	22 Sep 2005 00:16:01 -0000
@@ -23,6 +23,9 @@
 {
   BootClassLoader(String libdir)
   {
+    // The BootClassLoader is the top of the delegation chain. It does not
+    // have a parent.
+    super((ClassLoader) null);
     addDirectoriesFromProperty("java.endorsed.dirs");
     addDirectoriesFromProperty("gnu.gcj.runtime.endorsed.dirs");
 
Index: gnu/gcj/runtime/HelperClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/HelperClassLoader.java,v
retrieving revision 1.1
diff -u -r1.1 HelperClassLoader.java
--- gnu/gcj/runtime/HelperClassLoader.java	29 Mar 2005 22:54:04 -0000	1.1
+++ gnu/gcj/runtime/HelperClassLoader.java	22 Sep 2005 00:16:01 -0000
@@ -25,6 +25,11 @@
   {
     super(new URL[0]);
   }
+  
+  HelperClassLoader(ClassLoader parent)
+  {
+    super(new URL[0], parent);
+  }
 
   /**
    * This is a helper method that adds all the jar and zip files from

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]