This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
mingw hash sync patch, take 2
- From: Adam Megacz <gcj at lists dot megacz dot com>
- To: java-patches at gcc dot gnu dot org
- Date: 20 Oct 2002 16:16:09 -0700
- Subject: mingw hash sync patch, take 2
- Organization: Myself
Ok to commit?
- a
Index: aclocal.m4
===================================================================
RCS file: /cvs/gcc/gcc/libjava/aclocal.m4,v
retrieving revision 1.28
diff -u -r1.28 aclocal.m4
--- aclocal.m4 16 May 2002 17:42:53 -0000 1.28
+++ aclocal.m4 20 Oct 2002 23:14:37 -0000
@@ -434,3 +434,26 @@
done<<>>dnl>>)
changequote([,]))])
+AC_DEFUN([CHECK_FOR_BROKEN_MINGW_LD],
+[
+AC_MSG_CHECKING(whether 'ld' is at least 2.13)
+LD_PROG=`$CC --print-prog-name=ld`
+LD_VERSION=`$LD_PROG --version`
+LD_VERSION_MAJOR=`echo "$LD_VERSION" | head -1 | cut -d '.' -f 1 | cut -d ' ' -f 4`
+LD_VERSION_MINOR=`echo "$LD_VERSION" | head -1 | cut -d '.' -f 2`
+if expr "$LD_VERSION_MAJOR" \> 2 > /dev/null; then
+ LD_OK="ok"
+else
+ if expr "$LD_VERSION_MAJOR" = 2 && expr "$LD_VERSION_MINOR" \>= 13 > /dev/null; then
+ LD_OK="ok"
+ fi
+fi
+if test "x$LD_OK" != x; then
+ AC_MSG_RESULT([yes; major=$LD_VERSION_MAJOR, minor=$LD_VERSION_MINOR])
+else
+ AC_MSG_RESULT([no; major=$LD_VERSION_MAJOR, minor=$LD_VERSION_MINOR])
+ AC_MSG_WARN([ld <2.13 detected; enabling JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS hack...])
+ AC_DEFINE(JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS, 1,
+ [Indicate that linker is not able to 8-byte align static data])
+fi[]dnl
+])# CHECK_FOR_BROKEN_MINGW_LD
Index: configure.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/configure.in,v
retrieving revision 1.140
diff -u -r1.140 configure.in
--- configure.in 17 Sep 2002 06:58:39 -0000 1.140
+++ configure.in 20 Oct 2002 23:14:40 -0000
@@ -226,6 +226,7 @@
PLATFORM=Win32
PLATFORMOBJS=win32.lo
PLATFORMH=win32.h
+ CHECK_FOR_BROKEN_MINGW_LD
;;
*)
PLATFORM=Posix
@@ -444,7 +445,7 @@
HASH_SYNC_SPEC=
# Hash synchronization is only useful with posix threads right now.
-if test "$enable_hash_synchronization" = yes && test "$THREADS" = "posix"; then
+if test "$enable_hash_synchronization" = yes; then
HASH_SYNC_SPEC=-fhash-synchronization
AC_DEFINE(JV_HASH_SYNCHRONIZATION, 1, [Define if hash synchronization is in use])
fi
Index: include/win32-threads.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/win32-threads.h,v
retrieving revision 1.5
diff -u -r1.5 win32-threads.h
--- include/win32-threads.h 2 Feb 2002 04:27:34 -0000 1.5
+++ include/win32-threads.h 20 Oct 2002 23:14:40 -0000
@@ -33,6 +33,14 @@
java::lang::Thread *thread_obj;
} _Jv_Thread_t;
+typedef DWORD _Jv_ThreadId_t;
+
+inline _Jv_ThreadId_t
+_Jv_ThreadSelf (void)
+{
+ return GetCurrentThreadId();
+}
+
typedef void _Jv_ThreadStartFunc (java::lang::Thread *);
//
Index: java/lang/natObject.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/natObject.cc,v
retrieving revision 1.22
diff -u -r1.22 natObject.cc
--- java/lang/natObject.cc 10 Mar 2002 03:53:13 -0000 1.22
+++ java/lang/natObject.cc 20 Oct 2002 23:14:43 -0000
@@ -305,9 +305,9 @@
#include <assert.h>
#include <limits.h>
#include <unistd.h> // for usleep, sysconf.
-#include <sched.h> // for sched_yield.
#include <gcj/javaprims.h>
#include <sysdep/locks.h>
+#include <java/lang/Thread.h>
// Try to determine whether we are on a multiprocessor, i.e. whether
// spinning may be profitable.
@@ -525,14 +525,14 @@
}
else if (n < yield_limit)
{
- sched_yield();
+ _Jv_ThreadYield();
}
else
{
unsigned duration = MIN_SLEEP_USECS << (n - yield_limit);
if (n >= 15 + yield_limit || duration > MAX_SLEEP_USECS)
- duration = MAX_SLEEP_USECS;
- usleep(duration);
+ duration = MAX_SLEEP_USECS;
+ java::lang::Thread::sleep(0, duration);
}
}
@@ -574,7 +574,15 @@
heavy_lock_obj_finalization_proc (void *obj, void *cd)
{
heavy_lock *hl = (heavy_lock *)cd;
+
+// This only addresses misalignment of statics, not heap objects. It
+// works only because registering statics for finalization is a noop,
+// no matter what the least significant bits are.
+#ifdef JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS
+ obj_addr_t addr = (obj_addr_t)obj & ~((obj_addr_t)0x7);
+#else
obj_addr_t addr = (obj_addr_t)obj;
+#endif
hash_entry *he = light_locks + JV_SYNC_HASH(addr);
obj_addr_t he_address = (he -> address & ~LOCKED);
@@ -753,7 +761,11 @@
void
_Jv_MonitorEnter (jobject obj)
{
+#ifdef JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS
+ obj_addr_t addr = (obj_addr_t)obj & ~((obj_addr_t)FLAGS);
+#else
obj_addr_t addr = (obj_addr_t)obj;
+#endif
obj_addr_t address;
unsigned hash = JV_SYNC_HASH(addr);
hash_entry * he = light_locks + hash;
@@ -898,7 +910,11 @@
void
_Jv_MonitorExit (jobject obj)
{
+#ifdef JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS
+ obj_addr_t addr = (obj_addr_t)obj & ~((obj_addr_t)FLAGS);
+#else
obj_addr_t addr = (obj_addr_t)obj;
+#endif
_Jv_ThreadId_t self = _Jv_ThreadSelf();
unsigned hash = JV_SYNC_HASH(addr);
hash_entry * he = light_locks + hash;
@@ -1078,7 +1094,11 @@
void
java::lang::Object::wait (jlong timeout, jint nanos)
{
+#ifdef JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS
+ obj_addr_t addr = (obj_addr_t)this & ~((obj_addr_t)FLAGS);
+#else
obj_addr_t addr = (obj_addr_t)this;
+#endif
_Jv_ThreadId_t self = _Jv_ThreadSelf();
unsigned hash = JV_SYNC_HASH(addr);
hash_entry * he = light_locks + hash;
@@ -1155,7 +1175,11 @@
void
java::lang::Object::notify (void)
{
+#ifdef JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS
+ obj_addr_t addr = (obj_addr_t)this & ~((obj_addr_t)FLAGS);
+#else
obj_addr_t addr = (obj_addr_t)this;
+#endif
_Jv_ThreadId_t self = _Jv_ThreadSelf();
unsigned hash = JV_SYNC_HASH(addr);
hash_entry * he = light_locks + hash;
@@ -1200,7 +1224,11 @@
void
java::lang::Object::notifyAll (void)
{
+#ifdef JV_LINKER_CANNOT_8BYTE_ALIGN_STATICS
+ obj_addr_t addr = (obj_addr_t)this & ~((obj_addr_t)FLAGS);
+#else
obj_addr_t addr = (obj_addr_t)this;
+#endif
_Jv_ThreadId_t self = _Jv_ThreadSelf();
unsigned hash = JV_SYNC_HASH(addr);
hash_entry * he = light_locks + hash;