Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 May 2005 11:19:22 +0200 (CEST)
From:      "Arne H. Juul" <arnej@pvv.ntnu.no>
To:        freebsd-java@freebsd.org
Subject:   Re: JDK 1.5.0: application crash with multiple threads
Message-ID:  <Pine.LNX.4.62.0505111057070.23037@decibel.pvv.ntnu.no>

next in thread | raw e-mail | index | archive | help

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@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.LNX.4.62.0505111057070.23037>