[Midnightbsd-cvs] mports [20225] trunk/java/openjdk6: update openjdk 6

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Sep 12 20:58:26 EDT 2015


Revision: 20225
          http://svnweb.midnightbsd.org/mports/?rev=20225
Author:   laffer1
Date:     2015-09-12 20:58:25 -0400 (Sat, 12 Sep 2015)
Log Message:
-----------
update openjdk 6

Modified Paths:
--------------
    trunk/java/openjdk6/Makefile
    trunk/java/openjdk6/Makefile.icedtea
    trunk/java/openjdk6/distinfo
    trunk/java/openjdk6/files/patch-set

Removed Paths:
-------------
    trunk/java/openjdk6/files/patch-sharedRuntime_x86_64.cpp

Modified: trunk/java/openjdk6/Makefile
===================================================================
--- trunk/java/openjdk6/Makefile	2015-09-13 00:45:55 UTC (rev 20224)
+++ trunk/java/openjdk6/Makefile	2015-09-13 00:58:25 UTC (rev 20225)
@@ -1,27 +1,16 @@
 # $MidnightBSD$
 
 PORTNAME=	openjdk6
-PORTVERSION=	b27
-PORTREVISION?=	2
+PORTVERSION=	b36
+PORTEPOCH=	1
 CATEGORIES=	java devel
-MASTER_SITES=	http://download.java.net/openjdk/jdk6/promoted/${PORTVERSION}/ \
-		http://download.java.net/jaxp/openjdk/jdk6/:jaxp \
-		http://download.java.net/glassfish/components/jax-ws/openjdk/jdk6/:jaxws \
-		https://java.net/downloads/jax-ws/OpenJDK6/:jaf \
-		http://icedtea.classpath.org/download/drops/:jaxp \
-		http://icedtea.classpath.org/download/drops/:jaxws \
-		http://icedtea.classpath.org/download/drops/:jaf \
-		http://icedtea.wildebeest.org/download/drops/:jaxp \
-		http://icedtea.wildebeest.org/download/drops/:jaxws \
-		http://icedtea.wildebeest.org/download/drops/:jaf \
-		APACHE/ant/binaries/:ant \
-		http://download.java.net/openjdk/jtreg/promoted/4.1/${JTREGVERSION}/:jtreg
+MASTER_SITES=	APACHE/ant/binaries/:ant \
+		http://download.java.net/openjdk/jtreg/promoted/4.1/b05/:jtreg \
+		https://java.net/downloads/openjdk6/ \
+		LOCAL/jkim
 DISTNAME=	openjdk-6-src-${PORTVERSION}-${OPENJDK_BUILDDATE}
-DISTFILES=	${DISTNAME}${EXTRACT_SUFX} \
-		${JAXPFILE}:jaxp \
-		${JAXWSFILE}:jaxws \
-		${JAFFILE}:jaf \
-		${ANTFILE}:ant
+DISTFILES=	${ANTFILE}:ant \
+		${DISTNAME}${EXTRACT_SUFX}
 EXTRACT_ONLY=	${DISTNAME}${EXTRACT_SUFX} ${ANTFILE}
 
 MAINTAINER=	luke at midnightbsd.org
@@ -36,7 +25,7 @@
 RUN_DEPENDS=	javavm:${PORTSDIR}/java/javavmwrapper \
 		${LOCALBASE}/share/fonts/dejavu:${PORTSDIR}/x11-fonts/dejavu
 
-OPENJDK_BUILDDATE=	26_oct_2012
+OPENJDK_BUILDDATE=	22_jul_2015
 
 OPTIONS_DEFINE=	ICEDTEA IPV6 POLICY SOUND TZUPDATE
 OPTIONS_DEFAULT=ICEDTEA IPV6 TZUPDATE
@@ -46,40 +35,39 @@
 TZUPDATE_DESC=	Update the time zone data
 
 .if !defined(BUILD_JRE)
-OPTIONS_DEFINE+=DEBUG FASTDEBUG TEST
+OPTIONS_DEFINE+=TEST
+OPTIONS_RADIO=	DEVEL
+DEVEL_DESC=	Build for OpenJDK development
+OPTIONS_RADIO_DEVEL=	DEBUG FASTDEBUG
 DEBUG_DESC=	Enable legacy debugging support
 FASTDEBUG_DESC=	Include fastdebug build
 TEST_DESC=	Add support for running regression test
 .endif
 
+PKGDEINSTALL=	${WRKDIR}/pkg-deinstall
+PKGINSTALL=	${WRKDIR}/pkg-install
+
+USES=		compiler gmake iconv motif tar:xz
+
 .include <bsd.mport.options.mk>
 .include "${.CURDIR}/../openjdk6/Makefile.icedtea"
+.include "${.CURDIR}/../openjdk6/Makefile.test"
 
-EXTRA_PATCHES=	${ICEDTEA_PATCHES}
+EXTRA_PATCHES+=	${ICEDTEA_PATCHES}
 
 # java extracts directly to the cwd
 WRKSRC=		${WRKDIR}
 
-USES=		gmake
-USE_MOTIF=	yes
 USE_XORG=	x11 xext xi xt xtst
 
-JAXP_BUILD=	144_05
-JAXPFILE=	jaxp${JAXP_BUILD}.zip
-JAXWS_BUILD=	2_1_6-2011_06_13
-JAXWSFILE=	jdk6-jaxws${JAXWS_BUILD}.zip
-JAF_BUILD=	b20
-JAFFILE=	jdk6-jaf-${JAF_BUILD}.zip
-JTREGVERSION=	b04
-JTREGFILE=	jtreg-4.1-bin-${JTREGVERSION}_14_mar_2012.zip
-UPDATE_VERSION=	32
-
 # do not depend on devel/apache-ant to avoid circular dependency, but
 # use .tar.bz2 distfile to avoid duplicated downloads
 ANTVERSION=	1.9.4
 ANTFILE=	apache-ant-${ANTVERSION}-bin.tar.bz2
 
-.include <bsd.port.pre.mk>
+JTREG_BUILD=	b05_29_nov_2012
+JTREGFILE=	jtreg-4.1-bin-${JTREG_BUILD}.zip
+UPDATE_VERSION=	32
 
 .if ${PORT_OPTIONS:MIPV6}
 CATEGORIES+=	ipv6
@@ -108,7 +96,6 @@
 BUILD_DEPENDS+=		${BOOTSTRAPJDKDIR}/bin/javac:${PORTSDIR}/java/bootstrap-openjdk
 .endif
 
-FETCH_ARGS=	-Fpr
 MAKE_ENV=	LANG=C LC_ALL=C OS= \
 		ARCH=${ARCH} \
 		ARCH_DATA_MODEL=64 \
@@ -130,16 +117,9 @@
 		MILESTONE=fcs \
 		JDK_UPDATE_VERSION=${UPDATE_VERSION}
 
-# HotSpot wants CCC instead of CXX.  Also, HotSpot SA wants GCC.
-MAKE_ENV+=	CCC="${CXX}" GCC="${CC}"
-
-# XXX Turn off -Werror from HotSpot.
-MAKE_ENV+=	WARNINGS_ARE_ERRORS="${WARNINGS_ARE_ERRORS}"
-
 # XXX Turn off parallel build by default.
-_MAKE_JOBS=	#
-MAKE_ENV+=	ALT_PARALLEL_COMPILE_JOBS=${MAKE_JOBS_NUMBER} \
-		HOTSPOT_BUILD_JOBS=${MAKE_JOBS_NUMBER}
+MAKE_JOBS_UNSAFE=	yes
+MAKE_ENV+=	HOTSPOT_BUILD_JOBS=${MAKE_JOBS_NUMBER}
 
 .if ${PORT_OPTIONS:MDEBUG}
 ALL_TARGET=	debug_build
@@ -146,7 +126,6 @@
 OPENJDK_OSARCH=	bsd-${ARCH:S/i386/i586/}-debug
 .else
 OPENJDK_OSARCH=	bsd-${ARCH:S/i386/i586/}
-WARNINGS_ARE_ERRORS?=	-w
 .endif
 
 # disable FASTDEBUG_BUILD by default to improve compile time.
@@ -160,6 +139,10 @@
 MAKE_ENV+=	DONT_ENABLE_IPV6="YES"
 .endif
 
+.if ${PORT_OPTIONS:MPOLICY}
+MAKE_ENV+=	UNLIMITED_CRYPTO="YES"
+.endif
+
 .if ${PORT_OPTIONS:MSOUND}
 EXTRA_PATCHES+=	${FILESDIR}/alsa-enable.patch
 LIB_DEPENDS+=	libasound.so:${PORTSDIR}/audio/alsa-lib
@@ -178,23 +161,12 @@
 .endif
 
 COPYDIRS=	\
-	hotspot/src/os/linux/vm \
-	hotspot/src/os_cpu/linux_x86/vm \
-	hotspot/agent/src/os/linux \
-	hotspot/make/linux \
-	hotspot/make/linux/makefiles \
-	hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/linux \
-	hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/linux/amd64 \
-	hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/linux/x86 \
-	hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/linux \
-	hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/linux_amd64 \
-	hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/linux_x86 \
 	jdk/src/linux/doc/man
 
 COPYFILES=	\
 	corba/make/common/Defs-linux.gmk \
 	corba/make/common/shared/Defs-linux.gmk \
-	hotspot/agent/src/share/classes/sun/jvm/hotspot/LinuxVtblAccess.java \
+	hotspot/src/os/linux/vm/decoder_linux.cpp \
 	jdk/make/com/sun/tools/attach/mapfile-linux \
 	jdk/make/common/Defs-linux.gmk \
 	jdk/make/common/shared/Defs-linux.gmk \
@@ -209,6 +181,28 @@
 	jdk/src/solaris/native/java/net/linux_close.c \
 	jdk/src/solaris/native/sun/tools/attach/LinuxVirtualMachine.c
 
+.include <bsd.port.pre.mk>
+
+.if ${COMPILER_TYPE} == clang
+.if ${COMPILER_VERSION} >= 35
+MAKE_ENV+=	COMPILER_WARNINGS_FATAL=false
+.endif
+MAKE_ENV+=	USE_CLANG=true
+.endif
+
+# GCC is broken with PCH: https://lists.freebsd.org/pipermail/svn-src-all/2015-March/101722.html
+.if ${COMPILER_TYPE} == gcc
+MAKE_ENV+=	USE_PRECOMPILED_HEADER=0
+.endif
+
+.if empty(ICONV_LIB)
+ICONV_CPPFLAGS=	-DLIBICONV_PLUG
+.else
+ICONV_CPPFLAGS=	-I${LOCALBASE}/include
+ICONV_LDFLAGS=	-L${LOCALBASE}/lib ${ICONV_LIB}
+.endif
+ZLIB_LDFLAGS?=	-lz
+
 post-extract:
 	@for d in ${COPYDIRS}; do \
 		${MKDIR} `echo ${WRKSRC}/$$d | ${SED} 's/linux/bsd/g;'`; \
@@ -225,27 +219,49 @@
 		${SED} 's/linux/bsd/g; s/Linux/Bsd/g' < ${WRKSRC}/$$f > ${WRKSRC}/$$t; \
 	done
 	@${SED} 's/solaris/bsd/g; s/Solaris/Bsd/g' \
-		< ${WRKSRC}/jdk/src/solaris/hpi/native_threads/src/threads_solaris.c \
-		> ${WRKSRC}/jdk/src/solaris/hpi/native_threads/src/threads_bsd.c
-	@${SED} "s|/usr/local|${LOCALBASE}|" < ${FILESDIR}/fontconfig.properties \
-		> ${WRKSRC}/jdk/src/solaris/classes/sun/awt/fontconfigs/bsd.fontconfig.properties
-	@${SED} "s|%%LOCALBASE%%|${LOCALBASE}|" < ${FILESDIR}/Makefile.test \
-		> ${WRKSRC}/jdk/test/Makefile
-	@${FIND} ${WRKSRC}/jdk/test -type f -name \*.sh -exec ${SED} -i "" -e s/Linux/FreeBSD/g {} \;
+	    ${WRKSRC}/jdk/src/solaris/hpi/native_threads/src/threads_solaris.c > \
+	    ${WRKSRC}/jdk/src/solaris/hpi/native_threads/src/threads_bsd.c
+	@${SED} "s|/usr/local|${LOCALBASE}|" \
+	    ${FILESDIR}/fontconfig.properties > \
+	    ${WRKSRC}/jdk/src/solaris/classes/sun/awt/fontconfigs/bsd.fontconfig.properties
+	@${SED} "s|%%LOCALBASE%%|${LOCALBASE}|" ${FILESDIR}/Makefile.test.in > \
+	    ${WRKSRC}/jdk/test/Makefile
+	@${FIND} ${WRKSRC}/jdk/test -type f -name \*.sh -exec ${SED} -i "" \
+	    -e s/Linux/FreeBSD/g {} \;
 
 post-patch:
-	@${REINPLACE_CMD} "s|/lib:/usr/lib|/lib:/usr/lib:${LOCALBASE}/lib|" \
-		${WRKSRC}/hotspot/src/os/bsd/vm/os_bsd.cpp
-.if ${PORT_OPTIONS:MPOLICY}
-	@${REINPLACE_CMD} 's|build-policy install-limited|build-policy install-unlimited|' \
-		${WRKSRC}/jdk/make/javax/crypto/Makefile
+	@${REINPLACE_CMD} -e "s|%%CXX_LDFLAGS%%|${CXX_LDFLAGS}|" \
+	    ${WRKSRC}/corba/make/common/Defs-bsd.gmk \
+	    ${WRKSRC}/jdk/make/common/Defs-bsd.gmk
+.if ${COMPILER_TYPE} == "clang"
+	@${REINPLACE_CMD} -e "s|-fno-omit-frame-pointer|-fno-omit-frame-pointer -mno-omit-leaf-frame-pointer|" \
+	    ${WRKSRC}/corba/make/common/Defs-bsd.gmk \
+	    ${WRKSRC}/hotspot/make/bsd/makefiles/amd64.make \
+	    ${WRKSRC}/jdk/make/common/Defs-bsd.gmk
 .endif
-.if empty(ICONV_LIB)
-	@${REINPLACE_CMD} 's| -liconv||' \
-		${WRKSRC}/Makefile \
-		${WRKSRC}/jdk/make/sun/splashscreen/Makefile \
-		${WRKSRC}/jdk/make/java/npt/Makefile \
-		${WRKSRC}/jdk/make/java/instrument/Makefile
+	@${REINPLACE_CMD} -e "s|%%ICONV_CPPFLAGS%%|${ICONV_CPPFLAGS}|" \
+	    -e "s|%%ICONV_LDFLAGS%%|${ICONV_LDFLAGS}|" \
+	    ${WRKSRC}/Makefile ${WRKSRC}/jdk/make/java/instrument/Makefile \
+	    ${WRKSRC}/jdk/make/java/npt/Makefile \
+	    ${WRKSRC}/jdk/make/sun/splashscreen/Makefile
+	@${REINPLACE_CMD} -e "s|%%ZLIB_LDFLAGS%%|${ZLIB_LDFLAGS}|" \
+	    ${WRKSRC}/jdk/make/com/sun/java/pack/Makefile \
+	    ${WRKSRC}/jdk/make/common/Program.gmk \
+	    ${WRKSRC}/jdk/make/java/jli/Makefile \
+	    ${WRKSRC}/jdk/make/java/zip/Makefile \
+	    ${WRKSRC}/jdk/make/tools/freetypecheck/Makefile
+	@${REINPLACE_CMD} -e "s|%%LOCALBASE%%|${LOCALBASE}|" \
+	    ${WRKSRC}/hotspot/src/os/bsd/vm/os_bsd.cpp \
+	    ${WRKSRC}/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java \
+	    ${WRKSRC}/jdk/src/share/classes/sun/print/PSPrinterJob.java
+.if defined(BUILD_JRE)
+	@${REINPLACE_CMD} -e "s|%%JAVA_HOME%%|${PREFIX}/openjdk6-jre|" \
+	    ${WRKSRC}/hotspot/src/os/posix/launcher/java_md.c \
+	    ${WRKSRC}/jdk/src/solaris/bin/java_md.c
+.else
+	@${REINPLACE_CMD} -e "s|%%JAVA_HOME%%|${PREFIX}/openjdk6|" \
+	    ${WRKSRC}/hotspot/src/os/posix/launcher/java_md.c \
+	    ${WRKSRC}/jdk/src/solaris/bin/java_md.c
 .endif
 
 post-build:
@@ -254,11 +270,11 @@
 .if defined(BUILD_JRE)
 	@${RM} -rf ${WRKSRC}/build/${OPENJDK_OSARCH}/j2re-image/lib/zi
 	@${LN} -s -f ${LOCALBASE}/share/java/zi \
-		${WRKSRC}/build/${OPENJDK_OSARCH}/j2re-image/lib
+	    ${WRKSRC}/build/${OPENJDK_OSARCH}/j2re-image/lib
 .else
 	@${RM} -rf ${WRKSRC}/build/${OPENJDK_OSARCH}/j2sdk-image/jre/lib/zi
 	@${LN} -s -f ${LOCALBASE}/share/java/zi \
-		${WRKSRC}/build/${OPENJDK_OSARCH}/j2sdk-image/jre/lib
+	    ${WRKSRC}/build/${OPENJDK_OSARCH}/j2sdk-image/jre/lib
 .endif
 .endif
 .if ${PORT_OPTIONS:MTEST}
@@ -268,78 +284,71 @@
 	@${ECHO_MSG} "Unset the environment DISPLAY variable to run tests in a virtual X server."
 .endif
 	@${ECHO_MSG} ""
-
-test: build-depends build
-.if !defined(DISPLAY)
-	@${LOCALBASE}/bin/Xvfb :1001 -screen 0 800x600x24 -fp ${LOCALBASE}/lib/X11/fonts/misc > /dev/null 2>&1 & ${ECHO} $$! > ${WRKDIR}/.Xvfb.pid
 .endif
-	@-(cd ${WRKSRC}/jdk/test; ${SETENV} ${MAKE_ENV} ${GMAKE} tests)
-.if !defined(DISPLAY)
-	@-${CAT} ${WRKDIR}/.Xvfb.pid | ${XARGS} kill
-	@${RM} -f ${WRKDIR}/.Xvfb.pid
-.endif
-	@${ECHO_MSG} ""
-	@${ECHO_MSG} "You can run \"make test\" again to re-execute only the failed tests."
-	@${ECHO_MSG} ""
-.endif
 
 do-install:
 .if defined(BUILD_JRE)
-	@${MKDIR} ${PREFIX}/openjdk6-jre/
 	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}/j2re-image && \
-		${COPYTREE_SHARE} . ${PREFIX}/openjdk6-jre
-	@${CHOWN} ${BINOWN}:${BINGRP} ${PREFIX}/openjdk6-jre/bin/* \
-		${PREFIX}/openjdk6-jre/lib/${ARCH}/jexec
-	@${CHMOD} ${BINMODE} ${PREFIX}/openjdk6-jre/bin/* \
-		${PREFIX}/openjdk6-jre/lib/${ARCH}/jexec
-	@${ECHO_MSG} "@unexec ${LOCALBASE}/bin/unregistervm ${PREFIX}/openjdk6-jre/bin/java" >> ${TMPPLIST}
-	@${FIND} -s ${PREFIX}/openjdk6-jre -not -type d | \
-		${SED} -e 's#^${PREFIX}/##' >> ${TMPPLIST}
-	@${ECHO} "@exec mkdir ${PREFIX}/openjdk6-jre/lib/applet" >> ${TMPPLIST}
-	@${FIND} ${PREFIX}/openjdk6-jre -type d | ${SORT} -r | \
-		${SED} 's,^${PREFIX}/, at dirrm ,' >> ${TMPPLIST}
-	@${ECHO_MSG} "@exec ${LOCALBASE}/bin/registervm '${PREFIX}/openjdk6-jre/bin/java # OpenJDK6 JRE'" >> ${TMPPLIST}
+	    ${COPYTREE_SHARE} . ${STAGEDIR}${PREFIX}/openjdk6-jre \
+	    "-not ( -type d -name bin -prune )"
+	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}/j2re-image && \
+	    ${COPYTREE_BIN} bin ${STAGEDIR}${PREFIX}/openjdk6-jre
+	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}/j2re-image && \
+	    ${INSTALL_PROGRAM} lib/${ARCH}/jexec \
+	    ${STAGEDIR}${PREFIX}/openjdk6-jre/lib/${ARCH}
 .else
-	@${MKDIR} ${PREFIX}/openjdk6/
 	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}/j2sdk-image && \
-		${COPYTREE_SHARE} . ${PREFIX}/openjdk6
-	@${INSTALL_DATA} ${WRKSRC}/build/${OPENJDK_OSARCH}/btjars/compilefontconfig.jar ${WRKSRC}/build/${OPENJDK_OSARCH}/btjars/javazic.jar ${PREFIX}/openjdk6/jre/lib/
-	@for dir in `${FIND} ${PREFIX}/openjdk6 -name bin -type d`; do \
-		${CHOWN} -h -R ${BINOWN}:${BINGRP} $$dir; \
-		${FIND} $$dir -type f -exec ${CHMOD} ${BINMODE} "{}" \; ; \
-	done
-	@${CHOWN} ${BINOWN}:${BINGRP} \
-		${PREFIX}/openjdk6/jre/lib/${ARCH}/jexec
-	@${CHMOD} ${BINMODE} \
-		${PREFIX}/openjdk6/jre/lib/${ARCH}/jexec
+	    ${COPYTREE_SHARE} . ${STAGEDIR}${PREFIX}/openjdk6 \
+	    "-not ( -type d -name bin -prune )"
+	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}/j2sdk-image && \
+	    ${COPYTREE_BIN} "bin jre/bin" ${STAGEDIR}${PREFIX}/openjdk6
+	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}/j2sdk-image && \
+	    ${INSTALL_PROGRAM} jre/lib/${ARCH}/jexec \
+	    ${STAGEDIR}${PREFIX}/openjdk6/jre/lib/${ARCH}
+	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}/btjars && \
+	    ${INSTALL_DATA} compilefontconfig.jar javazic.jar \
+	    ${STAGEDIR}${PREFIX}/openjdk6/jre/lib
 .if ${PORT_OPTIONS:MFASTDEBUG}
-	@${MKDIR} ${PREFIX}/openjdk6-fastdebug/
-	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}/j2sdk-image && \
-		${COPYTREE_SHARE} . ${PREFIX}/openjdk6-fastdebug
-	@for dir in `${FIND} ${PREFIX}/openjdk6-fastdebug -name bin -type d`; do \
-		${CHOWN} -h -R ${BINOWN}:${BINGRP} $$dir; \
-		${FIND} $$dir -type f -exec ${CHMOD} ${BINMODE} "{}" \; ; \
-	done
-	@${CHOWN} ${BINOWN}:${BINGRP} \
-		${PREFIX}/openjdk6-fastdebug/jre/lib/${ARCH}/jexec
-	@${CHMOD} ${BINMODE} \
-		${PREFIX}/openjdk6-fastdebug/jre/lib/${ARCH}/jexec
+	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}-fastdebug/j2sdk-image && \
+	    ${COPYTREE_SHARE} . ${STAGEDIR}${PREFIX}/openjdk6-fastdebug \
+	    "-not ( -type d -name bin -prune )"
+	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}-fastdebug/j2sdk-image && \
+	    ${COPYTREE_BIN} "bin jre/bin" \
+	    ${STAGEDIR}${PREFIX}/openjdk6-fastdebug
+	@cd ${WRKSRC}/build/${OPENJDK_OSARCH}-fastdebug/j2sdk-image && \
+	    ${INSTALL_PROGRAM} jre/lib/${ARCH}/jexec \
+	    ${STAGEDIR}${PREFIX}/openjdk6-fastdebug/jre/lib/${ARCH}
 .endif
-	@${ECHO_MSG} "@unexec ${LOCALBASE}/bin/unregistervm ${TRUE_PREFIX}/openjdk6/bin/java" >> ${TMPPLIST}
-	@${FIND} -s ${PREFIX}/openjdk6 -not -type d | \
-		${SED} -e 's#^${PREFIX}/##' >> ${TMPPLIST}
-	@${ECHO} "@exec mkdir ${TRUE_PREFIX}/openjdk6/jre/lib/applet" >> ${TMPPLIST}
-	@${FIND} ${PREFIX}/openjdk6 -type d | ${SORT} -r | \
-		${SED} 's,^${PREFIX}/, at dirrm ,' >> ${TMPPLIST}
-	@${ECHO_MSG} "@exec ${LOCALBASE}/bin/registervm '${TRUE_PREFIX}/openjdk6/bin/java # OpenJDK6'" >> ${TMPPLIST}
+.endif
+	@${ECHO_CMD} "#!/bin/sh" > ${PKGDEINSTALL}
+	@${ECHO_CMD} "#!/bin/sh" > ${PKGINSTALL}
+.if defined(BUILD_JRE)
+	@cd ${STAGEDIR}${PREFIX}/openjdk6-jre && \
+	    ${FIND} -s . -not -type d | \
+	    ${SED} -e 's,^\./,openjdk6-jre/,' >> ${TMPPLIST}
+	@cd ${STAGEDIR}${PREFIX}/openjdk6-jre && \
+	    ${FIND} -s . -type d -empty | \
+	    ${SED} 's,^\./, at dir openjdk6-jre/,' >> ${TMPPLIST}
+	@${ECHO_CMD} '${TEST} $$2 = DEINSTALL && ${LOCALBASE}/bin/unregistervm ${PREFIX}/openjdk6-jre/bin/java' >> ${PKGDEINSTALL}
+	@${ECHO_CMD} '${TEST} $$2 = POST-INSTALL && ${LOCALBASE}/bin/registervm "${PREFIX}/openjdk6-jre/bin/java # OpenJDK6 JRE"' >> ${PKGINSTALL}
+.else
+	@cd ${STAGEDIR}${PREFIX}/openjdk6 && \
+	    ${FIND} -s . -not -type d | \
+	    ${SED} -e 's,^\./,openjdk6/,' >> ${TMPPLIST}
+	@cd ${STAGEDIR}${PREFIX}/openjdk6 && \
+	    ${FIND} -s . -type d -empty | \
+	    ${SED} 's,^\./, at dir openjdk6/,' >> ${TMPPLIST}
+	@${ECHO_CMD} '${TEST} $$2 = DEINSTALL && ${LOCALBASE}/bin/unregistervm ${PREFIX}/openjdk6/bin/java' >> ${PKGDEINSTALL}
+	@${ECHO_CMD} '${TEST} $$2 = POST-INSTALL && ${LOCALBASE}/bin/registervm "${PREFIX}/openjdk6/bin/java # OpenJDK6"' >> ${PKGINSTALL}
 .if ${PORT_OPTIONS:MFASTDEBUG}
-	@${ECHO_MSG} "@unexec ${LOCALBASE}/bin/unregistervm ${TRUE_PREFIX}/openjdk6-fastdebug/bin/java" >> ${TMPPLIST}
-	@${FIND} -s ${PREFIX}/openjdk6-fastdebug -not -type d | \
-		${SED} -e 's#^${PREFIX}/##' >> ${TMPPLIST}
-	@${ECHO} "@exec mkdir ${TRUE_PREFIX}/openjdk6-fastdebug/jre/lib/applet" >> ${TMPPLIST}
-	@${FIND} ${PREFIX}/openjdk6-fastdebug -type d | ${SORT} -r | \
-		${SED} 's,^${PREFIX}/, at dirrm ,' >> ${TMPPLIST}
-	@${ECHO_MSG} "@exec ${LOCALBASE}/bin/registervm '${TRUE_PREFIX}/openjdk6-fastdebug/bin/java # OpenJDK6'" >> ${TMPPLIST}
+	@cd ${STAGEDIR}${PREFIX}/openjdk6-fastdebug && \
+	    ${FIND} -s . -not -type d | \
+	    ${SED} -e 's,^\./,openjdk6-fastdebug/,' >> ${TMPPLIST}
+	@cd ${STAGEDIR}${PREFIX}/openjdk6-fastdebug && \
+	    ${FIND} -s . -type d -empty | \
+	    ${SED} 's,^\./, at dir openjdk6-fastdebug/,' >> ${TMPPLIST}
+	@${ECHO_CMD} '${TEST} $$2 = DEINSTALL && ${LOCALBASE}/bin/unregistervm ${PREFIX}/openjdk6-fastdebug/bin/java' >> ${PKGDEINSTALL}
+	@${ECHO_CMD} '${TEST} $$2 = POST-INSTALL && ${LOCALBASE}/bin/registervm "${PREFIX}/openjdk6-fastdebug/bin/java # OpenJDK6"' >> ${PKGINSTALL}
 .endif
 
 post-install:
@@ -346,5 +355,7 @@
 	(cd ${PREFIX}/openjdk6/include/ && ${LN} -s freebsd midnightbsd)
 
 .endif
+	@${ECHO_CMD} "exit 0" >> ${PKGDEINSTALL}
+	@${ECHO_CMD} "exit 0" >> ${PKGINSTALL}
 
 .include <bsd.port.post.mk>

Modified: trunk/java/openjdk6/Makefile.icedtea
===================================================================
--- trunk/java/openjdk6/Makefile.icedtea	2015-09-13 00:45:55 UTC (rev 20224)
+++ trunk/java/openjdk6/Makefile.icedtea	2015-09-13 00:58:25 UTC (rev 20225)
@@ -1,170 +1,10 @@
 # $MidnightBSD$
 
-_PATCHES= \
-	jaxp.patch \
-	jaxws.patch \
-	security/20120830/7182135-impossible_to_use_some_editors_directly.patch \
-	security/20130201/7201068.patch \
-	security/20130201/6563318.patch \
-	security/20130201/6664509.patch \
-	security/20130201/6776941.patch \
-	security/20130201/7141694.patch \
-	security/20130201/7173145.patch \
-	security/20130201/7186945.patch \
-	security/20130201/7186948.patch \
-	security/20130201/7186952.patch \
-	security/20130201/7186954.patch \
-	security/20130201/7192392.patch \
-	security/20130201/7192393.patch \
-	security/20130201/7192977.patch \
-	security/20130201/7197546.patch \
-	security/20130201/7200491.patch \
-	security/20130201/7200500.patch \
-	security/20130201/7201064.patch \
-	security/20130201/7201066.patch \
-	security/20130201/7201070.patch \
-	security/20130201/7201071.patch \
-	security/20130201/8000210.patch \
-	security/20130201/8000537.patch \
-	security/20130201/8000540.patch \
-	security/20130201/8000631.patch \
-	security/20130201/8001242.patch \
-	security/20130201/8001307.patch \
-	security/20130201/8001972.patch \
-	security/20130201/8002325.patch \
-	security/20130219/8006446.patch \
-	security/20130219/8006777.patch \
-	security/20130219/8007688.patch \
-	security/20130304/8007014.patch \
-	security/20130304/8007675.patch \
-	openjdk/7036559-concurrenthashmap_improvements.patch \
-	security/20130416/8009063.patch \
-	openjdk/8004302-soap_test_failure.patch \
-	security/20130416/6657673.patch \
-	security/20130416/6657673-fixup.patch \
-	openjdk/7133220-factory_finder_parser_transform_useBSClassLoader.patch \
-	security/20130416/6657673-factory_finder.patch \
-	openjdk/6669869-queries_per_appcontext.patch \
-	openjdk/5102804-memory_leak.patch \
-	openjdk/6963811-deadlock_fix.patch \
-	openjdk/7064279-resource_release.patch \
-	openjdk/7064279-fixup.patch \
-	security/20130416/7200507.patch \
-	security/20130416/8000724.patch \
-	security/20130416/8004986.patch \
-	openjdk/6501644-icu_sync.patch \
-	openjdk/6886358-layout_update.patch \
-	security/20130416/8001031.patch \
-	openjdk/7017324-kerning_crash.patch \
-	security/20130416/8001040.patch \
-	security/20130416/8001322.patch \
-	security/20130416/8001329.patch \
-	security/20130416/8003335.patch \
-	security/20130416/8003445.patch \
-	security/20130416/8003543.patch \
-	security/20130416/8004261.patch \
-	security/20130416/8004336.patch \
-	security/20130416/8005432.patch \
-	security/20130416/8005943.patch \
-	security/20130416/8006309.patch \
-	security/20130416/8006435.patch \
-	security/20130416/8006790.patch \
-	security/20130416/8006795.patch \
-	security/20130416/8007406.patch \
-	security/20130416/8007617.patch \
-	security/20130416/8007667.patch \
-	security/20130416/8007918.patch \
-	security/20130416/8009305.patch \
-	security/20130416/8009699.patch \
-	security/20130416/8009814.patch \
-	security/20130416/8009857.patch \
-	openjdk/7195301-no_instanceof_node.patch \
-	openjdk/6469266-xmlsec_1.4.2.patch \
-	security/20130618/6741606-apache_santuario.patch \
-	security/20130618/7170730-windows_network_stack.patch \
-	security/20130618/8000638-improve_deserialization.patch \
-	security/20130618/8001032-restrict_object_access-corba.patch \
-	security/20130618/8001033-refactor_address_handling.patch \
-	security/20130618/8001034-memory_management.patch \
-	security/20130618/8001038-resourcefully_handle_resources.patch \
-	security/20130618/8001043-clarify_definition_restrictions.patch \
-	security/20130618/8001309-better_handling_of_annotation_interfaces.patch \
-	security/20130618/8001318-socket_getlocaladdress_consistency.patch \
-	security/20130618/8001318-6_fixup.patch \
-	security/20130618/8001330-improve_checking_order.patch \
-	security/20130618/8003703-update_rmi_connection_dialog.patch \
-	openjdk/8005615-failure_to_load_logger_implementation.patch \
-	openjdk/8007393.patch \
-	openjdk/8007611.patch \
-	security/20130618/8004584-augment_applet_contextualization.patch \
-	security/20130618/8005007-better_glyph_processing.patch \
-	security/20130618/8006328-sound_class_robustness.patch \
-	security/20130618/8006328-6_fixup.patch \
-	security/20130618/8006611-improve_scripting.patch \
-	security/20130618/8007467-improve_jmx_internal_api_robustness.patch \
-	security/20130618/8007471-improve_mbean_notifications.patch \
-	security/20130618/8007471-6_fixup.patch \
-	security/20130618/8007812-getenclosingmethod.patch \
-	security/20130618/8008120-improve_jmx_class_checking.patch \
-	security/20130618/8008124-better_compliance_testing.patch \
-	security/20130618/8008128-better_jmx_api_coherence.patch \
-	security/20130618/8008132-better_serialization.patch \
-	security/20130618/8008585-jmx_data_handling.patch \
-	security/20130618/8008593-better_urlclassloader.patch \
-	security/20130618/8008603-jmx_provider_provision.patch \
-	security/20130618/8008611-jmx_annotations.patch \
-	security/20130618/8008611-6_fixup.patch \
-	security/20130618/8008615-jmx_internal_api_robustness.patch \
-	security/20130618/8008623-mbeanserver_handling.patch \
-	security/20130618/8008744-6741606_rework.patch \
-	security/20130618/8008982-jmx_interface_changes.patch \
-	security/20130618/8009004-rmi_connection_improvement.patch \
-	security/20130618/8009013-t2k_glyphs.patch \
-	security/20130618/8009034-jmx_notification_improvement.patch \
-	security/20130618/8009038-jmx_notification_support_improvement.patch \
-	security/20130618/8009067-improve_key_storing.patch \
-	security/20130618/8009235-improve_tsa_data_handling.patch \
-	openjdk/6888167-medialib_memory_leaks.patch \
-	security/20130618/8011243-improve_imaginglib.patch \
-	security/20130618/8011248-better_component_rasters.patch \
-	security/20130618/8011253-better_short_component_rasters.patch \
-	security/20130618/8011257-better_byte_component_rasters.patch \
-	security/20130618/8011557-improve_reflection.patch \
-	security/20130618/8012421-better_positioning.patch \
-	security/20130618/8012438-better_image_validation.patch \
-	security/20130618/8012597-better_image_channel_validation.patch \
-	security/20130618/8012601-better_layout_validation.patch \
-	security/20130618/8014281-better_xml_signature_checking.patch \
-	security/20130618/diamond_fix.patch \
-	security/20130618/handle_npe.patch \
-	security/20130618/javac_issue.patch \
-	security/20130618/7158805-nested_subroutine_rewriting.patch \
-	security/20130618/8001330-checking_order_improvement.patch \
-	security/20130618/8000642-better_transportation_handling.patch \
-	openjdk/6786028-wcag_bold_tags.patch \
-	openjdk/6786682-wcag_lang.patch \
-	openjdk/6802694-no_deprecated.patch \
-	openjdk/6786690-wcag_dl.patch \
-	openjdk/6786688-wcag_table.patch \
-	openjdk/6961178-doclet_xml.patch \
-	openjdk/6851834-restructure.patch \
-	openjdk/6851834-handle_renames.patch \
-	openjdk/7006270-regressions.patch \
-	security/20130618/8012375-javadoc_framing.patch \
-	security/20130618/8015997-more_javadoc_framing.patch \
-	security/20130618/langtools_merge-01.patch \
-	security/20130618/langtools_merge-02.patch \
-	security/20130618/langtools_generics.patch \
-	security/20130618/langtools_merge-03.patch \
-	security/20130618/8009071-improve_shape_handling.patch
+_PATCHES=
 
 .if ${PORT_OPTIONS:MICEDTEA}
 _PATCHES+= \
 	applet_hole.patch \
-	openjdk/7032388-work_without_cmov_instruction.patch \
-	openjdk/8004341-jck_dialog_failure.patch \
-	openjdk/8004341-jck_dialog_failure-02.patch \
-	openjdk/7197906-handle_32_bit_shifts.patch \
 	jpegclasses.patch
 .endif
 

Modified: trunk/java/openjdk6/distinfo
===================================================================
--- trunk/java/openjdk6/distinfo	2015-09-13 00:45:55 UTC (rev 20224)
+++ trunk/java/openjdk6/distinfo	2015-09-13 00:58:25 UTC (rev 20225)
@@ -1,14 +1,6 @@
-SHA256 (openjdk-6-src-b27-26_oct_2012.tar.gz) = 044c3877b15940ff04f8aa817337f2878a00cc89674854557f1a02f15b1802a0
-SIZE (openjdk-6-src-b27-26_oct_2012.tar.gz) = 45789350
-SHA256 (jaxp144_05.zip) = c1a8a5a219fa55ecbf2ad43b66514335a3e96ccad40bd2ec9165a821343b2bff
-SIZE (jaxp144_05.zip) = 5976387
-SHA256 (jdk6-jaxws2_1_6-2011_06_13.zip) = 229040544e791f44906e8e7b6f6faf503c730a5d854275135f3925490d5c3be3
-SIZE (jdk6-jaxws2_1_6-2011_06_13.zip) = 5512710
-SHA256 (jdk6-jaf-b20.zip) = 78c7b5c9d6271e88ee46abadd018a61f1e9645f8936cc8df1617e5f4f5074012
-SIZE (jdk6-jaf-b20.zip) = 71243
 SHA256 (apache-ant-1.9.4-bin.tar.bz2) = 20c16575684b8869dd9d19abe0fb504566adefb5d397881e70a417886e0088cf
 SIZE (apache-ant-1.9.4-bin.tar.bz2) = 4351965
-SHA256 (jdk6-jaf-b20.zip) = 78c7b5c9d6271e88ee46abadd018a61f1e9645f8936cc8df1617e5f4f5074012
-SIZE (jdk6-jaf-b20.zip) = 71243
-SHA256 (jtreg-4.1-bin-b04_14_mar_2012.zip) = 6d63447f3b70828b4d5f9e5c2416ba08ca00d54714a9d219837eae989df676c5
-SIZE (jtreg-4.1-bin-b04_14_mar_2012.zip) = 6126941
+SHA256 (openjdk-6-src-b36-22_jul_2015.tar.xz) = c9df23d208b3b61f5f57c030accca2f7b3218a97bd140668506265ececdf26f4
+SIZE (openjdk-6-src-b36-22_jul_2015.tar.xz) = 33757312
+SHA256 (jtreg-4.1-bin-b05_29_nov_2012.zip) = 9291eb4a14501232b35614e88686ff66ad8b69d0098dbd4322b28f97b672653d
+SIZE (jtreg-4.1-bin-b05_29_nov_2012.zip) = 5993382

Modified: trunk/java/openjdk6/files/patch-set
===================================================================
--- trunk/java/openjdk6/files/patch-set	2015-09-13 00:45:55 UTC (rev 20224)
+++ trunk/java/openjdk6/files/patch-set	2015-09-13 00:58:25 UTC (rev 20225)
@@ -10,8 +10,8 @@
 +    OTHER_LDLIBS += -liconv
 +  else
 +    ifneq ($(OS_NAME), netbsd)
-+      CPPFLAGS += -I$(PACKAGE_PATH)/include
-+      OTHER_LDLIBS += -L$(PACKAGE_PATH)/lib -liconv
++      CPPFLAGS += %%ICONV_CPPFLAGS%%
++      OTHER_LDLIBS += %%ICONV_LDFLAGS%%
 +    endif
 +  endif
 +endif
@@ -116,7 +116,7 @@
  endif
  
  #
-@@ -278,7 +255,9 @@
+@@ -278,24 +255,22 @@
  override HAVE_FILIOH             = false
  override HAVE_GETHRTIME          = false
  override HAVE_GETHRVTIME         = false
@@ -126,7 +126,11 @@
  override LEX_LIBRARY             = -lfl
  ifeq ($(STATIC_CXX),true)
  override LIBCXX                  = -Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic
-@@ -289,13 +268,9 @@
+ else
+-override LIBCXX                  = -lstdc++
++override LIBCXX                  = %%CXX_LDFLAGS%%
+ endif
+ override LIBPOSIX4               =
  override LIBSOCKET               =
  override LIBTHREAD               =
  override MOOT_PRIORITIES         = true
@@ -142,17 +146,6 @@
  override OTHER_M4FLAGS           = -D__GLIBC__ -DGNU_ASSEMBLER
  override SUN_CMM_SUBDIR          =
  override THREADS_FLAG            = native
---- corba/make/common/Defs-linux.gmk
-+++ corba/make/common/Defs-linux.gmk
-@@ -290,7 +290,7 @@
- override LIBTHREAD               =
- override MOOT_PRIORITIES         = true
- override NO_INTERRUPTIBLE_IO     = true
--override OPENWIN_HOME            = /usr/X11R6
-+override OPENWIN_HOME            = $(X11_PATH)
- ifeq ($(ARCH), amd64)
- override OPENWIN_LIB             = $(OPENWIN_HOME)/lib64
- else
 --- corba/make/common/Defs.gmk
 +++ corba/make/common/Defs.gmk
 @@ -53,6 +53,24 @@
@@ -262,17 +255,6 @@
  endif
  
  # _BOOTDIR1: First choice for a Bootstrap JDK, previous released JDK.
---- corba/make/common/shared/Defs-java.gmk
-+++ corba/make/common/shared/Defs-java.gmk
-@@ -38,7 +38,7 @@
-   #   Suspect this may not be needed anymore.
-   JAVA_MEM_FLAGS   += -Xms$(MAX_VM_MEMORY)m -XX:-Inline
- else
--  JAVA_MEM_FLAGS   += -Xms$(MIN_VM_MEMORY)m -XX:PermSize=32m -XX:MaxPermSize=160m
-+  JAVA_MEM_FLAGS   += -Xms$(MIN_VM_MEMORY)m
- endif
- 
- # 
 --- corba/make/common/shared/Defs-utils.gmk
 +++ corba/make/common/shared/Defs-utils.gmk
 @@ -53,6 +53,13 @@
@@ -426,383 +408,20 @@
      fi)
    MIN_VM_MEMORY := $(shell \
      if [ $(MAX_VM_MEMORY) -le 128 ] ; then \
---- hotspot/agent/make/Makefile
-+++ hotspot/agent/make/Makefile
-@@ -52,6 +52,9 @@
- sun.jvm.hotspot.compiler \
- sun.jvm.hotspot.debugger \
- sun.jvm.hotspot.debugger.amd64 \
-+sun.jvm.hotspot.debugger.bsd \
-+sun.jvm.hotspot.debugger.bsd.amd64 \
-+sun.jvm.hotspot.debugger.bsd.x86 \
- sun.jvm.hotspot.debugger.cdbg \
- sun.jvm.hotspot.debugger.cdbg.basic \
- sun.jvm.hotspot.debugger.cdbg.basic.amd64 \
-@@ -94,6 +97,9 @@
- sun.jvm.hotspot.oops \
- sun.jvm.hotspot.runtime \
- sun.jvm.hotspot.runtime.amd64 \
-+sun.jvm.hotspot.runtime.bsd \
-+sun.jvm.hotspot.runtime.bsd_amd64 \
-+sun.jvm.hotspot.runtime.bsd_x86 \
- sun.jvm.hotspot.runtime.ia64 \
- sun.jvm.hotspot.runtime.linux \
- sun.jvm.hotspot.runtime.linux_amd64 \
-@@ -143,6 +149,9 @@
- sun/jvm/hotspot/compiler/*.java \
- sun/jvm/hotspot/debugger/*.java \
- sun/jvm/hotspot/debugger/amd64/*.java \
-+sun/jvm/hotspot/debugger/bsd/*.java \
-+sun/jvm/hotspot/debugger/bsd/amd64/*.java \
-+sun/jvm/hotspot/debugger/bsd/x86/*.java \
- sun/jvm/hotspot/debugger/cdbg/*.java \
- sun/jvm/hotspot/debugger/cdbg/basic/*.java \
- sun/jvm/hotspot/debugger/cdbg/basic/amd64/*.java \
-@@ -178,6 +187,9 @@
- sun/jvm/hotspot/oops/*.java \
- sun/jvm/hotspot/runtime/*.java \
- sun/jvm/hotspot/runtime/amd64/*.java \
-+sun/jvm/hotspot/runtime/bsd/*.java \
-+sun/jvm/hotspot/runtime/bsd_amd64/*.java \
-+sun/jvm/hotspot/runtime/bsd_x86/*.java \
- sun/jvm/hotspot/runtime/ia64/*.java \
- sun/jvm/hotspot/runtime/linux/*.java \
- sun/jvm/hotspot/runtime/linux_amd64/*.java \
---- hotspot/agent/src/os/bsd/BsdDebuggerLocal.c
-+++ hotspot/agent/src/os/bsd/BsdDebuggerLocal.c
-@@ -22,6 +22,7 @@
-  *
-  */
- 
-+#include <stdlib.h>
- #include <jni.h>
- #include "libproc.h"
- 
-@@ -73,7 +74,7 @@
-   (JNIEnv *env, jclass cls) {
-   jclass listClass;
- 
--  if (init_libproc(getenv("LIBSAPROC_DEBUG")) != true) {
-+  if (init_libproc(getenv("LIBSAPROC_DEBUG") != NULL) != true) {
-      THROW_NEW_DEBUGGER_EXCEPTION("can't initialize libproc");
-   }
- 
-@@ -275,7 +276,7 @@
-   bufPtr = (*env)->GetByteArrayElements(env, array, &isCopy);
-   CHECK_EXCEPTION_(0);
- 
--  err = ps_pdread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
-+  err = ps_pread(get_proc_handle(env, this_obj), (psaddr_t) (uintptr_t)addr, bufPtr, numBytes);
-   (*env)->ReleaseByteArrayElements(env, array, bufPtr, 0);
-   return (err == PS_OK)? array : 0;
- }
-@@ -283,11 +284,10 @@
- JNIEXPORT jlongArray JNICALL Java_sun_jvm_hotspot_debugger_bsd_BsdDebuggerLocal_getThreadIntegerRegisterSet0
-   (JNIEnv *env, jobject this_obj, jint lwp_id) {
- 
--  struct user_regs_struct gregs;
-+  struct reg gregs;
-   jboolean isCopy;
-   jlongArray array;
-   jlong *regs;
--  int i;
- 
-   struct ps_prochandle* ph = get_proc_handle(env, this_obj);
-   if (get_lwp_regs(ph, lwp_id, &gregs) != true) {
-@@ -317,26 +317,27 @@
- #ifdef i386
- #define REG_INDEX(reg) sun_jvm_hotspot_debugger_x86_X86ThreadContext_##reg
- 
--  regs[REG_INDEX(GS)]  = (uintptr_t) gregs.xgs;
--  regs[REG_INDEX(FS)]  = (uintptr_t) gregs.xfs;
--  regs[REG_INDEX(ES)]  = (uintptr_t) gregs.xes;
--  regs[REG_INDEX(DS)]  = (uintptr_t) gregs.xds;
--  regs[REG_INDEX(EDI)] = (uintptr_t) gregs.edi;
--  regs[REG_INDEX(ESI)] = (uintptr_t) gregs.esi;
--  regs[REG_INDEX(FP)] = (uintptr_t) gregs.ebp;
--  regs[REG_INDEX(SP)] = (uintptr_t) gregs.esp;
--  regs[REG_INDEX(EBX)] = (uintptr_t) gregs.ebx;
--  regs[REG_INDEX(EDX)] = (uintptr_t) gregs.edx;
--  regs[REG_INDEX(ECX)] = (uintptr_t) gregs.ecx;
--  regs[REG_INDEX(EAX)] = (uintptr_t) gregs.eax;
--  regs[REG_INDEX(PC)] = (uintptr_t) gregs.eip;
--  regs[REG_INDEX(CS)]  = (uintptr_t) gregs.xcs;
--  regs[REG_INDEX(SS)]  = (uintptr_t) gregs.xss;
-+  regs[REG_INDEX(GS)]  = (uintptr_t) gregs.r_gs;
-+  regs[REG_INDEX(FS)]  = (uintptr_t) gregs.r_fs;
-+  regs[REG_INDEX(ES)]  = (uintptr_t) gregs.r_es;
-+  regs[REG_INDEX(DS)]  = (uintptr_t) gregs.r_ds;
-+  regs[REG_INDEX(EDI)] = (uintptr_t) gregs.r_edi;
-+  regs[REG_INDEX(ESI)] = (uintptr_t) gregs.r_esi;
-+  regs[REG_INDEX(FP)] = (uintptr_t) gregs.r_ebp;
-+  regs[REG_INDEX(SP)] = (uintptr_t) gregs.r_isp;
-+  regs[REG_INDEX(EBX)] = (uintptr_t) gregs.r_ebx;
-+  regs[REG_INDEX(EDX)] = (uintptr_t) gregs.r_edx;
-+  regs[REG_INDEX(ECX)] = (uintptr_t) gregs.r_ecx;
-+  regs[REG_INDEX(EAX)] = (uintptr_t) gregs.r_eax;
-+  regs[REG_INDEX(PC)] = (uintptr_t) gregs.r_eip;
-+  regs[REG_INDEX(CS)]  = (uintptr_t) gregs.r_cs;
-+  regs[REG_INDEX(SS)]  = (uintptr_t) gregs.r_ss;
- 
- #endif /* i386 */
- 
- #if ia64
-   regs = (*env)->GetLongArrayElements(env, array, &isCopy);
-+  int i;
-   for (i = 0; i < NPRGREG; i++ ) {
-     regs[i] = 0xDEADDEAD;
-   }
-@@ -345,31 +346,31 @@
- #ifdef amd64
- #define REG_INDEX(reg) sun_jvm_hotspot_debugger_amd64_AMD64ThreadContext_##reg
- 
--  regs[REG_INDEX(R15)] = gregs.r15;
--  regs[REG_INDEX(R14)] = gregs.r14;
--  regs[REG_INDEX(R13)] = gregs.r13;
--  regs[REG_INDEX(R12)] = gregs.r12;
--  regs[REG_INDEX(RBP)] = gregs.rbp;
--  regs[REG_INDEX(RBX)] = gregs.rbx;
--  regs[REG_INDEX(R11)] = gregs.r11;
--  regs[REG_INDEX(R10)] = gregs.r10;
--  regs[REG_INDEX(R9)] = gregs.r9;
--  regs[REG_INDEX(R8)] = gregs.r8;
--  regs[REG_INDEX(RAX)] = gregs.rax;
--  regs[REG_INDEX(RCX)] = gregs.rcx;
--  regs[REG_INDEX(RDX)] = gregs.rdx;
--  regs[REG_INDEX(RSI)] = gregs.rsi;
--  regs[REG_INDEX(RDI)] = gregs.rdi;
--  regs[REG_INDEX(RIP)] = gregs.rip;
--  regs[REG_INDEX(CS)] = gregs.cs;
--  regs[REG_INDEX(RSP)] = gregs.rsp;
--  regs[REG_INDEX(SS)] = gregs.ss;
--  regs[REG_INDEX(FSBASE)] = gregs.fs_base;
--  regs[REG_INDEX(GSBASE)] = gregs.gs_base;
--  regs[REG_INDEX(DS)] = gregs.ds;
--  regs[REG_INDEX(ES)] = gregs.es;
--  regs[REG_INDEX(FS)] = gregs.fs;
--  regs[REG_INDEX(GS)] = gregs.gs;
-+  regs[REG_INDEX(R15)] = gregs.r_r15;
-+  regs[REG_INDEX(R14)] = gregs.r_r14;
-+  regs[REG_INDEX(R13)] = gregs.r_r13;
-+  regs[REG_INDEX(R12)] = gregs.r_r12;
-+  regs[REG_INDEX(RBP)] = gregs.r_rbp;
-+  regs[REG_INDEX(RBX)] = gregs.r_rbx;
-+  regs[REG_INDEX(R11)] = gregs.r_r11;
-+  regs[REG_INDEX(R10)] = gregs.r_r10;
-+  regs[REG_INDEX(R9)] = gregs.r_r9;
-+  regs[REG_INDEX(R8)] = gregs.r_r8;
-+  regs[REG_INDEX(RAX)] = gregs.r_rax;
-+  regs[REG_INDEX(RCX)] = gregs.r_rcx;
-+  regs[REG_INDEX(RDX)] = gregs.r_rdx;
-+  regs[REG_INDEX(RSI)] = gregs.r_rsi;
-+  regs[REG_INDEX(RDI)] = gregs.r_rdi;
-+  regs[REG_INDEX(RIP)] = gregs.r_rip;
-+  regs[REG_INDEX(CS)] = gregs.r_cs;
-+  regs[REG_INDEX(RSP)] = gregs.r_rsp;
-+  regs[REG_INDEX(SS)] = gregs.r_ss;
-+//  regs[REG_INDEX(FSBASE)] = gregs.fs_base;
-+//  regs[REG_INDEX(GSBASE)] = gregs.gs_base;
-+//  regs[REG_INDEX(DS)] = gregs.ds;
-+//  regs[REG_INDEX(ES)] = gregs.es;
-+//  regs[REG_INDEX(FS)] = gregs.fs;
-+//  regs[REG_INDEX(GS)] = gregs.gs;
- 
- #endif /* amd64 */
- 
 --- hotspot/agent/src/os/bsd/Makefile
 +++ hotspot/agent/src/os/bsd/Makefile
-@@ -22,8 +22,8 @@
- #  
+@@ -23,7 +23,7 @@
  #
  
--ARCH := $(shell if ([ `uname -m` = "ia64" ])  ; then echo ia64 ; elif ([ `uname -m` = "x86_64" ]) ; then echo amd64; elif ([ `uname -m` = "sparc64" ]) ; then echo sparc; else echo i386 ; fi )
+ ARCH := $(shell if ([ `uname -m` = "ia64" ])  ; then echo ia64 ; elif ([ `uname -m` = "amd64" ]) ; then echo amd64; elif ([ `uname -m` = "sparc64" ]) ; then echo sparc; else echo i386 ; fi )
 -GCC      = gcc
-+ARCH := $(shell if ([ `uname -m` = "ia64" ])  ; then echo ia64 ; elif ([ `uname -m` = "amd64" ]) ; then echo amd64; elif ([ `uname -m` = "sparc64" ]) ; then echo sparc; else echo i386 ; fi )
 +GCC      ?= gcc
  
  JAVAH    = ${JAVA_HOME}/bin/javah
  
-@@ -32,25 +32,24 @@
- 	libproc_impl.c  \
- 	ps_proc.c       \
- 	ps_core.c       \
--	BsdDebuggerLocal.c 
-+	BsdDebuggerLocal.c
- 
--INCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/bsd 
-+INCLUDES = -I${JAVA_HOME}/include -I${JAVA_HOME}/include/$(shell uname -s | tr "[:upper:]" "[:lower:]")
- 
- OBJS     = $(SOURCES:.c=.o)
- 
--LIBS     = -lthread_db
-+LIBS     = -lutil -lthread_db
- 
--CFLAGS   = -c -fPIC -g -D_GNU_SOURCE -D$(ARCH) $(INCLUDES)
-+CFLAGS   = -c -fPIC -g -Wall -D_ALLBSD_SOURCE -D_GNU_SOURCE -D$(ARCH) $(INCLUDES)
- 
- LIBSA = $(ARCH)/libsaproc.so
- 
- all: $(LIBSA)
- 
- BsdDebuggerLocal.o: BsdDebuggerLocal.c
--	$(JAVAH) -jni -classpath ../../../build/classes  \
-+	$(JAVAH) -jni -classpath ../../../../../build/bsd-i586/hotspot/outputdir/bsd_i486_compiler2/generated/saclasses  \
- 		sun.jvm.hotspot.debugger.x86.X86ThreadContext \
--		sun.jvm.hotspot.debugger.sparc.SPARCThreadContext \
--		sun.jvm.hotspot.debugger.amd64.AMD64ThreadContext 
-+		sun.jvm.hotspot.debugger.amd64.AMD64ThreadContext
- 	$(GCC) $(CFLAGS) $<
- 
- .c.obj:
-@@ -60,26 +59,19 @@
-   LFLAGS_LIBSA = -Xlinker --version-script=mapfile
- endif
- 
--# If this is a --hash-style=gnu system, use --hash-style=both
--#   The gnu .hash section won't work on some Bsd systems like SuSE 10.
--_HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu')
--ifneq ($(_HAS_HASH_STYLE_GNU),)
--  LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
--endif
--LFLAGS_LIBSA += $(LDFLAGS_HASH_STYLE)
--
- $(LIBSA): $(OBJS) mapfile
- 	if [ ! -d $(ARCH) ] ; then mkdir $(ARCH) ; fi
- 	$(GCC) -shared $(LFLAGS_LIBSA) -o $(LIBSA) $(OBJS) $(LIBS)
- 
--test.o: test.c
-+test.o: $(LIBSA) test.c
- 	$(GCC) -c -o test.o -g -D_GNU_SOURCE -D$(ARCH) $(INCLUDES) test.c
- 
- test: test.o
- 	$(GCC) -o test test.o -L$(ARCH) -lsaproc $(LIBS)
- 
- clean:
--	rm -rf $(LIBSA)
--	rm -rf $(OBJS)
--	rmdir $(ARCH)
-+	rm -f $(LIBSA)
-+	rm -f $(OBJS)
-+	rm -f test.o
-+	-rmdir $(ARCH)
- 
---- hotspot/agent/src/os/bsd/elfmacros.h
-+++ hotspot/agent/src/os/bsd/elfmacros.h
-@@ -25,16 +25,19 @@
- #ifndef _ELFMACROS_H_
- #define _ELFMACROS_H_
- 
-+#define ELF_NHDR        Elf_Note
-+
- #if defined(_LP64)
- #define ELF_EHDR        Elf64_Ehdr
- #define ELF_SHDR        Elf64_Shdr
- #define ELF_PHDR        Elf64_Phdr
- #define ELF_SYM         Elf64_Sym
--#define ELF_NHDR        Elf64_Nhdr
- #define ELF_DYN         Elf64_Dyn
- #define ELF_ADDR        Elf64_Addr
- 
-+#ifndef ELF_ST_TYPE
- #define ELF_ST_TYPE     ELF64_ST_TYPE
-+#endif
- 
- #else
- 
-@@ -42,11 +45,12 @@
- #define ELF_SHDR        Elf32_Shdr
- #define ELF_PHDR        Elf32_Phdr
- #define ELF_SYM         Elf32_Sym
--#define ELF_NHDR        Elf32_Nhdr
- #define ELF_DYN         Elf32_Dyn
- #define ELF_ADDR        Elf32_Addr
- 
-+#ifndef ELF_ST_TYPE
- #define ELF_ST_TYPE     ELF32_ST_TYPE
-+#endif
- 
- #endif
- 
---- hotspot/agent/src/os/bsd/libproc.h
-+++ hotspot/agent/src/os/bsd/libproc.h
-@@ -27,7 +27,8 @@
- 
- #include <unistd.h>
- #include <stdint.h>
--#include "proc_service.h"
-+#include <machine/reg.h>
-+#include <proc_service.h>
- 
- #if defined(sparc) || defined(sparcv9)
- /*
-@@ -50,14 +51,11 @@
- adds Pgrab__ and some missing stuff. We hide the difference b/w live process and core
- file by this interface.
- 
--1. pthread_id unique in both NPTL & BsdThreads. We store this in
--OSThread::_pthread_id in JVM code.
-+1. pthread_id is unique. We store this in OSThread::_pthread_id in JVM code.
- 
--2. All threads see the same pid when they call getpid() under NPTL.
--Threads receive different pid under BsdThreads. We used to save the result of
--::getpid() call in OSThread::_thread_id. This way uniqueness of OSThread::_thread_id
--was lost under NPTL. Now, we store the result of ::gettid() call in
--OSThread::_thread_id. Because gettid returns actual pid of thread (lwp id), this is
-+2. All threads see the same pid when they call getpid().
-+We used to save the result of ::getpid() call in OSThread::_thread_id.
-+Because gettid returns actual pid of thread (lwp id), this is
- unique again. We therefore use OSThread::_thread_id as unique identifier.
- 
- 3. There is a unique LWP id under both thread libraries. libthread_db  maps pthread_id
-@@ -74,20 +72,7 @@
- 
- *************************************************************************************/
- 
--#ifdef ia64
--struct user_regs_struct {
--/* copied from user.h which doesn't define this in a struct */
--
--#define IA64_REG_COUNT (EF_SIZE/8+32)   /* integer and fp regs */
--unsigned long   regs[IA64_REG_COUNT];     /* integer and fp regs */
--};
--#endif
--
--#if defined(sparc)  || defined(sparcv9)
--#define user_regs_struct  pt_regs
--#endif
--
--// This C bool type must be int for compatibility with Bsd calls and
-+// This C bool type must be int for compatibility with BSD calls and
- // it would be a mistake to equivalence it to C++ bool on many platforms
- 
- typedef int bool;
-@@ -118,7 +103,7 @@
- lwpid_t get_lwp_id(struct ps_prochandle* ph, int index);
- 
- // get regs for a given lwp
--bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct user_regs_struct* regs);
-+bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lid, struct reg* regs);
- 
- // get number of shared objects
- int get_num_libs(struct ps_prochandle* ph);
 --- hotspot/agent/src/os/bsd/libproc_impl.c
 +++ hotspot/agent/src/os/bsd/libproc_impl.c
-@@ -174,10 +174,13 @@
-       return NULL;
-    }
- 
--   newlib->symtab = build_symtab(newlib->fd, libname);
-+   newlib->symtab = build_symtab(newlib->fd);
-    if (newlib->symtab == NULL) {
-       print_debug("symbol table build failed for %s\n", newlib->name);
-    }
-+   else {
-+      print_debug("built symbol table for %s\n", newlib->name);
-+   }
- 
-    // even if symbol table building fails, we add the lib_info.
-    // This is because we may need to read from the ELF file for core file
-@@ -232,6 +235,24 @@
+@@ -235,6 +235,24 @@
  }
  
  // add a thread to ps_prochandle
@@ -827,7 +446,7 @@
  thread_info* add_thread_info(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
     thread_info* newthr;
     if ( (newthr = (thread_info*) calloc(1, sizeof(thread_info))) == NULL) {
-@@ -249,6 +270,7 @@
+@@ -252,6 +270,7 @@
     ph->num_threads++;
     return newthr;
  }
@@ -835,7 +454,7 @@
  
  
  // struct used for client data from thread_db callback
-@@ -270,10 +292,17 @@
+@@ -273,10 +292,17 @@
      return err;
    }
  
@@ -847,120 +466,15 @@
 +#else
    print_debug("thread_db : pthread %d (lwp %d)\n", ti.ti_tid, ti.ti_lid);
  
--  if (ptr->callback(ptr->ph, ti.ti_tid, ti.ti_lid) != true)
-+  if (ptr->callback(ptr->ph, (pthread_t)ti.ti_tid, ti.ti_lid) != true)
+   if (ptr->callback(ptr->ph, (pthread_t)ti.ti_tid, ti.ti_lid) != true)
      return TD_ERR;
 +#endif
  
    return TD_OK;
  }
-@@ -324,7 +353,7 @@
- }
- 
- // get regs for a given lwp
--bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs) {
-+bool get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs) {
-   return ph->ops->get_lwp_regs(ph, lwp_id, regs);
- }
- 
-@@ -375,11 +404,6 @@
- //--------------------------------------------------------------------------
- // proc service functions
- 
--// get process id
--pid_t ps_getpid(struct ps_prochandle *ph) {
--   return ph->pid;
--}
--
- // ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
- // of the load object object_name in the target process identified by ph.
- // It returns the symbol's value as an address in the target process in
-@@ -392,17 +416,33 @@
- }
- 
- // read "size" bytes info "buf" from address "addr"
--ps_err_e ps_pdread(struct ps_prochandle *ph, psaddr_t  addr,
--                   void *buf, size_t size) {
-+ps_err_e ps_pread(struct ps_prochandle *ph, psaddr_t  addr,
-+                  void *buf, size_t size) {
-   return ph->ops->p_pread(ph, (uintptr_t) addr, buf, size)? PS_OK: PS_ERR;
- }
- 
- // write "size" bytes of data to debuggee at address "addr"
--ps_err_e ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr,
--                    const void *buf, size_t size) {
-+ps_err_e ps_pwrite(struct ps_prochandle *ph, psaddr_t addr,
-+                   const void *buf, size_t size) {
-   return ph->ops->p_pwrite(ph, (uintptr_t)addr, buf, size)? PS_OK: PS_ERR;
- }
- 
-+// fill in ptrace_lwpinfo for lid
-+ps_err_e ps_linfo(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
-+  return ph->ops->get_lwp_info(ph, lwp_id, linfo)? PS_OK: PS_ERR;
-+}
-+
-+// needed for when libthread_db is compiled with TD_DEBUG defined
-+void
-+ps_plog (const char *format, ...)
-+{
-+  va_list alist;
-+
-+  va_start(alist, format);
-+  vfprintf(stderr, format, alist);
-+  va_end(alist);
-+}
-+
- // ------------------------------------------------------------------------
- // Functions below this point are not yet implemented. They are here only
- // to make the linker happy.
-@@ -427,8 +467,12 @@
-   return PS_OK;
- }
- 
--// new libthread_db of NPTL seem to require this symbol
--ps_err_e ps_get_thread_area() {
--  print_debug("ps_get_thread_area not implemented\n");
-+ps_err_e ps_lstop(struct ps_prochandle *ph, lwpid_t lid) {
-+  print_debug("ps_lstop not implemented\n");
-+  return PS_OK;
-+}
-+
-+ps_err_e ps_pcontinue(struct ps_prochandle *ph) {
-+  print_debug("ps_pcontinue not implemented\n");
-   return PS_OK;
- }
 --- hotspot/agent/src/os/bsd/libproc_impl.h
 +++ hotspot/agent/src/os/bsd/libproc_impl.h
-@@ -47,7 +47,7 @@
- typedef struct thread_info {
-    lwpid_t                  lwp_id;
-    pthread_t                pthread_id; // not used cores, always -1
--   struct user_regs_struct  regs;       // not for process, core uses for caching regset
-+   struct reg               regs;       // not for process, core uses for caching regset
-    struct thread_info*      next;
- } thread_info;
- 
-@@ -71,7 +71,9 @@
-    bool (*p_pwrite)(struct ps_prochandle *ph,
-             uintptr_t addr, const char *buf , size_t size);
-    // get integer regset of a thread
--   bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct user_regs_struct* regs);
-+   bool (*get_lwp_regs)(struct ps_prochandle* ph, lwpid_t lwp_id, struct reg* regs);
-+   // get info on thread
-+   bool (*get_lwp_info)(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo);
- } ps_prochandle_ops;
- 
- // the ps_prochandle
-@@ -79,7 +81,7 @@
- struct core_data {
-    int                core_fd;   // file descriptor of core file
-    int                exec_fd;   // file descriptor of exec file
--   int                interp_fd; // file descriptor of interpreter (ld-bsd.so.2)
-+   int                interp_fd; // file descriptor of interpreter (ld-elf.so.1)
-    // part of the class sharing workaround
-    int                classes_jsa_fd; // file descriptor of class share archive
-    uintptr_t          dynamic_addr;  // address of dynamic section of a.out
-@@ -107,7 +109,11 @@
+@@ -109,7 +109,11 @@
  void print_debug(const char* format,...);
  bool is_debug();
  
@@ -972,7 +486,7 @@
  
  // reads thread info using libthread_db and calls above callback for each thread
  bool read_thread_info(struct ps_prochandle* ph, thread_info_callback cb);
-@@ -120,7 +126,11 @@
+@@ -122,7 +126,11 @@
                            uintptr_t base);
  
  // adds a new thread to threads list, returns NULL on failure
@@ -984,212 +498,9 @@
  
  // a test for ELF signature without using libelf
  bool is_elf_file(int fd);
---- hotspot/agent/src/os/bsd/mapfile
-+++ hotspot/agent/src/os/bsd/mapfile
-@@ -43,13 +43,17 @@
- 		# proc_service.h functions - to be used by libthread_db
- 		ps_getpid;
- 		ps_pglobal_lookup;
--		ps_pdread;
--		ps_pdwrite;
-+		ps_pread;
-+		ps_pwrite;
- 		ps_lsetfpregs;
- 		ps_lsetregs;
- 		ps_lgetfpregs;
- 		ps_lgetregs;
--		ps_get_thread_area;
-+		ps_lcontinue;
-+		ps_lgetxmmregs;
-+		ps_lsetxmmregs;
-+		ps_lstop;
-+		ps_linfo;
- 
-                 # used by attach test program
-                 init_libproc;
---- hotspot/agent/src/os/bsd/proc_service.h
-+++ hotspot/agent/src/os/bsd/proc_service.h	1969-12-31 19:00:00.000000000 -0500
-@@ -1,76 +0,0 @@
--/*
-- * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
-- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
-- *
-- * This code is free software; you can redistribute it and/or modify it
-- * under the terms of the GNU General Public License version 2 only, as
-- * published by the Free Software Foundation.
-- *
-- * This code is distributed in the hope that it will be useful, but WITHOUT
-- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
-- * version 2 for more details (a copy is included in the LICENSE file that
-- * accompanied this code).
-- *
-- * You should have received a copy of the GNU General Public License version
-- * 2 along with this work; if not, write to the Free Software Foundation,
-- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
-- *
-- * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
-- * or visit www.oracle.com if you need additional information or have any
-- * questions.
-- *
-- */
--
--#ifndef _PROC_SERVICE_H_
--#define _PROC_SERVICE_H_
--
--#include <stdio.h>
--#include <thread_db.h>
--
--// Bsd does not have the proc service library, though it does provide the
--// thread_db library which can be used to manipulate threads without having
--// to know the details of BsdThreads or NPTL
--
--// copied from Solaris "proc_service.h"
--typedef enum {
--        PS_OK,          /* generic "call succeeded" */
--        PS_ERR,         /* generic error */
--        PS_BADPID,      /* bad process handle */
--        PS_BADLID,      /* bad lwp identifier */
--        PS_BADADDR,     /* bad address */
--        PS_NOSYM,       /* p_lookup() could not find given symbol */
--        PS_NOFREGS      /* FPU register set not available for given lwp */
--} ps_err_e;
--
--// ps_getpid() is only defined on Bsd to return a thread's process ID
--pid_t ps_getpid(struct ps_prochandle *ph);
--
--// ps_pglobal_lookup() looks up the symbol sym_name in the symbol table
--// of the load object object_name in the target process identified by ph.
--// It returns the symbol's value as an address in the target process in
--// *sym_addr.
--
--ps_err_e ps_pglobal_lookup(struct ps_prochandle *ph, const char *object_name,
--                    const char *sym_name, psaddr_t *sym_addr);
--
--// read "size" bytes of data from debuggee at address "addr"
--ps_err_e ps_pdread(struct ps_prochandle *ph, psaddr_t  addr,
--                   void *buf, size_t size);
--
--// write "size" bytes of data to debuggee at address "addr"
--ps_err_e ps_pdwrite(struct ps_prochandle *ph, psaddr_t addr,
--                    const void *buf, size_t size);
--
--ps_err_e ps_lsetfpregs(struct ps_prochandle *ph, lwpid_t lid, const prfpregset_t *fpregs);
--
--ps_err_e ps_lsetregs(struct ps_prochandle *ph, lwpid_t lid, const prgregset_t gregset);
--
--ps_err_e  ps_lgetfpregs(struct  ps_prochandle  *ph,  lwpid_t lid, prfpregset_t *fpregs);
--
--ps_err_e ps_lgetregs(struct ps_prochandle *ph, lwpid_t lid, prgregset_t gregset);
--
--// new libthread_db of NPTL seem to require this symbol
--ps_err_e ps_get_thread_area();
--
--#endif /* _PROC_SERVICE_H_ */
 --- hotspot/agent/src/os/bsd/ps_core.c
 +++ hotspot/agent/src/os/bsd/ps_core.c
-@@ -142,6 +142,7 @@
- 
-    map->next = ph->core->class_share_maps;
-    ph->core->class_share_maps = map;
-+   return map;
- }
- 
- // Return the map_info for the given virtual address.  We keep a sorted
-@@ -228,8 +229,8 @@
- 
-     // 4991491 NOTICE These are C++ bool's in filemap.hpp and must match up with
-     // the C type matching the C++ bool type on any given platform. For
--    // Hotspot on Bsd we assume the corresponding C type is char but
--    // licensees on Bsd versions may need to adjust the type of these fields.
-+    // Hotspot on BSD we assume the corresponding C type is char but
-+    // licensees on BSD versions may need to adjust the type of these fields.
-     char   _read_only;       // read only space?
-     char   _allow_exec;      // executable code in space?
- 
-@@ -240,7 +241,7 @@
- 
- static bool read_jboolean(struct ps_prochandle* ph, uintptr_t addr, jboolean* pvalue) {
-    jboolean i;
--   if (ps_pdread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
-+   if (ps_pread(ph, (psaddr_t) addr, &i, sizeof(i)) == PS_OK) {
-       *pvalue = i;
-       return true;
-    } else {
-@@ -250,7 +251,7 @@
- 
- static bool read_pointer(struct ps_prochandle* ph, uintptr_t addr, uintptr_t* pvalue) {
-    uintptr_t uip;
--   if (ps_pdread(ph, (psaddr_t) addr, &uip, sizeof(uip)) == PS_OK) {
-+   if (ps_pread(ph, (psaddr_t) addr, &uip, sizeof(uip)) == PS_OK) {
-       *pvalue = uip;
-       return true;
-    } else {
-@@ -264,7 +265,7 @@
-    char  c = ' ';
- 
-    while (c != '\0') {
--     if (ps_pdread(ph, (psaddr_t) addr, &c, sizeof(char)) != PS_OK)
-+     if (ps_pread(ph, (psaddr_t) addr, &c, sizeof(char)) != PS_OK)
-          return false;
-       if (i < size - 1)
-          buf[i] = c;
-@@ -296,7 +297,6 @@
-          uintptr_t base = 0, useSharedSpacesAddr = 0;
-          uintptr_t sharedArchivePathAddrAddr = 0, sharedArchivePathAddr = 0;
-          jboolean useSharedSpaces = 0;
--         map_info* mi = 0;
- 
-          memset(classes_jsa, 0, sizeof(classes_jsa));
-          jvm_name = lib->name;
-@@ -306,9 +306,9 @@
-             return false;
-          }
- 
--         // Hotspot vm types are not exported to build this library. So
--         // using equivalent type jboolean to read the value of
--         // UseSharedSpaces which is same as hotspot type "bool".
-+	 // Hotspot vm types are not exported to build this library. So
-+	 // using equivalent type jboolean to read the value of
-+	 // UseSharedSpaces which is same as hotspot type "bool".
-          if (read_jboolean(ph, useSharedSpacesAddr, &useSharedSpaces) != true) {
-             print_debug("can't read the value of 'UseSharedSpaces' flag\n");
-             return false;
-@@ -507,12 +507,12 @@
- }
- 
- static bool core_get_lwp_regs(struct ps_prochandle* ph, lwpid_t lwp_id,
--                          struct user_regs_struct* regs) {
-+                          struct reg* regs) {
-    // for core we have cached the lwp regs from NOTE section
-    thread_info* thr = ph->threads;
-    while (thr) {
-      if (thr->lwp_id == lwp_id) {
--       memcpy(regs, &thr->regs, sizeof(struct user_regs_struct));
-+       memcpy(regs, &thr->regs, sizeof(struct reg));
-        return true;
-      }
-      thr = thr->next;
-@@ -520,11 +520,17 @@
-    return false;
- }
- 
-+static bool core_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
-+   print_debug("core_get_lwp_info not implemented\n");
-+   return false;
-+}
-+
- static ps_prochandle_ops core_ops = {
-    .release=  core_release,
-    .p_pread=  core_read_data,
-    .p_pwrite= core_write_data,
--   .get_lwp_regs= core_get_lwp_regs
-+   .get_lwp_regs= core_get_lwp_regs,
-+   .get_lwp_info= core_get_lwp_info
- };
- 
- // read regs and create thread from NT_PRSTATUS entries from core file
-@@ -534,57 +540,62 @@
+@@ -540,9 +540,14 @@
     prstatus_t* prstat = (prstatus_t*) buf;
     thread_info* newthr;
     print_debug("got integer regset for lwp %d\n", prstat->pr_pid);
@@ -1203,1557 +514,25 @@
 +#endif
  
     // copy regs
--   memcpy(&newthr->regs, prstat->pr_reg, sizeof(struct user_regs_struct));
-+   memcpy(&newthr->regs, &prstat->pr_reg, sizeof(struct reg));
- 
-    if (is_debug()) {
-       print_debug("integer regset\n");
- #ifdef i386
-       // print the regset
--      print_debug("\teax = 0x%x\n", newthr->regs.eax);
--      print_debug("\tebx = 0x%x\n", newthr->regs.ebx);
--      print_debug("\tecx = 0x%x\n", newthr->regs.ecx);
--      print_debug("\tedx = 0x%x\n", newthr->regs.edx);
--      print_debug("\tesp = 0x%x\n", newthr->regs.esp);
--      print_debug("\tebp = 0x%x\n", newthr->regs.ebp);
--      print_debug("\tesi = 0x%x\n", newthr->regs.esi);
--      print_debug("\tedi = 0x%x\n", newthr->regs.edi);
--      print_debug("\teip = 0x%x\n", newthr->regs.eip);
-+      print_debug("\teax = 0x%x\n", newthr->regs.r_eax);
-+      print_debug("\tebx = 0x%x\n", newthr->regs.r_ebx);
-+      print_debug("\tecx = 0x%x\n", newthr->regs.r_ecx);
-+      print_debug("\tedx = 0x%x\n", newthr->regs.r_edx);
-+      print_debug("\tesp = 0x%x\n", newthr->regs.r_esp);
-+      print_debug("\tebp = 0x%x\n", newthr->regs.r_ebp);
-+      print_debug("\tesi = 0x%x\n", newthr->regs.r_esi);
-+      print_debug("\tedi = 0x%x\n", newthr->regs.r_edi);
-+      print_debug("\teip = 0x%x\n", newthr->regs.r_eip);
- #endif
- 
- #if defined(amd64) || defined(x86_64)
-       // print the regset
--      print_debug("\tr15 = 0x%lx\n", newthr->regs.r15);
--      print_debug("\tr14 = 0x%lx\n", newthr->regs.r14);
--      print_debug("\tr13 = 0x%lx\n", newthr->regs.r13);
--      print_debug("\tr12 = 0x%lx\n", newthr->regs.r12);
--      print_debug("\trbp = 0x%lx\n", newthr->regs.rbp);
--      print_debug("\trbx = 0x%lx\n", newthr->regs.rbx);
--      print_debug("\tr11 = 0x%lx\n", newthr->regs.r11);
--      print_debug("\tr10 = 0x%lx\n", newthr->regs.r10);
--      print_debug("\tr9 = 0x%lx\n", newthr->regs.r9);
--      print_debug("\tr8 = 0x%lx\n", newthr->regs.r8);
--      print_debug("\trax = 0x%lx\n", newthr->regs.rax);
--      print_debug("\trcx = 0x%lx\n", newthr->regs.rcx);
--      print_debug("\trdx = 0x%lx\n", newthr->regs.rdx);
--      print_debug("\trsi = 0x%lx\n", newthr->regs.rsi);
--      print_debug("\trdi = 0x%lx\n", newthr->regs.rdi);
--      print_debug("\torig_rax = 0x%lx\n", newthr->regs.orig_rax);
--      print_debug("\trip = 0x%lx\n", newthr->regs.rip);
--      print_debug("\tcs = 0x%lx\n", newthr->regs.cs);
--      print_debug("\teflags = 0x%lx\n", newthr->regs.eflags);
--      print_debug("\trsp = 0x%lx\n", newthr->regs.rsp);
--      print_debug("\tss = 0x%lx\n", newthr->regs.ss);
--      print_debug("\tfs_base = 0x%lx\n", newthr->regs.fs_base);
--      print_debug("\tgs_base = 0x%lx\n", newthr->regs.gs_base);
--      print_debug("\tds = 0x%lx\n", newthr->regs.ds);
--      print_debug("\tes = 0x%lx\n", newthr->regs.es);
--      print_debug("\tfs = 0x%lx\n", newthr->regs.fs);
--      print_debug("\tgs = 0x%lx\n", newthr->regs.gs);
-+      print_debug("\tr15 = 0x%lx\n", newthr->regs.r_r15);
-+      print_debug("\tr14 = 0x%lx\n", newthr->regs.r_r14);
-+      print_debug("\tr13 = 0x%lx\n", newthr->regs.r_r13);
-+      print_debug("\tr12 = 0x%lx\n", newthr->regs.r_r12);
-+      print_debug("\trbp = 0x%lx\n", newthr->regs.r_rbp);
-+      print_debug("\trbx = 0x%lx\n", newthr->regs.r_rbx);
-+      print_debug("\tr11 = 0x%lx\n", newthr->regs.r_r11);
-+      print_debug("\tr10 = 0x%lx\n", newthr->regs.r_r10);
-+      print_debug("\tr9 = 0x%lx\n", newthr->regs.r_r9);
-+      print_debug("\tr8 = 0x%lx\n", newthr->regs.r_r8);
-+      print_debug("\trax = 0x%lx\n", newthr->regs.r_rax);
-+      print_debug("\trcx = 0x%lx\n", newthr->regs.r_rcx);
-+      print_debug("\trdx = 0x%lx\n", newthr->regs.r_rdx);
-+      print_debug("\trsi = 0x%lx\n", newthr->regs.r_rsi);
-+      print_debug("\trdi = 0x%lx\n", newthr->regs.r_rdi);
-+      //print_debug("\torig_rax = 0x%lx\n", newthr->regs.orig_rax);
-+      print_debug("\trip = 0x%lx\n", newthr->regs.r_rip);
-+      print_debug("\tcs = 0x%lx\n", newthr->regs.r_cs);
-+      //print_debug("\teflags = 0x%lx\n", newthr->regs.eflags);
-+      print_debug("\trsp = 0x%lx\n", newthr->regs.r_rsp);
-+      print_debug("\tss = 0x%lx\n", newthr->regs.r_ss);
-+      //print_debug("\tfs_base = 0x%lx\n", newthr->regs.fs_base);
-+      //print_debug("\tgs_base = 0x%lx\n", newthr->regs.gs_base);
-+      //print_debug("\tds = 0x%lx\n", newthr->regs.ds);
-+      //print_debug("\tes = 0x%lx\n", newthr->regs.es);
-+      //print_debug("\tfs = 0x%lx\n", newthr->regs.fs);
-+      //print_debug("\tgs = 0x%lx\n", newthr->regs.gs);
- #endif
-    }
- 
-@@ -656,7 +667,7 @@
-     * contains a set of saved /proc structures), and PT_LOAD (which
-     * represents a memory mapping from the process's address space).
-     *
--    * Difference b/w Solaris PT_NOTE and Bsd PT_NOTE:
-+    * Difference b/w Solaris PT_NOTE and BSD PT_NOTE:
-     *
-     *     In Solaris there are two PT_NOTE segments the first PT_NOTE (if present)
-     *     contains /proc structs in the pre-2.6 unstructured /proc format. the last
-@@ -666,10 +677,10 @@
-     *     integer register set among other stuff. For each LWP, we have one lwpstatus
-     *     entry that has integer regset for that LWP.
-     *
--    *     Bsd threads are actually 'clone'd processes. To support core analysis
--    *     of "multithreaded" process, Bsd creates more than one pstatus (called
-+    *     Linux threads are actually 'clone'd processes. To support core analysis
-+    *     of "multithreaded" process, Linux creates more than one pstatus (called
-     *     "prstatus") entry in PT_NOTE. Each prstatus entry has integer regset for one
--    *     "thread". Please refer to Bsd kernel src file 'fs/binfmt_elf.c', in particular
-+    *     "thread". Please refer to Linux kernel src file 'fs/binfmt_elf.c', in particular
-     *     function "elf_core_dump".
-     */
- 
-@@ -725,7 +736,7 @@
-    return false;
- }
- 
--// process segments from interpreter (ld.so or ld-bsd.so)
-+// process segments from interpreter (ld-elf.so.1)
- static bool read_interp_segments(struct ps_prochandle* ph) {
-    ELF_EHDR interp_ehdr;
- 
-@@ -826,7 +837,7 @@
- 
-    dyn.d_tag = DT_NULL;
-    while (dyn.d_tag != DT_DEBUG) {
--      if (ps_pdread(ph, (psaddr_t) addr, &dyn, sizeof(ELF_DYN)) != PS_OK) {
-+      if (ps_pread(ph, (psaddr_t) addr, &dyn, sizeof(ELF_DYN)) != PS_OK) {
-          print_debug("can't read debug info from _DYNAMIC\n");
-          return false;
-       }
-@@ -836,23 +847,27 @@
-    // we have got Dyn entry with DT_DEBUG
-    debug_base = dyn.d_un.d_ptr;
-    // at debug_base we have struct r_debug. This has first link map in r_map field
--   if (ps_pdread(ph, (psaddr_t) debug_base + FIRST_LINK_MAP_OFFSET,
-+   if (ps_pread(ph, (psaddr_t) debug_base + FIRST_LINK_MAP_OFFSET,
-                  &first_link_map_addr, sizeof(uintptr_t)) != PS_OK) {
-       print_debug("can't read first link map address\n");
-       return false;
-    }
- 
-    // read ld_base address from struct r_debug
--   if (ps_pdread(ph, (psaddr_t) debug_base + LD_BASE_OFFSET, &ld_base_addr,
-+   // XXX: There is no r_ldbase member on BSD
-+/*
-+   if (ps_pread(ph, (psaddr_t) debug_base + LD_BASE_OFFSET, &ld_base_addr,
-                  sizeof(uintptr_t)) != PS_OK) {
-       print_debug("can't read ld base address\n");
-       return false;
-    }
-    ph->core->ld_base_addr = ld_base_addr;
-+*/
-+   ph->core->ld_base_addr = 0;
- 
-    print_debug("interpreter base address is 0x%lx\n", ld_base_addr);
- 
--   // now read segments from interp (i.e ld.so or ld-bsd.so)
-+   // now read segments from interp (i.e ld-elf.so.1)
-    if (read_interp_segments(ph) != true)
-       return false;
- 
-@@ -870,26 +885,23 @@
-       // address mentioned in shared object and the actual virtual base where runtime
-       // linker loaded it. We use "base diff" in read_lib_segments call below.
- 
--      if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_ADDR_OFFSET,
-+      if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_ADDR_OFFSET,
-                    &lib_base_diff, sizeof(uintptr_t)) != PS_OK) {
-          print_debug("can't read shared object base address diff\n");
-          return false;
-       }
- 
-       // read address of the name
--      if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_NAME_OFFSET,
-+      if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_NAME_OFFSET,
-                     &lib_name_addr, sizeof(uintptr_t)) != PS_OK) {
-          print_debug("can't read address of shared object name\n");
-          return false;
-       }
- 
-       // read name of the shared object
--      lib_name[0] = '\0';
--      if (lib_name_addr != 0 &&
--          read_string(ph, (uintptr_t) lib_name_addr, lib_name, sizeof(lib_name)) != true) {
-+      if (read_string(ph, (uintptr_t) lib_name_addr, lib_name, sizeof(lib_name)) != true) {
-          print_debug("can't read shared object name\n");
--         // don't let failure to read the name stop opening the file.  If something is really wrong
--         // it will fail later.
-+         return false;
-       }
- 
-       if (lib_name[0] != '\0') {
-@@ -924,7 +936,7 @@
-       }
- 
-       // read next link_map address
--      if (ps_pdread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
-+      if (ps_pread(ph, (psaddr_t) link_map_addr + LINK_MAP_NEXT_OFFSET,
-                         &link_map_addr, sizeof(uintptr_t)) != PS_OK) {
-          print_debug("can't read next link in link_map\n");
-          return false;
-@@ -938,7 +950,6 @@
- struct ps_prochandle* Pgrab_core(const char* exec_file, const char* core_file) {
-    ELF_EHDR core_ehdr;
-    ELF_EHDR exec_ehdr;
--   ELF_EHDR lib_ehdr;
- 
-    struct ps_prochandle* ph = (struct ps_prochandle*) calloc(1, sizeof(struct ps_prochandle));
-    if (ph == NULL) {
+    memcpy(&newthr->regs, &prstat->pr_reg, sizeof(struct reg));
 --- hotspot/agent/src/os/bsd/ps_proc.c
 +++ hotspot/agent/src/os/bsd/ps_proc.c
-@@ -22,20 +22,22 @@
-  *
-  */
- 
-+#include <limits.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <errno.h>
-+#include <sys/types.h>
-+#include <sys/wait.h>
- #include <sys/ptrace.h>
-+#include <sys/param.h>
-+#include <sys/user.h>
-+#include <elf.h>
-+#include <sys/elf_common.h>
-+#include <sys/link_elf.h>
-+#include <libutil.h>
- #include "libproc_impl.h"
--
--#if defined(x86_64) && !defined(amd64)
--#define amd64 1
--#endif
--
--#ifndef __WALL
--#define __WALL          0x40000000  // Copied from /usr/include/bsd/wait.h
--#endif
-+#include "elfmacros.h"
- 
- // This file has the libproc implementation specific to live process
- // For core files, refer to ps_core.c
-@@ -50,253 +52,365 @@
- 
- // read "size" bytes of data from "addr" within the target process.
- // unlike the standard ptrace() function, process_read_data() can handle
--// unaligned address - alignment check, if required, should be done
-+// unaligned address - alignment check, if required, should be done 
- // before calling process_read_data.
- 
- static bool process_read_data(struct ps_prochandle* ph, uintptr_t addr, char *buf, size_t size) {
--  long rslt;
-+  int rslt;
-   size_t i, words;
-   uintptr_t end_addr = addr + size;
--  uintptr_t aligned_addr = align(addr, sizeof(long));
-+  uintptr_t aligned_addr = align(addr, sizeof(int));
- 
-   if (aligned_addr != addr) {
-     char *ptr = (char *)&rslt;
-     errno = 0;
--    rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
-+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
-     if (errno) {
--      print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
-+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
-       return false;
-     }
-     for (; aligned_addr != addr; aligned_addr++, ptr++);
--    for (; ((intptr_t)aligned_addr % sizeof(long)) && aligned_addr < end_addr;
--        aligned_addr++)
-+    for (; ((intptr_t)aligned_addr % sizeof(int)) && aligned_addr < end_addr; 
-+        aligned_addr++) 
-        *(buf++) = *(ptr++);
-   }
- 
--  words = (end_addr - aligned_addr) / sizeof(long);
-+  words = (end_addr - aligned_addr) / sizeof(int);
- 
--  // assert((intptr_t)aligned_addr % sizeof(long) == 0);
-+  // assert((intptr_t)aligned_addr % sizeof(int) == 0);
-   for (i = 0; i < words; i++) {
-     errno = 0;
--    rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
-+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
-     if (errno) {
--      print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
-+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
-       return false;
-     }
--    *(long *)buf = rslt;
--    buf += sizeof(long);
--    aligned_addr += sizeof(long);
-+    *(int *)buf = rslt;
-+    buf += sizeof(int);
-+    aligned_addr += sizeof(int);
-   }
- 
-   if (aligned_addr != end_addr) {
-     char *ptr = (char *)&rslt;
-     errno = 0;
--    rslt = ptrace(PTRACE_PEEKDATA, ph->pid, aligned_addr, 0);
-+    rslt = ptrace(PT_READ_D, ph->pid, (caddr_t) aligned_addr, 0);
-     if (errno) {
--      print_debug("ptrace(PTRACE_PEEKDATA, ..) failed for %d bytes @ %lx\n", size, addr);
-+      print_debug("ptrace(PT_READ_D, ..) failed for %d bytes @ %lx\n", size, addr);
-       return false;
-     }
--    for (; aligned_addr != end_addr; aligned_addr++)
-+    for (; aligned_addr != end_addr; aligned_addr++) 
-        *(buf++) = *(ptr++);
-   }
-   return true;
- }
- 
- // null implementation for write
--static bool process_write_data(struct ps_prochandle* ph,
-+static bool process_write_data(struct ps_prochandle* ph, 
-                              uintptr_t addr, const char *buf , size_t size) {
-   return false;
- }
- 
--// "user" should be a pointer to a user_regs_struct
--static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct user_regs_struct *user) {
-+// "user" should be a pointer to a reg
-+static bool process_get_lwp_regs(struct ps_prochandle* ph, pid_t pid, struct reg *user) {
-   // we have already attached to all thread 'pid's, just use ptrace call
-   // to get regset now. Note that we don't cache regset upfront for processes.
--// Bsd on x86 and sparc are different.  On x86 ptrace(PTRACE_GETREGS, ...)
--// uses pointer from 4th argument and ignores 3rd argument.  On sparc it uses
--// pointer from 3rd argument and ignores 4th argument
--#if defined(sparc) || defined(sparcv9)
--#define ptrace_getregs(request, pid, addr, data) ptrace(request, pid, addr, data)
--#else
--#define ptrace_getregs(request, pid, addr, data) ptrace(request, pid, data, addr)
--#endif
--
--#if defined(_LP64) && defined(PTRACE_GETREGS64)
--#define PTRACE_GETREGS_REQ PTRACE_GETREGS64
--#elif defined(PTRACE_GETREGS)
--#define PTRACE_GETREGS_REQ PTRACE_GETREGS
--#elif defined(PT_GETREGS)
--#define PTRACE_GETREGS_REQ PT_GETREGS
--#endif
--
--#ifdef PTRACE_GETREGS_REQ
-- if (ptrace_getregs(PTRACE_GETREGS_REQ, pid, user, NULL) < 0) {
-+ if (ptrace(PT_GETREGS, pid, (caddr_t) user, 0) < 0) {
-    print_debug("ptrace(PTRACE_GETREGS, ...) failed for lwp %d\n", pid);
-    return false;
-  }
-  return true;
--#else
-- print_debug("ptrace(PTRACE_GETREGS, ...) not supported\n");
-- return false;
--#endif
-+}
-+
-+// fill in ptrace_lwpinfo for lid
-+static bool process_get_lwp_info(struct ps_prochandle *ph, lwpid_t lwp_id, void *linfo) {
-+  errno = 0;
-+  ptrace(PT_LWPINFO, lwp_id, linfo, sizeof(struct ptrace_lwpinfo));
- 
-+  return (errno == 0)? true: false;
- }
- 
- // attach to a process/thread specified by "pid"
- static bool ptrace_attach(pid_t pid) {
--  if (ptrace(PTRACE_ATTACH, pid, NULL, NULL) < 0) {
-+  if (ptrace(PT_ATTACH, pid, NULL, 0) < 0) {
-     print_debug("ptrace(PTRACE_ATTACH, ..) failed for %d\n", pid);
-     return false;
-   } else {
-     int ret;
-     int status;
-     do {
--      // Wait for debuggee to stop.
-+      // Wait for debuggee to stop. 
-       ret = waitpid(pid, &status, 0);
--      if (ret == -1 && errno == ECHILD) {
--        // try cloned process.
--        ret = waitpid(pid, &status, __WALL);
--      }
-       if (ret >= 0) {
--        if (WIFSTOPPED(status)) {
--          // Debuggee stopped.
--          return true;
-+	if (WIFSTOPPED(status)) {
-+	  // Debuggee stopped.
-+	  return true;
-         } else {
--          print_debug("waitpid(): Child process exited/terminated (status = 0x%x)\n", status);
--          return false;
--        }
-+    	  print_debug("waitpid(): Child process exited/terminated (status = 0x%x)\n", status);
-+	  return false;
-+	}
-       } else {
--        switch (errno) {
--          case EINTR:
-+	switch (errno) {
-+	  case EINTR: 
-             continue;
--            break;
--          case ECHILD:
--            print_debug("waitpid() failed. Child process pid (%d) does not exist \n", pid);
--            break;
--          case EINVAL:
--            print_debug("waitpid() failed. Invalid options argument.\n");
--            break;
--          default:
--            print_debug("waitpid() failed. Unexpected error %d\n",errno);
-+	    break;
-+	  case ECHILD:
-+    	    print_debug("waitpid() failed. Child process pid (%d) does not exist \n", pid);
-+	    break;
-+	  case EINVAL:
-+    	    print_debug("waitpid() failed. Invalid options argument.\n");
-+	    break;
-+	  default:
-+    	    print_debug("waitpid() failed. Unexpected error %d\n",errno);
-         }
-         return false;
--      }
-+      } 
-     } while(true);
--  }
--}
--
-+  } 
-+} 
-+  
+@@ -173,9 +173,15 @@
  // -------------------------------------------------------
- // functions for obtaining library information
- // -------------------------------------------------------
  
--/*
-- * splits a string _str_ into substrings with delimiter _delim_ by replacing old * delimiters with _new_delim_ (ideally, '\0'). the address of each substring
-- * is stored in array _ptrs_ as the return value. the maximum capacity of _ptrs_ * array is specified by parameter _n_.
-- * RETURN VALUE: total number of substrings (always <= _n_)
-- * NOTE: string _str_ is modified if _delim_!=_new_delim_
-- */
--static int split_n_str(char * str, int n, char ** ptrs, char delim, char new_delim)
--{
--   int i;
--   for(i = 0; i < n; i++) ptrs[i] = NULL;
--   if (str == NULL || n < 1 ) return 0;
--
--   i = 0;
--
--   // skipping leading blanks
--   while(*str&&*str==delim) str++;
--
--   while(*str&&i<n){
--     ptrs[i++] = str;
--     while(*str&&*str!=delim) str++;
--     while(*str&&*str==delim) *(str++) = new_delim;
--   }
--
--   return i;
-+// callback for read_thread_info
+ // callback for read_thread_info
 +#ifdef __MidnightBSD__
 +static bool add_new_thread(struct ps_prochandle* ph, lwpid_t lwp_id) {
 +  return add_thread_info(ph, lwp_id) != NULL;
 +}
 +#else
-+static bool add_new_thread(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
-+  return add_thread_info(ph, pthread_id, lwp_id) != NULL;
+ static bool add_new_thread(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
+   return add_thread_info(ph, pthread_id, lwp_id) != NULL;
  }
 +#endif
  
-+#if defined(__MidnightBSD__) && __MidnightBSD_version < 4015
+ #if defined(__FreeBSD__) && __FreeBSD_version < 701000
  /*
-- * fgets without storing '\n' at the end of the string
-+ * TEXT_START_ADDR from binutils/ld/emulparams/<arch_spec>.sh
-+ * Not the most robust but good enough.
-  */
--static char * fgets_no_cr(char * buf, int n, FILE *fp)
--{
--   char * rslt = fgets(buf, n, fp);
--   if (rslt && buf && *buf){
--       char *p = strchr(buf, '\0');
--       if (*--p=='\n') *p='\0';
--   }
--   return rslt;
--}
- 
--// callback for read_thread_info
--static bool add_new_thread(struct ps_prochandle* ph, pthread_t pthread_id, lwpid_t lwp_id) {
--  return add_thread_info(ph, pthread_id, lwp_id) != NULL;
-+#if defined(amd64) || defined(x86_64)
-+#define TEXT_START_ADDR 0x400000
-+#elif defined(i386)
-+#define TEXT_START_ADDR 0x8048000
-+#else
-+#error TEXT_START_ADDR not defined
-+#endif
-+
-+#define BUF_SIZE (PATH_MAX + NAME_MAX + 1)
-+
-+uintptr_t linkmap_addr(struct ps_prochandle *ph) {
-+  uintptr_t ehdr_addr, phdr_addr, dyn_addr, dmap_addr, lmap_addr;
-+  ELF_EHDR ehdr;
-+  ELF_PHDR *phdrs, *phdr;
-+  ELF_DYN *dyns, *dyn;
-+  struct r_debug dmap;
-+  unsigned long hdrs_size;
-+  unsigned int i;
-+
-+  /* read ELF_EHDR at TEXT_START_ADDR and validate */
-+
-+  ehdr_addr = (uintptr_t)TEXT_START_ADDR;
-+
-+  if (process_read_data(ph, ehdr_addr, (char *)&ehdr, sizeof(ehdr)) != true) {
-+    print_debug("process_read_data failed for ehdr_addr %p\n", ehdr_addr);
-+    return (0);
-+  }
-+
-+  if (!IS_ELF(ehdr) ||
-+        ehdr.e_ident[EI_CLASS] != ELF_TARG_CLASS ||
-+        ehdr.e_ident[EI_DATA] != ELF_TARG_DATA ||
-+        ehdr.e_ident[EI_VERSION] != EV_CURRENT ||
-+        ehdr.e_phentsize != sizeof(ELF_PHDR) ||
-+        ehdr.e_version != ELF_TARG_VER ||
-+        ehdr.e_machine != ELF_TARG_MACH) {
-+    print_debug("not an ELF_EHDR at %p\n", ehdr_addr);
-+    return (0);
-+  }
-+
-+  /* allocate space for all ELF_PHDR's and read */
-+
-+  phdr_addr = ehdr_addr + ehdr.e_phoff;
-+  hdrs_size = ehdr.e_phnum * sizeof(ELF_PHDR);
-+
-+  if ((phdrs = malloc(hdrs_size)) == NULL)
-+    return (0);
-+
-+  if (process_read_data(ph, phdr_addr, (char *)phdrs, hdrs_size) != true) {
-+    print_debug("process_read_data failed for phdr_addr %p\n", phdr_addr);
-+    return (0);
-+  }
-+
-+  /* find PT_DYNAMIC section */
-+
-+  for (i = 0, phdr = phdrs; i < ehdr.e_phnum; i++, phdr++) {
-+    if (phdr->p_type == PT_DYNAMIC)
-+      break;
-+  }
-+
-+  if (i >= ehdr.e_phnum) {
-+    print_debug("PT_DYNAMIC section not found!\n");
-+    free(phdrs);
-+    return (0);
-+  }
-+
-+  /* allocate space and read in ELF_DYN headers */
-+
-+  dyn_addr = phdr->p_vaddr;
-+  hdrs_size = phdr->p_memsz;
-+  free(phdrs);
-+
-+  if ((dyns = malloc(hdrs_size)) == NULL)
-+    return (0);
-+
-+  if (process_read_data(ph, dyn_addr, (char *)dyns, hdrs_size) != true) {
-+    print_debug("process_read_data failed for dyn_addr %p\n", dyn_addr);
-+    free(dyns);
-+    return (0);
-+  }
-+
-+  /* find DT_DEBUG */
-+  
-+  dyn = dyns;
-+  while (dyn->d_tag != DT_DEBUG && dyn->d_tag != DT_NULL) {
-+    dyn++;
-+  }
-+
-+  if (dyn->d_tag != DT_DEBUG) {
-+    print_debug("failed to find DT_DEBUG\n");
-+    free(dyns);
-+    return (0);
-+  }
-+
-+  /* read struct r_debug into dmap */
-+
-+  dmap_addr = (uintptr_t)dyn->d_un.d_ptr;
-+  free(dyns);
-+
-+  if (process_read_data(ph, dmap_addr, (char *)&dmap, sizeof(dmap)) != true) {
-+    print_debug("process_read_data failed for dmap_addr %p\n", dmap_addr);
-+    return (0);
-+  }
-+
-+  lmap_addr = (uintptr_t)dmap.r_map;
-+
-+  return (lmap_addr);
- }
-+#endif // __MidnightBSD__ && __MidnightBSD_version < 4015
- 
- static bool read_lib_info(struct ps_prochandle* ph) {
--  char fname[32];
--  char buf[256];
--  FILE *fp = NULL;
--
--  sprintf(fname, "/proc/%d/maps", ph->pid);
--  fp = fopen(fname, "r");
--  if (fp == NULL) {
--    print_debug("can't open /proc/%d/maps file\n", ph->pid);
--    return false;
-+#if defined(__MidnightBSD__) && __MidnightBSD_version >= 4015
-+  struct kinfo_vmentry *freep, *kve;
-+  int i, cnt;
-+
-+  freep = kinfo_getvmmap(ph->pid, &cnt);
-+  if (freep == NULL) {
-+      print_debug("can't get vm map for pid\n", ph->pid);
-+      return false;
-   }
- 
--  while(fgets_no_cr(buf, 256, fp)){
--    char * word[6];
--    int nwords = split_n_str(buf, 6, word, ' ', '\0');
--    if (nwords > 5 && find_lib(ph, word[5]) == false) {
--       intptr_t base;
--       lib_info* lib;
--#ifdef _LP64
--       sscanf(word[0], "%lx", &base);
--#else
--       sscanf(word[0], "%x", &base);
--#endif
--       if ((lib = add_lib_info(ph, word[5], (uintptr_t)base)) == NULL)
-+  for (i = 0; i < cnt; i++) {
-+    kve = &freep[i];
-+    if ((kve->kve_flags & KVME_FLAG_COW) &&
-+        kve->kve_path != NULL &&
-+        strlen(kve->kve_path) > 0) {
-+
-+      if (find_lib(ph, kve->kve_path) == false) {
-+        lib_info* lib;
-+        if ((lib = add_lib_info(ph, kve->kve_path,
-+                                (uintptr_t) kve->kve_start)) == NULL)
-           continue; // ignore, add_lib_info prints error
- 
--       // we don't need to keep the library open, symtab is already
--       // built. Only for core dump we need to keep the fd open.
--       close(lib->fd);
--       lib->fd = -1;
-+        // we don't need to keep the library open, symtab is already
-+        // built. Only for core dump we need to keep the fd open.
-+        close(lib->fd);
-+        lib->fd = -1;
-+      }
-     }
-   }
--  fclose(fp);
-+
-+  free(freep);
-+
-+  return true;
-+#else
-+  char *l_name;
-+  struct link_map *lmap;
-+  uintptr_t lmap_addr;
-+
-+  if ((l_name = malloc(BUF_SIZE)) == NULL)
-+    return false;
-+
-+  if ((lmap = malloc(sizeof(*lmap))) == NULL) {
-+    free(l_name);
-+    return false;
-+  }
-+
-+  lmap_addr = linkmap_addr(ph);
-+
-+  if (lmap_addr == 0) {
-+    free(l_name);
-+    free(lmap);
-+    return false;
-+  }
-+
-+  do {
-+    if (process_read_data(ph, lmap_addr, (char *)lmap, sizeof(*lmap)) != true) {
-+      print_debug("process_read_data failed for lmap_addr %p\n", lmap_addr);
-+      free (l_name);
-+      free (lmap);
-+      return false;
-+    }
-+
-+    if (process_read_data(ph, (uintptr_t)lmap->l_name, l_name,
-+        BUF_SIZE) != true) {
-+      print_debug("process_read_data failed for lmap->l_name %p\n",
-+          lmap->l_name);
-+      free (l_name);
-+      free (lmap);
-+      return false;
-+    }
-+
-+    if (find_lib(ph, l_name) == false) {
-+      lib_info* lib;
-+      if ((lib = add_lib_info(ph, l_name,
-+                              (uintptr_t) lmap->l_addr)) == NULL)
-+        continue; // ignore, add_lib_info prints error
-+
-+      // we don't need to keep the library open, symtab is already
-+      // built. Only for core dump we need to keep the fd open.
-+      close(lib->fd);
-+      lib->fd = -1;
-+    }
-+    lmap_addr = (uintptr_t)lmap->l_next;
-+  } while (lmap->l_next != NULL);
-+
-+  free (l_name);
-+  free (lmap);
-+
-   return true;
-+#endif
- }
- 
- // detach a given pid
- static bool ptrace_detach(pid_t pid) {
--  if (pid && ptrace(PTRACE_DETACH, pid, NULL, NULL) < 0) {
-+  if (pid && ptrace(PT_DETACH, pid, (caddr_t)1, 0) < 0) {
-     print_debug("ptrace(PTRACE_DETACH, ..) failed for %d\n", pid);
-     return false;
-   } else {
-     return true;
--  }
--}
--
--// detach all pids of a ps_prochandle
--static void detach_all_pids(struct ps_prochandle* ph) {
--  thread_info* thr = ph->threads;
--  while (thr) {
--     ptrace_detach(thr->lwp_id);
--     thr = thr->next;
--  }
-+  } 
- }
- 
- static void process_cleanup(struct ps_prochandle* ph) {
--  detach_all_pids(ph);
-+  ptrace_detach(ph->pid);
- }
- 
- static ps_prochandle_ops process_ops = {
-   .release=  process_cleanup,
-   .p_pread=  process_read_data,
-   .p_pwrite= process_write_data,
--  .get_lwp_regs= process_get_lwp_regs
-+  .get_lwp_regs= process_get_lwp_regs,
-+  .get_lwp_info= process_get_lwp_info
- };
- 
- // attach to the process. One and only one exposed stuff
-@@ -323,21 +437,14 @@
-   // read library info and symbol tables, must do this before attaching threads,
-   // as the symbols in the pthread library will be used to figure out
-   // the list of threads within the same process.
--  read_lib_info(ph);
--
-+  if (read_lib_info(ph) != true) {
-+     ptrace_detach(pid);
-+     free(ph);
-+     return NULL;
-+  }
-+ 
-   // read thread info
-   read_thread_info(ph, add_new_thread);
- 
--  // attach to the threads
--  thr = ph->threads;
--  while (thr) {
--     // don't attach to the main thread again
--     if (ph->pid != thr->lwp_id && ptrace_attach(thr->lwp_id) != true) {
--        // even if one attach fails, we get return NULL
--        Prelease(ph);
--        return NULL;
--     }
--     thr = thr->next;
--  }
-   return ph;
- }
---- hotspot/agent/src/os/bsd/salibelf.c
-+++ hotspot/agent/src/os/bsd/salibelf.c
-@@ -25,6 +25,7 @@
- #include "salibelf.h"
- #include <stdlib.h>
- #include <unistd.h>
-+#include <string.h>
- 
- extern void print_debug(const char*,...);
- 
---- hotspot/agent/src/os/bsd/symtab.c
-+++ hotspot/agent/src/os/bsd/symtab.c
-@@ -23,10 +23,11 @@
-  */
- 
- #include <unistd.h>
--#include <sys/procfs.h>
- #include <search.h>
- #include <stdlib.h>
- #include <string.h>
-+#include <db.h>
-+#include <fcntl.h>
- #include "symtab.h"
- #include "salibelf.h"
- 
-@@ -50,279 +51,12 @@
-   char *strs;
-   size_t num_symbols;
-   struct elf_symbol *symbols;
--  struct hsearch_data *hash_table;
-+  DB* hash_table;
- } symtab_t;
- 
--
--// Directory that contains global debuginfo files.  In theory it
--// should be possible to change this, but in a Java environment there
--// is no obvious place to put a user interface to do it.  Maybe this
--// could be set with an environment variable.
--static const char debug_file_directory[] = "/usr/lib/debug";
--
--/* The CRC used in gnu_debuglink, retrieved from
--   http://sourceware.org/gdb/current/onlinedocs/gdb/Separate-Debug-Files.html#Separate-Debug-Files. */
--unsigned int gnu_debuglink_crc32 (unsigned int crc,
--                                  unsigned char *buf, size_t len)
--{
--  static const unsigned int crc32_table[256] =
--    {
--      0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
--      0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
--      0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
--      0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
--      0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
--      0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
--      0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
--      0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
--      0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
--      0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
--      0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
--      0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
--      0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
--      0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
--      0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
--      0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
--      0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
--      0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
--      0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
--      0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
--      0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
--      0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
--      0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
--      0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
--      0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
--      0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
--      0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
--      0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
--      0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
--      0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
--      0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
--      0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
--      0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
--      0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
--      0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
--      0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
--      0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
--      0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
--      0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
--      0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
--      0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
--      0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
--      0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
--      0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
--      0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
--      0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
--      0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
--      0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
--      0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
--      0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
--      0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
--      0x2d02ef8d
--    };
--  unsigned char *end;
--
--  crc = ~crc & 0xffffffff;
--  for (end = buf + len; buf < end; ++buf)
--    crc = crc32_table[(crc ^ *buf) & 0xff] ^ (crc >> 8);
--  return ~crc & 0xffffffff;
--}
--
--/* Open a debuginfo file and check its CRC.  If it exists and the CRC
--   matches return its fd.  */
--static int
--open_debug_file (const char *pathname, unsigned int crc)
--{
--  unsigned int file_crc = 0;
--  unsigned char buffer[8 * 1024];
--
--  int fd = pathmap_open(pathname);
--
--  if (fd < 0)
--    return -1;
--
--  lseek(fd, 0, SEEK_SET);
--
--  for (;;) {
--    int len = read(fd, buffer, sizeof buffer);
--    if (len <= 0)
--      break;
--    file_crc = gnu_debuglink_crc32(file_crc, buffer, len);
--  }
--
--  if (crc == file_crc)
--    return fd;
--  else {
--    close(fd);
--    return -1;
--  }
--}
--
--/* Find an ELF section.  */
--static struct elf_section *find_section_by_name(char *name,
--                                                int fd,
--                                                ELF_EHDR *ehdr,
--                                                ELF_SHDR *shbuf,
--                                                struct elf_section *scn_cache)
--{
--  ELF_SHDR* cursct = NULL;
--  char *strtab;
--  int cnt;
--
--  if (scn_cache[ehdr->e_shstrndx].c_data == NULL) {
--    if ((scn_cache[ehdr->e_shstrndx].c_data
--         = read_section_data(fd, ehdr, cursct)) == NULL) {
--      return NULL;
--    }
--  }
--
--  strtab = scn_cache[ehdr->e_shstrndx].c_data;
--
--  for (cursct = shbuf, cnt = 0;
--       cnt < ehdr->e_shnum;
--       cnt++, cursct++) {
--    if (strcmp(cursct->sh_name + strtab, name) == 0) {
--      scn_cache[cnt].c_data = read_section_data(fd, ehdr, cursct);
--      return &scn_cache[cnt];
--    }
--  }
--
--  return NULL;
--}
--
--/* Look for a ".gnu_debuglink" section.  If one exists, try to open a
--   suitable debuginfo file.  */
--static int open_file_from_debug_link(const char *name,
--                                     int fd,
--                                     ELF_EHDR *ehdr,
--                                     ELF_SHDR *shbuf,
--                                     struct elf_section *scn_cache)
--{
--  int debug_fd;
--  struct elf_section *debug_link = find_section_by_name(".gnu_debuglink", fd, ehdr,
--                                                        shbuf, scn_cache);
--  if (debug_link == NULL)
--    return -1;
--  char *debug_filename = debug_link->c_data;
--  int offset = (strlen(debug_filename) + 4) >> 2;
--  static unsigned int crc;
--  crc = ((unsigned int*)debug_link->c_data)[offset];
--  char *debug_pathname = malloc(strlen(debug_filename)
--                                + strlen(name)
--                                + strlen(".debug/")
--                                + strlen(debug_file_directory)
--                                + 2);
--  strcpy(debug_pathname, name);
--  char *last_slash = strrchr(debug_pathname, '/');
--  if (last_slash == NULL)
--    return -1;
--
--  /* Look in the same directory as the object.  */
--  strcpy(last_slash+1, debug_filename);
--
--  debug_fd = open_debug_file(debug_pathname, crc);
--  if (debug_fd >= 0) {
--    free(debug_pathname);
--    return debug_fd;
--  }
--
--  /* Look in a subdirectory named ".debug".  */
--  strcpy(last_slash+1, ".debug/");
--  strcat(last_slash, debug_filename);
--
--  debug_fd = open_debug_file(debug_pathname, crc);
--  if (debug_fd >= 0) {
--    free(debug_pathname);
--    return debug_fd;
--  }
--
--  /* Look in /usr/lib/debug + the full pathname.  */
--  strcpy(debug_pathname, debug_file_directory);
--  strcat(debug_pathname, name);
--  last_slash = strrchr(debug_pathname, '/');
--  strcpy(last_slash+1, debug_filename);
--
--  debug_fd = open_debug_file(debug_pathname, crc);
--  if (debug_fd >= 0) {
--    free(debug_pathname);
--    return debug_fd;
--  }
--
--  free(debug_pathname);
--  return -1;
--}
--
--static struct symtab* build_symtab_internal(int fd, const char *filename, bool try_debuginfo);
--
--/* Look for a ".gnu_debuglink" section.  If one exists, try to open a
--   suitable debuginfo file and read a symbol table from it.  */
--static struct symtab *build_symtab_from_debug_link(const char *name,
--                                     int fd,
--                                     ELF_EHDR *ehdr,
--                                     ELF_SHDR *shbuf,
--                                     struct elf_section *scn_cache)
--{
--  fd = open_file_from_debug_link(name, fd, ehdr, shbuf, scn_cache);
--
--  if (fd >= 0) {
--    struct symtab *symtab = build_symtab_internal(fd, NULL, /* try_debuginfo */ false);
--    close(fd);
--    return symtab;
--  }
--
--  return NULL;
--}
--
--// Given a build_id, find the associated debuginfo file
--static char *
--build_id_to_debug_filename (size_t size, unsigned char *data)
--{
--  char *filename, *s;
--
--  filename = malloc(strlen (debug_file_directory) + (sizeof "/.build-id/" - 1) + 1
--                    + 2 * size + (sizeof ".debug" - 1) + 1);
--  s = filename + sprintf (filename, "%s/.build-id/", debug_file_directory);
--  if (size > 0)
--    {
--      size--;
--      s += sprintf (s, "%02x", *data++);
--    }
--  if (size > 0)
--    *s++ = '/';
--  while (size-- > 0)
--    s += sprintf (s, "%02x", *data++);
--  strcpy (s, ".debug");
--
--  return filename;
--}
--
--// Read a build ID note.  Try to open any associated debuginfo file
--// and return its symtab
--static struct symtab* build_symtab_from_build_id(Elf64_Nhdr *note)
--{
--  int fd;
--  struct symtab *symtab = NULL;
--
--  unsigned char *bytes
--    = (unsigned char*)(note+1) + note->n_namesz;
--  unsigned char *filename
--    = (build_id_to_debug_filename (note->n_descsz, bytes));
--
--  fd = pathmap_open(filename);
--  if (fd >= 0) {
--    symtab = build_symtab_internal(fd, NULL, /* try_debuginfo */ false);
--    close(fd);
--  }
--  free(filename);
--
--  return symtab;
--}
--
--// read symbol table from given fd.  If try_debuginfo) is true, also
--// try to open an associated debuginfo file
--static struct symtab* build_symtab_internal(int fd, const char *filename, bool try_debuginfo) {
-+// read symbol table from given fd.
-+struct symtab* build_symtab(int fd) {
-   ELF_EHDR ehdr;
--  char *names = NULL;
-   struct symtab* symtab = NULL;
- 
-   // Reading of elf header
-@@ -331,8 +65,9 @@
-   ELF_SHDR* shbuf = NULL;
-   ELF_SHDR* cursct = NULL;
-   ELF_PHDR* phbuf = NULL;
--  ELF_PHDR* phdr = NULL;
--  int sym_section = SHT_DYNSYM;
-+  int symtab_found = 0;
-+  int dynsym_found = 0;
-+  uint32_t symsection = SHT_SYMTAB;
- 
-   uintptr_t baseaddr = (uintptr_t)-1;
- 
-@@ -349,33 +84,39 @@
- 
-   baseaddr = find_base_address(fd, &ehdr);
- 
--  scn_cache = (struct elf_section *)
--              calloc(ehdr.e_shnum * sizeof(struct elf_section), 1);
-+  scn_cache = calloc(ehdr.e_shnum, sizeof(*scn_cache));
-   if (scn_cache == NULL) {
-     goto quit;
-   }
- 
-   for (cursct = shbuf, cnt = 0; cnt < ehdr.e_shnum; cnt++) {
-     scn_cache[cnt].c_shdr = cursct;
--    if (cursct->sh_type == SHT_SYMTAB || cursct->sh_type == SHT_STRTAB
--        || cursct->sh_type == SHT_NOTE || cursct->sh_type == SHT_DYNSYM) {
--      if ( (scn_cache[cnt].c_data = read_section_data(fd, &ehdr, cursct)) == NULL) {
-+    if (cursct->sh_type == SHT_SYMTAB ||
-+        cursct->sh_type == SHT_STRTAB ||
-+        cursct->sh_type == SHT_DYNSYM) {
-+      if ((scn_cache[cnt].c_data = read_section_data(fd, &ehdr, cursct)) == NULL) {
-          goto quit;
-       }
-     }
--    if (cursct->sh_type == SHT_SYMTAB) {
--      // Full symbol table available so use that
--      sym_section = cursct->sh_type;
--    }
-+
-+    if (cursct->sh_type == SHT_SYMTAB)
-+       symtab_found++;
-+
-+    if (cursct->sh_type == SHT_DYNSYM)
-+       dynsym_found++;
-+
-     cursct++;
-   }
- 
-+  if (!symtab_found && dynsym_found)
-+     symsection = SHT_DYNSYM;
-+
-   for (cnt = 1; cnt < ehdr.e_shnum; cnt++) {
-     ELF_SHDR *shdr = scn_cache[cnt].c_shdr;
- 
--    if (shdr->sh_type == sym_section) {
-+    if (shdr->sh_type == symsection) {
-       ELF_SYM  *syms;
--      int j, n, rslt;
-+      int j, n;
-       size_t size;
- 
-       // FIXME: there could be multiple data buffers associated with the
-@@ -383,7 +124,7 @@
-       // for elf_getdata on Solaris.
- 
-       // guarantee(symtab == NULL, "multiple symtab");
--      symtab = (struct symtab*)calloc(1, sizeof(struct symtab));
-+      symtab = calloc(1, sizeof(*symtab));
-       if (symtab == NULL) {
-          goto quit;
-       }
-@@ -393,27 +134,32 @@
-       // number of symbols
-       n = shdr->sh_size / shdr->sh_entsize;
- 
--      // create hash table, we use hcreate_r, hsearch_r and hdestroy_r to
-+      // create hash table, we use berkeley db to
-       // manipulate the hash table.
--      symtab->hash_table = (struct hsearch_data*) calloc(1, sizeof(struct hsearch_data));
--      rslt = hcreate_r(n, symtab->hash_table);
--      // guarantee(rslt, "unexpected failure: hcreate_r");
-+      symtab->hash_table = dbopen(NULL, O_CREAT | O_RDWR, 0600, DB_HASH, NULL);
-+      // guarantee(symtab->hash_table, "unexpected failure: dbopen");
-+      if (symtab->hash_table == NULL)
-+	goto bad;
- 
-       // shdr->sh_link points to the section that contains the actual strings
-       // for symbol names. the st_name field in ELF_SYM is just the
-       // string table index. we make a copy of the string table so the
-       // strings will not be destroyed by elf_end.
-       size = scn_cache[shdr->sh_link].c_shdr->sh_size;
--      symtab->strs = (char *)malloc(size);
-+      symtab->strs = malloc(size);
-+      if (symtab->strs == NULL)
-+	goto bad;
-       memcpy(symtab->strs, scn_cache[shdr->sh_link].c_data, size);
- 
-       // allocate memory for storing symbol offset and size;
-       symtab->num_symbols = n;
--      symtab->symbols = (struct elf_symbol *)calloc(n , sizeof(struct elf_symbol));
-+      symtab->symbols = calloc(n , sizeof(*symtab->symbols));
-+      if (symtab->symbols == NULL)
-+	goto bad;
- 
-       // copy symbols info our symtab and enter them info the hash table
-       for (j = 0; j < n; j++, syms++) {
--        ENTRY item, *ret;
-+        DBT key, value;
-         char *sym_name = symtab->strs + syms->st_name;
- 
-         // skip non-object and non-function symbols
-@@ -427,52 +173,19 @@
-         symtab->symbols[j].offset = syms->st_value - baseaddr;
-         symtab->symbols[j].size   = syms->st_size;
- 
--        item.key = sym_name;
--        item.data = (void *)&(symtab->symbols[j]);
--
--        hsearch_r(item, ENTER, &ret, symtab->hash_table);
-+        key.data = sym_name;
-+        key.size = strlen(sym_name) + 1;
-+        value.data = &(symtab->symbols[j]);
-+        value.size = sizeof(void *);
-+        (*symtab->hash_table->put)(symtab->hash_table, &key, &value, 0);
-       }
-     }
-   }
-+  goto quit;
- 
--  // Look for a separate debuginfo file.
--  if (try_debuginfo) {
--
--    // We prefer a debug symtab to an object's own symtab, so look in
--    // the debuginfo file.  We stash a copy of the old symtab in case
--    // there is no debuginfo.
--    struct symtab* prev_symtab = symtab;
--    symtab = NULL;
--
--#ifdef NT_GNU_BUILD_ID
--    // First we look for a Build ID
--    for (cursct = shbuf, cnt = 0;
--         symtab == NULL && cnt < ehdr.e_shnum;
--         cnt++) {
--      if (cursct->sh_type == SHT_NOTE) {
--        Elf64_Nhdr *note = (Elf64_Nhdr *)scn_cache[cnt].c_data;
--        if (note->n_type == NT_GNU_BUILD_ID) {
--          symtab = build_symtab_from_build_id(note);
--        }
--      }
--      cursct++;
--    }
--#endif
--
--    // Then, if that doesn't work, the debug link
--    if (symtab == NULL) {
--      symtab = build_symtab_from_debug_link(filename, fd, &ehdr, shbuf,
--                                            scn_cache);
--    }
--
--    // If we still haven't found a symtab, use the object's own symtab.
--    if (symtab != NULL) {
--      if (prev_symtab != NULL)
--        destroy_symtab(prev_symtab);
--    } else {
--      symtab = prev_symtab;
--    }
--  }
-+bad:
-+  destroy_symtab(symtab);
-+  symtab = NULL;
- 
- quit:
-   if (shbuf) free(shbuf);
-@@ -488,44 +201,36 @@
-   return symtab;
- }
- 
--struct symtab* build_symtab(int fd, const char *filename) {
--  return build_symtab_internal(fd, filename, /* try_debuginfo */ true);
--}
--
--
- void destroy_symtab(struct symtab* symtab) {
-   if (!symtab) return;
-   if (symtab->strs) free(symtab->strs);
-   if (symtab->symbols) free(symtab->symbols);
-   if (symtab->hash_table) {
--     hdestroy_r(symtab->hash_table);
--     free(symtab->hash_table);
-+    (*symtab->hash_table->close)(symtab->hash_table);
-   }
-   free(symtab);
- }
- 
- uintptr_t search_symbol(struct symtab* symtab, uintptr_t base,
-                       const char *sym_name, int *sym_size) {
--  ENTRY item;
--  ENTRY* ret = NULL;
-+  DBT key, value;
-+  int ret;
- 
-   // library does not have symbol table
-   if (!symtab || !symtab->hash_table)
--     return (uintptr_t)NULL;
-+     return 0;
- 
--  item.key = (char*) strdup(sym_name);
--  hsearch_r(item, FIND, &ret, symtab->hash_table);
--  if (ret) {
--    struct elf_symbol * sym = (struct elf_symbol *)(ret->data);
-+  key.data = (char*)(uintptr_t)sym_name;
-+  key.size = strlen(sym_name) + 1;
-+  ret = (*symtab->hash_table->get)(symtab->hash_table, &key, &value, 0);
-+  if (ret == 0) {
-+    struct elf_symbol *sym = value.data;
-     uintptr_t rslt = (uintptr_t) ((char*)base + sym->offset);
-     if (sym_size) *sym_size = sym->size;
--    free(item.key);
-     return rslt;
-   }
- 
--quit:
--  free(item.key);
--  return (uintptr_t) NULL;
-+  return 0;
- }
- 
- const char* nearest_symbol(struct symtab* symtab, uintptr_t offset,
-@@ -533,12 +238,12 @@
-   int n = 0;
-   if (!symtab) return NULL;
-   for (; n < symtab->num_symbols; n++) {
--     struct elf_symbol* sym = &(symtab->symbols[n]);
--     if (sym->name != NULL &&
--         offset >= sym->offset && offset < sym->offset + sym->size) {
--        if (poffset) *poffset = (offset - sym->offset);
--        return sym->name;
--     }
-+    struct elf_symbol* sym = &symtab->symbols[n];
-+    if (sym->name != NULL &&
-+      offset >= sym->offset && offset < sym->offset + sym->size) {
-+      if (poffset) *poffset = (offset - sym->offset);
-+      return sym->name;
-+    }
-   }
-   return NULL;
- }
---- hotspot/agent/src/os/bsd/symtab.h
-+++ hotspot/agent/src/os/bsd/symtab.h
-@@ -32,7 +32,7 @@
- struct symtab;
- 
- // build symbol table for a given ELF file descriptor
--struct symtab* build_symtab(int fd, const char *filename);
-+struct symtab* build_symtab(int fd);
- 
- // destroy the symbol table
- void destroy_symtab(struct symtab* symtab);
---- hotspot/agent/src/os/bsd/test.c
-+++ hotspot/agent/src/os/bsd/test.c
-@@ -44,7 +44,7 @@
-       }
- 
-       default: {
--        printf("usage %s <pid> or %s <exec file> <core file>\n");
-+        fprintf(stderr, "usage %s <pid> or %s <exec file> <core file>\n", argv[0], argv[0]);
-         return 1;
-       }
-    }
---- hotspot/agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java
-+++ hotspot/agent/src/share/classes/sun/jvm/hotspot/HotSpotAgent.java
-@@ -28,6 +28,7 @@
- import java.net.*;
- import java.rmi.*;
- import sun.jvm.hotspot.debugger.*;
-+import sun.jvm.hotspot.debugger.bsd.*;
- import sun.jvm.hotspot.debugger.dbx.*;
- import sun.jvm.hotspot.debugger.proc.*;
- import sun.jvm.hotspot.debugger.remote.*;
-@@ -337,6 +338,8 @@
-                 setupDebuggerWin32();
-             } else if (os.equals("linux")) {
-                 setupDebuggerLinux();
-+            } else if (os.equals("bsd")) {
-+                setupDebuggerBsd();
-             } else {
-                 // Add support for more operating systems here
-                 throw new DebuggerException("Operating system " + os + " not yet supported");
-@@ -392,6 +395,10 @@
-                 db = new HotSpotTypeDataBase(machDesc,
-                 new LinuxVtblAccess(debugger, jvmLibNames),
-                 debugger, jvmLibNames);
-+            } else if (os.equals("bsd")) {
-+                db = new HotSpotTypeDataBase(machDesc,
-+                new BsdVtblAccess(debugger, jvmLibNames),
-+                debugger, jvmLibNames);
-             } else {
-                 throw new DebuggerException("OS \"" + os + "\" not yet supported (no VtblAccess yet)");
-             }
-@@ -557,6 +564,8 @@
-             setupJVMLibNamesWin32();
-         } else if (os.equals("linux")) {
-             setupJVMLibNamesLinux();
-+        } else if (os.equals("bsd")) {
-+            setupJVMLibNamesBsd();
-         } else {
-             throw new RuntimeException("Unknown OS type");
-         }
-@@ -638,6 +647,31 @@
-         jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so" };
-     }
- 
-+    //
-+    // BSD
-+    //
-+
-+    private void setupDebuggerBsd() {
-+        setupJVMLibNamesBsd();
-+
-+        if (cpu.equals("x86")) {
-+            machDesc = new MachineDescriptionIntelX86();
-+        } else if (cpu.equals("amd64")) {
-+            machDesc = new MachineDescriptionAMD64();
-+        } else {
-+            throw new DebuggerException("BSD only supported on x86/amd64");
-+        }
-+
-+        BsdDebuggerLocal dbg = new BsdDebuggerLocal(machDesc, !isServer);
-+        debugger = dbg;
-+
-+        attachDebugger();
-+    }
-+
-+    private void setupJVMLibNamesBsd() {
-+        jvmLibNames = new String[] { "libjvm.so", "libjvm_g.so" };
-+    }
-+
-     /** Convenience routine which should be called by per-platform
-       debugger setup. Should not be called when startupMode is
-       REMOTE_MODE. */
---- hotspot/agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java
-+++ hotspot/agent/src/share/classes/sun/jvm/hotspot/bugspot/BugSpotAgent.java
-@@ -29,6 +29,7 @@
- import java.rmi.*;
- import sun.jvm.hotspot.*;
- import sun.jvm.hotspot.debugger.*;
-+import sun.jvm.hotspot.debugger.bsd.*;
- import sun.jvm.hotspot.debugger.dbx.*;
- import sun.jvm.hotspot.debugger.proc.*;
- import sun.jvm.hotspot.debugger.cdbg.*;
-@@ -516,6 +517,8 @@
-                 setupDebuggerWin32();
-             } else if (os.equals("linux")) {
-                 setupDebuggerLinux();
-+            } else if (os.equals("bsd")) {
-+                setupDebuggerBsd();
-             } else {
-                 // Add support for more operating systems here
-                 throw new DebuggerException("Operating system " + os + " not yet supported");
-@@ -567,6 +570,9 @@
-             } else if (os.equals("linux")) {
-                 db = new HotSpotTypeDataBase(machDesc, new LinuxVtblAccess(debugger, jvmLibNames),
-                 debugger, jvmLibNames);
-+            } else if (os.equals("bsd")) {
-+                db = new HotSpotTypeDataBase(machDesc, new BsdVtblAccess(debugger, jvmLibNames),
-+                debugger, jvmLibNames);
-             } else {
-                 throw new DebuggerException("OS \"" + os + "\" not yet supported (no VtblAccess implemented yet)");
-             }
-@@ -739,6 +745,8 @@
-             setupJVMLibNamesWin32();
-         } else if (os.equals("linux")) {
-             setupJVMLibNamesLinux();
-+        } else if (os.equals("bsd")) {
-+            setupJVMLibNamesBsd();
-         } else {
-             throw new RuntimeException("Unknown OS type");
-         }
-@@ -822,6 +830,34 @@
-         setupJVMLibNamesSolaris();
-     }
- 
-+    //
-+    // BSD
-+    //
-+
-+    private void setupDebuggerBsd() {
-+        setupJVMLibNamesBsd();
-+
-+        if (cpu.equals("x86")) {
-+            machDesc = new MachineDescriptionIntelX86();
-+        } else if (cpu.equals("amd64")) {
-+            machDesc = new MachineDescriptionAMD64();
-+        } else {
-+            throw new DebuggerException("BSD only supported on x86/amd64");
-+        }
-+
-+        // Note we do not use a cache for the local debugger in server
-+        // mode; it will be taken care of on the client side (once remote
-+        // debugging is implemented).
-+
-+        debugger = new BsdDebuggerLocal(machDesc, !isServer);
-+        attachDebugger();
-+    }
-+
-+    private void setupJVMLibNamesBsd() {
-+        // same as solaris
-+        setupJVMLibNamesSolaris();
-+    }
-+
-     /** Convenience routine which should be called by per-platform
-       debugger setup. Should not be called when startupMode is
-       REMOTE_MODE. */
---- hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java
-+++ hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdCDebugger.java
-@@ -30,10 +30,8 @@
- import sun.jvm.hotspot.debugger.cdbg.*;
- import sun.jvm.hotspot.debugger.x86.*;
- import sun.jvm.hotspot.debugger.amd64.*;
--import sun.jvm.hotspot.debugger.sparc.*;
- import sun.jvm.hotspot.debugger.bsd.x86.*;
- import sun.jvm.hotspot.debugger.bsd.amd64.*;
--import sun.jvm.hotspot.debugger.bsd.sparc.*;
- import sun.jvm.hotspot.utilities.*;
- 
- class BsdCDebugger implements CDebugger {
-@@ -99,13 +97,6 @@
-        Address pc  = context.getRegisterAsAddress(AMD64ThreadContext.RIP);
-        if (pc == null) return null;
-        return new BsdAMD64CFrame(dbg, rbp, pc);
--    } else if (cpu.equals("sparc")) {
--       SPARCThreadContext context = (SPARCThreadContext) thread.getContext();
--       Address sp = context.getRegisterAsAddress(SPARCThreadContext.R_SP);
--       if (sp == null) return null;
--       Address pc  = context.getRegisterAsAddress(SPARCThreadContext.R_O7);
--       if (pc == null) return null;
--       return new BsdSPARCCFrame(dbg, sp, pc, BsdDebuggerLocal.getAddressSize());
-     } else {
-        throw new DebuggerException(cpu + " is not yet supported");
-     }
---- hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThreadContextFactory.java
-+++ hotspot/agent/src/share/classes/sun/jvm/hotspot/debugger/bsd/BsdThreadContextFactory.java
-@@ -26,9 +26,7 @@
- 
- import sun.jvm.hotspot.debugger.*;
- import sun.jvm.hotspot.debugger.bsd.amd64.*;
--import sun.jvm.hotspot.debugger.bsd.ia64.*;
- import sun.jvm.hotspot.debugger.bsd.x86.*;
--import sun.jvm.hotspot.debugger.bsd.sparc.*;
- 
- class BsdThreadContextFactory {
-    static ThreadContext createThreadContext(BsdDebugger dbg) {
-@@ -37,10 +35,6 @@
-          return new BsdX86ThreadContext(dbg);
-       } else if (cpu.equals("amd64")) {
-          return new BsdAMD64ThreadContext(dbg);
--      } else if (cpu.equals("ia64")) {
--         return new BsdIA64ThreadContext(dbg);
--      } else if (cpu.equals("sparc")) {
--         return new BsdSPARCThreadContext(dbg);
-       } else {
-          throw new RuntimeException("cpu " + cpu + " is not yet supported");
-       }
 --- hotspot/agent/src/share/classes/sun/jvm/hotspot/jdi/ConnectorImpl.java
 +++ hotspot/agent/src/share/classes/sun/jvm/hotspot/jdi/ConnectorImpl.java
 @@ -217,7 +217,7 @@
@@ -2760,9 +539,9 @@
      }
  
      protected void checkNativeLink(SecurityManager sm, String os) {
--        if (os.equals("SunOS") || os.equals("Linux")) {
-+        if (os.equals("SunOS") || os.equals("Linux") || os.equals("MidnightBSD")) {
-             // link "saproc" - SA native library on SunOS and Linux?
+-        if (os.equals("SunOS") || os.equals("Linux") || os.contains("OS X")) {
++        if (os.equals("SunOS") || os.equals("Linux") || os.equals("MidnightBSD") || os.contains("OS X")) {
+             // link "saproc" - SA native library on SunOS, Linux, and Mac OS X
              sm.checkLink("saproc");
          } else if (os.startsWith("Windows")) {
 --- hotspot/agent/src/share/classes/sun/jvm/hotspot/jdi/SAPIDAttachingConnector.java
@@ -2776,1335 +555,552 @@
                      // Whether the caller can read /proc/<pid> file?
                      sm.checkRead("/proc/" + pid);
                  }
---- hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java
-+++ hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/Threads.java
-@@ -37,6 +37,8 @@
- import sun.jvm.hotspot.runtime.linux_ia64.LinuxIA64JavaThreadPDAccess;
- import sun.jvm.hotspot.runtime.linux_amd64.LinuxAMD64JavaThreadPDAccess;
- import sun.jvm.hotspot.runtime.linux_sparc.LinuxSPARCJavaThreadPDAccess;
-+import sun.jvm.hotspot.runtime.bsd_x86.BsdX86JavaThreadPDAccess;
-+import sun.jvm.hotspot.runtime.bsd_amd64.BsdAMD64JavaThreadPDAccess;
- import sun.jvm.hotspot.utilities.*;
- 
- public class Threads {
-@@ -90,7 +92,12 @@
-             } else if (cpu.equals("sparc")) {
-                 access = new LinuxSPARCJavaThreadPDAccess();
-             }
--
-+        } else if (os.equals("bsd")) {
-+            if (cpu.equals("x86")) {
-+                access = new BsdX86JavaThreadPDAccess();
-+            } else if (cpu.equals("amd64")) {
-+                access = new BsdAMD64JavaThreadPDAccess();
-+            }
-         }
- 
-         if (access == null) {
---- hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd/BsdSignals.java
-+++ hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd/BsdSignals.java
-@@ -28,37 +28,36 @@
-   private static String[] signalNames = {
-     "",           /* No signal 0 */
-     "SIGHUP",     /* hangup */
--    "SIGINT",     /* interrupt (rubout) */
--    "SIGQUIT",    /* quit (ASCII FS) */
--    "SIGILL",     /* illegal instruction (not reset when caught) */
-+    "SIGINT",     /* interrupt */
-+    "SIGQUIT",    /* quit */
-+    "SIGILL",     /* illegal instr. (not reset when caught) */
-     "SIGTRAP",    /* trace trap (not reset when caught) */
--    "SIGABRT",    /* used by abort, replace SIGIOT in the future */
--    "SIGIOT",
--    "SIGBUS",
-+    "SIGABRT",    /* abort() */
-+    "SIGEMT",     /* EMT instruction */
-     "SIGFPE",     /* floating point exception */
-     "SIGKILL",    /* kill (cannot be caught or ignored) */
--    "SIGUSR1",    /* user defined signal 1 */
-+    "SIGBUS",     /* bus error */
-     "SIGSEGV",    /* segmentation violation */
--    "SIGUSR2",    /* user defined signal 2 */
-+    "SIGSYS",     /* non-existent system call invoked */
-     "SIGPIPE",    /* write on a pipe with no one to read it */
-     "SIGALRM",    /* alarm clock */
-     "SIGTERM",    /* software termination signal from kill */
--    "SIGSTKFLT",
--    "SIGCHLD",    /* child status change alias */
--    "SIGCONT",    /* stopped process has been continued */
--    "SIGSTOP",    /* stop (cannot be caught or ignored) */
--    "SIGTSTP",    /* user stop requested from tty */
--    "SIGTTIN",    /* background tty read attempted */
--    "SIGTTOU",    /* background tty write attempted */
--    "SIGURG",     /* urgent socket condition */
--    "SIGXCPU",    /* exceeded cpu limit */
-+    "SIGURG",     /* urgent condition on IO channel */
-+    "SIGSTOP",    /* sendable stop signal not from tty */
-+    "SIGTSTP",    /* stop signal from tty */
-+    "SIGCONT",    /* continue a stopped process */
-+    "SIGCHLD",    /* to parent on child stop or exit */
-+    "SIGTTIN",    /* to readers pgrp upon background tty read */
-+    "SIGTTOU",    /* like TTIN if (tp->t_local&LTOSTOP) */
-+    "SIGIO",      /* input/output possible signal */
-+    "SIGXCPU",    /* exceeded CPU time limit */
-     "SIGXFSZ",    /* exceeded file size limit */
--    "SIGVTALRM",  /* virtual timer expired */
--    "SIGPROF",    /* profiling timer expired */
--    "SIGWINCH",   /* window size change */
--    "SIGPOLL",    /* pollable event occured */
--    "SIGPWR",     /* power-fail restart */
--    "SIGSYS"
-+    "SIGVTALRM",  /* virtual time alarm */
-+    "SIGPROF",    /* profiling time alarm */
-+    "SIGWINCH",   /* window size changes */
-+    "SIGINFO",    /* information request */
-+    "SIGUSR1",    /* user defined signal 1 */
-+    "SIGUSR2"     /* user defined signal 2 */
-   };
- 
-   public static String getSignalName(int sigNum) {
---- hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdSignals.java
-+++ hotspot/agent/src/share/classes/sun/jvm/hotspot/runtime/bsd_x86/BsdSignals.java
-@@ -28,37 +28,36 @@
-   private static String[] signalNames = {
-     "",           /* No signal 0 */
-     "SIGHUP",     /* hangup */
--    "SIGINT",     /* interrupt (rubout) */
--    "SIGQUIT",    /* quit (ASCII FS) */
--    "SIGILL",     /* illegal instruction (not reset when caught) */
-+    "SIGINT",     /* interrupt */
-+    "SIGQUIT",    /* quit */
-+    "SIGILL",     /* illegal instr. (not reset when caught) */
-     "SIGTRAP",    /* trace trap (not reset when caught) */
--    "SIGABRT",    /* used by abort, replace SIGIOT in the future */
--    "SIGIOT",
--    "SIGBUS",
-+    "SIGABRT",    /* abort() */
-+    "SIGEMT",     /* EMT instruction */
-     "SIGFPE",     /* floating point exception */
-     "SIGKILL",    /* kill (cannot be caught or ignored) */
--    "SIGUSR1",    /* user defined signal 1 */
-+    "SIGBUS",     /* bus error */
-     "SIGSEGV",    /* segmentation violation */
--    "SIGUSR2",    /* user defined signal 2 */
-+    "SIGSYS",     /* non-existent system call invoked */
-     "SIGPIPE",    /* write on a pipe with no one to read it */
-     "SIGALRM",    /* alarm clock */
-     "SIGTERM",    /* software termination signal from kill */
--    "SIGSTKFLT",
--    "SIGCHLD",    /* child status change alias */
--    "SIGCONT",    /* stopped process has been continued */
--    "SIGSTOP",    /* stop (cannot be caught or ignored) */
--    "SIGTSTP",    /* user stop requested from tty */
--    "SIGTTIN",    /* background tty read attempted */
--    "SIGTTOU",    /* background tty write attempted */
--    "SIGURG",     /* urgent socket condition */
--    "SIGXCPU",    /* exceeded cpu limit */
-+    "SIGURG",     /* urgent condition on IO channel */
-+    "SIGSTOP",    /* sendable stop signal not from tty */
-+    "SIGTSTP",    /* stop signal from tty */
-+    "SIGCONT",    /* continue a stopped process */
-+    "SIGCHLD",    /* to parent on child stop or exit */
-+    "SIGTTIN",    /* to readers pgrp upon background tty read */
-+    "SIGTTOU",    /* like TTIN if (tp->t_local&LTOSTOP) */
-+    "SIGIO",      /* input/output possible signal */
-+    "SIGXCPU",    /* exceeded CPU time limit */
-     "SIGXFSZ",    /* exceeded file size limit */
--    "SIGVTALRM",  /* virtual timer expired */
--    "SIGPROF",    /* profiling timer expired */
--    "SIGWINCH",   /* window size change */
--    "SIGPOLL",    /* pollable event occured */
--    "SIGPWR",     /* power-fail restart */
--    "SIGSYS"
-+    "SIGVTALRM",  /* virtual time alarm */
-+    "SIGPROF",    /* profiling time alarm */
-+    "SIGWINCH",   /* window size changes */
-+    "SIGINFO",    /* information request */
-+    "SIGUSR1",    /* user defined signal 1 */
-+    "SIGUSR2"     /* user defined signal 2 */
-   };
- 
-   public static String getSignalName(int sigNum) {
---- hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java
-+++ hotspot/agent/src/share/classes/sun/jvm/hotspot/utilities/PlatformInfo.java
-@@ -37,6 +37,14 @@
-       return "solaris";
-     } else if (os.equals("Linux")) {
-       return "linux";
-+    } else if (os.equals("MidnightBSD")) {
-+      return "bsd";
-+    } else if (os.equals("NetBSD")) {
-+      return "bsd";
-+    } else if (os.equals("OpenBSD")) {
-+      return "bsd";
-+    } else if (os.equals("Darwin")) {
-+      return "bsd";
-     } else if (os.startsWith("Windows")) {
-       return "win32";
-     } else {
---- hotspot/make/Makefile
-+++ hotspot/make/Makefile
-@@ -321,28 +321,28 @@
- ifneq ($(OSNAME),windows)
-   ifeq ($(ZERO_BUILD), true)
-     ifeq ($(SHARK_BUILD), true)
--$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(SHARK_DIR)/%.so
-+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(SHARK_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
--$(EXPORT_SERVER_DIR)/%.so:       $(SHARK_DIR)/%.so
-+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(SHARK_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
-     else
--$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(ZERO_DIR)/%.so
-+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(ZERO_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
--$(EXPORT_SERVER_DIR)/%.so:       $(ZERO_DIR)/%.so
-+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(ZERO_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
-     endif
-   else
--$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(C1_DIR)/%.so
-+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(C1_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
--$(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(C2_DIR)/%.so
-+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(C2_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
--$(EXPORT_CLIENT_DIR)/%.so:       $(C1_DIR)/%.so
-+$(EXPORT_CLIENT_DIR)/%.$(LIBRARY_SUFFIX):       $(C1_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
--$(EXPORT_CLIENT_DIR)/64/%.so:    $(C1_DIR)/%.so
-+$(EXPORT_CLIENT_DIR)/64/%.$(LIBRARY_SUFFIX):    $(C1_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
--$(EXPORT_SERVER_DIR)/%.so:       $(C2_DIR)/%.so
-+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(C2_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
--$(EXPORT_SERVER_DIR)/64/%.so:    $(C2_DIR)/%.so
-+$(EXPORT_SERVER_DIR)/64/%.$(LIBRARY_SUFFIX):    $(C2_DIR)/%.$(LIBRARY_SUFFIX)
- 	$(install-file)
-   endif
- endif
---- hotspot/make/bsd/Makefile
-+++ hotspot/make/bsd/Makefile
-@@ -230,7 +230,8 @@
- # Solaris 2.5.1, 2.6).
- # Disable this check by setting DISABLE_HOTSPOT_OS_VERSION_CHECK=ok.
- 
--SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3%
-+#SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 3%
-+DISABLE_HOTSPOT_OS_VERSION_CHECK = ok
- OS_VERSION := $(shell uname -r)
- EMPTY_IF_NOT_SUPPORTED = $(filter $(SUPPORTED_OS_VERSION),$(OS_VERSION))
- 
 --- hotspot/make/bsd/makefiles/adlc.make
 +++ hotspot/make/bsd/makefiles/adlc.make
-@@ -60,7 +60,8 @@
- 
+@@ -69,7 +69,7 @@
  # CFLAGS_WARN holds compiler options to suppress/enable warnings.
  # Compiler warnings are treated as errors
--CFLAGS_WARN = -Werror
-+WARNINGS_ARE_ERRORS ?= -Werror
-+CFLAGS_WARN = $(WARNINGS_ARE_ERRORS)
+ ifneq ($(COMPILER_WARNINGS_FATAL),false)
+-  CFLAGS_WARN = -Werror
++  CFLAGS_WARN = $(WARNINGS_ARE_ERRORS)
+ endif
  CFLAGS += $(CFLAGS_WARN)
  
- OBJECTNAMES = \
---- hotspot/make/bsd/makefiles/buildtree.make
-+++ hotspot/make/bsd/makefiles/buildtree.make
-@@ -303,10 +303,11 @@
- 	[ -n "$$JAVA_HOME" ] && { echo ": \$${JAVA_HOME:=$${JAVA_HOME}}"; }; \
- 	{ \
- 	echo "LD_LIBRARY_PATH=.:$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}\$${JAVA_HOME}/jre/lib/${LIBARCH}/native_threads:\$${JAVA_HOME}/jre/lib/${LIBARCH}:${GCC_LIB}"; \
-+	echo "DYLD_LIBRARY_PATH=.:$${DYLD_LIBRARY_PATH:+$$DYLD_LIBRARY_PATH:}\$${JAVA_HOME}/jre/lib/${LIBARCH}/native_threads:\$${JAVA_HOME}/jre/lib/${LIBARCH}:${GCC_LIB}"; \
- 	echo "CLASSPATH=$${CLASSPATH:+$$CLASSPATH:}.:\$${JAVA_HOME}/jre/lib/rt.jar:\$${JAVA_HOME}/jre/lib/i18n.jar"; \
- 	} | sed s:$${JAVA_HOME:--------}:\$${JAVA_HOME}:g; \
- 	echo "HOTSPOT_BUILD_USER=\"$${LOGNAME:-$$USER} in `basename $(GAMMADIR)`\""; \
--	echo "export JAVA_HOME LD_LIBRARY_PATH CLASSPATH HOTSPOT_BUILD_USER"; \
-+	echo "export JAVA_HOME LD_LIBRARY_PATH DYLD_LIBRARY_PATH CLASSPATH HOTSPOT_BUILD_USER"; \
- 	) > $@
+--- hotspot/make/bsd/makefiles/build_vm_def.sh
++++ hotspot/make/bsd/makefiles/build_vm_def.sh
+@@ -7,6 +7,10 @@
+ NM=nm
+ fi
  
- env.csh: env.sh
---- hotspot/make/bsd/makefiles/cscope.make
-+++ hotspot/make/bsd/makefiles/cscope.make
-@@ -71,7 +71,7 @@
- # OS-specific files for other systems are excluded by default.  Use CS_OS=yes
- # to include platform-specific files for other platforms.
- ifndef	CS_OS
--CS_OS		= bsd macos solaris win32
-+CS_OS		= linux macos solaris win32 bsd
- CS_PRUNE_OS	= $(patsubst %,-o -name '*%*',$(filter-out ${OS},${CS_OS}))
- endif
- 
---- hotspot/make/bsd/makefiles/defs.make
-+++ hotspot/make/bsd/makefiles/defs.make
-@@ -72,8 +72,8 @@
-   HS_ARCH            = sparc
- endif
- 
--# x86_64
--ifeq ($(ARCH), x86_64) 
-+# amd64
-+ifeq ($(ARCH), amd64) 
-   ifeq ($(ARCH_DATA_MODEL), 64)
-     ARCH_DATA_MODEL = 64
-     MAKE_ARGS       += LP64=1
-@@ -85,17 +85,27 @@
-     PLATFORM        = bsd-i586
-     VM_PLATFORM     = bsd_i486
-     HS_ARCH         = x86
--    # We have to reset ARCH to i686 since SRCARCH relies on it
--    ARCH            = i686   
-+    # We have to reset ARCH to i386 since SRCARCH relies on it
-+    ARCH            = i386   
-   endif
- endif
- 
--# i686
--ifeq ($(ARCH), i686)
--  ARCH_DATA_MODEL  = 32
--  PLATFORM         = bsd-i586
--  VM_PLATFORM      = bsd_i486
--  HS_ARCH          = x86
-+# i386
-+ifeq ($(ARCH), i386)
-+  ifeq ($(ARCH_DATA_MODEL), 64)
-+    ARCH_DATA_MODEL = 64
-+    MAKE_ARGS       += LP64=1
-+    PLATFORM        = bsd-amd64
-+    VM_PLATFORM     = bsd_amd64
-+    HS_ARCH         = x86
-+    # We have to reset ARCH to amd64 since SRCARCH relies on it
-+    ARCH            = amd64
-+  else
-+    ARCH_DATA_MODEL  = 32
-+    PLATFORM         = bsd-i586
-+    VM_PLATFORM      = bsd_i486
-+    HS_ARCH          = x86
-+  endif
- endif
- 
- # ARM
-@@ -116,39 +126,45 @@
- 
- JDK_INCLUDE_SUBDIR=bsd
- 
-+# Library suffix
-+OS_VENDOR:=$(shell uname -s)
-+ifeq ($(OS_VENDOR),Darwin)
-+  LIBRARY_SUFFIX=dylib
-+else
-+  LIBRARY_SUFFIX=so
-+endif
-+
- # FIXUP: The subdirectory for a debug build is NOT the same on all platforms
- VM_DEBUG=jvmg
- 
- EXPORT_LIST += $(EXPORT_DOCS_DIR)/platform/jvmti/jvmti.html
- 
- # client and server subdirectories have symbolic links to ../libjsig.so
--EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.so
-+EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libjsig.$(LIBRARY_SUFFIX)
- EXPORT_SERVER_DIR = $(EXPORT_JRE_LIB_ARCH_DIR)/server
- 
- ifndef BUILD_CLIENT_ONLY
- EXPORT_LIST += $(EXPORT_SERVER_DIR)/Xusage.txt
--EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.so
-+EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.$(LIBRARY_SUFFIX)
- endif
- 
- ifneq ($(ZERO_BUILD), true)
-   ifeq ($(ARCH_DATA_MODEL), 32)
-     EXPORT_CLIENT_DIR = $(EXPORT_JRE_LIB_ARCH_DIR)/client
-     EXPORT_LIST += $(EXPORT_CLIENT_DIR)/Xusage.txt
--    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.so 
-+    EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.$(LIBRARY_SUFFIX)
-   endif
- endif
- 
- # Serviceability Binaries
- # No SA Support for PPC, IA64, ARM or zero
--ADD_SA_BINARIES/x86   = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.so \
--                        $(EXPORT_LIB_DIR)/sa-jdi.jar 
--ADD_SA_BINARIES/sparc = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.so \
--                        $(EXPORT_LIB_DIR)/sa-jdi.jar 
--ADD_SA_BINARIES/ppc   = 
--ADD_SA_BINARIES/ia64  = 
--ADD_SA_BINARIES/arm   = 
--ADD_SA_BINARIES/zero  = 
-+ADD_SA_BINARIES/x86   = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
-+                        $(EXPORT_LIB_DIR)/sa-jdi.jar
-+ADD_SA_BINARIES/sparc = $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.$(LIBRARY_SUFFIX) \
-+                        $(EXPORT_LIB_DIR)/sa-jdi.jar
-+ADD_SA_BINARIES/ppc   =
-+ADD_SA_BINARIES/ia64  =
-+ADD_SA_BINARIES/arm   =
-+ADD_SA_BINARIES/zero  =
- 
- EXPORT_LIST += $(ADD_SA_BINARIES/$(HS_ARCH))
--
--
+-$NM --defined-only $* | awk '
+-   { if ($3 ~ /^_ZTV/ || $3 ~ /^gHotSpotVM/) print "\t" $3 ";" }
+-   '
++$NM --defined-only $* \
++    | awk '{
++              if ($3 ~ /^_ZTV/ || $3 ~ /^gHotSpotVM/) print "\t" $3 ";"
++              if ($3 ~ /^UseSharedSpaces$/) print "\t" $3 ";"
++              if ($3 ~ /^_ZN9Arguments17SharedArchivePathE$/) print "\t" $3 ";"
++          }' \
++    | sort -u
 --- hotspot/make/bsd/makefiles/gcc.make
 +++ hotspot/make/bsd/makefiles/gcc.make
-@@ -22,20 +22,24 @@
- #  
- #
- 
-+OS_VENDOR = $(shell uname -s)
-+
- #------------------------------------------------------------------------
- # CC, CPP & AS
- 
- # When cross-compiling the ALT_COMPILER_PATH points
- # to the cross-compilation toolset
- ifdef CROSS_COMPILE_ARCH
-+CXX = $(ALT_COMPILER_PATH)/g++
- CPP = $(ALT_COMPILER_PATH)/g++
- CC  = $(ALT_COMPILER_PATH)/gcc
- else
--CPP = g++
--CC  = gcc
-+CXX ?= g++
-+CPP = $(CXX)
-+CC  ?= gcc
+@@ -35,8 +35,8 @@
+  HOSTCXX = g++
+  HOSTCC  = gcc
+ else ifneq ($(OS_VENDOR), Darwin)
+- CXX = g++
+- CC  = gcc
++ CXX ?= g++
++ CC  ?= gcc
+  HOSTCXX = $(CXX)
+  HOSTCC  = $(CC)
  endif
- 
--AS  = $(CC) -c
-+AS   = $(CC) -c -x assembler-with-cpp
- 
- # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only
- # prints the numbers (e.g. "2.95", "3.2.1")
-@@ -73,7 +77,7 @@
+@@ -110,12 +110,16 @@
  CFLAGS += $(VM_PICFLAG)
  CFLAGS += -fno-rtti
  CFLAGS += -fno-exceptions
--CFLAGS += -D_REENTRANT
-+CFLAGS += -pthread
- CFLAGS += -fcheck-new
+-CFLAGS += -pthread
+-CFLAGS += -fcheck-new
+-# version 4 and above support fvisibility=hidden (matches jni_x86.h file)
+-# except 4.1.2 gives pointless warnings that can't be disabled (afaik)
+-ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
+-CFLAGS += -fvisibility=hidden
++CFLAGS += -D_REENTRANT
++ifeq ($(USE_CLANG),)
++ CFLAGS += -fcheck-new
++ # version 4 and above support fvisibility=hidden (matches jni_x86.h file)
++ # except 4.1.2 gives pointless warnings that can't be disabled (afaik)
++ ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
++  CFLAGS += -fvisibility=hidden
++ endif
++else
++ CFLAGS += -fvisibility=hidden
+ endif
  
  ARCHFLAG = $(ARCHFLAG/$(BUILDARCH))
-@@ -82,10 +86,12 @@
- ARCHFLAG/ia64    =
- ARCHFLAG/sparc   = -m32 -mcpu=v9
- ARCHFLAG/sparcv9 = -m64 -mcpu=v9
--ARCHFLAG/arm     =  -fsigned-char
- ARCHFLAG/zero    = $(ZERO_ARCHFLAG)
--ifndef E500V2
--ARCHFLAG/ppc     =  -mcpu=powerpc
-+
-+# Darwin-specific build flags
-+ifeq ($(OS_VENDOR), Darwin)
-+  # Ineffecient 16-byte stack re-alignment on Darwin/IA32
-+  ARCHFLAG/i486 += -mstackrealign
+@@ -163,14 +167,24 @@
+   WARNINGS_ARE_ERRORS = -Werror
  endif
  
- CFLAGS     += $(ARCHFLAG)
-@@ -115,7 +121,7 @@
+-# Except for a few acceptable ones
+-# Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit
+-# conversions which might affect the values. To avoid that, we need to turn
+-# it off explicitly. 
+-ifneq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
++ifeq ($(USE_CLANG), true)
++  # However we need to clean the code up before we can unrestrictedly enable this option with Clang
++  WARNINGS_ARE_ERRORS += -Wno-logical-op-parentheses -Wno-parentheses-equality -Wno-parentheses
++  WARNINGS_ARE_ERRORS += -Wno-switch -Wno-tautological-compare
++# Not yet supported by clang in Xcode 4.6.2
++# WARNINGS_ARE_ERRORS += -Wno-tautological-constant-out-of-range-compare
++  WARNINGS_ARE_ERRORS += -Wno-delete-non-virtual-dtor -Wno-deprecated -Wno-format -Wno-dynamic-class-memaccess
++  WARNINGS_ARE_ERRORS += -Wno-return-type -Wno-empty-body
++endif 
++
+ ACCEPTABLE_WARNINGS = -Wpointer-arith -Wsign-compare
+-else
+-ACCEPTABLE_WARNINGS = -Wpointer-arith -Wconversion -Wsign-compare
++
++ifeq "$(shell expr \( $(CC_VER_MAJOR) \> 4 \) \| \( \( $(CC_VER_MAJOR) = 4 \) \& \( $(CC_VER_MINOR) \>= 3 \) \))" "0"
++  # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit
++  # conversions which might affect the values. Only enable it in earlier versions.
++  ifeq ($(USE_CLANG),)
++    ACCEPTABLE_WARNINGS += -Wconversion
++  endif
  endif
  
- # Compiler warnings are treated as errors
--WARNINGS_ARE_ERRORS = -Werror
-+WARNINGS_ARE_ERRORS ?= -Werror
- 
- # Except for a few acceptable ones
- # Since GCC 4.3, -Wconversion has changed its meanings to warn these implicit
-@@ -130,6 +136,11 @@
  CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ACCEPTABLE_WARNINGS)
- # Special cases
- CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@)) 
-+# XXXDARWIN: for _dyld_bind_fully_image_containing_address
-+ifeq ($(OS_VENDOR), Darwin)
-+  CFLAGS_WARN/os_bsd.o = $(CFLAGS_WARN/DEFAULT) -Wno-deprecated-declarations
-+endif
-+
- 
- # The flags to use for an Optimized g++ build
- OPT_CFLAGS += -O3
-@@ -175,28 +186,40 @@
- LFLAGS += -Wl,-relax
+@@ -282,7 +296,11 @@
+ DEBUG_CFLAGS/ppc   = -g
+ DEBUG_CFLAGS += $(DEBUG_CFLAGS/$(BUILDARCH))
+ ifeq ($(DEBUG_CFLAGS/$(BUILDARCH)),)
+-DEBUG_CFLAGS += -gstabs
++  ifeq ($(USE_CLANG), true)
++    DEBUG_CFLAGS += -g
++  else
++    DEBUG_CFLAGS += -gstabs
++  endif
  endif
  
--# Enable linker optimization
--LFLAGS += -Xlinker -O1
--
--# If this is a --hash-style=gnu system, use --hash-style=both
--#   The gnu .hash section won't work on some Bsd systems like SuSE 10.
--_HAS_HASH_STYLE_GNU:=$(shell $(CC) -dumpspecs | grep -- '--hash-style=gnu')
--ifneq ($(_HAS_HASH_STYLE_GNU),)
--  LDFLAGS_HASH_STYLE = -Wl,--hash-style=both
--endif
--LFLAGS += $(LDFLAGS_HASH_STYLE)
--
- # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file.
- MAPFLAG = -Xlinker --version-script=FILENAME
- 
--# Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
--SONAMEFLAG = -Xlinker -soname=SONAME
-+#
-+# Shared Library
-+#
-+ifeq ($(OS_VENDOR), Darwin)
-+  # Standard linker flags
-+  LFLAGS +=
-+
-+  # Darwin doesn't use ELF and doesn't support version scripts
-+  LDNOMAP = true
-+
-+  # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
-+  SONAMEFLAG =
-+
-+  # Build shared library
-+  SHARED_FLAG = -dynamiclib $(VM_PICFLAG)
- 
--# Build shared library
--SHARED_FLAG = -shared
-+  # Keep symbols even they are not used
-+  #AOUT_FLAGS += -export-dynamic
-+else
-+  # Enable linker optimization
-+  LFLAGS += -Xlinker -O1
-+
-+  # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
-+  SONAMEFLAG = -Xlinker -soname=SONAME
- 
--# Keep symbols even they are not used
--AOUT_FLAGS += -export-dynamic
-+  # Build shared library
-+  SHARED_FLAG = -shared $(VM_PICFLAG)
-+
-+  # Keep symbols even they are not used
-+  AOUT_FLAGS += -export-dynamic
-+endif
- 
- #------------------------------------------------------------------------
- # Debug flags
+ # DEBUG_BINARIES overrides everything, use full -g debug information
 --- hotspot/make/bsd/makefiles/jsig.make
 +++ hotspot/make/bsd/makefiles/jsig.make
-@@ -25,11 +25,16 @@
- # Rules to build signal interposition library, used by vm.make
- 
- # libjsig[_g].so: signal interposition library
--JSIG = jsig
--LIBJSIG = lib$(JSIG).so
-+JSIG   = jsig
-+JSIG_G = $(JSIG)$(G_SUFFIX)
- 
--JSIG_G    = $(JSIG)$(G_SUFFIX)
--LIBJSIG_G = lib$(JSIG_G).so
-+ifeq ($(OS_VENDOR), Darwin)
-+  LIBJSIG   = lib$(JSIG).dylib
-+  LIBJSIG_G = lib$(JSIG_G).dylib
-+else
-+  LIBJSIG   = lib$(JSIG).so
-+  LIBJSIG_G = lib$(JSIG_G).so
-+endif
- 
- JSIGSRCDIR = $(GAMMADIR)/src/os/$(Platform_os_family)/vm
- 
-@@ -42,7 +47,7 @@
+@@ -47,7 +47,7 @@
  # cause problems with interposing. See CR: 6466665
  # LFLAGS_JSIG += $(MAPFLAG:FILENAME=$(LIBJSIG_MAPFILE))
  
--LFLAGS_JSIG += -D_GNU_SOURCE -D_REENTRANT $(LDFLAGS_HASH_STYLE)
-+LFLAGS_JSIG += -D_GNU_SOURCE -pthread $(LDFLAGS_HASH_STYLE)
+-LFLAGS_JSIG += -D_GNU_SOURCE -pthread $(LDFLAGS_HASH_STYLE)
++LFLAGS_JSIG += -D_GNU_SOURCE -D_REENTRANT $(LDFLAGS_HASH_STYLE)
  
  # DEBUG_BINARIES overrides everything, use full -g debug information
  ifeq ($(DEBUG_BINARIES), true)
-@@ -52,7 +57,7 @@
- $(LIBJSIG): $(JSIGSRCDIR)/jsig.c $(LIBJSIG_MAPFILE)
- 	@echo Making signal interposition lib...
- 	$(QUIETLY) $(CC) $(SYMFLAG) $(ARCHFLAG) $(SHARED_FLAG) $(PICFLAG) \
--                         $(LFLAGS_JSIG) $(JSIG_DEBUG_CFLAGS) -o $@ $< -ldl
-+                         $(LFLAGS_JSIG) $(JSIG_DEBUG_CFLAGS) -o $@ $<
- 	$(QUIETLY) [ -f $(LIBJSIG_G) ] || { ln -s $@ $(LIBJSIG_G); }
+--- hotspot/make/bsd/makefiles/mapfile-vers-debug
++++ hotspot/make/bsd/makefiles/mapfile-vers-debug
+@@ -1,8 +1,4 @@
+ #
+-# @(#)mapfile-vers-debug	1.18 07/10/25 16:47:35
+-#
+-
+-#
+ # Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ #
+@@ -88,7 +84,7 @@
+                 JVM_EnableCompiler;
+                 JVM_Exit;
+                 JVM_FillInStackTrace;
+-                JVM_FindClassFromCaller
++                JVM_FindClassFromCaller;
+                 JVM_FindClassFromClass;
+                 JVM_FindClassFromClassLoader;
+                 JVM_FindClassFromBootLoader;
+@@ -222,6 +218,7 @@
+                 JVM_SetArrayElement;
+                 JVM_SetClassSigners;
+                 JVM_SetLength;
++                JVM_SetNativeThreadName;
+                 JVM_SetPrimitiveArrayElement;
+                 JVM_SetProtectionDomain;
+                 JVM_SetSockOpt;
+@@ -245,24 +242,6 @@
+                 JVM_Yield;
+                 JVM_handle_bsd_signal;
  
- install_jsig: $(LIBJSIG)
---- hotspot/make/bsd/makefiles/launcher.make
-+++ hotspot/make/bsd/makefiles/launcher.make
-@@ -50,7 +50,7 @@
-   LIBS_LAUNCHER             += $(STATIC_STDCXX) $(LIBS)
- else
-   LAUNCHER.o                 = launcher.o
--  LFLAGS_LAUNCHER           += -L `pwd`
-+  LFLAGS_LAUNCHER           += -L`pwd`
-   LIBS_LAUNCHER             += -l$(JVM) $(LIBS)
- endif
- 
---- hotspot/make/bsd/makefiles/sa.make
-+++ hotspot/make/bsd/makefiles/sa.make
-@@ -45,8 +45,8 @@
- 
- # gnumake 3.78.1 does not accept the *s that
- # are in AGENT_FILES1 and AGENT_FILES2, so use the shell to expand them
--AGENT_FILES1 := $(shell /usr/bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES1))
--AGENT_FILES2 := $(shell /usr/bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES2))
-+AGENT_FILES1 := $(shell /bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES1))
-+AGENT_FILES2 := $(shell /bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_FILES2))
- 
- AGENT_FILES1_LIST := $(GENERATED)/agent1.classes.list
- AGENT_FILES2_LIST := $(GENERATED)/agent2.classes.list
---- hotspot/make/bsd/makefiles/saproc.make
-+++ hotspot/make/bsd/makefiles/saproc.make
-@@ -25,23 +25,33 @@
- # Rules to build serviceability agent library, used by vm.make
- 
- # libsaproc[_g].so: serviceability agent
+-                # Old reflection routines
+-                # These do not need to be present in the product build in JDK 1.4
+-                # but their code has not been removed yet because there will not
+-                # be a substantial code savings until JVM_InvokeMethod and
+-                # JVM_NewInstanceFromConstructor can also be removed; see
+-                # reflectionCompat.hpp.
+-                JVM_GetClassConstructor;
+-                JVM_GetClassConstructors;
+-                JVM_GetClassField;
+-                JVM_GetClassFields;
+-                JVM_GetClassMethod;
+-                JVM_GetClassMethods;
+-                JVM_GetField;
+-                JVM_GetPrimitiveField;
+-                JVM_NewInstance;
+-                JVM_SetField;
+-                JVM_SetPrimitiveField;
 -
--SAPROC = saproc
--LIBSAPROC = lib$(SAPROC).so
+                 # debug JVM
+                 JVM_AccessVMBooleanFlag;
+                 JVM_AccessVMIntFlag;
+--- hotspot/make/bsd/makefiles/mapfile-vers-product
++++ hotspot/make/bsd/makefiles/mapfile-vers-product
+@@ -1,8 +1,4 @@
+ #
+-# @(#)mapfile-vers-product	1.19 08/02/12 10:56:37
+-#
 -
-+SAPROC   = saproc
- SAPROC_G = $(SAPROC)$(G_SUFFIX)
--LIBSAPROC_G = lib$(SAPROC_G).so
-+
-+ifeq ($(OS_VENDOR), Darwin)
-+  LIBSAPROC   = lib$(SAPROC).dylib
-+  LIBSAPROC_G = lib$(SAPROC_G).dylib
-+else
-+  LIBSAPROC   = lib$(SAPROC).so
-+  LIBSAPROC_G = lib$(SAPROC_G).so
-+endif
+-#
+ # Copyright (c) 2002, 2014, Oracle and/or its affiliates. All rights reserved.
+ # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ #
+@@ -88,7 +84,7 @@
+                 JVM_EnableCompiler;
+                 JVM_Exit;
+                 JVM_FillInStackTrace;
+-                JVM_FindClassFromCaller
++                JVM_FindClassFromCaller;
+                 JVM_FindClassFromClass;
+                 JVM_FindClassFromClassLoader;
+                 JVM_FindClassFromBootLoader;
+@@ -222,6 +218,7 @@
+                 JVM_SetArrayElement;
+                 JVM_SetClassSigners;
+                 JVM_SetLength;
++                JVM_SetNativeThreadName;
+                 JVM_SetPrimitiveArrayElement;
+                 JVM_SetProtectionDomain;
+                 JVM_SetSockOpt;
+@@ -245,24 +242,6 @@
+                 JVM_Yield;
+                 JVM_handle_bsd_signal;
  
- AGENT_DIR = $(GAMMADIR)/agent
+-                # Old reflection routines
+-                # These do not need to be present in the product build in JDK 1.4
+-                # but their code has not been removed yet because there will not
+-                # be a substantial code savings until JVM_InvokeMethod and
+-                # JVM_NewInstanceFromConstructor can also be removed; see
+-                # reflectionCompat.hpp.
+-                JVM_GetClassConstructor;
+-                JVM_GetClassConstructors;
+-                JVM_GetClassField;
+-                JVM_GetClassFields;
+-                JVM_GetClassMethod;
+-                JVM_GetClassMethods;
+-                JVM_GetField;
+-                JVM_GetPrimitiveField;
+-                JVM_NewInstance;
+-                JVM_SetField;
+-                JVM_SetPrimitiveField;
+-
+                 # miscellaneous functions
+                 jio_fprintf;
+                 jio_printf;
+--- hotspot/make/bsd/makefiles/rules.make
++++ hotspot/make/bsd/makefiles/rules.make
+@@ -126,8 +126,8 @@
+ RUN.JAR$(MAKE_VERBOSE) += >/dev/null
  
- SASRCDIR = $(AGENT_DIR)/src/os/$(Platform_os_family)
+ # Settings for javac
+-BOOT_SOURCE_LANGUAGE_VERSION = 6
+-BOOT_TARGET_CLASS_VERSION = 6
++BOOT_SOURCE_LANGUAGE_VERSION = 5
++BOOT_TARGET_CLASS_VERSION = 5
+ JAVAC_FLAGS = -g -encoding ascii
+ BOOTSTRAP_JAVAC_FLAGS = $(JAVAC_FLAGS) -source $(BOOT_SOURCE_LANGUAGE_VERSION) -target $(BOOT_TARGET_CLASS_VERSION)
  
-+ifeq ($(OS_VENDOR), MidnightBSD)
- SASRCFILES = $(SASRCDIR)/salibelf.c                   \
-              $(SASRCDIR)/symtab.c                     \
-              $(SASRCDIR)/libproc_impl.c               \
-              $(SASRCDIR)/ps_proc.c                    \
-              $(SASRCDIR)/ps_core.c                    \
-              $(SASRCDIR)/BsdDebuggerLocal.c
-+SALIBS = -lutil -lthread_db
-+else
-+SASRCFILES = $(SASRCDIR)/StubDebuggerLocal.c
-+SALIBS = 
-+endif
+--- hotspot/src/cpu/x86/vm/assembler_x86.cpp
++++ hotspot/src/cpu/x86/vm/assembler_x86.cpp
+@@ -4087,7 +4087,7 @@
+ }
  
- SAMAPFILE = $(SASRCDIR)/mapfile
+ void Assembler::adcq(Register dst, Register src) {
+-  (int) prefixq_and_encode(dst->encoding(), src->encoding());
++  (void) prefixq_and_encode(dst->encoding(), src->encoding());
+   emit_arith(0x13, 0xC0, dst, src);
+ }
  
-@@ -62,7 +72,10 @@
- endif
+@@ -4142,7 +4142,7 @@
+ }
  
+ void Assembler::andq(Register dst, Register src) {
+-  (int) prefixq_and_encode(dst->encoding(), src->encoding());
++  (void) prefixq_and_encode(dst->encoding(), src->encoding());
+   emit_arith(0x23, 0xC0, dst, src);
+ }
  
--SA_LFLAGS = $(MAPFLAG:FILENAME=$(SAMAPFILE)) $(LDFLAGS_HASH_STYLE)
-+ifneq ($(OS_VENDOR), Darwin)
-+SA_LFLAGS = $(MAPFLAG:FILENAME=$(SAMAPFILE))
-+endif
-+SA_LFLAGS += $(LDFLAGS_HASH_STYLE)
+--- hotspot/src/cpu/x86/vm/globals_x86.hpp
++++ hotspot/src/cpu/x86/vm/globals_x86.hpp
+@@ -70,11 +70,7 @@
+ define_pd_global(bool, RewriteBytecodes,     true);
+ define_pd_global(bool, RewriteFrequentPairs, true);
  
- $(LIBSAPROC): $(SASRCFILES) $(SAMAPFILE)
- 	$(QUIETLY) if [ "$(BOOT_JAVA_HOME)" = "" ]; then \
-@@ -75,12 +88,12 @@
- 	           -I$(SASRCDIR)                                        \
- 	           -I$(GENERATED)                                       \
- 	           -I$(BOOT_JAVA_HOME)/include                          \
--	           -I$(BOOT_JAVA_HOME)/include/$(Platform_os_family)    \
-+	           -I$(BOOT_JAVA_HOME)/include/$(shell uname -s | tr "[:upper:]" "[:lower:]") \
- 	           $(SASRCFILES)                                        \
- 	           $(SA_LFLAGS)                                         \
- 	           $(SA_DEBUG_CFLAGS)                                   \
- 	           -o $@                                                \
--	           -lthread_db
-+	           $(SALIBS)
- 	$(QUIETLY) [ -f $(LIBSAPROC_G) ] || { ln -s $@ $(LIBSAPROC_G); }
+-#ifdef _ALLBSD_SOURCE
+-define_pd_global(bool, UseMembar,            true);
+-#else
+ define_pd_global(bool, UseMembar,            false);
+-#endif
  
- install_saproc: $(BUILDLIBSAPROC)
---- hotspot/make/bsd/makefiles/vm.make
-+++ hotspot/make/bsd/makefiles/vm.make
-@@ -91,6 +91,10 @@
-   ${JRE_VERSION}     \
-   ${VM_DISTRO}
- 
-+ifdef DEFAULT_LIBPATH
-+CPPFLAGS += -DDEFAULT_LIBPATH="\"$(DEFAULT_LIBPATH)\""
-+endif
-+
- # CFLAGS_WARN holds compiler options to suppress/enable warnings.
- CFLAGS += $(CFLAGS_WARN/BYFILE)
- 
-@@ -101,7 +105,7 @@
- CFLAGS += $(EXTRA_CFLAGS)
- LFLAGS += $(EXTRA_CFLAGS)
- 
--LIBS += -lm -ldl -lpthread
-+LIBS += -lm -pthread
- 
- # By default, link the *.o into the library, not the executable.
- LINK_INTO$(LINK_INTO) = LIBJVM
-@@ -115,9 +119,15 @@
- #----------------------------------------------------------------------
- # JVM
- 
--JVM      = jvm
--LIBJVM   = lib$(JVM).so
--LIBJVM_G = lib$(JVM)$(G_SUFFIX).so
-+JVM    = jvm
-+ifeq ($(OS_VENDOR), Darwin)
-+  LIBJVM   = lib$(JVM).dylib
-+  LIBJVM_G = lib$(JVM)$(G_SUFFIX).dylib
-+  CFLAGS  += -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE
-+else
-+  LIBJVM   = lib$(JVM).so
-+  LIBJVM_G = lib$(JVM)$(G_SUFFIX).so
-+endif
- 
- CORE_PATHS := $(shell find $(GAMMADIR)/src/share/vm/* -type d \! \( -name adlc -o -name c1 -o -name gc_implementation -o -name opto -o -name shark -o -name libadt \))
- CORE_PATHS += $(GAMMADIR)/src/os/$(Platform_os_family)/vm
-@@ -196,15 +206,7 @@
- vm.def: $(Res_Files) $(Obj_Files)
- 	sh $(GAMMADIR)/make/bsd/makefiles/build_vm_def.sh *.o > $@
- 
--ifeq ($(SHARK_BUILD), true)
--  STATIC_CXX = false
--else
--  ifeq ($(ZERO_LIBARCH), ppc64)
--    STATIC_CXX = false
--  else
--    STATIC_CXX = true
--  endif
--endif
-+STATIC_CXX = false
- 
- ifeq ($(LINK_INTO),AOUT)
-   LIBJVM.o                 =
-@@ -216,14 +218,21 @@
-   LFLAGS_VM$(LDNOMAP)      += $(MAPFLAG:FILENAME=$(LIBJVM_MAPFILE))
-   LFLAGS_VM                += $(SONAMEFLAG:SONAME=$(LIBJVM))
- 
-+  ifeq ($(OS_VENDOR), Darwin)
-+    LFLAGS_VM += -Xlinker -rpath -Xlinker @loader_path/.
-+    LFLAGS_VM += -Xlinker -rpath -Xlinker @loader_path/..
-+    LFLAGS_VM += -Xlinker -install_name -Xlinker @rpath/$(@F)
-+  endif
-+
-   # JVM is statically linked with libgcc[_s] and libstdc++; this is needed to
-   # get around library dependency and compatibility issues. Must use gcc not
-   # g++ to link.
-   ifeq ($(STATIC_CXX), true)
-     LFLAGS_VM              += $(STATIC_LIBGCC)
-     LIBS_VM                += $(STATIC_STDCXX)
-+    LINK_VM                = $(LINK_LIB.c)
-   else
--    LIBS_VM                += -lstdc++
-+    LINK_VM                = $(LINK_LIB.CC)
-   endif
- 
-   LIBS_VM                  += $(LIBS)
-@@ -236,7 +245,6 @@
-   LIBS_VM   += $(LLVM_LIBS)
- endif
- 
--LINK_VM = $(LINK_LIB.c)
- 
- # rule for building precompiled header
- $(PRECOMPILED_HEADER):
-@@ -264,11 +272,6 @@
- LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
- endif
- 
--# With more recent Redhat releases (or the cutting edge version Fedora), if
--# SEBsd is configured to be enabled, the runtime linker will fail to apply
--# the text relocation to libjvm.so considering that it is built as a non-PIC
--# DSO. To workaround that, we run chcon to libjvm.so after it is built. See 
--# details in bug 6538311.
- $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
- 	$(QUIETLY) {                                                    \
- 	    echo Linking vm...;                                         \
-@@ -278,17 +281,6 @@
- 	    $(LINK_LIB.CC/POST_HOOK)                                    \
- 	    rm -f $@.1; ln -s $@ $@.1;                                  \
- 	    [ -f $(LIBJVM_G) ] || { ln -s $@ $(LIBJVM_G); ln -s $@.1 $(LIBJVM_G).1; }; \
--            if [ \"$(CROSS_COMPILE_ARCH)\" = \"\" ] ; then                    \
--	      if [ -x /usr/sbin/sebsdenabled ] ; then                 \
--	        /usr/sbin/sebsdenabled;                               \
--                if [ $$? = 0 ] ; then					\
--		  /usr/bin/chcon -t textrel_shlib_t $@;                 \
--		  if [ $$? != 0 ]; then                                 \
--		    echo "ERROR: Cannot chcon $@";			\
--		  fi							\
--	        fi							\
--	      fi                                                        \
--            fi 								\
- 	}
- 
- DEST_JVM = $(JDK_LIBDIR)/$(VM_SUBDIR)/$(LIBJVM)
---- hotspot/make/bsd/platform_amd64
-+++ hotspot/make/bsd/platform_amd64
-@@ -12,4 +12,4 @@
- 
- compiler = gcc
- 
--sysdefs = -DBSD -D_GNU_SOURCE -DAMD64
-+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DAMD64
---- hotspot/make/bsd/platform_i486
-+++ hotspot/make/bsd/platform_i486
-@@ -12,4 +12,4 @@
- 
- compiler = gcc
- 
--sysdefs = -DBSD -D_GNU_SOURCE -DIA32
-+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DIA32
---- hotspot/make/defs.make
-+++ hotspot/make/defs.make
-@@ -118,13 +118,23 @@
- # Windows should have OS predefined
- ifeq ($(OS),)
-   OS   := $(shell uname -s)
-+  ifneq ($(findstring BSD,$(OS)),)
-+    OS=bsd
-+  endif
-+  ifeq ($(OS), Darwin)
-+    OS=bsd
-+  endif
-   HOST := $(shell uname -n)
- endif
- 
--# If not SunOS and not Linux, assume Windows
-+# If not SunOS, not Linux and not BSD, assume Windows
- ifneq ($(OS), Linux)
-   ifneq ($(OS), SunOS)
--    OSNAME=windows
-+    ifneq ($(OS), bsd)
-+      OSNAME=windows
-+    else
-+      OSNAME=bsd
-+    endif
-   else
-     OSNAME=solaris
-   endif
---- hotspot/make/sa.files
-+++ hotspot/make/sa.files
-@@ -50,6 +50,9 @@
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/compiler/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/amd64/*.java \
-+$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/bsd/*.java \
-+$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/bsd/amd64/*.java \
-+$(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/bsd/x86/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/debugger/cdbg/basic/x86/*.java \
-@@ -95,6 +98,9 @@
- AGENT_FILES2 = \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/amd64/*.java \
-+$(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/bsd/*.java \
-+$(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/bsd_amd64/*.java \
-+$(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/bsd_x86/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/ia64/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/linux/*.java \
- $(AGENT_SRC_DIR)/sun/jvm/hotspot/runtime/linux_amd64/*.java \
---- hotspot/src/cpu/x86/vm/bytes_x86.hpp
-+++ hotspot/src/cpu/x86/vm/bytes_x86.hpp
-@@ -81,6 +81,9 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "bytes_windows_x86.inline.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "bytes_bsd_x86.inline.hpp"
-+#endif
- 
- 
- #endif // CPU_X86_VM_BYTES_X86_HPP
---- hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp
-+++ hotspot/src/cpu/x86/vm/c1_LIRAssembler_x86.cpp
-@@ -481,8 +481,8 @@
-   // Fetch the exception from TLS and clear out exception related thread state
-   __ get_thread(rsi);
-   __ movptr(rax, Address(rsi, JavaThread::exception_oop_offset()));
--  __ movptr(Address(rsi, JavaThread::exception_oop_offset()), (int32_t)NULL_WORD);
--  __ movptr(Address(rsi, JavaThread::exception_pc_offset()), (int32_t)NULL_WORD);
-+  __ movptr(Address(rsi, JavaThread::exception_oop_offset()), (intptr_t)NULL_WORD);
-+  __ movptr(Address(rsi, JavaThread::exception_pc_offset()), (intptr_t)NULL_WORD);
- 
-   __ bind(_unwind_handler_entry);
-   __ verify_not_null_oop(rax);
---- hotspot/src/cpu/x86/vm/copy_x86.hpp
-+++ hotspot/src/cpu/x86/vm/copy_x86.hpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "copy_windows_x86.inline.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "copy_bsd_x86.inline.hpp"
-+#endif
- 
- 
- static void pd_fill_to_words(HeapWord* tohw, size_t count, juint value) {
---- hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp
-+++ hotspot/src/cpu/x86/vm/interp_masm_x86_32.cpp
-@@ -45,6 +45,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- 
- // Implementation of InterpreterMacroAssembler
-@@ -1170,7 +1173,7 @@
-   int recvr_offset = in_bytes(VirtualCallData::receiver_offset(start_row));
-   set_mdp_data_at(mdp, recvr_offset, receiver);
-   int count_offset = in_bytes(VirtualCallData::receiver_count_offset(start_row));
--  movptr(reg2, (int32_t)DataLayout::counter_increment);
-+  movptr(reg2, (intptr_t)DataLayout::counter_increment);
-   set_mdp_data_at(mdp, count_offset, reg2);
-   if (start_row > 0) {
-     jmp(done);
-@@ -1313,7 +1316,7 @@
-     test_method_data_pointer(mdp, profile_continue);
- 
-     // Build the base (index * per_case_size_in_bytes()) + case_array_offset_in_bytes()
--    movptr(reg2, (int32_t)in_bytes(MultiBranchData::per_case_size()));
-+    movptr(reg2, (intptr_t)in_bytes(MultiBranchData::per_case_size()));
-     // index is positive and so should have correct value if this code were
-     // used on 64bits
-     imulptr(index, reg2);
---- hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp
-+++ hotspot/src/cpu/x86/vm/interp_masm_x86_64.cpp
-@@ -45,6 +45,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- 
- // Implementation of InterpreterMacroAssembler
+ // GC Ergo Flags
+ define_pd_global(intx, CMSYoungGenPerWorker, 64*M);  // default max size of CMS young gen, per GC worker thread
 --- hotspot/src/cpu/x86/vm/jni_x86.h
 +++ hotspot/src/cpu/x86/vm/jni_x86.h
-@@ -26,7 +26,7 @@
- #ifndef _JAVASOFT_JNI_MD_H_
- #define _JAVASOFT_JNI_MD_H_
+@@ -28,7 +28,7 @@
  
--#if defined(SOLARIS) || defined(LINUX)
-+#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)
-   #define JNIEXPORT
-   #define JNIIMPORT
-   #define JNICALL
+ #if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)
+ 
+-#if defined(__GNUC__) && (__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2)
++#if defined(__clang__) || (defined(__GNUC__) && (__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ > 2))
+   #define JNIEXPORT     __attribute__((visibility("default")))
+   #define JNIIMPORT     __attribute__((visibility("default")))
+ #else
 --- hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp
 +++ hotspot/src/cpu/x86/vm/stubGenerator_x86_32.cpp
-@@ -47,6 +47,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifdef COMPILER2
- #include "opto/runtime.hpp"
- #endif
+@@ -94,7 +94,7 @@
+  private:
+ 
+ #ifdef PRODUCT
+-#define inc_counter_np(counter) (0)
++#define inc_counter_np(counter) ((void)0)
+ #else
+   void inc_counter_np_(int& counter) {
+     __ incrementl(ExternalAddress((address)&counter));
 --- hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
 +++ hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
-@@ -47,6 +47,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifdef COMPILER2
- #include "opto/runtime.hpp"
- #endif
---- hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp
-+++ hotspot/src/cpu/x86/vm/stubRoutines_x86_32.cpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+@@ -92,7 +92,7 @@
+  private:
  
- // Implementation of the platform-specific part of StubRoutines - for
- // a description of how to extend it, see the stubRoutines.hpp file.
---- hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp
-+++ hotspot/src/cpu/x86/vm/stubRoutines_x86_64.cpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+ #ifdef PRODUCT
+-#define inc_counter_np(counter) (0)
++#define inc_counter_np(counter) ((void)0)
+ #else
+   void inc_counter_np_(int& counter) {
+     // This can destroy rscratch1 if counter is far from the code cache
+--- hotspot/src/os/bsd/vm/globals_bsd.hpp
++++ hotspot/src/os/bsd/vm/globals_bsd.hpp
+@@ -26,25 +26,19 @@
+ #define OS_BSD_VM_GLOBALS_BSD_HPP
  
- // Implementation of the platform-specific part of StubRoutines - for
- // a description of how to extend it, see the stubRoutines.hpp file.
---- hotspot/src/cpu/x86/vm/vm_version_x86.cpp
-+++ hotspot/src/cpu/x86/vm/vm_version_x86.cpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+ //
+-// Defines Bsd specific flags. They are not available on other platforms.
++// Defines BSD specific flags. They are not available on other platforms.
+ //
+ #define RUNTIME_OS_FLAGS(develop, develop_pd, product, product_pd, diagnostic, notproduct) \
+   product(bool, UseOprofile, false,                                     \
+         "enable support for Oprofile profiler")                         \
+                                                                         \
+-  product(bool, UseBsdPosixThreadCPUClocks, true,                     \
+-          "enable fast Bsd Posix clocks where available")             \
+-/*  NB: The default value of UseBsdPosixThreadCPUClocks may be        \
+-    overridden in Arguments::parse_each_vm_init_arg.  */                \
+-                                                                        \
+-  product(bool, UseHugeTLBFS, false,                                    \
+-          "Use MAP_HUGETLB for large pages")                            \
+-                                                                        \
+-  product(bool, UseSHM, false,                                          \
+-          "Use SYSV shared memory for large pages")
++  product(bool, UseBsdPosixThreadCPUClocks, true,                       \
++          "enable fast BSD Posix clocks where available")
++/*  NB: The default value of UseBsdPosixThreadCPUClocks may be
++    overridden in Arguments::parse_each_vm_init_arg.  */
  
+ //
+-// Defines Bsd-specific default values. The flags are available on all
++// Defines BSD-specific default values. The flags are available on all
+ // platforms, but they may have different default values on other platforms.
+ //
+ define_pd_global(bool, UseLargePages, false);
+--- hotspot/src/os/bsd/vm/jsig.c
++++ hotspot/src/os/bsd/vm/jsig.c
+@@ -140,9 +140,13 @@
+ }
  
- int VM_Version::_cpu;
---- hotspot/src/cpu/zero/vm/bytes_zero.hpp
-+++ hotspot/src/cpu/zero/vm/bytes_zero.hpp
-@@ -168,6 +168,9 @@
- #ifdef TARGET_OS_ARCH_linux_zero
- # include "bytes_linux_zero.inline.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "bytes_bsd_zero.inline.hpp"
+ sa_handler_t sigset(int sig, sa_handler_t disp) {
++#ifdef __MidnightBSD__
++  return set_signal(sig, disp, true);
++#else
+   printf("sigset() is not supported by BSD");
+   exit(0);
+- }
 +#endif
++}
  
- #endif // VM_LITTLE_ENDIAN
+ static int call_os_sigaction(int sig, const struct sigaction  *act,
+                              struct sigaction *oact) {
+--- hotspot/src/os/bsd/vm/jvm_bsd.cpp
++++ hotspot/src/os/bsd/vm/jvm_bsd.cpp
+@@ -50,6 +50,7 @@
+     case INTERRUPT_SIGNAL:
+     case SIGFPE:
+     case SIGILL:
++    case SIGBUS:
+     case SIGSEGV:
  
---- hotspot/src/cpu/zero/vm/interp_masm_zero.cpp
-+++ hotspot/src/cpu/zero/vm/interp_masm_zero.cpp
-@@ -40,5 +40,8 @@
- #ifdef TARGET_OS_FAMILY_linux
- # include "thread_linux.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+     /* The following signal is used by the VM to dump thread stacks unless
+@@ -110,71 +111,29 @@
+ JVM_END
  
- // This file is intentionally empty
---- hotspot/src/cpu/zero/vm/stubGenerator_zero.cpp
-+++ hotspot/src/cpu/zero/vm/stubGenerator_zero.cpp
-@@ -43,6 +43,9 @@
- #ifdef TARGET_OS_FAMILY_linux
- # include "thread_linux.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifdef COMPILER2
- #include "opto/runtime.hpp"
- #endif
---- hotspot/src/cpu/zero/vm/stubRoutines_zero.cpp
-+++ hotspot/src/cpu/zero/vm/stubRoutines_zero.cpp
-@@ -30,6 +30,9 @@
- #ifdef TARGET_OS_FAMILY_linux
- # include "thread_linux.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+ /*
+-  All the defined signal names for Bsd.
++  All the defined signal names for BSD are defined by sys_signame[].
  
- #ifdef IA32
- address StubRoutines::x86::_call_stub_compiled_return = NULL;
---- hotspot/src/cpu/zero/vm/vm_version_zero.cpp
-+++ hotspot/src/cpu/zero/vm/vm_version_zero.cpp
-@@ -32,5 +32,8 @@
- #ifdef TARGET_OS_FAMILY_linux
- # include "os_linux.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+   NOTE that not all of these names are accepted by our Java implementation
  
- // This file is intentionally empty
---- hotspot/src/os/bsd/vm/attachListener_bsd.cpp
-+++ hotspot/src/os/bsd/vm/attachListener_bsd.cpp
-@@ -170,53 +170,41 @@
- // Initialization - create a listener socket and bind it to a file
+   Via an existing claim by the VM, sigaction restrictions, or
+   the "rules of Unix" some of these names will be rejected at runtime.
+   For example the VM sets up to handle USR1, sigaction returns EINVAL for
+-  STOP, and Bsd simply doesn't allow catching of KILL.
++  STOP, and BSD simply doesn't allow catching of KILL.
  
- int BsdAttachListener::init() {
--  char path[UNIX_PATH_MAX];          // socket file
--  char initial_path[UNIX_PATH_MAX];  // socket file during setup
--  int listener;                      // listener socket (file descriptor)
-+  char path[UNIX_PATH_MAX];        // socket file
-+  int listener;                 // listener socket (file descriptor)
+   Here are the names currently accepted by a user of sun.misc.Signal with
+   1.4.1 (ignoring potential interaction with use of chaining, etc):
  
-   // register function to cleanup
-   ::atexit(listener_cleanup);
+-    HUP, INT, TRAP, ABRT, IOT, BUS, USR2, PIPE, ALRM, TERM, STKFLT,
+-    CLD, CHLD, CONT, TSTP, TTIN, TTOU, URG, XCPU, XFSZ, VTALRM, PROF,
+-    WINCH, POLL, IO, PWR, SYS
+-
++      HUP, INT, TRAP, ABRT, EMT, SYS, PIPE, ALRM, TERM, URG, TSTP, CONT,
++      CHLD, TTIN, TTOU, IO, XCPU, XFSZ, VTALRM, PROF, WINCH, INFO, USR2
+ */
  
--  int n = snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
--                   os::get_temp_directory(), os::current_process_id());
--  if (n < (int)UNIX_PATH_MAX) {
--    n = snprintf(initial_path, UNIX_PATH_MAX, "%s.tmp", path);
--  }
--  if (n >= (int)UNIX_PATH_MAX) {
--    return -1;
--  }
+-struct siglabel {
+-  const char *name;
+-  int   number;
+-};
 -
-   // create the listener socket
-   listener = ::socket(PF_UNIX, SOCK_STREAM, 0);
-   if (listener == -1) {
-     return -1;
-   }
+-struct siglabel siglabels[] = {
+-  /* derived from /usr/include/bits/signum.h on RH7.2 */
+-   "HUP",       SIGHUP,         /* Hangup (POSIX).  */
+-  "INT",        SIGINT,         /* Interrupt (ANSI).  */
+-  "QUIT",       SIGQUIT,        /* Quit (POSIX).  */
+-  "ILL",        SIGILL,         /* Illegal instruction (ANSI).  */
+-  "TRAP",       SIGTRAP,        /* Trace trap (POSIX).  */
+-  "ABRT",       SIGABRT,        /* Abort (ANSI).  */
+-  "EMT",        SIGEMT,         /* EMT trap  */
+-  "FPE",        SIGFPE,         /* Floating-point exception (ANSI).  */
+-  "KILL",       SIGKILL,        /* Kill, unblockable (POSIX).  */
+-  "BUS",        SIGBUS,         /* BUS error (4.2 BSD).  */
+-  "SEGV",       SIGSEGV,        /* Segmentation violation (ANSI).  */
+-  "SYS",        SIGSYS,         /* Bad system call. Only on some Bsden! */
+-  "PIPE",       SIGPIPE,        /* Broken pipe (POSIX).  */
+-  "ALRM",       SIGALRM,        /* Alarm clock (POSIX).  */
+-  "TERM",       SIGTERM,        /* Termination (ANSI).  */
+-  "URG",        SIGURG,         /* Urgent condition on socket (4.2 BSD).  */
+-  "STOP",       SIGSTOP,        /* Stop, unblockable (POSIX).  */
+-  "TSTP",       SIGTSTP,        /* Keyboard stop (POSIX).  */
+-  "CONT",       SIGCONT,        /* Continue (POSIX).  */
+-  "CHLD",       SIGCHLD,        /* Child status has changed (POSIX).  */
+-  "TTIN",       SIGTTIN,        /* Background read from tty (POSIX).  */
+-  "TTOU",       SIGTTOU,        /* Background write to tty (POSIX).  */
+-  "IO",         SIGIO,          /* I/O now possible (4.2 BSD).  */
+-  "XCPU",       SIGXCPU,        /* CPU limit exceeded (4.2 BSD).  */
+-  "XFSZ",       SIGXFSZ,        /* File size limit exceeded (4.2 BSD).  */
+-  "VTALRM",     SIGVTALRM,      /* Virtual alarm clock (4.2 BSD).  */
+-  "PROF",       SIGPROF,        /* Profiling alarm clock (4.2 BSD).  */
+-  "WINCH",      SIGWINCH,       /* Window size change (4.3 BSD, Sun).  */
+-  "INFO",       SIGINFO,        /* Information request.  */
+-  "USR1",       SIGUSR1,        /* User-defined signal 1 (POSIX).  */
+-  "USR2",       SIGUSR2         /* User-defined signal 2 (POSIX).  */
+-  };
+-
+ JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
  
--  // bind socket
-+  int res = -1;
-   struct sockaddr_un addr;
-   addr.sun_family = AF_UNIX;
--  strcpy(addr.sun_path, initial_path);
--  ::unlink(initial_path);
--  int res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr));
-+
-+  snprintf(path, UNIX_PATH_MAX, "%s/.java_pid%d",
-+           os::get_temp_directory(), os::current_process_id());
-+  strcpy(addr.sun_path, path);
-+  ::unlink(path);
-+  res = ::bind(listener, (struct sockaddr*)&addr, sizeof(addr));
-   if (res == -1) {
-     RESTARTABLE(::close(listener), res);
-     return -1;
-   }
-+  set_path(path);
+   /* find and return the named signal's number */
  
--  // put in listen mode, set permissions, and rename into place
--  res = ::listen(listener, 5);
--  if (res == 0) {
--      RESTARTABLE(::chmod(initial_path, S_IREAD|S_IWRITE), res);
--      if (res == 0) {
--          res = ::rename(initial_path, path);
--      }
--  }
--  if (res == -1) {
-+  // put in listen mode and set permission and ownership
-+  if ((::listen(listener, 5) == -1) || (::chmod(path, S_IREAD|S_IWRITE) == -1) ||
-+      (::chown(path, geteuid(), getegid()) == -1)) {
-     RESTARTABLE(::close(listener), res);
--    ::unlink(initial_path);
-+    ::unlink(path);
-+    set_path(NULL);
-     return -1;
-   }
--  set_path(path);
-   set_listener(listener);
+-  for(uint i=0; i<ARRAY_SIZE(siglabels); i++)
+-    if(!strcmp(name, siglabels[i].name))
+-      return siglabels[i].number;
++  for (int i = 1; i < NSIG; i++)
++    if (strcasecmp(name, sys_signame[i]) == 0)
++      return i;
  
-   return 0;
-@@ -337,6 +325,15 @@
+   return -1;
  
-     // get the credentials of the peer and check the effective uid/guid
-     // - check with jeff on this.
-+#ifdef _ALLBSD_SOURCE
-+    uid_t puid;
-+    gid_t pgid;
-+    if (::getpeereid(s, &puid, &pgid) != 0) {
-+      int res;
-+      RESTARTABLE(::close(s), res);
-+      continue;
-+    }
-+#else
-     struct ucred cred_info;
-     socklen_t optlen = sizeof(cred_info);
-     if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) {
-@@ -344,10 +341,13 @@
-       RESTARTABLE(::close(s), res);
-       continue;
-     }
-+    uid_t puid = cred_info.uid;
-+    gid_t pgid = cred_info.gid;
-+#endif
-     uid_t euid = geteuid();
-     gid_t egid = getegid();
+@@ -182,11 +141,14 @@
  
--    if (cred_info.uid != euid || cred_info.gid != egid) {
-+    if (puid != euid || pgid != egid) {
-       int res;
-       RESTARTABLE(::close(s), res);
-       continue;
-@@ -467,16 +467,13 @@
-   if (init_at_startup() || is_initialized()) {
-     return false;               // initialized at startup or already initialized
-   }
--  char fn[PATH_MAX+1];
--  sprintf(fn, ".attach_pid%d", os::current_process_id());
-+  char path[PATH_MAX + 1];
-   int ret;
--  struct stat64 st;
--  RESTARTABLE(::stat64(fn, &st), ret);
--  if (ret == -1) {
--    snprintf(fn, sizeof(fn), "%s/.attach_pid%d",
--             os::get_temp_directory(), os::current_process_id());
--    RESTARTABLE(::stat64(fn, &st), ret);
+ // used by os::exception_name()
+ extern bool signal_name(int signo, char* buf, size_t len) {
+-  for(uint i = 0; i < ARRAY_SIZE(siglabels); i++) {
+-    if (signo == siglabels[i].number) {
+-      jio_snprintf(buf, len, "SIG%s", siglabels[i].name);
+-      return true;
+-    }
 -  }
-+  struct stat st;
-+
-+  snprintf(path, PATH_MAX + 1, "%s/.attach_pid%d",
-+           os::get_temp_directory(), os::current_process_id());
-+  RESTARTABLE(::stat(path, &st), ret);
-   if (ret == 0) {
-     // simple check to avoid starting the attach mechanism when
-     // a bogus user creates the file
---- hotspot/src/os/bsd/vm/jsig.c
-+++ hotspot/src/os/bsd/vm/jsig.c
-@@ -143,7 +143,8 @@
+-  return false;
++  if (signo <= 0 || signo >= NSIG)
++    return false;
++  char signame[8];
++  const char *s = sys_signame[signo];
++  uint i;
++  for (i = 0; i < sizeof(signame) - 1 && s[i] != '\0'; i++)
++    signame[i] = toupper(s[i]);
++  signame[i] = '\0';
++  jio_snprintf(buf, len, "SIG%s", signame);
++  return true;
  }
- 
- sa_handler_t sigset(int sig, sa_handler_t disp) {
--  return set_signal(sig, disp, true);
-+  printf("sigset() is not supported by BSD");
-+  exit(0);
-  }
- 
- static int call_os_sigaction(int sig, const struct sigaction  *act,
---- hotspot/src/os/bsd/vm/jvm_bsd.cpp
-+++ hotspot/src/os/bsd/vm/jvm_bsd.cpp
-@@ -146,38 +146,31 @@
-   "ILL",        SIGILL,         /* Illegal instruction (ANSI).  */
-   "TRAP",       SIGTRAP,        /* Trace trap (POSIX).  */
-   "ABRT",       SIGABRT,        /* Abort (ANSI).  */
--  "IOT",        SIGIOT,         /* IOT trap (4.2 BSD).  */
--  "BUS",        SIGBUS,         /* BUS error (4.2 BSD).  */
-+  "EMT",	SIGEMT,		/* EMT trap  */
-   "FPE",        SIGFPE,         /* Floating-point exception (ANSI).  */
-   "KILL",       SIGKILL,        /* Kill, unblockable (POSIX).  */
--  "USR1",       SIGUSR1,        /* User-defined signal 1 (POSIX).  */
-+  "BUS",	SIGBUS,		/* BUS error (4.2 BSD).  */
-   "SEGV",       SIGSEGV,        /* Segmentation violation (ANSI).  */
--  "USR2",       SIGUSR2,        /* User-defined signal 2 (POSIX).  */
-+  "SYS",	SIGSYS,		/* Bad system call. Only on some Bsden! */
-   "PIPE",       SIGPIPE,        /* Broken pipe (POSIX).  */
-   "ALRM",       SIGALRM,        /* Alarm clock (POSIX).  */
-   "TERM",       SIGTERM,        /* Termination (ANSI).  */
--#ifdef SIGSTKFLT
--  "STKFLT",     SIGSTKFLT,      /* Stack fault.  */
--#endif
--  "CLD",        SIGCLD,         /* Same as SIGCHLD (System V).  */
--  "CHLD",       SIGCHLD,        /* Child status has changed (POSIX).  */
--  "CONT",       SIGCONT,        /* Continue (POSIX).  */
-+  "URG",	SIGURG,		/* Urgent condition on socket (4.2 BSD).  */
-   "STOP",       SIGSTOP,        /* Stop, unblockable (POSIX).  */
-   "TSTP",       SIGTSTP,        /* Keyboard stop (POSIX).  */
-+  "CONT",	SIGCONT,	/* Continue (POSIX).  */
-+  "CHLD",	SIGCHLD,	/* Child status has changed (POSIX).  */
-   "TTIN",       SIGTTIN,        /* Background read from tty (POSIX).  */
-   "TTOU",       SIGTTOU,        /* Background write to tty (POSIX).  */
--  "URG",        SIGURG,         /* Urgent condition on socket (4.2 BSD).  */
-+  "IO",		SIGIO,		/* I/O now possible (4.2 BSD).  */
-   "XCPU",       SIGXCPU,        /* CPU limit exceeded (4.2 BSD).  */
-   "XFSZ",       SIGXFSZ,        /* File size limit exceeded (4.2 BSD).  */
-   "VTALRM",     SIGVTALRM,      /* Virtual alarm clock (4.2 BSD).  */
-   "PROF",       SIGPROF,        /* Profiling alarm clock (4.2 BSD).  */
-   "WINCH",      SIGWINCH,       /* Window size change (4.3 BSD, Sun).  */
--  "POLL",       SIGPOLL,        /* Pollable event occurred (System V).  */
--  "IO",         SIGIO,          /* I/O now possible (4.2 BSD).  */
--  "PWR",        SIGPWR,         /* Power failure restart (System V).  */
--#ifdef SIGSYS
--  "SYS",        SIGSYS          /* Bad system call. Only on some Bsden! */
--#endif
-+  "INFO",	SIGINFO,	/* Information request.  */
-+  "USR1",	SIGUSR1,	/* User-defined signal 1 (POSIX).  */
-+  "USR2",	SIGUSR2		/* User-defined signal 2 (POSIX).  */
-   };
- 
- JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
 --- hotspot/src/os/bsd/vm/jvm_bsd.h
 +++ hotspot/src/os/bsd/vm/jvm_bsd.h
-@@ -54,7 +54,11 @@
- #define AGENT_ONATTACH_SYMBOLS  {"Agent_OnAttach"}
- 
- #define JNI_LIB_PREFIX "lib"
-+#ifdef __APPLE__
-+#define JNI_LIB_SUFFIX ".dylib"
-+#else
- #define JNI_LIB_SUFFIX ".so"
-+#endif
- 
- // Hack: MAXPATHLEN is 4095 on some Bsd and 4096 on others. This may
- //       cause problems if JVM and the rest of JDK are built on different
-@@ -93,6 +97,20 @@
+@@ -112,20 +112,6 @@
  #define SHUTDOWN2_SIGNAL SIGINT
  #define SHUTDOWN3_SIGNAL SIGTERM
  
-+#ifndef SIGRTMIN
-+#ifdef __OpenBSD__
-+#define SIGRTMIN	1
-+#else
-+#define SIGRTMIN	33
-+#endif
-+#endif
-+#ifndef SIGRTMAX
-+#ifdef __OpenBSD__
-+#define SIGRTMAX	31
-+#else
-+#define SIGRTMAX	63
-+#endif
-+#endif
+-#ifndef SIGRTMIN
+-#ifdef __OpenBSD__
+-#define SIGRTMIN        1
+-#else
+-#define SIGRTMIN        33
+-#endif
+-#endif
+-#ifndef SIGRTMAX
+-#ifdef __OpenBSD__
+-#define SIGRTMAX        31
+-#else
+-#define SIGRTMAX        63
+-#endif
+-#endif
  #endif /* JVM_MD_H */
  
- // Reconciliation History
+ #endif // OS_BSD_VM_JVM_BSD_H
 --- hotspot/src/os/bsd/vm/osThread_bsd.cpp
 +++ hotspot/src/os/bsd/vm/osThread_bsd.cpp
-@@ -43,8 +43,12 @@
+@@ -49,7 +49,7 @@
  
  void OSThread::pd_initialize() {
    assert(this != NULL, "check");
-+#ifdef __MidnightBSD__
+-#ifdef __APPLE__
++#if defined(__APPLE__) || defined(__MidnightBSD__)
    _thread_id        = 0;
--  _pthread_id       = 0;
-+#else
-+  _thread_id        = NULL;
-+#endif
-+  _pthread_id       = NULL;
-   _siginfo = NULL;
-   _ucontext = NULL;
-   _expanding_stack = 0;
+ #else
+   _thread_id        = NULL;
 --- hotspot/src/os/bsd/vm/osThread_bsd.hpp
 +++ hotspot/src/os/bsd/vm/osThread_bsd.hpp
-@@ -39,6 +39,7 @@
+@@ -39,7 +39,7 @@
  
   private:
  
-+#ifdef __MidnightBSD__
-   // _thread_id is kernel thread id (similar to LWP id on Solaris). Each
-   // thread has a unique thread_id (BsdThreads or NPTL). It can be used
-   // to access /proc.
-@@ -47,6 +48,12 @@
-   // _pthread_id is the pthread id, which is used by library calls
-   // (e.g. pthread_kill).
-   pthread_t _pthread_id;
-+#else
-+  // _thread_id and _pthread_id are the same on BSD
-+  // keep both to minimize code divergence in os_bsd.cpp
-+  pthread_t _thread_id;
-+  pthread_t _pthread_id;
-+#endif
+-#ifdef _ALLBSD_SOURCE
++#if defined(_ALLBSD_SOURCE) && !defined(__MidnightBSD__)
  
-   sigset_t _caller_sigmask; // Caller's signal mask
- 
-@@ -56,12 +63,22 @@
+ #ifdef __APPLE__
+   thread_t  _thread_id;
+@@ -70,7 +70,7 @@
    sigset_t  caller_sigmask() const       { return _caller_sigmask; }
    void    set_caller_sigmask(sigset_t sigmask)  { _caller_sigmask = sigmask; }
  
-+#ifdef __MidnightBSD__
-   pid_t thread_id() const {
+-#ifdef _ALLBSD_SOURCE
++#if defined(_ALLBSD_SOURCE) && !defined(__MidnightBSD__)
+ #ifdef __APPLE__
+   thread_t thread_id() const {
      return _thread_id;
-   }
-+#else
-+  pthread_t thread_id() const {
-+    return _thread_id;
-+  }
-+#endif
+@@ -87,8 +87,12 @@
+ #endif
  #ifndef PRODUCT
    // Used for debugging, return a unique integer for each thread.
 +#ifdef __MidnightBSD__
-   int thread_identifier() const   { return _thread_id; }
++  int thread_identifier() const   { return _thread_id; }
 +#else
-+  intptr_t thread_identifier() const   { return (intptr_t)_pthread_id; }
+   intptr_t thread_identifier() const   { return (intptr_t)_pthread_id; }
+ #endif
 +#endif
- #endif
  #ifdef ASSERT
    // We expect no reposition failures so kill vm if we get one.
-@@ -70,9 +87,15 @@
+   //
+@@ -96,7 +100,7 @@
      return false;
    }
  #endif // ASSERT
-+#ifdef __MidnightBSD__
-   void set_thread_id(pid_t id) {
+-#ifdef _ALLBSD_SOURCE
++#if defined(_ALLBSD_SOURCE) && !defined(__MidnightBSD__)
+ #ifdef __APPLE__
+   void set_thread_id(thread_t id) {
      _thread_id = id;
-   }
-+#else
-+  void set_thread_id(pthread_t id) {
-+    _thread_id = id;
-+  }
-+#endif
-   pthread_t pthread_id() const {
-     return _pthread_id;
-   }
 --- hotspot/src/os/bsd/vm/os_bsd.cpp
 +++ hotspot/src/os/bsd/vm/os_bsd.cpp
-@@ -88,7 +88,6 @@
+@@ -94,7 +94,6 @@
  # include <sys/mman.h>
  # include <sys/stat.h>
  # include <sys/select.h>
@@ -4112,39 +1108,23 @@
  # include <signal.h>
  # include <errno.h>
  # include <dlfcn.h>
-@@ -102,21 +101,57 @@
- # include <sys/utsname.h>
- # include <sys/socket.h>
- # include <sys/wait.h>
-+# include <time.h>
- # include <pwd.h>
- # include <poll.h>
- # include <semaphore.h>
- # include <fcntl.h>
- # include <string.h>
-+#ifdef _ALLBSD_SOURCE
-+# include <sys/param.h>
-+# include <sys/sysctl.h>
-+#else
- # include <syscall.h>
- # include <sys/sysinfo.h>
- # include <gnu/libc-version.h>
-+#endif
- # include <sys/ipc.h>
+@@ -126,11 +125,25 @@
  # include <sys/shm.h>
--# include <link.h>
+ #ifndef __APPLE__
+ # include <link.h>
++# include <stdlib.h>
+ #endif
  # include <stdint.h>
  # include <inttypes.h>
  # include <sys/ioctl.h>
  
 +#ifdef __MidnightBSD__
-+#if __MidnightBSD_version > 4000
-+#include <bitset>
++#if __MidnightBSD_version > 4015
 +#include <sys/cpuset.h>
 +#endif
 +#include <vm/swap_pager.h>
 +#include <vm/vm_param.h>
-+#if __MidnightBSD_version > 4014
++#if __MidnightBSD_version > 5000
 +#include <pthread_np.h>
 +#else
 +extern "C" int thr_self(long *); // XXX #include <sys/thr.h>
@@ -4151,78 +1131,49 @@
 +#endif
 +#endif
 +
-+#ifndef __APPLE__
-+# include <link.h>
-+#endif
-+
-+#if defined(__MidnightBSD__) || defined(__NetBSD__)
-+# include <elf.h>
-+#endif
-+
-+#ifdef __APPLE__
-+#include <mach/mach.h> // semaphore_* API
-+#include <mach-o/dyld.h>
-+#endif
-+
-+#ifndef MAP_ANONYMOUS
-+#define MAP_ANONYMOUS MAP_ANON
-+#endif
-+
- #define MAX_PATH    (2 * K)
+ #if defined(__FreeBSD__) || defined(__NetBSD__)
+ # include <elf.h>
+ #endif
+@@ -162,8 +175,10 @@
+ #endif
  
- // for timer info max values which include all bits
-@@ -127,19 +162,25 @@
- // global variables
- julong os::Bsd::_physical_memory = 0;
- 
-+#ifndef _ALLBSD_SOURCE
- address   os::Bsd::_initial_thread_stack_bottom = NULL;
- uintptr_t os::Bsd::_initial_thread_stack_size   = 0;
+ int (*os::Bsd::_clock_gettime)(clockid_t, struct timespec *) = NULL;
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
+ int (*os::Bsd::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
 +#endif
- 
- int (*os::Bsd::_clock_gettime)(clockid_t, struct timespec *) = NULL;
 +#ifndef _ALLBSD_SOURCE
- int (*os::Bsd::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
  Mutex* os::Bsd::_createThread_lock = NULL;
-+#endif
+ #endif
  pthread_t os::Bsd::_main_thread;
- int os::Bsd::_page_size = -1;
-+#ifndef _ALLBSD_SOURCE
+@@ -171,7 +186,11 @@
+ #ifndef _ALLBSD_SOURCE
  bool os::Bsd::_is_floating_stack = false;
  bool os::Bsd::_is_NPTL = false;
++#endif
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
  bool os::Bsd::_supports_fast_thread_cpu_time = false;
++#endif
++#ifndef _ALLBSD_SOURCE
  const char * os::Bsd::_glibc_version = NULL;
  const char * os::Bsd::_libpthread_version = NULL;
-+#endif
+ #endif
+@@ -205,6 +224,28 @@
  
- static jlong initial_time_count=0;
- 
-@@ -157,8 +198,6 @@
- static int SR_signum = SIGUSR2;
- sigset_t SR_sigset;
- 
--/* Used to protect dlsym() calls */
--static pthread_mutex_t dl_mutex;
- 
- ////////////////////////////////////////////////////////////////////////////////
- // utility functions
-@@ -171,11 +210,38 @@
- }
- 
  julong os::Bsd::available_memory() {
-+#ifdef _ALLBSD_SOURCE
+ #ifdef _ALLBSD_SOURCE
 +#ifdef __MidnightBSD__
 +  static const char *vm_stats[] = {
 +    "vm.stats.vm.v_free_count",
 +    "vm.stats.vm.v_cache_count",
-+    /* "vm.stats.vm.v_inactive_count", */
-+    NULL
++    "vm.stats.vm.v_inactive_count"
 +  };
 +  size_t size;
 +  julong free_pages;
 +  u_int i, npages;
 +
-+  for (i = 0, free_pages = 0, size = sizeof(npages); vm_stats[i] != NULL; i++) {
++  for (i = 0, free_pages = 0; i < sizeof(vm_stats) / sizeof(vm_stats[0]); i++) {
++    size = sizeof(npages);
 +    if (sysctlbyname(vm_stats[i], &npages, &size, NULL, 0) == -1) {
 +      free_pages = 0;
 +      break;
@@ -4230,38 +1181,38 @@
 +    free_pages += npages;
 +  }
 +  if (free_pages > 0)
-+    free_pages *= os::vm_page_size();
++    return free_pages * os::vm_page_size();
 +  else
 +#endif
-+  // XXXBSD: this is just a stopgap implementation
-+  return physical_memory() >> 2;
-+#else
-   // values in struct sysinfo are "unsigned long"
-   struct sysinfo si;
-   sysinfo(&si);
+   // XXXBSD: this is just a stopgap implementation
+   return physical_memory() >> 2;
+ #else
+@@ -221,6 +262,17 @@
+ }
  
-   return (julong)si.freeram * si.mem_unit;
+ julong os::allocatable_physical_memory(julong size) {
++#ifdef _ALLBSD_SOURCE
++  struct rlimit limits;
++  getrlimit(RLIMIT_DATA, &limits);
++  if (limits.rlim_cur != RLIM_INFINITY)
++    size = MIN2(size, (julong)limits.rlim_cur);
++#ifdef RLIMIT_AS
++  getrlimit(RLIMIT_AS, &limits);
++  if (limits.rlim_cur != RLIM_INFINITY)
++    size = MIN2(size, (julong)limits.rlim_cur);
 +#endif
- }
- 
- julong os::physical_memory() {
-@@ -223,6 +289,7 @@
- }
- 
- 
-+#ifndef _ALLBSD_SOURCE
- #ifndef SYS_gettid
- // i386: 224, ia64: 1105, amd64: 186, sparc 143
- #ifdef __ia64__
-@@ -237,6 +304,7 @@
- #error define gettid for the arch
++#endif
+ #ifdef _LP64
+   return size;
+ #else
+@@ -308,16 +360,22 @@
+ #define COMPILER_VARIANT "client"
  #endif
- #endif
-+#endif
  
- // Cpu architecture string
- #if   defined(ZERO)
-@@ -267,28 +335,86 @@
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
+ // pid_t gettid()
+ //
  // Returns the kernel thread id of the currently running thread. Kernel
  // thread id is used to access /proc.
  //
@@ -4268,16 +1219,9 @@
 -// (Note that getpid() on BsdThreads returns kernel thread id too; but
 -// on NPTL, it returns the same pid for all threads, as required by POSIX.)
 -//
+ pid_t os::Bsd::gettid() {
 +#ifdef __MidnightBSD__
- pid_t os::Bsd::gettid() {
--  int rslt = syscall(SYS_gettid);
--  if (rslt == -1) {
--     // old kernel, no NPTL support
--     return getpid();
--  } else {
--     return (pid_t)rslt;
--  }
-+#if __MidnightBSD_version > 4015
++#if __MidnightBSD_version > 5000
 +  return pthread_getthreadid_np();
 +#else
 +  long tid;
@@ -4284,9 +1228,23 @@
 +  thr_self(&tid);
 +  return (pid_t)tid;
 +#endif
-+}
++#else
+   int rslt = syscall(SYS_gettid);
+   if (rslt == -1) {
+      // old kernel, no NPTL support
+@@ -325,6 +383,7 @@
+   } else {
+      return (pid_t)rslt;
+   }
 +#endif
-+
+ }
+ 
+ // Most versions of bsd have a bug where the number of processors are
+@@ -337,7 +396,35 @@
+                      "environment on Bsd when /proc filesystem is not mounted.";
+ #endif
+ 
+-#ifdef _ALLBSD_SOURCE
 +#if defined(__MidnightBSD__)
 +void os::Bsd::initialize_system_info() {
 +  int cpu_val = sysconf(_SC_NPROCESSORS_CONF);
@@ -4314,541 +1272,120 @@
 +  else
 +    _physical_memory = 256*1024*1024;       // fallback (XXXBSD?)
 +#endif
- }
++ }
 +#elif defined(_ALLBSD_SOURCE)
-+void os::Bsd::initialize_system_info() {
-+  int mib[2];
-+  size_t len;
-+  int cpu_val;
-+  u_long mem_val;
-+
-+  /* get processors count via hw.ncpus sysctl */
-+  mib[0] = CTL_HW;
-+  mib[1] = HW_NCPU;
-+  len = sizeof(cpu_val);
-+  if (sysctl(mib, 2, &cpu_val, &len, NULL, 0) != -1 && cpu_val >= 1) {
-+       set_processor_count(cpu_val);
-+  }
-+  else {
-+       set_processor_count(1);   // fallback
-+  }
- 
--// Most versions of bsd have a bug where the number of processors are
--// determined by looking at the /proc file system.  In a chroot environment,
--// the system call returns 1.  This causes the VM to act as if it is
--// a single processor and elide locking (see is_MP() call).
--static bool unsafe_chroot_detected = false;
--static const char *unstable_chroot_error = "/proc file system not found.\n"
--                     "Java may be unstable running multithreaded in a chroot "
--                     "environment on Bsd when /proc filesystem is not mounted.";
-+  /* get physical memory via hw.usermem sysctl (hw.usermem is used
-+   * instead of hw.physmem because we need size of allocatable memory
-+   */
-+  mib[0] = CTL_HW;
-+  mib[1] = HW_USERMEM;
-+  len = sizeof(mem_val);
-+  if (sysctl(mib, 2, &mem_val, &len, NULL, 0) != -1)
-+       _physical_memory = mem_val;
-+  else
-+       _physical_memory = 256*1024*1024;       // fallback (XXXBSD?)
- 
-+#ifdef __OpenBSD__
-+  {
-+       // limit _physical_memory memory view on OpenBSD since
-+       // datasize rlimit restricts us anyway.
-+       struct rlimit limits;
-+       getrlimit(RLIMIT_DATA, &limits);
-+       _physical_memory = MIN2(_physical_memory, (julong)limits.rlim_cur);
-+  }
-+#endif
-+}
-+#else
  void os::Bsd::initialize_system_info() {
-   set_processor_count(sysconf(_SC_NPROCESSORS_CONF));
-   if (processor_count() == 1) {
-@@ -305,6 +431,7 @@
-   _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE);
-   assert(processor_count() > 0, "bsd error");
- }
-+#endif
- 
- void os::init_system_properties_values() {
- //  char arch[12];
-@@ -348,9 +475,7 @@
-  *        ...
+   int mib[2];
+   size_t len;
+@@ -452,7 +539,7 @@
   *        7: The default directories, normally /lib and /usr/lib.
   */
--#if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390))
--#define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib"
--#else
-+#ifndef DEFAULT_LIBPATH
- #define DEFAULT_LIBPATH "/lib:/usr/lib"
+ #ifndef DEFAULT_LIBPATH
+-#define DEFAULT_LIBPATH "/lib:/usr/lib"
++#define DEFAULT_LIBPATH "/lib:/usr/lib:%%LOCALBASE%%/lib"
  #endif
  
-@@ -429,7 +554,11 @@
-          * should always exist (until the legacy problem cited above is
-          * addressed).
-          */
-+#ifdef __APPLE__
-+        char *v = getenv("DYLD_LIBRARY_PATH");
-+#else
-         char *v = getenv("LD_LIBRARY_PATH");
-+#endif
-         if (v != NULL) {
-             char *t = ld_library_path;
-             /* That's +1 for the colon and +1 for the trailing '\0' */
-@@ -588,6 +717,7 @@
-   }
- }
- 
-+#ifndef _ALLBSD_SOURCE
- //////////////////////////////////////////////////////////////////////////////
- // detecting pthread library
- 
-@@ -751,6 +881,7 @@
-   }
-   return false;
- }
-+#endif
- 
- //////////////////////////////////////////////////////////////////////////////
- // create new thread
-@@ -759,6 +890,9 @@
- 
- // check if it's safe to start a new thread
- static bool _thread_safety_check(Thread* thread) {
-+#ifdef _ALLBSD_SOURCE
-+    return true;
-+#else
-   if (os::Bsd::is_BsdThreads() && !os::Bsd::is_floating_stack()) {
-     // Fixed stack BsdThreads (SuSE Bsd/x86, and some versions of Redhat)
-     //   Heap is mmap'ed at lower end of memory space. Thread stacks are
-@@ -792,6 +926,7 @@
-     //   here, that means enough space has been reserved for stack.
-     return true;
-   }
-+#endif
- }
- 
- // Thread start routine for all newly created threads
-@@ -819,15 +954,22 @@
+ #define EXTENSIONS_DIR  "/lib/ext"
+@@ -997,7 +1084,7 @@
      return NULL;
    }
  
-+#ifdef __MidnightBSD__
+-#ifdef _ALLBSD_SOURCE
++#if defined(_ALLBSD_SOURCE) && !defined(__MidnightBSD__)
+ #ifdef __APPLE__
+   // thread_id is mach thread on macos
+   osthread->set_thread_id(::mach_thread_self());
+@@ -1009,6 +1096,7 @@
    // thread_id is kernel thread id (similar to Solaris LWP id)
    osthread->set_thread_id(os::Bsd::gettid());
-+#else
-+  // thread_id is pthread_id on BSD
-+  osthread->set_thread_id(::pthread_self());
-+#endif
  
-+#ifndef _ALLBSD_SOURCE
++#ifndef __MidnightBSD__
    if (UseNUMA) {
      int lgrp_id = os::numa_get_group_id();
      if (lgrp_id != -1) {
-       thread->set_lgrp_id(lgrp_id);
+@@ -1016,6 +1104,7 @@
      }
    }
+ #endif
 +#endif
    // initialize signal mask for this thread
    os::Bsd::hotspot_sigmask(thread);
  
-@@ -910,17 +1052,22 @@
+@@ -1105,7 +1194,7 @@
      // let pthread_create() pick the default value.
    }
  
-+#ifndef _ALLBSD_SOURCE
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    // glibc guard page
    pthread_attr_setguardsize(&attr, os::Bsd::default_guard_size(thr_type));
-+#endif
- 
-   ThreadState state;
- 
-   {
-+
-+#ifndef _ALLBSD_SOURCE
-     // Serialize thread creation if we are running with fixed stack BsdThreads
-     bool lock = os::Bsd::is_BsdThreads() && !os::Bsd::is_floating_stack();
-     if (lock) {
-       os::Bsd::createThread_lock()->lock_without_safepoint_check();
-     }
-+#endif
- 
-     pthread_t tid;
-     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
-@@ -934,7 +1081,9 @@
-       // Need to clean up stuff we've allocated so far
-       thread->set_osthread(NULL);
-       delete osthread;
-+#ifndef _ALLBSD_SOURCE
-       if (lock) os::Bsd::createThread_lock()->unlock();
-+#endif
-       return false;
-     }
- 
-@@ -950,9 +1099,11 @@
-       }
-     }
- 
-+#ifndef _ALLBSD_SOURCE
-     if (lock) {
-       os::Bsd::createThread_lock()->unlock();
-     }
-+#endif
+ #endif
+@@ -1194,7 +1283,7 @@
    }
  
-   // Aborted due to thread limit being reached
-@@ -990,7 +1141,11 @@
-   }
- 
    // Store pthread info into the OSThread
-+#ifdef __MidnightBSD__
-   osthread->set_thread_id(os::Bsd::gettid());
-+#else
-+  osthread->set_thread_id(::pthread_self());
-+#endif
-   osthread->set_pthread_id(::pthread_self());
- 
-   // initialize floating point control register
-@@ -1001,6 +1156,7 @@
- 
-   thread->set_osthread(osthread);
- 
-+#ifndef _ALLBSD_SOURCE
-   if (UseNUMA) {
-     int lgrp_id = os::numa_get_group_id();
-     if (lgrp_id != -1) {
-@@ -1027,6 +1183,7 @@
-     os::Bsd::manually_expand_stack(jt, addr);
-     osthread->clear_expanding_stack();
-   }
-+#endif
- 
-   // initialize signal mask for this thread
-   // and save the caller's signal mask
-@@ -1085,6 +1242,7 @@
- //////////////////////////////////////////////////////////////////////////////
- // initial thread
- 
-+#ifndef _ALLBSD_SOURCE
- // Check if current thread is the initial thread, similar to Solaris thr_main.
- bool os::Bsd::is_initial_thread(void) {
-   char dummy;
-@@ -1321,6 +1479,7 @@
-   _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size());
-   _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size;
+-#ifdef _ALLBSD_SOURCE
++#if defined(_ALLBSD_SOURCE) && !defined(__MidnightBSD__)
+ #ifdef __APPLE__
+   osthread->set_thread_id(::mach_thread_self());
+ #else
+@@ -1630,7 +1719,10 @@
  }
-+#endif
- 
- ////////////////////////////////////////////////////////////////////////////////
- // time support
-@@ -1342,9 +1501,7 @@
-   return (1000 * 1000);
- }
- 
--// For now, we say that bsd does not support vtime.  I have no idea
--// whether it can actually be made to (DLD, 9/13/05).
--
-+// XXX: For now, code this as if BSD does not support vtime.
- bool os::supports_vtime() { return false; }
- bool os::enable_vtime()   { return false; }
- bool os::vtime_enabled()  { return false; }
-@@ -1364,6 +1521,21 @@
- #define CLOCK_MONOTONIC (1)
  #endif
  
-+#ifdef __APPLE__
-+void os::Bsd::clock_init() {
-+	// XXXDARWIN: Investigate replacement monotonic clock
-+}
-+#elif defined(_ALLBSD_SOURCE)
-+void os::Bsd::clock_init() {
-+  struct timespec res;
-+  struct timespec tp;
-+  if (::clock_getres(CLOCK_MONOTONIC, &res) == 0 &&
-+      ::clock_gettime(CLOCK_MONOTONIC, &tp)  == 0) {
-+    // yes, monotonic clock is supported
-+    _clock_gettime = ::clock_gettime;
-+  }
-+}
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
++#ifdef __MidnightBSD__
++#define sys_clock_getres       clock_getres
 +#else
- void os::Bsd::clock_init() {
-   // we do dlopen's in this particular order due to bug in bsd
-   // dynamical loader (see 6348968) leading to crash on exit
-@@ -1399,7 +1571,9 @@
-     }
-   }
- }
-+#endif
- 
-+#ifndef _ALLBSD_SOURCE
  #ifndef SYS_clock_getres
  
  #if defined(IA32) || defined(AMD64)
-@@ -1440,6 +1614,7 @@
-     _pthread_getcpuclockid = pthread_getcpuclockid_func;
-   }
- }
+@@ -1644,6 +1736,7 @@
+ #else
+ #define sys_clock_getres(x,y)  ::syscall(SYS_clock_getres, x, y)
+ #endif
 +#endif
  
- jlong os::javaTimeNanos() {
-   if (Bsd::supports_monotonic_clock()) {
-@@ -1608,7 +1783,14 @@
- 
- // DLL functions
- 
--const char* os::dll_file_extension() { return ".so"; }
-+#define JNI_LIB_PREFIX "lib"
-+#ifdef __APPLE__
-+#define JNI_LIB_SUFFIX ".dylib"
-+#else
-+#define JNI_LIB_SUFFIX ".so"
-+#endif
-+
-+const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; }
- 
- // This must be hard coded because it's the system's temporary
- // directory not the java application's temp directory, ala java.io.tmpdir.
-@@ -1628,13 +1810,13 @@
-   const size_t pnamelen = pname ? strlen(pname) : 0;
- 
-   // Quietly truncate on buffer overflow.  Should be an error.
--  if (pnamelen + strlen(fname) + 10 > (size_t) buflen) {
-+  if (pnamelen + strlen(fname) + strlen(JNI_LIB_PREFIX) + strlen(JNI_LIB_SUFFIX) + 2 > buflen) {
-     *buffer = '\0';
-     return;
-   }
- 
-   if (pnamelen == 0) {
--    snprintf(buffer, buflen, "lib%s.so", fname);
-+    snprintf(buffer, buflen, JNI_LIB_PREFIX "%s" JNI_LIB_SUFFIX, fname);
-   } else if (strchr(pname, *os::path_separator()) != NULL) {
-     int n;
-     char** pelements = split_path(pname, &n);
-@@ -1643,7 +1825,8 @@
-       if (pelements[i] == NULL || strlen(pelements[i]) == 0) {
-         continue; // skip the empty path values
-       }
--      snprintf(buffer, buflen, "%s/lib%s.so", pelements[i], fname);
-+      snprintf(buffer, buflen, "%s/" JNI_LIB_PREFIX "%s" JNI_LIB_SUFFIX,
-+          pelements[i], fname);
-       if (file_exists(buffer)) {
-         break;
-       }
-@@ -1658,7 +1841,7 @@
-       FREE_C_HEAP_ARRAY(char*, pelements);
-     }
-   } else {
--    snprintf(buffer, buflen, "%s/lib%s.so", pname, fname);
-+    snprintf(buffer, buflen, "%s/" JNI_LIB_PREFIX "%s" JNI_LIB_SUFFIX, pname, fname);
-   }
+ void os::Bsd::fast_thread_clock_init() {
+   if (!UseBsdPosixThreadCPUClocks) {
+@@ -1814,8 +1907,10 @@
  }
  
-@@ -1708,6 +1891,23 @@
-   return false;
+ intx os::current_thread_id() {
+-#ifdef __APPLE__
++#if defined(__APPLE__)
+   return (intx)::mach_thread_self();
++#elif defined(__MidnightBSD__)
++  return (intx)os::Bsd::gettid();
+ #else
+   return (intx)::pthread_self();
+ #endif
+@@ -2338,14 +2433,16 @@
  }
  
-+#ifdef _ALLBSD_SOURCE
-+// ported from solaris version
-+bool os::dll_address_to_library_name(address addr, char* buf,
-+                                     int buflen, int* offset) {
-+  Dl_info dlinfo;
-+
-+  if (dladdr((void*)addr, &dlinfo)){
-+     if (buf) jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
-+     if (offset) *offset = addr - (address)dlinfo.dli_fbase;
-+     return true;
-+  } else {
-+     if (buf) buf[0] = '\0';
-+     if (offset) *offset = -1;
-+     return false;
-+  }
-+}
-+#else
- struct _address_to_library_name {
-   address addr;          // input : memory address
-   size_t  buflen;        //         size of fname
-@@ -1782,11 +1982,27 @@
-      return false;
-   }
- }
-+#endif
+ void os::print_os_info_brief(outputStream* st) {
+-  st->print("Bsd");
++  st->print("BSD");
++  st->cr();
  
-   // Loads .dll/.so and
-   // in case of error it checks if .dll/.so was built for the
-   // same architecture as Hotspot is running on
-+ 
-+#ifdef __APPLE__
-+void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
-+  void * result= ::dlopen(filename, RTLD_LAZY);
-+  if (result != NULL) {
-+    // Successful loading
-+    return result;
-+  }
-+
-+  // Read system error message into ebuf
-+  ::strncpy(ebuf, ::dlerror(), ebuflen-1);
-+  ebuf[ebuflen-1]='\0';
- 
-+  return NULL;
-+}
-+#else
- void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
- {
-   void * result= ::dlopen(filename, RTLD_LAZY);
-@@ -1839,6 +2055,26 @@
-   #define EM_486          6               /* Intel 80486 */
-   #endif
- 
-+  #ifndef EM_MIPS_RS3_LE
-+  #define EM_MIPS_RS3_LE  10              /* MIPS */
-+  #endif
-+
-+  #ifndef EM_PPC64
-+  #define EM_PPC64        21              /* PowerPC64 */
-+  #endif
-+
-+  #ifndef EM_S390
-+  #define EM_S390         22              /* IBM System/390 */
-+  #endif
-+
-+  #ifndef EM_IA_64
-+  #define EM_IA_64        50              /* HP/Intel IA-64 */ 
-+  #endif
-+
-+  #ifndef EM_X86_64
-+  #define EM_X86_64       62              /* AMD x86-64 */ 
-+  #endif
-+
-   static const arch_t arch_array[]={
-     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
-     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
-@@ -1942,17 +2178,11 @@
- 
-   return NULL;
+   os::Posix::print_uname_info(st);
  }
-+#endif /* !__APPLE__ */
  
--/*
-- * glibc-2.0 libdl is not MT safe.  If you are building with any glibc,
-- * chances are you might want to run the generated bits against glibc-2.0
-- * libdl.so, so always use locking for any version of glibc.
-- */
-+// XXX: Do we need a lock around this as per Linux?
- void* os::dll_lookup(void* handle, const char* name) {
--  pthread_mutex_lock(&dl_mutex);
--  void* res = dlsym(handle, name);
--  pthread_mutex_unlock(&dl_mutex);
--  return res;
-+  return dlsym(handle, name);
- }
+ void os::print_os_info(outputStream* st) {
+   st->print("OS:");
+-  st->print("Bsd");
++  st->print("BSD");
++  st->cr();
  
+   os::Posix::print_uname_info(st);
  
-@@ -1975,7 +2205,51 @@
- 
- void os::print_dll_info(outputStream *st) {
-    st->print_cr("Dynamic libraries:");
--
-+#ifdef _ALLBSD_SOURCE
-+#ifdef RTLD_DI_LINKMAP
-+    Dl_info dli;
-+    void *handle;
-+    Link_map *map;
-+    Link_map *p;
-+
-+    if (!dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli)) {
-+        st->print_cr("Error: Cannot print dynamic libraries.");
-+        return;
-+    }
-+    handle = dlopen(dli.dli_fname, RTLD_LAZY);
-+    if (handle == NULL) {
-+        st->print_cr("Error: Cannot print dynamic libraries.");
-+        return;
-+    }
-+    dlinfo(handle, RTLD_DI_LINKMAP, &map);
-+    if (map == NULL) {
-+        st->print_cr("Error: Cannot print dynamic libraries.");
-+        return;
-+    }
-+
-+    while (map->l_prev != NULL)
-+        map = map->l_prev;
-+
-+    while (map != NULL) {
-+        st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name);
-+        map = map->l_next;
-+    }
-+
-+    dlclose(handle);
-+#elif defined(__APPLE__)
-+    uint32_t count;
-+    uint32_t i;
-+
-+    count = _dyld_image_count();
-+    for (i = 1; i < count; i++) {
-+        const char *name = _dyld_get_image_name(i);
-+        intptr_t slide = _dyld_get_image_vmaddr_slide(i);
-+        st->print_cr(PTR_FORMAT " \t%s", slide, name);
-+    }
-+#else
-+   st->print_cr("Error: Cannot print dynamic libraries.");
-+#endif
-+#else
-    char fname[32];
-    pid_t pid = os::Bsd::gettid();
- 
-@@ -1984,6 +2258,7 @@
-    if (!_print_ascii_file(fname, st)) {
-      st->print("Can not get library information for pid = %d\n", pid);
-    }
-+#endif
- }
- 
- 
-@@ -2018,6 +2293,7 @@
-   st->print(name.machine);
-   st->cr();
- 
-+#ifndef _ALLBSD_SOURCE
-   // Print warning if unsafe chroot environment detected
-   if (unsafe_chroot_detected) {
-     st->print("WARNING!! ");
-@@ -2032,6 +2308,7 @@
-      st->print("(%s stack)", os::Bsd::is_floating_stack() ? "floating" : "fixed");
-   }
-   st->cr();
-+#endif
- 
-   // rlimit
-   st->print("rlimit:");
-@@ -2057,6 +2334,7 @@
-   if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
-   else st->print("%d", rlim.rlim_cur);
- 
-+#ifndef _ALLBSD_SOURCE
-   st->print(", AS ");
-   getrlimit(RLIMIT_AS, &rlim);
-   if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
-@@ -2069,11 +2347,7 @@
-   os::loadavg(loadavg, 3);
-   st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
-   st->cr();
--
--  // meminfo
--  st->print("\n/proc/meminfo:\n");
--  _print_ascii_file("/proc/meminfo", st);
--  st->cr();
-+#endif
- }
- 
- void os::print_memory_info(outputStream* st) {
-@@ -2081,19 +2355,55 @@
+@@ -2363,7 +2460,23 @@
    st->print("Memory:");
    st->print(" %dk page", os::vm_page_size()>>10);
  
-+#ifdef _ALLBSD_SOURCE
-+#ifdef __MidnightBSD__
+-#ifndef _ALLBSD_SOURCE
++#if defined(__MidnightBSD__)
 +  struct xswdev xsw;
 +  size_t mibsize, size;
 +  int mib[16], n, total = 0, used = 0;
@@ -4864,561 +1401,255 @@
 +      used += xsw.xsw_used;
 +    }
 +  }
-+#endif
-+#else
++#elif !defined(_ALLBSD_SOURCE)
    // values in struct sysinfo are "unsigned long"
    struct sysinfo si;
    sysinfo(&si);
-+#endif
- 
-   st->print(", physical " UINT64_FORMAT "k",
+@@ -2373,17 +2486,22 @@
              os::physical_memory() >> 10);
    st->print("(" UINT64_FORMAT "k free)",
              os::available_memory() >> 10);
-+#ifdef _ALLBSD_SOURCE
-+#ifdef __MidnightBSD__
+-#ifndef _ALLBSD_SOURCE
++#if defined(__MidnightBSD__)
 +  st->print(", swap " UINT64_FORMAT "k",
 +            ((jlong)total * os::vm_page_size()) >> 10);
 +  st->print("(" UINT64_FORMAT "k free)",
 +            ((jlong)(total - used) * os::vm_page_size()) >> 10);
-+#endif
-+#else
++#elif !defined(_ALLBSD_SOURCE)
    st->print(", swap " UINT64_FORMAT "k",
              ((jlong)si.totalswap * si.mem_unit) >> 10);
    st->print("(" UINT64_FORMAT "k free)",
              ((jlong)si.freeswap * si.mem_unit) >> 10);
-+#endif
-+  st->cr();
-+
-+#ifndef _ALLBSD_SOURCE
-+  // meminfo
-+  st->print("\n/proc/meminfo:\n");
-+  _print_ascii_file("/proc/meminfo", st);
+-#endif
    st->cr();
-+#endif
- }
  
- // Taken from /usr/include/bits/siginfo.h  Supposed to be architecture specific
-@@ -2333,19 +2643,29 @@
- static volatile jint pending_signals[NSIG+1] = { 0 };
- 
- // Bsd(POSIX) specific hand shaking semaphore.
-+#ifdef __APPLE__
-+static semaphore_t sig_sem;
-+#define SEM_INIT(sem, value)	semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, value)
-+#define SEM_WAIT(sem)		semaphore_wait(sem);
-+#define SEM_POST(sem)		semaphore_signal(sem);
-+#else
- static sem_t sig_sem;
-+#define SEM_INIT(sem, value)	sem_init(&sem, 0, value)
-+#define SEM_WAIT(sem)		sem_wait(&sem);
-+#define SEM_POST(sem)		sem_post(&sem);
+   // meminfo
+   st->print("\n/proc/meminfo:\n");
+   _print_ascii_file("/proc/meminfo", st);
 +#endif
- 
- void os::signal_init_pd() {
-   // Initialize signal structures
-   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
- 
-   // Initialize signal semaphore
--  ::sem_init(&sig_sem, 0, 0);
-+  ::SEM_INIT(sig_sem, 0);
+   st->cr();
  }
  
- void os::signal_notify(int sig) {
-   Atomic::inc(&pending_signals[sig]);
--  ::sem_post(&sig_sem);
-+  ::SEM_POST(sig_sem);
- }
+@@ -2396,7 +2514,7 @@
  
- static int check_pending_signals(bool wait) {
-@@ -2367,7 +2687,7 @@
-     do {
-       thread->set_suspend_equivalent();
-       // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
--      ::sem_wait(&sig_sem);
-+      ::SEM_WAIT(sig_sem);
+ const char *fpe_names[] = { "FPE0", "FPE_INTDIV", "FPE_INTOVF", "FPE_FLTDIV",
+                           "FPE_FLTOVF", "FPE_FLTUND", "FPE_FLTRES",
+-                          "FPE_FLTINV", "FPE_FLTSUB", "FPE_FLTDEN" };
++                          "FPE_FLTINV", "FPE_FLTSUB" };
  
-       // were we externally suspended while we were waiting?
-       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
-@@ -2378,7 +2698,7 @@
-         // while suspended because that would surprise the thread that
-         // suspended us.
-         //
--        ::sem_post(&sig_sem);
-+        ::SEM_POST(sig_sem);
+ const char *segv_names[] = { "SEGV0", "SEGV_MAPERR", "SEGV_ACCERR" };
  
-         thread->java_suspend_self();
-       }
-@@ -2422,10 +2742,10 @@
-     return;
-   }
+@@ -2422,7 +2540,7 @@
+     st->print(", si_addr=" PTR_FORMAT, si->si_addr);
+     break;
+   case SIGFPE:
+-    st->print(", si_code=%d (%s)", c, c > 9 ? "" : fpe_names[c]);
++    st->print(", si_code=%d (%s)", c, c > 8 ? "" : fpe_names[c]);
+     st->print(", si_addr=" PTR_FORMAT, si->si_addr);
+     break;
+   case SIGSEGV:
+@@ -2531,10 +2649,17 @@
+         jrelib_p = buf + len;
  
--  char buf[PATH_MAX+1];
-+  char buf[PATH_MAX + 1];
-   int num = Atomic::add(1, &cnt);
- 
--  snprintf(buf, sizeof(buf), "%s/hs-vm-%d-%d",
-+  snprintf(buf, PATH_MAX + 1, "%s/hs-vm-%d-%d",
-            os::get_temp_directory(), os::current_process_id(), num);
-   unlink(buf);
- 
-@@ -2451,9 +2771,14 @@
- //       problem.
- bool os::commit_memory(char* addr, size_t size, bool exec) {
-   int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE;
-+#ifdef __OpenBSD__
-+  // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
-+  return ::mprotect(addr, size, prot) == 0;
+         // Add the appropriate library subdir
++#ifdef __APPLE__
+         snprintf(jrelib_p, buflen-len, "/jre/lib");
+         if (0 != access(buf, F_OK)) {
+           snprintf(jrelib_p, buflen-len, "/lib");
+         }
 +#else
-   uintptr_t res = (uintptr_t) ::mmap(addr, size, prot,
-                                    MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
-   return res != (uintptr_t) MAP_FAILED;
++        snprintf(jrelib_p, buflen-len, "/jre/lib/%s", cpu_arch);
++        if (0 != access(buf, F_OK)) {
++          snprintf(jrelib_p, buflen-len, "/lib/%s", cpu_arch);
++        }
 +#endif
+ 
+         // Add the appropriate client or server subdir
+         len = strlen(buf);
+@@ -2752,7 +2877,7 @@
+       if (::write(fd, "", 1) == 1) {
+         mmap(base, size,
+              PROT_READ|PROT_WRITE|PROT_EXEC,
+-             MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0);
++             MAP_PRIVATE|MAP_FIXED, fd, 0);
+       }
+     }
+     ::close(fd);
+@@ -2815,7 +2940,7 @@
  }
  
- bool os::commit_memory(char* addr, size_t size, size_t alignment_hint,
-@@ -2469,36 +2794,27 @@
+ void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) {
+-  ::madvise(addr, bytes, MADV_DONTNEED);
++  commit_memory(addr, bytes, false);
  }
  
  void os::numa_make_global(char *addr, size_t bytes) {
--  Bsd::numa_interleave_memory(addr, bytes);
+@@ -2962,7 +3087,7 @@
+   return ::mprotect(addr, size, PROT_NONE) == 0;
+ #else
+   uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
+-                MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
++                MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
+   return res  != (uintptr_t) MAP_FAILED;
+ #endif
  }
+@@ -2989,15 +3114,16 @@
+   char * addr;
+   int flags;
  
- void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) {
--  Bsd::numa_tonode_memory(addr, bytes, lgrp_hint);
- }
+-  flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS;
++  flags = MAP_PRIVATE | MAP_ANONYMOUS;
+   if (fixed) {
+     assert((uintptr_t)requested_addr % os::Bsd::page_size() == 0, "unaligned address");
+     flags |= MAP_FIXED;
+   }
  
- bool os::numa_topology_changed()   { return false; }
+-  // Map uncommitted pages PROT_READ and PROT_WRITE, change access
+-  // to PROT_EXEC if executable when we commit the page.
+-  addr = (char*)::mmap(requested_addr, bytes, PROT_READ|PROT_WRITE,
++  // Map reserved/uncommitted pages PROT_NONE so we fail early if we
++  // touch an uncommitted page. Otherwise, the read/write might
++  // succeed if we have enough swap space to back the physical page.
++  addr = (char*)::mmap(requested_addr, bytes, PROT_NONE,
+                        flags, -1, 0);
  
- size_t os::numa_get_groups_num() {
--  int max_node = Bsd::numa_max_node();
--  return max_node > 0 ? max_node + 1 : 1;
-+  return 1;
- }
+   if (addr != MAP_FAILED) {
+@@ -3242,9 +3368,11 @@
+ #endif
  
- int os::numa_get_group_id() {
--  int cpu_id = Bsd::sched_getcpu();
--  if (cpu_id != -1) {
--    int lgrp_id = Bsd::get_node_by_cpu(cpu_id);
--    if (lgrp_id != -1) {
--      return lgrp_id;
--    }
--  }
-   return 0;
- }
- 
- size_t os::numa_get_leaf_groups(int *ids, size_t size) {
--  for (size_t i = 0; i < size; i++) {
--    ids[i] = i;
-+  if (size > 0) {
-+    ids[0] = 0;
-+    return 1;
-   }
--  return size;
-+  return 0;
- }
- 
- bool os::get_page_info(char *start, page_info* info) {
-@@ -2509,6 +2825,7 @@
-   return end;
- }
- 
+ char* os::reserve_memory_special(size_t bytes, char* req_addr, bool exec) {
 +#ifndef _ALLBSD_SOURCE
- extern "C" void numa_warn(int number, char *where, ...) { }
- extern "C" void numa_error(char *where) { }
- 
-@@ -2610,104 +2927,26 @@
- os::Bsd::numa_tonode_memory_func_t os::Bsd::_numa_tonode_memory;
- os::Bsd::numa_interleave_memory_func_t os::Bsd::_numa_interleave_memory;
- unsigned long* os::Bsd::_numa_all_nodes;
+   // "exec" is passed in but not used.  Creating the shared image for
+   // the code cache doesn't have an SHM_X executable permission to check.
+   assert(UseLargePages && UseSHM, "only for SHM large pages");
 +#endif
  
- bool os::uncommit_memory(char* addr, size_t size) {
-+#ifdef __OpenBSD__
-+  // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
-+  return ::mprotect(addr, size, PROT_NONE) == 0;
+   key_t key = IPC_PRIVATE;
+   char *addr;
+@@ -3319,11 +3447,19 @@
+ // with SysV SHM the entire memory region must be allocated as shared
+ // memory.
+ bool os::can_commit_large_page_memory() {
++#ifdef _ALLBSD_SOURCE
++  return false;
 +#else
-   uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE,
-                 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0);
-   return res  != (uintptr_t) MAP_FAILED;
+   return UseHugeTLBFS;
 +#endif
  }
  
--// Bsd uses a growable mapping for the stack, and if the mapping for
--// the stack guard pages is not removed when we detach a thread the
--// stack cannot grow beyond the pages where the stack guard was
--// mapped.  If at some point later in the process the stack expands to
--// that point, the Bsd kernel cannot expand the stack any further
--// because the guard pages are in the way, and a segfault occurs.
--//
--// However, it's essential not to split the stack region by unmapping
--// a region (leaving a hole) that's already part of the stack mapping,
--// so if the stack mapping has already grown beyond the guard pages at
--// the time we create them, we have to truncate the stack mapping.
--// So, we need to know the extent of the stack mapping when
--// create_stack_guard_pages() is called.
--
--// Find the bounds of the stack mapping.  Return true for success.
--//
--// We only need this for stacks that are growable: at the time of
--// writing thread stacks don't use growable mappings (i.e. those
--// creeated with MAP_GROWSDOWN), and aren't marked "[stack]", so this
--// only applies to the main thread.
--static bool
--get_stack_bounds(uintptr_t *bottom, uintptr_t *top)
--{
--  FILE *f = fopen("/proc/self/maps", "r");
--  if (f == NULL)
--    return false;
--
--  while (!feof(f)) {
--    size_t dummy;
--    char *str = NULL;
--    ssize_t len = getline(&str, &dummy, f);
--    if (len == -1) {
--      fclose(f);
--      return false;
--    }
--
--    if (len > 0 && str[len-1] == '\n') {
--      str[len-1] = 0;
--      len--;
--    }
--
--    static const char *stack_str = "[stack]";
--    if (len > (ssize_t)strlen(stack_str)
--       && (strcmp(str + len - strlen(stack_str), stack_str) == 0)) {
--      if (sscanf(str, "%" SCNxPTR "-%" SCNxPTR, bottom, top) == 2) {
--        uintptr_t sp = (uintptr_t)__builtin_frame_address(0);
--        if (sp >= *bottom && sp <= *top) {
--          free(str);
--          fclose(f);
--          return true;
--        }
--      }
--    }
--    free(str);
--  }
--  fclose(f);
--  return false;
--}
--
--// If the (growable) stack mapping already extends beyond the point
--// where we're going to put our guard pages, truncate the mapping at
--// that point by munmap()ping it.  This ensures that when we later
--// munmap() the guard pages we don't leave a hole in the stack
--// mapping. This only affects the main/initial thread, but guard
--// against future OS changes
- bool os::create_stack_guard_pages(char* addr, size_t size) {
--  uintptr_t stack_extent, stack_base;
--  bool chk_bounds = NOT_DEBUG(os::Bsd::is_initial_thread()) DEBUG_ONLY(true);
--  if (chk_bounds && get_stack_bounds(&stack_extent, &stack_base)) {
--      assert(os::Bsd::is_initial_thread(),
--           "growable stack in non-initial thread");
--    if (stack_extent < (uintptr_t)addr)
--      ::munmap((void*)stack_extent, (uintptr_t)addr - stack_extent);
--  }
--
-   return os::commit_memory(addr, size);
- }
- 
- // If this is a growable mapping, remove the guard pages entirely by
--// munmap()ping them.  If not, just call uncommit_memory(). This only
--// affects the main/initial thread, but guard against future OS changes
-+// munmap()ping them.  If not, just call uncommit_memory().
- bool os::remove_stack_guard_pages(char* addr, size_t size) {
--  uintptr_t stack_extent, stack_base;
--  bool chk_bounds = NOT_DEBUG(os::Bsd::is_initial_thread()) DEBUG_ONLY(true);
--  if (chk_bounds && get_stack_bounds(&stack_extent, &stack_base)) {
--      assert(os::Bsd::is_initial_thread(),
--           "growable stack in non-initial thread");
--
--    return ::munmap(addr, size) == 0;
--  }
--
-   return os::uncommit_memory(addr, size);
- }
- 
-@@ -2812,6 +3051,9 @@
- static size_t _large_page_size = 0;
- 
- bool os::large_page_init() {
+ bool os::can_execute_large_page_memory() {
 +#ifdef _ALLBSD_SOURCE
 +  return false;
 +#else
-   if (!UseLargePages) return false;
- 
-   if (LargePageSizeInBytes) {
-@@ -2869,6 +3111,7 @@
-   // We optimistically assume the support is available. If later it turns out
-   // not true, VM will automatically switch to use regular page size.
-   return true;
+   return UseHugeTLBFS;
 +#endif
  }
  
- #ifndef SHM_HUGETLB
-@@ -3045,7 +3288,7 @@
- }
- 
- size_t os::read(int fd, void *buf, unsigned int nBytes) {
--  return ::read(fd, buf, nBytes);
-+  RESTARTABLE_RETURN_INT(::read(fd, buf, nBytes));
- }
- 
- // TODO-FIXME: reconcile Solaris' os::sleep with the bsd variation.
-@@ -3181,6 +3424,44 @@
- // this reason, the code should not be used as default (ThreadPriorityPolicy=0).
- // It is only used when ThreadPriorityPolicy=1 and requires root privilege.
- 
-+#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__)
-+int os::java_to_os_priority[MaxPriority + 1] = {
-+  19,              // 0 Entry should never be used
-+
-+   0,              // 1 MinPriority
-+   3,              // 2
-+   6,              // 3
-+
-+   10,              // 4
-+   15,              // 5 NormPriority
-+   18,              // 6
-+
-+   21,              // 7
-+   25,              // 8
-+   28,              // 9 NearMaxPriority
-+
-+   31              // 10 MaxPriority
-+};
-+#elif defined(__APPLE__)
-+/* Using Mach high-level priority assignments */
-+int os::java_to_os_priority[MaxPriority + 1] = {
-+   0,              // 0 Entry should never be used (MINPRI_USER)
-+
-+  27,              // 1 MinPriority
-+  28,              // 2
-+  29,              // 3
-+
-+  30,              // 4
-+  31,              // 5 NormPriority (BASEPRI_DEFAULT)
-+  32,              // 6
-+
-+  33,              // 7
-+  34,              // 8
-+  35,              // 9 NearMaxPriority
-+
-+  36               // 10 MaxPriority
-+};
-+#else
- int os::java_to_os_priority[MaxPriority + 1] = {
-   19,              // 0 Entry should never be used
- 
-@@ -3198,6 +3479,7 @@
- 
-   -5               // 10 MaxPriority
- };
-+#endif
- 
- static int prio_init() {
-   if (ThreadPriorityPolicy == 1) {
-@@ -3217,8 +3499,28 @@
- OSReturn os::set_native_priority(Thread* thread, int newpri) {
-   if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) return OS_OK;
- 
-+#ifdef __OpenBSD__
-+  // OpenBSD pthread_setprio starves low priority threads
-+  return OS_OK;
-+#elif defined(__MidnightBSD__)
-+  int ret = pthread_setprio(thread->osthread()->pthread_id(), newpri);
-+#elif defined(__APPLE__) || defined(__NetBSD__)
-+  struct sched_param sp;
-+  int policy;
-+  pthread_t self = pthread_self();
-+
-+  if (pthread_getschedparam(self, &policy, &sp) != 0)
-+    return OS_ERR;
-+
-+  sp.sched_priority = newpri;
-+  if (pthread_setschedparam(self, policy, &sp) != 0)
-+    return OS_ERR;
-+
-+  return OS_OK;
-+#else
+ // Reserve memory at an arbitrary address, only if that area is
+@@ -3652,8 +3788,8 @@
+   return OS_OK;
+ #else
    int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri);
-   return (ret == 0) ? OS_OK : OS_ERR;
-+#endif
+-  return (ret == 0) ? OS_OK : OS_ERR;
+ #endif
++  return (ret == 0) ? OS_OK : OS_ERR;
  }
  
  OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
-@@ -3228,7 +3530,17 @@
+@@ -4169,7 +4305,7 @@
    }
- 
-   errno = 0;
-+#if defined(__OpenBSD__) || defined(__MidnightBSD__)
-+  *priority_ptr = pthread_getprio(thread->osthread()->pthread_id());
-+#elif defined(__APPLE__) || defined(__NetBSD__)
-+  int policy;
-+  struct sched_param sp;
-+
-+  pthread_getschedparam(pthread_self(), &policy, &sp);
-+  *priority_ptr = sp.sched_priority;
-+#else
-   *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id());
-+#endif
-   return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR);
  }
  
-@@ -3338,7 +3650,7 @@
-   /* Get signal number to use for suspend/resume */
-   if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
-     int sig = ::strtol(s, 0, 10);
--    if (sig > 0 || sig < _NSIG) {
-+    if (sig > 0 || sig < NSIG) {
-         SR_signum = sig;
-     }
-   }
-@@ -3682,6 +3994,28 @@
-     set_signal_handler(SIGFPE, true);
-     set_signal_handler(SIGXFSZ, true);
- 
-+#if defined(__APPLE__)
-+    // In Mac OS X 10.4, CrashReporter will write a crash log for all 'fatal' signals, including
-+    // signals caught and handled by the JVM. To work around this, we reset the mach task
-+    // signal handler that's placed on our process by CrashReporter. This disables
-+    // CrashReporter-based reporting.
-+    //
-+    // This work-around is not necessary for 10.5+, as CrashReporter no longer intercedes
-+    // on caught fatal signals.
-+    //
-+    // Additionally, gdb installs both standard BSD signal handlers, and mach exception
-+    // handlers. By replacing the existing task exception handler, we disable gdb's mach
-+    // exception handling, while leaving the standard BSD signal handlers functional.
-+    kern_return_t kr;
-+    kr = task_set_exception_ports(mach_task_self(),
-+        EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC,
-+        MACH_PORT_NULL,
-+        EXCEPTION_STATE_IDENTITY,
-+        MACHINE_THREAD_STATE);
-+
-+    assert(kr == KERN_SUCCESS, "could not set mach task signal handler");
-+#endif
-+
-     if (libjsig_is_loaded) {
-       // Tell libjsig jvm finishes setting signal handlers
-       (*end_signal_setting)();
-@@ -3702,6 +4036,7 @@
-   }
- }
- 
-+#ifndef _ALLBSD_SOURCE
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
  // This is the fastest way to get thread cpu time on Bsd.
  // Returns cpu time (user+sys) for any thread, not only for current.
  // POSIX compliant clocks are implemented in the kernels 2.6.16+.
-@@ -3716,6 +4051,7 @@
- 
-   return (tp.tv_sec * SEC_IN_NANOSECS) + tp.tv_nsec;
+@@ -4186,6 +4322,7 @@
  }
-+#endif
+ #endif
  
++#ifndef _ALLBSD_SOURCE
  /////
  // glibc on Bsd platform uses non-documented flag
-@@ -3937,13 +4273,13 @@
+ // to indicate, that some special sort of signal
+@@ -4196,6 +4333,7 @@
+ #undef SIGNIFICANT_SIGNAL_MASK
+ #endif
+ #define SIGNIFICANT_SIGNAL_MASK (~0x04000000)
++#endif
  
-   _initial_pid = (java_launcher_pid > 0) ? java_launcher_pid : getpid();
+ static const char* get_signal_handler_name(address handler,
+                                            char* buf, int buflen) {
+@@ -4220,8 +4358,10 @@
  
--  clock_tics_per_sec = sysconf(_SC_CLK_TCK);
-+  clock_tics_per_sec = CLK_TCK;
+   sigaction(sig, NULL, &sa);
  
-   init_random(1234567);
++#ifndef _ALLBSD_SOURCE
+   // See comment for SIGNIFICANT_SIGNAL_MASK define
+   sa.sa_flags &= SIGNIFICANT_SIGNAL_MASK;
++#endif
  
-   ThreadCritical::initialize();
+   st->print("%s: ", os::exception_name(sig, buf, buflen));
  
--  Bsd::set_page_size(sysconf(_SC_PAGESIZE));
-+  Bsd::set_page_size(getpagesize());
-   if (Bsd::page_size() == -1) {
-     fatal(err_msg("os_bsd.cpp: os::init: sysconf failed (%s)",
-                   strerror(errno)));
-@@ -3957,7 +4293,16 @@
- 
-   Bsd::clock_init();
-   initial_time_count = os::elapsed_counter();
--  pthread_mutex_init(&dl_mutex, NULL);
-+
-+#ifdef __APPLE__
-+  // XXXDARWIN
-+  // Work around the unaligned VM callbacks in hotspot's
-+  // sharedRuntime. The callbacks don't use SSE2 instructions, and work on
-+  // Linux, Solaris, and MidnightBSD. On Mac OS X, dyld (rightly so) enforces
-+  // alignment when doing symbol lookup. To work around this, we force early
-+  // binding of all symbols now, thus binding when alignment is known-good.
-+  _dyld_bind_fully_image_containing_address((const void *) &os::init);
+@@ -4243,7 +4383,11 @@
+   // May be, handler was resetted by VMError?
+   if(rh != NULL) {
+     handler = rh;
++#ifdef _ALLBSD_SOURCE
++    sa.sa_flags = VMError::get_resetted_sigflags(sig);
++#else
+     sa.sa_flags = VMError::get_resetted_sigflags(sig) & SIGNIFICANT_SIGNAL_MASK;
 +#endif
- }
+   }
  
- // To install functions for atexit system call
-@@ -3970,7 +4315,9 @@
- // this is called _after_ the global arguments have been parsed
- jint os::init_2(void)
- {
+   st->print(", sa_flags="   PTR32_FORMAT, sa.sa_flags);
+@@ -4318,7 +4462,9 @@
+   os_sigaction(sig, (struct sigaction*)NULL, &act);
+ 
+ 
 +#ifndef _ALLBSD_SOURCE
-   Bsd::fast_thread_clock_init();
+   act.sa_flags &= SIGNIFICANT_SIGNAL_MASK;
 +#endif
  
-   // Allocate a single page and mark it as readable for safepoint polling
-   address polling_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
-@@ -4028,6 +4375,7 @@
-   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
-         vm_page_size()));
+   address thisHandler = (act.sa_flags & SA_SIGINFO)
+     ? CAST_FROM_FN_PTR(address, act.sa_sigaction)
+@@ -4379,6 +4525,14 @@
  
-+#ifndef _ALLBSD_SOURCE
-   Bsd::capture_initial_stack(JavaThread::stack_size_at_create());
+ extern bool signal_name(int signo, char* buf, size_t len);
  
-   Bsd::libpthread_init();
-@@ -4050,6 +4398,7 @@
-       UseNUMA = true;
-     }
-   }
++#ifndef SIGRTMAX
++#ifdef __OpenBSD__
++#define SIGRTMAX        31
++#else
++#define SIGRTMAX        63
 +#endif
- 
-   if (MaxFDLimit) {
-     // set the number of file descriptors to max. print out error
-@@ -4061,6 +4410,14 @@
-         perror("os::init_2 getrlimit failed");
-     } else {
-       nbr_files.rlim_cur = nbr_files.rlim_max;
-+      
-+#ifdef __APPLE__
-+      // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
-+      // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
-+      // be used instead
-+      nbr_files.rlim_cur = MIN(OPEN_MAX, nbr_files.rlim_cur);
 +#endif
 +
-       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
-       if (status != 0) {
-         if (PrintMiscellaneous && (Verbose || WizardMode))
-@@ -4069,8 +4426,10 @@
-     }
-   }
+ const char* os::exception_name(int exception_code, char* buf, size_t size) {
+   if (0 < exception_code && exception_code <= SIGRTMAX) {
+     // signal
+@@ -4448,7 +4602,7 @@
+ // this is called _after_ the global arguments have been parsed
+ jint os::init_2(void)
+ {
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
+   Bsd::fast_thread_clock_init();
+ #endif
  
-+#ifndef _ALLBSD_SOURCE
-   // Initialize lock used to serialize thread creation (see os::create_thread)
-   Bsd::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false));
-+#endif
+@@ -4632,6 +4786,20 @@
  
-   // at-exit methods are called in the reverse order of their registration.
-   // atexit functions are called on return from main or as a result of a
-@@ -4114,11 +4473,29 @@
- };
- 
  int os::active_processor_count() {
-+#ifdef _ALLBSD_SOURCE
+ #ifdef _ALLBSD_SOURCE
 +#ifdef __MidnightBSD__
 +  int online_cpus = 0;
-+#if __MidnightBSD_version > 4000
-+  std::bitset<CPU_SETSIZE> mask;
-+  assert(sizeof(mask) == sizeof(cpuset_t), "Invalid bitset for cpuset_t");
++#if __MidnightBSD_version > 4015
++  cpuset_t mask;
 +  if (cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1, sizeof(mask),
-+      reinterpret_cast<cpuset_t*>(&mask)) == 0)
-+    online_cpus = mask.count();
++      &mask) == 0)
++    for (u_int i = 0; i < sizeof(mask) / sizeof(long); i++)
++      online_cpus += __builtin_popcountl(((long *)&mask)[i]);
 +#else
 +  online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
 +#endif
@@ -5425,619 +1656,408 @@
 +  if (online_cpus > 0 && online_cpus <= _processor_count)
 +    return online_cpus;
 +#endif
-+  return _processor_count;
-+#else
+   return _processor_count;
+ #else
    // Bsd doesn't yet have a (official) notion of processor sets,
-   // so just return the number of online processors.
-   int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
-   assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
-   return online_cpus;
-+#endif
- }
- 
- bool os::distribute_processes(uint length, uint* distribution) {
-@@ -4160,6 +4537,9 @@
- 
- int os::Bsd::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
- {
-+#ifdef _ALLBSD_SOURCE
-+  return pthread_cond_timedwait(_cond, _mutex, _abstime);
-+#else
-    if (is_NPTL()) {
-       return pthread_cond_timedwait(_cond, _mutex, _abstime);
-    } else {
-@@ -4175,6 +4555,7 @@
- #endif // IA64
-       return status;
-    }
-+#endif
- }
- 
- ////////////////////////////////////////////////////////////////////////////////
-@@ -4322,14 +4703,14 @@
-   int o_delete = (oflag & O_DELETE);
-   oflag = oflag & ~O_DELETE;
- 
--  fd = ::open64(path, oflag, mode);
-+  fd = ::open(path, oflag, mode);
-   if (fd == -1) return -1;
- 
-   //If the open succeeded, the file might still be a directory
-   {
--    struct stat64 buf64;
--    int ret = ::fstat64(fd, &buf64);
--    int st_mode = buf64.st_mode;
-+    struct stat buf;
-+    int ret = ::fstat(fd, &buf);
-+    int st_mode = buf.st_mode;
- 
-     if (ret != -1) {
-       if ((st_mode & S_IFMT) == S_IFDIR) {
-@@ -4386,17 +4767,17 @@
-   if (!rewrite_existing) {
-     oflags |= O_EXCL;
-   }
--  return ::open64(path, oflags, S_IREAD | S_IWRITE);
-+  return ::open(path, oflags, S_IREAD | S_IWRITE);
- }
- 
- // return current position of file pointer
- jlong os::current_file_offset(int fd) {
--  return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
-+  return (jlong)::lseek(fd, (off_t)0, SEEK_CUR);
- }
- 
- // move file pointer to the specified offset
- jlong os::seek_to_file_offset(int fd, jlong offset) {
--  return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
-+  return (jlong)::lseek(fd, (off_t)offset, SEEK_SET);
- }
- 
- // This code originates from JDK's sysAvailable
-@@ -4405,10 +4786,10 @@
- int os::available(int fd, jlong *bytes) {
-   jlong cur, end;
-   int mode;
--  struct stat64 buf64;
-+  struct stat buf;
- 
--  if (::fstat64(fd, &buf64) >= 0) {
--    mode = buf64.st_mode;
-+  if (::fstat(fd, &buf) >= 0) {
-+    mode = buf.st_mode;
-     if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) {
-       /*
-       * XXX: is the following call interruptible? If so, this might
-@@ -4422,11 +4803,11 @@
-       }
-     }
-   }
--  if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) {
-+  if ((cur = ::lseek(fd, 0L, SEEK_CUR)) == -1) {
-     return 0;
--  } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) {
-+  } else if ((end = ::lseek(fd, 0L, SEEK_END)) == -1) {
-     return 0;
--  } else if (::lseek64(fd, cur, SEEK_SET) == -1) {
-+  } else if (::lseek(fd, cur, SEEK_SET) == -1) {
-     return 0;
-   }
-   *bytes = end - cur;
-@@ -4489,6 +4870,7 @@
+@@ -5031,7 +5199,7 @@
    return munmap(addr, bytes) == 0;
  }
  
-+#ifndef _ALLBSD_SOURCE
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
  static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
  
  static clockid_t thread_cpu_clockid(Thread* thread) {
-@@ -4500,6 +4882,7 @@
-   assert(rc == 0, "pthread_getcpuclockid is expected to return 0 code");
-   return clockid;
- }
-+#endif
- 
- // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
- // are used by JVM M&M and JVMTI to get user+sys or user CPU time
-@@ -4509,39 +4892,71 @@
- // the fast estimate available on the platform.
- 
+@@ -5055,7 +5223,7 @@
  jlong os::current_thread_cpu_time() {
-+#ifdef __APPLE__
-+  return os::thread_cpu_time(Thread::current(), true /* user + sys */);
-+#elif !defined(_ALLBSD_SOURCE)
+ #ifdef __APPLE__
+   return os::thread_cpu_time(Thread::current(), true /* user + sys */);
+-#elif !defined(_ALLBSD_SOURCE)
++#elif !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    if (os::Bsd::supports_fast_thread_cpu_time()) {
      return os::Bsd::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
    } else {
-     // return user + sys since the cost is the same
-     return slow_thread_cpu_time(Thread::current(), true /* user + sys */);
-   }
-+#endif
+@@ -5066,7 +5234,7 @@
  }
  
  jlong os::thread_cpu_time(Thread* thread) {
-+#ifndef _ALLBSD_SOURCE
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    // consistent with what current_thread_cpu_time() returns
    if (os::Bsd::supports_fast_thread_cpu_time()) {
      return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
-   } else {
-     return slow_thread_cpu_time(thread, true /* user + sys */);
-   }
-+#endif
- }
- 
+@@ -5079,7 +5247,7 @@
  jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
-+#ifdef __APPLE__
-+  return os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
-+#elif !defined(_ALLBSD_SOURCE)
+ #ifdef __APPLE__
+   return os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
+-#elif !defined(_ALLBSD_SOURCE)
++#elif !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    if (user_sys_cpu_time && os::Bsd::supports_fast_thread_cpu_time()) {
      return os::Bsd::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
    } else {
-     return slow_thread_cpu_time(Thread::current(), user_sys_cpu_time);
+@@ -5108,7 +5276,7 @@
+   } else {
+     return ((jlong)tinfo.user_time.seconds * 1000000000) + ((jlong)tinfo.user_time.microseconds * (jlong)1000);
    }
-+#endif
- }
- 
- jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
-+#ifdef __APPLE__
-+  struct thread_basic_info tinfo;
-+  mach_msg_type_number_t tcount = THREAD_INFO_MAX;
-+  kern_return_t kr;
-+  mach_port_t mach_thread;
-+
-+  mach_thread = pthread_mach_thread_np(thread->osthread()->thread_id());
-+  kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount);
-+  if (kr != KERN_SUCCESS)
-+    return -1;
-+
-+  if (user_sys_cpu_time) {
-+    jlong nanos;
-+    nanos = ((jlong) tinfo.system_time.seconds + tinfo.user_time.seconds) * (jlong)1000000000;
-+    nanos += ((jlong) tinfo.system_time.microseconds + (jlong) tinfo.user_time.microseconds) * (jlong)1000;
-+    return nanos;
-+  } else {
-+    return ((jlong)tinfo.user_time.seconds * 1000000000) + ((jlong)tinfo.user_time.microseconds * (jlong)1000);
-+  }
-+#elif !defined(_ALLBSD_SOURCE)
+-#elif !defined(_ALLBSD_SOURCE)
++#elif !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    if (user_sys_cpu_time && os::Bsd::supports_fast_thread_cpu_time()) {
      return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
    } else {
-     return slow_thread_cpu_time(thread, user_sys_cpu_time);
-   }
-+#endif
+@@ -5117,12 +5285,15 @@
+ #endif
  }
  
-+#ifndef _ALLBSD_SOURCE
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
  //
  //  -1 on error.
  //
-@@ -4631,6 +5046,7 @@
+ 
+ static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
++#ifdef __MidnightBSD__
++  return -1;
++#else
+   static bool proc_pid_cpu_avail = true;
+   static bool proc_task_unchecked = true;
+   static const char *proc_stat_path = "/proc/%d/stat";
+@@ -5206,6 +5377,7 @@
+   } else {
      return (jlong)user_time * (1000000000 / clock_tics_per_sec);
    }
++#endif
  }
-+#endif
+ #endif
  
- void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
-   info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
-@@ -4647,7 +5063,13 @@
+@@ -5224,7 +5396,7 @@
  }
  
  bool os::is_thread_cpu_time_supported() {
-+#ifdef __APPLE__
+-#ifdef __APPLE__
++#if defined(__APPLE__) || defined(__MidnightBSD__)
    return true;
-+#elif defined(_ALLBSD_SOURCE)
-+  return false;
-+#else
-+  return true;
-+#endif
- }
+ #elif defined(_ALLBSD_SOURCE)
+   return false;
+@@ -5799,3 +5971,30 @@
  
- // System loadavg support.  Returns -1 if load average cannot be obtained.
-@@ -4780,7 +5202,7 @@
- // abstime will be the absolute timeout time
- // TODO: replace compute_abstime() with unpackTime()
- 
--static struct timespec* compute_abstime(timespec* abstime, jlong millis) {
-+static struct timespec* compute_abstime(struct timespec* abstime, jlong millis) {
-   if (millis < 0)  millis = 0;
-   struct timeval now;
-   int status = gettimeofday(&now, NULL);
-@@ -4832,7 +5254,7 @@
-         status = pthread_cond_wait(_cond, _mutex);
-         // for some reason, under 2.7 lwp_cond_wait() may return ETIME ...
-         // Treat this the same as if the wait was interrupted
--        if (status == ETIME) { status = EINTR; }
-+        if (status == ETIMEDOUT) { status = EINTR; } 
-         assert_status(status == 0 || status == EINTR, status, "cond_wait");
-      }
-      -- _nParked ;
-@@ -4890,10 +5312,10 @@
-       pthread_cond_init (_cond, NULL) ;
-     }
-     assert_status(status == 0 || status == EINTR ||
--                  status == ETIME || status == ETIMEDOUT,
-+		  status == ETIMEDOUT, 
-                   status, "cond_timedwait");
-     if (!FilterSpuriousWakeups) break ;                 // previous semantics
--    if (status == ETIME || status == ETIMEDOUT) break ;
-+    if (status == ETIMEDOUT) break ; 
-     // We consume and ignore EINTR and spurious wakeups.
-   }
-   --_nParked ;
-@@ -4985,7 +5407,7 @@
-  * years from "now".
-  */
- 
--static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
-+static void unpackTime(struct timespec* absTime, bool isAbsolute, jlong time) {
-   assert (time > 0, "convertTime");
- 
-   struct timeval now;
-@@ -5045,7 +5467,7 @@
-   }
- 
-   // Next, demultiplex/decode time arguments
--  timespec absTime;
-+  struct timespec absTime;
-   if (time < 0 || (isAbsolute && time == 0) ) { // don't wait at all
-     return;
-   }
-@@ -5099,7 +5521,7 @@
-     }
-   }
-   assert_status(status == 0 || status == EINTR ||
--                status == ETIME || status == ETIMEDOUT,
-+                status == ETIMEDOUT, 
-                 status, "cond_timedwait");
- 
- #ifdef ASSERT
-@@ -5142,14 +5564,12 @@
+     return true;
  }
- 
- 
-+/* Darwin has no "environ" in a dynamic library. */
++
++// Get the default path to the core file
++// Returns the length of the string
++int os::get_core_path(char *buffer, size_t bufferSize) {
 +#ifdef __APPLE__
-+#include <crt_externs.h>
-+#define environ (*_NSGetEnviron())
++  jio_snprintf(buffer, bufferSize, "/cores/core.%d", current_process_id());
 +#else
- extern char** environ;
--
--#ifndef __NR_fork
--#define __NR_fork IA32_ONLY(2) IA64_ONLY(not defined) AMD64_ONLY(57)
--#endif
--
--#ifndef __NR_execve
--#define __NR_execve IA32_ONLY(11) IA64_ONLY(1033) AMD64_ONLY(59)
- #endif
- 
- // Run the specified command in a separate process. Return its exit value,
-@@ -5164,8 +5584,7 @@
-   // separate process to execve. Make a direct syscall to fork process.
-   // On IA64 there's no fork syscall, we have to use fork() and hope for
-   // the best...
--  pid_t pid = NOT_IA64(syscall(__NR_fork);)
--              IA64_ONLY(fork();)
-+  pid_t pid = fork();
- 
-   if (pid < 0) {
-     // fork failed
-@@ -5181,8 +5600,7 @@
-     // in the new process, so make a system call directly.
-     // IA64 should use normal execve() from glibc to match the glibc fork()
-     // above.
--    NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);)
--    IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);)
-+    execve("/bin/sh", (char* const*)argv, environ);
- 
-     // execve failed
-     _exit(-1);
++  const char *p = get_current_directory(buffer, bufferSize);
++
++  if (p == NULL) {
++    assert(p != NULL, "failed to get current directory");
++    return 0;
++  }
++
++  const char *q = getprogname();
++
++  if (q == NULL) {
++    assert(q != NULL, "failed to get progname");
++    return 0;
++  }
++
++  const int n = strlen(buffer);
++
++  jio_snprintf(buffer + n, bufferSize - n, "/%s.core", q);
++#endif
++  return strlen(buffer);
++}
 --- hotspot/src/os/bsd/vm/os_bsd.hpp
 +++ hotspot/src/os/bsd/vm/os_bsd.hpp
-@@ -30,6 +30,12 @@
- /* pthread_getattr_np comes with BsdThreads-0.9-7 on RedHat 7.1 */
- typedef int (*pthread_getattr_func_type) (pthread_t, pthread_attr_t *);
- 
-+#ifdef __APPLE__
-+// Mac OS X doesn't support clock_gettime. Stub out the type, it is
-+// unused
-+typedef int clockid_t;
-+#endif
-+
- class Bsd {
-   friend class os;
- 
-@@ -50,6 +56,7 @@
+@@ -56,9 +56,11 @@
    static int sigflags[MAXSIGNUM];
  
    static int (*_clock_gettime)(clockid_t, struct timespec *);
-+#ifndef _ALLBSD_SOURCE
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    static int (*_pthread_getcpuclockid)(pthread_t, clockid_t *);
- 
-   static address   _initial_thread_stack_bottom;
-@@ -61,6 +68,7 @@
-   static bool _is_floating_stack;
-   static bool _is_NPTL;
-   static bool _supports_fast_thread_cpu_time;
 +#endif
  
-   static GrowableArray<int>* _cpu_to_node;
- 
-@@ -68,38 +76,54 @@
- 
-   static julong _physical_memory;
-   static pthread_t _main_thread;
 +#ifndef _ALLBSD_SOURCE
-   static Mutex* _createThread_lock;
-+#endif
-   static int _page_size;
+   static address   _initial_thread_stack_bottom;
+   static uintptr_t _initial_thread_stack_size;
  
-   static julong available_memory();
-   static julong physical_memory() { return _physical_memory; }
-   static void initialize_system_info();
+@@ -67,6 +69,8 @@
  
-+#ifndef _ALLBSD_SOURCE
-   static void set_glibc_version(const char *s)      { _glibc_version = s; }
-   static void set_libpthread_version(const char *s) { _libpthread_version = s; }
+   static bool _is_floating_stack;
+   static bool _is_NPTL;
 +#endif
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
+   static bool _supports_fast_thread_cpu_time;
+ #endif
  
-   static bool supports_variable_stack_size();
+@@ -112,13 +116,15 @@
+ #endif
+   static pthread_t main_thread(void)                                { return _main_thread; }
  
-+#ifndef _ALLBSD_SOURCE
-   static void set_is_NPTL()                   { _is_NPTL = true;  }
-   static void set_is_BsdThreads()           { _is_NPTL = false; }
-   static void set_is_floating_stack()         { _is_floating_stack = true; }
-+#endif
- 
-   static void rebuild_cpu_to_node_map();
-   static GrowableArray<int>* cpu_to_node()    { return _cpu_to_node; }
-  public:
-+
-   static void init_thread_fpu_state();
-+#ifndef _ALLBSD_SOURCE
-   static int  get_fpu_control_word();
-   static void set_fpu_control_word(int fpu_control);
-+#endif
-   static pthread_t main_thread(void)                                { return _main_thread; }
-+
-+#ifdef __MidnightBSD__
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    // returns kernel thread id (similar to LWP id on Solaris), which can be
    // used to access /proc
    static pid_t gettid();
-+#endif
 +#ifndef _ALLBSD_SOURCE
    static void set_createThread_lock(Mutex* lk)                      { _createThread_lock = lk; }
    static Mutex* createThread_lock(void)                             { return _createThread_lock; }
+ #endif
 +#endif
    static void hotspot_sigmask(Thread* thread);
  
-+#ifndef _ALLBSD_SOURCE
-   static address   initial_thread_stack_bottom(void)                { return _initial_thread_stack_bottom; }
-   static uintptr_t initial_thread_stack_size(void)                  { return _initial_thread_stack_size; }
-+#endif
-   static bool is_initial_thread(void);
- 
-   static int page_size(void)                                        { return _page_size; }
-@@ -136,6 +160,7 @@
-   static struct sigaction *get_chained_signal_action(int sig);
-   static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
- 
-+#ifndef _ALLBSD_SOURCE
-   // GNU libc and libpthread version strings
-   static const char *glibc_version()          { return _glibc_version; }
-   static const char *libpthread_version()     { return _libpthread_version; }
-@@ -151,6 +176,7 @@
-   static void libpthread_init();
-   static bool libnuma_init();
-   static void* libnuma_dlsym(void* handle, const char* name);
-+#endif
-   // Minimum stack size a thread can be created with (allowing
-   // the VM to completely create the thread and enter user code)
-   static size_t min_stack_allowed;
-@@ -159,17 +185,21 @@
-   static size_t default_stack_size(os::ThreadType thr_type);
-   static size_t default_guard_size(os::ThreadType thr_type);
- 
-+#ifndef _ALLBSD_SOURCE
-   static void capture_initial_stack(size_t max_size);
- 
-   // Stack overflow handling
-   static bool manually_expand_stack(JavaThread * t, address addr);
-   static int max_register_window_saves_before_flushing();
-+#endif
- 
+ #ifndef _ALLBSD_SOURCE
+@@ -197,12 +203,12 @@
    // Real-time clock functions
    static void clock_init(void);
  
-+#ifndef _ALLBSD_SOURCE
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    // fast POSIX clocks support
    static void fast_thread_clock_init(void);
-+#endif
+ #endif
  
-   static bool supports_monotonic_clock() {
+-  static bool supports_monotonic_clock() {
++  static inline bool supports_monotonic_clock() {
      return _clock_gettime != NULL;
-@@ -179,6 +209,7 @@
+   }
+ 
+@@ -210,7 +216,7 @@
      return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
    }
  
-+#ifndef _ALLBSD_SOURCE
+-#ifndef _ALLBSD_SOURCE
++#if !defined(_ALLBSD_SOURCE) || defined(__MidnightBSD__)
    static int pthread_getcpuclockid(pthread_t tid, clockid_t *clock_id) {
      return _pthread_getcpuclockid ? _pthread_getcpuclockid(tid, clock_id) : -1;
    }
-@@ -188,6 +219,7 @@
+--- hotspot/src/os/bsd/vm/perfMemory_bsd.cpp
++++ hotspot/src/os/bsd/vm/perfMemory_bsd.cpp
+@@ -303,7 +303,6 @@
+   DIR *dirp = NULL;
+   RESTARTABLE(::open(dirname, O_RDONLY|O_NOFOLLOW), result);
+   if (result == OS_ERR) {
+-    // Directory doesn't exist or is a symlink, so there is nothing to cleanup.
+     if (PrintMiscellaneous && Verbose) {
+       if (errno == ELOOP) {
+         warning("directory %s is a symlink and is not secure\n", dirname);
+@@ -420,6 +419,7 @@
+   return true;
+ }
+ 
++
+ // return the user name for the given user id
+ //
+ // the caller is expected to free the allocated memory.
+@@ -542,6 +542,18 @@
+       continue;
+     }
+ 
++    // Since we don't create the backing store files in directories
++    // pointed to by symbolic links, we also don't follow them when
++    // looking for the files. We check for a symbolic link after the
++    // call to opendir in order to eliminate a small window where the
++    // symlink can be exploited.
++    //
++    if (!is_directory_secure(usrdir_name)) {
++      FREE_C_HEAP_ARRAY(char, usrdir_name);
++      os::closedir(subdirp);
++      continue;
++    }
++
+     struct dirent* udentry;
+     char* udbuf = NEW_C_HEAP_ARRAY(char, os::readdir_buf_size(usrdir_name));
+     errno = 0;
+@@ -643,6 +655,7 @@
    }
+ }
  
-   static jlong fast_thread_cpu_time(clockid_t clockid);
-+#endif
++
+ // cleanup stale shared memory resources
+ //
+ // This method attempts to remove all stale shared memory files in
+@@ -655,7 +668,7 @@
+ static void cleanup_sharedmem_resources(const char* dirname) {
  
-   // Stack repair handling
+   int saved_cwd_fd;
+-  // open the directory and set the current working directory to it
++  // open the directory
+   DIR* dirp = open_directory_secure_cwd(dirname, &saved_cwd_fd);
+   if (dirp == NULL) {
+     // directory doesn't exist or is insecure, so there is nothing to cleanup
+@@ -681,7 +694,6 @@
+     if (pid == 0) {
  
---- hotspot/src/os/bsd/vm/os_bsd.inline.hpp
-+++ hotspot/src/os/bsd/vm/os_bsd.inline.hpp
-@@ -86,7 +86,15 @@
+       if (strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0) {
+-
+         // attempt to remove all unexpected files, except "." and ".."
+         unlink(entry->d_name);
+       }
+@@ -705,7 +717,6 @@
+     //
+     if ((pid == os::current_process_id()) ||
+         (kill(pid, 0) == OS_ERR && (errno == ESRCH || errno == EPERM))) {
+-
+         unlink(entry->d_name);
+     }
+     errno = 0;
+@@ -914,7 +925,6 @@
  
- inline bool os::allocate_stack_guard_pages() {
-   assert(uses_stack_guard_pages(), "sanity check");
-+#if !defined(__MidnightBSD__) || __FreeBSD__ < 5
-+  // 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;
-+#else
-+  // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks.
-+  // Must 'allocate' them or guard pages are ignored.
-   return true;
-+#endif
- }
+   char* dirname = get_user_tmp_dir(user_name);
+   char* filename = get_sharedmem_filename(dirname, vmid);
+-
+   // get the short filename
+   char* short_filename = strrchr(filename, '/');
+   if (short_filename == NULL) {
+--- hotspot/src/os/bsd/vm/threadCritical_bsd.cpp
++++ hotspot/src/os/bsd/vm/threadCritical_bsd.cpp
+@@ -33,35 +33,36 @@
+ // See threadCritical.hpp for details of this class.
+ //
  
+-static pthread_t             tc_owner = 0;
+-static pthread_mutex_t       tc_mutex = PTHREAD_MUTEX_INITIALIZER;
+-static int                   tc_count = 0;
++static pthread_mutex_t       tc_mutex;
++static pthread_mutexattr_t   tc_attr;
++static bool                  initialized = false;
  
-@@ -118,7 +126,7 @@
+ void ThreadCritical::initialize() {
++  int ret;
++  ret = pthread_mutexattr_init(&tc_attr);
++  guarantee(ret == 0, "fatal error with pthread_mutexattr_init()");
++  ret = pthread_mutexattr_settype(&tc_attr, PTHREAD_MUTEX_RECURSIVE);
++  guarantee(ret == 0, "fatal error with pthread_mutexattr_settype()");
++  ret = pthread_mutex_init(&tc_mutex, &tc_attr);
++  guarantee(ret == 0, "fatal error with pthread_mutex_init()");
++  initialized = true;
  }
  
- inline jlong os::lseek(int fd, jlong offset, int whence) {
--  return (jlong) ::lseek64(fd, offset, whence);
-+  return (jlong) ::lseek(fd, (off_t)offset, whence);
+ void ThreadCritical::release() {
++  pthread_mutex_destroy(&tc_mutex);
++  pthread_mutexattr_destroy(&tc_attr);
  }
  
- inline int os::fsync(int fd) {
-@@ -130,7 +138,7 @@
+ ThreadCritical::ThreadCritical() {
+-  pthread_t self = pthread_self();
+-  if (self != tc_owner) {
+-    int ret = pthread_mutex_lock(&tc_mutex);
+-    guarantee(ret == 0, "fatal error with pthread_mutex_lock()");
+-    assert(tc_count == 0, "Lock acquired with illegal reentry count.");
+-    tc_owner = self;
+-  }
+-  tc_count++;
++  if (initialized)
++    pthread_mutex_lock(&tc_mutex);
++  else
++    assert(Threads::number_of_threads() == 0, "valid only during initialization");
  }
  
- inline int os::ftruncate(int fd, jlong length) {
--  return ::ftruncate64(fd, length);
-+  return ::ftruncate(fd, (off_t)length);
+ ThreadCritical::~ThreadCritical() {
+-  assert(tc_owner == pthread_self(), "must have correct owner");
+-  assert(tc_count > 0, "must have correct count");
+-
+-  tc_count--;
+-  if (tc_count == 0) {
+-    tc_owner = 0;
+-    int ret = pthread_mutex_unlock(&tc_mutex);
+-    guarantee(ret == 0, "fatal error with pthread_mutex_unlock()");
+-  }
++  if (initialized)
++    pthread_mutex_unlock(&tc_mutex);
++  else
++    assert(Threads::number_of_threads() == 0, "valid only during initialization");
  }
- 
- inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf)
 --- hotspot/src/os/bsd/vm/vmError_bsd.cpp
 +++ hotspot/src/os/bsd/vm/vmError_bsd.cpp
-@@ -34,6 +34,12 @@
+@@ -33,30 +33,50 @@
+ #include <sys/syscall.h>
  #include <unistd.h>
  #include <signal.h>
- 
 +#ifdef __MidnightBSD__
-+#define	GDB_LAUNCHER	"gdb /proc/%d/file %d"
-+#else
-+#define	GDB_LAUNCHER	"gdb /proc/%d/exe %d"
++#include <limits.h>
++#include <sys/sysctl.h>
 +#endif
 +
++#define GDB_CMD "gdb"
++
++static void set_debugger(char *buf, int buflen) {
++  int pid = os::current_process_id();
++#ifdef __MidnightBSD__
++  char cmd[PATH_MAX+1];
++  int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, pid };
++  size_t len = sizeof(cmd);
++  if (sysctl(name, 4, cmd, &len, NULL, 0) == 0 && len > 0) {
++    cmd[len] = '\0';
++    jio_snprintf(buf, buflen, "%s %s %d", GDB_CMD, cmd, pid);
++  } else
++#endif
++  jio_snprintf(buf, buflen, "%s /proc/%d/file %d", GDB_CMD, pid, pid);
++}
+ 
  void VMError::show_message_box(char *buf, int buflen) {
    bool yes;
    do {
-@@ -44,7 +50,7 @@
+-    error_string(buf, buflen);
+-    int len = (int)strlen(buf);
++    intx tid = os::current_thread_id();
++    set_debugger(buf, buflen);
++    int len = (int)strlen(buf) + 1;
++    char *msg = &buf[len];
++    error_string(msg, buflen - len);
++    len += (int)strlen(msg);
+     char *p = &buf[len];
+ 
      jio_snprintf(p, buflen - len,
                 "\n\n"
                 "Do you want to debug the problem?\n\n"
 -               "To debug, run 'gdb /proc/%d/exe %d'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n"
-+               "To debug, run '" GDB_LAUNCHER "'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n"
-                "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
+-               "Enter 'yes' to launch gdb automatically (PATH must include gdb)\n"
++               "To debug, run '%s'; then switch to thread " INTX_FORMAT " (" INTPTR_FORMAT ")\n"
++               "Enter 'yes' to launch " GDB_CMD " automatically (PATH must include " GDB_CMD ")\n"
                 "Otherwise, press RETURN to abort...",
-                os::current_process_id(), os::current_process_id(),
-@@ -54,7 +60,7 @@
+-               os::current_process_id(), os::current_process_id(),
+-               os::current_thread_id(), os::current_thread_id());
++               buf, tid, tid);
  
+-    yes = os::message_box("Unexpected Error", buf);
++    yes = os::message_box("Unexpected Error", msg);
+ 
      if (yes) {
        // yes, user asked VM to launch debugger
 -      jio_snprintf(buf, buflen, "gdb /proc/%d/exe %d",
-+      jio_snprintf(buf, buflen, GDB_LAUNCHER,
-                    os::current_process_id(), os::current_process_id());
- 
+-                   os::current_process_id(), os::current_process_id());
+-
        os::fork_and_exec(buf);
+       yes = false;
+     }
 --- hotspot/src/os/posix/launcher/java_md.c
 +++ hotspot/src/os/posix/launcher/java_md.c
-@@ -35,20 +35,30 @@
+@@ -35,6 +35,9 @@
  #include <sys/stat.h>
  #include <unistd.h>
  #include <sys/types.h>
-+#ifndef _SC_PHYS_PAGES
++#ifdef __MidnightBSD__
 +#include <sys/sysctl.h>
 +#endif
  
  #ifndef GAMMA
  #include "manifest_info.h"
- #include "version_comp.h"
- #endif
- 
--#ifdef __linux__
-+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
- #include <pthread.h>
- #else
- #include <thread.h>
- #endif
- 
-+#ifdef __APPLE__
-+#define JVM_DLL "libjvm.dylib"
-+#define JAVA_DLL "libjava.dylib"
-+#define LD_LIBRARY_PATH "DYLD_LIBRARY_PATH"
-+#else
- #define JVM_DLL "libjvm.so"
- #define JAVA_DLL "libjava.so"
-+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
-+#endif
- 
- #ifndef GAMMA   /* launcher.make defines ARCH */
- /*
-@@ -89,7 +99,7 @@
+@@ -96,8 +99,8 @@
   *      A collection of useful strings. One should think of these as #define
   *      entries, but actual strings can be more efficient (with many compilers).
   */
 -#ifdef __linux__
+-static const char *system_dir   = "/usr/java";
 +#if defined(__linux__) || defined(_ALLBSD_SOURCE)
- static const char *system_dir   = "/usr/java";
++static const char *system_dir   = "%%JAVA_HOME%%";
  static const char *user_dir     = "/java";
  #else /* Solaris */
-@@ -423,10 +433,10 @@
-        * If not on Solaris, assume only a single LD_LIBRARY_PATH
-        * variable.
-        */
--      runpath = getenv("LD_LIBRARY_PATH");
-+      runpath = getenv(LD_LIBRARY_PATH);
- #endif /* __sun */
- 
--#ifdef __linux
-+#if defined(__linux)
-       /*
-        * On linux, if a binary is running as sgid or suid, glibc sets
-        * LD_LIBRARY_PATH to the empty string for security purposes.  (In
-@@ -442,6 +452,22 @@
-       if((getgid() != getegid()) || (getuid() != geteuid()) ) {
-         return;
-       }
-+#elif defined(_ALLBSD_SOURCE)
-+      /*
-+       * On BSD, if a binary is running as sgid or suid, libc sets
-+       * LD_LIBRARY_PATH to the empty string for security purposes.  (In
-+       * contrast, on Solaris the LD_LIBRARY_PATH variable for a
-+       * privileged binary does not lose its settings; but the dynamic
-+       * linker does apply more scrutiny to the path.) The launcher uses
-+       * the value of LD_LIBRARY_PATH to prevent an exec loop.
-+       * Therefore, if we are running sgid or suid, this function's
-+       * setting of LD_LIBRARY_PATH will be ineffective and we should
-+       * return from the function now.  Getting the right libraries to
-+       * be found must be handled through other mechanisms.
-+       */
-+      if(issetugid()) {
-+        return;
-+      }
- #endif
- 
-       /* runpath contains current effective LD_LIBRARY_PATH setting */
-@@ -450,7 +476,7 @@
-       new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) +
-                               2*strlen(jrepath) + 2*strlen(arch) +
-                               strlen(jvmpath) + 52);
--      newpath = new_runpath + strlen("LD_LIBRARY_PATH=");
-+      newpath = new_runpath + strlen(LD_LIBRARY_PATH "=");
- 
- 
-       /*
-@@ -465,7 +491,7 @@
- 
-         /* jvmpath, ((running != wanted)?((wanted==64)?"/"LIBARCH64NAME:"/.."):""), */
- 
--        sprintf(new_runpath, "LD_LIBRARY_PATH="
-+        sprintf(new_runpath, LD_LIBRARY_PATH "="
-                 "%s:"
-                 "%s/lib/%s:"
-                 "%s/../lib/%s",
-@@ -503,7 +529,7 @@
+ static const char *system_dir   = "/usr/jdk";
+@@ -526,7 +529,7 @@
         * LD_LIBRARY_PATH.  Note that this prevents any possible infinite
         * loop of execv() because we test for the prefix, above.
         */
@@ -6046,40 +2066,26 @@
          strcat(new_runpath, ":");
          strcat(new_runpath, runpath);
        }
-@@ -792,7 +818,7 @@
- jboolean
- GetApplicationHome(char *buf, jint bufsize)
- {
--#ifdef __linux__
-+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
-     char *execname = GetExecname();
-     if (execname) {
-         strncpy(buf, execname, bufsize-1);
-@@ -961,9 +987,13 @@
-             }
-         }
-     }
--#elif defined(__linux__)
-+#elif defined(__linux__) || defined(_ALLBSD_SOURCE)
-     {
-+#ifdef __MidnightBSD__
-+        const char* self = "/proc/curproc/file";
-+#else
-         const char* self = "/proc/self/exe";
-+#endif
-         char buf[PATH_MAX+1];
-         int len = readlink(self, buf, PATH_MAX);
-         if (len >= 0) {
-@@ -971,7 +1001,7 @@
+@@ -1002,7 +1005,17 @@
              exec_path = JLI_StringDup(buf);
          }
      }
 -#else /* !__sun && !__linux */
-+#else /* !__sun && !__linux && !_ALLBSD_SOURCE */
++#elif defined(__MidnightBSD__)
++    {
++        char buf[PATH_MAX+1];
++        int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
++        size_t len = sizeof(buf);
++        if (sysctl(name, 4, buf, &len, NULL, 0) == 0 && len > 0) {
++            buf[len] = '\0';
++            exec_path = JLI_StringDup(buf);
++        }
++    }
++#else /* !__sun && !__linux && !__MidnightBSD__ */
      {
          /* Not implemented */
      }
-@@ -1069,6 +1099,7 @@
+@@ -1100,6 +1113,7 @@
  /* Compute physical memory by asking the OS */
  uint64_t
  physical_memory(void) {
@@ -6087,7 +2093,7 @@
    const uint64_t pages     = (uint64_t) sysconf(_SC_PHYS_PAGES);
    const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);
    const uint64_t result    = pages * page_size;
-@@ -1080,6 +1111,28 @@
+@@ -1111,6 +1125,28 @@
             "  physical memory: " UINT64_FORMAT " (%.3fGB)\n",
             pages, page_size, result, result / (double) GB);
    }
@@ -6116,74 +2122,43 @@
    return result;
  }
  
-@@ -1175,7 +1228,7 @@
+@@ -1271,7 +1307,7 @@
+ #endif
+ }
  
+-#endif /* __linux__ && i586 */
++#endif /* (__linux__ || _ALLBSD_SOURCE) && i586 */
+ 
+ #ifdef i586
+ /*
+@@ -1450,7 +1486,7 @@
+ 
  #endif /* __sun && i586 */
  
 -#if defined(__linux__) && defined(i586)
 +#if (defined(__linux__) || defined(_ALLBSD_SOURCE)) && defined(i586)
  
- /*
-  * A utility method for asking the CPU about itself.
-@@ -1240,7 +1293,7 @@
- #endif
+ /* The definition of a server-class machine for linux-i586 */
+ jboolean
+@@ -1481,7 +1517,7 @@
+   return result;
  }
  
 -#endif /* __linux__ && i586 */
 +#endif /* (__linux__ || _ALLBSD_SOURCE) && i586 */
  
- #ifdef i586
- /*
-@@ -1452,6 +1505,39 @@
+ #if defined(_ALLBSD_SOURCE) && defined(i586)
  
- #endif /* __linux__ && i586 */
- 
-+#if defined(_ALLBSD_SOURCE) && defined(i586)
-+
-+/* The definition of a server-class machine for bsd-i586 */
-+jboolean
-+bsd_i586_ServerClassMachine(void) {
-+  jboolean            result            = JNI_FALSE;
-+  /* How big is a server class machine? */
-+  const unsigned long server_processors = 2UL;
-+  const uint64_t      server_memory     = 2UL * GB;
-+  /*
-+   * We seem not to get our full complement of memory.
-+   *     We allow some part (1/8?) of the memory to be "missing",
-+   *     based on the sizes of DIMMs, and maybe graphics cards.
-+   */
-+  const uint64_t      missing_memory    = 256UL * MB;
-+  const uint64_t      actual_memory     = physical_memory();
-+
-+  /* Is this a server class machine? */
-+  if (actual_memory >= (server_memory - missing_memory)) {
-+    const unsigned long actual_processors = physical_processors();
-+    if (actual_processors >= server_processors) {
-+      result = JNI_TRUE;
-+    }
-+  }
-+  if (_launcher_debug) {
+@@ -1508,7 +1544,7 @@
+     }
+   }
+   if (_launcher_debug) {
+-    printf("linux_" LIBARCHNAME "_ServerClassMachine: %s\n",
 +    printf("bsd_" LIBARCHNAME "_ServerClassMachine: %s\n",
-+           (result == JNI_TRUE ? "true" : "false"));
-+  }
-+  return result;
-+}
-+
-+#endif /* _ALLBSD_SOURCE && i586 */
-+
- /* Dispatch to the platform-specific definition of "server-class" */
- jboolean
- ServerClassMachine(void) {
-@@ -1466,6 +1552,8 @@
-   result = solaris_i586_ServerClassMachine();
- #elif defined(__linux__) && defined(i586)
-   result = linux_i586_ServerClassMachine();
-+#elif defined(_ALLBSD_SOURCE) && defined(i586)
-+  result = bsd_i586_ServerClassMachine();
- #else
-   if (_launcher_debug) {
-     printf("ServerClassMachine: returns default value of %s\n",
-@@ -1606,7 +1694,7 @@
+            (result == JNI_TRUE ? "true" : "false"));
+   }
+   return result;
+@@ -1672,7 +1708,7 @@
      while (dp != NULL) {
          cp = strchr(dp, (int)':');
          if (cp != NULL)
@@ -6192,16 +2167,7 @@
          if ((target = ProcessDir(info, dp)) != NULL)
              break;
          dp = cp;
-@@ -1821,7 +1909,7 @@
- int
- ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
-     int rslt;
--#ifdef __linux__
-+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
-     pthread_t tid;
-     pthread_attr_t attr;
-     pthread_attr_init(&attr);
-@@ -1865,8 +1953,8 @@
+@@ -1931,8 +1967,8 @@
  #define MAX_PID_STR_SZ   20
  
  void SetJavaLauncherPlatformProps() {
@@ -6212,2481 +2178,1020 @@
      const char *substr = "-Dsun.java.launcher.pid=";
      char *pid_prop_str = (char *)JLI_MemAlloc(strlen(substr) + MAX_PID_STR_SZ + 1);
      sprintf(pid_prop_str, "%s%d", substr, getpid());
---- hotspot/src/os/posix/launcher/launcher.script
-+++ hotspot/src/os/posix/launcher/launcher.script
-@@ -1,4 +1,4 @@
--#!/bin/bash
-+#!/bin/sh
+--- hotspot/src/os/posix/vm/os_posix.cpp
++++ hotspot/src/os/posix/vm/os_posix.cpp
+@@ -33,19 +33,18 @@
  
- # Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
- # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
---- hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s
-+++ hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s
-@@ -21,6 +21,17 @@
- # questions.
- # 
+ // Check core dump limit and report possible place where core can be found
+ void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) {
++  int n;
+   struct rlimit rlim;
+-  static char cwd[O_BUFLEN];
+   bool success;
  
-+ 
-+#ifdef __APPLE__
-+# Darwin uses _ prefixed global symbols
-+#define SYMBOL(s) _ ## s
-+#define ELF_TYPE(name, description)
-+#else
-+#define SYMBOL(s) s
-+#define ELF_TYPE(name, description) .type name,description
-+#endif
-+
-+	.globl SYMBOL(fixcw)
- 	
-         # NOTE WELL!  The _Copy functions are called directly
- 	# from server-compiler-generated code via CallLeafNoFP,
-@@ -28,42 +39,62 @@
- 	# point or use it in the same manner as does the server
- 	# compiler.
- 	
--        .globl _Copy_conjoint_bytes
--        .globl _Copy_arrayof_conjoint_bytes
--        .globl _Copy_conjoint_jshorts_atomic
--	.globl _Copy_arrayof_conjoint_jshorts
--        .globl _Copy_conjoint_jints_atomic
--        .globl _Copy_arrayof_conjoint_jints
--	.globl _Copy_conjoint_jlongs_atomic
--	.globl _mmx_Copy_arrayof_conjoint_jshorts
-+        .globl SYMBOL(_Copy_conjoint_bytes)
-+        .globl SYMBOL(_Copy_arrayof_conjoint_bytes)
-+        .globl SYMBOL(_Copy_conjoint_jshorts_atomic)
-+	.globl SYMBOL(_Copy_arrayof_conjoint_jshorts)
-+        .globl SYMBOL(_Copy_conjoint_jints_atomic)
-+        .globl SYMBOL(_Copy_arrayof_conjoint_jints)
-+	.globl SYMBOL(_Copy_conjoint_jlongs_atomic)
-+	.globl SYMBOL(_mmx_Copy_arrayof_conjoint_jshorts)
+-  get_current_directory(cwd, sizeof(cwd));
++  n = get_core_path(buffer, bufferSize);
  
--        .globl _Atomic_cmpxchg_long
--        .globl _Atomic_move_long
-+        .globl SYMBOL(_Atomic_cmpxchg_long)
-+        .globl SYMBOL(_Atomic_move_long)
+   if (getrlimit(RLIMIT_CORE, &rlim) != 0) {
+-    jio_snprintf(buffer, bufferSize, "%s/core or core.%d (may not exist)", cwd, current_process_id());
++    jio_snprintf(buffer + n, bufferSize - n, " (may not exist)");
+     success = true;
+   } else {
+     switch(rlim.rlim_cur) {
+       case RLIM_INFINITY:
+-        jio_snprintf(buffer, bufferSize, "%s/core or core.%d", cwd, current_process_id());
+         success = true;
+         break;
+       case 0:
+@@ -53,7 +52,7 @@
+         success = false;
+         break;
+       default:
+-        jio_snprintf(buffer, bufferSize, "%s/core or core.%d (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", cwd, current_process_id(), (unsigned long)(rlim.rlim_cur >> 10));
++        jio_snprintf(buffer + n, bufferSize - n, " (max size %lu kB). To ensure a full core dump, try \"ulimit -c unlimited\" before starting Java again", (unsigned long)(rlim.rlim_cur >> 10));
+         success = true;
+         break;
+     }
+--- hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp
++++ hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp
+@@ -42,7 +42,6 @@
+ #endif // AMD64
  
- 	.text
+ define_pd_global(intx, CompilerThreadStackSize,  0);
+-define_pd_global(intx, SurvivorRatio,            8);
  
--        .globl  SafeFetch32, Fetch32PFI, Fetch32Resume
--        .globl  SafeFetchN
-+# Support for void os::Solaris::init_thread_fpu_state() in os_solaris_i486.cpp
-+# Set fpu to 53 bit precision.  This happens too early to use a stub.
-+# ported from solaris_x86_32.s
-+#ifdef __APPLE__
-+        .align   4
-+#else
-+	.align   16
-+#endif
-+SYMBOL(fixcw):
-+	pushl    $0x27f
-+	fldcw    0(%esp)
-+	popl     %eax
-+	ret
-+
-+#ifdef __APPLE__
-+        .align   4
-+#else
-+        .align   16
-+#endif
-+
-+        .globl  SYMBOL(SafeFetch32), SYMBOL(Fetch32PFI), SYMBOL(Fetch32Resume)
-+        .globl  SYMBOL(SafeFetchN)
-         ## TODO: avoid exposing Fetch32PFI and Fetch32Resume.
-         ## Instead, the signal handler would call a new SafeFetchTriage(FaultingEIP)
-         ## routine to vet the address.  If the address is the faulting LD then
-         ## SafeFetchTriage() would return the resume-at EIP, otherwise null.
--	.type    SafeFetch32, at function
-+	ELF_TYPE(SafeFetch32, at function)
-         .p2align 4,,15
--SafeFetch32:
--SafeFetchN:
-+SYMBOL(SafeFetch32):
-+SYMBOL(SafeFetchN):
-          movl    0x8(%esp), %eax
-          movl    0x4(%esp), %ecx
--Fetch32PFI:
-+SYMBOL(Fetch32PFI):
-          movl    (%ecx), %eax
--Fetch32Resume:
-+SYMBOL(Fetch32Resume):
-          ret
+ define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
  
+--- hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp
++++ hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp
+@@ -29,8 +29,10 @@
+ // constants required by the Serviceability Agent. This file is
+ // referenced by vmStructs.cpp.
  
--        .globl  SpinPause
--	.type   SpinPause, at function
-+        .globl  SYMBOL(SpinPause)
-+	ELF_TYPE(SpinPause, at function)
-         .p2align 4,,15
--SpinPause:
-+SYMBOL(SpinPause):
-         rep
-         nop
-         movl    $1, %eax
-@@ -73,8 +104,8 @@
-         #                                       void* to,
-         #                                       size_t count)
-         .p2align 4,,15
--	.type    _Copy_conjoint_bytes, at function
--_Copy_conjoint_bytes:
-+	ELF_TYPE(_Copy_conjoint_bytes, at function)
-+SYMBOL(_Copy_conjoint_bytes):
-         pushl    %esi
-         movl     4+12(%esp),%ecx      # count
-         pushl    %edi
-@@ -181,8 +212,8 @@
-         #
-         # Same as _Copy_conjoint_bytes, except no source alignment check.
-         .p2align 4,,15
--	.type    _Copy_arrayof_conjoint_bytes, at function
--_Copy_arrayof_conjoint_bytes:
-+	ELF_TYPE(_Copy_arrayof_conjoint_bytes, at function)
-+SYMBOL(_Copy_arrayof_conjoint_bytes):
-         pushl    %esi
-         movl     4+12(%esp),%ecx      # count
-         pushl    %edi
-@@ -241,7 +272,7 @@
-         jbe      2f                   # <= 32 dwords
-         rep;     smovl
-         jmp      4f
--	.=.+8
-+	.skip 8
- 2:      subl     %esi,%edi
-         .p2align 4,,15
- 3:      movl     (%esi),%edx
-@@ -269,8 +300,8 @@
-         #                                                void* to,
-         #                                                size_t count)
-         .p2align 4,,15
--	.type    _Copy_conjoint_jshorts_atomic, at function
--_Copy_conjoint_jshorts_atomic:
-+	ELF_TYPE(_Copy_conjoint_jshorts_atomic, at function)
-+SYMBOL(_Copy_conjoint_jshorts_atomic):
-         pushl    %esi
-         movl     4+12(%esp),%ecx      # count
-         pushl    %edi
-@@ -356,8 +387,8 @@
-         #                                                 void* to,
-         #                                                 size_t count)
-         .p2align 4,,15
--	.type    _Copy_arrayof_conjoint_jshorts, at function
--_Copy_arrayof_conjoint_jshorts:
-+	ELF_TYPE(_Copy_arrayof_conjoint_jshorts, at function)
-+SYMBOL(_Copy_arrayof_conjoint_jshorts):
-         pushl    %esi
-         movl     4+12(%esp),%ecx      # count
-         pushl    %edi
-@@ -378,7 +409,7 @@
-         rep;     smovl
-         jmp      4f 
-         # copy aligned dwords
--        .=.+5
-+        .skip 5
- 2:      subl     %esi,%edi 
-         .p2align 4,,15
- 3:      movl     (%esi),%edx
-@@ -433,10 +464,10 @@
-         # Equivalent to
-         #   arrayof_conjoint_jints
-         .p2align 4,,15
--	.type    _Copy_conjoint_jints_atomic, at function
--	.type    _Copy_arrayof_conjoint_jints, at function
--_Copy_conjoint_jints_atomic:
--_Copy_arrayof_conjoint_jints:
-+	ELF_TYPE(_Copy_conjoint_jints_atomic, at function)
-+	ELF_TYPE(_Copy_arrayof_conjoint_jints, at function)
-+SYMBOL(_Copy_conjoint_jints_atomic):
-+SYMBOL(_Copy_arrayof_conjoint_jints):
-         pushl    %esi
-         movl     4+12(%esp),%ecx      # count
-         pushl    %edi
-@@ -454,7 +485,7 @@
-         popl     %edi
-         popl     %esi
-         ret
--        .=.+10
-+        .skip 10
- 2:      subl     %esi,%edi
-         jmp      4f
-         .p2align 4,,15
-@@ -498,7 +529,7 @@
-         #
-         # count treated as signed
-         #
--        # if (from > to) {
-+        # // if (from > to) {
-         #   while (--count >= 0) {
-         #     *to++ = *from++;
-         #   }
-@@ -508,8 +539,8 @@
-         #   }
-         # }
-         .p2align 4,,15
--	.type    _Copy_conjoint_jlongs_atomic, at function
--_Copy_conjoint_jlongs_atomic:
-+	ELF_TYPE(_Copy_conjoint_jlongs_atomic, at function)
-+SYMBOL(_Copy_conjoint_jlongs_atomic):
-         movl     4+8(%esp),%ecx       # count
-         movl     4+0(%esp),%eax       # from
-         movl     4+4(%esp),%edx       # to
-@@ -537,8 +568,8 @@
-         #                                                 void* to,
-         #                                                 size_t count)
-         .p2align 4,,15
--	.type    _mmx_Copy_arrayof_conjoint_jshorts, at function
--_mmx_Copy_arrayof_conjoint_jshorts:
-+	ELF_TYPE(_mmx_Copy_arrayof_conjoint_jshorts, at function)
-+SYMBOL(_mmx_Copy_arrayof_conjoint_jshorts):
-         pushl    %esi
-         movl     4+12(%esp),%ecx
-         pushl    %edi
-@@ -636,8 +667,8 @@
-         #                                   bool is_MP)
-         #
-         .p2align 4,,15
--	.type    _Atomic_cmpxchg_long, at function
--_Atomic_cmpxchg_long:
-+	ELF_TYPE(_Atomic_cmpxchg_long, at function)
-+SYMBOL(_Atomic_cmpxchg_long):
-                                    #  8(%esp) : return PC
-         pushl    %ebx              #  4(%esp) : old %ebx
-         pushl    %edi              #  0(%esp) : old %edi
-@@ -658,8 +689,8 @@
-         # Support for jlong Atomic::load and Atomic::store.
-         # void _Atomic_move_long(volatile jlong* src, volatile jlong* dst)
-         .p2align 4,,15
--	.type    _Atomic_move_long, at function
--_Atomic_move_long:
-+	ELF_TYPE(_Atomic_move_long, at function)
-+SYMBOL(_Atomic_move_long):
-         movl     4(%esp), %eax   # src
-         fildll    (%eax)
-         movl     8(%esp), %eax   # dest
---- hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s
-+++ hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s
-@@ -21,6 +21,14 @@
- # questions.
- #
+-#ifdef __APPLE__
++#if defined(__APPLE__)
+ #define OS_THREAD_ID_TYPE thread_t
++#elif defined(__MidnightBSD__)
++#define OS_THREAD_ID_TYPE pid_t
+ #else
+ #define OS_THREAD_ID_TYPE pthread_t
+ #endif
+@@ -46,17 +48,31 @@
+   last_entry()
  
-+#ifdef __APPLE__
-+# Darwin uses _ prefixed global symbols
-+#define SYMBOL(s) _ ## s
-+#define ELF_TYPE(name, description)
+ 
++#ifdef __MidnightBSD__
+ #define VM_TYPES_OS_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type, last_entry) \
+                                                                           \
+   /**********************/                                                \
+   /* Posix Thread IDs   */                                                \
+   /**********************/                                                \
+                                                                           \
+-  declare_unsigned_integer_type(thread_t)                                 \
++  declare_integer_type(pid_t)                                             \
+   declare_unsigned_integer_type(pthread_t)                                \
+                                                                           \
+   /* This must be the last entry, and must be present */                  \
+   last_entry()
 +#else
-+#define SYMBOL(s) s
-+#define ELF_TYPE(name, description) .type name,description
++#define VM_TYPES_OS_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type, last_entry) \
++                                                                          \
++  /**********************/                                                \
++  /* Posix Thread IDs   */                                                \
++  /**********************/                                                \
++                                                                          \
++  declare_unsigned_integer_type(OS_THREAD_ID_TYPE)                        \
++  declare_unsigned_integer_type(pthread_t)                                \
++                                                                          \
++  /* This must be the last entry, and must be present */                  \
++  last_entry()
 +#endif
  
-         # NOTE WELL!  The _Copy functions are called directly
- 	# from server-compiler-generated code via CallLeafNoFP,
-@@ -28,42 +36,54 @@
- 	# point or use it in the same manner as does the server
- 	# compiler.
- 	
--        .globl _Copy_arrayof_conjoint_bytes
--	.globl _Copy_arrayof_conjoint_jshorts
--        .globl _Copy_conjoint_jshorts_atomic
--        .globl _Copy_arrayof_conjoint_jints
--        .globl _Copy_conjoint_jints_atomic
--        .globl _Copy_arrayof_conjoint_jlongs
--        .globl _Copy_conjoint_jlongs_atomic
-+        .globl SYMBOL(_Copy_arrayof_conjoint_bytes)
-+	.globl SYMBOL(_Copy_arrayof_conjoint_jshorts)
-+        .globl SYMBOL(_Copy_conjoint_jshorts_atomic)
-+        .globl SYMBOL(_Copy_arrayof_conjoint_jints)
-+        .globl SYMBOL(_Copy_conjoint_jints_atomic)
-+        .globl SYMBOL(_Copy_arrayof_conjoint_jlongs)
-+        .globl SYMBOL(_Copy_conjoint_jlongs_atomic)
+ #define VM_INT_CONSTANTS_OS_CPU(declare_constant, declare_preprocessor_constant, declare_c1_constant, declare_c2_constant, declare_c2_preprocessor_constant, last_entry) \
+                                                                         \
+--- hotspot/src/share/vm/adlc/arena.cpp
++++ hotspot/src/share/vm/adlc/arena.cpp
+@@ -24,7 +24,7 @@
  
- 	.text
+ #include "adlc.hpp"
  
--        .globl SafeFetch32, Fetch32PFI, Fetch32Resume
-+        .globl SYMBOL(SafeFetch32), SYMBOL(Fetch32PFI), SYMBOL(Fetch32Resume)
-+#ifdef __APPLE__
-+        .align  4
-+#else
-         .align  16
--        .type   SafeFetch32, at function
-+#endif
-+        ELF_TYPE(SafeFetch32, at function)
-         // Prototype: int SafeFetch32 (int * Adr, int ErrValue) 
--SafeFetch32:
-+SYMBOL(SafeFetch32):
-         movl    %esi, %eax
--Fetch32PFI:
-+SYMBOL(Fetch32PFI):
-         movl    (%rdi), %eax
--Fetch32Resume:
-+SYMBOL(Fetch32Resume):
-         ret
+-void* Chunk::operator new(size_t requested_size, size_t length) {
++void* Chunk::operator new(size_t requested_size, size_t length) throw() {
+   return CHeapObj::operator new(requested_size + length);
+ }
  
--        .globl SafeFetchN, FetchNPFI, FetchNResume
-+        .globl SYMBOL(SafeFetchN), SYMBOL(FetchNPFI), SYMBOL(FetchNResume)
-+#ifdef __APPLE__
-+        .align  4
-+#else
-         .align  16
--        .type   SafeFetchN, at function
-+#endif
-+        ELF_TYPE(SafeFetchN, at function)
-         // Prototype: intptr_t SafeFetchN (intptr_t * Adr, intptr_t ErrValue) 
--SafeFetchN:
-+SYMBOL(SafeFetchN):
-         movq    %rsi, %rax
--FetchNPFI:
-+SYMBOL(FetchNPFI):
-         movq    (%rdi), %rax
--FetchNResume:
-+SYMBOL(FetchNResume):
-         ret
+@@ -163,7 +163,7 @@
+ //-----------------------------------------------------------------------------
+ // CHeapObj
  
--        .globl SpinPause
--        .align 16
--        .type  SpinPause, at function
--SpinPause:
-+        .globl SYMBOL(SpinPause)
-+#ifdef __APPLE__
-+        .align  4
-+#else
-+        .align  16
-+#endif
-+        ELF_TYPE(SpinPause, at function)
-+SYMBOL(SpinPause):
-         rep
-         nop
-         movq   $1, %rax
-@@ -77,8 +97,8 @@
-         # rdx - count, treated as ssize_t
-         #
-         .p2align 4,,15
--	.type    _Copy_arrayof_conjoint_bytes, at function
--_Copy_arrayof_conjoint_bytes:
-+	ELF_TYPE(_Copy_arrayof_conjoint_bytes, at function)
-+SYMBOL(_Copy_arrayof_conjoint_bytes):
-         movq     %rdx,%r8             # byte count
-         shrq     $3,%rdx              # qword count
-         cmpq     %rdi,%rsi
-@@ -179,10 +199,10 @@
-         # rdx - count, treated as ssize_t
-         #
-         .p2align 4,,15
--	.type    _Copy_arrayof_conjoint_jshorts, at function
--	.type    _Copy_conjoint_jshorts_atomic, at function
--_Copy_arrayof_conjoint_jshorts:
--_Copy_conjoint_jshorts_atomic:
-+	ELF_TYPE(_Copy_arrayof_conjoint_jshorts, at function)
-+	ELF_TYPE(_Copy_conjoint_jshorts_atomic, at function)
-+SYMBOL(_Copy_arrayof_conjoint_jshorts):
-+SYMBOL(_Copy_conjoint_jshorts_atomic):
-         movq     %rdx,%r8             # word count
-         shrq     $2,%rdx              # qword count
-         cmpq     %rdi,%rsi
-@@ -269,10 +289,10 @@
-         # rdx - count, treated as ssize_t
-         #
-         .p2align 4,,15
--	.type    _Copy_arrayof_conjoint_jints, at function
--	.type    _Copy_conjoint_jints_atomic, at function
--_Copy_arrayof_conjoint_jints:
--_Copy_conjoint_jints_atomic:
-+	ELF_TYPE(_Copy_arrayof_conjoint_jints, at function)
-+	ELF_TYPE(_Copy_conjoint_jints_atomic, at function)
-+SYMBOL(_Copy_arrayof_conjoint_jints):
-+SYMBOL(_Copy_conjoint_jints_atomic):
-         movq     %rdx,%r8             # dword count
-         shrq     %rdx                 # qword count
-         cmpq     %rdi,%rsi
-@@ -348,10 +368,10 @@
-         # rdx - count, treated as ssize_t
-         #
-         .p2align 4,,15
--	.type    _Copy_arrayof_conjoint_jlongs, at function
--	.type    _Copy_conjoint_jlongs_atomic, at function
--_Copy_arrayof_conjoint_jlongs:
--_Copy_conjoint_jlongs_atomic:
-+	ELF_TYPE(_Copy_arrayof_conjoint_jlongs, at function)
-+	ELF_TYPE(_Copy_conjoint_jlongs_atomic, at function)
-+SYMBOL(_Copy_arrayof_conjoint_jlongs):
-+SYMBOL(_Copy_conjoint_jlongs_atomic):
-         cmpq     %rdi,%rsi
-         leaq     -8(%rdi,%rdx,8),%rax # from + count*8 - 8
-         jbe      acl_CopyRight
---- hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp
-+++ hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp
-@@ -25,7 +25,33 @@
- #ifndef OS_CPU_BSD_X86_VM_BYTES_BSD_X86_INLINE_HPP
- #define OS_CPU_BSD_X86_VM_BYTES_BSD_X86_INLINE_HPP
+-void* CHeapObj::operator new(size_t size){
++void* CHeapObj::operator new(size_t size) throw() {
+   return (void *) malloc(size);
+ }
  
-+#ifndef _ALLBSD_SOURCE
- #include <byteswap.h>
-+#endif
-+
-+#ifdef __APPLE__
-+#include <libkern/OSByteOrder.h>
-+#endif
-+
-+#if defined(AMD64)
-+#  if defined(__APPLE__)
-+#    define bswap_16(x)	OSSwapInt16(x)
-+#    define bswap_32(x)	OSSwapInt32(x)
-+#    define bswap_64(x)	OSSwapInt64(x)
-+#  elif defined(__OpenBSD__)
-+#    define bswap_16(x)	swap16(x)
-+#    define bswap_32(x)	swap32(x)
-+#    define bswap_64(x)	swap64(x)
-+#  elif defined(__NetBSD__)
-+#    define bswap_16(x)	bswap16(x)
-+#    define bswap_32(x)	bswap32(x)
-+#    define bswap_64(x)	bswap64(x)
-+#  else
-+#    define bswap_16(x) __bswap16(x)
-+#    define bswap_32(x) __bswap32(x)
-+#    define bswap_64(x) __bswap64(x)
-+#  endif
-+#endif
+--- hotspot/src/share/vm/adlc/arena.hpp
++++ hotspot/src/share/vm/adlc/arena.hpp
+@@ -42,7 +42,7 @@
  
- // Efficient swapping of data bytes from Java byte
- // ordering to native byte ordering and vice versa.
---- hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp
-+++ hotspot/src/os_cpu/bsd_x86/vm/globals_bsd_x86.hpp
-@@ -25,9 +25,10 @@
- #ifndef OS_CPU_BSD_X86_VM_GLOBALS_BSD_X86_HPP
- #define OS_CPU_BSD_X86_VM_GLOBALS_BSD_X86_HPP
+ class CHeapObj {
+  public:
+-  void* operator new(size_t size);
++  void* operator new(size_t size) throw();
+   void  operator delete(void* p);
+   void* new_array(size_t size);
+ };
+@@ -53,7 +53,7 @@
  
-+//
- // Sets the default values for platform dependent flags used by the runtime system.
- // (see globals.hpp)
--
-+//
- define_pd_global(bool, DontYieldALot,            false);
- #ifdef AMD64
- define_pd_global(intx, ThreadStackSize,          1024); // 0 => use system default
-@@ -41,11 +42,12 @@
- #endif // AMD64
+ class ValueObj {
+  public:
+-  void* operator new(size_t size);
++  void* operator new(size_t size) throw();
+   void operator delete(void* p);
+ };
  
- define_pd_global(intx, CompilerThreadStackSize,  0);
-+define_pd_global(intx, SurvivorRatio,            8);
+@@ -61,7 +61,7 @@
  
--define_pd_global(uintx,JVMInvokeMethodSlack,     8192);
-+define_pd_global(uintx, JVMInvokeMethodSlack,    8192);
+ class AllStatic {
+  public:
+-  void* operator new(size_t size);
++  void* operator new(size_t size) throw();
+   void operator delete(void* p);
+ };
  
- // Only used on 64 bit platforms
--define_pd_global(uintx,HeapBaseMinAddress,       2*G);
-+define_pd_global(uintx, HeapBaseMinAddress,      2*G);
- // Only used on 64 bit Windows platforms
- define_pd_global(bool, UseVectoredExceptions,    false);
+@@ -70,7 +70,7 @@
+ // Linked list of raw memory chunks
+ class Chunk: public CHeapObj {
+  public:
+-  void* operator new(size_t size, size_t length);
++  void* operator new(size_t size, size_t length) throw();
+   void  operator delete(void* p, size_t length);
+   Chunk(size_t length);
  
---- hotspot/src/os_cpu/bsd_x86/vm/orderAccess_bsd_x86.inline.hpp
-+++ hotspot/src/os_cpu/bsd_x86/vm/orderAccess_bsd_x86.inline.hpp
-@@ -93,7 +93,7 @@
+--- hotspot/src/share/vm/adlc/main.cpp
++++ hotspot/src/share/vm/adlc/main.cpp
+@@ -508,7 +508,7 @@
  
- inline void     OrderAccess::store_fence(jbyte*  p, jbyte  v) {
-   __asm__ volatile (  "xchgb (%2),%0"
--                    : "=r" (v)
-+                    : "=q" (v)
-                     : "0" (v), "r" (p)
-                     : "memory");
+ // VS2005 has its own definition, identical to this one.
+ #if !defined(_WIN32) || defined(_WIN64) || _MSC_VER < 1400
+-void *operator new( size_t size, int, const char *, int ) {
++void *operator new( size_t size, int, const char *, int ) throw() {
+   return ::operator new( size );
  }
-@@ -155,7 +155,7 @@
- // Must duplicate definitions instead of calling store_fence because we don't want to cast away volatile.
- inline void     OrderAccess::release_store_fence(volatile jbyte*  p, jbyte  v) {
-   __asm__ volatile (  "xchgb (%2),%0"
--                    : "=r" (v)
-+                    : "=q" (v)
-                     : "0" (v), "r" (p)
-                     : "memory");
- }
---- hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp
-+++ hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp
-@@ -78,25 +78,209 @@
- # include <sys/wait.h>
- # include <pwd.h>
- # include <poll.h>
-+#ifndef __OpenBSD__
- # include <ucontext.h>
--# include <fpu_control.h>
-+#endif
-+
-+#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__) && !defined(__NetBSD__)
-+# include <pthread_np.h>
-+#endif
+ #endif
+--- hotspot/src/share/vm/asm/codeBuffer.hpp
++++ hotspot/src/share/vm/asm/codeBuffer.hpp
+@@ -290,7 +290,7 @@
+   // CodeBuffers must be allocated on the stack except for a single
+   // special case during expansion which is handled internally.  This
+   // is done to guarantee proper cleanup of resources.
+-  void* operator new(size_t size) { return ResourceObj::operator new(size); }
++  void* operator new(size_t size) throw() { return ResourceObj::operator new(size); }
+   void  operator delete(void* p)  { ShouldNotCallThis(); }
  
- #ifdef AMD64
--#define REG_SP REG_RSP
--#define REG_PC REG_RIP
--#define REG_FP REG_RBP
- #define SPELL_REG_SP "rsp"
- #define SPELL_REG_FP "rbp"
- #else
--#define REG_SP REG_UESP
--#define REG_PC REG_EIP
--#define REG_FP REG_EBP
- #define SPELL_REG_SP "esp"
- #define SPELL_REG_FP "ebp"
- #endif // AMD64
+  public:
+--- hotspot/src/share/vm/c1/c1_Compilation.hpp
++++ hotspot/src/share/vm/c1/c1_Compilation.hpp
+@@ -263,8 +263,8 @@
+ // Base class for objects allocated by the compiler in the compilation arena
+ class CompilationResourceObj ALLOCATION_SUPER_CLASS_SPEC {
+  public:
+-  void* operator new(size_t size) { return Compilation::current()->arena()->Amalloc(size); }
+-  void* operator new(size_t size, Arena* arena) {
++  void* operator new(size_t size) throw() { return Compilation::current()->arena()->Amalloc(size); }
++  void* operator new(size_t size, Arena* arena) throw() {
+     return arena->Amalloc(size);
+   }
+   void  operator delete(void* p) {} // nothing to do
+--- hotspot/src/share/vm/c1/c1_IR.cpp
++++ hotspot/src/share/vm/c1/c1_IR.cpp
+@@ -499,7 +499,7 @@
+   _loop_map(0, 0),          // initialized later with correct size
+   _compilation(c)
+ {
+-  TRACE_LINEAR_SCAN(2, "***** computing linear-scan block order");
++  TRACE_LINEAR_SCAN(2, tty->print_cr("***** computing linear-scan block order"));
  
-+#ifdef __MidnightBSD__
-+# define context_trapno uc_mcontext.mc_trapno
-+# ifdef AMD64
-+#  define context_pc uc_mcontext.mc_rip
-+#  define context_sp uc_mcontext.mc_rsp
-+#  define context_fp uc_mcontext.mc_rbp
-+#  define context_rip uc_mcontext.mc_rip
-+#  define context_rsp uc_mcontext.mc_rsp
-+#  define context_rbp uc_mcontext.mc_rbp
-+#  define context_rax uc_mcontext.mc_rax
-+#  define context_rbx uc_mcontext.mc_rbx
-+#  define context_rcx uc_mcontext.mc_rcx
-+#  define context_rdx uc_mcontext.mc_rdx
-+#  define context_rsi uc_mcontext.mc_rsi
-+#  define context_rdi uc_mcontext.mc_rdi
-+#  define context_r8  uc_mcontext.mc_r8
-+#  define context_r9  uc_mcontext.mc_r9
-+#  define context_r10 uc_mcontext.mc_r10
-+#  define context_r11 uc_mcontext.mc_r11
-+#  define context_r12 uc_mcontext.mc_r12
-+#  define context_r13 uc_mcontext.mc_r13
-+#  define context_r14 uc_mcontext.mc_r14
-+#  define context_r15 uc_mcontext.mc_r15
-+#  define context_flags uc_mcontext.mc_flags
-+#  define context_err uc_mcontext.mc_err
-+# else
-+#  define context_pc uc_mcontext.mc_eip
-+#  define context_sp uc_mcontext.mc_esp
-+#  define context_fp uc_mcontext.mc_ebp
-+#  define context_eip uc_mcontext.mc_eip
-+#  define context_esp uc_mcontext.mc_esp
-+#  define context_eax uc_mcontext.mc_eax
-+#  define context_ebx uc_mcontext.mc_ebx
-+#  define context_ecx uc_mcontext.mc_ecx
-+#  define context_edx uc_mcontext.mc_edx
-+#  define context_ebp uc_mcontext.mc_ebp
-+#  define context_esi uc_mcontext.mc_esi
-+#  define context_edi uc_mcontext.mc_edi
-+#  define context_eflags uc_mcontext.mc_eflags
-+#  define context_trapno uc_mcontext.mc_trapno
-+# endif
-+#endif
-+
-+#ifdef __APPLE__ 
-+# if __DARWIN_UNIX03 && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
-+  // 10.5 UNIX03 member name prefixes
-+  #define DU3_PREFIX(s, m) __ ## s.__ ## m
-+# else
-+  #define DU3_PREFIX(s, m) s ## . ## m
-+# endif
-+
-+# ifdef AMD64
-+#  define context_pc context_rip
-+#  define context_sp context_rsp
-+#  define context_fp context_rbp
-+#  define context_rip uc_mcontext->DU3_PREFIX(ss,rip)
-+#  define context_rsp uc_mcontext->DU3_PREFIX(ss,rsp)
-+#  define context_rax uc_mcontext->DU3_PREFIX(ss,rax)
-+#  define context_rbx uc_mcontext->DU3_PREFIX(ss,rbx)
-+#  define context_rcx uc_mcontext->DU3_PREFIX(ss,rcx)
-+#  define context_rdx uc_mcontext->DU3_PREFIX(ss,rdx)
-+#  define context_rbp uc_mcontext->DU3_PREFIX(ss,rbp)
-+#  define context_rsi uc_mcontext->DU3_PREFIX(ss,rsi)
-+#  define context_rdi uc_mcontext->DU3_PREFIX(ss,rdi)
-+#  define context_r8  uc_mcontext->DU3_PREFIX(ss,r8)
-+#  define context_r9  uc_mcontext->DU3_PREFIX(ss,r9)
-+#  define context_r10 uc_mcontext->DU3_PREFIX(ss,r10)
-+#  define context_r11 uc_mcontext->DU3_PREFIX(ss,r11)
-+#  define context_r12 uc_mcontext->DU3_PREFIX(ss,r12)
-+#  define context_r13 uc_mcontext->DU3_PREFIX(ss,r13)
-+#  define context_r14 uc_mcontext->DU3_PREFIX(ss,r14)
-+#  define context_r15 uc_mcontext->DU3_PREFIX(ss,r15)
-+#  define context_flags uc_mcontext->DU3_PREFIX(ss,rflags)
-+#  define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
-+#  define context_err uc_mcontext->DU3_PREFIX(es,err)
-+# else
-+#  define context_pc context_eip
-+#  define context_sp context_esp
-+#  define context_fp context_ebp
-+#  define context_eip uc_mcontext->DU3_PREFIX(ss,eip)
-+#  define context_esp uc_mcontext->DU3_PREFIX(ss,esp)
-+#  define context_eax uc_mcontext->DU3_PREFIX(ss,eax)
-+#  define context_ebx uc_mcontext->DU3_PREFIX(ss,ebx)
-+#  define context_ecx uc_mcontext->DU3_PREFIX(ss,ecx)
-+#  define context_edx uc_mcontext->DU3_PREFIX(ss,edx)
-+#  define context_ebp uc_mcontext->DU3_PREFIX(ss,ebp)
-+#  define context_esi uc_mcontext->DU3_PREFIX(ss,esi)
-+#  define context_edi uc_mcontext->DU3_PREFIX(ss,edi)
-+#  define context_eflags uc_mcontext->DU3_PREFIX(ss,eflags)
-+#  define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
-+# endif
-+#endif
-+
-+#ifdef __OpenBSD__
-+# define context_trapno sc_trapno
-+# ifdef AMD64
-+#  define context_pc sc_rip
-+#  define context_sp sc_rsp
-+#  define context_fp sc_rbp
-+#  define context_rip sc_rip
-+#  define context_rsp sc_rsp
-+#  define context_rbp sc_rbp
-+#  define context_rax sc_rax
-+#  define context_rbx sc_rbx
-+#  define context_rcx sc_rcx
-+#  define context_rdx sc_rdx
-+#  define context_rsi sc_rsi
-+#  define context_rdi sc_rdi
-+#  define context_r8  sc_r8
-+#  define context_r9  sc_r9
-+#  define context_r10 sc_r10
-+#  define context_r11 sc_r11
-+#  define context_r12 sc_r12
-+#  define context_r13 sc_r13
-+#  define context_r14 sc_r14
-+#  define context_r15 sc_r15
-+#  define context_flags sc_rflags
-+#  define context_err sc_err
-+# else
-+#  define context_pc sc_eip
-+#  define context_sp sc_esp
-+#  define context_fp sc_ebp
-+#  define context_eip sc_eip
-+#  define context_esp sc_esp
-+#  define context_eax sc_eax
-+#  define context_ebx sc_ebx
-+#  define context_ecx sc_ecx
-+#  define context_edx sc_edx
-+#  define context_ebp sc_ebp
-+#  define context_esi sc_esi
-+#  define context_edi sc_edi
-+#  define context_eflags sc_eflags
-+#  define context_trapno sc_trapno
-+# endif
-+#endif
-+
-+#ifdef __NetBSD__
-+# define context_trapno uc_mcontext.__gregs[_REG_TRAPNO]
-+# ifdef AMD64
-+#  define __register_t __greg_t
-+#  define context_pc uc_mcontext.__gregs[_REG_RIP]
-+#  define context_sp uc_mcontext.__gregs[_REG_URSP]
-+#  define context_fp uc_mcontext.__gregs[_REG_RBP]
-+#  define context_rip uc_mcontext.__gregs[_REG_RIP]
-+#  define context_rsp uc_mcontext.__gregs[_REG_URSP]
-+#  define context_rax uc_mcontext.__gregs[_REG_RAX]
-+#  define context_rbx uc_mcontext.__gregs[_REG_RBX]
-+#  define context_rcx uc_mcontext.__gregs[_REG_RCX]
-+#  define context_rdx uc_mcontext.__gregs[_REG_RDX]
-+#  define context_rbp uc_mcontext.__gregs[_REG_RBP]
-+#  define context_rsi uc_mcontext.__gregs[_REG_RSI]
-+#  define context_rdi uc_mcontext.__gregs[_REG_RDI]
-+#  define context_r8  uc_mcontext.__gregs[_REG_R8]
-+#  define context_r9  uc_mcontext.__gregs[_REG_R9]
-+#  define context_r10 uc_mcontext.__gregs[_REG_R10]
-+#  define context_r11 uc_mcontext.__gregs[_REG_R11]
-+#  define context_r12 uc_mcontext.__gregs[_REG_R12]
-+#  define context_r13 uc_mcontext.__gregs[_REG_R13]
-+#  define context_r14 uc_mcontext.__gregs[_REG_R14]
-+#  define context_r15 uc_mcontext.__gregs[_REG_R15]
-+#  define context_flags uc_mcontext.__gregs[_REG_RFL]
-+#  define context_err uc_mcontext.__gregs[_REG_ERR]
-+# else
-+#  define context_pc uc_mcontext.__gregs[_REG_EIP]
-+#  define context_sp uc_mcontext.__gregs[_REG_UESP]
-+#  define context_fp uc_mcontext.__gregs[_REG_EBP]
-+#  define context_eip uc_mcontext.__gregs[_REG_EIP]
-+#  define context_esp uc_mcontext.__gregs[_REG_UESP]
-+#  define context_eax uc_mcontext.__gregs[_REG_EAX]
-+#  define context_ebx uc_mcontext.__gregs[_REG_EBX]
-+#  define context_ecx uc_mcontext.__gregs[_REG_ECX]
-+#  define context_edx uc_mcontext.__gregs[_REG_EDX]
-+#  define context_ebp uc_mcontext.__gregs[_REG_EBP]
-+#  define context_esi uc_mcontext.__gregs[_REG_ESI]
-+#  define context_edi uc_mcontext.__gregs[_REG_EDI]
-+#  define context_eflags uc_mcontext.__gregs[_REG_EFL]
-+#  define context_trapno uc_mcontext.__gregs[_REG_TRAPNO]
-+# endif
-+#endif
-+
- address os::current_stack_pointer() {
--#ifdef SPARC_WORKS
-+#if defined(__clang__)
-+  register void *esp;
-+  // XXX must be compiled with -O1 or above.
-+  __asm__ volatile("mov %%" SPELL_REG_SP ", %0" : "=r"(esp));
-+  return (address) esp;
-+#elif defined(SPARC_WORKS)
-   register void *esp;
-   __asm__("mov %%"SPELL_REG_SP", %0":"=r"(esp));
-   return (address) ((char*)esp + sizeof(long)*2);
-@@ -119,15 +303,15 @@
+   init_visited();
+   count_edges(start_block, NULL);
+@@ -665,7 +665,7 @@
  }
  
- address os::Bsd::ucontext_get_pc(ucontext_t * uc) {
--  return (address)uc->uc_mcontext.gregs[REG_PC];
-+  return (address)uc->context_pc;
- }
+ void ComputeLinearScanOrder::assign_loop_depth(BlockBegin* start_block) {
+-  TRACE_LINEAR_SCAN(3, "----- computing loop-depth and weight");
++  TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing loop-depth and weight"));
+   init_visited();
  
- intptr_t* os::Bsd::ucontext_get_sp(ucontext_t * uc) {
--  return (intptr_t*)uc->uc_mcontext.gregs[REG_SP];
-+  return (intptr_t*)uc->context_sp;
+   assert(_work_list.is_empty(), "work list must be empty before processing");
+@@ -839,7 +839,7 @@
  }
  
- intptr_t* os::Bsd::ucontext_get_fp(ucontext_t * uc) {
--  return (intptr_t*)uc->uc_mcontext.gregs[REG_FP];
-+  return (intptr_t*)uc->context_fp;
- }
+ void ComputeLinearScanOrder::compute_order(BlockBegin* start_block) {
+-  TRACE_LINEAR_SCAN(3, "----- computing final block order");
++  TRACE_LINEAR_SCAN(3, tty->print_cr("----- computing final block order"));
  
- // For Forte Analyzer AsyncGetCallTrace profiling support - thread
-@@ -179,7 +363,11 @@
- }
+   // the start block is always the first block in the linear scan order
+   _linear_scan_order = new BlockList(_num_blocks);
+--- hotspot/src/share/vm/c1/c1_Instruction.hpp
++++ hotspot/src/share/vm/c1/c1_Instruction.hpp
+@@ -311,7 +311,7 @@
+   }
  
- intptr_t* _get_previous_fp() {
--#ifdef SPARC_WORKS
-+#if defined(__clang__)
-+  register intptr_t **ebp;
-+  // XXX must be compiled with -O1 or above.
-+  __asm__ volatile("mov %%" SPELL_REG_FP ", %0" : "=r"(ebp));
-+#elif defined(SPARC_WORKS)
-   register intptr_t **ebp;
-   __asm__("mov %%"SPELL_REG_FP", %0":"=r"(ebp));
- #else
-@@ -279,18 +467,18 @@
-     pc = (address) os::Bsd::ucontext_get_pc(uc);
+  public:
+-  void* operator new(size_t size) {
++  void* operator new(size_t size) throw() {
+     Compilation* c = Compilation::current();
+     void* res = c->arena()->Amalloc(size);
+     ((Instruction*)res)->_id = c->get_next_id();
+@@ -1529,7 +1529,7 @@
+   friend class SuxAndWeightAdjuster;
  
-     if (pc == (address) Fetch32PFI) {
--       uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ;
-+       uc->context_pc = intptr_t(Fetch32Resume) ;
-        return 1 ;
-     }
- #ifdef AMD64
-     if (pc == (address) FetchNPFI) {
--       uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ;
-+       uc->context_pc = intptr_t (FetchNResume) ;
-        return 1 ;
-     }
- #endif // AMD64
+  public:
+-   void* operator new(size_t size) {
++   void* operator new(size_t size) throw() {
+     Compilation* c = Compilation::current();
+     void* res = c->arena()->Amalloc(size);
+     ((BlockBegin*)res)->_id = c->get_next_id();
+--- hotspot/src/share/vm/ci/ciUtilities.hpp
++++ hotspot/src/share/vm/ci/ciUtilities.hpp
+@@ -93,7 +93,7 @@
+     CLEAR_PENDING_EXCEPTION;                     \
+     return (result);                             \
+   }                                              \
+-  (0
++  (void)(0
  
-     // Handle ALL stack overflow variations here
--    if (sig == SIGSEGV) {
-+    if (sig == SIGSEGV || sig == SIGBUS) {
-       address addr = (address) info->si_addr;
+ #define KILL_COMPILE_ON_ANY                      \
+   THREAD);                                       \
+@@ -101,7 +101,7 @@
+     fatal("unhandled ci exception");             \
+     CLEAR_PENDING_EXCEPTION;                     \
+   }                                              \
+-(0
++(void)(0
  
-       // check if fault address is within thread stack
-@@ -312,6 +500,7 @@
-           // to handle_unexpected_exception way down below.
-           thread->disable_stack_red_zone();
-           tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
-+#ifndef _ALLBSD_SOURCE
-         } else {
-           // Accessing stack address below sp may cause SEGV if current
-           // thread has MAP_GROWSDOWN stack. This should only happen when
-@@ -327,6 +516,7 @@
-           } else {
-              fatal("recursive segv. expanding stack.");
-           }
-+#endif
-         }
-       }
-     }
-@@ -335,9 +525,16 @@
-       // Java thread running in Java code => find exception handler if any
-       // a fault inside compiled code, the interpreter, or a stub
  
--      if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
-+      if ((sig == SIGSEGV || sig == SIGBUS) && os::is_poll_address((address)info->si_addr)) {
-         stub = SharedRuntime::get_poll_stub(pc);
-+#if defined(__APPLE__) && !defined(AMD64)
-+      // 32-bit Darwin reports a SIGBUS for nearly all memory access exceptions.
-+      // Catching SIGBUS here prevents the implicit SIGBUS NULL check below from
-+      // being called, so only do so if the implicit NULL check is not necessary.
-+      } else if (sig == SIGBUS && MacroAssembler::needs_explicit_null_check((int)info->si_addr)) {
-+#else
-       } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
-+#endif
-         // BugId 4454115: A read from a MappedByteBuffer can fault
-         // here if the underlying file has been truncated.
-         // Do not crash the VM in such a case.
-@@ -358,6 +555,28 @@
-                                               pc,
-                                               SharedRuntime::
-                                               IMPLICIT_DIVIDE_BY_ZERO);
-+#ifdef __APPLE__
-+      } else if (sig == SIGFPE && info->si_code == FPE_NOOP) {
-+        int op = pc[0];
-+
-+        // Skip REX
-+        if ((pc[0] & 0xf0) == 0x40) {
-+          op = pc[1];
-+        } else {
-+          op = pc[0];
-+        }
-+
-+        // Check for IDIV
-+        if (op == 0xF7) {
-+          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime:: IMPLICIT_DIVIDE_BY_ZERO);
-+        } else {
-+          // TODO: handle more cases if we are using other x86 instructions
-+          //   that can generate SIGFPE signal.
-+          tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
-+          fatal("please update this code.");
-+        }
-+#endif /* __APPLE__ */
-+
- #else
-       if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
-         // HACK: si_code does not work on bsd 2.2.12-20!!!
-@@ -385,7 +604,7 @@
-           fatal("please update this code.");
-         }
- #endif // AMD64
--      } else if (sig == SIGSEGV &&
-+      } else if ((sig == SIGSEGV || sig == SIGBUS) &&
-                !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
-           // Determination of interpreter/vtable stub/compiled code null exception
-           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
-@@ -409,7 +628,7 @@
-     // process of write protecting the memory serialization page.
-     // It write enables the page immediately after protecting it
-     // so we can just return to retry the write.
--    if ((sig == SIGSEGV) &&
-+    if ((sig == SIGSEGV || sig == SIGBUS) &&
-         os::is_memory_serialize_page(thread, (address) info->si_addr)) {
-       // Block current thread until the memory serialize page permission restored.
-       os::block_on_serialize_page_trap();
-@@ -430,7 +649,7 @@
-   // Furthermore, a false-positive should be harmless.
-   if (UnguardOnExecutionViolation > 0 &&
-       (sig == SIGSEGV || sig == SIGBUS) &&
--      uc->uc_mcontext.gregs[REG_TRAPNO] == trap_page_fault) {
-+      uc->context_trapno == trap_page_fault) {
-     int page_size = os::vm_page_size();
-     address addr = (address) info->si_addr;
-     address pc = os::Bsd::ucontext_get_pc(uc);
-@@ -500,7 +719,7 @@
-     // save all thread context in case we need to restore it
-     if (thread != NULL) thread->set_saved_exception_pc(pc);
+ inline const char* bool_to_str(bool b) {
+--- hotspot/src/share/vm/classfile/verifier.hpp
++++ hotspot/src/share/vm/classfile/verifier.hpp
+@@ -84,9 +84,9 @@
+ // These macros are used similarly to CHECK macros but also check
+ // the status of the verifier and return if that has an error.
+ #define CHECK_VERIFY(verifier) \
+-  CHECK); if ((verifier)->has_error()) return; (0
++  CHECK); if ((verifier)->has_error()) return; ((void)0
+ #define CHECK_VERIFY_(verifier, result) \
+-  CHECK_(result)); if ((verifier)->has_error()) return (result); (0
++  CHECK_(result)); if ((verifier)->has_error()) return (result); ((void)0
  
--    uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub;
-+    uc->context_pc = (intptr_t)stub;
-     return true;
-   }
- 
-@@ -530,13 +749,24 @@
-   ShouldNotReachHere();
+ // A new instance of this class is created for each class being verified
+ class ClassVerifier : public StackObj {
+--- hotspot/src/share/vm/code/codeBlob.cpp
++++ hotspot/src/share/vm/code/codeBlob.cpp
+@@ -242,7 +242,7 @@
  }
  
-+#ifdef _ALLBSD_SOURCE
-+// From solaris_i486.s ported to bsd_i486.s
-+extern "C" void fixcw();
-+#endif
-+
- void os::Bsd::init_thread_fpu_state(void) {
- #ifndef AMD64
-+# ifdef _ALLBSD_SOURCE
-+  // Set fpu to 53 bit precision. This happens too early to use a stub.
-+  fixcw();
-+# else
-   // set fpu to 53 bit precision
-   set_fpu_control_word(0x27f);
-+# endif
- #endif // !AMD64
- }
  
-+#ifndef _ALLBSD_SOURCE
- int os::Bsd::get_fpu_control_word(void) {
- #ifdef AMD64
-   return 0;
-@@ -552,11 +782,12 @@
-   _FPU_SETCW(fpu_control);
- #endif // !AMD64
+-void* BufferBlob::operator new(size_t s, unsigned size) {
++void* BufferBlob::operator new(size_t s, unsigned size) throw() {
+   void* p = CodeCache::allocate(size);
+   return p;
  }
-+#endif
- 
- // Check that the bsd kernel version is 2.4 or higher since earlier
- // versions do not support SSE without patches.
- bool os::supports_sse() {
--#ifdef AMD64
-+#if defined(AMD64) || defined(_ALLBSD_SOURCE)
-   return true;
- #else
-   struct utsname uts;
-@@ -610,6 +841,9 @@
- #define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
- #endif
- 
-+#ifdef _ALLBSD_SOURCE
-+bool os::Bsd::supports_variable_stack_size() { return true; }
-+#else
- // Test if pthread library can support variable thread stack size. BsdThreads
- // in fixed stack mode allocates 2M fixed slot for each thread. BsdThreads
- // in floating stack mode and NPTL support variable stack size.
-@@ -632,7 +866,7 @@
-     //
-     // Note that %gs is a reserved glibc register since early 2001, so
-     // applications are not allowed to change its value (Ulrich Drepper from
--    // Red Hat confirmed that all known offenders have been modified to use
-+    // Redhat confirmed that all known offenders have been modified to use
-     // either %fs or TSD). In the worst case scenario, when VM is embedded in
-     // a native application that plays with %gs, we might see non-zero %gs
-     // even BsdThreads is running in fixed stack mode. As the result, we'll
-@@ -646,6 +880,7 @@
- #endif
-   }
+@@ -344,14 +344,14 @@
  }
-+#endif
- #endif // AMD64
  
- // return default stack size for thr_type
-@@ -699,6 +934,41 @@
- //    pthread_attr_getstack()
  
- static void current_stack_region(address * bottom, size_t * size) {
-+#ifdef __APPLE__
-+  pthread_t self = pthread_self();
-+  void *stacktop = pthread_get_stackaddr_np(self);
-+  *size = pthread_get_stacksize_np(self);
-+  *bottom = (address) stacktop - *size;
-+#elif defined(__OpenBSD__)
-+  stack_t ss;
-+  int rslt = pthread_stackseg_np(pthread_self(), &ss);
-+
-+  if (rslt != 0)
-+    fatal(err_msg("pthread_stackseg_np failed with err = %d", rslt));
-+
-+  *bottom = (address)((char *)ss.ss_sp - ss.ss_size);
-+  *size   = ss.ss_size;
-+#elif defined(_ALLBSD_SOURCE)
-+  pthread_attr_t attr;
-+
-+  int rslt = pthread_attr_init(&attr);
-+
-+  // JVM needs to know exact stack location, abort if it fails
-+  if (rslt != 0)
-+    fatal(err_msg("pthread_attr_init failed with err = %d", rslt));
-+
-+  rslt = pthread_attr_get_np(pthread_self(), &attr);
-+
-+  if (rslt != 0)
-+    fatal(err_msg("pthread_attr_get_np failed with err = %d", rslt));
-+
-+  if (pthread_attr_getstackaddr(&attr, (void **)bottom) != 0 ||
-+    pthread_attr_getstacksize(&attr, size) != 0) {
-+    fatal("Can not locate current stack attributes!");
-+  }
-+
-+  pthread_attr_destroy(&attr);
-+#else
-   if (os::Bsd::is_initial_thread()) {
-      // initial thread needs special handling because pthread_getattr_np()
-      // may return bogus value.
-@@ -725,6 +995,7 @@
-      pthread_attr_destroy(&attr);
- 
-   }
-+#endif
-   assert(os::current_stack_pointer() >= *bottom &&
-          os::current_stack_pointer() < *bottom + *size, "just checking");
+-void* RuntimeStub::operator new(size_t s, unsigned size) {
++void* RuntimeStub::operator new(size_t s, unsigned size) throw() {
+   void* p = CodeCache::allocate(size);
+   if (!p) fatal("Initial size of CodeCache is too small");
+   return p;
  }
-@@ -753,46 +1024,44 @@
-   ucontext_t *uc = (ucontext_t*)context;
-   st->print_cr("Registers:");
- #ifdef AMD64
--  st->print(  "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]);
--  st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]);
--  st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]);
--  st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]);
--  st->cr();
--  st->print(  "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]);
--  st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]);
--  st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]);
--  st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]);
--  st->cr();
--  st->print(  "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]);
--  st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]);
--  st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]);
--  st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]);
--  st->cr();
--  st->print(  "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]);
--  st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]);
--  st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]);
--  st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]);
--  st->cr();
--  st->print(  "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]);
--  st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]);
--  st->print(", CSGSFS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_CSGSFS]);
--  st->print(", ERR=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ERR]);
--  st->cr();
--  st->print("  TRAPNO=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_TRAPNO]);
--#else
--  st->print(  "EAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EAX]);
--  st->print(", EBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EBX]);
--  st->print(", ECX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ECX]);
--  st->print(", EDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EDX]);
--  st->cr();
--  st->print(  "ESP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_UESP]);
--  st->print(", EBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EBP]);
--  st->print(", ESI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ESI]);
--  st->print(", EDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EDI]);
--  st->cr();
--  st->print(  "EIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EIP]);
--  st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]);
--  st->print(", CR2=" INTPTR_FORMAT, uc->uc_mcontext.cr2);
-+  st->print(  "RAX=" INTPTR_FORMAT, uc->context_rax);
-+  st->print(", RBX=" INTPTR_FORMAT, uc->context_rbx);
-+  st->print(", RCX=" INTPTR_FORMAT, uc->context_rcx);
-+  st->print(", RDX=" INTPTR_FORMAT, uc->context_rdx);
-+  st->cr();
-+  st->print(  "RSP=" INTPTR_FORMAT, uc->context_rsp);
-+  st->print(", RBP=" INTPTR_FORMAT, uc->context_rbp);
-+  st->print(", RSI=" INTPTR_FORMAT, uc->context_rsi);
-+  st->print(", RDI=" INTPTR_FORMAT, uc->context_rdi);
-+  st->cr();
-+  st->print(  "R8 =" INTPTR_FORMAT, uc->context_r8);
-+  st->print(", R9 =" INTPTR_FORMAT, uc->context_r9);
-+  st->print(", R10=" INTPTR_FORMAT, uc->context_r10);
-+  st->print(", R11=" INTPTR_FORMAT, uc->context_r11);
-+  st->cr();
-+  st->print(  "R12=" INTPTR_FORMAT, uc->context_r12);
-+  st->print(", R13=" INTPTR_FORMAT, uc->context_r13);
-+  st->print(", R14=" INTPTR_FORMAT, uc->context_r14);
-+  st->print(", R15=" INTPTR_FORMAT, uc->context_r15);
-+  st->cr();
-+  st->print(  "RIP=" INTPTR_FORMAT, uc->context_rip);
-+  st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_flags);
-+  st->print(", ERR=" INTPTR_FORMAT, uc->context_err);
-+  st->cr();
-+  st->print("  TRAPNO=" INTPTR_FORMAT, uc->context_trapno);
-+#else
-+  st->print(  "EAX=" INTPTR_FORMAT, uc->context_eax);
-+  st->print(", EBX=" INTPTR_FORMAT, uc->context_ebx);
-+  st->print(", ECX=" INTPTR_FORMAT, uc->context_ecx);
-+  st->print(", EDX=" INTPTR_FORMAT, uc->context_edx);
-+  st->cr();
-+  st->print(  "ESP=" INTPTR_FORMAT, uc->context_esp);
-+  st->print(", EBP=" INTPTR_FORMAT, uc->context_ebp);
-+  st->print(", ESI=" INTPTR_FORMAT, uc->context_esi);
-+  st->print(", EDI=" INTPTR_FORMAT, uc->context_edi);
-+  st->cr();
-+  st->print(  "EIP=" INTPTR_FORMAT, uc->context_eip);
-+  st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_eflags);
- #endif // AMD64
-   st->cr();
-   st->cr();
-@@ -825,31 +1094,31 @@
-   // this is only for the "general purpose" registers
  
- #ifdef AMD64
--  st->print("RAX="); print_location(st, uc->uc_mcontext.gregs[REG_RAX]);
--  st->print("RBX="); print_location(st, uc->uc_mcontext.gregs[REG_RBX]);
--  st->print("RCX="); print_location(st, uc->uc_mcontext.gregs[REG_RCX]);
--  st->print("RDX="); print_location(st, uc->uc_mcontext.gregs[REG_RDX]);
--  st->print("RSP="); print_location(st, uc->uc_mcontext.gregs[REG_RSP]);
--  st->print("RBP="); print_location(st, uc->uc_mcontext.gregs[REG_RBP]);
--  st->print("RSI="); print_location(st, uc->uc_mcontext.gregs[REG_RSI]);
--  st->print("RDI="); print_location(st, uc->uc_mcontext.gregs[REG_RDI]);
--  st->print("R8 ="); print_location(st, uc->uc_mcontext.gregs[REG_R8]);
--  st->print("R9 ="); print_location(st, uc->uc_mcontext.gregs[REG_R9]);
--  st->print("R10="); print_location(st, uc->uc_mcontext.gregs[REG_R10]);
--  st->print("R11="); print_location(st, uc->uc_mcontext.gregs[REG_R11]);
--  st->print("R12="); print_location(st, uc->uc_mcontext.gregs[REG_R12]);
--  st->print("R13="); print_location(st, uc->uc_mcontext.gregs[REG_R13]);
--  st->print("R14="); print_location(st, uc->uc_mcontext.gregs[REG_R14]);
--  st->print("R15="); print_location(st, uc->uc_mcontext.gregs[REG_R15]);
--#else
--  st->print("EAX="); print_location(st, uc->uc_mcontext.gregs[REG_EAX]);
--  st->print("EBX="); print_location(st, uc->uc_mcontext.gregs[REG_EBX]);
--  st->print("ECX="); print_location(st, uc->uc_mcontext.gregs[REG_ECX]);
--  st->print("EDX="); print_location(st, uc->uc_mcontext.gregs[REG_EDX]);
--  st->print("ESP="); print_location(st, uc->uc_mcontext.gregs[REG_ESP]);
--  st->print("EBP="); print_location(st, uc->uc_mcontext.gregs[REG_EBP]);
--  st->print("ESI="); print_location(st, uc->uc_mcontext.gregs[REG_ESI]);
--  st->print("EDI="); print_location(st, uc->uc_mcontext.gregs[REG_EDI]);
-+  st->print("RAX="); print_location(st, uc->context_rax);
-+  st->print("RBX="); print_location(st, uc->context_rbx);
-+  st->print("RCX="); print_location(st, uc->context_rcx);
-+  st->print("RDX="); print_location(st, uc->context_rdx);
-+  st->print("RSP="); print_location(st, uc->context_rsp);
-+  st->print("RBP="); print_location(st, uc->context_rbp);
-+  st->print("RSI="); print_location(st, uc->context_rsi);
-+  st->print("RDI="); print_location(st, uc->context_rdi);
-+  st->print("R8 ="); print_location(st, uc->context_r8);
-+  st->print("R9 ="); print_location(st, uc->context_r9);
-+  st->print("R10="); print_location(st, uc->context_r10);
-+  st->print("R11="); print_location(st, uc->context_r11);
-+  st->print("R12="); print_location(st, uc->context_r12);
-+  st->print("R13="); print_location(st, uc->context_r13);
-+  st->print("R14="); print_location(st, uc->context_r14);
-+  st->print("R15="); print_location(st, uc->context_r15);
-+#else
-+  st->print("EAX="); print_location(st, uc->context_eax);
-+  st->print("EBX="); print_location(st, uc->context_ebx);
-+  st->print("ECX="); print_location(st, uc->context_ecx);
-+  st->print("EDX="); print_location(st, uc->context_edx);
-+  st->print("ESP="); print_location(st, uc->context_esp);
-+  st->print("EBP="); print_location(st, uc->context_ebp);
-+  st->print("ESI="); print_location(st, uc->context_esi);
-+  st->print("EDI="); print_location(st, uc->context_edi);
- #endif // AMD64
+ // operator new shared by all singletons:
+-void* SingletonBlob::operator new(size_t s, unsigned size) {
++void* SingletonBlob::operator new(size_t s, unsigned size) throw() {
+   void* p = CodeCache::allocate(size);
+   if (!p) fatal("Initial size of CodeCache is too small");
+   return p;
+--- hotspot/src/share/vm/code/codeBlob.hpp
++++ hotspot/src/share/vm/code/codeBlob.hpp
+@@ -213,7 +213,7 @@
+   BufferBlob(const char* name, int size);
+   BufferBlob(const char* name, int size, CodeBuffer* cb);
  
-   st->cr();
---- hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp
-+++ hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp
-@@ -30,8 +30,10 @@
- #ifndef AMD64
-   // map stack pointer to thread pointer - see notes in threadLS_bsd_x86.cpp
-   #define SP_BITLENGTH  32
-+#ifndef PAGE_SHIFT
-   #define PAGE_SHIFT    12
-   #define PAGE_SIZE     (1UL << PAGE_SHIFT)
-+#endif
-   static Thread* _sp_map[1UL << (SP_BITLENGTH - PAGE_SHIFT)];
- #endif // !AMD64
+-  void* operator new(size_t s, unsigned size);
++  void* operator new(size_t s, unsigned size) throw();
  
---- hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp
-+++ hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp
-@@ -29,6 +29,7 @@
- // constants required by the Serviceability Agent. This file is
- // referenced by vmStructs.cpp.
+  public:
+   // Creation
+@@ -287,7 +287,7 @@
+     bool        caller_must_gc_arguments
+   );
  
-+#ifdef __MidnightBSD__
- #define VM_STRUCTS_OS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field, last_entry) \
-                                                                                                                                      \
-   /******************************/                                                                                                   \
-@@ -38,6 +39,17 @@
-   nonstatic_field(OSThread,                      _pthread_id,                                     pthread_t)                         \
-   /* This must be the last entry, and must be present */                                                                             \
-   last_entry()
-+#else
-+#define VM_STRUCTS_OS_CPU(nonstatic_field, static_field, unchecked_nonstatic_field, volatile_nonstatic_field, nonproduct_nonstatic_field, c2_nonstatic_field, unchecked_c1_static_field, unchecked_c2_static_field, last_entry) \
-+                                                                                                                                     \
-+  /******************************/                                                                                                   \
-+  /* Threads (NOTE: incomplete) */                                                                                                   \
-+  /******************************/                                                                                                   \
-+  nonstatic_field(OSThread,                      _thread_id,                                      pthread_t)                         \
-+  nonstatic_field(OSThread,                      _pthread_id,                                     pthread_t)                         \
-+  /* This must be the last entry, and must be present */                                                                             \
-+  last_entry()
-+#endif
+-  void* operator new(size_t s, unsigned size);
++  void* operator new(size_t s, unsigned size) throw();
  
+  public:
+   // Creation
+@@ -325,7 +325,7 @@
+   friend class VMStructs;
  
- #define VM_TYPES_OS_CPU(declare_type, declare_toplevel_type, declare_oop_type, declare_integer_type, declare_unsigned_integer_type, declare_c1_toplevel_type, declare_c2_type, declare_c2_toplevel_type, last_entry) \
---- hotspot/src/share/vm/adlc/adlc.hpp
-+++ hotspot/src/share/vm/adlc/adlc.hpp
-@@ -72,9 +72,9 @@
- #endif
- #endif // _WIN32
+  protected:
+-  void* operator new(size_t s, unsigned size);
++  void* operator new(size_t s, unsigned size) throw();
  
--#ifdef LINUX
-+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
-   #include <inttypes.h>
--#endif // LINUX
-+#endif // LINUX || _ALLBSD_SOURCE
+  public:
+    SingletonBlob(
+--- hotspot/src/share/vm/code/debugInfoRec.cpp
++++ hotspot/src/share/vm/code/debugInfoRec.cpp
+@@ -38,7 +38,7 @@
+   int  _length; // number of bytes in the stream
+   int  _hash;   // hash of stream bytes (for quicker reuse)
  
- // Macros
- #define uint32 unsigned int
---- hotspot/src/share/vm/c1/c1_globals.hpp
-+++ hotspot/src/share/vm/c1/c1_globals.hpp
-@@ -41,6 +41,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "c1_globals_windows.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "c1_globals_bsd.hpp"
-+#endif
+-  void* operator new(size_t ignore, DebugInformationRecorder* dir) {
++  void* operator new(size_t ignore, DebugInformationRecorder* dir) throw() {
+     assert(ignore == sizeof(DIR_Chunk), "");
+     if (dir->_next_chunk >= dir->_next_chunk_limit) {
+       const int CHUNK = 100;
+--- hotspot/src/share/vm/code/dependencies.cpp
++++ hotspot/src/share/vm/code/dependencies.cpp
+@@ -932,7 +932,7 @@
+   assert(changes.involves_context(context_type), "irrelevant dependency");
+   klassOop new_type = changes.new_type();
  
- //
- // Defines all global flags used by the client compiler.
---- hotspot/src/share/vm/classfile/classLoader.cpp
-+++ hotspot/src/share/vm/classfile/classLoader.cpp
-@@ -68,6 +68,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+-  count_find_witness_calls();
++  (void)count_find_witness_calls();
+   NOT_PRODUCT(deps_find_witness_singles++);
  
+   // Current thread must be in VM (not native mode, as in CI):
+--- hotspot/src/share/vm/code/nmethod.cpp
++++ hotspot/src/share/vm/code/nmethod.cpp
+@@ -784,7 +784,7 @@
+ }
+ #endif // def HAVE_DTRACE_H
  
- // Entry points in zip.dll for loading zip/jar file entries
---- hotspot/src/share/vm/classfile/javaClasses.cpp
-+++ hotspot/src/share/vm/classfile/javaClasses.cpp
-@@ -55,6 +55,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- static bool find_field(instanceKlass* ik,
-                        symbolOop name_symbol, symbolOop signature_symbol,
-@@ -991,7 +994,7 @@
+-void* nmethod::operator new(size_t size, int nmethod_size) {
++void* nmethod::operator new(size_t size, int nmethod_size) throw() {
+   // Always leave some room in the CodeCache for I2C/C2I adapters
+   if (CodeCache::largest_free_block() < CodeCacheMinimumFreeSpace) return NULL;
+   return CodeCache::allocate(nmethod_size);
+@@ -2488,7 +2488,8 @@
+                       relocation_begin()-1+ip[1]);
+       for (; ip < index_end; ip++)
+         tty->print_cr("  (%d ?)", ip[0]);
+-      tty->print_cr("          @" INTPTR_FORMAT ": index_size=%d", ip, *ip++);
++      tty->print_cr("          @" INTPTR_FORMAT ": index_size=%d", ip, *ip);
++      ip++;
+       tty->print_cr("reloc_end @" INTPTR_FORMAT ":", ip);
      }
-     nmethod* nm = method->code();
-     if (WizardMode && nm != NULL) {
--      sprintf(buf + (int)strlen(buf), "(nmethod " PTR_FORMAT ")", (intptr_t)nm);
-+      sprintf(buf + (int)strlen(buf), "(nmethod " INTPTR_FORMAT ")", (intptr_t)nm);
-     }
    }
+--- hotspot/src/share/vm/code/nmethod.hpp
++++ hotspot/src/share/vm/code/nmethod.hpp
+@@ -263,7 +263,7 @@
+           int comp_level);
  
---- hotspot/src/share/vm/code/stubs.hpp
-+++ hotspot/src/share/vm/code/stubs.hpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+   // helper methods
+-  void* operator new(size_t size, int nmethod_size);
++  void* operator new(size_t size, int nmethod_size) throw();
  
- // The classes in this file provide a simple framework for the
- // management of little pieces of machine code - or stubs -
---- hotspot/src/share/vm/compiler/disassembler.hpp
-+++ hotspot/src/share/vm/compiler/disassembler.hpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+   const char* reloc_string_for(u_char* begin, u_char* end);
+   // Returns true if this thread changed the state of the nmethod or
+--- hotspot/src/share/vm/code/relocInfo.hpp
++++ hotspot/src/share/vm/code/relocInfo.hpp
+@@ -371,7 +371,7 @@
+   // "immediate" in the prefix header word itself.  This optimization
+   // is invisible outside this module.)
  
- class decode_env;
+-  inline friend relocInfo prefix_relocInfo(int datalen = 0);
++  inline friend relocInfo prefix_relocInfo(int datalen);
  
---- hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.cpp
-+++ hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.cpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
- elapsedTimer CMSAdaptiveSizePolicy::_concurrent_timer;
- elapsedTimer CMSAdaptiveSizePolicy::_STW_timer;
+  protected:
+   // an immediate relocInfo optimizes a prefix with one 10-bit unsigned value
+@@ -466,7 +466,7 @@
+   return relocInfo(relocInfo::none, relocInfo::offset_limit() - relocInfo::offset_unit);
+ }
  
---- hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
-+++ hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.cpp
-@@ -50,6 +50,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+-inline relocInfo prefix_relocInfo(int datalen) {
++inline relocInfo prefix_relocInfo(int datalen = 0) {
+   assert(relocInfo::fits_into_immediate(datalen), "datalen in limits");
+   return relocInfo(relocInfo::data_prefix_tag, relocInfo::RAW_BITS, relocInfo::datalen_tag | datalen);
+ }
+@@ -686,7 +686,7 @@
+   }
  
- //
- // ConcurrentMarkSweepPolicy methods
---- hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp
-+++ hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp
-@@ -36,6 +36,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+  public:
+-  void* operator new(size_t size, const RelocationHolder& holder) {
++  void* operator new(size_t size, const RelocationHolder& holder) throw() {
+     if (size > sizeof(holder._relocbuf)) guarantee_size();
+     assert((void* const *)holder.reloc() == &holder._relocbuf[0], "ptrs must agree");
+     return holder.reloc();
+--- hotspot/src/share/vm/code/vtableStubs.cpp
++++ hotspot/src/share/vm/code/vtableStubs.cpp
+@@ -49,7 +49,7 @@
+ static int num_vtable_chunks = 0;
  
- class ConcurrentMarkSweepGeneration;
- class CMSCollector;
---- hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeBlockDictionary.cpp
-+++ hotspot/src/share/vm/gc_implementation/concurrentMarkSweep/freeBlockDictionary.cpp
-@@ -33,6 +33,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
  
- #ifndef PRODUCT
- Mutex* FreeBlockDictionary::par_lock() const {
---- hotspot/src/share/vm/gc_implementation/g1/dirtyCardQueue.cpp
-+++ hotspot/src/share/vm/gc_implementation/g1/dirtyCardQueue.cpp
-@@ -39,6 +39,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+-void* VtableStub::operator new(size_t size, int code_size) {
++void* VtableStub::operator new(size_t size, int code_size) throw() {
+   assert(size == sizeof(VtableStub), "mismatched size");
+   num_vtable_chunks++;
+   // compute real VtableStub size (rounded to nearest word)
+--- hotspot/src/share/vm/code/vtableStubs.hpp
++++ hotspot/src/share/vm/code/vtableStubs.hpp
+@@ -46,7 +46,7 @@
+   bool           _is_vtable_stub;    // True if vtable stub, false, is itable stub
+   /* code follows here */            // The vtableStub code
  
- bool DirtyCardQueue::apply_closure(CardTableEntryClosure* cl,
-                                    bool consume,
---- hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
-+++ hotspot/src/share/vm/gc_implementation/g1/g1SATBCardTableModRefBS.cpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+-  void* operator new(size_t size, int code_size);
++  void* operator new(size_t size, int code_size) throw();
  
- G1SATBCardTableModRefBS::G1SATBCardTableModRefBS(MemRegion whole_heap,
-                                                  int max_covered_regions) :
---- hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp
-+++ hotspot/src/share/vm/gc_implementation/g1/ptrQueue.cpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+   VtableStub(bool is_vtable_stub, int index)
+         : _next(NULL), _is_vtable_stub(is_vtable_stub),
+--- hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp
++++ hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp
+@@ -1858,8 +1858,9 @@
+       _cm->grayRegionIfNecessary(MemRegion(_real_start_word, _real_end_word));
  
- PtrQueue::PtrQueue(PtrQueueSet* qset, bool perm, bool active) :
-   _qset(qset), _buf(NULL), _index(0), _active(active),
---- hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp
-+++ hotspot/src/share/vm/gc_implementation/parallelScavenge/parMarkBitMap.cpp
-@@ -38,6 +38,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
+ #ifndef PRODUCT
+-      if (use_local_bitmaps && verify_local_bitmaps)
+-        verify();
++#if (use_local_bitmaps && verify_local_bitmaps)
++      verify();
 +#endif
+ #endif // PRODUCT
+     } else {
+       assert(_real_start_word == NULL && _real_end_word == NULL, "invariant");
+--- hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp
++++ hotspot/src/share/vm/gc_implementation/parallelScavenge/psPromotionManager.inline.hpp
+@@ -25,6 +25,7 @@
+ #ifndef SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
+ #define SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_PSPROMOTIONMANAGER_INLINE_HPP
  
- bool
- ParMarkBitMap::initialize(MemRegion covered_region)
---- hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
-+++ hotspot/src/share/vm/gc_implementation/parallelScavenge/psVirtualspace.cpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
++#include "gc_implementation/parallelScavenge/psOldGen.hpp"
+ #include "gc_implementation/parallelScavenge/psPromotionManager.hpp"
+ #include "gc_implementation/parallelScavenge/psScavenge.hpp"
  
- // PSVirtualSpace
+--- hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp
++++ hotspot/src/share/vm/gc_implementation/shared/gcUtil.hpp
+@@ -144,9 +144,9 @@
+     _padded_avg(0.0), _deviation(0.0), _padding(padding) {}
  
---- hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp
-+++ hotspot/src/share/vm/gc_implementation/shared/mutableNUMASpace.cpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
+   // Placement support
+-  void* operator new(size_t ignored, void* p) { return p; }
++  void* operator new(size_t ignored, void* p) throw() { return p; }
+   // Allocator
+-  void* operator new(size_t size) { return CHeapObj::operator new(size); }
++  void* operator new(size_t size) throw() { return CHeapObj::operator new(size); }
+ 
+   // Accessor
+   float padded_average() const         { return _padded_avg; }
+--- hotspot/src/share/vm/libadt/port.hpp
++++ hotspot/src/share/vm/libadt/port.hpp
+@@ -163,7 +163,7 @@
+ extern void *safe_calloc (const char *file, unsigned line, unsigned nitems, unsigned size);
+ extern void *safe_realloc(const char *file, unsigned line, void *ptr, unsigned size);
+ extern char *safe_strdup (const char *file, unsigned line, const char *src);
+-inline void *operator new( size_t size ) { return malloc(size); }
++inline void *operator new( size_t size ) throw() { return malloc(size); }
+ inline void operator delete( void *ptr ) { free(ptr); }
  #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
  
- 
- MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment) {
---- hotspot/src/share/vm/gc_interface/collectedHeap.cpp
-+++ hotspot/src/share/vm/gc_interface/collectedHeap.cpp
-@@ -39,6 +39,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
+--- hotspot/src/share/vm/memory/allocation.cpp
++++ hotspot/src/share/vm/memory/allocation.cpp
+@@ -43,11 +43,11 @@
+ # include "os_bsd.inline.hpp"
  #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
  
+-void* CHeapObj::operator new(size_t size){
++void* CHeapObj::operator new(size_t size) throw() {
+   return (void *) AllocateHeap(size, "CHeapObj-new");
+ }
  
+-void* CHeapObj::operator new (size_t size, const std::nothrow_t&  nothrow_constant) {
++void* CHeapObj::operator new (size_t size, const std::nothrow_t&  nothrow_constant) throw() {
+   char* p = (char*) os::malloc(size);
  #ifdef ASSERT
---- hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp
-+++ hotspot/src/share/vm/gc_interface/collectedHeap.inline.hpp
-@@ -43,6 +43,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+   if (PrintMallocFree) trace_heap_malloc(size, "CHeapObj-new", p);
+@@ -59,12 +59,12 @@
+  FreeHeap(p);
+ }
  
- // Inline allocation implementations.
+-void* StackObj::operator new(size_t size)  { ShouldNotCallThis(); return 0; };
++void* StackObj::operator new(size_t size) throw() { ShouldNotCallThis(); return 0; };
+ void  StackObj::operator delete(void* p)   { ShouldNotCallThis(); };
+-void* _ValueObj::operator new(size_t size)  { ShouldNotCallThis(); return 0; };
++void* _ValueObj::operator new(size_t size) throw() { ShouldNotCallThis(); return 0; };
+ void  _ValueObj::operator delete(void* p)   { ShouldNotCallThis(); };
  
---- hotspot/src/share/vm/interpreter/abstractInterpreter.hpp
-+++ hotspot/src/share/vm/interpreter/abstractInterpreter.hpp
-@@ -50,6 +50,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+-void* ResourceObj::operator new(size_t size, allocation_type type) {
++void* ResourceObj::operator new(size_t size, allocation_type type) throw() {
+   address res;
+   switch (type) {
+    case C_HEAP:
+@@ -311,7 +311,7 @@
+ //--------------------------------------------------------------------------------------
+ // Chunk implementation
  
- // This file contains the platform-independent parts
- // of the abstract interpreter and the abstract interpreter generator.
---- hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
-+++ hotspot/src/share/vm/interpreter/bytecodeInterpreter.cpp
-@@ -59,6 +59,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "orderAccess_windows_x86.inline.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "orderAccess_bsd_x86.inline.hpp"
-+#endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "orderAccess_bsd_zero.inline.hpp"
-+#endif
+-void* Chunk::operator new(size_t requested_size, AllocFailType alloc_failmode, size_t length) {
++void* Chunk::operator new(size_t requested_size, AllocFailType alloc_failmode, size_t length) throw() {
+   // requested_size is equal to sizeof(Chunk) but in order for the arena
+   // allocations to come out aligned as expected the size must be aligned
+   // to expected arean alignment.
+@@ -576,7 +576,7 @@
+ // src/share/native/sun/awt/font/fontmanager/textcache/hsMemory.cpp::hsSoftNew
+ // define CATCH_OPERATOR_NEW_USAGE if you want to use this.
+ #ifdef CATCH_OPERATOR_NEW_USAGE
+-void* operator new(size_t size){
++void* operator new(size_t size) throw() {
+   static bool warned = false;
+   if (!warned && warn_new_operator)
+     warning("should not call global (default) operator new");
+--- hotspot/src/share/vm/memory/allocation.hpp
++++ hotspot/src/share/vm/memory/allocation.hpp
+@@ -106,8 +106,8 @@
  
+ class CHeapObj ALLOCATION_SUPER_CLASS_SPEC {
+  public:
+-  void* operator new(size_t size);
+-  void* operator new (size_t size, const std::nothrow_t&  nothrow_constant);
++  void* operator new(size_t size) throw();
++  void* operator new (size_t size, const std::nothrow_t&  nothrow_constant) throw();
+   void  operator delete(void* p);
+   void* new_array(size_t size);
+ };
+@@ -117,7 +117,7 @@
  
- // no precompiled headers
---- hotspot/src/share/vm/interpreter/bytecodeTracer.cpp
-+++ hotspot/src/share/vm/interpreter/bytecodeTracer.cpp
-@@ -92,7 +92,7 @@
-       // the incoming method.  We could lose a line of trace output.
-       // This is acceptable in a debug-only feature.
-       st->cr();
--      st->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
-+      st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
-       method->print_name(st);
-       st->cr();
-       _current_method = method();
-@@ -106,7 +106,7 @@
-     }
-     _code = code;
-      int bci = bcp - method->code_base();
--    st->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
-+    st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
-     if (Verbose) {
-       st->print("%8d  %4d  " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
-            BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
---- hotspot/src/share/vm/interpreter/interpreterRuntime.hpp
-+++ hotspot/src/share/vm/interpreter/interpreterRuntime.hpp
-@@ -41,6 +41,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+ class StackObj ALLOCATION_SUPER_CLASS_SPEC {
+  public:
+-  void* operator new(size_t size);
++  void* operator new(size_t size) throw();
+   void  operator delete(void* p);
+ };
  
- // The InterpreterRuntime is called by the interpreter for everything
- // that cannot/should not be dealt with in assembly and needs C support.
---- hotspot/src/share/vm/interpreter/linkResolver.cpp
-+++ hotspot/src/share/vm/interpreter/linkResolver.cpp
-@@ -52,6 +52,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- //------------------------------------------------------------------------------------------------------------------------
- // Implementation of FieldAccessInfo
---- hotspot/src/share/vm/memory/allocation.cpp
-+++ hotspot/src/share/vm/memory/allocation.cpp
-@@ -39,6 +39,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
- 
- void* CHeapObj::operator new(size_t size){
-   return (void *) AllocateHeap(size, "CHeapObj-new");
---- hotspot/src/share/vm/memory/collectorPolicy.cpp
-+++ hotspot/src/share/vm/memory/collectorPolicy.cpp
-@@ -47,6 +47,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifndef SERIALGC
- #include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
- #include "gc_implementation/concurrentMarkSweep/cmsGCAdaptivePolicyCounters.hpp"
---- hotspot/src/share/vm/memory/defNewGeneration.cpp
-+++ hotspot/src/share/vm/memory/defNewGeneration.cpp
-@@ -48,6 +48,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
+@@ -141,7 +141,7 @@
  //
- // DefNewGeneration functions.
---- hotspot/src/share/vm/memory/gcLocker.hpp
-+++ hotspot/src/share/vm/memory/gcLocker.hpp
-@@ -41,6 +41,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
+ class _ValueObj {
+  public:
+-  void* operator new(size_t size);
++  void* operator new(size_t size) throw();
+   void operator delete(void* p);
+ };
  
- // The direct lock/unlock calls do not force a collection if an unlock
- // decrements the count to zero. Avoid calling these if at all possible.
---- hotspot/src/share/vm/memory/genMarkSweep.cpp
-+++ hotspot/src/share/vm/memory/genMarkSweep.cpp
-@@ -55,6 +55,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+@@ -163,7 +163,7 @@
+   Chunk*       _next;     // Next Chunk in list
+   const size_t _len;      // Size of this Chunk
+  public:
+-  void* operator new(size_t size, AllocFailType alloc_failmode, size_t length);
++  void* operator new(size_t size, AllocFailType alloc_failmode, size_t length) throw();
+   void  operator delete(void* p);
+   Chunk(size_t length);
  
- void GenMarkSweep::invoke_at_safepoint(int level, ReferenceProcessor* rp,
-   bool clear_all_softrefs) {
---- hotspot/src/share/vm/memory/resourceArea.cpp
-+++ hotspot/src/share/vm/memory/resourceArea.cpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+@@ -392,19 +392,19 @@
+ #endif // ASSERT
  
- //------------------------------ResourceMark-----------------------------------
- debug_only(int ResourceArea::_warned;)      // to suppress multiple warnings
---- hotspot/src/share/vm/memory/resourceArea.hpp
-+++ hotspot/src/share/vm/memory/resourceArea.hpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+  public:
+-  void* operator new(size_t size, allocation_type type);
+-  void* operator new(size_t size, Arena *arena) {
++  void* operator new(size_t size, allocation_type type) throw();
++  void* operator new(size_t size, Arena *arena) throw() {
+       address res = (address)arena->Amalloc(size);
+       DEBUG_ONLY(set_allocation_type(res, ARENA);)
+       return res;
+   }
+-  void* operator new(size_t size) {
++  void* operator new(size_t size) throw() {
+       address res = (address)resource_allocate_bytes(size);
+       DEBUG_ONLY(set_allocation_type(res, RESOURCE_AREA);)
+       return res;
+   }
  
- // The resource area holds temporary data structures in the VM.
- // The actual allocation areas are thread local. Typical usage:
---- hotspot/src/share/vm/memory/space.hpp
-+++ hotspot/src/share/vm/memory/space.hpp
-@@ -44,6 +44,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+-  void* operator new(size_t size, const std::nothrow_t& nothrow_constant) {
++  void* operator new(size_t size, const std::nothrow_t& nothrow_constant) throw() {
+     address res = (address)resource_allocate_bytes(size, AllocFailStrategy::RETURN_NULL);
+     DEBUG_ONLY(if (res != NULL) set_allocation_type(res, RESOURCE_AREA);)
+     return res;
+--- hotspot/src/share/vm/memory/cardTableModRefBS.cpp
++++ hotspot/src/share/vm/memory/cardTableModRefBS.cpp
+@@ -389,7 +389,7 @@
+   }
+   // Touch the last card of the covered region to show that it
+   // is committed (or SEGV).
+-  debug_only(*byte_for(_covered[ind].last());)
++  debug_only((void) (*byte_for(_covered[ind].last()));)
+   debug_only(verify_guard();)
+ }
  
- // A space is an abstraction for the "storage units" backing
- // up the generation abstraction. It includes specific
---- hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp
-+++ hotspot/src/share/vm/memory/threadLocalAllocBuffer.cpp
-@@ -38,6 +38,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+--- hotspot/src/share/vm/memory/memRegion.hpp
++++ hotspot/src/share/vm/memory/memRegion.hpp
+@@ -99,13 +99,13 @@
  
- // Thread-Local Edens support
+ class MemRegionClosureRO: public MemRegionClosure {
+ public:
+-  void* operator new(size_t size, ResourceObj::allocation_type type) {
++  void* operator new(size_t size, ResourceObj::allocation_type type) throw() {
+         return ResourceObj::operator new(size, type);
+   }
+-  void* operator new(size_t size, Arena *arena) {
++  void* operator new(size_t size, Arena *arena) throw() {
+         return ResourceObj::operator new(size, arena);
+   }
+-  void* operator new(size_t size) {
++  void* operator new(size_t size) throw() {
+         return ResourceObj::operator new(size);
+   }
  
 --- hotspot/src/share/vm/memory/universe.cpp
 +++ hotspot/src/share/vm/memory/universe.cpp
-@@ -89,6 +89,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifndef SERIALGC
- #include "gc_implementation/concurrentMarkSweep/cmsAdaptiveSizePolicy.hpp"
- #include "gc_implementation/concurrentMarkSweep/cmsCollectorPolicy.hpp"
---- hotspot/src/share/vm/oops/constantPoolKlass.cpp
-+++ hotspot/src/share/vm/oops/constantPoolKlass.cpp
-@@ -44,6 +44,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifndef SERIALGC
- #include "gc_implementation/parNew/parOopClosures.inline.hpp"
- #include "gc_implementation/parallelScavenge/psPromotionManager.inline.hpp"
---- hotspot/src/share/vm/oops/instanceKlass.cpp
-+++ hotspot/src/share/vm/oops/instanceKlass.cpp
-@@ -59,6 +59,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifndef SERIALGC
- #include "gc_implementation/g1/g1CollectedHeap.inline.hpp"
- #include "gc_implementation/g1/g1OopClosures.inline.hpp"
---- hotspot/src/share/vm/oops/markOop.cpp
-+++ hotspot/src/share/vm/oops/markOop.cpp
-@@ -33,6 +33,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+@@ -657,7 +657,9 @@
+   if (vt) vt->initialize_vtable(false, CHECK);
+   if (ko->oop_is_instance()) {
+     instanceKlass* ik = (instanceKlass*)ko;
+-    for (KlassHandle s_h(THREAD, ik->subklass()); s_h() != NULL; s_h = (THREAD, s_h()->klass_part()->next_sibling())) {
++    for (KlassHandle s_h(THREAD, ik->subklass());
++         s_h() != NULL;
++         s_h = KlassHandle(THREAD, s_h()->klass_part()->next_sibling())) {
+       reinitialize_vtable_of(s_h, CHECK);
+     }
+   }
+--- hotspot/src/share/vm/oops/klass.cpp
++++ hotspot/src/share/vm/oops/klass.cpp
+@@ -181,7 +181,7 @@
+ }
  
+ void* Klass_vtbl::operator new(size_t ignored, KlassHandle& klass,
+-                               int size, TRAPS) {
++                               int size, TRAPS) throw() {
+   // The vtable pointer is installed during the execution of
+   // constructors in the call to permanent_obj_allocate().  Delay
+   // the installation of the klass pointer into the new klass "k"
+--- hotspot/src/share/vm/oops/klass.hpp
++++ hotspot/src/share/vm/oops/klass.hpp
+@@ -167,7 +167,7 @@
+   bool null_vtbl() { return *(intptr_t*)this == 0; }
  
- void markOopDesc::print_on(outputStream* st) const {
---- hotspot/src/share/vm/oops/oop.cpp
-+++ hotspot/src/share/vm/oops/oop.cpp
-@@ -36,6 +36,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+  protected:
+-  void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS);
++  void* operator new(size_t ignored, KlassHandle& klass, int size, TRAPS) throw();
+ };
  
- bool always_do_update_barrier = false;
  
---- hotspot/src/share/vm/oops/oopsHierarchy.cpp
-+++ hotspot/src/share/vm/oops/oopsHierarchy.cpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+--- hotspot/src/share/vm/oops/symbol.cpp
++++ hotspot/src/share/vm/oops/symbol.cpp
+@@ -36,7 +36,7 @@
+   }
+ }
  
- #ifdef CHECK_UNHANDLED_OOPS
+-void* Symbol::operator new(size_t size, int len) {
++void* Symbol::operator new(size_t size, int len) throw() {
+   return (void *) AllocateHeap(object_size(len) * HeapWordSize, "symbol");
+ }
  
---- hotspot/src/share/vm/opto/c2_globals.hpp
-+++ hotspot/src/share/vm/opto/c2_globals.hpp
-@@ -41,6 +41,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "c2_globals_windows.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "c2_globals_bsd.hpp"
-+#endif
+--- hotspot/src/share/vm/oops/symbol.hpp
++++ hotspot/src/share/vm/oops/symbol.hpp
+@@ -121,7 +121,7 @@
+   }
  
- //
- // Defines all globals flags used by the server compiler.
---- hotspot/src/share/vm/prims/forte.cpp
-+++ hotspot/src/share/vm/prims/forte.cpp
-@@ -639,6 +639,11 @@
- // Method to let libcollector know about a dynamically loaded function.
- // Because it is weakly bound, the calls become NOP's when the library
- // isn't present.
-+#ifdef __APPLE__
-+// XXXDARWIN: Link errors occur even when __attribute__((weak_import))
-+// is added
-+#define collector_func_load(x0,x1,x2,x3,x4,x5,x6) (0)
-+#else
- void    collector_func_load(char* name,
-                             void* null_argument_1,
-                             void* null_argument_2,
-@@ -649,6 +654,7 @@
- #pragma weak collector_func_load
- #define collector_func_load(x0,x1,x2,x3,x4,x5,x6) \
-         ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),0 : 0 )
-+#endif // __APPLE__
- #endif // !_WINDOWS
+   Symbol(const u1* name, int length);
+-  void* operator new(size_t size, int len);
++  void* operator new(size_t size, int len) throw();
  
- } // end extern "C"
---- hotspot/src/share/vm/prims/jni.cpp
-+++ hotspot/src/share/vm/prims/jni.cpp
-@@ -88,6 +88,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
+  public:
+   // Low-level access (used with care, since not GC-safe)
+--- hotspot/src/share/vm/opto/callGenerator.hpp
++++ hotspot/src/share/vm/opto/callGenerator.hpp
+@@ -240,7 +240,7 @@
+   // Because WarmInfo objects live over the entire lifetime of the
+   // Compile object, they are allocated into the comp_arena, which
+   // does not get resource marked or reset during the compile process
+-  void *operator new( size_t x, Compile* C ) { return C->comp_arena()->Amalloc(x); }
++  void *operator new( size_t x, Compile* C ) throw() { return C->comp_arena()->Amalloc(x); }
+   void operator delete( void * ) { } // fast deallocation
  
- static jint CurrentVersion = JNI_VERSION_1_6;
+   static WarmCallInfo* always_hot();
+--- hotspot/src/share/vm/opto/callnode.hpp
++++ hotspot/src/share/vm/opto/callnode.hpp
+@@ -215,7 +215,7 @@
+   // Because JVMState objects live over the entire lifetime of the
+   // Compile object, they are allocated into the comp_arena, which
+   // does not get resource marked or reset during the compile process
+-  void *operator new( size_t x, Compile* C ) { return C->comp_arena()->Amalloc(x); }
++  void *operator new( size_t x, Compile* C ) throw() { return C->comp_arena()->Amalloc(x); }
+   void operator delete( void * ) { } // fast deallocation
  
---- hotspot/src/share/vm/prims/jvm.cpp
-+++ hotspot/src/share/vm/prims/jvm.cpp
-@@ -72,6 +72,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "jvm_windows.h"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "jvm_bsd.h"
-+#endif
+   // Create a new JVMState, ready for abstract interpretation.
+--- hotspot/src/share/vm/opto/machnode.hpp
++++ hotspot/src/share/vm/opto/machnode.hpp
+@@ -58,7 +58,7 @@
+ class MachOper : public ResourceObj {
+ public:
+   // Allocate right next to the MachNodes in the same arena
+-  void *operator new( size_t x, Compile* C ) { return C->node_arena()->Amalloc_D(x); }
++  void *operator new( size_t x, Compile* C ) throw() { return C->node_arena()->Amalloc_D(x); }
  
- #include <errno.h>
- 
---- hotspot/src/share/vm/prims/jvm.h
-+++ hotspot/src/share/vm/prims/jvm.h
-@@ -36,6 +36,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "jvm_windows.h"
+   // Opcode
+   virtual uint opcode() const = 0;
+--- hotspot/src/share/vm/opto/memnode.cpp
++++ hotspot/src/share/vm/opto/memnode.cpp
+@@ -1933,6 +1933,11 @@
+       if (t != NULL) {
+         // constant oop => constant klass
+         if (offset == java_lang_Class::array_klass_offset_in_bytes()) {
++          if (t->is_void()) {
++            // We cannot create a void array. Since void is a primitive type return null
++            // klass. Users of this result need to do a null check on the returned klass.
++            return TypePtr::NULL_PTR;
++          }
+           return TypeKlassPtr::make(ciArrayKlass::make(t));
+         }
+         if (!t->is_klass()) {
+@@ -4164,7 +4169,7 @@
+   }
+ }
+ #else // !ASSERT
+-#define verify_memory_slice(m,i,n) (0)  // PRODUCT version is no-op
++#define verify_memory_slice(m,i,n) (void)(0)  // PRODUCT version is no-op
  #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "jvm_bsd.h"
-+#endif
  
- #ifndef _JAVASOFT_JVM_H_
- #define _JAVASOFT_JVM_H_
---- hotspot/src/share/vm/prims/jvmtiEnv.cpp
-+++ hotspot/src/share/vm/prims/jvmtiEnv.cpp
-@@ -68,6 +68,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
  
- 
- 
---- hotspot/src/share/vm/prims/jvmtiImpl.cpp
-+++ hotspot/src/share/vm/prims/jvmtiImpl.cpp
-@@ -51,6 +51,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
+--- hotspot/src/share/vm/opto/node.cpp
++++ hotspot/src/share/vm/opto/node.cpp
+@@ -284,6 +284,10 @@
+ #ifdef _MSC_VER // the IDX_INIT hack falls foul of warning C4355
+ #pragma warning( disable:4355 ) // 'this' : used in base member initializer list
  #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
++#ifdef __clang__
++#pragma clang diagnostic push
++#pragma GCC diagnostic ignored "-Wuninitialized"
 +#endif
  
- //
- // class JvmtiAgentThread
---- hotspot/src/share/vm/prims/nativeLookup.cpp
-+++ hotspot/src/share/vm/prims/nativeLookup.cpp
-@@ -49,6 +49,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+ // Out-of-line code from node constructors.
+ // Executed only when extra debug info. is being passed around.
+@@ -459,6 +463,10 @@
+   _in[6] = n6; if (n6 != NULL) n6->add_out((Node *)this);
+ }
  
- 
- static void mangle_name_on(outputStream* st, symbolOop name, int begin, int end) {
---- hotspot/src/share/vm/runtime/arguments.cpp
-+++ hotspot/src/share/vm/runtime/arguments.cpp
-@@ -55,6 +55,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
++#ifdef __clang__
++#pragma clang diagnostic pop
 +#endif
- #ifndef SERIALGC
- #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
- #endif
---- hotspot/src/share/vm/runtime/atomic.cpp
-+++ hotspot/src/share/vm/runtime/atomic.cpp
-@@ -33,6 +33,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
- #ifdef TARGET_OS_ARCH_linux_x86
- # include "atomic_linux_x86.inline.hpp"
- #endif
-@@ -51,6 +54,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "atomic_windows_x86.inline.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "atomic_bsd_x86.inline.hpp"
-+#endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "atomic_bsd_zero.inline.hpp"
-+#endif
++
  
- jbyte Atomic::cmpxchg(jbyte exchange_value, volatile jbyte* dest, jbyte compare_value) {
-   assert(sizeof(jbyte) == 1, "assumption.");
---- hotspot/src/share/vm/runtime/fprofiler.hpp
-+++ hotspot/src/share/vm/runtime/fprofiler.hpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+ //------------------------------clone------------------------------------------
+ // Clone a Node.
+--- hotspot/src/share/vm/opto/node.hpp
++++ hotspot/src/share/vm/opto/node.hpp
+@@ -207,7 +207,7 @@
  
- // a simple flat profiler for Java
+   // New Operator that takes a Compile pointer, this will eventually
+   // be the "new" New operator.
+-  inline void* operator new( size_t x, Compile* C) {
++  inline void* operator new( size_t x, Compile* C) throw() {
+     Node* n = (Node*)C->node_arena()->Amalloc_D(x);
+ #ifdef ASSERT
+     n->_in = (Node**)n; // magic cookie for assertion check
+@@ -218,7 +218,7 @@
  
---- hotspot/src/share/vm/runtime/globals.hpp
-+++ hotspot/src/share/vm/runtime/globals.hpp
-@@ -44,6 +44,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "globals_windows.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "globals_bsd.hpp"
-+#endif
- #ifdef TARGET_OS_ARCH_linux_x86
- # include "globals_linux_x86.hpp"
- #endif
-@@ -62,6 +65,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "globals_windows_x86.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "globals_bsd_x86.hpp"
-+#endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "globals_bsd_zero.hpp"
-+#endif
- #ifdef COMPILER1
- #ifdef TARGET_ARCH_x86
- # include "c1_globals_x86.hpp"
-@@ -78,6 +87,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "c1_globals_windows.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "c1_globals_bsd.hpp"
-+#endif
- #endif
- #ifdef COMPILER2
- #ifdef TARGET_ARCH_x86
-@@ -95,6 +107,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "c2_globals_windows.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "c2_globals_bsd.hpp"
-+#endif
- #endif
- #ifdef SHARK
- #ifdef TARGET_ARCH_zero
---- hotspot/src/share/vm/runtime/handles.cpp
-+++ hotspot/src/share/vm/runtime/handles.cpp
-@@ -38,6 +38,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
+   // New Operator that takes a Compile pointer, this will eventually
+   // be the "new" New operator.
+-  inline void* operator new( size_t x, Compile* C, int y) {
++  inline void* operator new( size_t x, Compile* C, int y) throw() {
+     Node* n = (Node*)C->node_arena()->Amalloc_D(x + y*sizeof(void*));
+     n->_in = (Node**)(((char*)n) + x);
  #ifdef ASSERT
- oop* HandleArea::allocate_handle(oop obj) {
---- hotspot/src/share/vm/runtime/handles.inline.hpp
-+++ hotspot/src/share/vm/runtime/handles.inline.hpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+--- hotspot/src/share/vm/opto/parse3.cpp
++++ hotspot/src/share/vm/opto/parse3.cpp
+@@ -487,7 +487,8 @@
+                           fun, NULL, TypeRawPtr::BOTTOM,
+                           makecon(TypeKlassPtr::make(array_klass)),
+                           length[0], length[1], length[2],
+-                          length[3], length[4]);
++                          (ndimensions > 2) ? length[3] : NULL,
++                          (ndimensions > 3) ? length[4] : NULL);
+   } else {
+     // Create a java array for dimension sizes
+     Node* dims = NULL;
+--- hotspot/src/share/vm/opto/type.hpp
++++ hotspot/src/share/vm/opto/type.hpp
+@@ -144,7 +144,7 @@
  
- // these inline functions are in a separate file to break an include cycle
- // between Thread and Handle
---- hotspot/src/share/vm/runtime/interfaceSupport.hpp
-+++ hotspot/src/share/vm/runtime/interfaceSupport.hpp
-@@ -44,6 +44,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+ public:
  
- // Wrapper for all entry points to the virtual machine.
- // The HandleMarkCleaner is a faster version of HandleMark.
-@@ -114,6 +117,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "interfaceSupport_windows.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "interfaceSupport_bsd.hpp"
-+#endif
+-  inline void* operator new( size_t x ) {
++  inline void* operator new( size_t x ) throw() {
+     Compile* compile = Compile::current();
+     compile->set_type_last_size(x);
+     void *temp = compile->type_arena()->Amalloc_D(x);
+--- hotspot/src/share/vm/prims/forte.cpp
++++ hotspot/src/share/vm/prims/forte.cpp
+@@ -635,7 +635,7 @@
+                             void* null_argument_3);
+ #pragma weak collector_func_load
+ #define collector_func_load(x0,x1,x2,x3,x4,x5,x6) \
+-        ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),0 : 0 )
++        ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),(void)0 : (void)0 )
+ #endif // __APPLE__
+ #endif // !_WINDOWS
  
- };
+--- hotspot/src/share/vm/runtime/arguments.cpp
++++ hotspot/src/share/vm/runtime/arguments.cpp
+@@ -2499,7 +2499,9 @@
+          FLAG_SET_CMDLINE(uintx, MaxNewSize, NewSize);
+       }
  
---- hotspot/src/share/vm/runtime/java.cpp
-+++ hotspot/src/share/vm/runtime/java.cpp
-@@ -79,6 +79,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
++#ifndef _ALLBSD_SOURCE  // UseLargePages is not yet supported on BSD.
+       FLAG_SET_DEFAULT(UseLargePages, true);
 +#endif
- #ifndef SERIALGC
- #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
- #include "gc_implementation/parallelScavenge/psScavenge.hpp"
---- hotspot/src/share/vm/runtime/javaCalls.cpp
-+++ hotspot/src/share/vm/runtime/javaCalls.cpp
-@@ -48,6 +48,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
  
- // -----------------------------------------------------
- // Implementation of JavaCallWrapper
---- hotspot/src/share/vm/runtime/javaCalls.hpp
-+++ hotspot/src/share/vm/runtime/javaCalls.hpp
-@@ -48,6 +48,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
+       // Increase some data structure sizes for efficiency
+       FLAG_SET_CMDLINE(uintx, BaseFootPrintEstimate, MaxHeapSize);
+@@ -3046,6 +3048,10 @@
+   UNSUPPORTED_OPTION(UseG1GC, "G1 GC");
  #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
  
- // A JavaCallWrapper is constructed before each JavaCall and destructed after the call.
- // Its purpose is to allocate/deallocate a new handle block and to save/restore the last
---- hotspot/src/share/vm/runtime/javaFrameAnchor.hpp
-+++ hotspot/src/share/vm/runtime/javaFrameAnchor.hpp
-@@ -44,6 +44,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "orderAccess_windows_x86.inline.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "orderAccess_bsd_x86.inline.hpp"
++#ifdef _ALLBSD_SOURCE  // UseLargePages is not yet supported on BSD.
++  UNSUPPORTED_OPTION(UseLargePages, "-XX:+UseLargePages");
 +#endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "orderAccess_bsd_zero.inline.hpp"
-+#endif
- //
- // An object for encapsulating the machine/os dependent part of a JavaThread frame state
- //
---- hotspot/src/share/vm/runtime/jniHandles.cpp
-+++ hotspot/src/share/vm/runtime/jniHandles.cpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- 
- JNIHandleBlock* JNIHandles::_global_handles       = NULL;
---- hotspot/src/share/vm/runtime/memprofiler.cpp
-+++ hotspot/src/share/vm/runtime/memprofiler.cpp
-@@ -46,6 +46,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
++
  #ifndef PRODUCT
+   if (TraceBytecodesAt != 0) {
+     TraceBytecodes = true;
+--- hotspot/src/share/vm/runtime/fprofiler.cpp
++++ hotspot/src/share/vm/runtime/fprofiler.cpp
+@@ -264,7 +264,7 @@
  
---- hotspot/src/share/vm/runtime/mutex.cpp
-+++ hotspot/src/share/vm/runtime/mutex.cpp
-@@ -39,6 +39,10 @@
- # include "mutex_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "mutex_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
+  public:
  
- // o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o-o
- //
---- hotspot/src/share/vm/runtime/mutexLocker.cpp
-+++ hotspot/src/share/vm/runtime/mutexLocker.cpp
-@@ -36,6 +36,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
+-  void* operator new(size_t size, ThreadProfiler* tp);
++  void* operator new(size_t size, ThreadProfiler* tp) throw();
+   void  operator delete(void* p);
  
- // Mutexes used in the VM (see comment in mutexLocker.hpp):
- //
---- hotspot/src/share/vm/runtime/mutexLocker.hpp
-+++ hotspot/src/share/vm/runtime/mutexLocker.hpp
-@@ -36,6 +36,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+   ProfilerNode() {
+@@ -371,7 +371,7 @@
+   }
+ };
  
- // Mutexes used in the VM.
+-void* ProfilerNode::operator new(size_t size, ThreadProfiler* tp){
++void* ProfilerNode::operator new(size_t size, ThreadProfiler* tp) throw() {
+   void* result = (void*) tp->area_top;
+   tp->area_top += size;
  
---- hotspot/src/share/vm/runtime/objectMonitor.cpp
-+++ hotspot/src/share/vm/runtime/objectMonitor.cpp
-@@ -50,6 +50,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
+--- hotspot/src/share/vm/runtime/globals.hpp
++++ hotspot/src/share/vm/runtime/globals.hpp
+@@ -1125,7 +1125,7 @@
+   product(intx, hashCode, 0,                                                \
+          "(Unstable) select hashCode generation algorithm" )                \
+                                                                             \
+-  product(intx, WorkAroundNPTLTimedWaitHang, 1,                             \
++  product(intx, WorkAroundNPTLTimedWaitHang, 0,                             \
+          "(Unstable, Linux-specific)"                                       \
+          " avoid NPTL-FUTEX hang pthread_cond_timedwait" )                  \
+                                                                             \
+--- hotspot/src/share/vm/runtime/interfaceSupport.hpp
++++ hotspot/src/share/vm/runtime/interfaceSupport.hpp
+@@ -67,7 +67,7 @@
+   }
  
- #if defined(__GNUC__) && !defined(IA64)
-   // Need to inhibit inlining for older versions of GCC to avoid build-time failures
---- hotspot/src/share/vm/runtime/os.cpp
-+++ hotspot/src/share/vm/runtime/os.cpp
-@@ -60,6 +60,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- # include <signal.h>
- 
-@@ -115,7 +119,11 @@
-     assert(false, "Failed localtime_pd");
-     return NULL;
+  private:
+-  inline void* operator new(size_t size, void* ptr) {
++  inline void* operator new(size_t size, void* ptr) throw() {
+     return ptr;
    }
-+#if defined(_ALLBSD_SOURCE)
-+  const time_t zone = (time_t) time_struct.tm_gmtoff;
-+#else
-   const time_t zone = timezone;
-+#endif
- 
-   // If daylight savings time is in effect,
-   // we are 1 hour East of our time zone
+ };
 --- hotspot/src/share/vm/runtime/os.hpp
 +++ hotspot/src/share/vm/runtime/os.hpp
-@@ -30,6 +30,9 @@
- #include "runtime/extendedPC.hpp"
- #include "runtime/handles.hpp"
- #include "utilities/top.hpp"
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "jvm_bsd.h"
-+#endif
- #ifdef TARGET_OS_FAMILY_linux
- # include "jvm_linux.h"
- #endif
-@@ -658,6 +661,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.hpp"
-+#endif
- #ifdef TARGET_OS_ARCH_linux_x86
- # include "os_linux_x86.hpp"
- #endif
-@@ -676,6 +682,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "os_windows_x86.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "os_bsd_x86.hpp"
-+#endif
-+#ifdef TARGET_OS_ARCH_linux_zero
-+# include "os_bsd_zero.hpp"
-+#endif
+@@ -636,6 +636,10 @@
+   // On Windows this will create an actual minidump, on Linux/Solaris it will simply check core dump limits
+   static void check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize);
  
++  // Get the default path to the core file
++  // Returns the length of the string
++  static int get_core_path(char* buffer, size_t bufferSize);
++
+   // JVMTI & JVM monitoring and management support
+   // The thread_cpu_time() and current_thread_cpu_time() are only
+   // supported if is_thread_cpu_time_supported() returns true.
+--- hotspot/src/share/vm/runtime/park.cpp
++++ hotspot/src/share/vm/runtime/park.cpp
+@@ -140,7 +140,7 @@
+ // well as bank access imbalance on Niagara-like platforms,
+ // although Niagara's hash function should help.
  
-   // debugging support (mostly used by debug.cpp but also fatal error handler)
---- hotspot/src/share/vm/runtime/osThread.hpp
-+++ hotspot/src/share/vm/runtime/osThread.hpp
-@@ -109,6 +109,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "osThread_windows.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "osThread_bsd.hpp"
-+#endif
+-void * ParkEvent::operator new (size_t sz) {
++void * ParkEvent::operator new (size_t sz) throw() {
+   return (void *) ((intptr_t (CHeapObj::operator new (sz + 256)) + 256) & -256) ;
+ }
  
- };
+--- hotspot/src/share/vm/runtime/park.hpp
++++ hotspot/src/share/vm/runtime/park.hpp
+@@ -166,7 +166,7 @@
+     // aligned on 256-byte address boundaries.  This ensures that the least
+     // significant byte of a ParkEvent address is always 0.
  
---- hotspot/src/share/vm/runtime/safepoint.cpp
-+++ hotspot/src/share/vm/runtime/safepoint.cpp
-@@ -70,6 +70,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifndef SERIALGC
- #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
- #include "gc_implementation/shared/concurrentGCThread.hpp"
---- hotspot/src/share/vm/runtime/synchronizer.cpp
-+++ hotspot/src/share/vm/runtime/synchronizer.cpp
-@@ -51,6 +51,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
+-    void * operator new (size_t sz) ;
++    void * operator new (size_t sz) throw() ;
+     void operator delete (void * a) ;
  
- #if defined(__GNUC__) && !defined(IA64)
-   // Need to inhibit inlining for older versions of GCC to avoid build-time failures
---- hotspot/src/share/vm/runtime/task.cpp
-+++ hotspot/src/share/vm/runtime/task.cpp
-@@ -39,6 +39,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
+   public:
+--- hotspot/src/share/vm/runtime/sharedRuntime.cpp
++++ hotspot/src/share/vm/runtime/sharedRuntime.cpp
+@@ -2778,7 +2778,7 @@
+   // ResourceObject, so do not put any ResourceMarks in here.
+   char *s = sig->as_C_string();
+   int len = (int)strlen(s);
+-  *s++; len--;                  // Skip opening paren
++  s++; len--;                   // Skip opening paren
+   char *t = s+len;
+   while( *(--t) != ')' ) ;      // Find close paren
  
- int PeriodicTask::_num_tasks = 0;
- PeriodicTask* PeriodicTask::_tasks[PeriodicTask::max_tasks];
 --- hotspot/src/share/vm/runtime/thread.cpp
 +++ hotspot/src/share/vm/runtime/thread.cpp
-@@ -88,6 +88,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifndef SERIALGC
- #include "gc_implementation/concurrentMarkSweep/concurrentMarkSweepThread.hpp"
- #include "gc_implementation/g1/concurrentMarkThread.inline.hpp"
+@@ -170,7 +170,7 @@
+ // ======= Thread ========
+ 
+ // Support for forcing alignment of thread objects for biased locking
+-void* Thread::operator new(size_t size) {
++void* Thread::operator new(size_t size) throw() {
+   if (UseBiasedLocking) {
+     const int alignment = markOopDesc::biased_lock_alignment;
+     size_t aligned_size = size + (alignment - sizeof(intptr_t));
 --- hotspot/src/share/vm/runtime/thread.hpp
 +++ hotspot/src/share/vm/runtime/thread.hpp
-@@ -1598,6 +1598,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "thread_windows_x86.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "thread_bsd_x86.hpp"
-+#endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "thread_bsd_zero.hpp"
-+#endif
- 
- 
+@@ -104,7 +104,7 @@
+   // Support for forcing alignment of thread objects for biased locking
+   void*       _real_malloc_address;
   public:
---- hotspot/src/share/vm/runtime/threadLocalStorage.cpp
-+++ hotspot/src/share/vm/runtime/threadLocalStorage.cpp
-@@ -36,6 +36,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
+-  void* operator new(size_t size);
++  void* operator new(size_t size) throw();
+   void  operator delete(void* p);
+  private:
  
- // static member initialization
- int ThreadLocalStorage::_thread_index = -1;
---- hotspot/src/share/vm/runtime/threadLocalStorage.hpp
-+++ hotspot/src/share/vm/runtime/threadLocalStorage.hpp
-@@ -62,6 +62,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "threadLS_windows_x86.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "threadLS_bsd_x86.hpp"
-+#endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "threadLS_bsd_zero.hpp"
-+#endif
+--- hotspot/src/share/vm/services/diagnosticArgument.cpp
++++ hotspot/src/share/vm/services/diagnosticArgument.cpp
+@@ -191,7 +191,7 @@
+   } else {
+     _value._time = 0;
+     _value._nanotime = 0;
+-    strcmp(_value._unit, "ns");
++    strcpy(_value._unit, "ns");
+   }
+ }
  
+--- hotspot/src/share/vm/utilities/exceptions.hpp
++++ hotspot/src/share/vm/utilities/exceptions.hpp
+@@ -182,15 +182,15 @@
+ #define HAS_PENDING_EXCEPTION                    (((ThreadShadow*)THREAD)->has_pending_exception())
+ #define CLEAR_PENDING_EXCEPTION                  (((ThreadShadow*)THREAD)->clear_pending_exception())
  
-  public:
---- hotspot/src/share/vm/runtime/timer.cpp
-+++ hotspot/src/share/vm/runtime/timer.cpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+-#define CHECK                                    THREAD); if (HAS_PENDING_EXCEPTION) return       ; (0
+-#define CHECK_(result)                           THREAD); if (HAS_PENDING_EXCEPTION) return result; (0
++#define CHECK                                    THREAD); if (HAS_PENDING_EXCEPTION) return       ; (void)(0
++#define CHECK_(result)                           THREAD); if (HAS_PENDING_EXCEPTION) return result; (void)(0
+ #define CHECK_0                                  CHECK_(0)
+ #define CHECK_NH                                 CHECK_(Handle())
+ #define CHECK_NULL                               CHECK_(NULL)
+ #define CHECK_false                              CHECK_(false)
  
+-#define CHECK_AND_CLEAR                         THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return;        } (0
+-#define CHECK_AND_CLEAR_(result)                THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return result; } (0
++#define CHECK_AND_CLEAR                         THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return;        } (void)(0
++#define CHECK_AND_CLEAR_(result)                THREAD); if (HAS_PENDING_EXCEPTION) { CLEAR_PENDING_EXCEPTION; return result; } (void)(0
+ #define CHECK_AND_CLEAR_0                       CHECK_AND_CLEAR_(0)
+ #define CHECK_AND_CLEAR_NH                      CHECK_AND_CLEAR_(Handle())
+ #define CHECK_AND_CLEAR_NULL                    CHECK_AND_CLEAR_(NULL)
+@@ -263,7 +263,7 @@
+     CLEAR_PENDING_EXCEPTION;               \
+     ex->print();                           \
+     ShouldNotReachHere();                  \
+-  } (0
++  } (void)(0
  
- void elapsedTimer::add(elapsedTimer t) {
---- hotspot/src/share/vm/runtime/virtualspace.cpp
-+++ hotspot/src/share/vm/runtime/virtualspace.cpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
+ // ExceptionMark is a stack-allocated helper class for local exception handling.
+ // It is used with the EXCEPTION_MARK macro.
+--- hotspot/src/share/vm/utilities/globalDefinitions.hpp
++++ hotspot/src/share/vm/utilities/globalDefinitions.hpp
+@@ -421,7 +421,7 @@
+ // Utility macros for compilers
+ // used to silence compiler warnings
  
+-#define Unused_Variable(var) var
++#define Unused_Variable(var) (void)(var)
  
- // ReservedSpace
---- hotspot/src/share/vm/runtime/vmStructs.cpp
-+++ hotspot/src/share/vm/runtime/vmStructs.cpp
-@@ -118,6 +118,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifdef TARGET_OS_ARCH_linux_x86
- # include "vmStructs_linux_x86.hpp"
- #endif
-@@ -136,6 +139,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "vmStructs_windows_x86.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "vmStructs_bsd_x86.hpp"
-+#endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "vmStructs_bsd_zero.hpp"
-+#endif
- #ifndef SERIALGC
- #include "gc_implementation/concurrentMarkSweep/cmsPermGen.hpp"
- #include "gc_implementation/concurrentMarkSweep/compactibleFreeListSpace.hpp"
---- hotspot/src/share/vm/runtime/vmThread.cpp
-+++ hotspot/src/share/vm/runtime/vmThread.cpp
-@@ -46,6 +46,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
  
- HS_DTRACE_PROBE_DECL3(hotspot, vmops__request, char *, uintptr_t, int);
- HS_DTRACE_PROBE_DECL3(hotspot, vmops__begin, char *, uintptr_t, int);
---- hotspot/src/share/vm/runtime/vmThread.hpp
-+++ hotspot/src/share/vm/runtime/vmThread.hpp
-@@ -36,6 +36,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- //
- // Prioritized queue of VM operations.
---- hotspot/src/share/vm/runtime/vm_operations.cpp
-+++ hotspot/src/share/vm/runtime/vm_operations.cpp
-@@ -43,6 +43,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- #define VM_OP_NAME_INITIALIZE(name) #name,
- 
---- hotspot/src/share/vm/runtime/vm_version.cpp
-+++ hotspot/src/share/vm/runtime/vm_version.cpp
-@@ -160,7 +160,8 @@
- 
- #define OS       LINUX_ONLY("linux")             \
-                  WINDOWS_ONLY("windows")         \
--                 SOLARIS_ONLY("solaris")
-+                 SOLARIS_ONLY("solaris")         \
-+                 BSD_ONLY("bsd")
- 
- #ifdef ZERO
- #define CPU      ZERO_LIBARCH
---- hotspot/src/share/vm/utilities/accessFlags.cpp
-+++ hotspot/src/share/vm/utilities/accessFlags.cpp
-@@ -34,6 +34,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
- 
- 
- void AccessFlags::atomic_set_bits(jint bits) {
---- hotspot/src/share/vm/utilities/array.cpp
-+++ hotspot/src/share/vm/utilities/array.cpp
-@@ -34,6 +34,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- 
- #ifdef ASSERT
---- hotspot/src/share/vm/utilities/bitMap.cpp
-+++ hotspot/src/share/vm/utilities/bitMap.cpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
- 
- 
- BitMap::BitMap(bm_word_t* map, idx_t size_in_bits) :
---- hotspot/src/share/vm/utilities/debug.cpp
-+++ hotspot/src/share/vm/utilities/debug.cpp
-@@ -62,6 +62,10 @@
- # include "os_windows.inline.hpp"
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- #ifndef ASSERT
- #  ifdef _DEBUG
---- hotspot/src/share/vm/utilities/elfFile.hpp
-+++ hotspot/src/share/vm/utilities/elfFile.hpp
-@@ -41,7 +41,9 @@
- typedef Elf64_Shdr      Elf_Shdr;
- typedef Elf64_Sym       Elf_Sym;
- 
-+#ifndef _ALLBSD_SOURCE
- #define ELF_ST_TYPE ELF64_ST_TYPE
-+#endif
- 
- #else
- 
-@@ -55,8 +57,10 @@
- typedef Elf32_Shdr      Elf_Shdr;
- typedef Elf32_Sym       Elf_Sym;
- 
-+#ifndef _ALLBSD_SOURCE
- #define ELF_ST_TYPE ELF32_ST_TYPE
- #endif
-+#endif
- 
- #include "globalDefinitions.hpp"
- #include "memory/allocation.hpp"
---- hotspot/src/share/vm/utilities/events.cpp
-+++ hotspot/src/share/vm/utilities/events.cpp
-@@ -38,6 +38,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- 
- #ifndef PRODUCT
---- hotspot/src/share/vm/utilities/exceptions.cpp
-+++ hotspot/src/share/vm/utilities/exceptions.cpp
-@@ -42,6 +42,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- 
- // Implementation of ThreadShadow
+ //----------------------------------------------------------------------------------------------------
 --- hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
 +++ hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
-@@ -76,13 +76,26 @@
- # include <sys/procfs.h>
- # endif
- 
--#ifdef LINUX
-+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
- #define __STDC_LIMIT_MACROS
- #include <inttypes.h>
- #include <signal.h>
-+#ifndef __OpenBSD__
- #include <ucontext.h>
-+#endif
-+#ifdef __APPLE__
-+  #include <AvailabilityMacros.h>
-+  #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4)
-+    // Mac OS X 10.4 defines EFL_AC and EFL_ID,
-+    // which conflict with hotspot variable names.
-+    //
-+    // This has been fixed in Mac OS X 10.5.
-+    #undef EFL_AC
-+    #undef EFL_ID
-+  #endif
-+#endif
- #include <sys/time.h>
--#endif // LINUX
-+#endif // LINUX || _ALLBSD_SOURCE
- 
- // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures
- // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in
-@@ -118,7 +131,7 @@
- // pointer is stored as integer value.  On some platforms, sizeof(intptr_t) >
- // sizeof(void*), so here we want something which is integer type, but has the
- // same size as a pointer.
--#ifdef LINUX
-+#ifdef __GNUC__
-   #ifdef _LP64
-     #define NULL_WORD  0L
-   #else
-@@ -130,7 +143,7 @@
-   #define NULL_WORD  NULL
+@@ -260,7 +260,7 @@
  #endif
  
--#ifndef LINUX
-+#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
- // Compiler-specific primitive types
- typedef unsigned short     uint16_t;
- #ifndef _UINT32_T
-@@ -150,7 +163,7 @@
- // prior definition of intptr_t, and add "&& !defined(XXX)" above.
- #endif // _SYS_INT_TYPES_H
- 
--#endif // !LINUX
-+#endif // !LINUX && !_ALLBSD_SOURCE
- 
- // Additional Java basic types
- 
-@@ -242,7 +255,9 @@
- inline int g_isnan(float  f) { return isnand(f); }
+ // GCC 4.3 does not allow 0.0/0.0 to produce a NAN value
+-#if (__GNUC__ == 4) && (__GNUC_MINOR__ > 2)
++#if defined(__clang__) || ((__GNUC__ == 4) && (__GNUC_MINOR__ > 2))
+ #define CAN_USE_NAN_DEFINE 1
  #endif
- inline int g_isnan(double f) { return isnand(f); }
--#elif LINUX
-+#elif defined(__APPLE__)
-+inline int g_isnan(double f) { return isnan(f); }
-+#elif defined(LINUX) || defined(_ALLBSD_SOURCE)
- inline int g_isnan(float  f) { return isnanf(f); }
- inline int g_isnan(double f) { return isnan(f); }
- #else
---- hotspot/src/share/vm/utilities/growableArray.cpp
-+++ hotspot/src/share/vm/utilities/growableArray.cpp
-@@ -34,6 +34,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- #ifdef ASSERT
- void GenericGrowableArray::set_nesting() {
-   if (on_stack()) {
---- hotspot/src/share/vm/utilities/hashtable.hpp
-+++ hotspot/src/share/vm/utilities/hashtable.hpp
-@@ -283,7 +283,7 @@
-   }
  
-   int index_for(symbolHandle name, Handle loader) {
--    return hash_to_index(compute_hash(name, loader));
-+    return this->hash_to_index(compute_hash(name, loader));
-   }
- };
- 
---- hotspot/src/share/vm/utilities/histogram.hpp
-+++ hotspot/src/share/vm/utilities/histogram.hpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
- 
- // This class provides a framework for collecting various statistics.
- // The current implementation is oriented towards counting invocations
 --- hotspot/src/share/vm/utilities/macros.hpp
 +++ hotspot/src/share/vm/utilities/macros.hpp
-@@ -161,6 +161,14 @@
- #define NOT_WINDOWS(code) code
+@@ -177,6 +177,14 @@
+ #define NOT_WIN64(code) code
  #endif
  
 +#if defined(__MidnightBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
@@ -8700,122 +3205,96 @@
  #if defined(IA32) || defined(AMD64)
  #define X86
  #define X86_ONLY(code) code
---- hotspot/src/share/vm/utilities/ostream.cpp
-+++ hotspot/src/share/vm/utilities/ostream.cpp
-@@ -39,6 +39,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "os_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "os_bsd.inline.hpp"
-+#endif
- 
- extern "C" void jio_print(const char* s); // Declarationtion of jvm method
- 
-@@ -863,7 +866,7 @@
- 
- #ifndef PRODUCT
- 
--#if defined(SOLARIS) || defined(LINUX)
-+#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)
- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
---- hotspot/src/share/vm/utilities/preserveException.hpp
-+++ hotspot/src/share/vm/utilities/preserveException.hpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- // This file provides more support for exception handling; see also exceptions.hpp
- class PreserveExceptionMark {
---- hotspot/src/share/vm/utilities/taskqueue.cpp
-+++ hotspot/src/share/vm/utilities/taskqueue.cpp
-@@ -37,6 +37,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- #ifdef TRACESPINNING
- uint ParallelTaskTerminator::_total_yields = 0;
 --- hotspot/src/share/vm/utilities/taskqueue.hpp
 +++ hotspot/src/share/vm/utilities/taskqueue.hpp
-@@ -47,6 +47,12 @@
- #ifdef TARGET_OS_ARCH_windows_x86
- # include "orderAccess_windows_x86.inline.hpp"
- #endif
-+#ifdef TARGET_OS_ARCH_bsd_x86
-+# include "orderAccess_bsd_x86.inline.hpp"
+@@ -334,8 +334,12 @@ bool GenericTaskQueue<E, N>::push_slow(E
+   if (dirty_n_elems == N - 1) {
+     // Actually means 0, so do the push.
+     uint localBot = _bottom;
+-    // g++ complains if the volatile result of the assignment is unused.
+-    const_cast<E&>(_elems[localBot] = t);
++    // g++ complains if the volatile result of the assignment is
++    // unused, so we cast the volatile away.  We cannot cast directly
++    // to void, because gcc treats that as not using the result of the
++    // assignment.  However, casting to E& means that we trigger an
++    // unused-value warning.  So, we cast the E& to void.
++    (void)const_cast<E&>(_elems[localBot] = t);
+     OrderAccess::release_store(&_bottom, increment_index(localBot));
+     TASKQUEUE_STATS_ONLY(stats.record_push());
+     return true;
+@@ -385,13 +389,24 @@ bool GenericTaskQueue<E, N>::pop_local_s
+ template<class E, unsigned int N>
+ bool GenericTaskQueue<E, N>::pop_global(E& t) {
+   Age oldAge = _age.get();
+-  uint localBot = _bottom;
++  // Architectures with weak memory model require a barrier here
++  // to guarantee that bottom is not older than age,
++  // which is crucial for the correctness of the algorithm.
++#if !(defined SPARC || defined IA32 || defined AMD64)
++  OrderAccess::fence();
 +#endif
-+#ifdef TARGET_OS_ARCH_bsd_zero
-+# include "orderAccess_bsd_zero.inline.hpp"
-+#endif
++  uint localBot = OrderAccess::load_acquire((volatile juint*)&_bottom); 
+   uint n_elems = size(localBot, oldAge.top());
+   if (n_elems == 0) {
+     return false;
+   }
  
- // Simple TaskQueue stats that are collected by default in debug builds.
- 
+-  const_cast<E&>(t = _elems[oldAge.top()]);
++  // g++ complains if the volatile result of the assignment is
++  // unused, so we cast the volatile away.  We cannot cast directly
++  // to void, because gcc treats that as not using the result of the
++  // assignment.  However, casting to E& means that we trigger an
++  // unused-value warning.  So, we cast the E& to void.
++  (void) const_cast<E&>(t = _elems[oldAge.top()]);
+   Age newAge(oldAge);
+   newAge.increment();
+   Age resAge = _age.cmpxchg(newAge, oldAge);
+@@ -668,13 +683,17 @@ public:
+ template<class E, unsigned int N> inline bool
+ GenericTaskQueue<E, N>::push(E t) {
+   uint localBot = _bottom;
+-  assert((localBot >= 0) && (localBot < N), "_bottom out of range.");
++  assert(localBot < N, "_bottom out of range.");
+   idx_t top = _age.top();
+   uint dirty_n_elems = dirty_size(localBot, top);
+   assert(dirty_n_elems < N, "n_elems out of range.");
+   if (dirty_n_elems < max_elems()) {
+-    // g++ complains if the volatile result of the assignment is unused.
+-    const_cast<E&>(_elems[localBot] = t);
++    // g++ complains if the volatile result of the assignment is
++    // unused, so we cast the volatile away.  We cannot cast directly
++    // to void, because gcc treats that as not using the result of the
++    // assignment.  However, casting to E& means that we trigger an
++    // unused-value warning.  So, we cast the E& to void.
++    (void) const_cast<E&>(_elems[localBot] = t);
+     OrderAccess::release_store(&_bottom, increment_index(localBot));
+     TASKQUEUE_STATS_ONLY(stats.record_push());
+     return true;
+@@ -698,7 +717,12 @@ GenericTaskQueue<E, N>::pop_local(E& t) 
+   // This is necessary to prevent any read below from being reordered
+   // before the store just above.
+   OrderAccess::fence();
+-  const_cast<E&>(t = _elems[localBot]);
++  // g++ complains if the volatile result of the assignment is
++  // unused, so we cast the volatile away.  We cannot cast directly
++  // to void, because gcc treats that as not using the result of the
++  // assignment.  However, casting to E& means that we trigger an
++  // unused-value warning.  So, we cast the E& to void.
++  (void) const_cast<E&>(t = _elems[localBot]);
+   // This is a second read of "age"; the "size()" above is the first.
+   // If there's still at least one element in the queue, based on the
+   // "_bottom" and "age" we've read, then there can be no interference with
 --- hotspot/src/share/vm/utilities/vmError.cpp
 +++ hotspot/src/share/vm/utilities/vmError.cpp
-@@ -44,13 +44,18 @@
-   "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
-   "JAVA_COMPILER", "PATH", "USERNAME",
- 
--  // Env variables that are defined on Solaris/Linux
-+  // Env variables that are defined on Solaris/Linux/BSD
-   "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
-   "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
- 
-   // defined on Linux
-   "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM",
- 
-+  // defined on Darwin
-+  "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH",
-+  "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",
-+  "DYLD_INSERT_LIBRARIES",
-+
-   // defined on Windows
-   "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
- 
-@@ -922,7 +927,7 @@
-     const char* ptr = OnError;
-     while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
-       out.print_raw   ("#   Executing ");
+@@ -1043,7 +1043,7 @@
+   const char* ptr = OnOutOfMemoryError;
+   while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
+     tty->print("#   Executing ");
 -#if defined(LINUX)
 +#if defined(LINUX) || defined(_ALLBSD_SOURCE)
-       out.print_raw   ("/bin/sh -c ");
+     tty->print  ("/bin/sh -c ");
  #elif defined(SOLARIS)
-       out.print_raw   ("/usr/bin/sh -c ");
---- hotspot/src/share/vm/utilities/workgroup.hpp
-+++ hotspot/src/share/vm/utilities/workgroup.hpp
-@@ -35,6 +35,9 @@
- #ifdef TARGET_OS_FAMILY_windows
- # include "thread_windows.inline.hpp"
- #endif
-+#ifdef TARGET_OS_FAMILY_bsd
-+# include "thread_bsd.inline.hpp"
-+#endif
- 
- // Forward declarations of classes defined here
- 
---- jaxp/jaxp.properties
-+++ jaxp/jaxp.properties
-@@ -25,8 +25,8 @@
- 
- drops.master.copy.base=${drops.dir}
- 
--jaxp_src.bundle.name=jaxp144_04.zip
--jaxp_src.bundle.md5.checksum=0ace787aa12177d201947e8ba0ba9bdd
-+jaxp_src.bundle.name=jaxp144_05.zip
-+jaxp_src.bundle.md5.checksum=03be10db6ee87a8163316a87a3d3cba5
- jaxp_src.master.bundle.dir=${drops.master.copy.base}
- jaxp_src.master.bundle.url.base=http://download.java.net/jaxp/openjdk/jdk6
- 
+     tty->print  ("/usr/bin/sh -c ");
 --- jdk/make/com/sun/java/pack/Makefile
 +++ jdk/make/com/sun/java/pack/Makefile
 @@ -61,6 +61,7 @@
@@ -8831,7 +3310,7 @@
    OTHER_CXXFLAGS += $(ZINCLUDE)
    LDDFLAGS += $(ZIPOBJS)
 + else
-+  LDDFLAGS += -lz
++  LDDFLAGS += %%ZLIB_LDFLAGS%%
 +  OTHER_CXXFLAGS += -DSYSTEM_ZLIB
 + endif
  else
@@ -8851,24 +3330,15 @@
  ifeq ($(PLATFORM), linux)
 --- jdk/make/com/sun/jmx/Makefile
 +++ jdk/make/com/sun/jmx/Makefile
-@@ -102,16 +102,7 @@
+@@ -102,7 +102,7 @@
  # when available, we need to run with latest rmic version available. rmic 
  # launch tool not built at this stage but we can invoke via rmi class.
  
 -RMIC_JAVA = $(OUTPUTDIR)/bin/java
--# need to treat 64bit solaris differently
--ifeq ($(PLATFORM)-$(LIBARCH), solaris-amd64)
--RMIC_JAVA = $(OUTPUTDIR)/bin/amd64/java
--endif
--ifeq ($(PLATFORM)-$(LIBARCH), solaris-sparcv9)
--RMIC_JAVA = $(OUTPUTDIR)/bin/sparcv9/java
--endif
--
--RMIC = $(RMIC_JAVA) $(JAVA_TOOLS_FLAGS) -cp $(OUTPUTDIR)/classes sun.rmi.rmic.Main
-+RMIC = $(BOOT_JAVA_CMD) -cp $(OUTPUTDIR)/classes sun.rmi.rmic.Main
- 
- $(CLASSDESTDIR)/%_Stub.class: $(CLASSDESTDIR)/%.class
- 	$(prep-target)
++RMIC_JAVA = $(BOOTDIR)/bin/java
+ # need to treat 64bit solaris differently
+ ifeq ($(PLATFORM)-$(LIBARCH), solaris-amd64)
+ RMIC_JAVA = $(OUTPUTDIR)/bin/amd64/java
 --- jdk/make/com/sun/security/auth/module/Makefile
 +++ jdk/make/com/sun/security/auth/module/Makefile
 @@ -70,7 +70,7 @@
@@ -9058,7 +3528,7 @@
  endif
  
  #
-@@ -306,7 +282,9 @@
+@@ -306,24 +282,22 @@
  override HAVE_FILIOH             = false
  override HAVE_GETHRTIME          = false
  override HAVE_GETHRVTIME         = false
@@ -9068,7 +3538,11 @@
  override LEX_LIBRARY             = -lfl
  ifeq ($(STATIC_CXX),true)
  override LIBCXX                  = -Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic
-@@ -317,13 +295,9 @@
+ else
+-override LIBCXX                  = -lstdc++
++override LIBCXX                  = %%CXX_LDFLAGS%%
+ endif
+ override LIBPOSIX4               =
  override LIBSOCKET               =
  override LIBTHREAD               =
  override MOOT_PRIORITIES         = true
@@ -9099,17 +3573,6 @@
  #
  # Japanese manpages
  #
---- jdk/make/common/Defs-linux.gmk
-+++ jdk/make/common/Defs-linux.gmk
-@@ -318,7 +318,7 @@
- override LIBTHREAD               =
- override MOOT_PRIORITIES         = true
- override NO_INTERRUPTIBLE_IO     = true
--override OPENWIN_HOME            = /usr/X11R6
-+override OPENWIN_HOME            = $(X11_PATH)
- ifeq ($(ARCH), amd64)
- override OPENWIN_LIB             = $(OPENWIN_HOME)/lib64
- else
 --- jdk/make/common/Defs.gmk
 +++ jdk/make/common/Defs.gmk
 @@ -117,6 +117,24 @@
@@ -9181,7 +3644,7 @@
 +    LDFLAGS += -Wl,--export-dynamic
 +  endif
 +  ifeq ($(SYSTEM_ZLIB),true)
-+      OTHER_LDLIBS += -lz
++      OTHER_LDLIBS += %%ZLIB_LDFLAGS%%
 +  endif
 +endif
  ifneq (,$(findstring $(PLATFORM), linux solaris))	# UNIX systems
@@ -9368,17 +3831,6 @@
  # Import JDK images allow for partial builds, components not built are
  #    imported (or copied from) these import areas when needed.
  
---- jdk/make/common/shared/Defs-java.gmk
-+++ jdk/make/common/shared/Defs-java.gmk
-@@ -42,7 +42,7 @@
-   #   Suspect this may not be needed anymore.
-   JAVA_MEM_FLAGS   += -Xms$(MAX_VM_MEMORY)m -XX:-Inline
- else
--  JAVA_MEM_FLAGS   += -Xms$(MIN_VM_MEMORY)m -XX:PermSize=32m -XX:MaxPermSize=160m
-+  JAVA_MEM_FLAGS   += -Xms$(MIN_VM_MEMORY)m
- endif
- 
- # 
 --- jdk/make/common/shared/Defs-utils.gmk
 +++ jdk/make/common/shared/Defs-utils.gmk
 @@ -80,6 +80,13 @@
@@ -9627,7 +4079,7 @@
  endif
 --- jdk/make/java/instrument/Makefile
 +++ jdk/make/java/instrument/Makefile
-@@ -102,6 +102,21 @@
+@@ -102,6 +102,19 @@
    # equivalent of strcasecmp is stricmp on Windows
    CPPFLAGS_COMMON += -Dstrcasecmp=stricmp
  else
@@ -9640,16 +4092,14 @@
 +    LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a
 +    LDFLAGS += -Wl,--no-whole-archive
 +  endif
-+
-+  ICONV_PATH = $(PACKAGE_PATH)
 +# Use CPPFLAGS instead of OTHER_INCLUDES to force this last
-+  CPPFLAGS += -I$(ICONV_PATH)/include
-+  OTHER_LDLIBS += -L$(ICONV_PATH)/lib -liconv
++  CPPFLAGS += %%ICONV_CPPFLAGS%%
++  OTHER_LDLIBS += %%ICONV_LDFLAGS%%
 +else
    LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
    OTHER_LDLIBS += -ljli
    OTHER_LDLIBS += -ldl 
-@@ -114,6 +129,7 @@
+@@ -114,6 +127,7 @@
      LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/jli
    endif
  endif
@@ -9795,7 +4245,7 @@
 +ifneq ($(SYSTEM_ZLIB),true)
 +  OTHER_INCLUDES += -I$(ZIP_SRC)
 +else
-+  LDLIBS += -lz
++  LDLIBS += %%ZLIB_LDFLAGS%%
 +endif
  
  #
@@ -9956,8 +4406,8 @@
 +    OTHER_LDLIBS += -liconv
 +  else
 +    ifneq ($(OS_NAME), netbsd)
-+      CPPFLAGS += -I$(PACKAGE_PATH)/include
-+      OTHER_LDLIBS += -L$(PACKAGE_PATH)/lib -liconv
++      CPPFLAGS += %%ICONV_CPPFLAGS%%
++      OTHER_LDLIBS += %%ICONV_LDFLAGS%%
 +    endif
 +  endif
 +endif
@@ -10064,7 +4514,7 @@
  # Link to JVM library for JVM_Zip* functions
  #
 +ifeq ($(SYSTEM_ZLIB),true)
-+OTHER_LDLIBS = -lz
++OTHER_LDLIBS = %%ZLIB_LDFLAGS%%
 +else
  OTHER_LDLIBS = $(JVMLIB)
 +endif
@@ -10100,7 +4550,7 @@
  	$(PORTFILES_export)
  
 +ifeq ($(PLATFORM), bsd)
-+LDFLAGS  += -L$(PACKAGE_PATH)/lib -lasound
++OTHER_LDLIBS  += -L$(PACKAGE_PATH)/lib -lasound
 +
 +CPPFLAGS += \
 +	-DUSE_DAUDIO=TRUE \
@@ -10108,7 +4558,7 @@
 +	-I$(PACKAGE_PATH)/include \
 +	-I$(SHARE_SRC)/native/com/sun/media/sound
 +else
- LDFLAGS += -lasound
+ OTHER_LDLIBS += -lasound
  
  CPPFLAGS += \
 @@ -73,6 +82,7 @@
@@ -10158,7 +4608,7 @@
  # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv LINUX
  vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/../java2d/opengl
  vpath %.c   $(PLATFORM_SRC)/native/$(PKGDIR)/../java2d/opengl
-@@ -421,6 +429,19 @@
+@@ -422,6 +430,19 @@
  # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLARIS
  endif # PLATFORM
  
@@ -10178,7 +4628,7 @@
  FONTCONFIGS     = $(_FONTCONFIGS:%=$(LIBDIR)/%.src)
  BINARYFONTCONFIGS = $(_FONTCONFIGS:%.properties=$(LIBDIR)/%.bfc)
  
-@@ -514,6 +535,9 @@
+@@ -515,6 +536,9 @@
              -I$(OPENWIN_HOME)/include/X11/extensions \
              -I$(PLATFORM_SRC)/native/$(PKGDIR)/font 
  endif
@@ -10188,7 +4638,7 @@
  CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/debug \
              -I$(SHARE_SRC)/native/$(PKGDIR)/../font \
              -I$(PLATFORM_SRC)/native/$(PKGDIR)/../font \
-@@ -535,7 +559,13 @@
+@@ -536,7 +560,13 @@
              -I$(PLATFORM_SRC)/native/$(PKGDIR) \
  	    $(EVENT_MODEL)
  
@@ -10416,7 +4866,7 @@
 +endif
 --- jdk/make/sun/splashscreen/Makefile
 +++ jdk/make/sun/splashscreen/Makefile
-@@ -61,10 +61,26 @@
+@@ -61,10 +61,25 @@
  
  CFLAGS += -DSPLASHSCREEN
  
@@ -10433,11 +4883,10 @@
 -  OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -lpthread
 +  ifeq ($(PLATFORM), bsd)
 +    CFLAGS += -DPNG_NO_MMX_CODE
-+    ICONV_PATH = $(PACKAGE_PATH)
 +    CPPFLAGS += -I$(OPENWIN_HOME)/include \
-+                -I$(OPENWIN_HOME)/include/X11/extensions \
-+                -I$(ICONV_PATH)/include
-+    OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext -L$(ICONV_PATH)/lib -liconv $(LIBM) -pthread
++                -I$(OPENWIN_HOME)/include/X11/extensions
++    CPPFLAGS += %%ICONV_CPPFLAGS%%
++    OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext %%ICONV_LDFLAGS%% $(LIBM) -pthread
 +  else
 +    CPPFLAGS += -I$(OPENWIN_HOME)/include -I$(OPENWIN_HOME)/include/X11/extensions
 +    OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -lpthread
@@ -10445,7 +4894,7 @@
  else # PLATFORM
    CFLAGS += -DWITH_WIN32
    OTHER_LDLIBS += kernel32.lib user32.lib gdi32.lib 
-@@ -77,14 +93,13 @@
+@@ -77,14 +92,13 @@
  vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/splashscreen
  vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)
  vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/giflib
@@ -10538,7 +4987,7 @@
 -      FT_OPTIONS += -Wl,-rpath -Wl,$(FT_LIB) -lfreetype
 +  else 
 +    ifeq ($(PLATFORM), bsd)
-+      FT_OPTIONS += -lfreetype -lz
++      FT_OPTIONS += -lfreetype %%ZLIB_LDFLAGS%%
 +    else # linux
 +        FT_OPTIONS += -Wl,-rpath -Wl,$(FREETYPE_LIB_PATH) -lfreetype
 +    endif
@@ -10778,29 +5227,15 @@
  void SetJavaLauncherPlatformProps(void);
 --- jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
 +++ jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
-@@ -477,6 +477,10 @@
+@@ -477,6 +477,8 @@
                  String[] dirs = new String[] {
                      userHome + sep + ".themes",
                      System.getProperty("swing.metacitythemedir"),
-+		    "/usr/X11R6/share/themes",
-+		    "/usr/X11R6/share/gnome/themes",
-+		    "/usr/local/share/themes",
-+		    "/usr/local/share/gnome/themes",
++		    "%%LOCALBASE%%/share/themes",
++		    "%%LOCALBASE%%/share/gnome/themes",
                      "/usr/share/themes",
                      "/usr/gnome/share/themes",  // Debian/Redhat/Solaris
                      "/opt/gnome2/share/themes"  // SuSE
---- jdk/src/share/classes/com/sun/jmx/snmp/SnmpPduTrap.java
-+++ jdk/src/share/classes/com/sun/jmx/snmp/SnmpPduTrap.java
-@@ -78,6 +78,9 @@
-      */
-     public long            timeStamp ;
- 
-+    // TODO: IcedTea: I am a stub.
-+    static public int trapAuthenticationFailure = 0;
-+
- 
- 
-     /**
 --- jdk/src/share/classes/java/awt/Font.java
 +++ jdk/src/share/classes/java/awt/Font.java
 @@ -449,18 +449,19 @@
@@ -11035,7 +5470,7 @@
                      registerFontDir(jreFontDirName);
                  }
                  registerFontsInDir(jreFontDirName, true, Font2D.JRE_RANK,
---- jdk/src/share/classes/sun/nio/ch/KqueueSelectorProvider.java	1969-12-31 19:00:00.000000000 -0500
+--- jdk/src/share/classes/sun/nio/ch/KqueueSelectorProvider.java
 +++ jdk/src/share/classes/sun/nio/ch/KqueueSelectorProvider.java
 @@ -0,0 +1,17 @@
 +package sun.nio.ch;
@@ -11057,7 +5492,7 @@
 +}
 --- jdk/src/share/classes/sun/print/PSPrinterJob.java
 +++ jdk/src/share/classes/sun/print/PSPrinterJob.java
-@@ -1531,7 +1531,9 @@
+@@ -1531,9 +1531,33 @@
              pFlags |= NOSHEET;
              ncomps+=1;
          }
@@ -11064,10 +5499,35 @@
 -       if (System.getProperty("os.name").equals("Linux")) {
 +
 +       String osname = System.getProperty("os.name");
-+       if (osname.equals("Linux") || osname.equals("MidnightBSD") || osname.equals("NetBSD") || osname.equals("OpenBSD") || osname.equals("Darwin")) {
++       if (osname.equals("Linux") || osname.endsWith("BSD") || osname.contains("OS X")) {
++            String lprPath = "/usr/bin/lpr";
++            if (osname.endsWith("BSD")) {
++                final PrintService pservice = getPrintService();
++                Boolean isIPPPrinter =
++                    (Boolean)java.security.AccessController.doPrivileged(
++                    new java.security.PrivilegedAction() {
++                        public Object run() {
++                            try {
++                                Class psClass =
++                                    Class.forName("sun.print.IPPPrintService");
++                                if (psClass.isInstance(pservice)) {
++                                    return Boolean.TRUE;
++                                }
++                            } catch (Throwable t) {
++                            }
++                            return Boolean.FALSE;
++                        }
++                    });
++                if (isIPPPrinter) {
++                    lprPath = "%%LOCALBASE%%/bin/lpr";
++                }
++            }
              execCmd = new String[ncomps];
-             execCmd[n++] = "/usr/bin/lpr";
+-            execCmd[n++] = "/usr/bin/lpr";
++            execCmd[n++] = lprPath;
              if ((pFlags & PRINTER) != 0) {
+                 execCmd[n++] = new String("-P" + printer);
+             }
 --- jdk/src/share/classes/sun/security/jgss/GSSManagerImpl.java
 +++ jdk/src/share/classes/sun/security/jgss/GSSManagerImpl.java
 @@ -49,8 +49,12 @@
@@ -11149,7 +5609,7 @@
  
      // An entryName(path)->File map generated during "expand", it helps to
      // decide whether or not an existing entry in a jar file needs to be
-@@ -249,6 +250,16 @@
+@@ -250,6 +251,16 @@
                      }
                  }
              } else if (xflag) {
@@ -11166,10 +5626,10 @@
                  replaceFSC(files);
                  if (fname != null && files != null) {
                      extract(fname, files);
-@@ -921,6 +932,10 @@
-         ZipEntry rc = null;
-         String name = e.getName();
-         File f = new File(e.getName().replace('/', File.separatorChar));
+@@ -975,6 +986,10 @@
+             return rc;    // leading '/' or 'dot-dot' only path
+         }
+         File f = new File(name.replace('/', File.separatorChar));
 +        if (!f.getCanonicalPath().startsWith(cwd)) {
 +            output(formatMsg("out.ignore.entry", name));
 +            return null;
@@ -11177,7 +5637,7 @@
          if (e.isDirectory()) {
              if (f.exists()) {
                  if (!f.isDirectory()) {
-@@ -942,6 +957,10 @@
+@@ -996,6 +1011,10 @@
          } else {
              if (f.getParent() != null) {
                  File d = new File(f.getParent());
@@ -14199,16 +8659,14 @@
  #include <dirent.h>
  #include <dlfcn.h>
  #include <fcntl.h>
-@@ -34,17 +35,33 @@
+@@ -34,17 +35,31 @@
  #include <sys/stat.h>
  #include <unistd.h>
  #include <sys/types.h>
 +#if defined(_ALLBSD_SOURCE)
++#include <sys/sysctl.h>
 +#include <sys/time.h>
 +#endif
-+#ifndef _SC_PHYS_PAGES
-+#include <sys/sysctl.h>
-+#endif
 +
  #include "manifest_info.h"
  #include "version_comp.h"
@@ -14232,9 +8690,9 @@
 +#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
 +#endif
  
- /*
-  * If a processor / os combination has the ability to run binaries of
-@@ -75,14 +92,31 @@
+ #define JRE_ERROR1      "Error: Could not find Java SE Runtime Environment."
+ #define JRE_ERROR11     "Error: Path length exceeds maximum length (PATH_MAX)"
+@@ -79,14 +94,31 @@
  #endif
  
  /* pointer to environment */
@@ -14252,7 +8710,7 @@
 -#ifdef __linux__
 -static const char *system_dir   = "/usr/java";
 +#if defined(__MidnightBSD__)
-+static const char *system_dir	= "/usr/local/openjdk6";
++static const char *system_dir	= "%%JAVA_HOME%%";
 +static const char *user_dir	= "/java";
 +#elif defined(__NetBSD__)
 +static const char *system_dir	= "/usr/local/openjdk6";
@@ -14268,7 +8726,7 @@
  static const char *user_dir     = "/java";
  #else /* Solaris */
  static const char *system_dir   = "/usr/jdk";
-@@ -404,10 +438,10 @@
+@@ -408,10 +440,10 @@
         * If not on Solaris, assume only a single LD_LIBRARY_PATH
         * variable.
         */
@@ -14281,7 +8739,7 @@
        /*
         * On linux, if a binary is running as sgid or suid, glibc sets
         * LD_LIBRARY_PATH to the empty string for security purposes.  (In
-@@ -423,6 +457,22 @@
+@@ -427,6 +459,22 @@
        if((getgid() != getegid()) || (getuid() != geteuid()) ) {
          return;
        }
@@ -14304,16 +8762,16 @@
  #endif
  
        /* runpath contains current effective LD_LIBRARY_PATH setting */
-@@ -431,7 +481,7 @@
-       new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) +
+@@ -436,7 +484,7 @@
                                2*strlen(jrepath) + 2*strlen(arch) +
-                               strlen(jvmpath) + 52);
+                               strlen(jvmpath) + 52;
+       new_runpath = JLI_MemAlloc(new_runpath_size);
 -      newpath = new_runpath + strlen("LD_LIBRARY_PATH=");
 +      newpath = new_runpath + strlen(LD_LIBRARY_PATH "=");
  
  
        /*
-@@ -446,7 +496,7 @@
+@@ -451,7 +499,7 @@
  
          /* jvmpath, ((running != wanted)?((wanted==64)?"/"LIBARCH64NAME:"/.."):""), */
  
@@ -14322,7 +8780,7 @@
                  "%s:"
                  "%s/lib/%s:"
                  "%s/../lib/%s",
-@@ -721,7 +771,7 @@
+@@ -737,7 +785,7 @@
  jboolean
  GetApplicationHome(char *buf, jint bufsize)
  {
@@ -14331,31 +8789,26 @@
      char *execname = GetExecname();
      if (execname) {
          strncpy(buf, execname, bufsize-1);
-@@ -878,9 +928,13 @@
-             }
-         }
-     }
--#elif defined(__linux__)
-+#elif defined(__linux__) || defined(_ALLBSD_SOURCE)
-     {
-+#ifdef __MidnightBSD__
-+        const char* self = "/proc/curproc/file";
-+#else
-         const char* self = "/proc/self/exe";
-+#endif
-         char buf[PATH_MAX+1];
-         int len = readlink(self, buf, PATH_MAX);
-         if (len >= 0) {
-@@ -888,7 +942,7 @@
+@@ -904,7 +952,17 @@
              exec_path = JLI_StringDup(buf);
          }
      }
 -#else /* !__sun && !__linux */
-+#else /* !__sun && !__linux && !_ALLBSD_SOURCE */
++#elif defined(__MidnightBSD__)
++    {
++        char buf[PATH_MAX+1];
++        int name[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 };
++        size_t len = sizeof(buf);
++        if (sysctl(name, 4, buf, &len, NULL, 0) == 0 && len > 0) {
++            buf[len] = '\0';
++            exec_path = JLI_StringDup(buf);
++        }
++    }
++#else /* !__sun && !__linux && !__MidnightBSD__ */
      {
          /* Not implemented */
      }
-@@ -977,6 +1031,7 @@
+@@ -993,6 +1051,7 @@
  /* Compute physical memory by asking the OS */
  uint64_t
  physical_memory(void) {
@@ -14363,7 +8816,7 @@
    const uint64_t pages     = (uint64_t) sysconf(_SC_PHYS_PAGES);
    const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);
    const uint64_t result    = pages * page_size;
-@@ -988,6 +1043,28 @@
+@@ -1004,6 +1063,28 @@
             "  physical memory: " UINT64_FORMAT " (%.3fGB)\n",
             pages, page_size, result, result / (double) GB);
    }
@@ -14392,7 +8845,7 @@
    return result;
  }
  
-@@ -1083,7 +1160,7 @@
+@@ -1099,7 +1180,7 @@
  
  #endif /* __sun && i586 */
  
@@ -14401,7 +8854,7 @@
  
  /*
   * A utility method for asking the CPU about itself.
-@@ -1148,7 +1225,7 @@
+@@ -1164,7 +1245,7 @@
  #endif
  }
  
@@ -14410,7 +8863,7 @@
  
  #ifdef i586
  /*
-@@ -1360,6 +1437,39 @@
+@@ -1376,6 +1457,39 @@
  
  #endif /* __linux__ && i586 */
  
@@ -14450,7 +8903,7 @@
  /* Dispatch to the platform-specific definition of "server-class" */
  jboolean
  ServerClassMachine(void) {
-@@ -1374,6 +1484,8 @@
+@@ -1390,6 +1504,8 @@
    result = solaris_i586_ServerClassMachine();
  #elif defined(__linux__) && defined(i586)
    result = linux_i586_ServerClassMachine();
@@ -14459,7 +8912,7 @@
  #else
    if (_launcher_debug) {
      printf("ServerClassMachine: returns default value of %s\n",
-@@ -1514,7 +1626,7 @@
+@@ -1530,7 +1646,7 @@
      while (dp != NULL) {
          cp = strchr(dp, (int)':');
          if (cp != NULL)
@@ -14468,7 +8921,7 @@
          if ((target = ProcessDir(info, dp)) != NULL)
              break;
          dp = cp;
-@@ -1692,9 +1804,29 @@
+@@ -1708,9 +1824,29 @@
      return(borrowed_unsetenv(name));
  }
  
@@ -14499,7 +8952,7 @@
  
  static void* hSplashLib = NULL;
  
-@@ -1722,13 +1854,15 @@
+@@ -1759,13 +1895,15 @@
      return "%lld";
  }
  
@@ -14517,7 +8970,7 @@
      pthread_t tid;
      pthread_attr_t attr;
      pthread_attr_init(&attr);
-@@ -1741,7 +1875,7 @@
+@@ -1778,7 +1916,7 @@
      if (pthread_create(&tid, &attr, (void *(*)(void*))continuation, (void*)args) == 0) {
        void * tmp;
        pthread_join(tid, &tmp);
@@ -14526,7 +8979,7 @@
      } else {
       /*
        * Continue execution in current thread if for some reason (e.g. out of
-@@ -1759,25 +1893,23 @@
+@@ -1796,25 +1934,23 @@
      if (thr_create(NULL, stack_size, (void *(*)(void *))continuation, args, flags, &tid) == 0) {
        void * tmp;
        thr_join(tid, NULL, &tmp);
@@ -14609,7 +9062,7 @@
          if ("SunOS".equals(osname)) {
              return new sun.nio.ch.DevPollSelectorProvider();
          }
---- jdk/src/solaris/classes/sun/nio/ch/KqueueArrayWrapper.java	1969-12-31 19:00:00.000000000 -0500
+--- jdk/src/solaris/classes/sun/nio/ch/KqueueArrayWrapper.java
 +++ jdk/src/solaris/classes/sun/nio/ch/KqueueArrayWrapper.java
 @@ -0,0 +1,231 @@
 +/*
@@ -14843,7 +9296,7 @@
 +    private static native short getKeventFlags(long address, int index);
 +    private static native int getKeventIdent(long address, int index);
 +}
---- jdk/src/solaris/classes/sun/nio/ch/KqueueSelectorImpl.java	1969-12-31 19:00:00.000000000 -0500
+--- jdk/src/solaris/classes/sun/nio/ch/KqueueSelectorImpl.java
 +++ jdk/src/solaris/classes/sun/nio/ch/KqueueSelectorImpl.java
 @@ -0,0 +1,205 @@
 +/*
@@ -15053,19 +9506,43 @@
 +}
 --- jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
 +++ jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
-@@ -119,7 +119,11 @@
+@@ -119,7 +119,9 @@
      }
  
      static boolean isBSD() {
 -        return osname.equals("Linux");
-+	return (osname.equals("Linux") ||
-+		osname.equals("MidnightBSD") ||
-+		osname.equals("Darwin") ||
-+		osname.equals("NetBSD") ||
-+		osname.equals("OpenBSD"));
++        return (osname.equals("Linux") ||
++                osname.endsWith("BSD") ||
++                osname.contains("OS X"));
      }
  
      static final int UNINITIALIZED = -1;
+@@ -129,13 +131,13 @@
+     static int cmdIndex = UNINITIALIZED;
+ 
+     String[] lpcFirstCom = {
+-        "/usr/sbin/lpc status | grep : | sed -ne '1,1 s/://p'",
++        "/usr/sbin/lpc status all | grep ':$' | sed -ne '1,1 s/://p'",
+         "/usr/sbin/lpc status | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}'"
+     };
+ 
+     String[] lpcAllCom = {
+-        "/usr/sbin/lpc status | grep : | sed -e 's/://'",
+-        "/usr/sbin/lpc -a status | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}' | sort"
++        "/usr/sbin/lpc status all | grep ':$' | sed -e 's/://'",
++        "/usr/sbin/lpc status all | grep -E '^[ 0-9a-zA-Z_-]*@' | awk -F'@' '{print $1}' | sort"
+     };
+ 
+     String[] lpcNameCom = {
+@@ -145,7 +147,7 @@
+ 
+ 
+     static int getBSDCommandIndex() {
+-        String command  = "/usr/sbin/lpc status";
++        String command  = "/usr/sbin/lpc status all";
+         String[] names = execCmd(command);
+ 
+         if ((names == null) || (names.length == 0)) {
 --- jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java
 +++ jdk/src/solaris/classes/sun/tools/attach/BsdVirtualMachine.java
 @@ -38,9 +38,6 @@
@@ -15499,12 +9976,12 @@
 -    return thr_suspend(tid->sys_thread);
 +#ifdef __APPLE__
 +    if (thread_suspend(pthread_mach_thread_np(tid->sys_thread)) == KERN_SUCCESS)
++#else
++    if (pthread_suspend_np(tid->sys_thread) == 0)
++#endif
 +        return SYS_OK;
 +    else
 +        return SYS_ERR;
-+#else
-+    return pthread_suspend_np(tid->sys_thread);
-+#endif
  }
  
 -
@@ -15518,22 +9995,26 @@
 -    return thr_continue(tid->sys_thread);
 +#ifdef __APPLE__
 +    if (thread_resume(pthread_mach_thread_np(tid->sys_thread)) == KERN_SUCCESS)
++#else
++    if (pthread_resume_np(tid->sys_thread) == 0)
++#endif
 +        return SYS_OK;
 +    else
 +        return SYS_ERR;
-+#else
-+    return pthread_resume_np(tid->sys_thread);
-+#endif
  }
  
  /*
-@@ -127,26 +105,74 @@
+@@ -122,9 +100,64 @@
+  */
+ void np_initialize_thread(sys_thread_t *tid)
+ {
+-    return;
+ }
  
- 
- /*
++/*
 + * Internal helper function to get stack information about specified thread.
 + */
-+#ifdef __APPLE__
++#if defined(__APPLE__)
 +static int
 +get_stackinfo(pthread_t tid, void **addr, long *sizep)
 +{
@@ -15540,9 +10021,17 @@
 +    void *stacktop = pthread_get_stackaddr_np(tid);
 +    *sizep = pthread_get_stacksize_np(tid);
 +    *addr = stacktop - *sizep;
-+
-+    return (SYS_OK);
++    return SYS_OK;
 +}
++#elif defined(__MidnightBSD__)
++static int
++get_stackinfo(pthread_t tid, pthread_attr_t *attr, void **addr, long *sizep)
++{
++    if (pthread_attr_get_np(tid, attr) == 0 &&
++        pthread_attr_getstack(attr, addr, sizep) == 0)
++        return SYS_OK;
++    return SYS_ERR;
++}
 +#elif defined(__OpenBSD__)
 +static int
 +get_stackinfo(pthread_t tid, void **addr, long *sizep)
@@ -15553,45 +10042,44 @@
 +        *addr = (void *)(ss.ss_sp) - ss.ss_size;
 +        *sizep = (long)(ss.ss_size);
 +        return SYS_OK;
-+    } else {
-+        return SYS_ERR; /* pthreads_stackseg_np failed. */
 +    }
++    return SYS_ERR;
 +}
 +#else
 +static int
-+get_stackinfo(pthread_t tid, pthread_attr_t attr, void **addr, long *sizep)
++get_stackinfo(pthread_t tid, pthread_attr_t *attr, void **addr, long *sizep)
 +{
-+    size_t s;
-+    void  *p;
-+    int    ret = SYS_ERR;
++    if (pthread_attr_get_np(tid, attr) == 0 &&
++        pthread_attr_getstackaddr(attr, addr) == 0 &&
++        pthread_attr_getstacksize(attr, sizep) == 0)
++        return SYS_OK;
++    return SYS_ERR;
++}
++#endif
 +
-+    if (pthread_attr_get_np(tid, &attr) != 0)
-+        goto err;
-+    if (pthread_attr_getstackaddr(&attr, &p) != 0)
-+        goto err;
-+    if (pthread_attr_getstacksize(&attr, &s) != 0)
-+        goto err;
-+    *addr = p;
-+    *sizep = s;
-+    ret = SYS_OK;
-+err:
-+
-+    return (ret);
++#if !defined(__APPLE__) && !defined(__OpenBSD__)
++static int
++get_stackaddr(pthread_t tid, pthread_attr_t *attr, void **addr)
++{
++    if (pthread_attr_get_np(tid, attr) == 0 &&
++        pthread_attr_getstackaddr(attr, addr) == 0)
++        return SYS_OK;
++    return SYS_ERR;
 +}
 +#endif
-+
-+/*
+ 
+ /*
   * Get the stack start address, and max stack size for the current thread.
-  */
+@@ -132,21 +165,19 @@
  int
  np_stackinfo(void **addr, long *size)
  {
 -    stack_t stkseg;
-+#if defined(__OpenBSD__) || defined(__APPLE__)
-+    return(get_stackinfo(pthread_self(), addr, size));
++#if defined(__APPLE__) || defined(__OpenBSD__)
++    return get_stackinfo(pthread_self(), addr, size);
 +#else
 +    pthread_attr_t attr;
-+    int    ret = SYS_ERR;
++    int ret;
  
 -    if (thr_stksegment(&stkseg) == 0) {
 -        *addr = (void *)(stkseg.ss_sp);
@@ -15606,16 +10094,16 @@
 -    } else {
 -        return SYS_ERR; /* thr_stksegment failed. */
 +    if (pthread_attr_init(&attr) == 0) {
-+        ret = get_stackinfo(pthread_self(), attr, addr, size);
++        ret = get_stackinfo(pthread_self(), &attr, addr, size);
 +        pthread_attr_destroy(&attr);
++        return ret;
      }
-+
-+    return (ret);
++    return SYS_ERR;
 +#endif
  }
  
  /*
-@@ -155,309 +181,194 @@
+@@ -155,309 +186,192 @@
  void
  np_profiler_init(sys_thread_t *tid)
  {
@@ -15779,7 +10267,7 @@
 -    int ret;
 +{ 
 +    sysAssert(SYS_QUEUE_LOCKED(sysThreadSelf()));
- 
++
 +    /* Iterate over all the threads in the task, suspending each one.
 +     * We have to loop until no new threads appear, and all are suspended */
 +    mach_port_t self = pthread_mach_thread_np(pthread_self());
@@ -15826,7 +10314,7 @@
 +            mach_port_deallocate(self, prev_list[k]);
 +
 +        vm_deallocate(self, (vm_address_t)prev_list, sizeof(thread_t) * prev_count);
-+
+ 
 +        /* Set up the 'new' list for the next loop iteration */
 +        prev_list = cur_list;
 +        prev_count = cur_count;
@@ -15930,7 +10418,7 @@
      }
 +
 +    vm_deallocate(self, (vm_address_t) thr_list, sizeof(thread_t) * thr_count);
-+}
+ }
 +#else
 +void
 +np_multi(void)
@@ -15937,7 +10425,7 @@
 +{
 +    sysAssert(SYS_QUEUE_LOCKED(sysThreadSelf()));
 +    pthread_resume_all_np();
- }
++}
 +#endif
  
  /*
@@ -16036,13 +10524,11 @@
  record_thread_regs()
  {
 +    void *addr;
-+    long sz;
-+
      sys_thread_t *tid;
      int i;
-+    int sp;
-+
-+#ifndef __OpenBSD__
++#if defined(__APPLE__) || defined(__OpenBSD__)
++    long sz;
++#else
 +    pthread_attr_t attr;
 +    int attr_inited;
 +    attr_inited = pthread_attr_init(&attr) == 0;
@@ -16050,15 +10536,15 @@
  
      tid = ThreadQueue;
      for (i = 0; i < ActiveThreadCount && tid != 0; i++) {
-@@ -466,7 +377,14 @@
+@@ -466,7 +380,14 @@
  
              if (tid->sys_thread != 0) {
                  /* if thread has already been initialized */
 -                tid->sp = __gettsp(tid->sys_thread);
-+#if defined(__OpenBSD__) || defined(__APPLE__)
++#if defined(__APPLE__) || defined(__OpenBSD__)
 +            if (get_stackinfo(tid->sys_thread, &addr, &sz) == SYS_OK)
 +#else
-+            if (get_stackinfo(tid->sys_thread, attr, &addr, &sz) == SYS_OK)
++            if (get_stackaddr(tid->sys_thread, &attr, &addr) == SYS_OK)
 +#endif
 +                tid->sp = addr;
 +            else
@@ -16066,7 +10552,7 @@
              } else {
                  /*
                   * thread is still in the process of being initalized.
-@@ -475,192 +393,11 @@
+@@ -475,192 +396,11 @@
                   */
                  tid->sp = 0;
              }
@@ -16099,10 +10585,7 @@
 -#ifdef MY_DEBUG
 -                VM_CALL(jio_fprintf)(stderr, "lwpid %d was not found in process\n",
 -                            lwpid_list[i]);
-+#ifndef __OpenBSD__
-+    if (attr_inited)
-+        pthread_attr_destroy(&attr);
- #endif
+-#endif
 -                continue;
 -            }
 -            memset(&lwpstatus, 0, sizeof(lwpstatus));
@@ -16201,7 +10684,10 @@
 -        if (syscall(SYS_ioctl, procfd, PIOCLWPIDS, lwpid_list) == -1) {
 -#ifdef MY_DEBUG
 -            VM_CALL(jio_fprintf)(stderr, "Can't read proc's lwpid list");
--#endif
++#if !defined(__APPLE__) && !defined(__OpenBSD__)
++    if (attr_inited)
++        pthread_attr_destroy(&attr);
+ #endif
 -            return;
 -        }
 -
@@ -16446,7 +10932,7 @@
  static size_t memGrainSize;     /* A page for Linux */
 +#elif defined(_ALLBSD_SOURCE)
 +static size_t memGrainSize;	/* A page for MidnightBSD */
-+#if defined(__MidnightBSD__) && (__MidnightBSD_version >= 3000)
++#if defined(__MidnightBSD__) && (__MidnightBSD_version >= 4015)
 +static inline void *
 +memalign(size_t alignment, size_t size)
 +{
@@ -16793,7 +11279,7 @@
  Java_com_sun_management_UnixOperatingSystem_getTotalPhysicalMemorySize
    (JNIEnv *env, jobject mbean)
  {
-+#ifdef _ALLBSD_SOURCE
++#if defined(_ALLBSD_SOURCE) && !defined(_SC_PHYS_PAGES)
 +    jlong result;
 +    int mib[2];
 +    size_t rlen;
@@ -17622,7 +12108,7 @@
              gethostbyaddr_r(hp->h_addr, hp->h_length, AF_INET,
                              &res2, buf2, sizeof(buf2), &hp, &h_error);
  #else
-@@ -178,7 +454,7 @@
+@@ -172,7 +448,7 @@
      }
  
      /* Try once, with our static buffer. */
@@ -17631,7 +12117,7 @@
      gethostbyname_r(hostname, &res, buf, sizeof(buf), &hp, &h_error);
  #else
      hp = gethostbyname_r(hostname, &res, buf, sizeof(buf), &h_error);
-@@ -191,7 +467,7 @@
+@@ -185,7 +461,7 @@
       */
      if (hp == NULL && errno == ERANGE) {
          if ((tmp = (char*)malloc(BIG_HENT_BUF_SIZE))) {
@@ -17640,7 +12126,7 @@
              gethostbyname_r(hostname, &res, tmp, BIG_HENT_BUF_SIZE,
                              &hp, &h_error);
  #else
-@@ -281,7 +557,7 @@
+@@ -274,7 +550,7 @@
      addr |= ((caddr[2] <<8) & 0xff00);
      addr |= (caddr[3] & 0xff);
      addr = htonl(addr);
@@ -17649,7 +12135,7 @@
      gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET, &hent,
                      buf, sizeof(buf), &hp, &h_error);
  #else
-@@ -295,7 +571,7 @@
+@@ -288,7 +564,7 @@
       */
      if (hp == NULL && errno == ERANGE) {
          if ((tmp = (char*)malloc(BIG_HENT_BUF_SIZE))) {
@@ -17658,7 +12144,7 @@
              gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET,
                              &hent, tmp, BIG_HENT_BUF_SIZE, &hp, &h_error);
  #else
-@@ -317,6 +593,8 @@
+@@ -310,6 +586,8 @@
      return ret;
  }
  
@@ -17720,10 +12206,10 @@
  }
 --- jdk/src/solaris/native/java/net/NetworkInterface.c
 +++ jdk/src/solaris/native/java/net/NetworkInterface.c
-@@ -23,13 +23,13 @@
-  * questions.
+@@ -24,13 +24,13 @@
   */
  
+ 
 +#include <sys/types.h>
 +#include <sys/socket.h>
  #include <errno.h>
@@ -17736,11 +12222,11 @@
  #include <arpa/inet.h>
  #include <net/if.h>
  #include <net/if_arp.h>
-@@ -47,6 +47,19 @@
- #else
+@@ -41,6 +41,19 @@
+ #include <stropts.h>
  #include <sys/sockio.h>
  #endif
-+#if defined(_ALLBSD_SOURCE)
++#ifdef _ALLBSD_SOURCE
 +#include <sys/param.h>
 +#include <sys/ioctl.h>
 +#if defined(__MidnightBSD__) || defined(__APPLE__)
@@ -17755,247 +12241,267 @@
 +#endif
  
  #ifdef __linux__
- #define ifr_index ifr_ifindex
-@@ -584,6 +597,7 @@
- }
+ #include <sys/ioctl.h>
+@@ -133,8 +146,9 @@
  
  
-+#if !defined(_ALLBSD_SOURCE)
- /*
-  * Enumerates and returns all IPv4 interfaces
-  */
-@@ -694,6 +708,176 @@
-     return ifs;
+ 
+-#ifdef __solaris__
++#if defined(_ALLBSD_SOURCE) || defined(__solaris__)
+ static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family);
++#ifdef __solaris__
+ static int    getMacFromDevice(JNIEnv *env, const char* ifname, unsigned char* retbuf);
+ 
+ #ifndef SIOCGLIFHWADDR
+@@ -142,6 +156,7 @@
+ #endif
+ 
+ #endif
++#endif
+ 
+ /******************* Java entry points *****************************/
+ 
+@@ -995,6 +1010,240 @@
  }
  
-+#else /* _ALLBSD_SOURCE */
-+ 
-+/*
-+ * Enumerates and returns all IPv4 interfaces
-+ *
-+ * WARNING! Make sure that it's correctly synchronized on future JDK
-+ * versions imports!
+ 
++/** BSD **/
++#ifdef _ALLBSD_SOURCE
++/* Open socket for further ioct calls, try v4 socket first and
++ * if it falls return v6 socket
 + */
-+static netif *enumIPv4Interfaces(JNIEnv *env, netif *ifs)
-+{
++
++#ifdef AF_INET6
++// unused arg ifname and struct if2
++static int openSocketWithFallback(JNIEnv *env, const char *ifname){
 +    int sock;
-+    struct ifaddrs *ifa, *origifa;
++    struct ifreq if2;
 +
-+    sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
-+    if (sock < 0) {
-+	/*
-+	 * If EPROTONOSUPPORT is returned it means we don't have
-+	 * IPv4 support so don't throw an exception.
-+	 */
-+	if (errno != EPROTONOSUPPORT) {
-+	    NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
-+                             "Socket creation failed");
-+	}
-+	return ifs;
++    if ((sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
++        if (errno == EPROTONOSUPPORT){
++            if ( (sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0)) < 0 ){
++                NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV6 Socket creation failed");
++                return -1;
++            }
++        }
++        else{ // errno is not NOSUPPORT
++            NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException", "IPV4 Socket creation failed");
++            return -1;
++        }
 +    }
 +
-+    if (getifaddrs(&origifa) != 0) {
-+        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
-+                         "getifaddrs() function failed");
-+	close(sock);
-+	return ifs;
-+    }
++    return sock;
++}
 +
-+    for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) {
++#else
++static int openSocketWithFallback(JNIEnv *env, const char *ifname){
++    return openSocket(env, AF_INET);
++}
++#endif
 +
-+	/*
-+	 * Skip non-AF_INET entries.
-+	 */
-+	if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET)
-+	    continue;
++static netif *enumIPv4Interfaces(JNIEnv *env, int sock, netif *ifs) {
++    return enumIPvXInterfaces(env, sock, ifs, AF_INET);
++}
 +
-+	/*
-+	 * Add to the list.
-+	 *
-+	 * BSDNOTE: in order to optimize code, interface index detection
-+	 * logic was added directly to addif().
-+	 */
-+	ifs = addif(env, ifs, ifa->ifa_name, (-1), AF_INET,
-+		    ifa->ifa_addr, sizeof(struct sockaddr_in), 0);
++#ifdef AF_INET6
++static netif *enumIPv6Interfaces(JNIEnv *env, int sock, netif *ifs) {
++    return enumIPvXInterfaces(env, sock, ifs, AF_INET6);
++}
++#endif
 +
-+	/*
-+	 * If an exception occurred then free the list.
-+	 */
-+	if ((*env)->ExceptionOccurred(env)) {
-+	    close(sock);
-+	    freeifaddrs(origifa);
-+	    freeif(ifs);
-+	    return NULL;
-+	}
++/*
++   Enumerates and returns all interfaces on BSD
++   use the same code for IPv4 and IPv6
++ */
++static netif *enumIPvXInterfaces(JNIEnv *env, int sock, netif *ifs, int family) {
++    struct ifaddrs *ifa0, *ifa;
++  
++    /*
++     * Grab the interface list
++     */
++    if (getifaddrs(&ifa0) < 0) {
++        return NULL;
 +    }
 +
 +    /*
-+     * Free socket and buffer
++     * Iterate through each interface
 +     */
-+    close(sock);
-+    freeifaddrs(origifa);
++    for (ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next) {
++        if (ifa->ifa_addr->sa_family == family) {
++            /*
++             * Add to the list
++             */
++            ifs = addif(env, sock, ifa->ifa_name, ifs, ifa->ifa_addr, family, 0);
++
++            /*
++             * If an exception occurred then free the list
++             */
++            if ((*env)->ExceptionOccurred(env)) {
++                freeif(ifs);
++                ifs = NULL;
++                break;
++            }
++        }
++    }
++    freeifaddrs(ifa0);
++
 +    return ifs;
 +}
 +
-+#if defined(AF_INET6)
-+/*
-+ * Determines the prefix on BSD for IPv6 interfaces.
-+ */
-+static
-+int prefix(void *val, int size) {
-+    u_char *name = (u_char *)val;
-+    int byte, bit, plen = 0;
++static int getIndex(int sock, const char *name){
++     /*
++      * Try to get the interface index
++      */
++    struct ifreq if2;
++    strcpy(if2.ifr_name, name);
 +
-+    for (byte = 0; byte < size; byte++, plen += 8)
-+        if (name[byte] != 0xff)
-+            break;
-+    if (byte == size)
-+        return (plen);
-+    for (bit = 7; bit != 0; bit--, plen++)
-+        if (!(name[byte] & (1 << bit)))
-+            break;
-+    for (; bit != 0; bit--)
-+        if (name[byte] & (1 << bit))
-+            return (0);
-+    byte++;
-+    for (; byte < size; byte++)
-+        if (name[byte])
-+            return (0);
-+    return (plen);
++    if (ioctl(sock, SIOCGIFINDEX, (char *)&if2) < 0) {
++        return -1;
++    }
++
++    return if2.ifr_index;
 +}
 +
-+/*
-+ * Enumerates and returns all IPv6 interfaces on MidnightBSD
-+ *
-+ * BSDNOTE: it's done in same as IPv4 enumeration and should be carefully
-+ *          reviewed with each JDK update (according to Solaris/Linux version)
++/**
++ * Returns the IPv4 broadcast address of a named interface, if it exists.
++ * Returns 0 if it doesn't have one.
 + */
-+static netif *enumIPv6Interfaces(JNIEnv *env, netif *ifs) {
++static struct sockaddr *getBroadcast(JNIEnv *env, int sock, const char *ifname, struct sockaddr *brdcast_store) {
++  struct sockaddr *ret = NULL;
++  struct ifreq if2;
 +
-+    int sock;
-+    struct ifaddrs *ifa, *origifa;
-+    struct sockaddr_in6 *sin6;
-+    struct in6_ifreq ifr6;
++  memset((char *) &if2, 0, sizeof(if2));
++  strcpy(if2.ifr_name, ifname);
 +
-+    // Open IPv6 UDP socket.
-+    sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
-+    if (sock < 0) {
-+        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
-+                     "Failed to create IPv6 socket");
-+        return ifs;
-+    }
++  /* Let's make sure the interface does have a broadcast address */
++  if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2)  < 0) {
++      NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL  SIOCGIFFLAGS failed");
++      return ret;
++  }
 +
-+    if (getifaddrs(&origifa) != 0) {
-+        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
-+                         "getifaddrs() function failed");
-+	close(sock);
-+	return ifs;
-+    }
++  if (if2.ifr_flags & IFF_BROADCAST) {
++      /* It does, let's retrieve it*/
++      if (ioctl(sock, SIOCGIFBRDADDR, (char *)&if2) < 0) {
++          NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFBRDADDR failed");
++          return ret;
++      }
 +
-+    for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) {
++      ret = brdcast_store;
++      memcpy(ret, &if2.ifr_broadaddr, sizeof(struct sockaddr));
++  }
 +
-+	/*
-+	 * Skip non-AF_INET6 entries.
-+	 */
-+	if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET6)
-+	    continue;
++  return ret;
++}
 +
-+	memset(&ifr6, 0, sizeof(ifr6));
-+	strlcpy(ifr6.ifr_name, ifa->ifa_name, sizeof(ifr6.ifr_name));
-+	memcpy(&ifr6.ifr_addr, ifa->ifa_addr, MIN(sizeof(ifr6.ifr_addr), ifa->ifa_addr->sa_len));
++/**
++ * Returns the IPv4 subnet prefix length (aka subnet mask) for the named
++ * interface, if it has one, otherwise return -1.
++ */
++static short getSubnet(JNIEnv *env, int sock, const char *ifname) {
++    unsigned int mask;
++    short ret;
++    struct ifreq if2;
 +
-+	if (ioctl(sock, SIOCGIFNETMASK_IN6, (caddr_t)&ifr6) < 0) {
-+	    NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
-+                             "ioctl SIOCGIFNETMASK_IN6 failed");
-+	    close(sock);
-+	    freeifaddrs(origifa);
-+	    freeif(ifs);
-+	    return NULL;
-+	}
++    memset((char *) &if2, 0, sizeof(if2));
++    strcpy(if2.ifr_name, ifname);
 +
-+	/* Add to the list.  */
-+	sin6 = (struct sockaddr_in6 *)&ifr6.ifr_addr;
-+	ifs = addif(env, ifs, ifa->ifa_name, (-1), AF_INET6,
-+	            ifa->ifa_addr, sizeof(struct sockaddr_in6),
-+		    prefix(&sin6->sin6_addr, sizeof(struct in6_addr)));
++    if (ioctl(sock, SIOCGIFNETMASK, (char *)&if2) < 0) {
++        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFNETMASK failed");
++        return -1;
++    }
 +
-+	/* If an exception occurred then free the list.  */
-+	if ((*env)->ExceptionOccurred(env)) {
-+	    close(sock);
-+	    freeifaddrs(origifa);
-+	    freeif(ifs);
-+	    return NULL;
-+	}
++    mask = ntohl(((struct sockaddr_in*)&(if2.ifr_addr))->sin_addr.s_addr);
++    ret = 0;
++    while (mask) {
++       mask <<= 1;
++       ret++;
 +    }
 +
++    return ret;
++}
++
++/**
++ * Get the Hardware address (usually MAC address) for the named interface.
++ * return puts the data in buf, and returns the length, in byte, of the
++ * MAC address. Returns -1 if there is no hardware address on that interface.
++ */
++static int getMacAddress(JNIEnv *env, int sock, const char* ifname, const struct in_addr* addr, unsigned char *buf) {
++    struct ifaddrs *ifa0, *ifa;
++    struct sockaddr *saddr;
++    struct sockaddr_dl *sadl;
++    int ret = -1;
++  
 +    /*
-+     * Free socket and ifaddrs buffer
++     * Grab the interface list
 +     */
-+    close(sock);
-+    freeifaddrs(origifa);
-+    return ifs;
-+}
-+#endif /* AF_INET6 */
++    if (getifaddrs(&ifa0) < 0) {
++        return ret;
++    }
 +
-+#endif /* !_ALLBSD_SOURCE */
- 
- #if defined(__solaris__) && defined(AF_INET6)
- /*
-@@ -1014,7 +1198,13 @@
-             JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
-             return ifs;
-         }
-+#if defined(_ALLBSD_SOURCE)
-+	currif->index = if_nametoindex(name);
-+	if (currif->index == 0)
-+	    currif->index = -1;
-+#else
-         currif->index = index;
-+#endif
-         currif->addr = NULL;
-         currif->childs = NULL;
-         currif->virtual = isVirtual;
-@@ -1302,6 +1492,31 @@
-    * All bytes to 0 means no hardware address.
-    */
-   return -1;
-+#elif defined(_ALLBSD_SOURCE)
-+  struct ifaddrs *ifa0, *ifa;
-+  struct sockaddr *saddr;
-+  int i;
++    /*
++     * Iterate through each interface
++     */
++    for (ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next) {
++        saddr = ifa->ifa_addr;
 +
-+  /* Grab the interface list */
-+  if (!getifaddrs(&ifa0)) {
-+    /* Cycle through the interfaces */
-+    for (i = 0, ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next, i++) {
-+      saddr = ifa->ifa_addr;
-+      /* Link layer contains the MAC address */
-+      if (saddr->sa_family == AF_LINK && !strcmp(ifname, ifa->ifa_name)) {
-+        struct sockaddr_dl *sadl = (struct sockaddr_dl *) saddr;
-+        /* Check the address is the correct length */
-+        if (sadl->sdl_alen == ETHER_ADDR_LEN) {
-+           memcpy(buf, (sadl->sdl_data + sadl->sdl_nlen), ETHER_ADDR_LEN);
-+           freeifaddrs(ifa0);
-+           return ETHER_ADDR_LEN;
++        /* Link layer contains the MAC address */
++        if (saddr->sa_family == AF_LINK && strcmp(ifname, ifa->ifa_name) == 0) {
++            sadl = (struct sockaddr_dl *)saddr;
++
++            /* Check the address is the correct length */
++            if (sadl->sdl_alen == ETHER_ADDR_LEN) {
++                memcpy(buf, (sadl->sdl_data + sadl->sdl_nlen), ETHER_ADDR_LEN);
++                ret = ETHER_ADDR_LEN;
++                break;
++            }
 +        }
-+      }
 +    }
 +    freeifaddrs(ifa0);
-+  }
 +
-+  return -1;
- #else
-   struct arpreq arpreq;
-   struct sockaddr_in* sin;
-@@ -1467,7 +1682,7 @@
-                                  "Socket creation failed");
-   } else {
- 
--#ifdef __linux__
-+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
-     memset((char *) &if2, 0, sizeof(if2));
-     strcpy(if2.ifr_name, name_utf);
- 
++    return ret;
++}
++
++static int getMTU(JNIEnv *env, int sock,  const char *ifname) {
++    struct ifreq if2;
++    memset((char *) &if2, 0, sizeof(if2));
++
++    if (ifname != NULL) {
++        strcpy(if2.ifr_name, ifname);
++    } else {
++        JNU_ThrowNullPointerException(env, "network interface name is NULL");
++        return -1;
++    }
++
++    if (ioctl(sock, SIOCGIFMTU, (char *)&if2) < 0) {
++        NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "IOCTL SIOCGIFMTU failed");
++        return -1;
++    }
++
++    return  if2.ifr_mtu;
++}
++
++static int getFlags(int sock, const char *ifname) {
++    struct ifreq if2;
++    int flags;
++
++    memset((char *) &if2, 0, sizeof(if2));
++    strcpy(if2.ifr_name, ifname);
++
++    if (ioctl(sock, SIOCGIFFLAGS, (char *)&if2) < 0) {
++        return -1;
++    }
++
++    flags = if2.ifr_flags & 0xffff;
++    flags |= if2.ifr_flagshigh << 16;
++
++    return flags;
++}
++
++#endif
++
+ /** Linux **/
+ #ifdef __linux__
+ /* Open socket for further ioct calls, try v4 socket first and
 --- jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c
 +++ jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c
 @@ -23,12 +23,12 @@
@@ -18013,7 +12519,7 @@
  
  #ifdef __solaris__
  #include <fcntl.h>
-@@ -335,7 +335,7 @@
+@@ -331,7 +331,7 @@
      /* The fdObj'fd */
      jint fd;
  
@@ -18022,7 +12528,7 @@
      SOCKADDR addr;
      int len;
  #endif
-@@ -345,26 +345,39 @@
+@@ -341,26 +341,39 @@
      }
      fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
  
@@ -18062,7 +12568,7 @@
          // After disconnecting a UDP socket, Linux kernel will set
          // local port to zero if the port number comes from implicit
          // bind. Successive send/recv on the same socket will fail.
-@@ -387,6 +400,7 @@
+@@ -383,6 +396,7 @@
              NET_Bind(fd, (struct sockaddr *)&addr, len);
          }
      }
@@ -18070,69 +12576,7 @@
  #else
      JVM_Connect(fd, 0, 0);
  #endif
-@@ -1057,31 +1071,38 @@
- Java_java_net_PlainDatagramSocketImpl_datagramSocketCreate(JNIEnv *env,
-                                                            jobject this) {
-     jobject fdObj = (*env)->GetObjectField(env, this, pdsi_fdID);
--    int fd;
--
--    int arg = -1;
--    int t = 1;
-+    int fd, t = 1;
-+#ifdef AF_INET6
-+    int domain = ipv6_available() ? AF_INET6 : AF_INET;
-+#else
-+    int domain = AF_INET;
-+#endif
- 
-     if (IS_NULL(fdObj)) {
-         JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
-                         "Socket closed");
-         return;
--    } else {
--#ifdef AF_INET6
--        if (ipv6_available()) {
--            fd =  JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
--        } else
--#endif /* AF_INET6 */
--            {
--                fd =  JVM_Socket(AF_INET, SOCK_DGRAM, 0);
--            }
-     }
--    if (fd == JVM_IO_ERR) {
-+
-+    if ((fd = JVM_Socket(domain, SOCK_DGRAM, 0)) == JVM_IO_ERR) {
-         NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
-                        "Error creating socket");
-         return;
-     }
- 
-+#ifdef AF_INET6
-+    /* Disable IPV6_V6ONLY to ensure dual-socket support */
-+    if (domain == AF_INET6) {
-+        int arg = 0;
-+        if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
-+                       sizeof(int)) < 0) {
-+            NET_ThrowNew(env, errno, "cannot set IPPROTO_IPV6");
-+            close(fd);
-+            return;
-+        }
-+    }
-+#endif /* AF_INET6 */
-+
-      setsockopt(fd, SOL_SOCKET, SO_BROADCAST, (char*) &t, sizeof(int));
- 
- #ifdef __linux__
-@@ -1094,7 +1115,7 @@
-      * On Linux for IPv6 sockets we must set the hop limit
-      * to 1 to be compatible with default ttl of 1 for IPv4 sockets.
-      */
--    if (ipv6_available()) {
-+    if (domain == AF_INET6) {
-         int ttl = 1;
-         setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (char *)&ttl,
-                    sizeof(ttl));
-@@ -1317,7 +1338,7 @@
+@@ -1306,7 +1320,7 @@
          /*
           * value is an InetAddress.
           */
@@ -18141,7 +12585,7 @@
          if (ipv6_available()) {
              mcast_set_if_by_addr_v6(env, this, fd, value);
          } else {
-@@ -1336,7 +1357,7 @@
+@@ -1325,7 +1339,7 @@
          /*
           * value is a NetworkInterface.
           */
@@ -18150,7 +12594,7 @@
          if (ipv6_available()) {
              mcast_set_if_by_if_v6(env, this, fd, value);
          } else {
-@@ -1413,7 +1434,7 @@
+@@ -1402,7 +1416,7 @@
   */
  static void setMulticastLoopbackMode(JNIEnv *env, jobject this, int fd,
                                    jint opt, jobject value) {
@@ -18159,7 +12603,7 @@
      if (ipv6_available()) {
          mcast_set_loop_v6(env, this, fd, value);
      } else {
-@@ -1981,7 +2002,7 @@
+@@ -1982,7 +1996,7 @@
          fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
      }
      /* setsockopt to be correct ttl */
@@ -18168,7 +12612,7 @@
      if (ipv6_available()) {
          setHopLimit(env, fd, ttl);
      } else {
-@@ -2374,18 +2395,30 @@
+@@ -2374,18 +2388,30 @@
              mname6.ipv6mr_interface = idx;
          }
  
@@ -18204,38 +12648,7 @@
          }
 --- jdk/src/solaris/native/java/net/PlainSocketImpl.c
 +++ jdk/src/solaris/native/java/net/PlainSocketImpl.c
-@@ -253,7 +253,12 @@
-                                            jboolean stream) {
-     jobject fdObj, ssObj;
-     int fd;
--    int arg = -1;
-+    int type = (stream ? SOCK_STREAM : SOCK_DGRAM);
-+#ifdef AF_INET6
-+    int domain = ipv6_available() ? AF_INET6 : AF_INET;
-+#else
-+    int domain = AF_INET;
-+#endif
- 
-     if (socketExceptionCls == NULL) {
-         jclass c = (*env)->FindClass(env, "java/net/SocketException");
-@@ -267,25 +272,29 @@
-         (*env)->ThrowNew(env, socketExceptionCls, "null fd object");
-         return;
-     }
--#ifdef AF_INET6
--    if (ipv6_available()) {
--        fd = JVM_Socket(AF_INET6, (stream ? SOCK_STREAM: SOCK_DGRAM), 0);
--    } else
--#endif /* AF_INET6 */
--        {
--            fd = JVM_Socket(AF_INET, (stream ? SOCK_STREAM: SOCK_DGRAM), 0);
--        }
--    if (fd == JVM_IO_ERR) {
-+
-+    if ((fd = JVM_Socket(domain, type, 0)) == JVM_IO_ERR) {
-         /* note: if you run out of fds, you may not be able to load
-          * the exception class, and get a NoClassDefFoundError
-          * instead.
+@@ -279,10 +279,21 @@
           */
          NET_ThrowNew(env, errno, "can't create socket");
          return;
@@ -18245,7 +12658,7 @@
  
 +#ifdef AF_INET6
 +    /* Disable IPV6_V6ONLY to ensure dual-socket support */
-+    if (domain == AF_INET6) {
++    if (ipv6_available()) {
 +        int arg = 0;
 +        if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
 +                       sizeof(int)) < 0) {
@@ -18259,7 +12672,7 @@
      /*
       * If this is a server socket then enable SO_REUSEADDR
       * automatically and set to non blocking.
-@@ -294,9 +303,15 @@
+@@ -291,9 +302,15 @@
      if (ssObj != NULL) {
          int arg = 1;
          SET_NONBLOCKING(fd);
@@ -18277,7 +12690,7 @@
  }
  
  /*
-@@ -528,9 +543,11 @@
+@@ -525,9 +542,11 @@
          if (connect_rv == JVM_IO_INTR) {
              JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
                              "operation interrupted");
@@ -18300,6 +12713,28 @@
  
  /*
   * The fd table and the number of file descriptors
+@@ -281,9 +281,7 @@
+ 
+ int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
+        struct sockaddr *from, int *fromlen) {
+-    socklen_t socklen = *fromlen;
+-    BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, &socklen) );
+-    *fromlen = socklen;
++    BLOCKING_IO_RETURN_INT( s, recvfrom(s, buf, len, flags, from, (socklen_t *)fromlen) );
+ }
+ 
+ int NET_Send(int s, void *msg, int len, unsigned int flags) {
+@@ -300,9 +298,7 @@
+ }
+ 
+ int NET_Accept(int s, struct sockaddr *addr, int *addrlen) {
+-    socklen_t socklen = *addrlen;
+-    BLOCKING_IO_RETURN_INT( s, accept(s, addr, &socklen) );
+-    *addrlen = socklen;
++    BLOCKING_IO_RETURN_INT( s, accept(s, addr, (socklen_t *)addrlen) );
+ }
+ 
+ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
 --- jdk/src/solaris/native/java/net/net_util_md.c
 +++ jdk/src/solaris/native/java/net/net_util_md.c
 @@ -34,6 +34,15 @@
@@ -18333,15 +12768,6 @@
  jint  IPv6_supported()
  {
  #ifndef AF_INET6
-@@ -230,7 +247,7 @@
-     int fd;
-     void *ipv6_fn;
-     SOCKADDR sa;
--    int sa_len = sizeof(sa);
-+    socklen_t sa_len = sizeof(sa);
- 
-     fd = JVM_Socket(AF_INET6, SOCK_STREAM, 0) ;
-     if (fd < 0) {
 @@ -356,6 +373,7 @@
      close(fd);
      return JNI_TRUE;
@@ -18350,7 +12776,7 @@
  
  void
  NET_AllocSockaddr(struct sockaddr **him, int *len) {
-@@ -710,6 +728,10 @@
+@@ -707,6 +725,10 @@
          him6->sin6_family = AF_INET6;
          *len = sizeof(struct sockaddr_in6) ;
  
@@ -18361,24 +12787,7 @@
          /*
           * On Linux if we are connecting to a link-local address
           * we need to specify the interface in the scope_id (2.4 kernel only)
-@@ -1107,7 +1129,16 @@
-     }
- #endif
- 
-+#ifdef __solaris__
-     rv = getsockopt(fd, level, opt, result, len);
-+#else
-+    {
-+        socklen_t socklen = *len;
-+        rv = getsockopt(fd, level, opt, result, &socklen);
-+        *len = socklen;
-+    }
-+#endif
-+
-     if (rv < 0) {
-         return rv;
-     }
-@@ -1154,6 +1185,24 @@
+@@ -1160,6 +1182,24 @@
  #define IPTOS_PREC_MASK 0xe0
  #endif
  
@@ -18403,7 +12812,7 @@
      /*
       * IPPROTO/IP_TOS :-
       * 1. IPv6 on Solaris: no-op and will be set in flowinfo
-@@ -1186,6 +1235,10 @@
+@@ -1192,6 +1232,10 @@
          *iptos &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK);
      }
  
@@ -18414,7 +12823,7 @@
      /*
       * SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On Solaris need to
       * ensure that value is <= max_buf as otherwise we get
-@@ -1233,6 +1286,84 @@
+@@ -1239,6 +1283,84 @@
      }
  #endif
  
@@ -18586,7 +12995,7 @@
  #include <string.h>
  #include <dirent.h>
  #include <sys/stat.h>
-@@ -49,7 +49,7 @@
+@@ -49,9 +49,13 @@
  #define fileclose       fclose
  #endif
  
@@ -18593,27 +13002,33 @@
 -#ifdef __linux__
 +#if defined(__linux__)  || defined(_ALLBSD_SOURCE)
  
++#ifdef __MidnightBSD__
++static const char *ETC_TIMEZONE_FILE = "/var/db/zoneinfo";
++#else
  static const char *ETC_TIMEZONE_FILE = "/etc/timezone";
++#endif
  static const char *ZONEINFO_DIR = "/usr/share/zoneinfo";
-@@ -199,7 +199,9 @@
+ static const char *DEFAULT_ZONEINFO_FILE = "/etc/localtime";
+ 
+@@ -199,7 +203,9 @@
      int fd;
      char *buf;
      size_t size;
 +    char zoneinfo_file[PATH_MAX+1];
  
-+#ifdef __linux__
++#if defined(__linux__) || defined(__MidnightBSD__)
      /*
       * Try reading the /etc/timezone file for Debian distros. There's
       * no spec of the file format available. This parsing assumes that
-@@ -223,6 +225,7 @@
+@@ -223,6 +229,7 @@
              return tz;
          }
      }
-+#endif /* __linux__ */
++#endif /* __linux__ || __MidnightBSD__ */
  
      /*
       * Next, try /etc/localtime to find the zone ID.
-@@ -231,6 +234,9 @@
+@@ -231,6 +238,9 @@
          return NULL;
      }
  
@@ -18623,7 +13038,7 @@
      /*
       * If it's a symlink, get the link name and its zone ID part. (The
       * older versions of timeconfig created a symlink as described in
-@@ -239,21 +245,25 @@
+@@ -239,21 +249,25 @@
       * from /etc/localtime.)
       */
      if (S_ISLNK(statbuf.st_mode)) {
@@ -18654,7 +13069,7 @@
  
      /*
       * If it's a regular file, we need to find out the same zoneinfo file
-@@ -264,7 +274,7 @@
+@@ -264,7 +278,7 @@
      if (buf == NULL) {
          return NULL;
      }
@@ -18663,7 +13078,7 @@
          free((void *) buf);
          return NULL;
      }
-@@ -493,7 +503,7 @@
+@@ -493,7 +507,7 @@
  
      tz = getenv("TZ");
  
@@ -18672,7 +13087,7 @@
      if (tz == NULL) {
  #else
  #ifdef __solaris__
-@@ -532,19 +542,32 @@
+@@ -532,19 +546,32 @@
  {
      time_t offset;
      char sign, buf[16];
@@ -18879,7 +13294,7 @@
  }
  #endif /* HEADLESS */
  
-@@ -1568,7 +1573,7 @@
+@@ -1571,7 +1576,7 @@
  {
      jobject point = NULL;
  #ifndef HEADLESS    /* return NULL in HEADLESS, Linux */
@@ -18888,7 +13303,7 @@
      int x,y;
  
      AWT_LOCK();
-@@ -1581,7 +1586,7 @@
+@@ -1584,7 +1589,7 @@
          DTRACE_PRINTLN("unable to call XineramaSolarisCenterFunc: symbol is null");
      }
      AWT_FLUSH_UNLOCK();
@@ -18897,7 +13312,7 @@
  #endif /* HEADLESS */
      return point;
  }
-@@ -1646,7 +1651,11 @@
+@@ -1649,7 +1654,11 @@
  {
      int rr_maj_ver = 0, rr_min_ver = 0;
  
@@ -18912,7 +13327,7 @@
                        "X11GD_InitXrandrFuncs: Could not open libXrandr.so.2");
 --- jdk/src/solaris/native/sun/awt/awt_InputMethod.c
 +++ jdk/src/solaris/native/sun/awt/awt_InputMethod.c
-@@ -69,7 +69,7 @@
+@@ -67,7 +67,7 @@
                                  XIMPreeditDrawCallbackStruct *);
  static void PreeditCaretCallback(XIC, XPointer,
                                   XIMPreeditCaretCallbackStruct *);
@@ -18921,7 +13336,7 @@
  static void StatusStartCallback(XIC, XPointer, XPointer);
  static void StatusDoneCallback(XIC, XPointer, XPointer);
  static void StatusDrawCallback(XIC, XPointer,
-@@ -83,7 +83,7 @@
+@@ -81,7 +81,7 @@
  #define PreeditDoneIndex        1
  #define PreeditDrawIndex        2
  #define PreeditCaretIndex       3
@@ -18930,7 +13345,7 @@
  #define StatusStartIndex        4
  #define StatusDoneIndex         5
  #define StatusDrawIndex         6
-@@ -101,14 +101,14 @@
+@@ -99,14 +99,14 @@
      (XIMProc)PreeditDoneCallback,
      (XIMProc)PreeditDrawCallback,
      (XIMProc)PreeditCaretCallback,
@@ -18947,7 +13362,7 @@
  #define MAX_STATUS_LEN  100
  typedef struct {
      Window   w;                /*status window id        */
-@@ -148,7 +148,7 @@
+@@ -146,7 +146,7 @@
  #endif /* XAWT */
      jobject     x11inputmethod; /* global ref to X11InputMethod instance */
                                  /* associated with the XIC */
@@ -18956,7 +13371,7 @@
      StatusWindow *statusWindow; /* our own status window  */
  #else
  #ifndef XAWT
-@@ -427,7 +427,7 @@
+@@ -425,7 +425,7 @@
  static void
  freeX11InputMethodData(JNIEnv *env, X11InputMethodData *pX11IMData)
  {
@@ -18965,7 +13380,7 @@
      if (pX11IMData->statusWindow != NULL){
          StatusWindow *sw = pX11IMData->statusWindow;
          XFreeGC(awt_display, sw->lightGC);
-@@ -533,7 +533,7 @@
+@@ -531,7 +531,7 @@
      pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance);
  
      if (pX11IMData == NULL) {
@@ -18974,7 +13389,7 @@
          return False;
  #else
          return result;
-@@ -541,7 +541,7 @@
+@@ -539,7 +539,7 @@
      }
  
      if ((ic = pX11IMData->current_ic) == (XIC)0){
@@ -18983,7 +13398,7 @@
          return False;
  #else
          return result;
-@@ -650,7 +650,7 @@
+@@ -648,7 +648,7 @@
      return result;
  }
  
@@ -18992,7 +13407,7 @@
  static StatusWindow *createStatusWindow(
  #ifdef XAWT
                                  Window parent) {
-@@ -994,7 +994,7 @@
+@@ -993,7 +993,7 @@
          }
      }
  }
@@ -19001,7 +13416,7 @@
  /*
   * Creates two XICs, one for active clients and the other for passive
   * clients. All information on those XICs are stored in the
-@@ -1051,7 +1051,7 @@
+@@ -1050,7 +1050,7 @@
          return FALSE ;
      }
  
@@ -19010,7 +13425,7 @@
      on_the_spot_styles |= XIMStatusNothing;
  
      /*kinput does not support XIMPreeditCallbacks and XIMStatusArea
-@@ -1064,7 +1064,7 @@
+@@ -1063,7 +1063,7 @@
              break;
          }
      }
@@ -19019,7 +13434,7 @@
  #ifdef XAWT
      on_the_spot_styles |= XIMStatusNothing;
  #else /* !XAWT */
-@@ -1087,7 +1087,7 @@
+@@ -1086,7 +1086,7 @@
          on_the_spot_styles |= XIMStatusNothing;
  
  #endif /* XAWT */
@@ -19028,7 +13443,7 @@
  
      for (i = 0; i < im_styles->count_styles; i++) {
          active_styles |= im_styles->supported_styles[i] & on_the_spot_styles;
-@@ -1135,7 +1135,7 @@
+@@ -1134,7 +1134,7 @@
                          NULL);
          if (preedit == (XVaNestedList)NULL)
              goto err;
@@ -19037,7 +13452,7 @@
          /*always try XIMStatusCallbacks for active client...*/
          {
              status = (XVaNestedList)XVaCreateNestedList(0,
-@@ -1157,7 +1157,7 @@
+@@ -1156,7 +1156,7 @@
              XFree((void *)status);
              XFree((void *)preedit);
          }
@@ -19046,7 +13461,7 @@
  #ifndef XAWT
          if (on_the_spot_styles & XIMStatusArea) {
              Widget parent;
-@@ -1185,7 +1185,7 @@
+@@ -1184,7 +1184,7 @@
          }
  #endif /* XAWT */
          XFree((void *)preedit);
@@ -19053,9 +13468,9 @@
 -#endif /* __linux__ */
 +#endif /* __linux__ || _ALLBSD_SOURCE */
          pX11IMData->ic_passive = XCreateIC(X11im,
-                                            XNClientWindow, XtWindow(w),
-                                            XNFocusWindow, XtWindow(w),
-@@ -1344,7 +1344,7 @@
+                                            XNClientWindow, w,
+                                            XNFocusWindow, w,
+@@ -1343,7 +1343,7 @@
  
  }
  
@@ -19064,7 +13479,7 @@
  static void
  StatusStartCallback(XIC ic, XPointer client_data, XPointer call_data)
  {
-@@ -1412,7 +1412,7 @@
+@@ -1411,7 +1411,7 @@
   finally:
      AWT_UNLOCK();
  }
@@ -19073,7 +13488,7 @@
  
  static void CommitStringCallback(XIC ic, XPointer client_data, XPointer call_data) {
      JNIEnv *env = GetJNIEnv();
-@@ -1514,14 +1514,14 @@
+@@ -1513,14 +1513,14 @@
  /* Use IMInstantiate call back only on Linux, as there is a bug in Solaris
     (4768335)
  */
@@ -19080,7 +13495,7 @@
 -#ifdef __linux__
 +#if defined(__linux__) || defined(_ALLBSD_SOURCE)
      registered = XRegisterIMInstantiateCallback(dpy, NULL, NULL,
-                      NULL, (XIMProc)OpenXIMCallback, NULL);
+                      NULL, (XIDProc)OpenXIMCallback, NULL);
      if (!registered) {
          /* directly call openXIM callback */
  #endif
@@ -19090,7 +13505,7 @@
      }
  #endif
  
-@@ -1585,13 +1585,13 @@
+@@ -1584,13 +1584,13 @@
  #endif /* XAWT */
      globalRef = (*env)->NewGlobalRef(env, this);
      pX11IMData->x11inputmethod = globalRef;
@@ -19107,10 +13522,10 @@
  
      pX11IMData->lookup_buf = 0;
      pX11IMData->lookup_buf_len = 0;
-@@ -1738,14 +1738,14 @@
+@@ -1737,14 +1737,14 @@
          setXICFocus(pX11IMData->current_ic, req);
          currentX11InputMethodInstance = pX11IMData->x11inputmethod;
-         currentFocusWindow =  XtWindow(w);
+         currentFocusWindow =  w;
 -#ifdef __linux__
 +#if defined(__linux__) || defined(_ALLBSD_SOURCE)
          if (active && pX11IMData->statusWindow && pX11IMData->statusWindow->on)
@@ -19124,7 +13539,7 @@
          onoffStatusWindow(pX11IMData, 0, False);
          if (pX11IMData->current_ic != NULL)
  #endif
-@@ -1762,7 +1762,7 @@
+@@ -1761,7 +1761,7 @@
  Java_sun_awt_X11InputMethod_turnoffStatusWindow(JNIEnv *env,
                                                  jobject this)
  {
@@ -19133,7 +13548,7 @@
      X11InputMethodData *pX11IMData;
      StatusWindow *statusWindow;
  
-@@ -1859,7 +1859,7 @@
+@@ -1858,7 +1858,7 @@
      X11InputMethodData *pX11IMData;
      XVaNestedList status;
  
@@ -19142,7 +13557,7 @@
        /*do nothing for linux? */
  #else
      AWT_LOCK();
-@@ -1965,7 +1965,7 @@
+@@ -1964,7 +1964,7 @@
  JNIEXPORT void JNICALL Java_sun_awt_X11_XInputMethod_adjustStatusWindow
    (JNIEnv *env, jobject this, jlong window)
  {
@@ -19392,10 +13807,10 @@
  #include <jni.h>
  #include <jni_util.h>
 +#include <jvm_md.h>
+ #include <sizecalc.h>
  #include <sun_font_FontManager.h>
  #ifndef HEADLESS
- #include <X11/Xlib.h>
-@@ -58,10 +59,24 @@
+@@ -59,10 +60,24 @@
  extern Display *awt_display;
  #endif /* !HEADLESS */
  
@@ -19421,7 +13836,7 @@
  /*
   * This can be set in the makefile to "/usr/X11" if so desired.
   */
-@@ -111,24 +126,40 @@
+@@ -112,24 +127,40 @@
      NULL, /* terminates the list */
  };
  
@@ -19474,7 +13889,7 @@
      NULL, /* terminates the list */
  };
  #endif
-@@ -351,7 +382,7 @@
+@@ -357,7 +388,7 @@
  
  #endif /* !HEADLESS */
  
@@ -19483,7 +13898,7 @@
  /* from awt_LoadLibrary.c */
  JNIEXPORT jboolean JNICALL AWTIsHeadless();
  #endif
-@@ -476,8 +507,10 @@
+@@ -482,8 +513,10 @@
       */
      fcdirs = getFontConfigLocations();
  
@@ -19495,7 +13910,7 @@
  #else /* IF SOLARIS */
      knowndirs = fullSolarisFontPath;
  #endif
-@@ -488,7 +521,8 @@
+@@ -494,7 +527,8 @@
       * be initialised.
       */
  #ifndef HEADLESS
@@ -19505,7 +13920,7 @@
      if (!AWTIsHeadless()) { /* .. so need to call a function to check */
  #endif
      AWT_LOCK();
-@@ -496,7 +530,7 @@
+@@ -502,7 +536,7 @@
          x11dirs = getX11FontPath();
      }
      AWT_UNLOCK();
@@ -19514,7 +13929,7 @@
      }
  #endif
  #endif /* !HEADLESS */
-@@ -608,7 +642,7 @@
+@@ -614,7 +648,7 @@
  }
  
  #include <dlfcn.h>
@@ -19523,7 +13938,7 @@
  #include <link.h>
  #endif
  
-@@ -654,9 +688,9 @@
+@@ -660,9 +694,9 @@
       * certain symbols - and functionality - to be available.
       * Also add explicit search for .so.1 in case .so symlink doesn't exist.
       */
@@ -19537,11 +13952,12 @@
          }
 --- jdk/src/solaris/native/sun/awt/gtk2_interface.c
 +++ jdk/src/solaris/native/sun/awt/gtk2_interface.c
-@@ -30,8 +30,9 @@
+@@ -30,9 +30,10 @@
  #include <string.h>
  #include "gtk2_interface.h"
  #include "java_awt_Transparency.h"
 +#include "jvm_md.h"
+ #include "sizecalc.h"
  
 -#define GTK2_LIB "libgtk-x11-2.0.so.0"
 +#define GTK2_LIB VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0")
@@ -19769,7 +14185,7 @@
  #include "awt_Component.h"
  #include "awt_GraphicsEnv.h"
  
-@@ -128,7 +129,7 @@
+@@ -129,7 +130,7 @@
  
      if (tryDGA && (getenv("NO_J2D_DGA") == NULL)) {
      /* we use RTLD_NOW because of bug 4032715 */
@@ -19865,7 +14281,7 @@
  #include <netinet/in.h>
  #endif
  
-@@ -86,7 +86,7 @@
+@@ -81,7 +81,7 @@
      rv = connect(fd, 0, 0);
  #endif
  
@@ -19874,7 +14290,7 @@
      {
          int len;
          SOCKADDR sa;
-@@ -96,17 +96,30 @@
+@@ -91,17 +91,30 @@
  #ifdef AF_INET6
          if (ipv6_available()) {
              struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)&sa;
@@ -20096,7 +14512,7 @@
  static jfieldID key_st_dev;    /* id for FileKey.st_dev */
  static jfieldID key_st_ino;    /* id for FileKey.st_ino */
  
---- jdk/src/solaris/native/sun/nio/ch/KqueueArrayWrapper.c	1969-12-31 19:00:00.000000000 -0500
+--- jdk/src/solaris/native/sun/nio/ch/KqueueArrayWrapper.c
 +++ jdk/src/solaris/native/sun/nio/ch/KqueueArrayWrapper.c
 @@ -0,0 +1,186 @@
 +/*
@@ -20285,9 +14701,60 @@
 +#ifdef __cplusplus
 +}
 +#endif
+--- jdk/src/solaris/native/sun/nio/ch/NativeThread.c
++++ jdk/src/solaris/native/sun/nio/ch/NativeThread.c
+@@ -33,12 +33,20 @@
+ #include "nio_util.h"
+ 
+ 
+-#ifdef __linux__
++#if defined(__linux__) || defined(_ALLBSD_SOURCE)
++#if defined(__linux__)
+ #include <pthread.h>
+ #include <sys/signal.h>
+ 
+ /* Also defined in src/solaris/native/java/net/linux_close.c */
+ #define INTERRUPT_SIGNAL (__SIGRTMAX - 2)
++#else
++#include <pthread.h>
++#include <signal.h>
++
++/* Also defined in src/solaris/native/java/net/bsd_close.c */
++#define INTERRUPT_SIGNAL SIGIO
++#endif
+ 
+ static void
+ nullHandler(int sig)
+@@ -51,7 +59,7 @@
+ JNIEXPORT void JNICALL
+ Java_sun_nio_ch_NativeThread_init(JNIEnv *env, jclass cl)
+ {
+-#ifdef __linux__
++#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+ 
+     /* Install the null handler for INTERRUPT_SIGNAL.  This might overwrite the
+      * handler previously installed by java/net/linux_close.c, but that's okay
+@@ -74,7 +82,7 @@
+ JNIEXPORT jlong JNICALL
+ Java_sun_nio_ch_NativeThread_current(JNIEnv *env, jclass cl)
+ {
+-#ifdef __linux__
++#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+     return (long)pthread_self();
+ #else
+     return -1;
+@@ -84,7 +92,7 @@
+ JNIEXPORT void JNICALL
+ Java_sun_nio_ch_NativeThread_signal(JNIEnv *env, jclass cl, jlong thread)
+ {
+-#ifdef __linux__
++#if defined(__linux__) || defined(_ALLBSD_SOURCE)
+     if (pthread_kill((pthread_t)thread, INTERRUPT_SIGNAL))
+         JNU_ThrowIOExceptionWithLastError(env, "Thread signal failed");
+ #endif
 --- jdk/src/solaris/native/sun/nio/ch/Net.c
 +++ jdk/src/solaris/native/sun/nio/ch/Net.c
-@@ -60,17 +60,33 @@
+@@ -65,17 +65,33 @@
                              jboolean reuse)
  {
      int fd;
@@ -20327,7 +14794,7 @@
      if (reuse) {
          int arg = 1;
          if (NET_SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
-@@ -138,10 +154,33 @@
+@@ -143,10 +159,33 @@
  Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo)
  {
      SOCKADDR sa;
@@ -20362,7 +14829,7 @@
      }
      return NET_GetPortFromSockaddr((struct sockaddr *)&sa);
  }
-@@ -150,15 +189,79 @@
+@@ -155,15 +194,79 @@
  Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo)
  {
      SOCKADDR sa;
@@ -20445,7 +14912,7 @@
  
  #ifdef NEEDED
  
-@@ -304,9 +407,11 @@
+@@ -309,9 +412,11 @@
      switch (errorValue) {
          case EINPROGRESS:       /* Non-blocking connect */
              return 0;
@@ -20949,8 +15416,8 @@
              os = "Linux";
 +	} else if (os.indexOf("MidnightBSD") >= 0) {
 +	    os = "MidnightBSD";
-+	} else if (os.indexOf("MidnightBSD") >= 0) {
-+	    os = "MidnightBSD";
++	} else if (os.indexOf("Darwin") >= 0) {
++	    os = "Darwin";
 +	} else if (os.indexOf("NetBSD") >= 0) {
 +	    os = "NetBSD";
 +	} else if (os.indexOf("OpenBSD") >= 0) {

Deleted: trunk/java/openjdk6/files/patch-sharedRuntime_x86_64.cpp
===================================================================
--- trunk/java/openjdk6/files/patch-sharedRuntime_x86_64.cpp	2015-09-13 00:45:55 UTC (rev 20224)
+++ trunk/java/openjdk6/files/patch-sharedRuntime_x86_64.cpp	2015-09-13 00:58:25 UTC (rev 20225)
@@ -1,76 +0,0 @@
-
-# HG changeset patch
-# User never
-# Date 1320440131 25200
-# Node ID 1feb272af3a704c03d544ef6c606db32049e492c
-# Parent 448691f285a54cd944c45c79ff0ba13ec8e3e205
-6636110: unaligned stackpointer leads to crash during deoptimization
-Reviewed-by: never, kvn
-Contributed-by: Andreas Schoesser <andreas.schoesser at sap.com>
-
---- hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp.orig	Thu Nov 03 04:12:49 2011 -0700
-+++ hotspot/src/cpu/x86/vm/sharedRuntime_x86_64.cpp	Fri Nov 04 13:55:31 2011 -0700
-@@ -2797,17 +2797,25 @@ void SharedRuntime::generate_deopt_blob(
-   // void Deoptimization::unpack_frames(JavaThread* thread, int exec_mode)
- 
-   // Use rbp because the frames look interpreted now
--  __ set_last_Java_frame(noreg, rbp, NULL);
--
-+  // Save "the_pc" since it cannot easily be retrieved using the last_java_SP after we aligned SP.
-+  // Don't need the precise return PC here, just precise enough to point into this code blob.
-+  address the_pc = __ pc();
-+  __ set_last_Java_frame(noreg, rbp, the_pc);
-+
-+  __ andptr(rsp, -(StackAlignmentInBytes));  // Fix stack alignment as required by ABI
-   __ mov(c_rarg0, r15_thread);
-   __ movl(c_rarg1, r14); // second arg: exec_mode
-   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames)));
-+  // Revert SP alignment after call since we're going to do some SP relative addressing below
-+  __ movptr(rsp, Address(r15_thread, JavaThread::last_Java_sp_offset()));
- 
-   // Set an oopmap for the call site
--  oop_maps->add_gc_map(__ pc() - start,
-+  // Use the same PC we used for the last java frame
-+  oop_maps->add_gc_map(the_pc - start,
-                        new OopMap( frame_size_in_words, 0 ));
- 
--  __ reset_last_Java_frame(true, false);
-+  // Clear fp AND pc
-+  __ reset_last_Java_frame(true, true);
- 
-   // Collect return values
-   __ movdbl(xmm0, Address(rsp, RegisterSaver::xmm0_offset_in_bytes()));
-@@ -2968,7 +2976,10 @@ void SharedRuntime::generate_uncommon_tr
-                               // Prolog
- 
-   // Use rbp because the frames look interpreted now
--  __ set_last_Java_frame(noreg, rbp, NULL);
-+  // Save "the_pc" since it cannot easily be retrieved using the last_java_SP after we aligned SP.
-+  // Don't need the precise return PC here, just precise enough to point into this code blob.
-+  address the_pc = __ pc();
-+  __ set_last_Java_frame(noreg, rbp, the_pc);
- 
-   // Call C code.  Need thread but NOT official VM entry
-   // crud.  We cannot block on this call, no GC can happen.  Call should
-@@ -2977,14 +2988,17 @@ void SharedRuntime::generate_uncommon_tr
-   //
-   // BasicType unpack_frames(JavaThread* thread, int exec_mode);
- 
-+  __ andptr(rsp, -(StackAlignmentInBytes)); // Align SP as required by ABI
-   __ mov(c_rarg0, r15_thread);
-   __ movl(c_rarg1, Deoptimization::Unpack_uncommon_trap);
-   __ call(RuntimeAddress(CAST_FROM_FN_PTR(address, Deoptimization::unpack_frames)));
- 
-   // Set an oopmap for the call site
--  oop_maps->add_gc_map(__ pc() - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
--
--  __ reset_last_Java_frame(true, false);
-+  // Use the same PC we used for the last java frame
-+  oop_maps->add_gc_map(the_pc - start, new OopMap(SimpleRuntimeFrame::framesize, 0));
-+
-+  // Clear fp AND pc
-+  __ reset_last_Java_frame(true, true);
- 
-   // Pop self-frame.
-   __ leave();                 // Epilog
-



More information about the Midnightbsd-cvs mailing list