JDK 1.5.0: application crash with multiple threads

Arne H. Juul arnej at pvv.ntnu.no
Wed May 11 02:19:28 PDT 2005


On Fri, Apr 08, 2005 at 10:22:31AM -0400, Brian Clapper wrote:
> I have a multithreaded application that is crashing under JDK 1.5.0 when
> using multiple threads. Works fine (and has worked fine for quite some
> time) with JDK 1.4.2.

I've spent some days tracing down this problem, and found this fix:

diff -ru jdk15.orig/hotspot/src/os/bsd/vm/os_bsd.inline.hpp jdk15/hotspot/src/os/bsd/vm/os_bsd.inline.hpp
--- jdk15.orig/hotspot/src/os/bsd/vm/os_bsd.inline.hpp	Wed May 11 10:59:36 2005
+++ jdk15/hotspot/src/os/bsd/vm/os_bsd.inline.hpp	Wed May 11 08:03:59 2005
@@ -29,10 +29,9 @@

  inline bool os::allocate_stack_guard_pages() {
    assert(uses_stack_guard_pages(), "sanity check");
-// XXXBSD: ??
-//  return thr_main();
-//  return pthread_main_np();
-  return true;
+  // since FreeBSD 4 uses malloc() for allocating the thread stack
+  // there is no need to do anything extra to allocate the guard pages
+  return false;
  }


What happens is this:

When a thread is started the stack is allocated via malloc(),
and then the bottom is the stack is again "allocated" via
commit_memory() and protected via guard_memory().  When the
thread is done it is "freed" via uncommit_memory() which mmaps
the memory with PROT_NONE, and then it is free()d as well.
Soon, when malloc() is used (for something else) it returns
a pointer into this region and when that pointer is used SIGBUS
happens.  The only reason this works in the java14 port is
that uncommit_memory() doesn't do what it is supposed to there.

-- 
Arne H Juul                       Mail:  arnej at europe.yahoo-inc.com
Release engineer                  Web:   http://www.yahoo.com/
Yahoo Norway                      Phone: +47 7320 1219
Prinsensgate 49, 7013 Trondheim   Fax:   +47 7320 1201



More information about the freebsd-java mailing list