commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FYI: Two small Runtime cleanups


From: Mark Wielaard
Subject: FYI: Two small Runtime cleanups
Date: Fri, 30 Apr 2004 17:21:57 +0200

Hi,

This cleans up two small things in Runtime.

2004-04-30  Mark Wielaard  <address@hidden>

       Reported by Nikolay Fiykov [bugs #8611]
       * java/lang/Runtime.java (loadLib): New private method.
       (load): Call loadLib.
       (loadLibrary): Call loadLib.

       * java/lang/Runtime.java (runShutdownHooks): Use Thread.yield().

Hopefully this prevents early bootstrap triggering of exception handling
and it might  be a little more efficient if your library path is large.
Thread.yield() is more appropriate as hint to the Runtime to give
another Thread a little chance to run. Thread.sleep() [which should have
been called staticly anyway] might have some minimum sleep time
associated with it that is inappropriate here.

Committed.

Cheers,

Mark
Index: java/lang/Runtime.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/lang/Runtime.java,v
retrieving revision 1.6
diff -u -r1.6 Runtime.java
--- java/lang/Runtime.java      17 Apr 2004 17:08:22 -0000      1.6
+++ java/lang/Runtime.java      30 Apr 2004 15:17:39 -0000
@@ -1,5 +1,5 @@
 /* Runtime.java -- access to the VM process
-   Copyright (C) 1998, 2002, 2003 Free Software Foundation
+   Copyright (C) 1998, 2002, 2003, 2004 Free Software Foundation
 
 This file is part of GNU Classpath.
 
@@ -287,14 +287,8 @@
                       {
                         shutdownHooks.remove(hooks[i]);
                       }
-                try
-                  {
-                    exitSequence.sleep(1); // Give other threads a chance.
-                  }
-                catch (InterruptedException e)
-                  {
-                    // Ignore, the next loop just starts sooner.
-                  }
+
+                    Thread.yield(); // Give other threads a chance.
               }
             synchronized (libpath)
               {
@@ -670,11 +664,20 @@
    */
   public void load(String filename)
   {
+    if (loadLib(filename) == 0)
+      throw new UnsatisfiedLinkError("Could not load library " + filename);
+  }
+
+  // Private version of load(String) that doesn't throw Exception on
+  // load error, but it does do security checks (which can throw
+  // SecurityExceptions). Convenience method for early bootstrap
+  // process.
+  private int loadLib(String filename)
+  {
     SecurityManager sm = securityManager; // Be thread-safe!
     if (sm != null)
       sm.checkLink(filename);
-    if (VMRuntime.nativeLoad(filename) == 0)
-      throw new UnsatisfiedLinkError("Could not load library " + filename);
+    return VMRuntime.nativeLoad(filename);
   }
 
   /**
@@ -706,21 +709,18 @@
         filename = cl.findLibrary(libname);
         if (filename != null)
           {
-            load(filename);
-            return;
+           // Use loadLib so no UnsatisfiedLinkError are thrown.
+            if (loadLib(filename) != 0)
+             return;
           }
       }
+
     filename = System.mapLibraryName(libname);
     for (int i = 0; i < libpath.length; i++)
-      try
-        {
-          load(libpath[i] + filename);
-          return;
-        }
-      catch (UnsatisfiedLinkError e)
-        {
-          // Try next path element.
-        }
+      // Use loadLib so no UnsatisfiedLinkError are thrown.
+      if (loadLib(libpath[i] + filename) != 0)
+       return;
+
     throw new UnsatisfiedLinkError("Could not find library " + libname + ".");
   }
 

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]