Massive performance loss from OS::sleep hack
Kurt Miller
kurt at intricatesoftware.com
Tue Sep 18 04:22:07 PDT 2007
David Xu confirmed for me that pthread_yield() does give some
time to lower priority threads on 7.0 using thr. Attached and inline
are two patches for the 1.5 port that is how I suggest the issue be
addressed.
For 7.0 and up default UseThreadPriorities to true and always
use pthread_yield(). For < 7.0 default UseThreadPriorities to
false and conditionally use pthread_yield()/os_sleep(). User's
can toggle UseThreadPriorities with the command line argument
-XX:+UseThreadPriorities
-------- files/patch-vm::os_bsd.cpp --------
$FreeBSD: ports/java/jdk15/files/patch-vm::os_bsd.cpp,v 1.7 2007/06/09
05:14:56 glewis Exp $
--- ../../hotspot/src/os/bsd/vm/os_bsd.cpp.orig Mon Sep 17 17:39:33 2007
+++ ../../hotspot/src/os/bsd/vm/os_bsd.cpp Mon Sep 17 20:57:26 2007
@@ -508,7 +508,7 @@
#define getenv(n) ::getenv(n)
#ifndef DEFAULT_LD_LIBRARY_PATH
-#define DEFAULT_LD_LIBRARY_PATH "/usr/lib" /* See ld.so.1(1) */
+#define DEFAULT_LD_LIBRARY_PATH "/usr/lib:/usr/local/lib" /* See ld.so.1(1)
*/
#endif
#define EXTENSIONS_DIR "/lib/ext"
#define ENDORSED_DIR "/lib/endorsed"
@@ -2273,11 +2273,14 @@
// BSDXXX: Only use pthread_yield here and below if the system thread
// scheduler gives time slices to lower priority threads when yielding.
-#ifdef __FreeBSD__
+// pthread_yield() can also be used when thread priorities are disabled.
+// Using os_sleep() here causes significant performance degradation.
+#if defined(_ALLBSD_SOURCE) && (!defined(__FreeBSD__) || __FreeBSD__ < 7)
+ if ( UseThreadPriorities )
os_sleep(MinSleepInterval, interruptible);
-#else
- pthread_yield();
+ else
#endif
+ pthread_yield();
#if SOLARIS
// XXX - This code was not exercised during the Merlin RC1
@@ -2299,11 +2302,14 @@
// BSDXXX: Only use pthread_yield here and above if the system thread
// scheduler gives time slices to lower priority threads when yielding.
-#ifdef __FreeBSD__
- os_sleep(MinSleepInterval, interruptible);
-#else
- pthread_yield();
+// pthread_yield() can be also used when thread priorities are disabled.
+// Using os_sleep() here causes significant performance degradation.
+#if defined(_ALLBSD_SOURCE) && (!defined(__FreeBSD__) || __FreeBSD__ < 7)
+ if ( UseThreadPriorities )
+ os_sleep(MinSleepInterval, interruptible);
+ else
#endif
+ pthread_yield();
return 0;
}
------- files/patch-vm::globals.hpp --------
$FreeBSD$
--- ../../hotspot/src/share/vm/runtime/globals.hpp.orig Mon Sep 17 10:12:16
2007
+++ ../../hotspot/src/share/vm/runtime/globals.hpp Mon Sep 17 10:20:32 2007
@@ -130,6 +130,12 @@
#define falseInProduct true
#endif
+#if !defined(_ALLBSD_SOURCE) || (defined(__FreeBSD__) && __FreeBSD__ >= 7)
+#define OSUseThreadPriorities true
+#else
+#define OSUseThreadPriorities false
+#endif
+
// develop flags are settable / visible only during development and are
constant in the PRODUCT version
// product flags are always settable / visible
@@ -2546,7 +2552,7 @@
"beginning to throw OutOfMemoryErrors in each compile") \
\
/* Priorities */ \
- product(bool, UseThreadPriorities, true, \
+ product(bool, UseThreadPriorities, OSUseThreadPriorities, \
"Use native thread priorities") \
\
product(intx, ThreadPriorityPolicy, 0, \
More information about the freebsd-java
mailing list