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: FYI: VMCompiler -vs- MessageDigest


I'm checking this in on the trunk and the 4.0 branch.

I was able to see a deadlock when running jonas.  This occurred
because VMCompiler used MessageDigest.getInstance(), causing an
inversion in the expected order of lock acquisition.

This fix avoids going through the class loaders to find the MD5
digester each time; instead we make one at class initialization time
and then clone it whenever we need a new one.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* java/lang/VMCompiler.java (md5Digest): New field.
	(compileClass): Clone md5Digest instead of looking up a new one.

Index: java/lang/VMCompiler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/VMCompiler.java,v
retrieving revision 1.4
diff -u -r1.4 VMCompiler.java
--- java/lang/VMCompiler.java 16 Feb 2005 18:51:21 -0000 1.4
+++ java/lang/VMCompiler.java 7 Mar 2005 18:57:41 -0000
@@ -79,6 +79,24 @@
 
   private static Vector precompiledMapFiles;
 
+  // We create a single MD5 engine and then clone it whenever we want
+  // a new one.  This is simpler than trying to find a new one each
+  // time, and it avoids potential deadlocks due to class loader
+  // oddities.
+  private static final MessageDigest md5Digest;
+
+  static
+  {
+    try
+      {
+	md5Digest = MessageDigest.getInstance("MD5");
+      }
+    catch (NoSuchAlgorithmException _)
+      {
+	md5Digest = null;
+      }
+  }
+
   static
   {
     gcjJitCompiler = System.getProperty("gnu.gcj.jit.compiler");
@@ -175,11 +193,18 @@
 
     try
       {
-	MessageDigest md = MessageDigest.getInstance("MD5");
+	MessageDigest md = (MessageDigest) md5Digest.clone();
 	digest = md.digest(data);
       }
-    catch (NoSuchAlgorithmException _)
+    catch (CloneNotSupportedException _)
+      {
+	// Can't happen.
+	return null;
+      }
+    catch (NullPointerException _)
       {
+	// If md5Digest==null -- but really this should never happen
+	// either, since the MD5 digest is in libgcj.
 	return null;
       }
 


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