From owner-freebsd-java@FreeBSD.ORG Wed May 11 09:19:28 2005 Return-Path: Delivered-To: freebsd-java@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 8F54416A4D0 for ; Wed, 11 May 2005 09:19:28 +0000 (GMT) Received: from decibel.pvv.ntnu.no (decibel.pvv.ntnu.no [129.241.210.179]) by mx1.FreeBSD.org (Postfix) with SMTP id E012243D66 for ; Wed, 11 May 2005 09:19:26 +0000 (GMT) (envelope-from arnej@pvv.ntnu.no) Received: (qmail 31221 invoked by uid 27959); 11 May 2005 09:19:22 -0000 Date: Wed, 11 May 2005 11:19:22 +0200 (CEST) From: "Arne H. Juul" To: freebsd-java@freebsd.org Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Subject: Re: JDK 1.5.0: application crash with multiple threads X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 11 May 2005 09:19:28 -0000 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