From owner-freebsd-java@FreeBSD.ORG Thu Feb 23 09:57:48 2006 Return-Path: X-Original-To: freebsd-java@freebsd.org 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 41D4316A420 for ; Thu, 23 Feb 2006 09:57:48 +0000 (GMT) (envelope-from arnej@pvv.ntnu.no) Received: from decibel.pvv.ntnu.no (decibel.pvv.ntnu.no [129.241.210.179]) by mx1.FreeBSD.org (Postfix) with SMTP id 7577043D48 for ; Thu, 23 Feb 2006 09:57:46 +0000 (GMT) (envelope-from arnej@pvv.ntnu.no) Received: (qmail 25784 invoked by uid 27959); 23 Feb 2006 09:57:45 -0000 Date: Thu, 23 Feb 2006 10:57:45 +0100 (CET) From: "Arne H. Juul" To: Ashley Moran In-Reply-To: <200602221524.35585.work@ashleymoran.me.uk> Message-ID: References: <200602221524.35585.work@ashleymoran.me.uk> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed Cc: freebsd-java@freebsd.org Subject: Re: i386 java binaries causing 100% cpu on amd64 X-BeenThere: freebsd-java@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Porting Java to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 23 Feb 2006 09:57:48 -0000 On Wed, 22 Feb 2006, Ashley Moran wrote: > I have an Althlon 64 server running 6.0-rel in amd64 mode. I'm trying to > compile JDK 1.5 on it, and I've gone about it two ways: > > * installing the binary package of the native JDK 1.4 created on my i386 > desktop > * installing emulators/linux_base and the Linux JDK 1.4 > > In both cases, when I run java -version, it does nothing but takes up 100% > CPU. I've stress-tested the system by running an i386 version of the > misc/chef port, and that runs, so the issue is not with i386 binaries in > general. this sounds like the problem I saw where the jdk tries to execute code from the data segment, and the amd64 CPU actually honors the execute protection (i386 traditionally has no notion of execute protection). I think you can use an i386 version of jdk 1.5 to bootstrap, or recompile your i386 jdk 1.4 with the patches below. > Date: Thu, 16 Feb 2006 22:39:30 +0100 > From: Arne Juul > To: freebsd-java@freebsd.org > Subject: executing data needs mprotect with PROT_EXEC > > I've been trying to run some FreeBSD4 packages > inside a jail on a FreeBSD6 / amd64 box; and I've > hit a problem with ports/jdk. > > A couple of places the VM uses an array of > integers, puts code in it, and executes it. > > This doesn't work on machines where the CPU > honors the PROT_EXEC settings; this can be > different on different machines (depending on > BIOS settings probably). > > The right fix is to call mprotect() from jdk to allow > execution of the memory in question, something like this: --- ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Tue Feb 14 21:12:46 2006 +++ ../../hotspot/src/os_cpu/bsd_i486/vm/os_bsd_i486.cpp Wed Feb 15 16:30:49 2006 @@ -561,6 +562,9 @@ } #else static void (*fixcw)(void) = CAST_TO_FN_PTR(void (*)(void), code_template); + + ::mprotect((void *)code_template, sizeof(code_template), + PROT_EXEC | PROT_READ | PROT_WRITE); #endif fixcw(); --- ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Thu Sep 11 03:40:14 2003 +++ ../../hotspot/src/cpu/i486/vm/vm_version_i486.cpp Tue Feb 14 23:34:40 2006 @@ -9,6 +9,8 @@ # include "incls/_precompiled.incl" # include "incls/_vm_version_i486.cpp.incl" +#include +#include int VM_Version::_cpu; int VM_Version::_cpuFeatures; @@ -145,6 +147,10 @@ ResourceMark rm; // Making this stub must be FIRST use of assembler CodeBuffer* c = new CodeBuffer(address(stubCode), sizeof(stubCode)); + + ::mprotect((void *)stubCode, sizeof(stubCode), + PROT_EXEC | PROT_READ | PROT_WRITE); + VM_Version_StubGenerator g(c); getPsrInfo_stub = CAST_TO_FN_PTR(_getPsrInfo_stub_t, g.generate_getPsrInfo());