Ticket #22760: patch-set

File patch-set, 525.8 KB (added by vike2000, 14 years ago)
Line 
1/*
2 * Copyright 2008-2009 Sun Microsystems, Inc.  All Rights Reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
20 * CA 95054 USA or visit www.sun.com if you need additional information or
21 * have any questions.
22 *
23 */
24diff -upr ../orig/corba/make/common/Defs-bsd.gmk ./corba/make/common/Defs-bsd.gmk
25--- ../orig/corba/make/common/Defs-bsd.gmk      2009-05-04 18:32:16.000000000 -0400
26+++ ./corba/make/common/Defs-bsd.gmk    2009-05-05 14:33:21.000000000 -0400
27@@ -40,18 +40,12 @@
28 # Get shared JDK settings
29 include $(BUILDDIR)/common/shared/Defs.gmk
30 
31-# Part of INCREMENTAL_BUILD mechanism.
32-#   Compiler emits things like:  path/file.o: file.h
33-#   We want something like: relative_path/file.o relative_path/file.d: file.h
34-CC_DEPEND       = -MM
35-CC_DEPEND_FILTER = $(SED) -e 's!$*\.$(OBJECT_SUFFIX)!$(dir $@)& $(dir $@)$*.$(DEPEND_SUFFIX)!g'
36-
37 ifndef PLATFORM_SRC
38   PLATFORM_SRC = $(TOPDIR)/src/solaris
39 endif # PLATFORM_SRC
40 
41 # platform specific include files
42-PLATFORM_INCLUDE_NAME = $(PLATFORM)
43+PLATFORM_INCLUDE_NAME = $(OS_NAME)
44 PLATFORM_INCLUDE      = $(INCLUDEDIR)/$(PLATFORM_INCLUDE_NAME)
45 
46 # suffix used for make dependencies files.
47@@ -94,6 +88,10 @@ endif
48 #    as the default.
49 CFLAGS_REQUIRED_amd64   += -fno-omit-frame-pointer -D_LITTLE_ENDIAN
50 CFLAGS_REQUIRED_i586    += -fno-omit-frame-pointer -D_LITTLE_ENDIAN
51+ifeq ($(OS_VENDOR),Apple)
52+  # 16-byte stack re-alignment on 32-bit Darwin
53+  CFLAGS_REQUIRED_i586 += -mstackrealign
54+endif
55 CFLAGS_REQUIRED_ia64    += -fno-omit-frame-pointer -D_LITTLE_ENDIAN
56 CFLAGS_REQUIRED_sparcv9 += -m64 -mcpu=v9
57 LDFLAGS_COMMON_sparcv9  += -m64 -mcpu=v9
58@@ -168,7 +166,7 @@ ifeq ($(FASTDEBUG), true)
59   CXXFLAGS_DBG += $(CC_LOWER_OPT)
60 endif
61 
62-CPPFLAGS_COMMON = -D$(ARCH) -DARCH='"$(ARCH)"' -DLINUX $(VERSION_DEFINES) \
63+CPPFLAGS_COMMON = -D$(ARCH) -DARCH='"$(ARCH)"' -D_ALLBSD_SOURCE $(VERSION_DEFINES) \
64                  -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_REENTRANT
65 
66 ifeq ($(ARCH_DATA_MODEL), 64)
67@@ -178,33 +176,15 @@ endif
68 CPPFLAGS_OPT    =
69 CPPFLAGS_DBG    = -DDEBUG
70 
71-ifdef LIBRARY
72-  # Libraries need to locate other libraries at runtime, and you can tell
73-  #   a library where to look by way of the dynamic runpaths (RPATH or RUNPATH)
74-  #   buried inside the .so. The $ORIGIN says to look relative to where
75-  #   the library itself is and it can be followed with relative paths from
76-  #   that. By default we always look in $ORIGIN, optionally we add relative
77-  #   paths if the Makefile sets LD_RUNPATH_EXTRAS to those relative paths.
78-  #   On Bsd we add a flag -z origin, not sure if this is necessary, but
79-  #   doesn't seem to hurt.
80-  #   The environment variable LD_LIBRARY_PATH will over-ride these runpaths.
81-  #   Try: 'readelf -d lib*.so' to see these settings in a library.
82-  #
83-  LDFLAGS_COMMON += -Xlinker -z -Xlinker origin -Xlinker -rpath -Xlinker \$$ORIGIN
84-  LDFLAGS_COMMON += $(LD_RUNPATH_EXTRAS:%=-Xlinker -z -Xlinker origin -Xlinker -rpath -Xlinker \$$ORIGIN/%)
85-endif
86-
87-EXTRA_LIBS += -lc
88-
89-LDFLAGS_DEFS_OPTION  = -z defs
90-LDFLAGS_COMMON  += $(LDFLAGS_DEFS_OPTION)
91-
92 #
93 # -L paths for finding and -ljava
94 #
95-LDFLAGS_OPT     = -Xlinker -O1
96 LDFLAGS_COMMON += -L$(LIBDIR)/$(LIBARCH)
97+
98+ifneq ($(OS_VENDOR), Apple)
99+LDFLAGS_OPT     = -Xlinker -O1
100 LDFLAGS_COMMON += -Wl,-soname=$(LIB_PREFIX)$(LIBRARY).$(LIBRARY_SUFFIX)
101+endif
102 
103 #
104 # -static-libgcc is a gcc-3 flag to statically link libgcc, gcc-2.9x always
105@@ -235,13 +215,9 @@ endif
106 #
107 LD_MAPFILE_FLAG = -Xlinker --version-script -Xlinker
108 
109-#
110-# Support for Quantify.
111-#
112-ifdef QUANTIFY
113-QUANTIFY_CMD = quantify
114-QUANTIFY_OPTIONS = -cache-dir=/tmp/quantify -always-use-cache-dir=yes
115-LINK_PRE_CMD = $(QUANTIFY_CMD) $(QUANTIFY_OPTIONS)
116+# Darwin does not support linker map files.
117+ifeq ($(OS_VENDOR), Apple)
118+LDNOMAP=true
119 endif
120 
121 #
122@@ -270,7 +246,9 @@ override HAVE_ALTZONE            = false
123 override HAVE_FILIOH             = false
124 override HAVE_GETHRTIME          = false
125 override HAVE_GETHRVTIME         = false
126+ifeq ($(OS_VENDOR),Apple)
127 override HAVE_SIGIGNORE          = true
128+endif
129 override LEX_LIBRARY             = -lfl
130 ifeq ($(STATIC_CXX),true)
131 override LIBCXX                  = -Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic
132@@ -281,13 +259,9 @@ override LIBPOSIX4               =
133 override LIBSOCKET               =
134 override LIBTHREAD               =
135 override MOOT_PRIORITIES         = true
136-override NO_INTERRUPTIBLE_IO     = true
137-override OPENWIN_HOME            = /usr/X11R6
138-ifeq ($(ARCH), amd64)
139-override OPENWIN_LIB             = $(OPENWIN_HOME)/lib64
140-else
141+override NO_INTERRUPTIBLE_IO     = false
142+override OPENWIN_HOME            = $(X11_PATH)
143 override OPENWIN_LIB             = $(OPENWIN_HOME)/lib
144-endif
145 override OTHER_M4FLAGS           = -D__GLIBC__ -DGNU_ASSEMBLER
146 override SUN_CMM_SUBDIR          =
147 override THREADS_FLAG            = native
148diff -upr ../orig/corba/make/common/Defs-linux.gmk ./corba/make/common/Defs-linux.gmk
149--- ../orig/corba/make/common/Defs-linux.gmk    2009-01-27 15:40:31.000000000 -0500
150+++ ./corba/make/common/Defs-linux.gmk  2009-05-04 17:37:15.000000000 -0400
151@@ -282,7 +282,7 @@ override LIBSOCKET               =
152 override LIBTHREAD               =
153 override MOOT_PRIORITIES         = true
154 override NO_INTERRUPTIBLE_IO     = true
155-override OPENWIN_HOME            = /usr/X11R6
156+override OPENWIN_HOME            = $(X11_PATH)
157 ifeq ($(ARCH), amd64)
158 override OPENWIN_LIB             = $(OPENWIN_HOME)/lib64
159 else
160diff -upr ../orig/corba/make/common/Defs.gmk ./corba/make/common/Defs.gmk
161--- ../orig/corba/make/common/Defs.gmk  2009-01-27 15:40:31.000000000 -0500
162+++ ./corba/make/common/Defs.gmk        2009-05-04 17:37:15.000000000 -0400
163@@ -53,6 +53,24 @@ endif
164 
165 _OUTPUTDIR=$(TOPDIR)/build/$(PLATFORM)-$(ARCH)
166 
167+ifneq ($(PLATFORM), windows)
168+  ifdef ALT_X11_PATH
169+    X11_PATH = $(ALT_X11_PATH)
170+  else
171+    X11_PATH = /usr/X11R6
172+  endif
173+
174+  ifdef ALT_PACKAGE_PATH
175+    PACKAGE_PATH = $(ALT_PACKAGE_PATH)
176+  else
177+    ifeq ($(PLATFORM), linux)
178+      PACKAGE_PATH = /usr
179+    else
180+      PACKAGE_PATH = /usr/local
181+    endif
182+  endif
183+endif
184+
185 #
186 # Get platform definitions
187 #
188@@ -97,6 +115,9 @@ ifdef PROGRAM
189     LDLIBS_COMMON = -ldl
190   endif
191 
192+  ifeq ($(PLATFORM), bsd)
193+    LDLIBS_COMMON = -pthread
194+  endif
195 endif # PROGRAM
196 
197 LDLIBS_COMMON += $(EXTRA_LIBS)
198diff -upr ../orig/corba/make/common/Mapfile-vers.gmk ./corba/make/common/Mapfile-vers.gmk
199--- ../orig/corba/make/common/Mapfile-vers.gmk  2009-01-27 15:40:31.000000000 -0500
200+++ ./corba/make/common/Mapfile-vers.gmk        2009-05-04 17:37:15.000000000 -0400
201@@ -77,7 +77,7 @@ endif
202 endif # PLATFORM
203 
204 
205-ifeq ($(PLATFORM), linux)
206+ifneq (,$(findstring $(PLATFORM), linux bsd))
207 
208 ifeq ($(VARIANT), OPT)
209   # OPT build MUST have a mapfile?
210diff -upr ../orig/corba/make/common/shared/Compiler-gcc.gmk ./corba/make/common/shared/Compiler-gcc.gmk
211--- ../orig/corba/make/common/shared/Compiler-gcc.gmk   2009-01-27 15:40:31.000000000 -0500
212+++ ./corba/make/common/shared/Compiler-gcc.gmk 2009-05-04 17:37:15.000000000 -0400
213@@ -99,6 +99,24 @@ ifeq ($(PLATFORM), linux)
214 
215 endif
216 
217+ifeq ($(PLATFORM), bsd)
218+  # Settings specific to BSD
219+  CC             = $(COMPILER_PATH)gcc
220+  CPP            = $(COMPILER_PATH)gcc -E
221+  CXX            = $(COMPILER_PATH)g++
222+  REQUIRED_CC_VER = 3.3
223+  REQUIRED_GCC_VER = 3.3.*
224+
225+# Option used to create a shared library
226+ifeq ($(OS_VENDOR), Apple)
227+  SHARED_LIBRARY_FLAG = -dynamiclib
228+else
229+  SHARED_LIBRARY_FLAG = -shared
230+endif
231+
232+  SUN_COMP_VER := $(shell $(CC) --verbose 2>&1 )
233+endif
234+
235 ifeq ($(PLATFORM), solaris)
236 
237   # Settings specific to Solaris
238diff -upr ../orig/corba/make/common/shared/Compiler.gmk ./corba/make/common/shared/Compiler.gmk
239--- ../orig/corba/make/common/shared/Compiler.gmk       2009-01-27 15:40:31.000000000 -0500
240+++ ./corba/make/common/shared/Compiler.gmk     2009-05-04 17:37:15.000000000 -0400
241@@ -42,6 +42,11 @@ ifeq ($(PLATFORM), linux)
242   override CC_VERSION = gcc
243 endif
244 
245+# BSD uses GNU compilers by default
246+ifeq ($(PLATFORM), bsd)
247+  override CC_VERSION = gcc
248+endif
249+
250 # Get the compiler specific settings
251 include $(BUILDDIR)/common/shared/Compiler-$(CC_VERSION).gmk
252 
253diff -upr ../orig/corba/make/common/shared/Defs-bsd.gmk ./corba/make/common/shared/Defs-bsd.gmk
254--- ../orig/corba/make/common/shared/Defs-bsd.gmk       2009-05-04 18:32:16.000000000 -0400
255+++ ./corba/make/common/shared/Defs-bsd.gmk     2009-05-04 17:37:15.000000000 -0400
256@@ -54,7 +54,7 @@ $(shell if [ "$1" != "" -a -d "$1" ]; th
257 endef
258 
259 # Location on system where jdk installs might be
260-USRJDKINSTANCES_PATH =/opt/java
261+USRJDKINSTANCES_PATH =$(PACKAGE_PATH)
262 
263 # UNIXCOMMAND_PATH: path to where the most common Unix commands are.
264 #  NOTE: Must end with / so that it could be empty, allowing PATH usage.
265@@ -107,7 +107,7 @@ endif
266 ifneq "$(origin ALT_DEVTOOLS_PATH)" "undefined"
267   DEVTOOLS_PATH :=$(call PrefixPath,$(ALT_DEVTOOLS_PATH))
268 else
269-  DEVTOOLS_PATH =/usr/bin/
270+  DEVTOOLS_PATH =$(PACKAGE_PATH)/bin/
271 endif
272 
273 # _BOOTDIR1: First choice for a Bootstrap JDK, previous released JDK.
274diff -upr ../orig/corba/make/common/shared/Defs-utils.gmk ./corba/make/common/shared/Defs-utils.gmk
275--- ../orig/corba/make/common/shared/Defs-utils.gmk     2009-01-27 15:40:31.000000000 -0500
276+++ ./corba/make/common/shared/Defs-utils.gmk   2009-05-04 17:37:15.000000000 -0400
277@@ -53,6 +53,13 @@ ifeq ($(PLATFORM),linux)
278   UTILS_DEVTOOL_PATH=$(USRBIN_PATH)
279 endif
280 
281+ifeq ($(PLATFORM),bsd)
282+  UTILS_COMMAND_PATH=$(UNIXCOMMAND_PATH)
283+  UTILS_USR_BIN_PATH=$(USRBIN_PATH)
284+  UTILS_CCS_BIN_PATH=$(USRBIN_PATH)
285+  UTILS_DEVTOOL_PATH=$(DEVTOOLS_PATH)
286+endif
287+
288 ifeq ($(PLATFORM),solaris)
289   UTILS_COMMAND_PATH=$(UNIXCOMMAND_PATH)
290   UTILS_USR_BIN_PATH=$(UNIXCOMMAND_PATH)
291@@ -209,3 +216,32 @@ ifeq ($(PLATFORM),solaris)
292   ECHO           = /usr/bin/echo
293 endif
294 
295+# BSD specific
296+ifeq ($(PLATFORM),bsd)
297+  BASENAME     = $(UTILS_USR_BIN_PATH)basename
298+  EGREP        = $(UTILS_USR_BIN_PATH)egrep
299+  EXPR         = $(UTILS_COMMAND_PATH)expr
300+  FMT          = $(UTILS_USR_BIN_PATH)fmt
301+  GREP         = $(UTILS_USR_BIN_PATH)grep
302+  GUNZIP       = $(UTILS_USR_BIN_PATH)gunzip
303+  ID           = $(UTILS_USR_BIN_PATH)id
304+  MSGFMT       = $(UTILS_DEVTOOL_PATH)msgfmt
305+  SED          = $(UTILS_USR_BIN_PATH)sed
306+  SORT         = $(UTILS_USR_BIN_PATH)sort
307+  TEST         = $(UTILS_COMMAND_PATH)test
308+  TOUCH        = $(UTILS_USR_BIN_PATH)touch
309+  TRUE         = $(UTILS_USR_BIN_PATH)true
310+  UNAME        = $(UTILS_USR_BIN_PATH)uname
311+  # BSD OS_VENDOR specific
312+  ifeq ($(OS_VENDOR), Apple)
313+    NAWK       = $(UTILS_USR_BIN_PATH)awk
314+    UNZIPSFX   = $(UTILS_USR_BIN_PATH)unzipsfx
315+    ZIPEXE     = $(UTILS_USR_BIN_PATH)zip
316+  else
317+    UNZIP      = $(UTILS_DEVTOOL_PATH)unzip
318+  endif
319+  ifneq ($(OS_VENDOR), OpenBSD)
320+    CPIO       = $(UTILS_USR_BIN_PATH)cpio
321+    TAR        = $(UTILS_USR_BIN_PATH)tar
322+  endif
323+endif
324diff -upr ../orig/corba/make/common/shared/Platform.gmk ./corba/make/common/shared/Platform.gmk
325--- ../orig/corba/make/common/shared/Platform.gmk       2009-01-27 15:40:31.000000000 -0500
326+++ ./corba/make/common/shared/Platform.gmk     2009-12-02 00:00:00.000000000 -0000
327@@ -262,6 +262,81 @@ ifeq ($(SYSTEM_UNAME), Linux)
328   MB_OF_MEMORY := $(shell free -m | fgrep Mem: | sed -e 's@\ \ *@ @g' | cut -d' ' -f2)
329 endif
330 
331+ifeq ($(SYSTEM_UNAME), FreeBSD)
332+  PLATFORM = bsd
333+  OS_NAME = freebsd
334+  OS_VENDOR = FreeBSD
335+ REQUIRED_OS_VERSION = 6.0
336+endif
337+
338+ifeq ($(SYSTEM_UNAME), Darwin)
339+  PLATFORM = bsd
340+  OS_NAME = darwin
341+  OS_VENDOR = Apple
342+ REQUIRED_OS_VERSION = 8.0
343+endif
344+
345+ifeq ($(SYSTEM_UNAME), NetBSD)
346+  PLATFORM = bsd
347+  OS_NAME = netbsd
348+  OS_VENDOR = NetBSD
349+  REQUIRED_OS_VERSION = 3.0
350+endif
351+
352+ifeq ($(SYSTEM_UNAME), OpenBSD)
353+  PLATFORM = bsd
354+  OS_NAME = openbsd
355+  OS_VENDOR = OpenBSD
356+  REQUIRED_OS_VERSION = 4.2
357+endif
358+
359+# Platform settings specific to BSD
360+ifeq ($(PLATFORM), bsd)
361+  OS_VERSION := $(shell uname -r)
362+  # Arch and OS name/version
363+  #warning "DEBUG: SYSTEM_UNAME: $(SYSTEM_UNAME)"
364+  ifeq ($(SYSTEM_UNAME), Darwin)
365+    ARCH        := $(shell uname -p)
366+  else
367+    mach := $(shell uname -m)
368+    archExpr = case "$(mach)" in \
369+                  i[3-9]86) \
370+                      echo i586 \
371+                      ;; \
372+                  *) \
373+                      echo $(mach) \
374+                      ;; \
375+        esac
376+    ARCH        := $(shell $(archExpr) )
377+  endif
378+  ARCH_FAMILY := $(ARCH)
379
380+  # i586 and sparc are 32 bit, amd64 and sparc64 are 64
381+  ifneq (,$(findstring $(ARCH), i586 sparc))
382+    ARCH_DATA_MODEL=32
383+  else
384+    ARCH_DATA_MODEL=64
385+  endif
386+
387+  # Need to maintain the jre/lib/i386 location for 32-bit Intel
388+  ifeq ($(ARCH), i586)
389+    LIBARCH = i386
390+  else
391+    LIBARCH = $(ARCH)
392+  endif
393+
394+  # Value of Java os.arch property
395+  ARCHPROP  = $(LIBARCH)
396+
397+  # Suffix for file bundles used in previous release
398+  BUNDLE_FILE_SUFFIX=.tar.gz
399+  # Minimum disk space needed as determined by running 'du -sk' on
400+  #    a fully built workspace.
401+  REQUIRED_FREE_SPACE=1500000
402+  # How much RAM does this machine have:
403+  MB_OF_MEMORY=$(shell sysctl -n hw.physmem | awk '{print int($$NF / 1048576); }' )
404+endif
405+
406 # Windows with and without CYGWIN will be slightly different
407 ifeq ($(SYSTEM_UNAME), Windows_NT)
408   PLATFORM = windows
409@@ -373,7 +443,14 @@ endif
410 #    build machines and adjustments will be made to prevent excessing
411 #    system swapping during the build.
412 #    If we don't know, assume 512. Subtract 128 from MB for VM MAX.
413-#    Don't set VM max over 1024-128=896.
414+#    Don't set VM max over 1024-128=896, except on OpenBSD where
415+#    736 is the max.
416+ifeq ($(OS_VENDOR), OpenBSD)
417+  ABS_MAX_MEMORY := "736"
418+else
419+  ABS_MAX_MEMORY := "896"
420+endif
421+
422 ifneq ($(MB_OF_MEMORY),)
423   LOW_MEMORY_MACHINE := $(shell \
424     if [ $(MB_OF_MEMORY) -le 512 ] ; then \
425@@ -385,7 +462,7 @@ ifneq ($(MB_OF_MEMORY),)
426     if [ $(MB_OF_MEMORY) -le 1024 ] ; then \
427       expr $(MB_OF_MEMORY) '-' 128 ; \
428     else \
429-      echo "896"; \
430+      echo $(ABS_MAX_MEMORY); \
431     fi)
432   MIN_VM_MEMORY := $(shell \
433     if [ $(MAX_VM_MEMORY) -le 128 ] ; then \
434diff -upr ../orig/corba/make/sun/corba/core/Makefile ./corba/make/sun/corba/core/Makefile
435--- ../orig/corba/make/sun/corba/core/Makefile  2009-01-27 15:40:31.000000000 -0500
436+++ ./corba/make/sun/corba/core/Makefile        2009-05-04 17:37:15.000000000 -0400
437@@ -53,11 +53,19 @@ include $(CORBA_JMK_DIRECTORY)sun_corba.
438 ifdef STANDALONE_CORBA_WS
439 # FIXUP: What is this all about?
440 OTHER_LDFLAGS=-L$(BOOTDIR)/jre/lib/$(ARCH) -L$(BOOTDIR)/jre/lib/$(LIBARCH)/native_threads -ljvm
441+ifeq ($(PLATFORM), bsd)
442+OTHER_INCLUDES+=-ICClassHeaders -I$(BOOTDIR)/include -I$(BOOTDIR)/include/$(OS_NAME)
443+else
444 OTHER_INCLUDES+=-ICClassHeaders -I$(BOOTDIR)/include -I$(BOOTDIR)/include/$(PLATFORM)
445+endif
446 else
447 OTHER_LDLIBS=$(JVMLIB)
448+ifeq ($(PLATFORM), bsd)
449+OTHER_INCLUDES+=-ICClassHeaders -I$(BOOTDIR)/include -I$(BOOTDIR)/include/$(OS_NAME)
450+else
451 OTHER_INCLUDES+=-ICClassHeaders -I$(BOOTDIR)/include -I$(BOOTDIR)/include/$(PLATFORM)
452 endif
453+endif
454 
455 
456 FILES_c = ioser.c
457diff -upr ../orig/hotspot/build/bsd/Makefile ./hotspot/build/bsd/Makefile
458--- ../orig/hotspot/build/bsd/Makefile  2009-05-04 18:32:15.000000000 -0400
459+++ ./hotspot/build/bsd/Makefile        2009-05-04 19:16:59.000000000 -0400
460@@ -198,7 +198,8 @@ checks: check_os_version check_j2se_vers
461 # Solaris 2.5.1, 2.6).
462 # Disable this check by setting DISABLE_HOTSPOT_OS_VERSION_CHECK=ok.
463 
464-SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7%
465+#SUPPORTED_OS_VERSION = 2.4% 2.5% 2.6% 2.7%
466+DISABLE_HOTSPOT_OS_VERSION_CHECK = ok
467 OS_VERSION := $(shell uname -r)
468 EMPTY_IF_NOT_SUPPORTED = $(filter $(SUPPORTED_OS_VERSION),$(OS_VERSION))
469 
470diff -upr ../orig/hotspot/build/bsd/makefiles/buildtree.make ./hotspot/build/bsd/makefiles/buildtree.make
471--- ../orig/hotspot/build/bsd/makefiles/buildtree.make  2009-05-04 18:32:15.000000000 -0400
472+++ ./hotspot/build/bsd/makefiles/buildtree.make        2009-05-05 15:01:26.000000000 -0400
473@@ -273,10 +273,11 @@ env.sh: $(BUILDTREE_MAKE)
474        [ -n "$$JAVA_HOME" ] && { echo ": \$${JAVA_HOME:=$${JAVA_HOME}}"; }; \
475        { \
476        echo "LD_LIBRARY_PATH=.:$${LD_LIBRARY_PATH:+$$LD_LIBRARY_PATH:}\$${JAVA_HOME}/jre/lib/${LIBARCH}/native_threads:\$${JAVA_HOME}/jre/lib/${LIBARCH}:${GCC_LIB}"; \
477+       echo "DYLD_LIBRARY_PATH=.:$${DYLD_LIBRARY_PATH:+$$DYLD_LIBRARY_PATH:}\$${JAVA_HOME}/jre/lib/${LIBARCH}/native_threads:\$${JAVA_HOME}/jre/lib/${LIBARCH}:${GCC_LIB}"; \
478        echo "CLASSPATH=$${CLASSPATH:+$$CLASSPATH:}.:\$${JAVA_HOME}/jre/lib/rt.jar:\$${JAVA_HOME}/jre/lib/i18n.jar"; \
479        } | sed s:$${JAVA_HOME:--------}:\$${JAVA_HOME}:g; \
480        echo "HOTSPOT_BUILD_USER=\"$${LOGNAME:-$$USER} in `basename $(GAMMADIR)`\""; \
481-       echo "export JAVA_HOME LD_LIBRARY_PATH CLASSPATH HOTSPOT_BUILD_USER"; \
482+       echo "export JAVA_HOME LD_LIBRARY_PATH DYLD_LIBRARY_PATH CLASSPATH HOTSPOT_BUILD_USER"; \
483        ) > $@
484 
485 env.csh: env.sh
486diff -upr ../orig/hotspot/build/bsd/makefiles/cscope.make ./hotspot/build/bsd/makefiles/cscope.make
487--- ../orig/hotspot/build/bsd/makefiles/cscope.make     2009-05-04 18:32:15.000000000 -0400
488+++ ./hotspot/build/bsd/makefiles/cscope.make   2009-05-05 15:08:05.000000000 -0400
489@@ -72,7 +72,7 @@ endif
490 # OS-specific files for other systems are excluded by default.  Use CS_OS=yes
491 # to include platform-specific files for other platforms.
492 ifndef CS_OS
493-CS_OS          = bsd macos solaris win32
494+CS_OS          = linux macos solaris win32 bsd
495 CS_PRUNE_OS    = $(patsubst %,-o -name '*%*',$(filter-out ${OS},${CS_OS}))
496 endif
497 
498diff -upr ../orig/hotspot/build/bsd/makefiles/defs.make ./hotspot/build/bsd/makefiles/defs.make
499--- ../orig/hotspot/build/bsd/makefiles/defs.make       2009-05-04 18:32:16.000000000 -0400
500+++ ./hotspot/build/bsd/makefiles/defs.make     2009-05-04 17:37:15.000000000 -0400
501@@ -28,8 +28,20 @@
502 
503 SLASH_JAVA ?= /java
504 
505+# Library suffix
506+OS_VENDOR:=$(shell uname -s)
507+ifeq ($(OS_VENDOR),Darwin)
508+  LIBRARY_SUFFIX=dylib
509+else
510+  LIBRARY_SUFFIX=so
511+endif
512+
513 # Need PLATFORM (os-arch combo names) for jdk and hotspot, plus libarch name
514-ARCH:=$(shell uname -m)
515+ifeq ($(OS_VENDOR),Darwin)
516+  ARCH:=$(shell uname -p)
517+else
518+  ARCH:=$(shell uname -m)
519+endif
520 PATH_SEP = :
521 ifeq ($(LP64), 1)
522   ARCH_DATA_MODEL ?= 64
523@@ -79,6 +87,31 @@ ifeq ($(ARCH), x86_64)
524   endif
525 endif
526 
527+# amd64
528+ifeq ($(ARCH), amd64)
529+  ARCH_DATA_MODEL = 64
530+  MAKE_ARGS       += LP64=1
531+  PLATFORM        = bsd-amd64
532+  VM_PLATFORM     = bsd_amd64
533+  HS_ARCH         = x86
534+endif
535+
536+# i386
537+ifeq ($(ARCH), i386)
538+  ARCH_DATA_MODEL  = 32
539+  PLATFORM         = bsd-i586
540+  VM_PLATFORM      = bsd_i486
541+  HS_ARCH          = x86
542+endif
543+
544+# i486
545+ifeq ($(ARCH), i486)
546+  ARCH_DATA_MODEL  = 32
547+  PLATFORM         = bsd-i586
548+  VM_PLATFORM      = bsd_i486
549+  HS_ARCH          = x86
550+endif
551+
552 # i686
553 ifeq ($(ARCH), i686)
554   ARCH_DATA_MODEL  = 32
555@@ -95,19 +128,11 @@ VM_DEBUG=jvmg
556 EXPORT_LIST += $(EXPORT_DOCS_DIR)/platform/jvmti/jvmti.html
557 EXPORT_SERVER_DIR = $(EXPORT_JRE_LIB_ARCH_DIR)/server
558 EXPORT_LIST += $(EXPORT_SERVER_DIR)/Xusage.txt
559-EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjsig.so
560-EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.so
561+EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjsig.$(LIBRARY_SUFFIX)
562+EXPORT_LIST += $(EXPORT_SERVER_DIR)/libjvm.$(LIBRARY_SUFFIX)
563 ifeq ($(ARCH_DATA_MODEL), 32)
564   EXPORT_CLIENT_DIR = $(EXPORT_JRE_LIB_ARCH_DIR)/client
565   EXPORT_LIST += $(EXPORT_CLIENT_DIR)/Xusage.txt
566-  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjsig.so
567-  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.so
568-  EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.so
569-  EXPORT_LIST += $(EXPORT_LIB_DIR)/sa-jdi.jar
570-else
571-  ifeq ($(ARCH),ia64)
572-    else
573-      EXPORT_LIST += $(EXPORT_JRE_LIB_ARCH_DIR)/libsaproc.so
574-      EXPORT_LIST += $(EXPORT_LIB_DIR)/sa-jdi.jar
575-    endif
576+  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjsig.$(LIBRARY_SUFFIX)
577+  EXPORT_LIST += $(EXPORT_CLIENT_DIR)/libjvm.$(LIBRARY_SUFFIX)
578 endif
579diff -upr ../orig/hotspot/build/bsd/makefiles/gcc.make ./hotspot/build/bsd/makefiles/gcc.make
580--- ../orig/hotspot/build/bsd/makefiles/gcc.make        2009-05-04 18:32:16.000000000 -0400
581+++ ./hotspot/build/bsd/makefiles/gcc.make      2009-05-04 17:37:15.000000000 -0400
582@@ -22,12 +22,15 @@
583 # 
584 #
585 
586+OS_VENDOR = $(shell uname -s)
587+
588 #------------------------------------------------------------------------
589 # CC, CPP & AS
590 
591-CPP = g++
592-CC  = gcc
593-AS  = $(CC) -c
594+CXX ?= g++
595+CPP  = $(CXX)
596+CC  ?= gcc
597+AS   = $(CC) -c -x assembler-with-cpp
598 
599 # -dumpversion in gcc-2.91 shows "egcs-2.91.66". In later version, it only
600 # prints the numbers (e.g. "2.95", "3.2.1")
601@@ -62,7 +65,7 @@ endif
602 CFLAGS += $(VM_PICFLAG)
603 CFLAGS += -fno-rtti
604 CFLAGS += -fno-exceptions
605-CFLAGS += -D_REENTRANT
606+CFLAGS += -pthread
607 CFLAGS += -fcheck-new
608 
609 ARCHFLAG = $(ARCHFLAG/$(BUILDARCH))
610@@ -72,6 +75,15 @@ ARCHFLAG/ia64    =
611 ARCHFLAG/sparc   = -m32 -mcpu=v9
612 ARCHFLAG/sparcv9 = -m64 -mcpu=v9
613 
614+# Darwin-specific build flags
615+ifeq ($(OS_VENDOR), Darwin)
616+  # Ineffecient 16-byte stack re-alignment on Darwin/IA32
617+  ARCHFLAG/i486 += -mstackrealign
618+
619+  # -arch compiler flag required for x64_64
620+  ARCHFLAGS/amd64 += -arch x86_64
621+endif
622+
623 CFLAGS     += $(ARCHFLAG)
624 AOUT_FLAGS += $(ARCHFLAG)
625 LFLAGS     += $(ARCHFLAG)
626@@ -96,6 +108,11 @@ ACCEPTABLE_WARNINGS = -Wpointer-arith -W
627 CFLAGS_WARN/DEFAULT = $(WARNINGS_ARE_ERRORS) $(ACCEPTABLE_WARNINGS)
628 # Special cases
629 CFLAGS_WARN/BYFILE = $(CFLAGS_WARN/$@)$(CFLAGS_WARN/DEFAULT$(CFLAGS_WARN/$@))
630+# XXXDARWIN: for _dyld_bind_fully_image_containing_address
631+ifeq ($(OS_VENDOR), Darwin)
632+  CFLAGS_WARN/os_bsd.o = $(CFLAGS_WARN/DEFAULT) -Wno-deprecated-declarations
633+endif
634+
635 
636 # The flags to use for an Optimized g++ build
637 OPT_CFLAGS += -O3
638@@ -126,20 +143,40 @@ ifeq ($(BUILDARCH), ia64)
639 LFLAGS += -Wl,-relax
640 endif
641 
642-# Enable linker optimization
643-LFLAGS += -Xlinker -O1
644-
645 # Use $(MAPFLAG:FILENAME=real_file_name) to specify a map file.
646 MAPFLAG = -Xlinker --version-script=FILENAME
647 
648-# Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
649-SONAMEFLAG = -Xlinker -soname=SONAME
650+#
651+# Shared Library
652+#
653+ifeq ($(OS_VENDOR), Darwin)
654+  # Standard linker flags
655+  LFLAGS +=
656+
657+  # Darwin doesn't use ELF and doesn't support version scripts
658+  LDNOMAP = true
659+
660+  # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
661+  SONAMEFLAG =
662+
663+  # Build shared library
664+  SHARED_FLAG = -dynamiclib $(VM_PICFLAG)
665 
666-# Build shared library
667-SHARED_FLAG = -shared
668+  # Keep symbols even they are not used
669+  #AOUT_FLAGS += -export-dynamic
670+else
671+  # Enable linker optimization
672+  LFLAGS += -Xlinker -O1
673+
674+  # Use $(SONAMEFLAG:SONAME=soname) to specify the intrinsic name of a shared obj
675+  SONAMEFLAG = -Xlinker -soname=SONAME
676 
677-# Keep symbols even they are not used
678-AOUT_FLAGS += -export-dynamic
679+  # Build shared library
680+  SHARED_FLAG = -shared $(VM_PICFLAG)
681+
682+  # Keep symbols even they are not used
683+  AOUT_FLAGS += -export-dynamic
684+endif
685 
686 #------------------------------------------------------------------------
687 # Debug flags
688diff -upr ../orig/hotspot/build/bsd/makefiles/jsig.make ./hotspot/build/bsd/makefiles/jsig.make
689--- ../orig/hotspot/build/bsd/makefiles/jsig.make       2009-05-04 18:32:16.000000000 -0400
690+++ ./hotspot/build/bsd/makefiles/jsig.make     2009-05-04 17:37:15.000000000 -0400
691@@ -26,7 +26,12 @@
692 
693 # libjsig[_g].so: signal interposition library
694 JSIG = jsig$(G_SUFFIX)
695-LIBJSIG = lib$(JSIG).so
696+
697+ifeq ($(OS_VENDOR), Darwin)
698+  LIBJSIG = lib$(JSIG).dylib
699+else
700+  LIBJSIG = lib$(JSIG).so
701+endif
702 
703 JSIGSRCDIR = $(GAMMADIR)/src/os/$(Platform_os_family)/vm
704 
705@@ -39,12 +44,12 @@ LIBJSIG_MAPFILE = $(MAKEFILES_DIR)/mapfi
706 # cause problems with interposing. See CR: 6466665
707 # LFLAGS_JSIG += $(MAPFLAG:FILENAME=$(LIBJSIG_MAPFILE))
708 
709-LFLAGS_JSIG += -D_GNU_SOURCE -D_REENTRANT
710+LFLAGS_JSIG += -D_GNU_SOURCE -pthread
711 
712 $(LIBJSIG): $(JSIGSRCDIR)/jsig.c $(LIBJSIG_MAPFILE)
713        @echo Making signal interposition lib...
714        $(QUIETLY) $(CC) $(SYMFLAG) $(ARCHFLAG) $(SHARED_FLAG) $(PICFLAG) \
715-                         $(LFLAGS_JSIG) -o $@ $< -ldl
716+                         $(LFLAGS_JSIG) -o $@ $<
717 
718 install_jsig: $(LIBJSIG)
719        @echo "Copying $(LIBJSIG) to $(DEST_JSIG)"
720diff -upr ../orig/hotspot/build/bsd/makefiles/launcher.make ./hotspot/build/bsd/makefiles/launcher.make
721--- ../orig/hotspot/build/bsd/makefiles/launcher.make   2009-05-04 18:32:16.000000000 -0400
722+++ ./hotspot/build/bsd/makefiles/launcher.make 2009-05-04 17:37:15.000000000 -0400
723@@ -44,7 +44,7 @@ ifeq ($(LINK_INTO),AOUT)
724   LIBS_LAUNCHER             += $(STATIC_STDCXX) $(LIBS)
725 else
726   LAUNCHER.o                 = launcher.o
727-  LFLAGS_LAUNCHER           += -L `pwd`
728+  LFLAGS_LAUNCHER           += -L`pwd`
729   LIBS_LAUNCHER             += -l$(JVM) $(LIBS)
730 endif
731 
732diff -upr ../orig/hotspot/build/bsd/makefiles/sa.make ./hotspot/build/bsd/makefiles/sa.make
733--- ../orig/hotspot/build/bsd/makefiles/sa.make 2009-05-04 18:32:16.000000000 -0400
734+++ ./hotspot/build/bsd/makefiles/sa.make       2009-05-04 17:37:17.000000000 -0400
735@@ -42,7 +42,7 @@ SA_CLASSPATH = $(BOOT_JAVA_HOME)/lib/too
736 
737 # gnumake 3.78.1 does not accept the *s that
738 # are in AGENT_ALLFILES, so use the shell to expand them
739-AGENT_ALLFILES := $(shell /usr/bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_ALLFILES))
740+AGENT_ALLFILES := $(shell /bin/test -d $(AGENT_DIR) && /bin/ls $(AGENT_ALLFILES))
741 
742 SA_CLASSDIR = $(GENERATED)/saclasses
743 
744diff -upr ../orig/hotspot/build/bsd/makefiles/saproc.make ./hotspot/build/bsd/makefiles/saproc.make
745--- ../orig/hotspot/build/bsd/makefiles/saproc.make     2009-05-04 18:32:16.000000000 -0400
746+++ ./hotspot/build/bsd/makefiles/saproc.make   2009-05-04 17:37:15.000000000 -0400
747@@ -26,7 +26,12 @@
748 
749 # libsaproc[_g].so: serviceability agent
750 SAPROC = saproc$(G_SUFFIX)
751-LIBSAPROC = lib$(SAPROC).so
752+
753+ifeq ($(OS_VENDOR), Darwin)
754+  LIBSAPROC = lib$(SAPROC).dylib
755+else
756+  LIBSAPROC = lib$(SAPROC).so
757+endif
758 
759 AGENT_DIR = $(GAMMADIR)/agent
760 
761@@ -43,11 +48,11 @@ SAMAPFILE = $(SASRCDIR)/mapfile
762 
763 DEST_SAPROC = $(JDK_LIBDIR)/$(LIBSAPROC)
764 
765-# if $(AGENT_DIR) does not exist, we don't build SA
766+# if $(SASRCDIR) does not exist, we don't build SA
767 # also, we don't build SA on Itanium.
768 
769 checkAndBuildSA:
770-       $(QUIETLY) if [ -d $(AGENT_DIR) -a "$(SRCARCH)" != "ia64" ] ; then \
771+       $(QUIETLY) if [ -d $(SASRCDIR) -a "$(SRCARCH)" != "ia64" ] ; then \
772           $(MAKE) -f vm.make $(LIBSAPROC); \
773        fi
774 
775diff -upr ../orig/hotspot/build/bsd/makefiles/vm.make ./hotspot/build/bsd/makefiles/vm.make
776--- ../orig/hotspot/build/bsd/makefiles/vm.make 2009-05-04 18:32:16.000000000 -0400
777+++ ./hotspot/build/bsd/makefiles/vm.make       2009-05-04 17:37:17.000000000 -0400
778@@ -93,7 +93,7 @@ CFLAGS += $(CFLAGS/NOEX)
779 # Extra flags from gnumake's invocation or environment
780 CFLAGS += $(EXTRA_CFLAGS)
781 
782-LIBS += -lm -ldl -lpthread
783+LIBS += -lm -pthread
784 
785 # By default, link the *.o into the library, not the executable.
786 LINK_INTO$(LINK_INTO) = LIBJVM
787@@ -108,7 +108,11 @@ include $(MAKEFILES_DIR)/dtrace.make
788 # JVM
789 
790 JVM    = jvm$(G_SUFFIX)
791-LIBJVM = lib$(JVM).so
792+ifeq ($(OS_VENDOR), Darwin)
793+  LIBJVM = lib$(JVM).dylib
794+else
795+  LIBJVM = lib$(JVM).so
796+endif
797 
798 JVM_OBJ_FILES = $(Obj_Files)
799 
800@@ -122,7 +126,7 @@ mapfile_reorder : mapfile $(REORDERFILE)
801        rm -f $@
802        cat $^ > $@
803 
804-STATIC_CXX = true
805+STATIC_CXX = false
806 
807 ifeq ($(LINK_INTO),AOUT)
808   LIBJVM.o                 =
809@@ -140,14 +144,14 @@ else
810   ifeq ($(STATIC_CXX), true)
811     LFLAGS_VM              += $(STATIC_LIBGCC)
812     LIBS_VM                += $(STATIC_STDCXX)
813+    LINK_VM                = $(LINK_LIB.c)
814   else
815-    LIBS_VM                += -lstdc++
816+    LINK_VM                = $(LINK_LIB.CC)
817   endif
818 
819   LIBS_VM                  += $(LIBS)
820 endif
821 
822-LINK_VM = $(LINK_LIB.c)
823 
824 # rule for building precompiled header
825 $(PRECOMPILED_HEADER): $(Precompiled_Files)
826@@ -175,11 +179,6 @@ $(LD_SCRIPT): $(LIBJVM_MAPFILE)
827 LD_SCRIPT_FLAG = -Wl,-T,$(LD_SCRIPT)
828 endif
829 
830-# With more recent Redhat releases (or the cutting edge version Fedora), if
831-# SEBsd is configured to be enabled, the runtime linker will fail to apply
832-# the text relocation to libjvm.so considering that it is built as a non-PIC
833-# DSO. To workaround that, we run chcon to libjvm.so after it is built. See
834-# details in bug 6538311.
835 $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE) $(LD_SCRIPT)
836        $(QUIETLY) {                                                    \
837            echo Linking vm...;                                         \
838@@ -188,15 +187,6 @@ $(LIBJVM): $(LIBJVM.o) $(LIBJVM_MAPFILE)
839                       $(LFLAGS_VM) -o $@ $(LIBJVM.o) $(LIBS_VM);       \
840            $(LINK_LIB.CC/POST_HOOK)                                    \
841            rm -f $@.1; ln -s $@ $@.1;                                  \
842-           if [ -x /usr/sbin/sebsdenabled ] ; then                   \
843-             /usr/sbin/sebsdenabled;                                 \
844-              if [ $$? = 0 ] ; then                                    \
845-               /usr/bin/chcon -t textrel_shlib_t $@;                   \
846-               if [ $$? != 0 ]; then                                   \
847-                 echo "ERROR: Cannot chcon $@"; exit 1;                \
848-               fi                                                      \
849-             fi                                                        \
850-           fi                                                          \
851        }
852 
853 DEST_JVM = $(JDK_LIBDIR)/$(VM_SUBDIR)/$(LIBJVM)
854diff -upr ../orig/hotspot/build/bsd/platform_amd64 ./hotspot/build/bsd/platform_amd64
855--- ../orig/hotspot/build/bsd/platform_amd64    2009-05-04 18:32:15.000000000 -0400
856+++ ./hotspot/build/bsd/platform_amd64  2009-05-04 17:37:17.000000000 -0400
857@@ -12,6 +12,4 @@ lib_arch = amd64
858 
859 compiler = gcc
860 
861-gnu_dis_arch = amd64
862-
863-sysdefs = -DLINUX -D_GNU_SOURCE -DAMD64
864+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DAMD64
865diff -upr ../orig/hotspot/build/bsd/platform_i486 ./hotspot/build/bsd/platform_i486
866--- ../orig/hotspot/build/bsd/platform_i486     2009-05-04 18:32:15.000000000 -0400
867+++ ./hotspot/build/bsd/platform_i486   2009-05-04 17:37:17.000000000 -0400
868@@ -12,6 +12,4 @@ lib_arch = i386
869 
870 compiler = gcc
871 
872-gnu_dis_arch = i386
873-
874-sysdefs = -DLINUX -D_GNU_SOURCE -DIA32
875+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DIA32
876diff -upr ../orig/hotspot/build/bsd/platform_sparc ./hotspot/build/bsd/platform_sparc
877--- ../orig/hotspot/build/bsd/platform_sparc    2009-05-04 18:32:15.000000000 -0400
878+++ ./hotspot/build/bsd/platform_sparc  2009-05-04 17:37:15.000000000 -0400
879@@ -12,6 +12,6 @@ lib_arch = sparc
880 
881 compiler = gcc
882 
883-gnu_dis_arch = sparc
884+sysdefs = -D_ALLBSD_SOURCE -D_GNU_SOURCE -DSPARC
885 
886 sysdefs = -DLINUX -D_GNU_SOURCE -DSPARC
887diff -upr ../orig/hotspot/make/Makefile ./hotspot/make/Makefile
888--- ../orig/hotspot/make/Makefile       2009-01-27 15:40:59.000000000 -0500
889+++ ./hotspot/make/Makefile     2009-05-04 17:37:15.000000000 -0400
890@@ -262,6 +262,19 @@ endif
891 
892 # Shared Library
893 ifneq ($(OSNAME),windows)
894+ifeq ($(OSNAME),bsd)
895+# BSD-specific LIBRARY_SUFFIX build option
896+$(EXPORT_JRE_LIB_ARCH_DIR)/%.$(LIBRARY_SUFFIX): $(C2_DIR)/%.$(LIBRARY_SUFFIX)
897+       $(install-file)
898+$(EXPORT_CLIENT_DIR)/%.$(LIBRARY_SUFFIX):       $(C1_DIR)/%.$(LIBRARY_SUFFIX)
899+       $(install-file)
900+$(EXPORT_CLIENT_DIR)/64/%.$(LIBRARY_SUFFIX):    $(C1_DIR)/%.$(LIBRARY_SUFFIX)
901+       $(install-file)
902+$(EXPORT_SERVER_DIR)/%.$(LIBRARY_SUFFIX):       $(C2_DIR)/%.$(LIBRARY_SUFFIX)
903+       $(install-file)
904+$(EXPORT_SERVER_DIR)/64/%.$(LIBRARY_SUFFIX):    $(C2_DIR)/%.$(LIBRARY_SUFFIX)
905+       $(install-file)
906+else
907 $(EXPORT_JRE_LIB_ARCH_DIR)/%.so: $(C2_DIR)/%.so
908        $(install-file)
909 $(EXPORT_CLIENT_DIR)/%.so:       $(C1_DIR)/%.so
910@@ -273,6 +286,7 @@ $(EXPORT_SERVER_DIR)/%.so:       $(C2_DI
911 $(EXPORT_SERVER_DIR)/64/%.so:    $(C2_DIR)/%.so
912        $(install-file)
913 endif
914+endif
915 
916 # Jar file (sa-jdi.jar)
917 $(EXPORT_LIB_DIR)/%.jar: $(GEN_DIR)/%.jar
918diff -upr ../orig/hotspot/make/defs.make ./hotspot/make/defs.make
919--- ../orig/hotspot/make/defs.make      2009-01-27 15:40:59.000000000 -0500
920+++ ./hotspot/make/defs.make    2009-05-04 17:37:15.000000000 -0400
921@@ -118,13 +118,23 @@ endif
922 # Windows should have OS predefined
923 ifeq ($(OS),)
924   OS   := $(shell uname -s)
925+  ifneq ($(findstring BSD,$(OS)),)
926+    OS=bsd
927+  endif
928+  ifeq ($(OS), Darwin)
929+    OS=bsd
930+  endif
931   HOST := $(shell uname -n)
932 endif
933 
934-# If not SunOS and not Linux, assume Windows
935+# If not SunOS, not Linux and not BSD, assume Windows
936 ifneq ($(OS), Linux)
937   ifneq ($(OS), SunOS)
938-    OSNAME=windows
939+    ifneq ($(OS), bsd)
940+      OSNAME=windows
941+    else
942+      OSNAME=bsd
943+    endif
944   else
945     OSNAME=solaris
946   endif
947diff -upr ../orig/hotspot/src/cpu/x86/vm/interpreterRT_x86_32.cpp ./hotspot/src/cpu/x86/vm/interpreterRT_x86_32.cpp
948--- ../orig/hotspot/src/cpu/x86/vm/interpreterRT_x86_32.cpp     2009-01-27 15:41:00.000000000 -0500
949+++ ./hotspot/src/cpu/x86/vm/interpreterRT_x86_32.cpp   2009-05-04 17:37:17.000000000 -0400
950@@ -57,7 +57,7 @@ void InterpreterRuntime::SignatureHandle
951   __ cmpl(Address(from(), Interpreter::local_offset_in_bytes(from_offset)), 0); // do not use temp() to avoid AGI
952   Label L;
953   __ jcc(Assembler::notZero, L);
954-  __ movl(temp(), 0);
955+  __ movl(temp(), NULL_WORD);
956   __ bind(L);
957   __ movl(Address(to(), to_offset * wordSize), temp());
958 }
959@@ -113,7 +113,7 @@ class SlowSignatureHandler: public Nativ
960   virtual void pass_object() {
961     // pass address of from
962     intptr_t from_addr = (intptr_t)(_from + Interpreter::local_offset_in_bytes(0));
963-    *_to++ = (*(intptr_t*)from_addr == 0) ? NULL : from_addr;
964+    *_to++ = (*(intptr_t*)from_addr == 0) ? NULL_WORD : from_addr;
965     debug_only(verify_tag(frame::TagReference));
966     _from -= Interpreter::stackElementSize();
967    }
968diff -upr ../orig/hotspot/src/cpu/x86/vm/jni_x86.h ./hotspot/src/cpu/x86/vm/jni_x86.h
969--- ../orig/hotspot/src/cpu/x86/vm/jni_x86.h    2009-01-27 15:41:00.000000000 -0500
970+++ ./hotspot/src/cpu/x86/vm/jni_x86.h  2009-05-04 17:37:15.000000000 -0400
971@@ -29,7 +29,7 @@
972 #ifndef _JAVASOFT_JNI_MD_H_
973 #define _JAVASOFT_JNI_MD_H_
974 
975-#if defined(SOLARIS) || defined(LINUX)
976+#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)
977   #define JNIEXPORT
978   #define JNIIMPORT
979   #define JNICALL
980diff -upr ../orig/hotspot/src/cpu/x86/vm/runtime_x86_32.cpp ./hotspot/src/cpu/x86/vm/runtime_x86_32.cpp
981--- ../orig/hotspot/src/cpu/x86/vm/runtime_x86_32.cpp   2009-01-27 15:41:00.000000000 -0500
982+++ ./hotspot/src/cpu/x86/vm/runtime_x86_32.cpp 2009-05-04 17:37:17.000000000 -0400
983@@ -132,11 +132,11 @@ void OptoRuntime::generate_exception_blo
984   // Get the exception pc in case we are deoptimized
985   __ movl(rdx, Address(rcx, JavaThread::exception_pc_offset()));
986 #ifdef ASSERT
987-  __ movl(Address(rcx, JavaThread::exception_handler_pc_offset()), 0);
988-  __ movl(Address(rcx, JavaThread::exception_pc_offset()), 0);
989+  __ movl(Address(rcx, JavaThread::exception_handler_pc_offset()), NULL_WORD);
990+  __ movl(Address(rcx, JavaThread::exception_pc_offset()), NULL_WORD);
991 #endif
992   // Clear the exception oop so GC no longer processes it as a root.
993-  __ movl(Address(rcx, JavaThread::exception_oop_offset()), 0);
994+  __ movl(Address(rcx, JavaThread::exception_oop_offset()), NULL_WORD);
995 
996   __ popl(rcx);
997 
998diff -upr ../orig/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp ./hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp
999--- ../orig/hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp     2009-01-27 15:41:00.000000000 -0500
1000+++ ./hotspot/src/cpu/x86/vm/stubGenerator_x86_64.cpp   2009-05-05 16:01:30.000000000 -0400
1001@@ -472,7 +472,7 @@ class StubGenerator: public StubCodeGene
1002     // setup rax & rdx, remove return address & clear pending exception
1003     __ popq(rdx);
1004     __ movq(rax, Address(r15_thread, Thread::pending_exception_offset()));
1005-    __ movptr(Address(r15_thread, Thread::pending_exception_offset()), (int)NULL_WORD);
1006+    __ movptr(Address(r15_thread, Thread::pending_exception_offset()), (int32_t)NULL_WORD);
1007 
1008 #ifdef ASSERT
1009     // make sure exception is set
1010@@ -941,9 +941,9 @@ class StubGenerator: public StubCodeGene
1011     __ jcc(Assembler::zero, exit); // if obj is NULL it is OK
1012     // Check if the oop is in the right area of memory
1013     __ movq(c_rarg2, rax);
1014-    __ movptr(c_rarg3, (int64_t) Universe::verify_oop_mask());
1015+    __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_mask());
1016     __ andq(c_rarg2, c_rarg3);
1017-    __ movptr(c_rarg3, (int64_t) Universe::verify_oop_bits());
1018+    __ movptr(c_rarg3, (intptr_t) Universe::verify_oop_bits());
1019     __ cmpq(c_rarg2, c_rarg3);
1020     __ jcc(Assembler::notZero, error);
1021 
1022@@ -953,9 +953,9 @@ class StubGenerator: public StubCodeGene
1023     __ jcc(Assembler::zero, error); // if klass is NULL it is broken
1024     // Check if the klass is in the right area of memory
1025     __ movq(c_rarg2, rax);
1026-    __ movptr(c_rarg3, (int64_t) Universe::verify_klass_mask());
1027+    __ movptr(c_rarg3, (intptr_t) Universe::verify_klass_mask());
1028     __ andq(c_rarg2, c_rarg3);
1029-    __ movptr(c_rarg3, (int64_t) Universe::verify_klass_bits());
1030+    __ movptr(c_rarg3, (intptr_t) Universe::verify_klass_bits());
1031     __ cmpq(c_rarg2, c_rarg3);
1032     __ jcc(Assembler::notZero, error);
1033 
1034@@ -964,9 +964,9 @@ class StubGenerator: public StubCodeGene
1035     __ testq(rax, rax);
1036     __ jcc(Assembler::zero, error); // if klass' klass is NULL it is broken
1037     // Check if the klass' klass is in the right area of memory
1038-    __ movptr(c_rarg3, (int64_t) Universe::verify_klass_mask());
1039+    __ movptr(c_rarg3, (intptr_t) Universe::verify_klass_mask());
1040     __ andq(rax, c_rarg3);
1041-    __ movptr(c_rarg3, (int64_t) Universe::verify_klass_bits());
1042+    __ movptr(c_rarg3, (intptr_t) Universe::verify_klass_bits());
1043     __ cmpq(rax, c_rarg3);
1044     __ jcc(Assembler::notZero, error);
1045 
1046diff -upr ../orig/hotspot/src/cpu/x86/vm/x86_32.ad ./hotspot/src/cpu/x86/vm/x86_32.ad
1047--- ../orig/hotspot/src/cpu/x86/vm/x86_32.ad    2009-01-27 15:41:00.000000000 -0500
1048+++ ./hotspot/src/cpu/x86/vm/x86_32.ad  2009-05-04 17:37:17.000000000 -0400
1049@@ -3364,7 +3364,7 @@ encode %{
1050          masm.movl  (Address(boxReg, 0), 3) ;            // results in ST-before-CAS penalty
1051          masm.get_thread (scrReg) ;
1052          masm.movl  (boxReg, tmpReg);                    // consider: LEA box, [tmp-2]
1053-         masm.movl  (tmpReg, 0);                         // consider: xor vs mov
1054+         masm.movl  (tmpReg, NULL_WORD);                         // consider: xor vs mov
1055          if (os::is_MP()) { masm.lock(); }
1056          masm.cmpxchg (scrReg, Address(boxReg, ObjectMonitor::owner_offset_in_bytes()-2)) ;
1057       } else
1058@@ -3383,7 +3383,7 @@ encode %{
1059 
1060          if ((EmitSync & 64) == 0) {
1061            // Optimistic form: consider XORL tmpReg,tmpReg
1062-           masm.movl  (tmpReg, 0 ) ;
1063+           masm.movl  (tmpReg, NULL_WORD ) ;
1064          } else {
1065            // Can suffer RTS->RTO upgrades on shared or cold $ lines
1066            // Test-And-CAS instead of CAS
1067@@ -3589,7 +3589,7 @@ encode %{
1068          masm.orl   (boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ;
1069          masm.orl   (boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ;
1070          masm.jccb  (Assembler::notZero, DONE_LABEL) ;
1071-         masm.movl  (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), 0) ;
1072+         masm.movl  (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ;
1073          masm.jmpb  (DONE_LABEL) ;
1074       } else {
1075          masm.xorl  (boxReg, Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2)) ; 
1076@@ -3598,7 +3598,7 @@ encode %{
1077          masm.movl  (boxReg, Address (tmpReg, ObjectMonitor::EntryList_offset_in_bytes()-2)) ;
1078          masm.orl   (boxReg, Address (tmpReg, ObjectMonitor::cxq_offset_in_bytes()-2)) ;
1079          masm.jccb  (Assembler::notZero, CheckSucc) ;
1080-         masm.movl  (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), 0) ;
1081+         masm.movl  (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ;
1082          masm.jmpb  (DONE_LABEL) ;
1083       }
1084 
1085@@ -3646,7 +3646,7 @@ encode %{
1086          // We currently use (3), although it's likely that switching to (2)
1087          // is correct for the future.
1088             
1089-         masm.movl  (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), 0) ;
1090+         masm.movl  (Address (tmpReg, ObjectMonitor::owner_offset_in_bytes()-2), NULL_WORD) ;
1091          if (os::is_MP()) {
1092             if (VM_Version::supports_sse2() && 1 == FenceInstruction) {
1093               masm.emit_raw (0x0F) ;    // MFENCE ...
1094diff -upr ../orig/hotspot/src/os/bsd/launcher/java_md.c ./hotspot/src/os/bsd/launcher/java_md.c
1095--- ../orig/hotspot/src/os/bsd/launcher/java_md.c       2009-05-04 18:32:15.000000000 -0400
1096+++ ./hotspot/src/os/bsd/launcher/java_md.c     2009-05-05 17:57:18.000000000 -0400
1097@@ -45,8 +45,15 @@
1098 #include "version_comp.h"
1099 #endif
1100 
1101+#ifdef __APPLE__
1102+#define JVM_DLL "libjvm.dylib"
1103+#define JAVA_DLL "libjava.dylib"
1104+#define LD_LIBRARY_PATH "DYLD_LIBRARY_PATH"
1105+#else
1106 #define JVM_DLL "libjvm.so"
1107 #define JAVA_DLL "libjava.so"
1108+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
1109+#endif
1110 
1111 #ifndef GAMMA   /* launcher.make defines ARCH */
1112 
1113@@ -112,7 +119,7 @@ extern char **environ;
1114  *      A collection of useful strings. One should think of these as #define
1115  *      entries, but actual strings can be more efficient (with many compilers).
1116  */
1117-#ifdef __bsd__
1118+#ifdef _ALLBSD_SOURCE
1119 static const char *system_dir  = "/usr/java";
1120 static const char *user_dir    = "/java";
1121 #else /* Solaris */
1122@@ -456,10 +463,10 @@ CreateExecutionEnvironment(int *_argcp,
1123        * If not on Solaris, assume only a single LD_LIBRARY_PATH
1124        * variable.
1125        */
1126-      runpath = getenv("LD_LIBRARY_PATH");
1127+      runpath = getenv(LD_LIBRARY_PATH);
1128 #endif /* __sun */
1129 
1130-#ifdef __bsd
1131+#ifdef _ALLBSD_SOURCE
1132       /*
1133        * On bsd, if a binary is running as sgid or suid, glibc sets
1134        * LD_LIBRARY_PATH to the empty string for security purposes.  (In
1135@@ -836,7 +843,7 @@ GetXUsagePath(char *buf, jint bufsize)
1136 jboolean
1137 GetApplicationHome(char *buf, jint bufsize)
1138 {
1139-#ifdef __bsd__
1140+#ifdef _ALLBSD_SOURCE
1141     char *execname = GetExecname();
1142     if (execname) {
1143        strncpy(buf, execname, bufsize-1);
1144@@ -1005,7 +1012,7 @@ SetExecname(char **argv)
1145            }
1146         }
1147     }
1148-#elif defined(__bsd__)
1149+#elif defined(__linux__)
1150     {
1151        const char* self = "/proc/self/exe";
1152         char buf[PATH_MAX+1];
1153@@ -1015,7 +1022,7 @@ SetExecname(char **argv)
1154            exec_path = strdup(buf);
1155        }
1156     }
1157-#else /* !__sun && !__bsd */
1158+#else /* !__sun && !__linux */
1159     {
1160         /* Not implemented */
1161     }
1162@@ -1220,7 +1227,7 @@ get_cpuid(uint32_t arg,
1163 
1164 #endif /* __sun && i586 */
1165 
1166-#if defined(__bsd__) && defined(i586)
1167+#if defined(_ALLBSD_SOURCE) && defined(i586)
1168 
1169 /*
1170  * A utility method for asking the CPU about itself.
1171@@ -1286,7 +1293,7 @@ get_cpuid(uint32_t arg,
1172 #endif
1173 }
1174 
1175-#endif /* __bsd__ && i586 */
1176+#endif /* _ALLBSD_SOURCE && i586 */
1177 
1178 #ifdef i586
1179 /*
1180@@ -1465,7 +1472,7 @@ solaris_i586_ServerClassMachine(void) {
1181 
1182 #endif /* __sun && i586 */
1183 
1184-#if defined(__bsd__) && defined(i586)
1185+#if defined(_ALLBSD_SOURCE) && defined(i586)
1186 
1187 /* The definition of a server-class machine for bsd-i586 */
1188 jboolean
1189@@ -1496,7 +1503,7 @@ bsd_i586_ServerClassMachine(void) {
1190   return result;
1191 }
1192 
1193-#endif /* __bsd__ && i586 */
1194+#endif /* _ALLBSD_SOURCE && i586 */
1195 
1196 /* Dispatch to the platform-specific definition of "server-class" */
1197 jboolean
1198@@ -1506,7 +1513,7 @@ ServerClassMachine(void) {
1199   result = solaris_sparc_ServerClassMachine();
1200 #elif defined(__sun) && defined(i586)
1201   result = solaris_i586_ServerClassMachine();
1202-#elif defined(__bsd__) && defined(i586)
1203+#elif defined(_ALLBSD_SOURCE) && defined(i586)
1204   result = bsd_i586_ServerClassMachine();
1205 #else
1206   if (_launcher_debug) {
1207diff -upr ../orig/hotspot/src/os/bsd/vm/attachListener_bsd.cpp ./hotspot/src/os/bsd/vm/attachListener_bsd.cpp
1208--- ../orig/hotspot/src/os/bsd/vm/attachListener_bsd.cpp        2009-05-04 18:32:15.000000000 -0400
1209+++ ./hotspot/src/os/bsd/vm/attachListener_bsd.cpp      2009-05-05 17:58:29.000000000 -0400
1210@@ -333,6 +333,15 @@ BsdAttachOperation* BsdAttachListener::d
1211 
1212     // get the credentials of the peer and check the effective uid/guid
1213     // - check with jeff on this.
1214+#ifdef _ALLBSD_SOURCE
1215+    uid_t puid;
1216+    gid_t pgid;
1217+    if (::getpeereid(s, &puid, &pgid) != 0) {
1218+      int res;
1219+      RESTARTABLE(::close(s), res);
1220+      continue;
1221+    }
1222+#else
1223     struct ucred cred_info;
1224     socklen_t optlen = sizeof(cred_info);
1225     if (::getsockopt(s, SOL_SOCKET, SO_PEERCRED, (void*)&cred_info, &optlen) == -1) {
1226@@ -340,10 +349,13 @@ BsdAttachOperation* BsdAttachListener::d
1227       RESTARTABLE(::close(s), res);
1228       continue;
1229     }
1230+    uid_t puid = cred_info.uid;
1231+    gid_t pgid = cred_info.gid;
1232+#endif
1233     uid_t euid = geteuid();
1234     gid_t egid = getegid();
1235 
1236-    if (cred_info.uid != euid || cred_info.gid != egid) {
1237+    if (puid != euid || pgid != egid) {
1238       int res;
1239       RESTARTABLE(::close(s), res);
1240       continue;
1241@@ -466,11 +478,11 @@ bool AttachListener::is_init_trigger() {
1242   char fn[32];
1243   sprintf(fn, ".attach_pid%d", os::current_process_id());
1244   int ret;
1245-  struct stat64 st;
1246-  RESTARTABLE(::stat64(fn, &st), ret);
1247+  struct stat st;
1248+  RESTARTABLE(::stat(fn, &st), ret);
1249   if (ret == -1) {
1250     sprintf(fn, "/tmp/.attach_pid%d", os::current_process_id());
1251-    RESTARTABLE(::stat64(fn, &st), ret);
1252+    RESTARTABLE(::stat(fn, &st), ret);
1253   }
1254   if (ret == 0) {
1255     // simple check to avoid starting the attach mechanism when
1256Only in ./hotspot/src/os/bsd/vm: dtraceJSDT_bsd.cpp
1257diff -upr ../orig/hotspot/src/os/bsd/vm/hpi_bsd.cpp ./hotspot/src/os/bsd/vm/hpi_bsd.cpp
1258--- ../orig/hotspot/src/os/bsd/vm/hpi_bsd.cpp   2009-05-04 18:32:15.000000000 -0400
1259+++ ./hotspot/src/os/bsd/vm/hpi_bsd.cpp 2009-05-05 18:00:58.000000000 -0400
1260@@ -31,6 +31,14 @@
1261 # include <sys/param.h>
1262 # include <dlfcn.h>
1263 
1264+#ifdef __APPLE__
1265+#define HPI_LIB "libhpi.dylib"
1266+#define HPI_G_LIB "libhpi.dylib"
1267+#else
1268+#define HPI_LIB "libhpi.so"
1269+#define HPI_G_LIB "libhpi.so"
1270+#endif
1271+
1272 typedef jint (JNICALL *init_t)(GetInterfaceFunc *, void *);
1273 
1274 void hpi::initialize_get_interface(vm_calls_t *callbacks) {
1275@@ -48,11 +56,11 @@ void hpi::initialize_get_interface(vm_ca
1276       os::jvm_path(buf, JVM_MAXPATHLEN);
1277       
1278 #ifdef PRODUCT
1279-      const char * hpi_lib = "/libhpi.so";
1280+      const char * hpi_lib = "/" HPI_LIB;
1281 #else
1282       char * ptr = strrchr(buf, '/');
1283       assert(strstr(ptr, "/libjvm") == ptr, "invalid library name");
1284-      const char * hpi_lib = strstr(ptr, "_g") ? "/libhpi_g.so" : "/libhpi.so";
1285+      const char * hpi_lib = strstr(ptr, "_g") ? "/" HPI_G_LIB : "/" HPI_LIB;
1286 #endif
1287 
1288       *(strrchr(buf, '/')) = '\0';  /* get rid of /libjvm.so */
1289diff -upr ../orig/hotspot/src/os/bsd/vm/hpi_bsd.hpp ./hotspot/src/os/bsd/vm/hpi_bsd.hpp
1290--- ../orig/hotspot/src/os/bsd/vm/hpi_bsd.hpp   2009-05-04 18:32:15.000000000 -0400
1291+++ ./hotspot/src/os/bsd/vm/hpi_bsd.hpp 2009-05-05 18:12:24.000000000 -0400
1292@@ -39,26 +39,22 @@
1293 // HPI_FileInterface
1294 
1295 inline int hpi::close(int fd) {
1296-  return ::close(fd);
1297+  RESTARTABLE_RETURN_INT(::close(fd));
1298 }
1299 
1300 inline size_t hpi::read(int fd, void *buf, unsigned int nBytes) {
1301-  size_t res;
1302-  RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res);
1303-  return res;
1304+  INTERRUPTIBLE_RETURN_INT(::read(fd, buf, (size_t) nBytes), os::Bsd::clear_interrupted);
1305 }
1306 
1307 inline size_t hpi::write(int fd, const void *buf, unsigned int nBytes) {
1308-  size_t res;
1309-  RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res);
1310-  return res;
1311+  INTERRUPTIBLE_RETURN_INT(::write(fd, buf, (size_t) nBytes), os::Bsd::clear_interrupted);
1312 }
1313 
1314 
1315 // HPI_SocketInterface
1316 
1317 inline int hpi::socket_close(int fd) {
1318-  return ::close(fd);
1319+  RESTARTABLE_RETURN_INT(::close(fd));
1320 }
1321 
1322 inline int hpi::socket(int domain, int type, int protocol) {
1323@@ -66,11 +62,11 @@ inline int hpi::socket(int domain, int t
1324 }
1325 
1326 inline int hpi::recv(int fd, char *buf, int nBytes, int flags) {
1327-  RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags));
1328+  INTERRUPTIBLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags), os::Bsd::clear_interrupted);
1329 }
1330 
1331 inline int hpi::send(int fd, char *buf, int nBytes, int flags) {
1332-  RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags));
1333+  INTERRUPTIBLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags), os::Bsd::clear_interrupted);
1334 }
1335 
1336 inline int hpi::timeout(int fd, long timeout) {
1337@@ -81,12 +77,13 @@ inline int hpi::timeout(int fd, long tim
1338   prevtime = ((julong)t.tv_sec * 1000)  +  t.tv_usec / 1000;
1339 
1340   for(;;) {
1341+    int res;
1342     struct pollfd pfd;
1343 
1344     pfd.fd = fd;
1345     pfd.events = POLLIN | POLLERR;
1346   
1347-    int res = ::poll(&pfd, 1, timeout);
1348+    INTERRUPTIBLE_NORESTART(::poll(&pfd, 1, timeout), res, os::Bsd::clear_interrupted);
1349 
1350     if (res == OS_ERR && errno == EINTR) {
1351 
1352@@ -110,7 +107,26 @@ inline int hpi::listen(int fd, int count
1353 }
1354 
1355 inline int hpi::connect(int fd, struct sockaddr *him, int len) {
1356-  RESTARTABLE_RETURN_INT(::connect(fd, him, len));
1357+  do {
1358+    int _result;
1359+    INTERRUPTIBLE_NORESTART(::connect(fd, him, len), _result,
1360+                           os::Bsd::clear_interrupted);
1361+
1362+    // Depending on when thread interruption is reset, _result could be
1363+    // one of two values when errno == EINTR
1364+
1365+    if (((_result == OS_INTRPT) || (_result == OS_ERR)) && (errno == EINTR)) {
1366+      /* restarting a connect() changes its errno semantics */
1367+      INTERRUPTIBLE(::connect(fd, him, len), _result,
1368+                     os::Bsd::clear_interrupted);
1369+      /* undo these changes */
1370+      if (_result == OS_ERR) {
1371+       if (errno == EALREADY) errno = EINPROGRESS; /* fall through */
1372+       else if (errno == EISCONN) { errno = 0; return OS_OK; }
1373+      }
1374+    }
1375+    return _result;
1376+  } while(false);
1377 }
1378 
1379 inline int hpi::accept(int fd, struct sockaddr *him, int *len) {
1380@@ -121,26 +137,33 @@ inline int hpi::accept(int fd, struct so
1381   // to 64 bits on some platform that we support.
1382   // Bsd doc says this can't return EINTR, unlike accept() on Solaris
1383 
1384-  return ::accept(fd, him, (socklen_t *)len);
1385+  if (fd < 0)
1386+    return OS_ERR;
1387+  INTERRUPTIBLE_RETURN_INT((int)::accept(fd, him, (socklen_t*) len), os::Bsd::clear_interrupted);
1388 }
1389 
1390 inline int hpi::recvfrom(int fd, char *buf, int nBytes, int flags,
1391                         sockaddr *from, int *fromlen) {
1392-  RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen));
1393+  INTERRUPTIBLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen), os::Bsd::clear_interrupted);
1394 }
1395 
1396 inline int hpi::sendto(int fd, char *buf, int len, int flags,
1397                        struct sockaddr *to, int tolen) {
1398-  RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen));
1399+  INTERRUPTIBLE_RETURN_INT((int)::sendto(fd, buf, len, (unsigned int) flags, to, tolen),os::Bsd::clear_interrupted);
1400 }
1401 
1402 inline int hpi::socket_available(int fd, jint *pbytes) {
1403   // Bsd doc says EINTR not returned, unlike Solaris
1404-  int ret = ::ioctl(fd, FIONREAD, pbytes);
1405+  int ret;
1406+
1407+  if (fd < 0)
1408+    return OS_OK;
1409+
1410+  RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret);
1411 
1412   //%% note ioctl can return 0 when successful, JVM_SocketAvailable
1413   // is expected to return 0 on failure and 1 on success to the jdk.
1414-  return (ret < 0) ? 0 : 1;
1415+  return (ret == OS_ERR) ? 0 : 1;
1416 }
1417 
1418 
1419@@ -167,7 +190,7 @@ HPIDECL(bind, "bind", _socket, Bind,
1420         (fd, him, len));
1421 */
1422 inline int hpi::bind(int fd, struct sockaddr *him, int len){
1423-  return ::bind(fd, him, len);
1424+  INTERRUPTIBLE_RETURN_INT_NORESTART(::bind(fd, him, len),os::Bsd::clear_interrupted);
1425 }
1426 
1427 /*
1428diff -upr ../orig/hotspot/src/os/bsd/vm/jsig.c ./hotspot/src/os/bsd/vm/jsig.c
1429--- ../orig/hotspot/src/os/bsd/vm/jsig.c        2009-05-04 18:32:15.000000000 -0400
1430+++ ./hotspot/src/os/bsd/vm/jsig.c      2009-05-04 17:37:15.000000000 -0400
1431@@ -146,7 +146,8 @@ sa_handler_t signal(int sig, sa_handler_
1432 }
1433 
1434 sa_handler_t sigset(int sig, sa_handler_t disp) {
1435-  return set_signal(sig, disp, true);
1436+  printf("sigset() is not supported by BSD");
1437+  exit(0);
1438  }
1439 
1440 static int call_os_sigaction(int sig, const struct sigaction  *act,
1441diff -upr ../orig/hotspot/src/os/bsd/vm/jvm_bsd.cpp ./hotspot/src/os/bsd/vm/jvm_bsd.cpp
1442--- ../orig/hotspot/src/os/bsd/vm/jvm_bsd.cpp   2009-05-04 18:32:15.000000000 -0400
1443+++ ./hotspot/src/os/bsd/vm/jvm_bsd.cpp 2009-05-05 18:16:36.000000000 -0400
1444@@ -141,44 +141,37 @@ struct siglabel {
1445 
1446 struct siglabel siglabels[] = {
1447   /* derived from /usr/include/bits/signum.h on RH7.2 */
1448-   "HUP",      SIGHUP,         /* Hangup (POSIX).  */
1449+  "HUP",       SIGHUP,         /* Hangup (POSIX).  */
1450   "INT",       SIGINT,         /* Interrupt (ANSI).  */
1451   "QUIT",      SIGQUIT,        /* Quit (POSIX).  */
1452   "ILL",       SIGILL,         /* Illegal instruction (ANSI).  */
1453   "TRAP",      SIGTRAP,        /* Trace trap (POSIX).  */
1454   "ABRT",      SIGABRT,        /* Abort (ANSI).  */
1455-  "IOT",       SIGIOT,         /* IOT trap (4.2 BSD).  */
1456-  "BUS",       SIGBUS,         /* BUS error (4.2 BSD).  */
1457+  "EMT",       SIGEMT,         /* EMT trap  */
1458   "FPE",       SIGFPE,         /* Floating-point exception (ANSI).  */
1459   "KILL",      SIGKILL,        /* Kill, unblockable (POSIX).  */
1460-  "USR1",      SIGUSR1,        /* User-defined signal 1 (POSIX).  */
1461+  "BUS",       SIGBUS,         /* BUS error (4.2 BSD).  */
1462   "SEGV",      SIGSEGV,        /* Segmentation violation (ANSI).  */
1463-  "USR2",      SIGUSR2,        /* User-defined signal 2 (POSIX).  */
1464+  "SYS",       SIGSYS,         /* Bad system call. Only on some Bsden! */
1465   "PIPE",      SIGPIPE,        /* Broken pipe (POSIX).  */
1466   "ALRM",      SIGALRM,        /* Alarm clock (POSIX).  */
1467   "TERM",      SIGTERM,        /* Termination (ANSI).  */
1468-#ifdef SIGSTKFLT
1469-  "STKFLT",    SIGSTKFLT,      /* Stack fault.  */
1470-#endif
1471-  "CLD",       SIGCLD,         /* Same as SIGCHLD (System V).  */
1472-  "CHLD",      SIGCHLD,        /* Child status has changed (POSIX).  */
1473-  "CONT",      SIGCONT,        /* Continue (POSIX).  */
1474+  "URG",       SIGURG,         /* Urgent condition on socket (4.2 BSD).  */
1475   "STOP",      SIGSTOP,        /* Stop, unblockable (POSIX).  */
1476   "TSTP",      SIGTSTP,        /* Keyboard stop (POSIX).  */
1477+  "CONT",      SIGCONT,        /* Continue (POSIX).  */
1478+  "CHLD",      SIGCHLD,        /* Child status has changed (POSIX).  */
1479   "TTIN",      SIGTTIN,        /* Background read from tty (POSIX).  */
1480   "TTOU",      SIGTTOU,        /* Background write to tty (POSIX).  */
1481-  "URG",       SIGURG,         /* Urgent condition on socket (4.2 BSD).  */
1482+  "IO",                SIGIO,          /* I/O now possible (4.2 BSD).  */
1483   "XCPU",      SIGXCPU,        /* CPU limit exceeded (4.2 BSD).  */
1484   "XFSZ",      SIGXFSZ,        /* File size limit exceeded (4.2 BSD).  */
1485   "VTALRM",    SIGVTALRM,      /* Virtual alarm clock (4.2 BSD).  */
1486   "PROF",      SIGPROF,        /* Profiling alarm clock (4.2 BSD).  */
1487   "WINCH",     SIGWINCH,       /* Window size change (4.3 BSD, Sun).  */
1488-  "POLL",      SIGPOLL,        /* Pollable event occurred (System V).  */
1489-  "IO",                SIGIO,          /* I/O now possible (4.2 BSD).  */
1490-  "PWR",       SIGPWR,         /* Power failure restart (System V).  */
1491-#ifdef SIGSYS
1492-  "SYS",       SIGSYS          /* Bad system call. Only on some Bsden! */
1493-#endif
1494+  "INFO",      SIGINFO,        /* Information request.  */
1495+  "USR1",      SIGUSR1,        /* User-defined signal 1 (POSIX).  */
1496+  "USR2",      SIGUSR2         /* User-defined signal 2 (POSIX).  */
1497   };
1498 
1499 JVM_ENTRY_NO_ENV(jint, JVM_FindSignal(const char *name))
1500diff -upr ../orig/hotspot/src/os/bsd/vm/jvm_bsd.h ./hotspot/src/os/bsd/vm/jvm_bsd.h
1501--- ../orig/hotspot/src/os/bsd/vm/jvm_bsd.h     2009-05-04 18:32:15.000000000 -0400
1502+++ ./hotspot/src/os/bsd/vm/jvm_bsd.h   2009-05-05 18:16:44.000000000 -0400
1503@@ -54,7 +54,11 @@
1504 #define AGENT_ONATTACH_SYMBOLS  {"Agent_OnAttach"}
1505 
1506 #define JNI_LIB_PREFIX "lib"
1507+#ifdef __APPLE__
1508+#define JNI_LIB_SUFFIX ".dylib"
1509+#else
1510 #define JNI_LIB_SUFFIX ".so"
1511+#endif
1512 
1513 // Hack: MAXPATHLEN is 4095 on some Bsd and 4096 on others. This may
1514 //       cause problems if JVM and the rest of JDK are built on different
1515@@ -93,6 +97,20 @@
1516 #define SHUTDOWN2_SIGNAL SIGINT
1517 #define SHUTDOWN3_SIGNAL SIGTERM
1518 
1519+#ifndef SIGRTMIN
1520+#ifdef __OpenBSD__
1521+#define SIGRTMIN       1
1522+#else
1523+#define SIGRTMIN       33
1524+#endif
1525+#endif
1526+#ifndef SIGRTMAX
1527+#ifdef __OpenBSD__
1528+#define SIGRTMAX       31
1529+#else
1530+#define SIGRTMAX       63
1531+#endif
1532+#endif
1533 #endif /* JVM_MD_H */
1534 
1535 // Reconciliation History
1536diff -upr ../orig/hotspot/src/os/bsd/vm/osThread_bsd.cpp ./hotspot/src/os/bsd/vm/osThread_bsd.cpp
1537--- ../orig/hotspot/src/os/bsd/vm/osThread_bsd.cpp      2009-05-04 18:32:15.000000000 -0400
1538+++ ./hotspot/src/os/bsd/vm/osThread_bsd.cpp    2009-05-05 18:19:09.000000000 -0400
1539@@ -31,8 +31,8 @@
1540 
1541 void OSThread::pd_initialize() {
1542   assert(this != NULL, "check");
1543-  _thread_id        = 0;
1544-  _pthread_id       = 0;
1545+  _thread_id        = NULL;
1546+  _pthread_id       = NULL;
1547   _siginfo = NULL;
1548   _ucontext = NULL;
1549   _expanding_stack = 0;
1550diff -upr ../orig/hotspot/src/os/bsd/vm/osThread_bsd.hpp ./hotspot/src/os/bsd/vm/osThread_bsd.hpp
1551--- ../orig/hotspot/src/os/bsd/vm/osThread_bsd.hpp      2009-05-04 18:32:15.000000000 -0400
1552+++ ./hotspot/src/os/bsd/vm/osThread_bsd.hpp    2009-05-05 20:37:04.000000000 -0400
1553@@ -39,6 +39,12 @@
1554 
1555  private:
1556 
1557+#ifdef _ALLBSD_SOURCE
1558+  // _thread_id and _pthread_id are the same on BSD
1559+  // keep both to minimize code divergence in os_bsd.cpp
1560+  pthread_t _thread_id;
1561+  pthread_t _pthread_id;
1562+#else
1563   // _thread_id is kernel thread id (similar to LWP id on Solaris). Each
1564   // thread has a unique thread_id (BsdThreads or NPTL). It can be used
1565   // to access /proc.
1566@@ -47,6 +53,7 @@
1567   // _pthread_id is the pthread id, which is used by library calls
1568   // (e.g. pthread_kill).
1569   pthread_t _pthread_id;
1570+#endif
1571 
1572   sigset_t _caller_sigmask; // Caller's signal mask
1573 
1574@@ -56,12 +63,18 @@
1575   sigset_t  caller_sigmask() const       { return _caller_sigmask; }
1576   void    set_caller_sigmask(sigset_t sigmask)  { _caller_sigmask = sigmask; }
1577 
1578+#ifdef _ALLBSD_SOURCE
1579+  pthread_t thread_id() const {
1580+    return _thread_id;
1581+  }
1582+#else
1583   pid_t thread_id() const {
1584     return _thread_id;
1585   }
1586+#endif
1587 #ifndef PRODUCT
1588   // Used for debugging, return a unique integer for each thread.
1589-  int thread_identifier() const   { return _thread_id; }
1590+  intptr_t thread_identifier() const   { return (intptr_t)_pthread_id; }
1591 #endif
1592 #ifdef ASSERT
1593   // We expect no reposition failures so kill vm if we get one.
1594@@ -70,9 +83,15 @@
1595     return false;
1596   }
1597 #endif // ASSERT
1598+#ifdef _ALLBSD_SOURCE
1599+  void set_thread_id(pthread_t id) {
1600+    _thread_id = id;
1601+  }
1602+#else
1603   void set_thread_id(pid_t id) {
1604     _thread_id = id;
1605   }
1606+#endif
1607   pthread_t pthread_id() const {
1608     return _pthread_id;
1609   }
1610@@ -123,6 +142,9 @@ public:
1611 
1612 private:
1613   Monitor* _startThread_lock;     // sync parent and child in thread creation
1614+#ifdef _ALLBSD_SOURCE
1615+  JavaThreadState      _saved_interrupt_thread_state;       // the thread state before a system call -- restored afterward
1616+#endif
1617 
1618 public:
1619 
1620@@ -130,6 +152,11 @@ public:
1621     return _startThread_lock;
1622   }
1623 
1624+#ifdef _ALLBSD_SOURCE
1625+  JavaThreadState   saved_interrupt_thread_state()                              { return _saved_interrupt_thread_state; }
1626+  void              set_saved_interrupt_thread_state(JavaThreadState state)     { _saved_interrupt_thread_state = state; }
1627+#endif
1628+
1629   // ***************************************************************
1630   // Platform dependent initialization and cleanup
1631   // ***************************************************************
1632diff -upr ../orig/hotspot/src/os/bsd/vm/os_bsd.cpp ./hotspot/src/os/bsd/vm/os_bsd.cpp
1633--- ../orig/hotspot/src/os/bsd/vm/os_bsd.cpp    2009-05-04 18:32:15.000000000 -0400
1634+++ ./hotspot/src/os/bsd/vm/os_bsd.cpp  2009-05-04 17:37:17.000000000 -0400
1635@@ -50,12 +50,33 @@
1636 # include <semaphore.h>
1637 # include <fcntl.h>
1638 # include <string.h>
1639+#ifdef _ALLBSD_SOURCE
1640+# include <sys/param.h>
1641+# include <sys/sysctl.h>
1642+#else
1643 # include <syscall.h>
1644 # include <sys/sysinfo.h>
1645 # include <gnu/libc-version.h>
1646+#endif
1647 # include <sys/ipc.h>
1648 # include <sys/shm.h>
1649+
1650+#ifndef __APPLE__
1651 # include <link.h>
1652+#endif
1653+
1654+#if defined(__FreeBSD__)
1655+# include <elf.h>
1656+#endif
1657+
1658+#ifdef __APPLE__
1659+#include <mach/mach.h> // semaphore_* API
1660+#include <mach-o/dyld.h>
1661+#endif
1662+
1663+#ifndef MAP_ANONYMOUS
1664+#define MAP_ANONYMOUS MAP_ANON
1665+#endif
1666 
1667 #define MAX_PATH    (2 * K)
1668 
1669@@ -67,19 +88,25 @@
1670 // global variables
1671 julong os::Bsd::_physical_memory = 0;
1672 
1673+#ifndef _ALLBSD_SOURCE
1674 address   os::Bsd::_initial_thread_stack_bottom = NULL;
1675 uintptr_t os::Bsd::_initial_thread_stack_size   = 0;
1676+#endif
1677 
1678 int (*os::Bsd::_clock_gettime)(clockid_t, struct timespec *) = NULL;
1679+#ifndef _ALLBSD_SOURCE
1680 int (*os::Bsd::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL;
1681 Mutex* os::Bsd::_createThread_lock = NULL;
1682+#endif
1683 pthread_t os::Bsd::_main_thread;
1684 int os::Bsd::_page_size = -1;
1685+#ifndef _ALLBSD_SOURCE
1686 bool os::Bsd::_is_floating_stack = false;
1687 bool os::Bsd::_is_NPTL = false;
1688 bool os::Bsd::_supports_fast_thread_cpu_time = false;
1689 const char * os::Bsd::_glibc_version = NULL;
1690 const char * os::Bsd::_libpthread_version = NULL;
1691+#endif
1692 
1693 static jlong initial_time_count=0;
1694 
1695@@ -97,6 +124,77 @@ static pid_t _initial_pid = 0;
1696 static int SR_signum = SIGUSR2;
1697 sigset_t SR_sigset;
1698 
1699+#ifdef _ALLBSD_SOURCE
1700+// XXXBSD: ported from solaris version
1701+// interruptible infrastructure
1702+
1703+// setup_interruptible saves the thread state before going into an
1704+// interruptible system call. 
1705+// The saved state is used to restore the thread to
1706+// its former state whether or not an interrupt is received. 
1707+// Used by classloader os::read
1708+// hpi calls skip this layer and stay in _thread_in_native
1709+
1710+void os::Bsd::setup_interruptible(JavaThread* thread) {
1711+
1712+  JavaThreadState thread_state = thread->thread_state();
1713+
1714+  assert(thread_state != _thread_blocked, "Coming from the wrong thread");
1715+  assert(thread_state != _thread_in_native, "Native threads skip setup_interruptible");
1716+  OSThread* osthread = thread->osthread();
1717+  osthread->set_saved_interrupt_thread_state(thread_state);
1718+  thread->frame_anchor()->make_walkable(thread);
1719+  ThreadStateTransition::transition(thread, thread_state, _thread_blocked);
1720+}
1721+
1722+// Version of setup_interruptible() for threads that are already in
1723+// _thread_blocked. Used by os_sleep().
1724+void os::Bsd::setup_interruptible_already_blocked(JavaThread* thread) {
1725+  thread->frame_anchor()->make_walkable(thread);
1726+}
1727+
1728+JavaThread* os::Bsd::setup_interruptible() {
1729+  JavaThread* thread = (JavaThread*)ThreadLocalStorage::thread();
1730+  setup_interruptible(thread);
1731+  return thread;
1732+}
1733+
1734+#ifdef ASSERT
1735+
1736+JavaThread* os::Bsd::setup_interruptible_native() {
1737+  JavaThread* thread = (JavaThread*)ThreadLocalStorage::thread();
1738+  JavaThreadState thread_state = thread->thread_state();
1739+  assert(thread_state == _thread_in_native, "Assumed thread_in_native");
1740+  return thread;
1741+}
1742+
1743+void os::Bsd::cleanup_interruptible_native(JavaThread* thread) {
1744+  JavaThreadState thread_state = thread->thread_state();
1745+  assert(thread_state == _thread_in_native, "Assumed thread_in_native");
1746+}
1747+#endif
1748+
1749+// cleanup_interruptible reverses the effects of setup_interruptible
1750+// setup_interruptible_already_blocked() does not need any cleanup.
1751+
1752+void os::Bsd::cleanup_interruptible(JavaThread* thread) {
1753+  OSThread* osthread = thread->osthread();
1754+
1755+  ThreadStateTransition::transition(thread, _thread_blocked, osthread->saved_interrupt_thread_state());
1756+}
1757+
1758+// I/O interruption related counters called in _INTERRUPTIBLE
1759+
1760+void os::Bsd::bump_interrupted_before_count() {
1761+  RuntimeService::record_interrupted_before_count();
1762+}
1763+
1764+void os::Bsd::bump_interrupted_during_count() {
1765+  RuntimeService::record_interrupted_during_count();
1766+}
1767+#endif
1768+
1769+
1770 ////////////////////////////////////////////////////////////////////////////////
1771 // utility functions
1772 
1773@@ -108,11 +206,17 @@ julong os::available_memory() {
1774 }
1775 
1776 julong os::Bsd::available_memory() {
1777+#ifdef _ALLBSD_SOURCE
1778+  // XXXBSD: this is just a stopgap implementation
1779+  return physical_memory() >> 2;
1780+#else
1781+
1782   // values in struct sysinfo are "unsigned long"
1783   struct sysinfo si;
1784   sysinfo(&si);
1785   
1786   return (julong)si.freeram * si.mem_unit;
1787+#endif
1788 }
1789 
1790 julong os::physical_memory() {
1791@@ -160,6 +264,7 @@ bool os::have_special_privileges() {
1792 }
1793 
1794 
1795+#ifndef _ALLBSD_SOURCE
1796 #ifndef SYS_gettid
1797 // i386: 224, ia64: 1105, amd64: 186, sparc 143
1798 #ifdef __ia64__
1799@@ -174,6 +279,7 @@ bool os::have_special_privileges() {
1800 #error define gettid for the arch
1801 #endif
1802 #endif
1803+#endif
1804 
1805 // Cpu architecture string
1806 #if   defined(IA64)
1807@@ -193,6 +299,7 @@ static char cpu_arch[] = "sparc";
1808 #endif
1809 
1810 
1811+#ifndef _ALLBSD_SOURCE
1812 // pid_t gettid()
1813 //
1814 // Returns the kernel thread id of the currently running thread. Kernel
1815@@ -219,7 +326,47 @@ static bool unsafe_chroot_detected = fal
1816 static const char *unstable_chroot_error = "/proc file system not found.\n"
1817                     "Java may be unstable running multithreaded in a chroot "
1818                     "environment on Bsd when /proc filesystem is not mounted.";
1819+#endif
1820 
1821+#ifdef _ALLBSD_SOURCE
1822+void os::Bsd::initialize_system_info() {
1823+  int mib[2];
1824+  size_t len;
1825+  int cpu_val;
1826+  u_long mem_val;
1827+
1828+  /* get processors count via hw.ncpus sysctl */
1829+  mib[0] = CTL_HW;
1830+  mib[1] = HW_NCPU;
1831+  len = sizeof(cpu_val);
1832+  if (sysctl(mib, 2, &cpu_val, &len, NULL, 0) != -1)
1833+        _processor_count = cpu_val;
1834+
1835+  if (_processor_count < 1)
1836+       _processor_count = 1;   // fallback
1837+
1838+  /* get physical memory via hw.usermem sysctl (hw.usermem is used
1839+   * instead of hw.physmem because we need size of allocatable memory
1840+   */
1841+  mib[0] = CTL_HW;
1842+  mib[1] = HW_USERMEM;
1843+  len = sizeof(mem_val);
1844+  if (sysctl(mib, 2, &mem_val, &len, NULL, 0) != -1)
1845+       _physical_memory = mem_val;
1846+  else
1847+       _physical_memory = 256*1024*1024;       // fallback (XXXBSD?)
1848+
1849+#ifdef __OpenBSD__
1850+  {
1851+       // limit _physical_memory memory view on OpenBSD since
1852+       // datasize rlimit restricts us anyway.
1853+       struct rlimit limits;
1854+       getrlimit(RLIMIT_DATA, &limits);
1855+       _physical_memory = MIN2(_physical_memory, (julong)limits.rlim_cur);
1856+  }
1857+#endif
1858+}
1859+#else
1860 void os::Bsd::initialize_system_info() {
1861   _processor_count = sysconf(_SC_NPROCESSORS_CONF);
1862   if (_processor_count == 1) {
1863@@ -236,6 +383,7 @@ void os::Bsd::initialize_system_info() {
1864   _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE);
1865   assert(_processor_count > 0, "bsd error");
1866 }
1867+#endif
1868 
1869 void os::init_system_properties_values() {
1870 //  char arch[12];
1871@@ -356,7 +504,12 @@ void os::init_system_properties_values()
1872         * should always exist (until the legacy problem cited above is
1873         * addressed).
1874         */
1875+#ifdef __APPLE__
1876+   char *v = getenv("DYLD_LIBRARY_PATH");
1877+#else
1878        char *v = getenv("LD_LIBRARY_PATH");
1879+#endif
1880+         
1881        if (v != NULL) {
1882            char *t = ld_library_path;
1883            /* That's +1 for the colon and +1 for the trailing '\0' */
1884@@ -515,6 +668,7 @@ void os::Bsd::hotspot_sigmask(Thread* th
1885   }
1886 }
1887 
1888+#ifndef _ALLBSD_SOURCE
1889 //////////////////////////////////////////////////////////////////////////////
1890 // detecting pthread library
1891 
1892@@ -679,6 +833,7 @@ bool os::Bsd::manually_expand_stack(Java
1893   }
1894   return false;
1895 }
1896+#endif
1897 
1898 //////////////////////////////////////////////////////////////////////////////
1899 // create new thread
1900@@ -687,6 +842,9 @@ static address highest_vm_reserved_addre
1901 
1902 // check if it's safe to start a new thread
1903 static bool _thread_safety_check(Thread* thread) {
1904+#ifdef _ALLBSD_SOURCE
1905+  return true;
1906+#else
1907   if (os::Bsd::is_BsdThreads() && !os::Bsd::is_floating_stack()) {
1908     // Fixed stack BsdThreads (SuSE Bsd/x86, and some versions of Redhat)
1909     //   Heap is mmap'ed at lower end of memory space. Thread stacks are
1910@@ -720,6 +878,7 @@ static bool _thread_safety_check(Thread*
1911     //   here, that means enough space has been reserved for stack.
1912     return true;
1913   }
1914+#endif
1915 }
1916 
1917 // Thread start routine for all newly created threads
1918@@ -747,6 +906,10 @@ static void *java_start(Thread *thread)
1919     return NULL;
1920   }
1921 
1922+#ifdef _ALLBSD_SOURCE
1923+  // thread_id is pthread_id on BSD
1924+  osthread->set_thread_id(::pthread_self());
1925+#else
1926   // thread_id is kernel thread id (similar to Solaris LWP id)
1927   osthread->set_thread_id(os::Bsd::gettid());
1928 
1929@@ -756,6 +919,7 @@ static void *java_start(Thread *thread)
1930       thread->set_lgrp_id(lgrp_id);
1931     }
1932   }
1933+#endif
1934   // initialize signal mask for this thread
1935   os::Bsd::hotspot_sigmask(thread);
1936 
1937@@ -836,17 +1000,22 @@ bool os::create_thread(Thread* thread, T
1938     // let pthread_create() pick the default value.
1939   }
1940 
1941+#ifndef _ALLBSD_SOURCE
1942   // glibc guard page
1943   pthread_attr_setguardsize(&attr, os::Bsd::default_guard_size(thr_type));
1944+#endif
1945 
1946   ThreadState state;
1947 
1948   {
1949+
1950+#ifndef _ALLBSD_SOURCE
1951     // Serialize thread creation if we are running with fixed stack BsdThreads
1952     bool lock = os::Bsd::is_BsdThreads() && !os::Bsd::is_floating_stack();
1953     if (lock) {
1954       os::Bsd::createThread_lock()->lock_without_safepoint_check();
1955     }
1956+#endif
1957 
1958     pthread_t tid;
1959     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
1960@@ -860,7 +1029,9 @@ bool os::create_thread(Thread* thread, T
1961       // Need to clean up stuff we've allocated so far
1962       thread->set_osthread(NULL);
1963       delete osthread;
1964+#ifndef _ALLBSD_SOURCE
1965       if (lock) os::Bsd::createThread_lock()->unlock();
1966+#endif
1967       return false;
1968     }
1969 
1970@@ -876,9 +1047,11 @@ bool os::create_thread(Thread* thread, T
1971       }
1972     }
1973 
1974+#ifndef _ALLBSD_SOURCE
1975     if (lock) {
1976       os::Bsd::createThread_lock()->unlock();
1977     }
1978+#endif
1979   }
1980 
1981   // Aborted due to thread limit being reached
1982@@ -916,7 +1089,11 @@ bool os::create_attached_thread(JavaThre
1983   }
1984 
1985   // Store pthread info into the OSThread
1986+#ifdef _ALLBSD_SOURCE
1987+  osthread->set_thread_id(::pthread_self());
1988+#else
1989   osthread->set_thread_id(os::Bsd::gettid());
1990+#endif
1991   osthread->set_pthread_id(::pthread_self());
1992 
1993   // initialize floating point control register
1994@@ -927,6 +1104,7 @@ bool os::create_attached_thread(JavaThre
1995 
1996   thread->set_osthread(osthread);
1997 
1998+#ifndef _ALLBSD_SOURCE
1999   if (UseNUMA) {
2000     int lgrp_id = os::numa_get_group_id();
2001     if (lgrp_id != -1) {
2002@@ -953,6 +1131,7 @@ bool os::create_attached_thread(JavaThre
2003     os::Bsd::manually_expand_stack(jt, addr);
2004     osthread->clear_expanding_stack();
2005   }
2006+#endif
2007 
2008   // initialize signal mask for this thread
2009   // and save the caller's signal mask
2010@@ -1011,6 +1190,7 @@ extern "C" Thread* get_thread() {
2011 //////////////////////////////////////////////////////////////////////////////
2012 // initial thread
2013 
2014+#ifndef _ALLBSD_SOURCE
2015 // Check if current thread is the initial thread, similar to Solaris thr_main.
2016 bool os::Bsd::is_initial_thread(void) {
2017   char dummy;
2018@@ -1241,6 +1421,7 @@ void os::Bsd::capture_initial_stack(size
2019   _initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size());
2020   _initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size;
2021 }
2022+#endif
2023 
2024 ////////////////////////////////////////////////////////////////////////////////
2025 // time support
2026@@ -1279,6 +1460,21 @@ jlong os::javaTimeMillis() {
2027 #define CLOCK_MONOTONIC (1)
2028 #endif
2029 
2030+#ifdef __APPLE__
2031+void os::Bsd::clock_init() {
2032+       // XXXDARWIN: Investigate replacement monotonic clock
2033+}
2034+#elif defined(_ALLBSD_SOURCE)
2035+void os::Bsd::clock_init() {
2036+  struct timespec res;
2037+  struct timespec tp;
2038+  if (::clock_getres(CLOCK_MONOTONIC, &res) == 0 &&
2039+      ::clock_gettime(CLOCK_MONOTONIC, &tp)  == 0) {
2040+    // yes, monotonic clock is supported
2041+    _clock_gettime = ::clock_gettime;
2042+  }
2043+}
2044+#else
2045 void os::Bsd::clock_init() {
2046   // we do dlopen's in this particular order due to bug in bsd
2047   // dynamical loader (see 6348968) leading to crash on exit
2048@@ -1314,7 +1510,9 @@ void os::Bsd::clock_init() {
2049     }
2050   }
2051 }
2052+#endif
2053 
2054+#ifndef _ALLBSD_SOURCE
2055 #ifndef SYS_clock_getres
2056 
2057 #if defined(IA32) || defined(AMD64)
2058@@ -1353,6 +1551,7 @@ void os::Bsd::fast_thread_clock_init() {
2059     _pthread_getcpuclockid = pthread_getcpuclockid_func;
2060   }
2061 }
2062+#endif
2063 
2064 jlong os::javaTimeNanos() {
2065   if (Bsd::supports_monotonic_clock()) {
2066@@ -1499,7 +1698,14 @@ int os::current_process_id() {
2067 
2068 // DLL functions
2069 
2070-const char* os::dll_file_extension() { return ".so"; }
2071+#define JNI_LIB_PREFIX "lib"
2072+#ifdef __APPLE__
2073+#define JNI_LIB_SUFFIX ".dylib"
2074+#else
2075+#define JNI_LIB_SUFFIX ".so"
2076+#endif
2077+
2078+const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; }
2079 
2080 const char* os::get_temp_directory() { return "/tmp/"; }
2081 
2082@@ -1540,6 +1746,23 @@ bool os::dll_address_to_function_name(ad
2083   }
2084 }
2085 
2086+#ifdef _ALLBSD_SOURCE
2087+// ported from solaris version
2088+bool os::dll_address_to_library_name(address addr, char* buf,
2089+                                     int buflen, int* offset) {
2090+  Dl_info dlinfo;
2091+
2092+  if (dladdr((void*)addr, &dlinfo)){
2093+     if (buf) jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname);
2094+     if (offset) *offset = addr - (address)dlinfo.dli_fbase;
2095+     return true;
2096+  } else {
2097+     if (buf) buf[0] = '\0';
2098+     if (offset) *offset = -1;
2099+     return false;
2100+  }
2101+}
2102+#else
2103 struct _address_to_library_name {
2104   address addr;          // input : memory address
2105   size_t  buflen;        //         size of fname
2106@@ -1614,11 +1837,27 @@ bool os::dll_address_to_library_name(add
2107      return false;
2108   }
2109 }
2110+#endif
2111 
2112   // Loads .dll/.so and
2113   // in case of error it checks if .dll/.so was built for the
2114   // same architecture as Hotspot is running on
2115+
2116+#ifdef __APPLE__
2117+void * os::dll_load(const char *filename, char *ebuf, int ebuflen) {
2118+  void * result= ::dlopen(filename, RTLD_LAZY);
2119+  if (result != NULL) {
2120+    // Successful loading
2121+    return result;
2122+  }
2123 
2124+  // Read system error message into ebuf
2125+  ::strncpy(ebuf, ::dlerror(), ebuflen-1);
2126+  ebuf[ebuflen-1]='\0';
2127+
2128+  return NULL;
2129+}
2130+#else
2131 void * os::dll_load(const char *filename, char *ebuf, int ebuflen)
2132 {
2133   void * result= ::dlopen(filename, RTLD_LAZY);
2134@@ -1671,6 +1910,20 @@ void * os::dll_load(const char *filename
2135   #define EM_486          6               /* Intel 80486 */
2136   #endif
2137 
2138+  #ifndef EM_PPC64
2139+  #define EM_PPC64        21              /* PowerPC64 */
2140+  #endif
2141+
2142+  #ifndef EM_IA_64
2143+  #define EM_IA_64        50              /* HP/Intel IA-64 */
2144+  #endif
2145+
2146+  #ifndef EM_X86_64
2147+  #define EM_X86_64       62              /* AMD x86-64 */
2148+  #endif
2149+
2150+
2151+
2152   static const arch_t arch_array[]={
2153     {EM_386,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
2154     {EM_486,         EM_386,     ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"},
2155@@ -1751,7 +2004,7 @@ void * os::dll_load(const char *filename
2156 
2157   return NULL;
2158 }
2159-
2160+#endif /* !__APPLE__  */
2161 
2162 
2163 
2164@@ -1774,7 +2027,51 @@ bool _print_ascii_file(const char* filen
2165 
2166 void os::print_dll_info(outputStream *st) {
2167    st->print_cr("Dynamic libraries:");
2168-
2169+#ifdef _ALLBSD_SOURCE
2170+#ifdef RTLD_DI_LINKMAP
2171+    Dl_info dli;
2172+    void *handle;
2173+    Link_map *map;
2174+    Link_map *p;
2175+
2176+    if (!dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli)) {
2177+        st->print_cr("Error: Cannot print dynamic libraries.");
2178+        return;
2179+    }
2180+    handle = dlopen(dli.dli_fname, RTLD_LAZY);
2181+    if (handle == NULL) {
2182+        st->print_cr("Error: Cannot print dynamic libraries.");
2183+        return;
2184+    }
2185+    dlinfo(handle, RTLD_DI_LINKMAP, &map);
2186+    if (map == NULL) {
2187+        st->print_cr("Error: Cannot print dynamic libraries.");
2188+        return;
2189+    }
2190+
2191+    while (map->l_prev != NULL)
2192+        map = map->l_prev;
2193+
2194+    while (map != NULL) {
2195+        st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name);
2196+        map = map->l_next;
2197+    }
2198+
2199+    dlclose(handle);
2200+#elif defined(__APPLE__)
2201+    uint32_t count;
2202+    uint32_t i;
2203+
2204+    count = _dyld_image_count();
2205+    for (i = 1; i < count; i++) {
2206+        const char *name = _dyld_get_image_name(i);
2207+        intptr_t slide = _dyld_get_image_vmaddr_slide(i);
2208+        st->print_cr(PTR_FORMAT " \t%s", slide, name);
2209+    }
2210+#else
2211+   st->print_cr("Error: Cannot print dynamic libraries.");
2212+#endif
2213+#else
2214    char fname[32];
2215    pid_t pid = os::Bsd::gettid();
2216 
2217@@ -1783,6 +2080,7 @@ void os::print_dll_info(outputStream *st
2218    if (!_print_ascii_file(fname, st)) {
2219      st->print("Can not get library information for pid = %d\n", pid);
2220    }
2221+#endif
2222 }
2223 
2224 
2225@@ -1815,6 +2113,7 @@ void os::print_os_info(outputStream* st)
2226   st->print(name.machine);
2227   st->cr();
2228 
2229+#ifndef _ALLBSD_SOURCE
2230   // Print warning if unsafe chroot environment detected
2231   if (unsafe_chroot_detected) {
2232     st->print("WARNING!! ");
2233@@ -1829,6 +2128,7 @@ void os::print_os_info(outputStream* st)
2234      st->print("(%s stack)", os::Bsd::is_floating_stack() ? "floating" : "fixed");
2235   }
2236   st->cr();
2237+#endif
2238 
2239   // rlimit
2240   st->print("rlimit:");
2241@@ -1854,6 +2154,7 @@ void os::print_os_info(outputStream* st)
2242   if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
2243   else st->print("%d", rlim.rlim_cur);
2244 
2245+#ifndef _ALLBSD_SOURCE
2246   st->print(", AS ");
2247   getrlimit(RLIMIT_AS, &rlim);
2248   if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity");
2249@@ -1866,6 +2167,7 @@ void os::print_os_info(outputStream* st)
2250   os::loadavg(loadavg, 3);
2251   st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]);
2252   st->cr();
2253+#endif
2254 }
2255 
2256 void os::print_memory_info(outputStream* st) {
2257@@ -1873,18 +2175,22 @@ void os::print_memory_info(outputStream*
2258   st->print("Memory:");
2259   st->print(" %dk page", os::vm_page_size()>>10);
2260 
2261+#ifndef _ALLBSD_SOURCE
2262   // values in struct sysinfo are "unsigned long"
2263   struct sysinfo si;
2264   sysinfo(&si);
2265+#endif
2266   
2267   st->print(", physical " UINT64_FORMAT "k",
2268             os::physical_memory() >> 10);
2269   st->print("(" UINT64_FORMAT "k free)",
2270             os::available_memory() >> 10);
2271+#ifndef _ALLBSD_SOURCE
2272   st->print(", swap " UINT64_FORMAT "k",
2273             ((jlong)si.totalswap * si.mem_unit) >> 10);
2274   st->print("(" UINT64_FORMAT "k free)",
2275             ((jlong)si.freeswap * si.mem_unit) >> 10);
2276+#endif
2277   st->cr();
2278 }
2279 
2280@@ -2108,19 +2414,29 @@ int os::sigexitnum_pd() {
2281 static volatile jint pending_signals[NSIG+1] = { 0 };
2282 
2283 // Bsd(POSIX) specific hand shaking semaphore.
2284+#ifdef __APPLE__
2285+static semaphore_t sig_sem;
2286+#define SEM_INIT(sem, value)   semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, value)
2287+#define SEM_WAIT(sem)          semaphore_wait(sem);
2288+#define SEM_POST(sem)          semaphore_signal(sem);
2289+#else
2290 static sem_t sig_sem;
2291+#define SEM_INIT(sem, value)   sem_init(&sem, 0, value)
2292+#define SEM_WAIT(sem)          sem_wait(&sem);
2293+#define SEM_POST(sem)          sem_post(&sem);
2294+#endif
2295 
2296 void os::signal_init_pd() {
2297   // Initialize signal structures
2298   ::memset((void*)pending_signals, 0, sizeof(pending_signals));
2299 
2300   // Initialize signal semaphore
2301-  ::sem_init(&sig_sem, 0, 0);
2302+  ::SEM_INIT(sig_sem, 0);
2303 }
2304 
2305 void os::signal_notify(int sig) {
2306   Atomic::inc(&pending_signals[sig]);
2307-  ::sem_post(&sig_sem);
2308+  ::SEM_POST(sig_sem);
2309 }
2310 
2311 static int check_pending_signals(bool wait) {
2312@@ -2142,7 +2458,7 @@ static int check_pending_signals(bool wa
2313     do {
2314       thread->set_suspend_equivalent();
2315       // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self()
2316-      ::sem_wait(&sig_sem);
2317+      ::SEM_WAIT(sig_sem);
2318 
2319       // were we externally suspended while we were waiting?
2320       threadIsSuspended = thread->handle_special_suspend_equivalent_condition();
2321@@ -2153,7 +2469,7 @@ static int check_pending_signals(bool wa
2322         // while suspended because that would surprise the thread that
2323         // suspended us.
2324         //
2325-        ::sem_post(&sig_sem);
2326+        ::SEM_POST(sig_sem);
2327 
2328         thread->java_suspend_self();
2329       }
2330@@ -2224,10 +2540,16 @@ void bsd_wrap_code(char* base, size_t si
2331 //       left at the time of mmap(). This could be a potential 
2332 //       problem.                                               
2333 bool os::commit_memory(char* addr, size_t size) {
2334+#ifdef __OpenBSD__
2335+  // XXX: Work-around mmap/MAP_FIXED bug temporarily on OpenBSD
2336+  return mprotect(addr, size, PROT_READ|PROT_WRITE|PROT_EXEC) == 0;
2337+#else
2338+
2339   uintptr_t res = (uintptr_t) ::mmap(addr, size,
2340                                    PROT_READ|PROT_WRITE|PROT_EXEC,
2341                                    MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0);
2342   return res != (uintptr_t) MAP_FAILED;
2343+#endif
2344 }
2345 
2346 bool os::commit_memory(char* addr, size_t size, size_t alignment_hint) {
2347@@ -2351,6 +2673,9 @@ bool os::unguard_memory(char* addr, size
2348 static size_t _large_page_size = 0;
2349 
2350 bool os::large_page_init() {
2351+#ifdef _ALLBSD_SOURCE
2352+ return false;
2353+#else
2354   if (!UseLargePages) return false;
2355 
2356   if (LargePageSizeInBytes) {
2357@@ -2405,6 +2730,7 @@ bool os::large_page_init() {
2358   // We optimistically assume the support is available. If later it turns out
2359   // not true, VM will automatically switch to use regular page size.
2360   return true;
2361+#endif
2362 }
2363 
2364 #ifndef SHM_HUGETLB
2365@@ -2575,7 +2901,7 @@ char* os::attempt_reserve_memory_at(size
2366 }
2367 
2368 size_t os::read(int fd, void *buf, unsigned int nBytes) {
2369-  return ::read(fd, buf, nBytes);
2370+  INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Bsd::clear_interrupted);
2371 } 
2372 
2373 // TODO-FIXME: reconcile Solaris' os::sleep with the bsd variation.
2374@@ -2711,6 +3037,44 @@ void os::loop_breaker(int attempts) {
2375 // this reason, the code should not be used as default (ThreadPriorityPolicy=0).
2376 // It is only used when ThreadPriorityPolicy=1 and requires root privilege.
2377 
2378+#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__)
2379+int os::java_to_os_priority[MaxPriority + 1] = {
2380+  19,              // 0 Entry should never be used
2381+
2382+   0,              // 1 MinPriority
2383+   3,              // 2
2384+   6,              // 3
2385+
2386+   10,              // 4
2387+   15,              // 5 NormPriority
2388+   18,              // 6
2389+
2390+   21,              // 7
2391+   25,              // 8
2392+   28,              // 9 NearMaxPriority
2393+
2394+   31              // 10 MaxPriority
2395+};
2396+#elif defined(__APPLE__)
2397+/* Using Mach high-level priority assignments */
2398+int os::java_to_os_priority[MaxPriority + 1] = {
2399+   0,              // 0 Entry should never be used (MINPRI_USER)
2400+
2401+  27,              // 1 MinPriority
2402+  28,              // 2
2403+  29,              // 3
2404+
2405+  30,              // 4
2406+  31,              // 5 NormPriority (BASEPRI_DEFAULT)
2407+  32,              // 6
2408+
2409+  33,              // 7
2410+  34,              // 8
2411+  35,              // 9 NearMaxPriority
2412+
2413+  36               // 10 MaxPriority
2414+};
2415+#else
2416 int os::java_to_os_priority[MaxPriority + 1] = {
2417   19,              // 0 Entry should never be used
2418 
2419@@ -2728,6 +3092,7 @@ int os::java_to_os_priority[MaxPriority
2420 
2421   -5               // 10 MaxPriority
2422 };
2423+#endif
2424 
2425 static int prio_init() {
2426   if (ThreadPriorityPolicy == 1) {
2427@@ -2747,8 +3112,28 @@ static int prio_init() {
2428 OSReturn os::set_native_priority(Thread* thread, int newpri) {
2429   if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) return OS_OK;
2430 
2431+#ifdef __OpenBSD__
2432+  // OpenBSD pthread_setprio starves low priority threads
2433+  return OS_OK;
2434+#elif defined(__FreeBSD__)
2435+  int ret = pthread_setprio(thread->osthread()->pthread_id(), newpri);
2436+#elif defined(__APPLE__)
2437+  struct sched_param sp;
2438+  int policy;
2439+  pthread_t self = pthread_self();
2440+
2441+  if (pthread_getschedparam(self, &policy, &sp) != 0)
2442+    return OS_ERR;
2443+
2444+  sp.sched_priority = newpri;
2445+  if (pthread_setschedparam(self, policy, &sp) != 0)
2446+    return OS_ERR;
2447+
2448+  return OS_OK;
2449+#else
2450   int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri);
2451   return (ret == 0) ? OS_OK : OS_ERR;
2452+#endif
2453 }
2454 
2455 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) {
2456@@ -2758,7 +3143,17 @@ OSReturn os::get_native_priority(const T
2457   }
2458 
2459   errno = 0;
2460+#if defined(__OpenBSD__) || defined(__FreeBSD__)
2461+  *priority_ptr = pthread_getprio(thread->osthread()->pthread_id());
2462+#elif defined(__APPLE__)
2463+  int policy;
2464+  struct sched_param sp;
2465+
2466+  pthread_getschedparam(pthread_self(), &policy, &sp);
2467+  *priority_ptr = sp.sched_priority;
2468+#else
2469   *priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id());
2470+#endif
2471   return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR);
2472 }
2473 
2474@@ -2868,7 +3263,7 @@ static int SR_initialize() {
2475   /* Get signal number to use for suspend/resume */
2476   if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) {
2477     int sig = ::strtol(s, 0, 10);
2478-    if (sig > 0 || sig < _NSIG) {
2479+    if (sig > 0 || sig < NSIG) {
2480        SR_signum = sig;
2481     }
2482   }
2483@@ -3211,6 +3606,28 @@ void os::Bsd::install_signal_handlers()
2484     set_signal_handler(SIGFPE, true);
2485     set_signal_handler(SIGXFSZ, true);
2486 
2487+#if defined(__APPLE__)
2488+    // In Mac OS X 10.4, CrashReporter will write a crash log for all 'fatal' signals, including
2489+    // signals caught and handled by the JVM. To work around this, we reset the mach task
2490+    // signal handler that's placed on our process by CrashReporter. This disables
2491+    // CrashReporter-based reporting.
2492+    //
2493+    // This work-around is not necessary for 10.5+, as CrashReporter no longer intercedes
2494+    // on caught fatal signals.
2495+    //
2496+    // Additionally, gdb installs both standard BSD signal handlers, and mach exception
2497+    // handlers. By replacing the existing task exception handler, we disable gdb's mach
2498+    // exception handling, while leaving the standard BSD signal handlers functional.
2499+    kern_return_t kr;
2500+    kr = task_set_exception_ports(mach_task_self(),
2501+        EXC_MASK_BAD_ACCESS | EXC_MASK_ARITHMETIC,
2502+        MACH_PORT_NULL,
2503+        EXCEPTION_STATE_IDENTITY,
2504+        MACHINE_THREAD_STATE);
2505+
2506+    assert(kr == KERN_SUCCESS, "could not set mach task signal handler");
2507+#endif
2508+
2509     if (libjsig_is_loaded) {
2510       // Tell libjsig jvm finishes setting signal handlers
2511       (*end_signal_setting)();
2512@@ -3231,6 +3648,7 @@ void os::Bsd::install_signal_handlers()
2513   }
2514 }
2515 
2516+#ifndef _ALLBSD_SOURCE
2517 // This is the fastest way to get thread cpu time on Bsd.
2518 // Returns cpu time (user+sys) for any thread, not only for current.
2519 // POSIX compliant clocks are implemented in the kernels 2.6.16+.
2520@@ -3245,6 +3663,7 @@ jlong os::Bsd::fast_thread_cpu_time(cloc
2521 
2522   return (tp.tv_sec * SEC_IN_NANOSECS) + tp.tv_nsec;
2523 }
2524+#endif
2525 
2526 /////
2527 // glibc on Bsd platform uses non-documented flag
2528@@ -3466,13 +3885,13 @@ void os::init(void) {
2529 
2530   _initial_pid = (java_launcher_pid > 0) ? java_launcher_pid : getpid();
2531 
2532-  clock_tics_per_sec = sysconf(_SC_CLK_TCK);
2533+  clock_tics_per_sec = CLK_TCK;
2534 
2535   init_random(1234567);
2536 
2537   ThreadCritical::initialize();
2538 
2539-  Bsd::set_page_size(sysconf(_SC_PAGESIZE));
2540+  Bsd::set_page_size(getpagesize());
2541   if (Bsd::page_size() == -1) {
2542     fatal1("os_bsd.cpp: os::init: sysconf failed (%s)", strerror(errno));
2543   }
2544@@ -3485,6 +3904,16 @@ void os::init(void) {
2545 
2546   Bsd::clock_init();
2547   initial_time_count = os::elapsed_counter();
2548+
2549+#ifdef __APPLE__
2550+  // XXXDARWIN
2551+  // Work around the unaligned VM callbacks in hotspot's
2552+  // sharedRuntime. The callbacks don't use SSE2 instructions, and work on
2553+  // Linux, Solaris, and FreeBSD. On Mac OS X, dyld (rightly so) enforces
2554+  // alignment when doing symbol lookup. To work around this, we force early
2555+  // binding of all symbols now, thus binding when alignment is known-good.
2556+  _dyld_bind_fully_image_containing_address((const void *) &os::init);
2557+#endif
2558 }
2559 
2560 // To install functions for atexit system call
2561@@ -3497,7 +3926,9 @@ extern "C" {
2562 // this is called _after_ the global arguments have been parsed
2563 jint os::init_2(void)
2564 {
2565+#ifndef _ALLBSD_SOURCE
2566   Bsd::fast_thread_clock_init();
2567+#endif
2568 
2569   // Allocate a single page and mark it as readable for safepoint polling
2570   address polling_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0);
2571@@ -3546,6 +3977,7 @@ jint os::init_2(void)
2572   JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes,
2573         vm_page_size()));
2574 
2575+#ifndef _ALLBSD_SOURCE
2576   Bsd::capture_initial_stack(JavaThread::stack_size_at_create());
2577 
2578   Bsd::libpthread_init();
2579@@ -3554,6 +3986,7 @@ jint os::init_2(void)
2580           Bsd::glibc_version(), Bsd::libpthread_version(),
2581           Bsd::is_floating_stack() ? "floating stack" : "fixed stack");
2582   }
2583+#endif
2584 
2585   if (MaxFDLimit) {
2586     // set the number of file descriptors to max. print out error
2587@@ -3565,6 +3998,14 @@ jint os::init_2(void)
2588         perror("os::init_2 getrlimit failed");
2589     } else {
2590       nbr_files.rlim_cur = nbr_files.rlim_max;
2591+     
2592+#ifdef __APPLE__
2593+      // Darwin returns RLIM_INFINITY for rlim_max, but fails with EINVAL if
2594+      // you attempt to use RLIM_INFINITY. As per setrlimit(2), OPEN_MAX must
2595+      // be used instead
2596+      nbr_files.rlim_cur = MIN(OPEN_MAX, nbr_files.rlim_cur);
2597+#endif
2598+
2599       status = setrlimit(RLIMIT_NOFILE, &nbr_files);
2600       if (status != 0) {
2601         if (PrintMiscellaneous && (Verbose || WizardMode))
2602@@ -3573,8 +4014,10 @@ jint os::init_2(void)
2603     }
2604   }
2605 
2606+#ifndef _ALLBSD_SOURCE
2607   // Initialize lock used to serialize thread creation (see os::create_thread)
2608   Bsd::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false));
2609+#endif
2610 
2611   // Initialize HPI.
2612   jint hpi_result = hpi::initialize();
2613@@ -3621,11 +4064,16 @@ void os::make_polling_page_readable(void
2614 };
2615 
2616 int os::active_processor_count() {
2617+#ifdef _ALLBSD_SOURCE
2618+  return _processor_count;
2619+#else
2620+
2621   // Bsd doesn't yet have a (official) notion of processor sets,
2622   // so just return the number of online processors.
2623   int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN);
2624   assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check");
2625   return online_cpus;
2626+#endif
2627 }
2628 
2629 bool os::distribute_processes(uint length, uint* distribution) {
2630@@ -3667,6 +4115,9 @@ ExtendedPC os::get_thread_pc(Thread* thr
2631 
2632 int os::Bsd::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime)
2633 {
2634+#ifdef _ALLBSD_SOURCE
2635+  return pthread_cond_timedwait(_cond, _mutex, _abstime);
2636+#else
2637    if (is_NPTL()) {
2638       return pthread_cond_timedwait(_cond, _mutex, _abstime);
2639    } else {
2640@@ -3682,6 +4133,7 @@ int os::Bsd::safe_cond_timedwait(pthread
2641 #endif // IA64
2642       return status;
2643    }
2644+#endif
2645 }
2646 
2647 ////////////////////////////////////////////////////////////////////////////////
2648@@ -3817,17 +4269,17 @@ int os::create_binary_file(const char* p
2649   if (!rewrite_existing) {
2650     oflags |= O_EXCL;
2651   }
2652-  return ::open64(path, oflags, S_IREAD | S_IWRITE);
2653+  return ::open(path, oflags, S_IREAD | S_IWRITE);
2654 }
2655 
2656 // return current position of file pointer
2657 jlong os::current_file_offset(int fd) {
2658-  return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR);
2659+  return (jlong)::lseek(fd, (off_t)0, SEEK_CUR);
2660 }
2661 
2662 // move file pointer to the specified offset
2663 jlong os::seek_to_file_offset(int fd, jlong offset) {
2664-  return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET);
2665+  return (jlong)::lseek(fd, (off_t)offset, SEEK_SET);
2666 }
2667 
2668 // Map a block of memory.
2669@@ -3877,6 +4329,7 @@ bool os::unmap_memory(char* addr, size_t
2670   return munmap(addr, bytes) == 0;
2671 }
2672 
2673+#ifndef _ALLBSD_SOURCE
2674 static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time);
2675 
2676 static clockid_t thread_cpu_clockid(Thread* thread) {
2677@@ -3888,6 +4341,7 @@ static clockid_t thread_cpu_clockid(Thre
2678   assert(rc == 0, "pthread_getcpuclockid is expected to return 0 code");
2679   return clockid;
2680 }
2681+#endif
2682 
2683 // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool)
2684 // are used by JVM M&M and JVMTI to get user+sys or user CPU time
2685@@ -3897,39 +4351,71 @@ static clockid_t thread_cpu_clockid(Thre
2686 // the fast estimate available on the platform.
2687 
2688 jlong os::current_thread_cpu_time() {
2689+#ifdef __APPLE__
2690+  return os::thread_cpu_time(Thread::current(), true /* user + sys */);
2691+#elif !defined(_ALLBSD_SOURCE)
2692   if (os::Bsd::supports_fast_thread_cpu_time()) {
2693     return os::Bsd::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
2694   } else {
2695     // return user + sys since the cost is the same
2696     return slow_thread_cpu_time(Thread::current(), true /* user + sys */);
2697   }
2698+#endif
2699 }
2700 
2701 jlong os::thread_cpu_time(Thread* thread) {
2702+#ifndef _ALLBSD_SOURCE
2703   // consistent with what current_thread_cpu_time() returns
2704   if (os::Bsd::supports_fast_thread_cpu_time()) {
2705     return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
2706   } else {
2707     return slow_thread_cpu_time(thread, true /* user + sys */);
2708   }
2709+#endif
2710 }
2711 
2712 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) {
2713+#ifdef __APPLE__
2714+  return os::thread_cpu_time(Thread::current(), user_sys_cpu_time);
2715+#elif !defined(_ALLBSD_SOURCE)
2716   if (user_sys_cpu_time && os::Bsd::supports_fast_thread_cpu_time()) {
2717     return os::Bsd::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID);
2718   } else {
2719     return slow_thread_cpu_time(Thread::current(), user_sys_cpu_time);
2720   }
2721+#endif
2722 }
2723 
2724 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) {
2725+#ifdef __APPLE__
2726+  struct thread_basic_info tinfo;
2727+  mach_msg_type_number_t tcount = THREAD_INFO_MAX;
2728+  kern_return_t kr;
2729+  mach_port_t mach_thread;
2730+
2731+  mach_thread = pthread_mach_thread_np(thread->osthread()->thread_id());
2732+  kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount);
2733+  if (kr != KERN_SUCCESS)
2734+    return -1;
2735+
2736+  if (user_sys_cpu_time) {
2737+    jlong nanos;
2738+    nanos = ((jlong) tinfo.system_time.seconds + tinfo.user_time.seconds) * (jlong)1000000000;
2739+    nanos += ((jlong) tinfo.system_time.microseconds + (jlong) tinfo.user_time.microseconds) * (jlong)1000;
2740+    return nanos;
2741+  } else {
2742+    return ((jlong)tinfo.user_time.seconds * 1000000000) + ((jlong)tinfo.user_time.microseconds * (jlong)1000);
2743+  }
2744+#elif !defined(_ALLBSD_SOURCE)
2745   if (user_sys_cpu_time && os::Bsd::supports_fast_thread_cpu_time()) {
2746     return os::Bsd::fast_thread_cpu_time(thread_cpu_clockid(thread));
2747   } else {
2748     return slow_thread_cpu_time(thread, user_sys_cpu_time);
2749   }
2750+#endif
2751 }
2752 
2753+#ifndef _ALLBSD_SOURCE
2754 //
2755 //  -1 on error.
2756 //
2757@@ -4018,6 +4504,7 @@ static jlong slow_thread_cpu_time(Thread
2758     return (jlong)user_time * (1000000000 / clock_tics_per_sec);
2759   }
2760 }
2761+#endif
2762 
2763 void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) {
2764   info_ptr->max_value = ALL_64_BITS;       // will not wrap in less than 64 bits
2765@@ -4034,7 +4521,13 @@ void os::thread_cpu_time_info(jvmtiTimer
2766 }
2767 
2768 bool os::is_thread_cpu_time_supported() {
2769+#ifdef __APPLE__
2770+  return true;
2771+#elif defined(_ALLBSD_SOURCE)
2772+  return false;
2773+#else
2774   return true;
2775+#endif
2776 }
2777 
2778 // System loadavg support.  Returns -1 if load average cannot be obtained.
2779@@ -4167,7 +4660,7 @@ jdk_pthread_sigmask(int how , const sigs
2780 // abstime will be the absolute timeout time
2781 // TODO: replace compute_abstime() with unpackTime()
2782 
2783-static struct timespec* compute_abstime(timespec* abstime, jlong millis) {
2784+static struct timespec* compute_abstime(struct timespec* abstime, jlong millis) {
2785   if (millis < 0)  millis = 0;
2786   struct timeval now;
2787   int status = gettimeofday(&now, NULL);
2788@@ -4219,7 +4712,7 @@ void os::PlatformEvent::park() {       /
2789         status = pthread_cond_wait(_cond, _mutex);
2790         // for some reason, under 2.7 lwp_cond_wait() may return ETIME ...
2791         // Treat this the same as if the wait was interrupted
2792-        if (status == ETIME) { status = EINTR; }
2793+        if (status == ETIMEDOUT) { status = EINTR; }
2794         assert_status(status == 0 || status == EINTR, status, "cond_wait");
2795      }
2796      -- _nParked ;
2797@@ -4277,10 +4770,10 @@ int os::PlatformEvent::park(jlong millis
2798       pthread_cond_init (_cond, NULL) ;
2799     }
2800     assert_status(status == 0 || status == EINTR ||
2801-                 status == ETIME || status == ETIMEDOUT,
2802+                 status == ETIMEDOUT,
2803                  status, "cond_timedwait");
2804     if (!FilterSpuriousWakeups) break ;                // previous semantics
2805-    if (status == ETIME || status == ETIMEDOUT) break ;
2806+    if (status == ETIMEDOUT) break ;
2807     // We consume and ignore EINTR and spurious wakeups.   
2808   }
2809   --_nParked ;
2810@@ -4372,7 +4865,7 @@ void os::PlatformEvent::unpark() {
2811  * years from "now".
2812  */
2813 
2814-static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) {
2815+static void unpackTime(struct timespec* absTime, bool isAbsolute, jlong time) {
2816   assert (time > 0, "convertTime");
2817 
2818   struct timeval now;
2819@@ -4431,7 +4924,7 @@ void Parker::park(bool isAbsolute, jlong
2820   }
2821 
2822   // Next, demultiplex/decode time arguments
2823-  timespec absTime;
2824+  struct timespec absTime;
2825   if (time < 0) { // don't wait at all
2826     return;
2827   }
2828@@ -4484,7 +4977,7 @@ void Parker::park(bool isAbsolute, jlong
2829     }
2830   }
2831   assert_status(status == 0 || status == EINTR ||
2832-                status == ETIME || status == ETIMEDOUT,
2833+                status == ETIMEDOUT,
2834                 status, "cond_timedwait");
2835 
2836 #ifdef ASSERT
2837@@ -4526,14 +5019,12 @@ void Parker::unpark() {
2838 }
2839 
2840 
2841+/* Darwin has no "environ" in a dynamic library. */
2842+#ifdef __APPLE__
2843+#include <crt_externs.h>
2844+#define environ (*_NSGetEnviron())
2845+#else
2846 extern char** environ;
2847-
2848-#ifndef __NR_fork
2849-#define __NR_fork IA32_ONLY(2) IA64_ONLY(not defined) AMD64_ONLY(57)
2850-#endif
2851-
2852-#ifndef __NR_execve
2853-#define __NR_execve IA32_ONLY(11) IA64_ONLY(1033) AMD64_ONLY(59)
2854 #endif
2855 
2856 // Run the specified command in a separate process. Return its exit value,
2857@@ -4548,8 +5039,7 @@ int os::fork_and_exec(char* cmd) {
2858   // separate process to execve. Make a direct syscall to fork process.
2859   // On IA64 there's no fork syscall, we have to use fork() and hope for
2860   // the best...
2861-  pid_t pid = NOT_IA64(syscall(__NR_fork);)
2862-              IA64_ONLY(fork();)
2863+  pid_t pid = fork();
2864 
2865   if (pid < 0) {
2866     // fork failed
2867@@ -4565,8 +5055,7 @@ int os::fork_and_exec(char* cmd) {
2868     // in the new process, so make a system call directly.
2869     // IA64 should use normal execve() from glibc to match the glibc fork()
2870     // above.
2871-    NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);)
2872-    IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);)
2873+    execve("/bin/sh", (char* const*)argv, environ);
2874 
2875     // execve failed
2876     _exit(-1);
2877diff -upr ../orig/hotspot/src/os/bsd/vm/os_bsd.hpp ./hotspot/src/os/bsd/vm/os_bsd.hpp
2878--- ../orig/hotspot/src/os/bsd/vm/os_bsd.hpp    2009-05-04 18:32:15.000000000 -0400
2879+++ ./hotspot/src/os/bsd/vm/os_bsd.hpp  2009-05-06 10:55:43.000000000 -0400
2880@@ -30,6 +30,12 @@
2881 /* pthread_getattr_np comes with BsdThreads-0.9-7 on RedHat 7.1 */
2882 typedef int (*pthread_getattr_func_type) (pthread_t, pthread_attr_t *);
2883 
2884+#ifdef __APPLE__
2885+// Mac OS X doesn't support clock_gettime. Stub out the type, it is
2886+// unused
2887+typedef int clockid_t;
2888+#endif
2889+
2890 class Bsd {
2891   friend class os;
2892 
2893@@ -50,6 +56,7 @@ class Bsd {
2894   static int sigflags[MAXSIGNUM];
2895 
2896   static int (*_clock_gettime)(clockid_t, struct timespec *);
2897+#ifndef _ALLBSD_SOURCE
2898   static int (*_pthread_getcpuclockid)(pthread_t, clockid_t *);
2899 
2900   static address   _initial_thread_stack_bottom;
2901@@ -61,42 +68,79 @@ class Bsd {
2902   static bool _is_floating_stack;
2903   static bool _is_NPTL;
2904   static bool _supports_fast_thread_cpu_time;
2905+#endif
2906 
2907  protected:
2908 
2909   static julong _physical_memory;
2910   static pthread_t _main_thread;
2911+#ifndef _ALLBSD_SOURCE
2912   static Mutex* _createThread_lock;
2913+#endif
2914   static int _page_size;
2915 
2916   static julong available_memory();
2917   static julong physical_memory() { return _physical_memory; }
2918   static void initialize_system_info();
2919 
2920+#ifndef _ALLBSD_SOURCE
2921   static void set_glibc_version(const char *s)      { _glibc_version = s; }
2922   static void set_libpthread_version(const char *s) { _libpthread_version = s; }
2923+#endif
2924 
2925   static bool supports_variable_stack_size();
2926 
2927+#ifndef _ALLBSD_SOURCE
2928   static void set_is_NPTL()                   { _is_NPTL = true;  }
2929   static void set_is_BsdThreads()           { _is_NPTL = false; }
2930   static void set_is_floating_stack()         { _is_floating_stack = true; }
2931+#endif
2932 
2933  public:
2934+#ifdef _ALLBSD_SOURCE
2935+//XXXBSD: ported from solaris version
2936+  enum {
2937+    clear_interrupted = true
2938+  };
2939+  static void setup_interruptible(JavaThread* thread);
2940+  static void setup_interruptible_already_blocked(JavaThread* thread);
2941+  static JavaThread* setup_interruptible();
2942+  static void cleanup_interruptible(JavaThread* thread);
2943+
2944+  // perf counter incrementers used by _INTERRUPTIBLE
2945+
2946+  static void bump_interrupted_before_count();
2947+  static void bump_interrupted_during_count();
2948+
2949+#ifdef ASSERT
2950+  static JavaThread* setup_interruptible_native();
2951+  static void cleanup_interruptible_native(JavaThread* thread);
2952+#endif
2953+
2954+#endif
2955+
2956 
2957   static void init_thread_fpu_state();
2958+#ifndef _ALLBSD_SOURCE
2959   static int  get_fpu_control_word();
2960   static void set_fpu_control_word(int fpu_control);
2961+#endif
2962   static pthread_t main_thread(void)                                { return _main_thread; }
2963+
2964+#ifndef _ALLBSD_SOURCE
2965   // returns kernel thread id (similar to LWP id on Solaris), which can be
2966   // used to access /proc
2967   static pid_t gettid();
2968   static void set_createThread_lock(Mutex* lk)                      { _createThread_lock = lk; }
2969   static Mutex* createThread_lock(void)                             { return _createThread_lock; }
2970+#endif
2971   static void hotspot_sigmask(Thread* thread);
2972 
2973+#ifndef _ALLBSD_SOURCE
2974   static address   initial_thread_stack_bottom(void)                { return _initial_thread_stack_bottom; }
2975   static uintptr_t initial_thread_stack_size(void)                  { return _initial_thread_stack_size; }
2976+#endif
2977+
2978   static bool is_initial_thread(void);
2979 
2980   static int page_size(void)                                        { return _page_size; }
2981@@ -133,6 +177,7 @@ class Bsd {
2982   static struct sigaction *get_chained_signal_action(int sig);
2983   static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
2984 
2985+#ifndef _ALLBSD_SOURCE
2986   // GNU libc and libpthread version strings
2987   static const char *glibc_version()          { return _glibc_version; }
2988   static const char *libpthread_version()     { return _libpthread_version; }
2989@@ -146,6 +191,7 @@ class Bsd {
2990   static bool is_floating_stack()             { return _is_floating_stack; }
2991 
2992   static void libpthread_init();
2993+#endif
2994 
2995   // Minimum stack size a thread can be created with (allowing
2996   // the VM to completely create the thread and enter user code)
2997@@ -155,17 +201,21 @@ class Bsd {
2998   static size_t default_stack_size(os::ThreadType thr_type);
2999   static size_t default_guard_size(os::ThreadType thr_type);
3000 
3001+#ifndef _ALLBSD_SOURCE
3002   static void capture_initial_stack(size_t max_size);
3003 
3004   // Stack overflow handling
3005   static bool manually_expand_stack(JavaThread * t, address addr);
3006   static int max_register_window_saves_before_flushing();
3007+#endif
3008 
3009   // Real-time clock functions
3010   static void clock_init(void);
3011 
3012+#ifndef _ALLBSD_SOURCE
3013   // fast POSIX clocks support
3014   static void fast_thread_clock_init(void);
3015+#endif
3016 
3017   static bool supports_monotonic_clock() {
3018     return _clock_gettime != NULL;
3019@@ -175,6 +225,7 @@ class Bsd {
3020     return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
3021   }
3022 
3023+#ifndef _ALLBSD_SOURCE
3024   static int pthread_getcpuclockid(pthread_t tid, clockid_t *clock_id) {
3025     return _pthread_getcpuclockid ? _pthread_getcpuclockid(tid, clock_id) : -1;
3026   }
3027@@ -184,6 +235,7 @@ class Bsd {
3028   }
3029 
3030   static jlong fast_thread_cpu_time(clockid_t clockid);
3031+#endif
3032 
3033   // Stack repair handling
3034 
3035diff -upr ../orig/hotspot/src/os/bsd/vm/os_bsd.inline.hpp ./hotspot/src/os/bsd/vm/os_bsd.inline.hpp
3036--- ../orig/hotspot/src/os/bsd/vm/os_bsd.inline.hpp     2009-05-04 18:32:15.000000000 -0400
3037+++ ./hotspot/src/os/bsd/vm/os_bsd.inline.hpp   2009-05-06 10:57:31.000000000 -0400
3038@@ -64,7 +64,15 @@ inline bool os::uses_stack_guard_pages()
3039 
3040 inline bool os::allocate_stack_guard_pages() {
3041   assert(uses_stack_guard_pages(), "sanity check");
3042+#if !defined(__FreeBSD__) || __FreeBSD__ < 5
3043+  // Since FreeBSD 4 uses malloc() for allocating the thread stack
3044+  // there is no need to do anything extra to allocate the guard pages
3045+  return false;
3046+#else
3047+  // FreeBSD 5+ uses mmap MAP_STACK for allocating the thread stacks.
3048+  // Must 'allocate' them or guard pages are ignored.
3049   return true;
3050+#endif
3051 }
3052 
3053 
3054@@ -112,6 +120,107 @@ inline int os::closedir(DIR *dirp)
3055   return ::closedir(dirp);
3056 }
3057 
3058+//XXXBSD: ported from solaris version
3059+//////////////////////////////////////////////////////////////////////////////
3060+////////////////////////////////////////////////////////////////////////////////
3061+
3062+// macros for interruptible io and system calls and system call restarting
3063+
3064+#define _INTERRUPTIBLE(_setup, _cmd, _result, _thread, _clear, _before, _after, _int_enable) \
3065+do { \
3066+  _setup; \
3067+  _before; \
3068+  OSThread* _osthread = _thread->osthread(); \
3069+  if (_int_enable && _thread->has_last_Java_frame()) { \
3070+    /* this is java interruptible io stuff */ \
3071+    if (os::is_interrupted(_thread, _clear))  { \
3072+      os::Bsd::bump_interrupted_before_count(); \
3073+      _result = OS_INTRPT; \
3074+    } else { \
3075+      /* _cmd always expands to an assignment to _result */ \
3076+      if ((_cmd) < 0 && errno == EINTR  \
3077+       && os::is_interrupted(_thread, _clear)) { \
3078+        os::Bsd::bump_interrupted_during_count(); \
3079+        _result = OS_INTRPT; \
3080+      } \
3081+    } \
3082+  } else { \
3083+    /* this is normal blocking io stuff */ \
3084+    _cmd; \
3085+  } \
3086+  _after; \
3087+} while(false)
3088+
3089+// Interruptible io support + restarting of interrupted system calls
3090+
3091+#ifndef ASSERT
3092+
3093+#define INTERRUPTIBLE(_cmd, _result, _clear) do { \
3094+  _INTERRUPTIBLE( JavaThread* _thread = (JavaThread*)ThreadLocalStorage::thread(),_result = _cmd, _result, _thread, _clear, , , UseVMInterruptibleIO); \
3095+} while((_result == OS_ERR) && (errno == EINTR))
3096+
3097+#else
3098+
3099+// This adds an assertion that it is only called from thread_in_native
3100+// The call overhead is skipped for performance in product mode
3101+#define INTERRUPTIBLE(_cmd, _result, _clear) do { \
3102+  _INTERRUPTIBLE(JavaThread* _thread = os::Bsd::setup_interruptible_native(), _result = _cmd, _result, _thread, _clear, , os::Bsd::cleanup_interruptible_native(_thread), UseVMInterruptibleIO ); \
3103+} while((_result == OS_ERR) && (errno == EINTR))
3104+
3105+#endif
3106+
3107+// Used for calls from _thread_in_vm, not from _thread_in_native
3108+#define INTERRUPTIBLE_VM(_cmd, _result, _clear) do { \
3109+  _INTERRUPTIBLE(JavaThread* _thread = os::Bsd::setup_interruptible(), _result = _cmd, _result, _thread, _clear, , os::Bsd::cleanup_interruptible(_thread), UseVMInterruptibleIO ); \
3110+} while((_result == OS_ERR) && (errno == EINTR))
3111+
3112+/* Use NORESTART when the system call cannot return EINTR, when something other
3113+   than a system call is being invoked, or when the caller must do EINTR
3114+   handling. */
3115+
3116+#ifndef ASSERT
3117+
3118+#define INTERRUPTIBLE_NORESTART(_cmd, _result, _clear) \
3119+  _INTERRUPTIBLE( JavaThread* _thread = (JavaThread*)ThreadLocalStorage::thread(),_result = _cmd, _result, _thread, _clear, , , UseVMInterruptibleIO)
3120+
3121+#else
3122+
3123+// This adds an assertion that it is only called from thread_in_native
3124+// The call overhead is skipped for performance in product mode
3125+#define INTERRUPTIBLE_NORESTART(_cmd, _result, _clear) \
3126+  _INTERRUPTIBLE(JavaThread* _thread = os::Bsd::setup_interruptible_native(), _result = _cmd, _result, _thread, _clear, , os::Bsd::cleanup_interruptible_native(_thread), UseVMInterruptibleIO )
3127+
3128+#endif
3129+
3130+// Don't attend to UseVMInterruptibleIO. Always allow interruption.
3131+// Also assumes that it is called from the _thread_blocked state.
3132+// Used by os_sleep().
3133+
3134+#define INTERRUPTIBLE_NORESTART_VM_ALWAYS(_cmd, _result, _thread, _clear) \
3135+  _INTERRUPTIBLE(os::Bsd::setup_interruptible_already_blocked(_thread), _result = _cmd, _result, _thread, _clear, , , true )
3136+
3137+#define INTERRUPTIBLE_RETURN_INT(_cmd, _clear) do { \
3138+  int _result; \
3139+  do { \
3140+    INTERRUPTIBLE(_cmd, _result, _clear); \
3141+  } while((_result == OS_ERR) && (errno == EINTR)); \
3142+  return _result; \
3143+} while(false)
3144+
3145+#define INTERRUPTIBLE_RETURN_INT_VM(_cmd, _clear) do { \
3146+  int _result; \
3147+  do { \
3148+    INTERRUPTIBLE_VM(_cmd, _result, _clear); \
3149+  } while((_result == OS_ERR) && (errno == EINTR)); \
3150+  return _result; \
3151+} while(false)
3152+
3153+#define INTERRUPTIBLE_RETURN_INT_NORESTART(_cmd, _clear) do { \
3154+  int _result; \
3155+  INTERRUPTIBLE_NORESTART(_cmd, _result, _clear); \
3156+  return _result; \
3157+} while(false)
3158+
3159 // macros for restartable system calls
3160 
3161 #define RESTARTABLE(_cmd, _result) do { \
3162Only in ./hotspot/src/os_cpu/bsd_x86/vm: assembler_bsd_x86.cpp
3163diff -upr ../orig/hotspot/src/os_cpu/bsd_x86/vm/assembler_bsd_x86_64.cpp ./hotspot/src/os_cpu/bsd_x86/vm/assembler_bsd_x86_64.cpp
3164--- ../orig/hotspot/src/os_cpu/bsd_x86/vm/assembler_bsd_x86_64.cpp      2009-05-04 18:32:15.000000000 -0400
3165+++ ./hotspot/src/os_cpu/bsd_x86/vm/assembler_bsd_x86_64.cpp    2009-05-06 11:53:03.000000000 -0400
3166@@ -69,8 +69,9 @@ void MacroAssembler::get_thread(Register
3167    }
3168 }
3169 
3170-// NOTE: since the bsd kernel resides at the low end of
3171-// user address space, no null pointer check is needed.
3172 bool MacroAssembler::needs_explicit_null_check(int offset) {
3173-  return offset < 0 || offset >= 0x100000;
3174+  // Bsd kernel guarantees that the first page is always unmapped. Don't
3175+  // assume anything more than that.
3176+  bool offset_in_first_page =   0 <= offset  &&  offset < os::vm_page_size();
3177+  return !offset_in_first_page;
3178 }
3179diff -upr ../orig/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s ./hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s
3180--- ../orig/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s  2009-05-04 18:32:15.000000000 -0400
3181+++ ./hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_32.s        2009-05-04 17:37:17.000000000 -0400
3182@@ -21,49 +21,82 @@
3183 # have any questions.
3184 #
3185 
3186+
3187+
3188 .ident "@(#)bsd_x86_32.s       1.10 07/05/17 15:48:59 JVM"
3189-       
3190+
3191+#ifdef __APPLE__
3192+# Darwin uses _ prefixed global symbols
3193+#define SYMBOL(s) _ ## s
3194+#define ELF_TYPE(name, description)
3195+#else
3196+#define SYMBOL(s) s
3197+#define ELF_TYPE(name, description) .type name,description
3198+#endif
3199+
3200+        .globl SYMBOL(fixcw)
3201+
3202         # NOTE WELL!  The _Copy functions are called directly
3203        # from server-compiler-generated code via CallLeafNoFP,
3204        # which means that they *must* either not use floating
3205        # point or use it in the same manner as does the server
3206        # compiler.
3207       
3208-        .globl _Copy_conjoint_bytes
3209-        .globl _Copy_arrayof_conjoint_bytes
3210-        .globl _Copy_conjoint_jshorts_atomic
3211-       .globl _Copy_arrayof_conjoint_jshorts
3212-        .globl _Copy_conjoint_jints_atomic
3213-        .globl _Copy_arrayof_conjoint_jints
3214-       .globl _Copy_conjoint_jlongs_atomic
3215-       .globl _mmx_Copy_arrayof_conjoint_jshorts
3216+        .globl SYMBOL(_Copy_conjoint_bytes)
3217+        .globl SYMBOL(_Copy_arrayof_conjoint_bytes)
3218+        .globl SYMBOL(_Copy_conjoint_jshorts_atomic)
3219+       .globl SYMBOL(_Copy_arrayof_conjoint_jshorts)
3220+        .globl SYMBOL(_Copy_conjoint_jints_atomic)
3221+        .globl SYMBOL(_Copy_arrayof_conjoint_jints)
3222+       .globl SYMBOL(_Copy_conjoint_jlongs_atomic)
3223+       .globl SYMBOL(_mmx_Copy_arrayof_conjoint_jshorts)
3224 
3225-        .globl _Atomic_cmpxchg_long
3226+        .globl SYMBOL(_Atomic_cmpxchg_long)
3227 
3228        .text
3229 
3230-        .globl  SafeFetch32, Fetch32PFI, Fetch32Resume
3231-        .globl  SafeFetchN
3232+# Support for void os::Solaris::init_thread_fpu_state() in os_solaris_i486.cpp
3233+# Set fpu to 53 bit precision.  This happens too early to use a stub.
3234+# ported from solaris_x86_32.s
3235+#ifdef __APPLE__
3236+        .align   4
3237+#else
3238+       .align   16
3239+#endif
3240+SYMBOL(fixcw):
3241+       pushl    $0x27f
3242+       fldcw    0(%esp)
3243+       popl     %eax
3244+       ret
3245+
3246+#ifdef __APPLE__
3247+        .align   4
3248+#else
3249+        .align   16
3250+#endif
3251+
3252+        .globl  SYMBOL(SafeFetch32), SYMBOL(Fetch32PFI), SYMBOL(Fetch32Resume)
3253+        .globl  SYMBOL(SafeFetchN)
3254         ## TODO: avoid exposing Fetch32PFI and Fetch32Resume.
3255         ## Instead, the signal handler would call a new SafeFetchTriage(FaultingEIP)
3256         ## routine to vet the address.  If the address is the faulting LD then
3257         ## SafeFetchTriage() would return the resume-at EIP, otherwise null.
3258-       .type    SafeFetch32,@function
3259+       ELF_TYPE(SafeFetch32,@function)
3260         .p2align 4,,15
3261-SafeFetch32:
3262-SafeFetchN:
3263+SYMBOL(SafeFetch32):
3264+SYMBOL(SafeFetchN):
3265          movl    0x8(%esp), %eax
3266          movl    0x4(%esp), %ecx
3267-Fetch32PFI:
3268+SYMBOL(Fetch32PFI):
3269          movl    (%ecx), %eax
3270-Fetch32Resume:
3271+SYMBOL(Fetch32Resume):
3272          ret
3273 
3274 
3275-        .globl  SpinPause
3276-       .type   SpinPause,@function
3277+        .globl  SYMBOL(SpinPause)
3278+       ELF_TYPE(SpinPause,@function)
3279         .p2align 4,,15
3280-SpinPause:
3281+SYMBOL(SpinPause):
3282         rep
3283         nop
3284         movl    $1, %eax
3285@@ -73,8 +106,8 @@ SpinPause:
3286         #                                       void* to,
3287         #                                       size_t count)
3288         .p2align 4,,15
3289-       .type    _Copy_conjoint_bytes,@function
3290-_Copy_conjoint_bytes:
3291+       ELF_TYPE(_Copy_conjoint_bytes,@function)
3292+SYMBOL(_Copy_conjoint_bytes):
3293         pushl    %esi
3294         movl     4+12(%esp),%ecx      # count
3295         pushl    %edi
3296@@ -181,8 +214,8 @@ cb_CopyLeft:
3297         #
3298         # Same as _Copy_conjoint_bytes, except no source alignment check.
3299         .p2align 4,,15
3300-       .type    _Copy_arrayof_conjoint_bytes,@function
3301-_Copy_arrayof_conjoint_bytes:
3302+       ELF_TYPE(_Copy_arrayof_conjoint_bytes,@function)
3303+SYMBOL(_Copy_arrayof_conjoint_bytes):
3304         pushl    %esi
3305         movl     4+12(%esp),%ecx      # count
3306         pushl    %edi
3307@@ -269,8 +302,8 @@ acb_CopyLeft:
3308         #                                                void* to,
3309         #                                                size_t count)
3310         .p2align 4,,15
3311-       .type    _Copy_conjoint_jshorts_atomic,@function
3312-_Copy_conjoint_jshorts_atomic:
3313+       ELF_TYPE(_Copy_conjoint_jshorts_atomic,@function)
3314+SYMBOL(_Copy_conjoint_jshorts_atomic):
3315         pushl    %esi
3316         movl     4+12(%esp),%ecx      # count
3317         pushl    %edi
3318@@ -355,8 +388,8 @@ cs_CopyLeft:
3319         #                                                 void* to,
3320         #                                                 size_t count)
3321         .p2align 4,,15
3322-       .type    _Copy_arrayof_conjoint_jshorts,@function
3323-_Copy_arrayof_conjoint_jshorts:
3324+       ELF_TYPE(_Copy_arrayof_conjoint_jshorts,@function)
3325+SYMBOL(_Copy_arrayof_conjoint_jshorts):
3326         pushl    %esi
3327         movl     4+12(%esp),%ecx      # count
3328         pushl    %edi
3329@@ -432,10 +465,10 @@ acs_CopyLeft:
3330         # Equivalent to
3331         #   arrayof_conjoint_jints
3332         .p2align 4,,15
3333-       .type    _Copy_conjoint_jints_atomic,@function
3334-       .type    _Copy_arrayof_conjoint_jints,@function
3335-_Copy_conjoint_jints_atomic:
3336-_Copy_arrayof_conjoint_jints:
3337+       ELF_TYPE(_Copy_conjoint_jints_atomic,@function)
3338+       ELF_TYPE(_Copy_arrayof_conjoint_jints,@function)
3339+SYMBOL(_Copy_conjoint_jints_atomic):
3340+SYMBOL(_Copy_arrayof_conjoint_jints):
3341         pushl    %esi
3342         movl     4+12(%esp),%ecx      # count
3343         pushl    %edi
3344@@ -495,7 +528,7 @@ ci_CopyLeft:
3345         #
3346         # count treated as signed
3347         #
3348-        # if (from > to) {
3349+        # // if (from > to) {
3350         #   while (--count >= 0) {
3351         #     *to++ = *from++;
3352         #   }
3353@@ -505,8 +538,8 @@ ci_CopyLeft:
3354         #   }
3355         # }
3356         .p2align 4,,15
3357-       .type    _Copy_conjoint_jlongs_atomic,@function
3358-_Copy_conjoint_jlongs_atomic:
3359+       ELF_TYPE(_Copy_conjoint_jlongs_atomic,@function)
3360+SYMBOL(_Copy_conjoint_jlongs_atomic):
3361         movl     4+8(%esp),%ecx       # count
3362         movl     4+0(%esp),%eax       # from
3363         movl     4+4(%esp),%edx       # to
3364@@ -534,8 +567,8 @@ cla_CopyLeft:
3365         #                                                 void* to,
3366         #                                                 size_t count)
3367         .p2align 4,,15
3368-       .type    _mmx_Copy_arrayof_conjoint_jshorts,@function
3369-_mmx_Copy_arrayof_conjoint_jshorts:
3370+       ELF_TYPE(_mmx_Copy_arrayof_conjoint_jshorts,@function)
3371+SYMBOL(_mmx_Copy_arrayof_conjoint_jshorts):
3372         pushl    %esi
3373         movl     4+12(%esp),%ecx
3374         pushl    %edi
3375@@ -633,8 +666,8 @@ mmx_acs_CopyLeft:
3376         #                                   bool is_MP)
3377         #
3378         .p2align 4,,15
3379-       .type    _Atomic_cmpxchg_long,@function
3380-_Atomic_cmpxchg_long:
3381+       ELF_TYPE(_Atomic_cmpxchg_long,@function)
3382+SYMBOL(_Atomic_cmpxchg_long):
3383                                    #  8(%esp) : return PC
3384         pushl    %ebx              #  4(%esp) : old %ebx
3385         pushl    %edi              #  0(%esp) : old %edi
3386diff -upr ../orig/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s ./hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s
3387--- ../orig/hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s  2009-05-04 18:32:15.000000000 -0400
3388+++ ./hotspot/src/os_cpu/bsd_x86/vm/bsd_x86_64.s        2009-05-06 11:56:15.000000000 -0400
3389@@ -23,48 +23,70 @@
3390 
3391 .ident "@(#)bsd_x86_64.s       1.7 07/05/05 17:04:47 JVM"
3392 
3393+#ifdef __APPLE__
3394+# Darwin uses _ prefixed global symbols
3395+#define SYMBOL(s) _ ## s
3396+#define ELF_TYPE(name, description)
3397+#else
3398+#define SYMBOL(s) s
3399+#define ELF_TYPE(name, description) .type name,description
3400+#endif
3401+
3402+
3403         # NOTE WELL!  The _Copy functions are called directly
3404        # from server-compiler-generated code via CallLeafNoFP,
3405        # which means that they *must* either not use floating
3406        # point or use it in the same manner as does the server
3407        # compiler.
3408       
3409-        .globl _Copy_arrayof_conjoint_bytes
3410-       .globl _Copy_arrayof_conjoint_jshorts
3411-        .globl _Copy_conjoint_jshorts_atomic
3412-        .globl _Copy_arrayof_conjoint_jints
3413-        .globl _Copy_conjoint_jints_atomic
3414-        .globl _Copy_arrayof_conjoint_jlongs
3415-        .globl _Copy_conjoint_jlongs_atomic
3416+        .globl SYMBOL(_Copy_arrayof_conjoint_bytes)
3417+       .globl SYMBOL(_Copy_arrayof_conjoint_jshorts)
3418+        .globl SYMBOL(_Copy_conjoint_jshorts_atomic)
3419+        .globl SYMBOL(_Copy_arrayof_conjoint_jints)
3420+        .globl SYMBOL(_Copy_conjoint_jints_atomic)
3421+        .globl SYMBOL(_Copy_arrayof_conjoint_jlongs)
3422+        .globl SYMBOL(_Copy_conjoint_jlongs_atomic)
3423 
3424        .text
3425 
3426-        .globl SafeFetch32, Fetch32PFI, Fetch32Resume
3427+        .globl SYMBOL(SafeFetch32), SYMBOL(Fetch32PFI), SYMBOL(Fetch32Resume)
3428+#ifdef __APPLE__
3429+        .align  4
3430+#else
3431         .align  16
3432-        .type   SafeFetch32,@function
3433+#endif
3434+        ELF_TYPE(SafeFetch32,@function)
3435         // Prototype: int SafeFetch32 (int * Adr, int ErrValue)
3436-SafeFetch32:
3437+SYMBOL(SafeFetch32):
3438         movl    %esi, %eax
3439-Fetch32PFI:
3440+SYMBOL(Fetch32PFI):
3441         movl    (%rdi), %eax
3442-Fetch32Resume:
3443+SYMBOL(Fetch32Resume):
3444         ret
3445 
3446-        .globl SafeFetchN, FetchNPFI, FetchNResume
3447+        .globl SYMBOL(SafeFetchN), SYMBOL(FetchNPFI), SYMBOL(FetchNResume)
3448+#ifdef __APPLE__
3449+        .align  4
3450+#else
3451         .align  16
3452-        .type   SafeFetchN,@function
3453+#endif
3454+        ELF_TYPE(SafeFetchN,@function)
3455         // Prototype: intptr_t SafeFetchN (intptr_t * Adr, intptr_t ErrValue)
3456-SafeFetchN:
3457+SYMBOL(SafeFetchN):
3458         movq    %rsi, %rax
3459-FetchNPFI:
3460+SYMBOL(FetchNPFI):
3461         movq    (%rdi), %rax
3462-FetchNResume:
3463+SYMBOL(FetchNResume):
3464         ret
3465 
3466-        .globl SpinPause
3467-        .align 16
3468-        .type  SpinPause,@function
3469-SpinPause:
3470+        .globl SYMBOL(SpinPause)
3471+#ifdef __APPLE__
3472+        .align  4
3473+#else
3474+        .align  16
3475+#endif
3476+        ELF_TYPE(SpinPause,@function)
3477+SYMBOL(SpinPause):
3478         rep
3479         nop
3480         movq   $1, %rax
3481@@ -78,8 +100,8 @@ SpinPause:
3482         # rdx - count, treated as ssize_t
3483         #
3484         .p2align 4,,15
3485-       .type    _Copy_arrayof_conjoint_bytes,@function
3486-_Copy_arrayof_conjoint_bytes:
3487+       ELF_TYPE(_Copy_arrayof_conjoint_bytes,@function)
3488+SYMBOL(_Copy_arrayof_conjoint_bytes):
3489         movq     %rdx,%r8             # byte count
3490         shrq     $3,%rdx              # qword count
3491         cmpq     %rdi,%rsi
3492@@ -180,10 +202,10 @@ acb_CopyLeft:
3493         # rdx - count, treated as ssize_t
3494         #
3495         .p2align 4,,15
3496-       .type    _Copy_arrayof_conjoint_jshorts,@function
3497-       .type    _Copy_conjoint_jshorts_atomic,@function
3498-_Copy_arrayof_conjoint_jshorts:
3499-_Copy_conjoint_jshorts_atomic:
3500+       ELF_TYPE(_Copy_arrayof_conjoint_jshorts,@function)
3501+       ELF_TYPE(_Copy_conjoint_jshorts_atomic,@function)
3502+SYMBOL(_Copy_arrayof_conjoint_jshorts):
3503+SYMBOL(_Copy_conjoint_jshorts_atomic):
3504         movq     %rdx,%r8             # word count
3505         shrq     $2,%rdx              # qword count
3506         cmpq     %rdi,%rsi
3507@@ -270,10 +292,10 @@ acs_CopyLeft:
3508         # rdx - count, treated as ssize_t
3509         #
3510         .p2align 4,,15
3511-       .type    _Copy_arrayof_conjoint_jints,@function
3512-       .type    _Copy_conjoint_jints_atomic,@function
3513-_Copy_arrayof_conjoint_jints:
3514-_Copy_conjoint_jints_atomic:
3515+       ELF_TYPE(_Copy_arrayof_conjoint_jints,@function)
3516+       ELF_TYPE(_Copy_conjoint_jints_atomic,@function)
3517+SYMBOL(_Copy_arrayof_conjoint_jints):
3518+SYMBOL(_Copy_conjoint_jints_atomic):
3519         movq     %rdx,%r8             # dword count
3520         shrq     %rdx                 # qword count
3521         cmpq     %rdi,%rsi
3522@@ -349,10 +371,10 @@ aci_CopyLeft:
3523         # rdx - count, treated as ssize_t
3524         #
3525         .p2align 4,,15
3526-       .type    _Copy_arrayof_conjoint_jlongs,@function
3527-       .type    _Copy_conjoint_jlongs_atomic,@function
3528-_Copy_arrayof_conjoint_jlongs:
3529-_Copy_conjoint_jlongs_atomic:
3530+       ELF_TYPE(_Copy_arrayof_conjoint_jlongs,@function)
3531+       ELF_TYPE(_Copy_conjoint_jlongs_atomic,@function)
3532+SYMBOL(_Copy_arrayof_conjoint_jlongs):
3533+SYMBOL(_Copy_conjoint_jlongs_atomic):
3534         cmpq     %rdi,%rsi
3535         leaq     -8(%rdi,%rdx,8),%rax # from + count*8 - 8
3536         jbe      acl_CopyRight
3537diff -upr ../orig/hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp ./hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp
3538--- ../orig/hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp      2009-05-04 18:32:15.000000000 -0400
3539+++ ./hotspot/src/os_cpu/bsd_x86/vm/bytes_bsd_x86.inline.hpp    2009-05-06 12:15:02.000000000 -0400
3540@@ -25,7 +25,29 @@
3541  * 
3542  */
3543 
3544+#ifndef _ALLBSD_SOURCE
3545 #include <byteswap.h>
3546+#endif
3547+
3548+#ifdef __APPLE__
3549+#include <libkern/OSByteOrder.h>
3550+#endif
3551+
3552+#if defined(AMD64)
3553+#  if defined(__APPLE__)
3554+#    define bswap_16(x)        OSSwapInt16(x)
3555+#    define bswap_32(x)        OSSwapInt32(x)
3556+#    define bswap_64(x)        OSSwapInt64(x)
3557+#  elif defined(__OpenBSD__)
3558+#    define bswap_16(x)        swap16(x)
3559+#    define bswap_32(x)        swap32(x)
3560+#    define bswap_64(x)        swap64(x)
3561+#  else
3562+#    define bswap_16(x) __bswap16(x)
3563+#    define bswap_32(x) __bswap32(x)
3564+#    define bswap_64(x) __bswap64(x)
3565+#  endif
3566+#endif
3567 
3568 // Efficient swapping of data bytes from Java byte
3569 // ordering to native byte ordering and vice versa.
3570diff -upr ../orig/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp ./hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp
3571--- ../orig/hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp        2009-05-04 18:32:15.000000000 -0400
3572+++ ./hotspot/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp      2009-05-04 17:37:17.000000000 -0400
3573@@ -47,23 +47,158 @@
3574 # include <sys/wait.h>
3575 # include <pwd.h>
3576 # include <poll.h>
3577+#ifndef __OpenBSD__
3578 # include <ucontext.h>
3579-# include <fpu_control.h>
3580+#endif
3581+
3582+#if defined(_ALLBSD_SOURCE) && !defined(__APPLE__)
3583+# include <pthread_np.h>
3584+#endif
3585 
3586 #ifdef AMD64
3587-#define REG_SP REG_RSP
3588-#define REG_PC REG_RIP
3589-#define REG_FP REG_RBP
3590 #define SPELL_REG_SP "rsp"
3591 #define SPELL_REG_FP "rbp"
3592 #else
3593-#define REG_SP REG_UESP
3594-#define REG_PC REG_EIP
3595-#define REG_FP REG_EBP
3596 #define SPELL_REG_SP "esp"
3597 #define SPELL_REG_FP "ebp"
3598 #endif // AMD64
3599 
3600+#ifdef __FreeBSD__
3601+# define context_trapno uc_mcontext.mc_trapno
3602+# ifdef AMD64
3603+#  define context_pc uc_mcontext.mc_rip
3604+#  define context_sp uc_mcontext.mc_rsp
3605+#  define context_fp uc_mcontext.mc_rbp
3606+#  define context_rip uc_mcontext.mc_rip
3607+#  define context_rsp uc_mcontext.mc_rsp
3608+#  define context_rbp uc_mcontext.mc_rbp
3609+#  define context_rax uc_mcontext.mc_rax
3610+#  define context_rbx uc_mcontext.mc_rbx
3611+#  define context_rcx uc_mcontext.mc_rcx
3612+#  define context_rdx uc_mcontext.mc_rdx
3613+#  define context_rsi uc_mcontext.mc_rsi
3614+#  define context_rdi uc_mcontext.mc_rdi
3615+#  define context_r8  uc_mcontext.mc_r8
3616+#  define context_r9  uc_mcontext.mc_r9
3617+#  define context_r10 uc_mcontext.mc_r10
3618+#  define context_r11 uc_mcontext.mc_r11
3619+#  define context_r12 uc_mcontext.mc_r12
3620+#  define context_r13 uc_mcontext.mc_r13
3621+#  define context_r14 uc_mcontext.mc_r14
3622+#  define context_r15 uc_mcontext.mc_r15
3623+#  define context_flags uc_mcontext.mc_flags
3624+#  define context_err uc_mcontext.mc_err
3625+# else
3626+#  define context_pc uc_mcontext.mc_eip
3627+#  define context_sp uc_mcontext.mc_esp
3628+#  define context_fp uc_mcontext.mc_ebp
3629+#  define context_eip uc_mcontext.mc_eip
3630+#  define context_esp uc_mcontext.mc_esp
3631+#  define context_eax uc_mcontext.mc_eax
3632+#  define context_ebx uc_mcontext.mc_ebx
3633+#  define context_ecx uc_mcontext.mc_ecx
3634+#  define context_edx uc_mcontext.mc_edx
3635+#  define context_ebp uc_mcontext.mc_ebp
3636+#  define context_esi uc_mcontext.mc_esi
3637+#  define context_edi uc_mcontext.mc_edi
3638+#  define context_eflags uc_mcontext.mc_eflags
3639+#  define context_trapno uc_mcontext.mc_trapno
3640+# endif
3641+#endif
3642+
3643+#ifdef __APPLE__
3644+# if __DARWIN_UNIX03 && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
3645+  // 10.5 UNIX03 member name prefixes
3646+  #define DU3_PREFIX(s, m) __ ## s.__ ## m
3647+# else
3648+  #define DU3_PREFIX(s, m) s ## . ## m
3649+# endif
3650+
3651+# ifdef AMD64
3652+#  define context_pc context_rip
3653+#  define context_sp context_rsp
3654+#  define context_fp context_rbp
3655+#  define context_rip uc_mcontext->DU3_PREFIX(ss,rip)
3656+#  define context_rsp uc_mcontext->DU3_PREFIX(ss,rsp)
3657+#  define context_rax uc_mcontext->DU3_PREFIX(ss,rax)
3658+#  define context_rbx uc_mcontext->DU3_PREFIX(ss,rbx)
3659+#  define context_rcx uc_mcontext->DU3_PREFIX(ss,rcx)
3660+#  define context_rdx uc_mcontext->DU3_PREFIX(ss,rdx)
3661+#  define context_rbp uc_mcontext->DU3_PREFIX(ss,rbp)
3662+#  define context_rsi uc_mcontext->DU3_PREFIX(ss,rsi)
3663+#  define context_rdi uc_mcontext->DU3_PREFIX(ss,rdi)
3664+#  define context_r8  uc_mcontext->DU3_PREFIX(ss,r8)
3665+#  define context_r9  uc_mcontext->DU3_PREFIX(ss,r9)
3666+#  define context_r10 uc_mcontext->DU3_PREFIX(ss,r10)
3667+#  define context_r11 uc_mcontext->DU3_PREFIX(ss,r11)
3668+#  define context_r12 uc_mcontext->DU3_PREFIX(ss,r12)
3669+#  define context_r13 uc_mcontext->DU3_PREFIX(ss,r13)
3670+#  define context_r14 uc_mcontext->DU3_PREFIX(ss,r14)
3671+#  define context_r15 uc_mcontext->DU3_PREFIX(ss,r15)
3672+#  define context_flags uc_mcontext->DU3_PREFIX(ss,rflags)
3673+#  define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
3674+#  define context_err uc_mcontext->DU3_PREFIX(es,err)
3675+# else
3676+#  define context_pc context_eip
3677+#  define context_sp context_esp
3678+#  define context_fp context_ebp
3679+#  define context_eip uc_mcontext->DU3_PREFIX(ss,eip)
3680+#  define context_esp uc_mcontext->DU3_PREFIX(ss,esp)
3681+#  define context_eax uc_mcontext->DU3_PREFIX(ss,eax)
3682+#  define context_ebx uc_mcontext->DU3_PREFIX(ss,ebx)
3683+#  define context_ecx uc_mcontext->DU3_PREFIX(ss,ecx)
3684+#  define context_edx uc_mcontext->DU3_PREFIX(ss,edx)
3685+#  define context_ebp uc_mcontext->DU3_PREFIX(ss,ebp)
3686+#  define context_esi uc_mcontext->DU3_PREFIX(ss,esi)
3687+#  define context_edi uc_mcontext->DU3_PREFIX(ss,edi)
3688+#  define context_eflags uc_mcontext->DU3_PREFIX(ss,eflags)
3689+#  define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
3690+# endif
3691+#endif
3692+
3693+#ifdef __OpenBSD__
3694+# define context_trapno sc_trapno
3695+# ifdef AMD64
3696+#  define context_pc sc_rip
3697+#  define context_sp sc_rsp
3698+#  define context_fp sc_rbp
3699+#  define context_rip sc_rip
3700+#  define context_rsp sc_rsp
3701+#  define context_rbp sc_rbp
3702+#  define context_rax sc_rax
3703+#  define context_rbx sc_rbx
3704+#  define context_rcx sc_rcx
3705+#  define context_rdx sc_rdx
3706+#  define context_rsi sc_rsi
3707+#  define context_rdi sc_rdi
3708+#  define context_r8  sc_r8
3709+#  define context_r9  sc_r9
3710+#  define context_r10 sc_r10
3711+#  define context_r11 sc_r11
3712+#  define context_r12 sc_r12
3713+#  define context_r13 sc_r13
3714+#  define context_r14 sc_r14
3715+#  define context_r15 sc_r15
3716+#  define context_flags sc_rflags
3717+#  define context_err sc_err
3718+# else
3719+#  define context_pc sc_eip
3720+#  define context_sp sc_esp
3721+#  define context_fp sc_ebp
3722+#  define context_eip sc_eip
3723+#  define context_esp sc_esp
3724+#  define context_eax sc_eax
3725+#  define context_ebx sc_ebx
3726+#  define context_ecx sc_ecx
3727+#  define context_edx sc_edx
3728+#  define context_ebp sc_ebp
3729+#  define context_esi sc_esi
3730+#  define context_edi sc_edi
3731+#  define context_eflags sc_eflags
3732+#  define context_trapno sc_trapno
3733+# endif
3734+#endif
3735+
3736 address os::current_stack_pointer() {
3737   register void *esp __asm__ (SPELL_REG_SP);
3738   return (address) esp;
3739@@ -82,15 +217,15 @@ void os::initialize_thread() {
3740 }
3741 
3742 address os::Bsd::ucontext_get_pc(ucontext_t * uc) {
3743-  return (address)uc->uc_mcontext.gregs[REG_PC];
3744+  return (address)uc->context_pc;
3745 }
3746 
3747 intptr_t* os::Bsd::ucontext_get_sp(ucontext_t * uc) {
3748-  return (intptr_t*)uc->uc_mcontext.gregs[REG_SP];
3749+  return (intptr_t*)uc->context_sp;
3750 }
3751 
3752 intptr_t* os::Bsd::ucontext_get_fp(ucontext_t * uc) {
3753-  return (intptr_t*)uc->uc_mcontext.gregs[REG_FP];
3754+  return (intptr_t*)uc->context_fp;
3755 }
3756 
3757 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
3758@@ -237,18 +372,18 @@ JVM_handle_bsd_signal(int sig,
3759     pc = (address) os::Bsd::ucontext_get_pc(uc);
3760 
3761     if (pc == (address) Fetch32PFI) {
3762-       uc->uc_mcontext.gregs[REG_PC] = intptr_t(Fetch32Resume) ;
3763+       uc->context_pc = intptr_t(Fetch32Resume) ;
3764        return 1 ; 
3765     }
3766 #ifdef AMD64
3767     if (pc == (address) FetchNPFI) {
3768-       uc->uc_mcontext.gregs[REG_PC] = intptr_t (FetchNResume) ;
3769+       uc->context_pc = intptr_t (FetchNResume) ;
3770        return 1 ;
3771     }
3772 #endif // AMD64
3773 
3774     // Handle ALL stack overflow variations here
3775-    if (sig == SIGSEGV) {
3776+    if (sig == SIGSEGV || sig == SIGBUS) {
3777       address addr = (address) info->si_addr;
3778 
3779       // check if fault address is within thread stack
3780@@ -270,6 +405,7 @@ JVM_handle_bsd_signal(int sig,
3781           // to handle_unexpected_exception way down below.
3782           thread->disable_stack_red_zone();
3783           tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
3784+#ifndef _ALLBSD_SOURCE
3785         } else {
3786           // Accessing stack address below sp may cause SEGV if current
3787           // thread has MAP_GROWSDOWN stack. This should only happen when
3788@@ -285,6 +421,7 @@ JVM_handle_bsd_signal(int sig,
3789           } else {
3790              fatal("recursive segv. expanding stack.");
3791           }
3792+#endif
3793         }
3794       }
3795     }
3796@@ -293,9 +430,16 @@ JVM_handle_bsd_signal(int sig,
3797       // Java thread running in Java code => find exception handler if any
3798       // a fault inside compiled code, the interpreter, or a stub
3799 
3800-      if (sig == SIGSEGV && os::is_poll_address((address)info->si_addr)) {
3801+      if ((sig == SIGSEGV || sig == SIGBUS) && os::is_poll_address((address)info->si_addr)) {
3802         stub = SharedRuntime::get_poll_stub(pc);
3803+#if defined(__APPLE__) && !defined(AMD64)
3804+      // 32-bit Darwin reports a SIGBUS for nearly all memory access exceptions.
3805+      // Catching SIGBUS here prevents the implicit SIGBUS NULL check below from
3806+      // being called, so only do so if the implicit NULL check is not necessary.
3807+      } else if (sig == SIGBUS && MacroAssembler::needs_explicit_null_check((int)info->si_addr)) {
3808+#else
3809       } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
3810+#endif
3811        // BugId 4454115: A read from a MappedByteBuffer can fault
3812        // here if the underlying file has been truncated.
3813        // Do not crash the VM in such a case.
3814@@ -316,6 +460,28 @@ JVM_handle_bsd_signal(int sig,
3815                                               pc,
3816                                               SharedRuntime::
3817                                               IMPLICIT_DIVIDE_BY_ZERO);
3818+#ifdef __APPLE__
3819+      } else if (sig == SIGFPE && info->si_code == FPE_NOOP) {
3820+        int op = pc[0];
3821+
3822+        // Skip REX
3823+        if ((pc[0] & 0xf0) == 0x40) {
3824+          op = pc[1];
3825+        } else {
3826+          op = pc[0];
3827+        }
3828+
3829+        // Check for IDIV
3830+        if (op == 0xF7) {
3831+          stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime:: IMPLICIT_DIVIDE_BY_ZERO);
3832+        } else {
3833+          // TODO: handle more cases if we are using other x86 instructions
3834+          //   that can generate SIGFPE signal.
3835+          tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
3836+          fatal("please update this code.");
3837+        }
3838+#endif /* __APPLE__ */
3839+
3840 #else
3841       if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
3842         // HACK: si_code does not work on bsd 2.2.12-20!!!
3843@@ -343,7 +509,7 @@ JVM_handle_bsd_signal(int sig,
3844           fatal("please update this code.");
3845         }
3846 #endif // AMD64
3847-      } else if (sig == SIGSEGV &&
3848+      } else if ((sig == SIGSEGV || sig == SIGBUS) &&
3849                !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
3850           // Determination of interpreter/vtable stub/compiled code null exception
3851           stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
3852@@ -367,7 +533,7 @@ JVM_handle_bsd_signal(int sig,
3853     // process of write protecting the memory serialization page.
3854     // It write enables the page immediately after protecting it
3855     // so we can just return to retry the write.
3856-    if ((sig == SIGSEGV) &&
3857+    if ((sig == SIGSEGV || sig == SIGBUS) &&
3858         os::is_memory_serialize_page(thread, (address) info->si_addr)) {
3859       // Block current thread until the memory serialize page permission restored.
3860       os::block_on_serialize_page_trap();
3861@@ -388,7 +554,7 @@ JVM_handle_bsd_signal(int sig,
3862   // Furthermore, a false-positive should be harmless.
3863   if (UnguardOnExecutionViolation > 0 &&
3864       (sig == SIGSEGV || sig == SIGBUS) &&
3865-      uc->uc_mcontext.gregs[REG_TRAPNO] == trap_page_fault) {
3866+      uc->context_trapno == trap_page_fault) {
3867     int page_size = os::vm_page_size();
3868     address addr = (address) info->si_addr;
3869     address pc = os::Bsd::ucontext_get_pc(uc);
3870@@ -457,7 +623,7 @@ JVM_handle_bsd_signal(int sig,
3871     // save all thread context in case we need to restore it
3872     if (thread != NULL) thread->set_saved_exception_pc(pc);
3873 
3874-    uc->uc_mcontext.gregs[REG_PC] = (greg_t)stub;
3875+    uc->context_pc = (intptr_t)stub;
3876     return true;
3877   }
3878 
3879@@ -487,13 +653,24 @@ JVM_handle_bsd_signal(int sig,
3880   ShouldNotReachHere();
3881 }
3882 
3883+#ifdef _ALLBSD_SOURCE
3884+// From solaris_i486.s ported to bsd_i486.s
3885+extern "C" void fixcw();
3886+#endif
3887+
3888 void os::Bsd::init_thread_fpu_state(void) {
3889 #ifndef AMD64
3890+# ifdef _ALLBSD_SOURCE
3891+  // Set fpu to 53 bit precision. This happens too early to use a stub.
3892+  fixcw();
3893+# else
3894   // set fpu to 53 bit precision
3895   set_fpu_control_word(0x27f);
3896+# endif
3897 #endif // !AMD64
3898 }
3899 
3900+#ifndef _ALLBSD_SOURCE
3901 int os::Bsd::get_fpu_control_word(void) {
3902 #ifdef AMD64
3903   return 0;
3904@@ -509,11 +686,12 @@ void os::Bsd::set_fpu_control_word(int f
3905   _FPU_SETCW(fpu_control);
3906 #endif // !AMD64
3907 }
3908+#endif
3909 
3910 // Check that the bsd kernel version is 2.4 or higher since earlier
3911 // versions do not support SSE without patches.
3912 bool os::supports_sse() {
3913-#ifdef AMD64
3914+#if defined(AMD64) || defined(_ALLBSD_SOURCE)
3915   return true;
3916 #else
3917   struct utsname uts;
3918@@ -565,8 +743,11 @@ size_t os::Bsd::min_stack_allowed  =  (4
3919 
3920 #define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
3921 
3922+#ifdef _ALLBSD_SOURCE
3923+bool os::Bsd::supports_variable_stack_size() { return true; }
3924+#else
3925 // Test if pthread library can support variable thread stack size. BsdThreads
3926-// in fixed stack mode allocates 2M fixed slot for each thread. BsdThreads
3927+// in fixed stack mode allocates 2M fixed slot for each thread. BsdThreads
3928 // in floating stack mode and NPTL support variable stack size.
3929 bool os::Bsd::supports_variable_stack_size() {
3930   if (os::Bsd::is_NPTL()) {
3931@@ -597,6 +778,7 @@ bool os::Bsd::supports_variable_stack_si
3932     return (GET_GS() != 0);
3933   }
3934 }
3935+#endif
3936 #endif // AMD64
3937 
3938 // return default stack size for thr_type
3939@@ -650,6 +832,41 @@ size_t os::Bsd::default_guard_size(os::T
3940 //    pthread_attr_getstack()
3941 
3942 static void current_stack_region(address * bottom, size_t * size) {
3943+#ifdef __APPLE__
3944+  pthread_t self = pthread_self();
3945+  void *stacktop = pthread_get_stackaddr_np(self);
3946+  *size = pthread_get_stacksize_np(self);
3947+  *bottom = (address) stacktop - *size;
3948+#elif defined(__OpenBSD__)
3949+  stack_t ss;
3950+  int rslt = pthread_stackseg_np(pthread_self(), &ss);
3951+
3952+  if (rslt != 0)
3953+    fatal1("pthread_stackseg_np failed with err = %d", rslt);
3954+
3955+  *bottom = (address)((char *)ss.ss_sp - ss.ss_size);
3956+  *size   = ss.ss_size;
3957+#elif defined(_ALLBSD_SOURCE)
3958+  pthread_attr_t attr;
3959+
3960+  int rslt = pthread_attr_init(&attr);
3961+
3962+  // JVM needs to know exact stack location, abort if it fails
3963+  if (rslt != 0)
3964+    fatal1("pthread_attr_init failed with err = %d", rslt);
3965+
3966+  rslt = pthread_attr_get_np(pthread_self(), &attr);
3967+
3968+  if (rslt != 0)
3969+    fatal1("pthread_attr_get_np failed with err = %d", rslt);
3970+
3971+  if (pthread_attr_getstackaddr(&attr, (void **)bottom) != 0 ||
3972+    pthread_attr_getstacksize(&attr, size) != 0) {
3973+    fatal("Can not locate current stack attributes!");
3974+  }
3975+
3976+  pthread_attr_destroy(&attr);
3977+#else
3978   if (os::Bsd::is_initial_thread()) {
3979      // initial thread needs special handling because pthread_getattr_np()
3980      // may return bogus value.
3981@@ -676,6 +893,7 @@ static void current_stack_region(address
3982      pthread_attr_destroy(&attr);
3983 
3984   }
3985+#endif
3986   assert(os::current_stack_pointer() >= *bottom &&
3987          os::current_stack_pointer() < *bottom + *size, "just checking");
3988 }
3989@@ -704,46 +922,44 @@ void os::print_context(outputStream *st,
3990   ucontext_t *uc = (ucontext_t*)context;
3991   st->print_cr("Registers:");
3992 #ifdef AMD64
3993-  st->print(  "RAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RAX]);
3994-  st->print(", RBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBX]);
3995-  st->print(", RCX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RCX]);
3996-  st->print(", RDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDX]);
3997+  st->print(  "RAX=" INTPTR_FORMAT, uc->context_rax);
3998+  st->print(", RBX=" INTPTR_FORMAT, uc->context_rbx);
3999+  st->print(", RCX=" INTPTR_FORMAT, uc->context_rcx);
4000+  st->print(", RDX=" INTPTR_FORMAT, uc->context_rdx);
4001   st->cr();
4002-  st->print(  "RSP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSP]);
4003-  st->print(", RBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RBP]);
4004-  st->print(", RSI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RSI]);
4005-  st->print(", RDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RDI]);
4006+  st->print(  "RSP=" INTPTR_FORMAT, uc->context_rsp);
4007+  st->print(", RBP=" INTPTR_FORMAT, uc->context_rbp);
4008+  st->print(", RSI=" INTPTR_FORMAT, uc->context_rsi);
4009+  st->print(", RDI=" INTPTR_FORMAT, uc->context_rdi);
4010   st->cr();
4011-  st->print(  "R8 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R8]);
4012-  st->print(", R9 =" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R9]);
4013-  st->print(", R10=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R10]);
4014-  st->print(", R11=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R11]);
4015+  st->print(  "R8 =" INTPTR_FORMAT, uc->context_r8);
4016+  st->print(", R9 =" INTPTR_FORMAT, uc->context_r9);
4017+  st->print(", R10=" INTPTR_FORMAT, uc->context_r10);
4018+  st->print(", R11=" INTPTR_FORMAT, uc->context_r11);
4019   st->cr();
4020-  st->print(  "R12=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R12]);
4021-  st->print(", R13=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R13]);
4022-  st->print(", R14=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R14]);
4023-  st->print(", R15=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_R15]);
4024+  st->print(  "R12=" INTPTR_FORMAT, uc->context_r12);
4025+  st->print(", R13=" INTPTR_FORMAT, uc->context_r13);
4026+  st->print(", R14=" INTPTR_FORMAT, uc->context_r14);
4027+  st->print(", R15=" INTPTR_FORMAT, uc->context_r15);
4028   st->cr();
4029-  st->print(  "RIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_RIP]);
4030-  st->print(", EFL=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]);
4031-  st->print(", CSGSFS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_CSGSFS]);
4032-  st->print(", ERR=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ERR]);
4033+  st->print(  "RIP=" INTPTR_FORMAT, uc->context_rip);
4034+  st->print(", EFL=" INTPTR_FORMAT, uc->context_flags);
4035+  st->print(", ERR=" INTPTR_FORMAT, uc->context_err);
4036   st->cr();
4037-  st->print("  TRAPNO=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_TRAPNO]);
4038+  st->print("  TRAPNO=" INTPTR_FORMAT, uc->context_trapno);
4039 #else
4040-  st->print(  "EAX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EAX]);
4041-  st->print(", EBX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EBX]);
4042-  st->print(", ECX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ECX]);
4043-  st->print(", EDX=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EDX]);
4044+  st->print(  "EAX=" INTPTR_FORMAT, uc->context_eax);
4045+  st->print(", EBX=" INTPTR_FORMAT, uc->context_ebx);
4046+  st->print(", ECX=" INTPTR_FORMAT, uc->context_ecx);
4047+  st->print(", EDX=" INTPTR_FORMAT, uc->context_edx);
4048   st->cr();
4049-  st->print(  "ESP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_UESP]);
4050-  st->print(", EBP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EBP]);
4051-  st->print(", ESI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_ESI]);
4052-  st->print(", EDI=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EDI]);
4053+  st->print(  "ESP=" INTPTR_FORMAT, uc->context_esp);
4054+  st->print(", EBP=" INTPTR_FORMAT, uc->context_ebp);
4055+  st->print(", ESI=" INTPTR_FORMAT, uc->context_esi);
4056+  st->print(", EDI=" INTPTR_FORMAT, uc->context_edi);
4057   st->cr();
4058-  st->print(  "EIP=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EIP]);
4059-  st->print(", CR2=" INTPTR_FORMAT, uc->uc_mcontext.cr2);
4060-  st->print(", EFLAGS=" INTPTR_FORMAT, uc->uc_mcontext.gregs[REG_EFL]);
4061+  st->print(  "EIP=" INTPTR_FORMAT, uc->context_eip);
4062+  st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_eflags);
4063 #endif // AMD64
4064   st->cr();
4065   st->cr();
4066diff -upr ../orig/hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp ./hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp
4067--- ../orig/hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp  2009-05-04 18:32:15.000000000 -0400
4068+++ ./hotspot/src/os_cpu/bsd_x86/vm/threadLS_bsd_x86.hpp        2009-05-06 12:03:40.000000000 -0400
4069@@ -30,8 +30,10 @@
4070 #ifndef AMD64
4071   // map stack pointer to thread pointer - see notes in threadLS_bsd_x86.cpp
4072   #define SP_BITLENGTH  32
4073+#ifndef PAGE_SHIFT
4074   #define PAGE_SHIFT    12
4075   #define PAGE_SIZE     (1UL << PAGE_SHIFT)
4076+#endif
4077   static Thread* _sp_map[1UL << (SP_BITLENGTH - PAGE_SHIFT)];
4078 #endif // !AMD64
4079 
4080diff -upr ../orig/hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp ./hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp
4081--- ../orig/hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp 2009-05-04 18:32:15.000000000 -0400
4082+++ ./hotspot/src/os_cpu/bsd_x86/vm/vmStructs_bsd_x86.hpp       2009-05-06 12:04:27.000000000 -0400
4083@@ -34,7 +34,7 @@
4084   /******************************/                                                                                                   \
4085   /* Threads (NOTE: incomplete) */                                                                                                   \
4086   /******************************/                                                                                                   \
4087-  nonstatic_field(OSThread,                      _thread_id,                                      pid_t)                             \
4088+  nonstatic_field(OSThread,                      _thread_id,                                      pthread_t)                             \
4089   nonstatic_field(OSThread,                      _pthread_id,                                     pthread_t)                         \
4090   /* This must be the last entry, and must be present */                                                                             \
4091   last_entry()
4092diff -upr ../orig/hotspot/src/share/vm/adlc/adlc.hpp ./hotspot/src/share/vm/adlc/adlc.hpp
4093--- ../orig/hotspot/src/share/vm/adlc/adlc.hpp  2009-01-27 15:41:01.000000000 -0500
4094+++ ./hotspot/src/share/vm/adlc/adlc.hpp        2009-05-04 17:37:15.000000000 -0400
4095@@ -76,9 +76,9 @@ typedef unsigned int uintptr_t;
4096 #endif
4097 #endif // _WIN32
4098 
4099-#ifdef LINUX
4100+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
4101   #include <inttypes.h>
4102-#endif // LINUX
4103+#endif // LINUX || _ALLBSD_SOURCE
4104 
4105 // Macros
4106 #define uint32 unsigned int
4107diff -upr ../orig/hotspot/src/share/vm/gc_implementation/includeDB_gc_concurrentMarkSweep ./hotspot/src/share/vm/gc_implementation/includeDB_gc_concurrentMarkSweep
4108--- ../orig/hotspot/src/share/vm/gc_implementation/includeDB_gc_concurrentMarkSweep     2009-01-27 15:41:01.000000000 -0500
4109+++ ./hotspot/src/share/vm/gc_implementation/includeDB_gc_concurrentMarkSweep   2009-05-04 17:37:17.000000000 -0400
4110@@ -28,6 +28,7 @@ binaryTreeDictionary.cpp               
4111 binaryTreeDictionary.cpp                binaryTreeDictionary.hpp
4112 binaryTreeDictionary.cpp                globals.hpp
4113 binaryTreeDictionary.cpp                ostream.hpp
4114+binaryTreeDictionary.cpp                space.inline.hpp
4115 
4116 binaryTreeDictionary.hpp                freeBlockDictionary.hpp
4117 binaryTreeDictionary.hpp                freeList.hpp
4118diff -upr ../orig/hotspot/src/share/vm/gc_implementation/includeDB_gc_parNew ./hotspot/src/share/vm/gc_implementation/includeDB_gc_parNew
4119--- ../orig/hotspot/src/share/vm/gc_implementation/includeDB_gc_parNew  2009-01-27 15:41:01.000000000 -0500
4120+++ ./hotspot/src/share/vm/gc_implementation/includeDB_gc_parNew        2009-05-04 17:37:17.000000000 -0400
4121@@ -30,6 +30,8 @@ asParNewGeneration.cpp                        cmsAdaptiveSize
4122 asParNewGeneration.cpp                  cmsGCAdaptivePolicyCounters.hpp
4123 asParNewGeneration.cpp                 defNewGeneration.inline.hpp
4124 asParNewGeneration.cpp                 oop.pcgc.inline.hpp
4125+asParNewGeneration.cpp                  markOop.inline.hpp
4126+asParNewGeneration.cpp                  markSweep.inline.hpp
4127 asParNewGeneration.cpp                 parNewGeneration.hpp
4128 asParNewGeneration.cpp                  referencePolicy.hpp
4129 
4130@@ -39,7 +41,7 @@ parCardTableModRefBS.cpp               
4131 parCardTableModRefBS.cpp                java.hpp
4132 parCardTableModRefBS.cpp                mutexLocker.hpp
4133 parCardTableModRefBS.cpp                sharedHeap.hpp
4134-parCardTableModRefBS.cpp                space.hpp
4135+parCardTableModRefBS.cpp                space.inline.hpp
4136 parCardTableModRefBS.cpp                universe.hpp
4137 parCardTableModRefBS.cpp                virtualspace.hpp
4138 
4139diff -upr ../orig/hotspot/src/share/vm/gc_implementation/includeDB_gc_parallelScavenge ./hotspot/src/share/vm/gc_implementation/includeDB_gc_parallelScavenge
4140--- ../orig/hotspot/src/share/vm/gc_implementation/includeDB_gc_parallelScavenge        2009-01-27 15:41:01.000000000 -0500
4141+++ ./hotspot/src/share/vm/gc_implementation/includeDB_gc_parallelScavenge      2009-05-04 17:37:15.000000000 -0400
4142@@ -302,6 +302,8 @@ psPermGen.cpp                           
4143 psPermGen.cpp                           psMarkSweepDecorator.hpp
4144 psPermGen.cpp                           psParallelCompact.hpp
4145 psPermGen.cpp                           psPermGen.hpp
4146+psPermGen.cpp                           markOop.inline.hpp
4147+psPermGen.cpp                           markSweep.inline.hpp
4148 
4149 psPermGen.hpp                           psOldGen.hpp
4150 
4151diff -upr ../orig/hotspot/src/share/vm/includeDB_compiler2 ./hotspot/src/share/vm/includeDB_compiler2
4152--- ../orig/hotspot/src/share/vm/includeDB_compiler2    2009-01-27 15:41:02.000000000 -0500
4153+++ ./hotspot/src/share/vm/includeDB_compiler2  2009-05-04 17:37:15.000000000 -0400
4154@@ -140,6 +140,7 @@ c2_globals_<os_family>.hpp             
4155 c2_globals_<os_family>.hpp              macros.hpp
4156 
4157 c2_init_<arch>.cpp                      compile.hpp
4158+c2_init_<arch>.cpp                      node.hpp
4159 
4160 c2compiler.cpp                          ad_<arch_model>.hpp
4161 c2compiler.cpp                          c2compiler.hpp
4162@@ -833,6 +834,7 @@ parseHelper.cpp                         
4163 phase.cpp                               compile.hpp
4164 phase.cpp                               compileBroker.hpp
4165 phase.cpp                               nmethod.hpp
4166+phase.cpp                               node.hpp
4167 phase.cpp                               phase.hpp
4168 
4169 phase.hpp                               port.hpp
4170diff -upr ../orig/hotspot/src/share/vm/includeDB_core ./hotspot/src/share/vm/includeDB_core
4171--- ../orig/hotspot/src/share/vm/includeDB_core 2009-01-27 15:41:02.000000000 -0500
4172+++ ./hotspot/src/share/vm/includeDB_core       2009-05-04 17:37:15.000000000 -0400
4173@@ -476,7 +476,7 @@ cardTableModRefBS.cpp                   
4174 cardTableModRefBS.cpp                   java.hpp
4175 cardTableModRefBS.cpp                   mutexLocker.hpp
4176 cardTableModRefBS.cpp                   sharedHeap.hpp
4177-cardTableModRefBS.cpp                   space.hpp
4178+cardTableModRefBS.cpp                   space.inline.hpp
4179 cardTableModRefBS.cpp                   universe.hpp
4180 cardTableModRefBS.cpp                   virtualspace.hpp
4181 
4182@@ -1978,7 +1978,7 @@ instanceKlass.cpp                       
4183 instanceKlass.cpp                       vmSymbols.hpp
4184 
4185 instanceKlass.hpp                       accessFlags.hpp
4186-instanceKlass.hpp                       bitMap.hpp
4187+instanceKlass.hpp                       bitMap.inline.hpp
4188 instanceKlass.hpp                       constMethodOop.hpp
4189 instanceKlass.hpp                       constantPoolOop.hpp
4190 instanceKlass.hpp                       handles.hpp
4191diff -upr ../orig/hotspot/src/share/vm/includeDB_features ./hotspot/src/share/vm/includeDB_features
4192--- ../orig/hotspot/src/share/vm/includeDB_features     2009-01-27 15:41:02.000000000 -0500
4193+++ ./hotspot/src/share/vm/includeDB_features   2009-05-04 17:37:15.000000000 -0400
4194@@ -58,6 +58,8 @@ dump.cpp                               
4195 
4196 dump_<arch_model>.cpp                   assembler_<arch_model>.inline.hpp
4197 dump_<arch_model>.cpp                   compactingPermGenGen.hpp
4198+dump_<arch_model>.cpp                   generation.inline.hpp
4199+dump_<arch_model>.cpp                   space.inline.hpp
4200 
4201 forte.cpp                               collectedHeap.inline.hpp
4202 forte.cpp                               debugInfoRec.hpp
4203diff -upr ../orig/hotspot/src/share/vm/interpreter/bytecodeTracer.cpp ./hotspot/src/share/vm/interpreter/bytecodeTracer.cpp
4204--- ../orig/hotspot/src/share/vm/interpreter/bytecodeTracer.cpp 2009-01-27 15:41:02.000000000 -0500
4205+++ ./hotspot/src/share/vm/interpreter/bytecodeTracer.cpp       2009-05-04 17:37:15.000000000 -0400
4206@@ -77,7 +77,7 @@ class BytecodePrinter: public BytecodeCl
4207       // the incoming method.  We could lose a line of trace output.
4208       // This is acceptable in a debug-only feature.
4209       st->cr();
4210-      st->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
4211+      st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
4212       method->print_name(st);
4213       st->cr();
4214       _current_method = method();
4215@@ -90,7 +90,7 @@ class BytecodePrinter: public BytecodeCl
4216       code = Bytecodes::code_at(bcp);
4217     }
4218     int bci = bcp - method->code_base();
4219-    st->print("[%d] ", (int) Thread::current()->osthread()->thread_id());
4220+    st->print("[%ld] ", (long) Thread::current()->osthread()->thread_id());
4221     if (Verbose) {
4222       st->print("%8d  %4d  " INTPTR_FORMAT " " INTPTR_FORMAT " %s",
4223           BytecodeCounter::counter_value(), bci, tos, tos2, Bytecodes::name(code));
4224diff -upr ../orig/hotspot/src/share/vm/prims/forte.cpp ./hotspot/src/share/vm/prims/forte.cpp
4225--- ../orig/hotspot/src/share/vm/prims/forte.cpp        2009-01-27 15:41:03.000000000 -0500
4226+++ ./hotspot/src/share/vm/prims/forte.cpp      2009-05-04 17:37:15.000000000 -0400
4227@@ -872,6 +872,11 @@ void AsyncGetCallTrace(ASGCT_CallTrace *
4228 // Method to let libcollector know about a dynamically loaded function.
4229 // Because it is weakly bound, the calls become NOP's when the library
4230 // isn't present.
4231+#ifdef __APPLE__
4232+// XXXDARWIN: Link errors occur even when __attribute__((weak_import))
4233+// is added
4234+#define collector_func_load(x0,x1,x2,x3,x4,x5,x6) (0)
4235+#else
4236 void    collector_func_load(char* name,
4237                             void* null_argument_1,
4238                             void* null_argument_2,
4239@@ -882,6 +887,7 @@ void    collector_func_load(char* name,
4240 #pragma weak collector_func_load
4241 #define collector_func_load(x0,x1,x2,x3,x4,x5,x6) \
4242         ( collector_func_load ? collector_func_load(x0,x1,x2,x3,x4,x5,x6),0 : 0 )
4243+#endif // __APPLE__
4244 #endif // !_WINDOWS
4245 
4246 } // end extern "C"
4247diff -upr ../orig/hotspot/src/share/vm/runtime/globals.hpp ./hotspot/src/share/vm/runtime/globals.hpp
4248--- ../orig/hotspot/src/share/vm/runtime/globals.hpp    2009-01-27 15:41:03.000000000 -0500
4249+++ ./hotspot/src/share/vm/runtime/globals.hpp  2009-05-06 12:07:35.000000000 -0400
4250@@ -294,7 +294,7 @@ class CommandLineFlags {
4251   /* UseMembar is theoretically a temp flag used for memory barrier         \
4252    * removal testing.  It was supposed to be removed before FCS but has     \
4253    * been re-added (see 6401008) */                                         \
4254-  product(bool, UseMembar, false,                                           \
4255+  product(bool, UseMembar, true,                                           \
4256           "(Unstable) Issues membars on thread state transitions")          \
4257                                                                             \
4258   product(bool, PrintCommandLineFlags, false,                               \
4259diff -upr ../orig/hotspot/src/share/vm/runtime/os.cpp ./hotspot/src/share/vm/runtime/os.cpp
4260--- ../orig/hotspot/src/share/vm/runtime/os.cpp 2009-01-27 15:41:03.000000000 -0500
4261+++ ./hotspot/src/share/vm/runtime/os.cpp       2009-05-04 17:37:17.000000000 -0400
4262@@ -155,7 +155,11 @@ char* os::iso8601_time(char* buffer, siz
4263   }
4264   // Save the results of localtime
4265   const struct tm time_struct = *time_struct_temp;
4266+#if defined(_ALLBSD_SOURCE)
4267+  const time_t zone = (time_t) time_struct_temp->tm_gmtoff;
4268+#else
4269   const time_t zone = timezone;
4270+#endif
4271   
4272   // If daylight savings time is in effect,
4273   // we are 1 hour East of our time zone
4274diff -upr ../orig/hotspot/src/share/vm/runtime/vm_version.cpp ./hotspot/src/share/vm/runtime/vm_version.cpp
4275--- ../orig/hotspot/src/share/vm/runtime/vm_version.cpp 2009-01-27 15:41:03.000000000 -0500
4276+++ ./hotspot/src/share/vm/runtime/vm_version.cpp       2009-05-04 17:37:15.000000000 -0400
4277@@ -141,7 +141,8 @@ const char* Abstract_VM_Version::vm_rele
4278 
4279 #define OS       LINUX_ONLY("linux")             \
4280                  WINDOWS_ONLY("windows")         \
4281-                 SOLARIS_ONLY("solaris")
4282+                 SOLARIS_ONLY("solaris")         \
4283+                 BSD_ONLY("bsd")
4284 
4285 #define CPU      IA32_ONLY("x86")                \
4286                  IA64_ONLY("ia64")               \
4287diff -upr ../orig/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp ./hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp
4288--- ../orig/hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp    2009-01-27 15:41:03.000000000 -0500
4289+++ ./hotspot/src/share/vm/utilities/globalDefinitions_gcc.hpp  2009-05-04 17:37:17.000000000 -0400
4290@@ -74,12 +74,25 @@
4291 # include <sys/procfs.h>
4292 # endif
4293 
4294-#ifdef LINUX
4295+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
4296 #include <inttypes.h>
4297 #include <signal.h>
4298+#ifndef __OpenBSD__
4299 #include <ucontext.h>
4300+#endif
4301+#ifdef __APPLE__
4302+  #include <AvailabilityMacros.h>
4303+  #if (MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_4)
4304+    // Mac OS X 10.4 defines EFL_AC and EFL_ID,
4305+    // which conflict with hotspot variable names.
4306+    //
4307+    // This has been fixed in Mac OS X 10.5.
4308+    #undef EFL_AC
4309+    #undef EFL_ID
4310+  #endif
4311+#endif
4312 #include <sys/time.h>
4313-#endif // LINUX
4314+#endif // LINUX || _ALLBSD_SOURCE
4315 
4316 // 4810578: varargs unsafe on 32-bit integer/64-bit pointer architectures
4317 // When __cplusplus is defined, NULL is defined as 0 (32-bit constant) in
4318@@ -115,17 +128,20 @@
4319 // pointer is stored as integer value.  On some platforms, sizeof(intptr_t) >
4320 // sizeof(void*), so here we want something which is integer type, but has the
4321 // same size as a pointer.
4322-#ifdef LINUX
4323+#ifdef __GNUC__
4324   #ifdef _LP64
4325     #define NULL_WORD  0L
4326   #else
4327-    #define NULL_WORD  0
4328+    // Cast 0 to intptr_t rather than int32_t since they are not the same type
4329+    // on platforms such as Mac OS X.
4330+    #define NULL_WORD  ((intptr_t)0)
4331   #endif
4332 #else
4333   #define NULL_WORD  NULL
4334 #endif
4335 
4336-#ifndef        LINUX
4337+
4338+#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
4339 // Compiler-specific primitive types
4340 typedef unsigned short     uint16_t;
4341 #ifndef _UINT32_T
4342@@ -145,7 +161,7 @@ typedef unsigned int                uintptr_t;
4343 // prior definition of intptr_t, and add "&& !defined(XXX)" above.
4344 #endif // _SYS_INT_TYPES_H
4345 
4346-#endif // !LINUX
4347+#endif // !LINUX && !_ALLBSD_SOURCE
4348 
4349 // Additional Java basic types
4350 
4351@@ -229,7 +245,9 @@ inline int g_isnan(float  f) { return is
4352 inline int g_isnan(float  f) { return isnand(f); }
4353 #endif
4354 inline int g_isnan(double f) { return isnand(f); }
4355-#elif LINUX
4356+#elif defined(__APPLE__)
4357+inline int g_isnan(double f) { return isnan(f); }
4358+#elif defined(LINUX) || defined(_ALLBSD_SOURCE)
4359 inline int g_isnan(float  f) { return isnanf(f); }
4360 inline int g_isnan(double f) { return isnan(f); }
4361 #else
4362diff -upr ../orig/hotspot/src/share/vm/utilities/macros.hpp ./hotspot/src/share/vm/utilities/macros.hpp
4363--- ../orig/hotspot/src/share/vm/utilities/macros.hpp   2009-01-27 15:41:03.000000000 -0500
4364+++ ./hotspot/src/share/vm/utilities/macros.hpp 2009-05-04 17:37:17.000000000 -0400
4365@@ -147,6 +147,16 @@
4366 #define NOT_WINDOWS(code) code
4367 #endif
4368 
4369+#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__APPLE__)
4370+#define BSD_ONLY(code) code
4371+#define NOT_BSD(code)
4372+#else
4373+#define BSD_ONLY(code)
4374+#define NOT_BSD(code) code
4375+#endif
4376+
4377+
4378+
4379 #ifdef IA32
4380 #define IA32_ONLY(code) code
4381 #define NOT_IA32(code)
4382diff -upr ../orig/hotspot/src/share/vm/utilities/ostream.cpp ./hotspot/src/share/vm/utilities/ostream.cpp
4383--- ../orig/hotspot/src/share/vm/utilities/ostream.cpp  2009-01-27 15:41:03.000000000 -0500
4384+++ ./hotspot/src/share/vm/utilities/ostream.cpp        2009-05-04 17:37:15.000000000 -0400
4385@@ -780,7 +780,7 @@ bufferedStream::~bufferedStream() {
4386 
4387 #ifndef PRODUCT
4388 
4389-#if defined(SOLARIS) || defined(LINUX)
4390+#if defined(SOLARIS) || defined(LINUX) || defined(_ALLBSD_SOURCE)
4391 #include <sys/types.h>
4392 #include <sys/socket.h>
4393 #include <netinet/in.h>
4394diff -upr ../orig/hotspot/src/share/vm/utilities/vmError.cpp ./hotspot/src/share/vm/utilities/vmError.cpp
4395--- ../orig/hotspot/src/share/vm/utilities/vmError.cpp  2009-01-27 15:41:04.000000000 -0500
4396+++ ./hotspot/src/share/vm/utilities/vmError.cpp        2009-05-04 17:37:17.000000000 -0400
4397@@ -34,13 +34,18 @@ const char *env_list[] = {
4398   "JAVA_HOME", "JRE_HOME", "JAVA_TOOL_OPTIONS", "_JAVA_OPTIONS", "CLASSPATH",
4399   "JAVA_COMPILER", "PATH", "USERNAME",
4400 
4401-  // Env variables that are defined on Solaris/Linux
4402+  // Env variables that are defined on Solaris/Linux/BSD
4403   "LD_LIBRARY_PATH", "LD_PRELOAD", "SHELL", "DISPLAY",
4404   "HOSTTYPE", "OSTYPE", "ARCH", "MACHTYPE",
4405 
4406   // defined on Linux
4407   "LD_ASSUME_KERNEL", "_JAVA_SR_SIGNUM",
4408 
4409+  // defined on Darwin
4410+  "DYLD_LIBRARY_PATH", "DYLD_FALLBACK_LIBRARY_PATH",
4411+  "DYLD_FRAMEWORK_PATH", "DYLD_FALLBACK_FRAMEWORK_PATH",
4412+  "DYLD_INSERT_LIBRARIES",
4413+
4414   // defined on Windows
4415   "OS", "PROCESSOR_IDENTIFIER", "_ALT_JAVA_HOME_DIR",
4416 
4417@@ -673,6 +678,11 @@ void VMError::report_and_die() {
4418     reset_signal_handlers();
4419 
4420   } else {
4421+    // If UseOsErrorReporting we call this for each level of the call stack
4422+    // while searching for the exception handler.  Only the first level needs
4423+    // to be reported.
4424+    if (UseOSErrorReporting && log_done) return;
4425+
4426     // This is not the first error, see if it happened in a different thread
4427     // or in the same thread during error reporting.
4428     if (first_error_tid != mytid) {
4429@@ -793,7 +803,7 @@ void VMError::report_and_die() {
4430     const char* ptr = OnError;
4431     while ((cmd = next_OnError_command(buffer, sizeof(buffer), &ptr)) != NULL){
4432       out.print_raw   ("#   Executing ");
4433-#if defined(LINUX)
4434+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
4435       out.print_raw   ("/bin/sh -c ");
4436 #elif defined(SOLARIS)
4437       out.print_raw   ("/usr/bin/sh -c ");
4438diff -upr ../orig/jdk/make/com/sun/java/pack/Makefile ./jdk/make/com/sun/java/pack/Makefile
4439--- ../orig/jdk/make/com/sun/java/pack/Makefile 2009-01-27 15:44:38.000000000 -0500
4440+++ ./jdk/make/com/sun/java/pack/Makefile       2009-05-04 17:37:15.000000000 -0400
4441@@ -61,6 +61,7 @@ vpath %.cpp $(SHARE_SRC)/native/$(PKGDIR
4442 
4443 
4444 ifeq ($(STANDALONE),true)
4445+ ifneq ($(SYSTEM_ZLIB),true)
4446   ZIPOBJDIR = $(OUTPUTDIR)/tmp/sun/java.util.zip/zip/$(OBJDIRNAME)
4447 
4448   ZIPOBJS =  $(ZIPOBJDIR)/zcrc32.$(OBJECT_SUFFIX) \
4449@@ -78,6 +79,10 @@ ifeq ($(STANDALONE),true)
4450   ZINCLUDE=-I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
4451   OTHER_CXXFLAGS += $(ZINCLUDE)
4452   LDDFLAGS += $(ZIPOBJS)
4453+ else
4454+  LDDFLAGS += -lz
4455+  OTHER_CXXFLAGS += -DSYSTEM_ZLIB
4456+ endif
4457 else
4458   OTHER_CXXFLAGS += -DNO_ZLIB -DUNPACK_JNI
4459   OTHER_LDLIBS += $(JVMLIB)
4460@@ -102,7 +107,11 @@ ifeq ($(PLATFORM), windows)
4461   COMPILER_WARNINGS_FATAL=false
4462 else
4463   LDOUTPUT = -o #Have a space
4464+ifeq ($(PLATFORM), bsd)
4465+  LDDFLAGS += -pthread
4466+else
4467   LDDFLAGS += -lc
4468+endif
4469   OTHER_LDLIBS  += $(LIBCXX)
4470 # setup the list of libraries to link in...
4471 ifeq ($(PLATFORM), linux)
4472diff -upr ../orig/jdk/make/com/sun/security/auth/module/Makefile ./jdk/make/com/sun/security/auth/module/Makefile
4473--- ../orig/jdk/make/com/sun/security/auth/module/Makefile      2009-01-27 15:44:38.000000000 -0500
4474+++ ./jdk/make/com/sun/security/auth/module/Makefile    2009-05-04 17:37:15.000000000 -0400
4475@@ -70,7 +70,7 @@ ifeq ($(PLATFORM), solaris)
4476   include FILES_c_solaris.gmk
4477 endif # solaris
4478 
4479-ifeq ($(PLATFORM), linux)
4480+ifneq (,$(findstring $(PLATFORM), linux bsd))
4481   LIBRARY = jaas_unix
4482   include FILES_export_unix.gmk
4483   include FILES_c_unix.gmk
4484diff -upr ../orig/jdk/make/com/sun/tools/attach/FILES_c.gmk ./jdk/make/com/sun/tools/attach/FILES_c.gmk
4485--- ../orig/jdk/make/com/sun/tools/attach/FILES_c.gmk   2009-01-27 15:44:38.000000000 -0500
4486+++ ./jdk/make/com/sun/tools/attach/FILES_c.gmk 2009-05-04 17:37:15.000000000 -0400
4487@@ -39,4 +39,7 @@ FILES_c = \
4488        LinuxVirtualMachine.c
4489 endif
4490 
4491-
4492+ifeq ($(PLATFORM),bsd)
4493+FILES_c = \
4494+       BsdVirtualMachine.c
4495+endif
4496diff -upr ../orig/jdk/make/com/sun/tools/attach/FILES_java.gmk ./jdk/make/com/sun/tools/attach/FILES_java.gmk
4497--- ../orig/jdk/make/com/sun/tools/attach/FILES_java.gmk        2009-01-27 15:44:38.000000000 -0500
4498+++ ./jdk/make/com/sun/tools/attach/FILES_java.gmk      2009-05-04 17:37:15.000000000 -0400
4499@@ -43,6 +43,11 @@ FILES_java += \
4500        sun/tools/attach/LinuxAttachProvider.java
4501 endif
4502 
4503+ifeq ($(PLATFORM), bsd)
4504+FILES_java += \
4505+       $(TARGDIR)/sun/tools/attach/BsdAttachProvider.java
4506+endif
4507+
4508 #
4509 # Files that need to be copied
4510 #
4511diff -upr ../orig/jdk/make/common/Defs-bsd.gmk ./jdk/make/common/Defs-bsd.gmk
4512--- ../orig/jdk/make/common/Defs-bsd.gmk        2009-05-04 18:32:16.000000000 -0400
4513+++ ./jdk/make/common/Defs-bsd.gmk      2009-05-04 17:37:15.000000000 -0400
4514@@ -43,12 +43,6 @@
4515 # Get shared JDK settings
4516 include $(JDK_MAKE_SHARED_DIR)/Defs.gmk
4517 
4518-# Part of INCREMENTAL_BUILD mechanism.
4519-#   Compiler emits things like:  path/file.o: file.h
4520-#   We want something like: relative_path/file.o relative_path/file.d: file.h
4521-CC_DEPEND       = -MM
4522-CC_DEPEND_FILTER = $(SED) -e 's!$*\.$(OBJECT_SUFFIX)!$(dir $@)& $(dir $@)$*.$(DEPEND_SUFFIX)!g'
4523-
4524 ifndef PLATFORM_SRC
4525   PLATFORM_SRC = $(BUILDDIR)/../src/solaris
4526 endif # PLATFORM_SRC
4527@@ -61,7 +55,7 @@ ifndef OPENJDK
4528 endif
4529 
4530 # platform specific include files
4531-PLATFORM_INCLUDE_NAME = $(PLATFORM)
4532+PLATFORM_INCLUDE_NAME = $(OS_NAME)
4533 PLATFORM_INCLUDE      = $(INCLUDEDIR)/$(PLATFORM_INCLUDE_NAME)
4534 
4535 # suffix used for make dependencies files.
4536@@ -104,6 +98,10 @@ endif
4537 #    as the default.
4538 CFLAGS_REQUIRED_amd64   += -fno-omit-frame-pointer -D_LITTLE_ENDIAN
4539 CFLAGS_REQUIRED_i586    += -fno-omit-frame-pointer -D_LITTLE_ENDIAN
4540+ifeq ($(OS_VENDOR),Apple)
4541+  # 16-byte stack re-alignment on 32-bit Darwin
4542+  CFLAGS_REQUIRED_i586 += -mstackrealign
4543+endif
4544 CFLAGS_REQUIRED_ia64    += -fno-omit-frame-pointer -D_LITTLE_ENDIAN
4545 CFLAGS_REQUIRED_sparcv9 += -m64 -mcpu=v9
4546 LDFLAGS_COMMON_sparcv9  += -m64 -mcpu=v9
4547@@ -178,7 +176,7 @@ ifeq ($(FASTDEBUG), true)
4548   CXXFLAGS_DBG += $(CC_LOWER_OPT)
4549 endif
4550 
4551-CPPFLAGS_COMMON = -D$(ARCH) -DARCH='"$(ARCH)"' -DLINUX $(VERSION_DEFINES) \
4552+CPPFLAGS_COMMON = -D$(ARCH) -DARCH='"$(ARCH)"' -D_ALLBSD_SOURCE $(VERSION_DEFINES) \
4553                  -D_LARGEFILE64_SOURCE -D_GNU_SOURCE -D_REENTRANT
4554 
4555 ifeq ($(ARCH_DATA_MODEL), 64)
4556@@ -188,33 +186,15 @@ endif
4557 CPPFLAGS_OPT    =
4558 CPPFLAGS_DBG    = -DDEBUG
4559 
4560-ifdef LIBRARY
4561-  # Libraries need to locate other libraries at runtime, and you can tell
4562-  #   a library where to look by way of the dynamic runpaths (RPATH or RUNPATH)
4563-  #   buried inside the .so. The $ORIGIN says to look relative to where
4564-  #   the library itself is and it can be followed with relative paths from
4565-  #   that. By default we always look in $ORIGIN, optionally we add relative
4566-  #   paths if the Makefile sets LD_RUNPATH_EXTRAS to those relative paths.
4567-  #   On Bsd we add a flag -z origin, not sure if this is necessary, but
4568-  #   doesn't seem to hurt.
4569-  #   The environment variable LD_LIBRARY_PATH will over-ride these runpaths.
4570-  #   Try: 'readelf -d lib*.so' to see these settings in a library.
4571-  #
4572-  LDFLAGS_COMMON += -Xlinker -z -Xlinker origin -Xlinker -rpath -Xlinker \$$ORIGIN
4573-  LDFLAGS_COMMON += $(LD_RUNPATH_EXTRAS:%=-Xlinker -z -Xlinker origin -Xlinker -rpath -Xlinker \$$ORIGIN/%)
4574-endif
4575-
4576-EXTRA_LIBS += -lc
4577-
4578-LDFLAGS_DEFS_OPTION  = -z defs
4579-LDFLAGS_COMMON  += $(LDFLAGS_DEFS_OPTION)
4580-
4581 #
4582 # -L paths for finding and -ljava
4583 #
4584-LDFLAGS_OPT     = -Xlinker -O1
4585 LDFLAGS_COMMON += -L$(LIBDIR)/$(LIBARCH)
4586+
4587+ifneq ($(OS_VENDOR), Apple)
4588+LDFLAGS_OPT     = -Xlinker -O1
4589 LDFLAGS_COMMON += -Wl,-soname=$(LIB_PREFIX)$(LIBRARY).$(LIBRARY_SUFFIX)
4590+endif
4591 
4592 #
4593 # -static-libgcc is a gcc-3 flag to statically link libgcc, gcc-2.9x always
4594@@ -235,8 +215,8 @@ AUTOMATIC_PCH_OPTION =
4595 #
4596 ifeq ($(VARIANT), OPT)
4597   ifneq ($(NO_STRIP), true)
4598-    # Debug 'strip -g' leaves local function Elf symbols (better stack traces)
4599-    POST_STRIP_PROCESS = $(STRIP) -g
4600+    # Debug 'strip -S' leaves local function Elf symbols (better stack traces)
4601+    POST_STRIP_PROCESS = $(STRIP) -S
4602   endif
4603 endif
4604 
4605@@ -245,13 +225,9 @@ endif
4606 #
4607 LD_MAPFILE_FLAG = -Xlinker --version-script -Xlinker
4608 
4609-#
4610-# Support for Quantify.
4611-#
4612-ifdef QUANTIFY
4613-QUANTIFY_CMD = quantify
4614-QUANTIFY_OPTIONS = -cache-dir=/tmp/quantify -always-use-cache-dir=yes
4615-LINK_PRE_CMD = $(QUANTIFY_CMD) $(QUANTIFY_OPTIONS)
4616+# Darwin does not support linker map files.
4617+ifeq ($(OS_VENDOR), Apple)
4618+LDNOMAP=true
4619 endif
4620 
4621 #
4622@@ -280,7 +256,9 @@ override HAVE_ALTZONE            = false
4623 override HAVE_FILIOH             = false
4624 override HAVE_GETHRTIME          = false
4625 override HAVE_GETHRVTIME         = false
4626+ifeq ($(OS_VENDOR),Apple)
4627 override HAVE_SIGIGNORE          = true
4628+endif
4629 override LEX_LIBRARY             = -lfl
4630 ifeq ($(STATIC_CXX),true)
4631 override LIBCXX                  = -Wl,-Bstatic -lstdc++ -lgcc -Wl,-Bdynamic
4632@@ -291,13 +269,9 @@ override LIBPOSIX4               =
4633 override LIBSOCKET               =
4634 override LIBTHREAD               =
4635 override MOOT_PRIORITIES         = true
4636-override NO_INTERRUPTIBLE_IO     = true
4637-override OPENWIN_HOME            = /usr/X11R6
4638-ifeq ($(ARCH), amd64)
4639-override OPENWIN_LIB             = $(OPENWIN_HOME)/lib64
4640-else
4641+override NO_INTERRUPTIBLE_IO     = false
4642+override OPENWIN_HOME            = $(X11_PATH)
4643 override OPENWIN_LIB             = $(OPENWIN_HOME)/lib
4644-endif
4645 override OTHER_M4FLAGS           = -D__GLIBC__ -DGNU_ASSEMBLER
4646 override SUN_CMM_SUBDIR          =
4647 override THREADS_FLAG            = native
4648@@ -318,6 +292,14 @@ override USE_EXECNAME            = true
4649 # DPS (Displayable PostScript) is available on Solaris machines
4650 HAVE_DPS = no
4651 
4652+ifeq ($(OS_VENDOR), FreeBSD)
4653+  SYSTEM_ZLIB = true
4654+endif
4655+
4656+ifeq ($(OS_VENDOR), OpenBSD)
4657+  SYSTEM_ZLIB = true
4658+endif
4659+
4660 #
4661 # Japanese manpages
4662 #
4663diff -upr ../orig/jdk/make/common/Defs-linux.gmk ./jdk/make/common/Defs-linux.gmk
4664--- ../orig/jdk/make/common/Defs-linux.gmk      2009-01-27 15:44:38.000000000 -0500
4665+++ ./jdk/make/common/Defs-linux.gmk    2009-05-04 17:37:15.000000000 -0400
4666@@ -292,7 +292,7 @@ override LIBSOCKET               =
4667 override LIBTHREAD               =
4668 override MOOT_PRIORITIES         = true
4669 override NO_INTERRUPTIBLE_IO     = true
4670-override OPENWIN_HOME            = /usr/X11R6
4671+override OPENWIN_HOME            = $(X11_PATH)
4672 ifeq ($(ARCH), amd64)
4673 override OPENWIN_LIB             = $(OPENWIN_HOME)/lib64
4674 else
4675diff -upr ../orig/jdk/make/common/Defs.gmk ./jdk/make/common/Defs.gmk
4676--- ../orig/jdk/make/common/Defs.gmk    2009-01-27 15:44:38.000000000 -0500
4677+++ ./jdk/make/common/Defs.gmk  2009-05-04 17:37:15.000000000 -0400
4678@@ -188,6 +188,24 @@ else
4679 _OUTPUTDIR=$(JDK_TOPDIR)/build/$(PLATFORM)-$(ARCH)
4680 endif
4681 
4682+ifneq ($(PLATFORM), windows)
4683+  ifdef ALT_X11_PATH
4684+    X11_PATH = $(ALT_X11_PATH)
4685+  else
4686+    X11_PATH = /usr/X11R6
4687+  endif
4688+
4689+  ifdef ALT_PACKAGE_PATH
4690+    PACKAGE_PATH = $(ALT_PACKAGE_PATH)
4691+  else
4692+    ifeq ($(PLATFORM), linux)
4693+      PACKAGE_PATH = /usr
4694+    else
4695+      PACKAGE_PATH = /usr/local
4696+    endif
4697+  endif
4698+endif
4699+
4700 #
4701 # Get platform definitions
4702 #
4703@@ -223,6 +241,7 @@ DEVTOOLS_FT_DIR_EXISTS = $(shell \
4704 
4705   ifdef ALT_FREETYPE_LIB_PATH
4706     FREETYPE_LIB_PATH = $(ALT_FREETYPE_LIB_PATH)
4707+    USING_SYSTEM_FT_LIB=true
4708   else
4709     ifeq ($(DEVTOOLS_FT_DIR_EXISTS), true)
4710       FREETYPE_LIB_PATH = $(DEVTOOLS_FT_DIR)/lib
4711@@ -287,6 +306,10 @@ ifdef PROGRAM
4712     LDLIBS_COMMON = -ldl
4713   endif
4714 
4715+  ifeq ($(PLATFORM), bsd)
4716+    LDLIBS_COMMON = -pthread
4717+  endif
4718+
4719 endif # PROGRAM
4720 
4721 LDLIBS_COMMON += $(EXTRA_LIBS)
4722diff -upr ../orig/jdk/make/common/Program.gmk ./jdk/make/common/Program.gmk
4723--- ../orig/jdk/make/common/Program.gmk 2009-01-27 15:44:38.000000000 -0500
4724+++ ./jdk/make/common/Program.gmk       2009-05-04 17:37:15.000000000 -0400
4725@@ -67,11 +67,27 @@ endif
4726 # Create a dependency on libjli (Java Launcher Infrastructure)
4727 #
4728 # On UNIX, this is a relative dependency using $ORIGIN. Unfortunately, to
4729-# do this reliably on Linux takes a different syntax than Solaris.
4730+# do this reliably on Linux takes a different syntax than Solaris. BSD's
4731+# don't support $ORIGIN so build an archive instead.
4732 #
4733 # On Windows, this is done by using the same directory as the executable
4734 # itself, as with all the Windows libraries.
4735 #
4736+ifeq ($(PLATFORM), bsd)
4737+  ifeq ($(OS_VENDOR), Apple)
4738+    LDFLAGS += -Wl,-all_load
4739+    LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a
4740+  else
4741+    LDFLAGS += -Wl,--whole-archive
4742+    LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a
4743+    LDFLAGS += -Wl,--no-whole-archive
4744+# Work-around an dlsym(RTLD_DEFAULT) bug in at least FreeBSD & OpenBSD
4745+    LDFLAGS += -Wl,--export-dynamic
4746+  endif
4747+  ifeq ($(SYSTEM_ZLIB),true)
4748+      OTHER_LDLIBS += -lz
4749+  endif
4750+endif
4751 ifneq (,$(findstring $(PLATFORM), linux solaris))      # UNIX systems
4752     LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
4753     OTHER_LDLIBS += -ljli
4754@@ -175,6 +191,10 @@ else # USE_PTHREADS
4755   THREADLIBS = $(LIBTHREAD)
4756 endif # USE_PTHREADS
4757 
4758+ifeq ($(PLATFORM), bsd)
4759+THREADLIBS = -pthread
4760+endif
4761+
4762 #
4763 # This rule only applies on unix.  It supports quantify and its ilk.
4764 #
4765@@ -243,15 +263,19 @@ endif
4766 
4767 
4768 ifneq ($(PLATFORM), windows)
4769+ifneq ($(PLATFORM), bsd)
4770 HAVE_GETHRTIME=true
4771 endif
4772+endif
4773 
4774 ifeq ($(HAVE_GETHRTIME),true)
4775 OTHER_CPPFLAGS += -DHAVE_GETHRTIME
4776 endif
4777 
4778 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)/bin -I$(LAUNCHER_PLATFORM_SRC)/bin
4779+ifneq ($(SYSTEM_ZLIB),true)
4780 OTHER_INCLUDES += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
4781+endif
4782 
4783 # this may not be necessary...
4784 ifeq ($(PLATFORM), windows)
4785diff -upr ../orig/jdk/make/common/Release.gmk ./jdk/make/common/Release.gmk
4786--- ../orig/jdk/make/common/Release.gmk 2009-01-27 15:44:38.000000000 -0500
4787+++ ./jdk/make/common/Release.gmk       2009-05-04 17:37:15.000000000 -0400
4788@@ -147,14 +147,13 @@ JRE_MAN_PAGES =         \
4789        tnameserv.1     \
4790        unpack200.1
4791 
4792-ifeq ($(ARCH_DATA_MODEL),32)
4793+ifeq ($(BUILD_DEPLOY), true)
4794   JRE_MAN_PAGES += javaws.1
4795 endif
4796 
4797 JDK_MAN_PAGES =            \
4798        $(JRE_MAN_PAGES)   \
4799        appletviewer.1     \
4800-        apt.1              \
4801        extcheck.1         \
4802        idlj.1             \
4803        jar.1              \
4804@@ -193,6 +192,11 @@ ifeq ($(PLATFORM), linux)
4805   JA_DIRNAME=ja_JP.$(JA_SOURCE_ENCODING)
4806 endif # linux
4807 
4808+ifeq ($(PLATFORM), bsd)
4809+  MANBASEDIRS=$(JDK_TOPDIR)/src/bsd/doc $(IMPORTDOCDIR)
4810+  MAN1SUBDIR = man
4811+endif
4812+
4813 define copy-man-pages
4814 $(MKDIR) -p $1/man/man1
4815 for manbase in $(MANBASEDIRS:%=%/$(MAN1SUBDIR)) ; do \
4816@@ -325,6 +329,12 @@ ifndef OPENJDK
4817   SOURCE_DIRS += $(CLOSED_SRC)/share/classes
4818 endif
4819 
4820+ifeq ($(OS_VENDOR), OpenBSD)
4821+  FILES_FROM_ARG=-I
4822+else
4823+  FILES_FROM_ARG=-T
4824+endif
4825+
4826 
4827 #
4828 # Specific files and directories that will be filtered out from above areas.
4829@@ -982,7 +992,7 @@ initial-image-jdk:: initial-image-jdk-se
4830        @# generated by the more efficient solaris/windows method of copying files.
4831        @# So for Linux, make use of the -T option (like Solaris' -I option) of
4832        @# obtaining the list of files from a file. MKS tar has no such option.
4833-  ifeq ($(PLATFORM), linux)
4834+  ifneq (,$(findstring $(PLATFORM), linux bsd))
4835        for d in $(SOURCE_DIRS); do \
4836          $(RM) $(ABS_TEMPDIR)/src-files.list; \
4837          ($(CD) $$d &&  \
4838@@ -995,7 +1005,7 @@ initial-image-jdk:: initial-image-jdk-se
4839            done ; \
4840          ) ; \
4841          if [ -f  $(ABS_TEMPDIR)/src-files.list ] ; then \
4842-           ($(CD) $$d && $(TAR) cf - -T $(ABS_TEMPDIR)/src-files.list ) \
4843+           ($(CD) $$d && $(TAR) cf - $(FILES_FROM_ARG) $(ABS_TEMPDIR)/src-files.list ) \
4844               | ($(CD) $(JDK_IMAGE_DIR)/src && $(TAR) xf -); \
4845          fi; \
4846        done
4847diff -upr ../orig/jdk/make/common/internal/BinaryPlugs.gmk ./jdk/make/common/internal/BinaryPlugs.gmk
4848--- ../orig/jdk/make/common/internal/BinaryPlugs.gmk    2009-01-27 15:44:38.000000000 -0500
4849+++ ./jdk/make/common/internal/BinaryPlugs.gmk  2009-05-04 17:37:17.000000000 -0400
4850@@ -49,8 +49,6 @@ PLUG_JMF_CLASS_NAMES = \
4851 com/sun/jmx/snmp/SnmpDataTypeEnums.class \
4852 com/sun/jmx/snmp/SnmpDefinitions.class \
4853 com/sun/jmx/snmp/SnmpOid.class \
4854-com/sun/jmx/snmp/SnmpOidDatabase.class \
4855-com/sun/jmx/snmp/SnmpOidDatabaseSupport.class \
4856 com/sun/jmx/snmp/SnmpOidRecord.class \
4857 com/sun/jmx/snmp/SnmpOidTable.class \
4858 com/sun/jmx/snmp/SnmpOidTableSupport.class \
4859@@ -60,22 +58,16 @@ com/sun/jmx/snmp/SnmpPeer.class \
4860 com/sun/jmx/snmp/SnmpTimeticks.class \
4861 com/sun/jmx/snmp/SnmpVarBind.class \
4862 com/sun/jmx/snmp/SnmpVarBindList.class \
4863-com/sun/jmx/snmp/Timestamp.class \
4864 com/sun/jmx/snmp/daemon/SendQ.class \
4865 com/sun/jmx/snmp/daemon/SnmpInformRequest.class \
4866-com/sun/jmx/snmp/daemon/SnmpQManager.class \
4867-com/sun/jmx/snmp/daemon/SnmpRequestCounter.class \
4868-com/sun/jmx/snmp/daemon/SnmpResponseHandler.class \
4869-com/sun/jmx/snmp/daemon/SnmpSendServer.class \
4870-com/sun/jmx/snmp/daemon/SnmpSession.class \
4871-com/sun/jmx/snmp/daemon/SnmpSocket.class \
4872-com/sun/jmx/snmp/daemon/SnmpTimerServer.class \
4873-com/sun/jmx/snmp/daemon/WaitQ.class
4874+com/sun/jmx/snmp/daemon/SnmpSession.class
4875+
4876+PLUG_GNU_CLASS_NAMES = gnu
4877 
4878 # Class list temp files (used by both import and export of plugs)
4879 
4880 PLUG_TEMPDIR=$(ABS_TEMPDIR)/plugs
4881-PLUG_CLASS_AREAS = jmf
4882+PLUG_CLASS_AREAS = jmf gnu
4883 PLUG_CLISTS = $(PLUG_CLASS_AREAS:%=$(PLUG_TEMPDIR)/%.clist)
4884 
4885 # Create jargs file command
4886@@ -93,11 +85,18 @@ $(PLUG_TEMPDIR)/jmf.clist:
4887        @for i in $(PLUG_JMF_CLASS_NAMES) ; do \
4888          $(ECHO) "$$i" >> $@; \
4889        done
4890+$(PLUG_TEMPDIR)/gnu.clist:
4891+       @$(prep-target)
4892+       @for i in $(PLUG_GNU_CLASS_NAMES) ; do \
4893+         $(ECHO) "$$i" >> $@ ; \
4894+       done
4895 $(PLUG_TEMPDIR)/all.clist: $(PLUG_CLISTS)
4896        @$(prep-target)
4897        $(CAT) $(PLUG_CLISTS) > $@
4898 $(PLUG_TEMPDIR)/jmf.jargs: $(PLUG_TEMPDIR)/jmf.clist
4899        $(plug-create-jargs)
4900+$(PLUG_TEMPDIR)/gnu.jargs: $(PLUG_TEMPDIR)/gnu.clist
4901+       $(plug-create-jargs)
4902 $(PLUG_TEMPDIR)/all.jargs: $(PLUG_TEMPDIR)/all.clist
4903        $(plug-create-jargs)
4904 
4905@@ -153,11 +152,16 @@ endif # IMPORT_BINARY_PLUGS
4906 
4907 import-binary-plug-jmf-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/jmf.clist
4908        $(call import-binary-plug-classes,$(PLUG_TEMPDIR)/jmf.clist)
4909+import-binary-plug-gnu-classes: $(PLUG_IMPORT_JARFILE) $(PLUG_TEMPDIR)/gnu.clist
4910+       $(call import-binary-plug-classes,$(PLUG_TEMPDIR)/gnu.clist)
4911+
4912+
4913 
4914 # Import all classes from the jar file
4915 
4916 import-binary-plug-jar: \
4917-            import-binary-plug-jmf-classes
4918+            import-binary-plug-jmf-classes \
4919+            import-binary-plug-gnu-classes
4920 
4921 # Binary plug start/complete messages
4922 
4923@@ -169,14 +173,12 @@ import-binary-plugs-completed:
4924 
4925 # Import lib files (only if they don't exist already)
4926 
4927-import-binary-plugs-libs: \
4928-    $(PLUG_LIBRARY_NAMES:%=$(LIB_LOCATION)/%)
4929+import-binary-plugs-libs:
4930 
4931 # Import everything
4932 
4933 import-binary-plugs: \
4934     import-binary-plugs-started \
4935-    import-binary-plugs-libs \
4936     import-binary-plug-jar \
4937     import-binary-plugs-completed
4938 
4939diff -upr ../orig/jdk/make/common/shared/Compiler-gcc.gmk ./jdk/make/common/shared/Compiler-gcc.gmk
4940--- ../orig/jdk/make/common/shared/Compiler-gcc.gmk     2009-01-27 15:44:38.000000000 -0500
4941+++ ./jdk/make/common/shared/Compiler-gcc.gmk   2009-05-04 17:37:15.000000000 -0400
4942@@ -99,6 +99,24 @@ ifeq ($(PLATFORM), linux)
4943 
4944 endif
4945 
4946+ifeq ($(PLATFORM), bsd)
4947+
4948+  # Settings specific to BSD
4949+  CC             = $(COMPILER_PATH)gcc
4950+  CPP            = $(COMPILER_PATH)gcc -E
4951+  CXX            = $(COMPILER_PATH)g++
4952+  REQUIRED_CC_VER = 3.2
4953+
4954+  # Option used to create a shared library
4955+  # Option used to create a shared library
4956+  ifeq ($(OS_VENDOR), Apple)
4957+    SHARED_LIBRARY_FLAG = -dynamiclib
4958+  else
4959+    SHARED_LIBRARY_FLAG = -shared
4960+  endif
4961+  SUN_COMP_VER := $(shell $(CC) --verbose 2>&1 )
4962+endif
4963+
4964 ifeq ($(PLATFORM), solaris)
4965 
4966   # Settings specific to Solaris
4967diff -upr ../orig/jdk/make/common/shared/Compiler.gmk ./jdk/make/common/shared/Compiler.gmk
4968--- ../orig/jdk/make/common/shared/Compiler.gmk 2009-01-27 15:44:38.000000000 -0500
4969+++ ./jdk/make/common/shared/Compiler.gmk       2009-05-04 17:37:15.000000000 -0400
4970@@ -37,8 +37,8 @@ ifeq ($(PLATFORM), solaris)
4971   override CC_VERSION = sun
4972 endif
4973 
4974-# Linux uses GNU compilers by default
4975-ifeq ($(PLATFORM), linux)
4976+# Linux  & BSD uses GNU compilers by default
4977+ifneq (,$(findstring $(PLATFORM), linux bsd))
4978   override CC_VERSION = gcc
4979 endif
4980 
4981diff -upr ../orig/jdk/make/common/shared/Defs-bsd.gmk ./jdk/make/common/shared/Defs-bsd.gmk
4982--- ../orig/jdk/make/common/shared/Defs-bsd.gmk 2009-05-04 18:32:16.000000000 -0400
4983+++ ./jdk/make/common/shared/Defs-bsd.gmk       2009-05-04 22:40:38.000000000 -0400
4984@@ -70,7 +70,7 @@ $(shell if [ "$1" != "" -a -d "$1" ]; th
4985 endef
4986 
4987 # Location on system where jdk installs might be
4988-USRJDKINSTANCES_PATH =/opt/java
4989+USRJDKINSTANCES_PATH = $(PACKAGE_PATH)
4990 
4991 # UNIXCOMMAND_PATH: path to where the most common Unix commands are.
4992 #  NOTE: Must end with / so that it could be empty, allowing PATH usage.
4993@@ -123,7 +123,7 @@ endif
4994 ifneq "$(origin ALT_DEVTOOLS_PATH)" "undefined"
4995   DEVTOOLS_PATH :=$(call PrefixPath,$(ALT_DEVTOOLS_PATH))
4996 else
4997-  DEVTOOLS_PATH =/usr/bin/
4998+  DEVTOOLS_PATH =$(PACKAGE_PATH)/bin/
4999 endif
5000 
5001 # _BOOTDIR1: First choice for a Bootstrap JDK, previous released JDK.
5002@@ -162,16 +162,12 @@ else
5003 endif
5004 MOTIF_INCLUDE = $(MOTIF_DIR)/include
5005 
5006-# GCC29_COMPILER_PATH: is the path to where the gcc 2.9 compiler is installed
5007-#  NOTE: Must end with / so that it could be empty, allowing PATH usage.
5008-ifneq "$(origin ALT_GCC29_COMPILER_PATH)" "undefined"
5009-  GCC29_COMPILER_PATH :=$(call PrefixPath,$(ALT_GCC29_COMPILER_PATH))
5010+ifeq ($(OS_VENDOR), Apple)
5011+  _CUPS_HEADERS_PATH=/usr/include
5012 else
5013-  GCC29_COMPILER_PATH = $(JDK_DEVTOOLS_DIR)/$(PLATFORM)/gcc29/usr/
5014+  _CUPS_HEADERS_PATH=$(PACKAGE_PATH)/include
5015 endif
5016 
5017-_CUPS_HEADERS_PATH=/usr/include
5018-
5019 # Import JDK images allow for partial builds, components not built are
5020 #    imported (or copied from) these import areas when needed.
5021 
5022diff -upr ../orig/jdk/make/common/shared/Defs-utils.gmk ./jdk/make/common/shared/Defs-utils.gmk
5023--- ../orig/jdk/make/common/shared/Defs-utils.gmk       2009-01-27 15:44:38.000000000 -0500
5024+++ ./jdk/make/common/shared/Defs-utils.gmk     2009-05-04 17:37:15.000000000 -0400
5025@@ -77,6 +77,13 @@ ifndef FINDBUGS_HOME
5026 endif
5027 FINDBUGS = $(FINDBUGS_HOME)/bin/findbugs
5028 
5029+ifeq ($(PLATFORM),bsd)
5030+  UTILS_COMMAND_PATH=$(UNIXCOMMAND_PATH)
5031+  UTILS_USR_BIN_PATH=$(USRBIN_PATH)
5032+  UTILS_CCS_BIN_PATH=$(USRBIN_PATH)
5033+  UTILS_DEVTOOL_PATH=$(DEVTOOLS_PATH)
5034+endif
5035+
5036 # Utilities
5037 ADB            = $(UTILS_COMMAND_PATH)adb
5038 AR             = $(UTILS_CCS_BIN_PATH)ar
5039@@ -198,3 +205,32 @@ ifeq ($(PLATFORM),solaris)
5040   ECHO           = /usr/bin/echo
5041 endif
5042 
5043+# BSD specific
5044+ifeq ($(PLATFORM),bsd)
5045+  BASENAME     = $(UTILS_USR_BIN_PATH)basename
5046+  EGREP        = $(UTILS_USR_BIN_PATH)egrep
5047+  EXPR         = $(UTILS_COMMAND_PATH)expr
5048+  FMT          = $(UTILS_USR_BIN_PATH)fmt
5049+  GREP         = $(UTILS_USR_BIN_PATH)grep
5050+  GUNZIP       = $(UTILS_USR_BIN_PATH)gunzip
5051+  ID           = $(UTILS_USR_BIN_PATH)id
5052+  MSGFMT       = $(UTILS_DEVTOOL_PATH)msgfmt
5053+  SED          = $(UTILS_USR_BIN_PATH)sed
5054+  SORT         = $(UTILS_USR_BIN_PATH)sort
5055+  TEST         = $(UTILS_COMMAND_PATH)test
5056+  TOUCH        = $(UTILS_USR_BIN_PATH)touch
5057+  TRUE         = $(UTILS_USR_BIN_PATH)true
5058+  UNAME        = $(UTILS_USR_BIN_PATH)uname
5059+  # BSD OS_VENDOR specific
5060+  ifeq ($(OS_VENDOR), Apple)
5061+    NAWK       = $(UTILS_USR_BIN_PATH)awk
5062+    UNZIPSFX   = $(UTILS_USR_BIN_PATH)unzipsfx
5063+    ZIPEXE     = $(UTILS_USR_BIN_PATH)zip
5064+  else
5065+    UNZIP      = $(UTILS_DEVTOOL_PATH)unzip
5066+  endif
5067+  ifneq ($(OS_VENDOR), OpenBSD)
5068+    CPIO       = $(UTILS_USR_BIN_PATH)cpio
5069+    TAR        = $(UTILS_USR_BIN_PATH)tar
5070+  endif
5071+endif
5072diff -upr ../orig/jdk/make/common/shared/Defs.gmk ./jdk/make/common/shared/Defs.gmk
5073--- ../orig/jdk/make/common/shared/Defs.gmk     2009-01-27 15:44:38.000000000 -0500
5074+++ ./jdk/make/common/shared/Defs.gmk   2009-05-04 17:37:15.000000000 -0400
5075@@ -143,7 +143,7 @@ $(shell \
5076         echo older; \
5077       else \
5078        if [ $(call MajorVersion,$1) -eq $(call MajorVersion,$2) -a \
5079-            $(call MinorVersion,$1) -lt $(call MinorVersion,$2) ]; then \
5080+            `echo $(call MinorVersion,$1) | sed -e 's/\([0-9]*\)\(.*\)/\1/'` -lt $(call MinorVersion,$2) ]; then \
5081           echo older; \
5082         else \
5083           echo newer; \
5084diff -upr ../orig/jdk/make/common/shared/Platform.gmk ./jdk/make/common/shared/Platform.gmk
5085--- ../orig/jdk/make/common/shared/Platform.gmk 2009-01-27 15:44:38.000000000 -0500
5086+++ ./jdk/make/common/shared/Platform.gmk       2009-12-02 00:00:00.000000000 -0000
5087@@ -276,6 +276,81 @@ ifeq ($(SYSTEM_UNAME), Linux)
5088   MB_OF_MEMORY := $(shell free -m | fgrep Mem: | sed -e 's@\ \ *@ @g' | cut -d' ' -f2)
5089 endif
5090 
5091+ifeq ($(SYSTEM_UNAME), FreeBSD)
5092+  PLATFORM = bsd
5093+  OS_NAME = freebsd
5094+  OS_VENDOR = FreeBSD
5095+  REQUIRED_OS_VERSION = 6.0
5096+endif
5097+
5098+ifeq ($(SYSTEM_UNAME), Darwin)
5099+  PLATFORM = bsd
5100+  OS_NAME = darwin
5101+  OS_VENDOR = Apple
5102+  REQUIRED_OS_VERSION = 8.0
5103+endif
5104+
5105+ifeq ($(SYSTEM_UNAME), NetBSD)
5106+  PLATFORM = bsd
5107+  OS_NAME = netbsd
5108+  OS_VENDOR = NetBSD
5109+  REQUIRED_OS_VERSION = 3.0
5110+endif
5111+
5112+ifeq ($(SYSTEM_UNAME), OpenBSD)
5113+  PLATFORM = bsd
5114+  OS_NAME = openbsd
5115+  OS_VENDOR = OpenBSD
5116+  REQUIRED_OS_VERSION = 4.2
5117+endif
5118+
5119+# Platform settings specific to BSD
5120+ifeq ($(PLATFORM), bsd)
5121+  OS_VERSION := $(shell uname -r)
5122+  # Arch and OS name/version
5123+  #warning "DEBUG: SYSTEM_UNAME: $(SYSTEM_UNAME)"
5124+  ifeq ($(SYSTEM_UNAME), Darwin)
5125+    ARCH        := $(shell uname -p)
5126+  else
5127+    mach := $(shell uname -m)
5128+    archExpr = case "$(mach)" in \
5129+                  i[3-9]86) \
5130+                      echo i586 \
5131+                      ;; \
5132+                  *) \
5133+                      echo $(mach) \
5134+                      ;; \
5135+        esac
5136+    ARCH        := $(shell $(archExpr) )
5137+  endif
5138+  ARCH_FAMILY := $(ARCH)
5139+
5140+  # i586 and sparc are 32 bit, amd64 and sparc64 are 64
5141+  ifneq (,$(findstring $(ARCH), i586 sparc))
5142+    ARCH_DATA_MODEL=32
5143+  else
5144+    ARCH_DATA_MODEL=64
5145+  endif
5146+
5147+  # Need to maintain the jre/lib/i386 location for 32-bit Intel
5148+  ifeq ($(ARCH), i586)
5149+    LIBARCH = i386
5150+  else
5151+    LIBARCH = $(ARCH)
5152+  endif
5153+
5154+  # Value of Java os.arch property
5155+  ARCHPROP  = $(LIBARCH)
5156+
5157+  # Suffix for file bundles used in previous release
5158+  BUNDLE_FILE_SUFFIX=.tar.gz
5159+  # Minimum disk space needed as determined by running 'du -sk' on
5160+  #    a fully built workspace.
5161+  REQUIRED_FREE_SPACE=1500000
5162+  # How much RAM does this machine have:
5163+  MB_OF_MEMORY=$(shell sysctl -n hw.physmem | awk '{print int($$NF / 1048576); }' )
5164+endif
5165+
5166 # Windows with and without CYGWIN will be slightly different
5167 ifeq ($(SYSTEM_UNAME), Windows_NT)
5168   PLATFORM = windows
5169@@ -392,6 +462,13 @@ endif
5170 #    system swapping during the build.
5171 #    If we don't know, assume 512. Subtract 128 from MB for VM MAX.
5172 #    Don't set VM max over 1024-128=896.
5173+#    736 is the max for OpenBSD.
5174+ifeq ($(OS_VENDOR), OpenBSD)
5175+  ABS_MAX_MEMORY := "736"
5176+else
5177+  ABS_MAX_MEMORY := "896"
5178+endif
5179+
5180 ifneq ($(MB_OF_MEMORY),)
5181   LOW_MEMORY_MACHINE := $(shell \
5182     if [ $(MB_OF_MEMORY) -le 512 ] ; then \
5183@@ -403,7 +480,7 @@ ifneq ($(MB_OF_MEMORY),)
5184     if [ $(MB_OF_MEMORY) -le 1024 ] ; then \
5185       expr $(MB_OF_MEMORY) '-' 128 ; \
5186     else \
5187-      echo "896"; \
5188+      echo $(ABS_MAX_MEMORY); \
5189     fi)
5190   MIN_VM_MEMORY := $(shell \
5191     if [ $(MAX_VM_MEMORY) -le 128 ] ; then \
5192@@ -455,6 +532,15 @@ ifneq ($(PLATFORM), windows)
5193   ARCH_VM_SUBDIR=jre/lib/$(LIBARCH)
5194 endif
5195 
5196+# Darwin-specific Overrides
5197+ifeq ($(SYSTEM_UNAME),Darwin)
5198+  # The suffix applied to runtime libraries
5199+  LIBRARY_SUFFIX = dylib
5200+  # The suffix applied to link libraries
5201+  LIB_SUFFIX = dylib
5202+endif
5203+
5204+
5205 # If blanks in the username, use the first 4 words and pack them together
5206 _USER1:=$(subst ', ,$(_USER))
5207 _USER2:=$(subst ", ,$(_USER1))
5208diff -upr ../orig/jdk/make/common/shared/Sanity-Settings.gmk ./jdk/make/common/shared/Sanity-Settings.gmk
5209--- ../orig/jdk/make/common/shared/Sanity-Settings.gmk  2009-01-27 15:44:38.000000000 -0500
5210+++ ./jdk/make/common/shared/Sanity-Settings.gmk        2009-05-04 17:37:15.000000000 -0400
5211@@ -257,6 +257,7 @@ ifdef OPENJDK
5212   ALL_SETTINGS+=$(call addHeading,OpenJDK-specific settings)
5213   ALL_SETTINGS+=$(call addAltSetting,FREETYPE_HEADERS_PATH)
5214   ALL_SETTINGS+=$(call addAltSetting,FREETYPE_LIB_PATH)
5215+  ALL_SETTINGS+=$(call addAltSetting,X11_PATH)
5216   ALL_SETTINGS+=$(call addHeading,OPENJDK Import Binary Plug Settings)
5217   ALL_SETTINGS+=$(call addAltSetting,BINARY_PLUGS_JARFILE)
5218   ALL_SETTINGS+=$(call addAltSetting,BINARY_PLUGS_PATH)
5219diff -upr ../orig/jdk/make/common/shared/Sanity.gmk ./jdk/make/common/shared/Sanity.gmk
5220--- ../orig/jdk/make/common/shared/Sanity.gmk   2009-01-27 15:44:38.000000000 -0500
5221+++ ./jdk/make/common/shared/Sanity.gmk 2009-05-04 17:37:15.000000000 -0400
5222@@ -96,6 +96,11 @@ ifeq ($(PLATFORM), windows)
5223     $(EGREP) "\#define" | $(NAWK) '{print $$3}')
5224 endif
5225 
5226+ifeq ($(PLATFORM), bsd)
5227+  FREE_SPACE := $(shell BLOCKSIZE=512 $(DF) $(OUTPUTDIR) | $(TAIL) -1 | $(NAWK) '{print $$2;}')
5228+  TEMP_FREE_SPACE := $(shell BLOCKSIZE=512 $(DF) $(TEMP_DISK) | $(TAIL) -1 | $(NAWK) '{print $$2;}')
5229+endif
5230+
5231 # Get the version numbers of what we are using
5232 _MAKE_VER  :=$(shell $(MAKE) --version 2>&1 | $(HEAD) -n 1)
5233 _ZIP_VER   :=$(shell $(ZIPEXE) -help 2>&1 | $(HEAD) -n 4 | $(EGREP) '^Zip')
5234diff -upr ../orig/jdk/make/docs/Makefile ./jdk/make/docs/Makefile
5235--- ../orig/jdk/make/docs/Makefile      2009-01-27 15:44:38.000000000 -0500
5236+++ ./jdk/make/docs/Makefile    2009-05-04 17:37:15.000000000 -0400
5237@@ -232,7 +232,7 @@ JDI_HEADER      = "Java Debug Interface"
5238 #       you get "No packages or classes specified." due to $(CLASSPATH_SEPARATOR)
5239 #       being interpreted as an end of command (newline)
5240 
5241-JAAS_SOURCEPATH  = "$(TOPDIR)/src/share/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/solaris/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/windows/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/linux/classes"
5242+JAAS_SOURCEPATH  = "$(TOPDIR)/src/share/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/solaris/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/windows/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/linux/classes$(CLASSPATH_SEPARATOR)$(TOPDIR)/src/bsd/classes"
5243 JAAS_DOCDIR     = $(DOCSDIR)/jre/api/security/jaas/spec
5244 JAAS_JAVADOCFLAGS = $(COMMON_JAVADOCFLAGS)                      \
5245                   -encoding ascii                               \
5246diff -upr ../orig/jdk/make/java/Makefile ./jdk/make/java/Makefile
5247--- ../orig/jdk/make/java/Makefile      2009-01-27 15:44:38.000000000 -0500
5248+++ ./jdk/make/java/Makefile    2009-05-04 17:37:15.000000000 -0400
5249@@ -49,7 +49,7 @@ ifeq ($(PLATFORM), solaris)
5250   endif
5251 endif # PLATFORM
5252 
5253-ifeq ($(PLATFORM), linux)
5254+ifneq (,$(findstring $(PLATFORM), linux bsd))
5255   SUBDIRS += jexec
5256 endif # PLATFORM
5257 
5258diff -upr ../orig/jdk/make/java/hpi/hpi_common.gmk ./jdk/make/java/hpi/hpi_common.gmk
5259--- ../orig/jdk/make/java/hpi/hpi_common.gmk    2009-01-27 15:44:38.000000000 -0500
5260+++ ./jdk/make/java/hpi/hpi_common.gmk  2009-05-04 17:37:15.000000000 -0400
5261@@ -86,5 +86,9 @@ endif
5262 # Things that must be linked in.
5263 #
5264 ifneq ($(PLATFORM), windows)
5265+ifeq ($(PLATFORM), bsd)
5266+OTHER_LDLIBS += $(LIBM)
5267+else
5268 OTHER_LDLIBS += $(LIBSOCKET) -lnsl $(LIBM) -ldl
5269 endif
5270+endif
5271diff -upr ../orig/jdk/make/java/hpi/native/Makefile ./jdk/make/java/hpi/native/Makefile
5272--- ../orig/jdk/make/java/hpi/native/Makefile   2009-01-27 15:44:38.000000000 -0500
5273+++ ./jdk/make/java/hpi/native/Makefile 2009-05-04 17:37:15.000000000 -0400
5274@@ -72,11 +72,18 @@ OTHER_CPPFLAGS += -DUSE_PTHREADS
5275 ifeq ($(MOOT_PRIORITIES),true)
5276 OTHER_CPPFLAGS += -DMOOT_PRIORITIES
5277 endif
5278+ifeq ($(PLATFORM), bsd)
5279+LIBPOSIX4      =
5280+OTHER_LDLIBS   += -pthread
5281+else
5282 LIBPOSIX4      = -lposix4
5283 OTHER_LDLIBS   += -lpthread $(LIBPOSIX4)
5284 endif
5285+endif
5286 
5287+ifneq ($(PLATFORM), bsd)
5288 HAVE_GETHRVTIME=true
5289+endif
5290 ifeq ($(HAVE_GETHRVTIME),true)
5291 OTHER_CPPFLAGS += -DHAVE_GETHRVTIME
5292 endif
5293diff -upr ../orig/jdk/make/java/instrument/Makefile ./jdk/make/java/instrument/Makefile
5294--- ../orig/jdk/make/java/instrument/Makefile   2009-01-27 15:44:38.000000000 -0500
5295+++ ./jdk/make/java/instrument/Makefile 2009-05-04 17:37:15.000000000 -0400
5296@@ -102,6 +102,21 @@ ifeq ($(PLATFORM), windows)
5297   # equivalent of strcasecmp is stricmp on Windows
5298   CPPFLAGS_COMMON += -Dstrcasecmp=stricmp
5299 else
5300+ifeq ($(PLATFORM), bsd)
5301+  ifeq ($(OS_VENDOR), Apple)
5302+    LDFLAGS += -Wl,-all_load
5303+    LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a
5304+  else
5305+    LDFLAGS += -Wl,--whole-archive
5306+    LDFLAGS += $(OUTPUTDIR)/tmp/java/jli/$(OBJDIRNAME)/static/libjli.a
5307+    LDFLAGS += -Wl,--no-whole-archive
5308+  endif
5309+
5310+  ICONV_PATH = $(PACKAGE_PATH)
5311+# Use CPPFLAGS instead of OTHER_INCLUDES to force this last
5312+  CPPFLAGS += -I$(ICONV_PATH)/include
5313+  OTHER_LDLIBS += -L$(ICONV_PATH)/lib -liconv
5314+else
5315   LDFLAGS += -L $(LIBDIR)/$(LIBARCH)/jli
5316   OTHER_LDLIBS += -ljli
5317   OTHER_LDLIBS += -ldl
5318@@ -114,6 +129,7 @@ else
5319     LDFLAGS += -Wl,-rpath -Wl,\$$ORIGIN/jli
5320   endif
5321 endif
5322+endif
5323 
5324 #
5325 # Library to compile.
5326diff -upr ../orig/jdk/make/java/java/Makefile ./jdk/make/java/java/Makefile
5327--- ../orig/jdk/make/java/java/Makefile 2009-01-27 15:44:38.000000000 -0500
5328+++ ./jdk/make/java/java/Makefile       2009-05-04 17:37:15.000000000 -0400
5329@@ -167,8 +167,10 @@ OTHER_INCLUDES += -I$(PLATFORM_SRC)/nati
5330 # Is the altzone extern documented in ctime(3C) available?
5331 #
5332 ifneq ($(PLATFORM), windows)
5333+ifneq ($(PLATFORM), bsd)
5334 HAVE_ALTZONE=true
5335 endif
5336+endif
5337 
5338 ifeq ($(HAVE_ALTZONE),true)
5339 OTHER_CPPFLAGS += -DHAVE_ALTZONE
5340@@ -205,9 +207,14 @@ ifeq ($(PLATFORM),windows)
5341 OTHER_LDLIBS += $(JVMLIB) -libpath:$(OBJDIR)/../../../fdlibm/$(OBJDIRNAME) fdlibm.lib \
5342                       -libpath:$(OBJDIR)/../../../verify/$(OBJDIRNAME) verify.lib
5343 else
5344+ifeq ($(PLATFORM), bsd)
5345+OTHER_LDLIBS += $(JVMLIB) -lverify \
5346+               -L$(OBJDIR)/../../../fdlibm/$(OBJDIRNAME) -lfdlibm.$(ARCH)
5347+else
5348 OTHER_LDLIBS += $(JVMLIB) -lverify $(LIBSOCKET) -lnsl -ldl \
5349                -L$(OBJDIR)/../../../fdlibm/$(OBJDIRNAME) -lfdlibm.$(ARCH)
5350 endif
5351+endif
5352 
5353 #
5354 # Rules.
5355diff -upr ../orig/jdk/make/java/java/localegen.sh ./jdk/make/java/java/localegen.sh
5356--- ../orig/jdk/make/java/java/localegen.sh     2009-01-27 15:44:38.000000000 -0500
5357+++ ./jdk/make/java/java/localegen.sh   2009-05-05 08:21:41.000000000 -0400
5358@@ -55,9 +55,9 @@ sed_script="$SED -e \"s@^#warn .*@// --
5359 for FILE in $RESOURCE_NAMES
5360 do
5361     getlocalelist $FILE $EURO_FILES_LIST
5362-    sed_script=$sed_script"-e \"s/#"$FILE"_EuroLocales#/$localelist/g\" "
5363+    sed_script=$sed_script"-e \"s@#"$FILE"_EuroLocales#@$localelist@g\" "
5364     getlocalelist $FILE $NONEURO_FILES_LIST
5365-    sed_script=$sed_script"-e \"s/#"$FILE"_NonEuroLocales#/$localelist/g\" "
5366+    sed_script=$sed_script"-e \"s@#"$FILE"_NonEuroLocales#@$localelist@g\" "
5367 done
5368 
5369 sed_script=$sed_script"$INPUT_FILE > $OUTPUT_FILE"
5370diff -upr ../orig/jdk/make/java/java_hprof_demo/Makefile ./jdk/make/java/java_hprof_demo/Makefile
5371--- ../orig/jdk/make/java/java_hprof_demo/Makefile      2009-01-27 15:44:38.000000000 -0500
5372+++ ./jdk/make/java/java_hprof_demo/Makefile    2009-05-04 17:37:15.000000000 -0400
5373@@ -83,8 +83,10 @@ OTHER_INCLUDES = -I$(SRCDIR) \
5374 ifeq ($(PLATFORM), windows)
5375   OTHER_LDLIBS += wsock32.lib winmm.lib
5376 else
5377+ifneq ($(PLATFORM), bsd)
5378   OTHER_LDLIBS += $(LIBSOCKET) -lnsl -ldl
5379 endif
5380+endif
5381 
5382 #
5383 # Tell library.gmk to copy the txt file first
5384diff -upr ../orig/jdk/make/java/jli/Makefile ./jdk/make/java/jli/Makefile
5385--- ../orig/jdk/make/java/jli/Makefile  2009-01-27 15:44:39.000000000 -0500
5386+++ ./jdk/make/java/jli/Makefile        2009-05-05 08:26:57.000000000 -0400
5387@@ -44,8 +44,10 @@ MS_RUNTIME_STATIC = true
5388 
5389 include $(BUILDDIR)/common/Defs.gmk
5390 
5391+ifneq ($(SYSTEM_ZLIB),true)
5392 ZLIB_VERSION = 1.1.3
5393 ZIP_SRC = $(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
5394+endif
5395 LAUNCHER_SHARE_SRC = $(SHARE_SRC)/bin
5396 LAUNCHER_PLATFORM_SRC = $(PLATFORM_SRC)/bin
5397 
5398@@ -56,7 +58,10 @@ FILES_c = \
5399        parse_manifest.c \
5400        version_comp.c \
5401        wildcard.c \
5402-       jli_util.c \
5403+       jli_util.c
5404+
5405+ifneq ($(SYSTEM_ZLIB),true)
5406+FILES_c += \
5407        inflate.c \
5408        infblock.c \
5409        inftrees.c \
5410@@ -65,6 +70,7 @@ FILES_c = \
5411        infutil.c \
5412        zadler32.c \
5413        zutil.c
5414+endif
5415 
5416 OTHER_CPPFLAGS += -DEXPAND_CLASSPATH_WILDCARDS
5417 
5418@@ -98,7 +104,11 @@ endif
5419 
5420 OTHER_INCLUDES += -I$(LAUNCHER_SHARE_SRC)
5421 OTHER_INCLUDES += -I$(LAUNCHER_PLATFORM_SRC)
5422-OTHER_INCLUDES += -I$(ZIP_SRC)
5423+ifneq ($(SYSTEM_ZLIB),true)
5424+  OTHER_INCLUDES += -I$(ZIP_SRC)
5425+else
5426+  LDLIBS += -lz
5427+endif
5428 
5429 #
5430 # Library to compile.
5431@@ -136,8 +146,29 @@ library:: $(STATIC_LIBRARY)
5432 
5433 endif  # PLATFORM
5434 
5435+ifeq ($(PLATFORM), bsd)
5436+
5437+STATIC_LIBRARY_DIR = $(OBJDIR)/static
5438+STATIC_LIBRARY_NAME = lib$(LIBRARY).a
5439+STATIC_LIBRARY = $(STATIC_LIBRARY_DIR)/$(STATIC_LIBRARY_NAME)
5440+
5441+$(STATIC_LIBRARY_DIR): $(OBJDIR)
5442+       @$(MKDIR) $(STATIC_LIBRARY_DIR)
5443+
5444+$(STATIC_LIBRARY): $(STATIC_LIBRARY_DIR)
5445+       @$(prep-target)
5446+       $(AR) -r $@ $(FILES_o)
5447+
5448+library:: $(STATIC_LIBRARY)
5449+
5450+endif  # PLATFORM
5451+
5452 #
5453 # Add to ambient vpath so we pick up the library files
5454 #
5455-vpath %.c $(LAUNCHER_SHARE_SRC) $(ZIP_SRC)
5456+vpath %.c $(LAUNCHER_SHARE_SRC)
5457+ifneq ($(SYSTEM_ZLIB),true)
5458+  vpath %.c $(ZIP_SRC)
5459+endif
5460+
5461 
5462diff -upr ../orig/jdk/make/java/management/Makefile ./jdk/make/java/management/Makefile
5463--- ../orig/jdk/make/java/management/Makefile   2009-01-27 15:44:39.000000000 -0500
5464+++ ./jdk/make/java/management/Makefile 2009-05-04 17:37:15.000000000 -0400
5465@@ -85,6 +85,11 @@ vpath %.c $(PLATFORM_SRC)/native/com/sun
5466 OTHER_INCLUDES += \
5467   -I$(SHARE_SRC)/native/sun/management
5468 
5469+ifeq ($(PLATFORM),bsd)
5470+OTHER_INCLUDES += \
5471+  -I$(PLATFORM_SRC)/hpi/include
5472+endif
5473+
5474 ifeq ($(PLATFORM),windows)
5475   OTHER_LDLIBS += $(JVMLIB)
5476 endif
5477diff -upr ../orig/jdk/make/java/net/FILES_c.gmk ./jdk/make/java/net/FILES_c.gmk
5478--- ../orig/jdk/make/java/net/FILES_c.gmk       2009-01-27 15:44:39.000000000 -0500
5479+++ ./jdk/make/java/net/FILES_c.gmk     2009-05-05 08:29:02.000000000 -0400
5480@@ -43,6 +43,10 @@ ifeq ($(PLATFORM), linux)
5481     FILES_c += linux_close.c
5482 endif
5483 
5484+ifeq ($(OS_VENDOR), FreeBSD)
5485+    FILES_c += bsd_close.c
5486+endif
5487+
5488 ifeq ($(PLATFORM), windows)
5489     FILES_c += TwoStacksPlainSocketImpl.c
5490     FILES_c += DualStackPlainSocketImpl.c
5491diff -upr ../orig/jdk/make/java/net/Makefile ./jdk/make/java/net/Makefile
5492--- ../orig/jdk/make/java/net/Makefile  2009-01-27 15:44:39.000000000 -0500
5493+++ ./jdk/make/java/net/Makefile        2009-05-05 08:30:25.000000000 -0400
5494@@ -92,6 +92,12 @@ include $(BUILDDIR)/common/Mapfile-vers.
5495 
5496 include $(BUILDDIR)/common/Library.gmk
5497 
5498+ifeq ($(PLATFORM), bsd)
5499+  ifdef DONT_ENABLE_IPV6
5500+    OTHER_CFLAGS += -DDONT_ENABLE_IPV6
5501+  endif
5502+  OTHER_LDLIBS = $(JVMLIB) -pthread
5503+else
5504 ifeq ($(PLATFORM), windows)
5505   OTHER_LDLIBS = ws2_32.lib $(JVMLIB)
5506   # Will not compile at warning level 3 if warnings are fatal
5507@@ -102,6 +108,7 @@ endif
5508 ifeq ($(PLATFORM), linux)
5509   OTHER_LDLIBS += -lpthread
5510 endif
5511+endif # PLATFORM == bsd
5512 
5513 CLASSES.export += java.lang.Integer java.io.FileDescriptor java.net.InetAddressImplFactory java.net.Inet4AddressImpl java.net.Inet6AddressImpl
5514 
5515diff -upr ../orig/jdk/make/java/nio/Makefile ./jdk/make/java/nio/Makefile
5516--- ../orig/jdk/make/java/nio/Makefile  2009-01-27 15:44:39.000000000 -0500
5517+++ ./jdk/make/java/nio/Makefile        2009-05-04 17:37:15.000000000 -0400
5518@@ -82,7 +82,7 @@ FILES_export += \
5519        sun/nio/ch/WindowsSelectorImpl.java
5520 endif # PLATFORM = windows
5521 
5522-ifeq ($(PLATFORM), linux)
5523+ifneq (,$(findstring $(PLATFORM), linux bsd))
5524 FILES_java += \
5525         sun/nio/ch/AbstractPollSelectorImpl.java \
5526        sun/nio/ch/EPollArrayWrapper.java \
5527@@ -126,6 +126,11 @@ OTHER_INCLUDES += \
5528   -I$(PLATFORM_SRC)/native/java/net \
5529   -I$(CLASSHDRDIR)/../../../java.lang/java/CClassHeaders
5530 
5531+ifeq ($(PLATFORM), bsd)
5532+OTHER_INCLUDES += \
5533+  -I$(PLATFORM_SRC)/hpi/include
5534+endif
5535+
5536 ifeq ($(PLATFORM),windows)
5537   OTHER_LDLIBS += $(JVMLIB) ws2_32.lib \
5538      -libpath:$(LIBDIR) java.lib \
5539@@ -137,6 +142,9 @@ ifeq ($(PLATFORM), linux)
5540 COMPILER_WARNINGS_FATAL=true
5541 OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -lnet -lpthread -ldl
5542 endif
5543+ifeq ($(PLATFORM), bsd)
5544+OTHER_LDLIBS += -L$(LIBDIR)/$(LIBARCH) -ljava -lnet -pthread
5545+endif
5546 ifeq ($(PLATFORM), solaris)
5547 OTHER_LDLIBS += $(JVMLIB) $(LIBSOCKET) -lposix4 -ldl \
5548                -L$(LIBDIR)/$(LIBARCH) -ljava -lnet
5549@@ -159,6 +167,9 @@ endif
5550 ifeq ($(PLATFORM), linux)
5551 FILES_m = mapfile-linux
5552 endif
5553+ifeq ($(PLATFORM), bsd)
5554+FILES_m = mapfile-bsd
5555+endif
5556 include $(BUILDDIR)/common/Mapfile-vers.gmk
5557 include $(BUILDDIR)/common/Library.gmk
5558 
5559diff -upr ../orig/jdk/make/java/npt/Makefile ./jdk/make/java/npt/Makefile
5560--- ../orig/jdk/make/java/npt/Makefile  2009-01-27 15:44:39.000000000 -0500
5561+++ ./jdk/make/java/npt/Makefile        2009-05-05 09:08:01.000000000 -0400
5562@@ -70,6 +70,18 @@ ifeq ($(PLATFORM), windows)
5563   OTHER_LCF += -export:nptInitialize -export:nptTerminate
5564 endif
5565 
5566+# Add location of iconv headers & libs
5567+ifeq ($(PLATFORM), bsd)
5568+  ifeq ($(OS_VENDOR), Apple)
5569+    OTHER_LDLIBS += -liconv
5570+  else
5571+    ifneq ($(OS_NAME), netbsd)
5572+      CPPFLAGS += -I$(PACKAGE_PATH)/include
5573+      OTHER_LDLIBS += -L$(PACKAGE_PATH)/lib -liconv
5574+    endif
5575+  endif
5576+endif
5577+
5578 #
5579 # Add to ambient vpath so we pick up the library files
5580 #
5581diff -upr ../orig/jdk/make/java/redist/FILES.gmk ./jdk/make/java/redist/FILES.gmk
5582--- ../orig/jdk/make/java/redist/FILES.gmk      2009-01-27 15:44:39.000000000 -0500
5583+++ ./jdk/make/java/redist/FILES.gmk    2009-05-04 17:37:15.000000000 -0400
5584@@ -38,6 +38,14 @@ SHARED_FONTFILES =                                   \
5585        $(LIBDIR)/fonts/LucidaSansDemiBold.ttf          \
5586 
5587 ifeq ($(PLATFORM), linux)
5588+NEED_OBLIQUE_FONTS = true
5589+endif
5590+
5591+ifeq ($(PLATFORM), bsd)
5592+NEED_OBLIQUE_FONTS = true
5593+endif
5594+
5595+ifeq ($(NEED_OBLIQUE_FONTS), true)
5596 
5597 # The oblique versions of the font are derived from the base versions
5598 # and since 2D can do this derivation on the fly at run time there is no
5599diff -upr ../orig/jdk/make/java/redist/Makefile ./jdk/make/java/redist/Makefile
5600--- ../orig/jdk/make/java/redist/Makefile       2009-01-27 15:44:39.000000000 -0500
5601+++ ./jdk/make/java/redist/Makefile     2009-05-04 17:37:15.000000000 -0400
5602@@ -85,6 +85,11 @@ ifeq ($(SA_EXISTS), false)
5603   INCLUDE_SA := false
5604 endif
5605 
5606+# FIXME: Remove when the build of libsaproc is fixed.
5607+ifeq ($(PLATFORM), bsd)
5608+  INCLUDE_SA := false
5609+endif
5610+
5611 ifeq ($(INCLUDE_SA), true)
5612   IMPORT_LIST += $(LIBDIR)/sa-jdi.jar \
5613                  $(LIB_LOCATION)/$(SALIB_NAME)
5614@@ -312,7 +317,7 @@ $(LIBDIR)/fonts/%.ttf: $(CLOSED_SRC)/sha
5615 $(FONTSDIRFILE): $(PLATFORM_SRC)/classes/sun/awt/motif/java.fonts.dir
5616        $(install-file)
5617 
5618-ifeq ($(PLATFORM), linux)
5619+ifneq (,$(findstring $(PLATFORM), linux bsd))
5620 
5621 # The oblique fonts are only needed/wanted on Linux.
5622 
5623@@ -326,7 +331,7 @@ $(LIBDIR)/oblique-fonts/%.ttf: $(CLOSED_
5624 $(OBLFONTSDIRFILE): $(PLATFORM_SRC)/classes/sun/awt/motif/java.oblique-fonts.dir
5625        $(install-file)
5626 
5627-endif # linux
5628+endif # linux || bsd
5629 endif # !OPENJDK
5630 
5631 # Import internal files (ones that are stashed in this source tree)
5632diff -upr ../orig/jdk/make/java/security/Makefile ./jdk/make/java/security/Makefile
5633--- ../orig/jdk/make/java/security/Makefile     2009-01-27 15:44:39.000000000 -0500
5634+++ ./jdk/make/java/security/Makefile   2009-05-04 17:37:15.000000000 -0400
5635@@ -51,7 +51,15 @@ ifeq ($(PLATFORM), windows)
5636   ifneq ($(ARCH_DATA_MODEL), 64)
5637     PROPS_SRC   = $(TOPDIR)/src/share/lib/security/java.security-windows
5638   endif
5639+
5640+else # windows
5641+
5642+ifeq ($(PLATFORM), bsd)
5643+  ifeq ($(OS_VENDOR), OpenBSD)
5644+    PROPS_SRC   = $(TOPDIR)/src/share/lib/security/java.security-openbsd
5645+  endif
5646 endif
5647+endif # windows
5648 endif # PLATFORM
5649 
5650 
5651diff -upr ../orig/jdk/make/java/zip/FILES_c.gmk ./jdk/make/java/zip/FILES_c.gmk
5652--- ../orig/jdk/make/java/zip/FILES_c.gmk       2009-01-27 15:44:39.000000000 -0500
5653+++ ./jdk/make/java/zip/FILES_c.gmk     2009-05-04 17:37:15.000000000 -0400
5654@@ -30,6 +30,10 @@ FILES_c = \
5655        Inflater.c \
5656        ZipFile.c \
5657        ZipEntry.c \
5658+       zip_util.c
5659+
5660+ifneq ($(SYSTEM_ZLIB),true)
5661+FILES_c += \
5662        zadler32.c \
5663        zcrc32.c \
5664        deflate.c \
5665@@ -40,5 +44,5 @@ FILES_c = \
5666        inftrees.c \
5667        infcodes.c \
5668        infutil.c \
5669-       inffast.c \
5670-       zip_util.c
5671+       inffast.c
5672+endif
5673diff -upr ../orig/jdk/make/java/zip/Makefile ./jdk/make/java/zip/Makefile
5674--- ../orig/jdk/make/java/zip/Makefile  2009-01-27 15:44:39.000000000 -0500
5675+++ ./jdk/make/java/zip/Makefile        2009-05-04 17:37:15.000000000 -0400
5676@@ -72,16 +72,24 @@ else
5677 CPPFLAGS += -UDEBUG
5678 endif
5679 
5680-CPPFLAGS += -I$(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
5681 CPPFLAGS += -I$(SHARE_SRC)/native/java/io
5682 CPPFLAGS += -I$(PLATFORM_SRC)/native/java/io
5683 
5684+ifneq ($(SYSTEM_ZLIB),true)
5685+CPPFLAGS += -I$(SHARE_SRC)/native/java/util/zip/zlib-$(ZLIB_VERSION)
5686+
5687 #
5688 # Add to ambient vpath so we pick up the library files
5689 #
5690 vpath %.c $(SHARE_SRC)/native/$(PKGDIR)/zlib-$(ZLIB_VERSION)
5691+endif
5692 
5693 #
5694 # Link to JVM library for JVM_Zip* functions
5695 #
5696+ifeq ($(SYSTEM_ZLIB),true)
5697+OTHER_LDLIBS = -lz
5698+else
5699 OTHER_LDLIBS = $(JVMLIB)
5700+endif
5701+
5702diff -upr ../orig/jdk/make/javax/sound/FILES_c.gmk ./jdk/make/javax/sound/FILES_c.gmk
5703--- ../orig/jdk/make/javax/sound/FILES_c.gmk    2009-01-27 15:44:39.000000000 -0500
5704+++ ./jdk/make/javax/sound/FILES_c.gmk  2009-05-04 17:37:15.000000000 -0400
5705@@ -34,6 +34,8 @@ FILES_solaris = \
5706 
5707 FILES_linux =
5708 
5709+FILES_bsd =
5710+
5711 FILES_windows = \
5712        PLATFORM_API_WinOS_MidiIn.c \
5713        PLATFORM_API_WinOS_MidiOut.c \
5714diff -upr ../orig/jdk/make/javax/sound/Makefile ./jdk/make/javax/sound/Makefile
5715--- ../orig/jdk/make/javax/sound/Makefile       2009-01-27 15:44:39.000000000 -0500
5716+++ ./jdk/make/javax/sound/Makefile     2009-05-04 17:37:15.000000000 -0400
5717@@ -107,6 +107,19 @@ ifeq ($(PLATFORM), linux)
5718   #MXSPP_ADD = $(PLATFORM)-$(ARCH)/
5719 endif # PLATFORM linux
5720 
5721+# XXXBSD: ???
5722+ifeq ($(PLATFORM), bsd)
5723+    # build with empty MIDI i/o
5724+    INCLUDE_MIDI = TRUE
5725+    # build with empty ports
5726+    INCLUDE_PORTS = TRUE
5727+    # build with empty direct audio
5728+    INCLUDE_DAUDIO = TRUE
5729+    ifeq ($(OS_VENDOR), OpenBSD)
5730+      LDFLAGS += -lossaudio
5731+    endif
5732+endif # PLATFORM bsd
5733+
5734 ifeq ($(PLATFORM), solaris)
5735   ifneq ($(ARCH), amd64)
5736     # build with ports and direct audio
5737diff -upr ../orig/jdk/make/javax/sound/SoundDefs.gmk ./jdk/make/javax/sound/SoundDefs.gmk
5738--- ../orig/jdk/make/javax/sound/SoundDefs.gmk  2009-01-27 15:44:39.000000000 -0500
5739+++ ./jdk/make/javax/sound/SoundDefs.gmk        2009-05-04 17:37:15.000000000 -0400
5740@@ -40,6 +40,10 @@ ifeq ($(PLATFORM), linux)
5741   CPPFLAGS += -DX_PLATFORM=X_LINUX
5742 endif # PLATFORM linux
5743 
5744+ifeq ($(PLATFORM), bsd)
5745+  CPPFLAGS += -DX_PLATFORM=X_BSD
5746+endif # PLATFORM bsd
5747+
5748 ifeq ($(PLATFORM), solaris)
5749   CPPFLAGS += -DX_PLATFORM=X_SOLARIS
5750 
5751diff -upr ../orig/jdk/make/jpda/back/Makefile ./jdk/make/jpda/back/Makefile
5752--- ../orig/jdk/make/jpda/back/Makefile 2009-01-27 15:44:39.000000000 -0500
5753+++ ./jdk/make/jpda/back/Makefile       2009-05-04 17:37:15.000000000 -0400
5754@@ -49,8 +49,10 @@ OTHER_INCLUDES = -I$(SHARE_SRC)/transpor
5755                  -I$(GENNATIVESRCDIR)/jdwp
5756 
5757 ifneq ($(PLATFORM), windows)
5758+ifneq ($(PLATFORM), bsd)
5759   OTHER_LDLIBS += -ldl
5760 endif # PLATFORM
5761+endif # PLATFORM
5762 
5763 #
5764 # This turns off all assert() checking in the optimized library
5765diff -upr ../orig/jdk/make/jpda/transport/socket/Makefile ./jdk/make/jpda/transport/socket/Makefile
5766--- ../orig/jdk/make/jpda/transport/socket/Makefile     2009-01-27 15:44:39.000000000 -0500
5767+++ ./jdk/make/jpda/transport/socket/Makefile   2009-05-04 17:37:15.000000000 -0400
5768@@ -45,6 +45,11 @@ ifeq ($(PLATFORM), linux)
5769   OTHER_LDLIBS += -lnsl $(LIBSOCKET) -lpthread
5770 endif
5771 
5772+ifeq ($(PLATFORM), bsd)
5773+  LIBSOCKET =
5774+  OTHER_LDLIBS += -pthread
5775+endif
5776+
5777 ifeq ($(PLATFORM), solaris)
5778   OTHER_LDLIBS += -lnsl $(LIBSOCKET)
5779 endif
5780diff -upr ../orig/jdk/make/sun/awt/Makefile ./jdk/make/sun/awt/Makefile
5781--- ../orig/jdk/make/sun/awt/Makefile   2009-01-27 15:44:42.000000000 -0500
5782+++ ./jdk/make/sun/awt/Makefile 2009-05-05 09:13:17.000000000 -0400
5783@@ -129,6 +129,14 @@ OTHER_CFLAGS += -DMOTIF_VERSION=2
5784 OTHER_LDLIBS = $(JVMLIB) $(LIBM) -ldl
5785 endif
5786 
5787+ifeq  ($(PLATFORM), bsd)
5788+FILES_c = $(FILES_2D_c)
5789+FILES_c += awt_LoadLibrary.c
5790+OTHER_CFLAGS += -DMLIB_NO_LIBSUNMATH
5791+OTHER_CFLAGS += -DMOTIF_VERSION=2
5792+OTHER_LDLIBS = $(JVMLIB) $(LIBM)
5793+endif
5794+
5795 FILES_c += initIDs.c
5796 
5797 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLARIS/LINUX
5798@@ -241,7 +249,7 @@ vpath %.c     $(SHARE_SRC)/native/$(PKGD
5799 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ WINDOWS
5800 endif # PLATFORM
5801 
5802-ifeq ($(PLATFORM), linux)
5803+ifneq (,$(findstring $(PLATFORM), linux bsd))
5804 # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv LINUX
5805 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/../java2d/opengl
5806 vpath %.c   $(PLATFORM_SRC)/native/$(PKGDIR)/../java2d/opengl
5807@@ -421,6 +429,19 @@ FONTCONFIGS_SRC_PREFIX = $(PLATFORM).
5808 # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SOLARIS
5809 endif # PLATFORM
5810 
5811+ifeq ($(PLATFORM), bsd)
5812+# vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv BSD
5813+
5814+FONTCONFIGS_SRC = $(PLATFORM_SRC)/classes/sun/awt/fontconfigs
5815+_FONTCONFIGS   = \
5816+       fontconfig.properties
5817+
5818+FONTCONFIGS_SRC_PREFIX = $(PLATFORM).
5819+
5820+# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ BSD
5821+endif # PLATFORM
5822+
5823+
5824 FONTCONFIGS     = $(_FONTCONFIGS:%=$(LIBDIR)/%.src)
5825 BINARYFONTCONFIGS = $(_FONTCONFIGS:%.properties=$(LIBDIR)/%.bfc)
5826 
5827@@ -514,6 +535,9 @@ CPPFLAGS += -I$(MOTIF_DIR)/include \
5828             -I$(OPENWIN_HOME)/include/X11/extensions \
5829             -I$(PLATFORM_SRC)/native/$(PKGDIR)/font
5830 endif
5831+ifeq ($(PLATFORM), bsd)
5832+CPPFLAGS += -I$(PLATFORM_SRC)/native/$(PKGDIR)/font
5833+endif
5834 CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/debug \
5835             -I$(SHARE_SRC)/native/$(PKGDIR)/../font \
5836             -I$(PLATFORM_SRC)/native/$(PKGDIR)/../font \
5837@@ -535,7 +559,13 @@ CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGD
5838             -I$(PLATFORM_SRC)/native/$(PKGDIR) \
5839            $(EVENT_MODEL)
5840 
5841-ifeq ($(PLATFORM), linux)
5842+# include these last so we don't pick up unintentional includes
5843+ifeq ($(PLATFORM), bsd)
5844+CPPFLAGS += -I$(OPENWIN_HOME)/include \
5845+            -I$(OPENWIN_HOME)/include/X11/extensions
5846+endif
5847+
5848+ifneq (,$(findstring $(PLATFORM), linux bsd))
5849 LDFLAGS += -L$(MOTIF_LIB) -L$(OPENWIN_LIB)
5850 endif
5851 
5852diff -upr ../orig/jdk/make/sun/awt/mawt.gmk ./jdk/make/sun/awt/mawt.gmk
5853--- ../orig/jdk/make/sun/awt/mawt.gmk   2009-01-27 15:44:42.000000000 -0500
5854+++ ./jdk/make/sun/awt/mawt.gmk 2009-05-04 17:37:15.000000000 -0400
5855@@ -172,7 +172,7 @@ ifeq ($(PLATFORM), solaris)
5856 OTHER_LDLIBS = $(LIBXM) -lXt -lXext $(LIBXTST) $(LIBXMU) -lX11 -lXi
5857 endif
5858 
5859-ifeq ($(PLATFORM), linux)
5860+ifneq (,$(findstring $(PLATFORM), linux bsd))
5861 OTHER_CFLAGS += -DMLIB_NO_LIBSUNMATH
5862 OTHER_CFLAGS += -DMOTIF_VERSION=2
5863 OTHER_CFLAGS += -DXMSTRINGDEFINES=1
5864@@ -183,7 +183,11 @@ endif
5865 # !HEADLESS
5866 
5867 OTHER_LDLIBS += $(JVMLIB) $(LIBCXX) \
5868-                -lawt $(LIBM) -ldl
5869+                -lawt $(LIBM)
5870+
5871+ifneq ($(PLATFORM), bsd)
5872+OTHER_LDLIBS += -ldl
5873+endif
5874 
5875 #
5876 # Sun CC with -Xa misdefines __STDC__ to 0 (zero).
5877@@ -227,16 +231,33 @@ CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGD
5878         -I$(PLATFORM_SRC)/native/$(PKGDIR) \
5879         $(EVENT_MODEL)
5880 
5881+CPPFLAGS += -I$(CUPS_HEADERS_PATH)
5882+
5883+ifndef HEADLESS
5884+CPPFLAGS += -I$(MOTIF_DIR)/include \
5885+            -I$(OPENWIN_HOME)/include
5886+LDFLAGS  += -L$(MOTIF_LIB) -L$(OPENWIN_LIB)
5887+
5888+endif # !HEADLESS
5889+
5890 ifeq ($(PLATFORM), linux)
5891 # Checking for the X11/extensions headers at the additional location
5892   CPPFLAGS += -I/X11R6/include/X11/extensions \
5893               -I/usr/include/X11/extensions
5894 endif
5895 
5896+ifeq ($(PLATFORM), bsd)
5897+  CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions \
5898+              -I$(OPENWIN_HOME)/include
5899+endif
5900+
5901 ifeq ($(PLATFORM), solaris)
5902   CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions
5903 endif
5904 
5905+ifneq ($(PLATFORM), windows)
5906+  CPPFLAGS += -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
5907+endif
5908 
5909 LDFLAGS += -L$(LIBDIR)/$(LIBARCH)/$(TSOBJDIR) \
5910           $(AWT_RUNPATH)
5911diff -upr ../orig/jdk/make/sun/font/Makefile ./jdk/make/sun/font/Makefile
5912--- ../orig/jdk/make/sun/font/Makefile  2009-01-27 15:44:42.000000000 -0500
5913+++ ./jdk/make/sun/font/Makefile        2009-05-04 17:37:15.000000000 -0400
5914@@ -177,6 +177,15 @@ else # PLATFORM
5915 # Libraries to link, and other C flags.
5916 #
5917 
5918+ifeq ($(PLATFORM), bsd)
5919+OTHER_INCLUDES += -I$(X11_PATH)/include
5920+OTHER_LDLIBS  += -lawt $(LIBM) $(LIBCXX)
5921+ ifeq ($(OS_VENDOR),Apple)
5922+   # XXXDARWIN Match BSD/Linux behavior -- the mawt.dylib symbols will
5923+   # be available at runtime.
5924+   OTHER_LDLIBS += -flat_namespace -undefined suppress
5925+ endif
5926+else
5927 ifeq ($(PLATFORM), solaris)
5928   # Note that on Solaris, fontmanager is built against the headless library.
5929   LDFLAGS      += -L$(LIBDIR)/$(LIBARCH)/headless
5930@@ -187,6 +196,7 @@ else # PLATFORM is linux
5931     OTHER_LDLIBS  += -Wl,-Bstatic -lgcc_eh -Wl,-Bdynamic
5932   endif                           
5933 endif
5934+endif
5935 
5936 endif # PLATFORM
5937 
5938diff -upr ../orig/jdk/make/sun/image/generic/Makefile ./jdk/make/sun/image/generic/Makefile
5939--- ../orig/jdk/make/sun/image/generic/Makefile 2009-01-27 15:44:43.000000000 -0500
5940+++ ./jdk/make/sun/image/generic/Makefile       2009-05-04 17:37:15.000000000 -0400
5941@@ -69,5 +69,9 @@ CPPFLAGS += \
5942             -I$(PLATFORM_SRC)/native/$(PKGDIR)/medialib
5943 
5944 OTHER_CFLAGS += -D__USE_J2D_NAMES -D__MEDIALIB_OLD_NAMES
5945-OTHER_LDLIBS = $(LIBM) -ldl
5946+OTHER_LDLIBS = $(LIBM)
5947+ifneq ($(PLATFORM), bsd)
5948+OTHER_LDLIBS += -ldl
5949+endif
5950+
5951 
5952diff -upr ../orig/jdk/make/sun/jawt/Makefile ./jdk/make/sun/jawt/Makefile
5953--- ../orig/jdk/make/sun/jawt/Makefile  2009-01-27 15:44:43.000000000 -0500
5954+++ ./jdk/make/sun/jawt/Makefile        2009-05-05 08:50:43.000000000 -0400
5955@@ -98,9 +98,7 @@ else # PLATFORM
5956 #
5957 # Other extra flags needed for compiling.
5958 #
5959-CPPFLAGS += -I$(OPENWIN_HOME)/include \
5960-           -I$(MOTIF_DIR)/include \
5961-           -I$(SHARE_SRC)/native/$(PKGDIR)/debug \
5962+CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/debug \
5963             -I$(SHARE_SRC)/native/$(PKGDIR)/image \
5964            -I$(SHARE_SRC)/native/$(PKGDIR)/image/cvutils \
5965            -I$(SHARE_SRC)/native/$(PKGDIR)/alphacomposite \
5966@@ -114,6 +112,8 @@ CPPFLAGS += -I$(OPENWIN_HOME)/include \
5967            -I$(SHARE_SRC)/native/$(PKGDIR)/../dc/doe \
5968            -I$(SHARE_SRC)/native/$(PKGDIR)/../dc/path \
5969             -I$(PLATFORM_SRC)/native/$(PKGDIR)/../jdga \
5970+           -I$(OPENWIN_HOME)/include \
5971+           -I$(MOTIF_DIR)/include \
5972            $(EVENT_MODEL)
5973 #
5974 # Libraries to link in.
5975@@ -122,7 +122,7 @@ ifeq ($(PLATFORM), solaris)
5976 OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -L$(OPENWIN_LIB) -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt
5977 endif # PLATFORM
5978 
5979-ifeq ($(PLATFORM), linux)
5980+ifneq (,$(findstring $(PLATFORM), linux bsd))
5981 OTHER_LDLIBS = -L$(LIBDIR)/$(LIBARCH) -lawt -L$(LIBDIR)/$(LIBARCH)/xawt -lmawt
5982 endif # PLATFORM
5983 
5984diff -upr ../orig/jdk/make/sun/security/jgss/wrapper/Makefile ./jdk/make/sun/security/jgss/wrapper/Makefile
5985--- ../orig/jdk/make/sun/security/jgss/wrapper/Makefile 2009-01-27 15:44:44.000000000 -0500
5986+++ ./jdk/make/sun/security/jgss/wrapper/Makefile       2009-05-04 17:37:15.000000000 -0400
5987@@ -71,6 +71,10 @@ include $(BUILDDIR)/common/Library.gmk
5988 #
5989 # Libraries to link
5990 #
5991-ifneq ($(PLATFORM), windows)
5992+ifneq (,$(findstring $(PLATFORM), linux solaris))
5993   OTHER_LDLIBS = -ldl $(JVMLIB)
5994 endif
5995+
5996+ifeq ($(PLATFORM), bsd)
5997+  OTHER_LDLIBS = $(JVMLIB)
5998+endif
5999diff -upr ../orig/jdk/make/sun/security/pkcs11/Makefile ./jdk/make/sun/security/pkcs11/Makefile
6000--- ../orig/jdk/make/sun/security/pkcs11/Makefile       2009-01-27 15:44:44.000000000 -0500
6001+++ ./jdk/make/sun/security/pkcs11/Makefile     2009-05-04 17:37:15.000000000 -0400
6002@@ -155,7 +155,7 @@ include $(BUILDDIR)/common/Library.gmk
6003 #
6004 # Libraries to link
6005 #
6006-ifeq ($(PLATFORM), windows)
6007+ifneq (,$(findstring $(PLATFORM), windows bsd))
6008   OTHER_LDLIBS = $(JVMLIB)
6009 else
6010   OTHER_LDLIBS = -ldl $(JVMLIB)
6011diff -upr ../orig/jdk/make/sun/security/smartcardio/Makefile ./jdk/make/sun/security/smartcardio/Makefile
6012--- ../orig/jdk/make/sun/security/smartcardio/Makefile  2009-01-27 15:44:44.000000000 -0500
6013+++ ./jdk/make/sun/security/smartcardio/Makefile        2009-05-04 17:37:15.000000000 -0400
6014@@ -75,6 +75,10 @@ include $(BUILDDIR)/common/Library.gmk
6015 ifeq ($(PLATFORM), windows)
6016   OTHER_LDLIBS = $(JVMLIB) winscard.lib
6017 else
6018-  OTHER_LDLIBS = -ldl $(JVMLIB)
6019+  ifeq ($(PLATFORM), bsd)
6020+    OTHER_LDLIBS = $(JVMLIB)
6021+  else
6022+    OTHER_LDLIBS = -ldl $(JVMLIB)
6023+  endif
6024   OTHER_CFLAGS = -D__sun_jdk
6025 endif
6026diff -upr ../orig/jdk/make/sun/splashscreen/FILES_c.gmk ./jdk/make/sun/splashscreen/FILES_c.gmk
6027--- ../orig/jdk/make/sun/splashscreen/FILES_c.gmk       2009-01-27 15:44:45.000000000 -0500
6028+++ ./jdk/make/sun/splashscreen/FILES_c.gmk     2009-05-04 17:37:15.000000000 -0400
6029@@ -49,20 +49,6 @@ FILES_c = \
6030        dgif_lib.c \
6031        gif_err.c \
6032        gifalloc.c \
6033-       compress.c \
6034-       deflate.c \
6035-       gzio.c \
6036-       infblock.c \
6037-       infcodes.c \
6038-       inffast.c \
6039-       inflate.c \
6040-       inftrees.c \
6041-       infutil.c \
6042-       trees.c \
6043-       uncompr.c \
6044-       zadler32.c \
6045-       zcrc32.c \
6046-       zutil.c \
6047        jcomapi.c \
6048        jdapimin.c \
6049        jdapistd.c \
6050@@ -108,3 +94,20 @@ FILES_c = \
6051        jfdctfst.c \
6052        jfdctint.c
6053 
6054+ifneq ($(SYSTEM_ZLIB),true)
6055+  FILES_c += \
6056+       compress.c \
6057+       deflate.c \
6058+       gzio.c \
6059+       infblock.c \
6060+       infcodes.c \
6061+       inffast.c \
6062+       inflate.c \
6063+       inftrees.c \
6064+       infutil.c \
6065+       trees.c \
6066+       uncompr.c \
6067+       zadler32.c \
6068+       zcrc32.c \
6069+       zutil.c
6070+endif
6071diff -upr ../orig/jdk/make/sun/splashscreen/Makefile ./jdk/make/sun/splashscreen/Makefile
6072--- ../orig/jdk/make/sun/splashscreen/Makefile  2009-01-27 15:44:45.000000000 -0500
6073+++ ./jdk/make/sun/splashscreen/Makefile        2009-05-04 17:37:15.000000000 -0400
6074@@ -61,10 +61,26 @@ JAVALIB=
6075 
6076 CFLAGS += -DSPLASHSCREEN
6077 
6078+CPPFLAGS += -I$(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen -I$(SHARE_SRC)/native/$(PKGDIR)/splashscreen
6079+CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/image/jpeg
6080+ifneq ($(SYSTEM_ZLIB),true)
6081+  CPPFLAGS += -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
6082+endif
6083+
6084+
6085 ifneq ($(PLATFORM), windows)
6086   CFLAGS += -DWITH_X11
6087-  CPPFLAGS += -I$(OPENWIN_HOME)/include -I$(OPENWIN_HOME)/include/X11/extensions
6088-  OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -lpthread
6089+  ifeq ($(PLATFORM), bsd)
6090+    CFLAGS += -DPNG_NO_MMX_CODE
6091+    ICONV_PATH = $(PACKAGE_PATH)
6092+    CPPFLAGS += -I$(OPENWIN_HOME)/include \
6093+                -I$(OPENWIN_HOME)/include/X11/extensions \
6094+                -I$(ICONV_PATH)/include
6095+    OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext -L$(ICONV_PATH)/lib -liconv $(LIBM) -pthread
6096+  else
6097+    CPPFLAGS += -I$(OPENWIN_HOME)/include -I$(OPENWIN_HOME)/include/X11/extensions
6098+    OTHER_LDLIBS += -L$(OPENWIN_LIB) -lX11 -lXext $(LIBM) -lpthread
6099+  endif
6100 else # PLATFORM
6101   CFLAGS += -DWITH_WIN32
6102   OTHER_LDLIBS += kernel32.lib user32.lib gdi32.lib
6103@@ -77,14 +93,13 @@ endif # PLATFORM
6104 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/splashscreen
6105 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)
6106 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/giflib
6107-vpath %.c   $(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
6108+ifneq ($(SYSTEM_ZLIB),true)
6109+  vpath %.c   $(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
6110+endif
6111 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/libpng
6112 vpath %.c   $(SHARE_SRC)/native/$(PKGDIR)/image/jpeg
6113 vpath %.c   $(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen
6114 
6115-CPPFLAGS += -I$(PLATFORM_SRC)/native/$(PKGDIR)/splashscreen -I$(SHARE_SRC)/native/$(PKGDIR)/splashscreen
6116-CPPFLAGS += -I$(SHARE_SRC)/native/$(PKGDIR)/image/jpeg -I$(SHARE_SRC)/native/java/util/zip/zlib-1.1.3
6117-
6118 ifeq ($(PLATFORM), linux)
6119   ifeq ($(ARCH_DATA_MODEL), 64)
6120     # 64-bit gcc has problems compiling MMX instructions.
6121diff -upr ../orig/jdk/make/sun/xawt/Makefile ./jdk/make/sun/xawt/Makefile
6122--- ../orig/jdk/make/sun/xawt/Makefile  2009-01-27 15:44:45.000000000 -0500
6123+++ ./jdk/make/sun/xawt/Makefile        2009-05-04 17:37:15.000000000 -0400
6124@@ -53,6 +53,11 @@ LDFLAGS += -lpthread
6125 dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
6126 endif
6127 
6128+ifeq ($(PLATFORM), bsd)
6129+LDFLAGS += -pthread
6130+dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
6131+endif
6132+
6133 # Since this library will be living in a subdirectory below the other libraries
6134 #   we need to add an extra runpath so that libraries in the upper directory
6135 #   are found at runtime.
6136@@ -86,7 +91,12 @@ vpath %.c   $(SHARE_SRC)/native/sun/java
6137 vpath %.c   $(PLATFORM_SRC)/native/sun/java2d/opengl
6138 vpath %.c   $(PLATFORM_SRC)/native/sun/java2d/x11
6139 
6140-OTHER_LDLIBS = $(LIBM) -lawt -lXext -lX11 -ldl \
6141+ifeq ($(PLATFORM), bsd)
6142+LIBDL=
6143+else
6144+LIBDL=-ldl
6145+endif
6146+OTHER_LDLIBS = $(LIBM) -lawt -lXext -lX11 $(LIBDL) \
6147                    $(LDFLAGS_COMMON) $(AWT_RUNPATH) $(OTHER_LDFLAGS) -lXtst -lXi
6148 
6149 ifeq  ($(PLATFORM), solaris)
6150@@ -94,8 +104,6 @@ CPPFLAGS += -DFUNCPROTO=15
6151 dummy := $(shell $(MKDIR) -p $(LIB_LOCATION))
6152 endif
6153 
6154-CPPFLAGS += -I$(CUPS_HEADERS_PATH)
6155-
6156 CPPFLAGS += -DXAWT -DXAWT_HACK \
6157         -I$(TEMPDIR)/../../sun.awt/awt/CClassHeaders \
6158         -I$(PLATFORM_SRC)/native/sun/awt \
6159@@ -122,9 +130,11 @@ CPPFLAGS += -DXAWT -DXAWT_HACK \
6160         -I$(SHARE_SRC)/native/sun/awt \
6161         -I$(PLATFORM_SRC)/native/sun/awt
6162 
6163+CPPFLAGS += -I$(CUPS_HEADERS_PATH)
6164+
6165 ifeq ($(PLATFORM), linux)
6166 # Allows for builds on Debian GNU Linux, X11 is in a different place
6167-  CPPFLAGS += -I/usr/X11R6/include/X11/extensions \
6168+  CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions \
6169               -I/usr/include/X11/extensions \
6170               -I$(MOTIF_DIR)/include \
6171               -I$(OPENWIN_HOME)/include
6172@@ -134,6 +144,14 @@ ifeq ($(PLATFORM), solaris)
6173   CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions -I$(MOTIF_DIR)/include
6174 endif
6175 
6176+ifeq ($(PLATFORM), bsd)
6177+  CPPFLAGS += -I$(OPENWIN_HOME)/include/X11/extensions -I$(OPENWIN_HOME)/include
6178+endif
6179+
6180+ifneq ($(PLATFORM), windows)
6181+  CPPFLAGS += -DX11_PATH=\"$(X11_PATH)\" -DPACKAGE_PATH=\"$(PACKAGE_PATH)\"
6182+endif
6183+
6184 ifeq ($(MILESTONE), internal)
6185   CPPFLAGS += -DINTERNAL_BUILD
6186 endif
6187diff -upr ../orig/jdk/make/tools/freetypecheck/Makefile ./jdk/make/tools/freetypecheck/Makefile
6188--- ../orig/jdk/make/tools/freetypecheck/Makefile       2009-01-27 15:44:46.000000000 -0500
6189+++ ./jdk/make/tools/freetypecheck/Makefile     2009-05-04 17:37:17.000000000 -0400
6190@@ -60,8 +60,12 @@ else
6191   #add runtime lib search path to ensure test will be runnable
6192   ifeq ($(PLATFORM), solaris)
6193     FT_OPTIONS += -R $(FT_LIB) -lfreetype
6194-  else #linux
6195-      FT_OPTIONS += -Wl,-rpath -Wl,$(FT_LIB) -lfreetype
6196+  else
6197+    ifeq ($(PLATFORM), bsd)
6198+      FT_OPTIONS += -lfreetype -lz
6199+    else # linux
6200+        FT_OPTIONS += -Wl,-rpath -Wl,$(FREETYPE_LIB_PATH) -lfreetype
6201+    endif
6202   endif
6203 endif
6204 
6205diff -upr ../orig/jdk/src/share/back/commonRef.c ./jdk/src/share/back/commonRef.c
6206--- ../orig/jdk/src/share/back/commonRef.c      2009-01-27 15:44:50.000000000 -0500
6207+++ ./jdk/src/share/back/commonRef.c    2009-05-04 17:37:16.000000000 -0400
6208@@ -23,6 +23,10 @@
6209  * have any questions.
6210  */
6211 
6212+#if defined(_ALLBSD_SOURCE)
6213+#include <stdint.h>                    /* for uintptr_t */
6214+#endif
6215+
6216 #include "util.h"
6217 #include "commonRef.h"
6218 
6219diff -upr ../orig/jdk/src/share/bin/java.c ./jdk/src/share/bin/java.c
6220--- ../orig/jdk/src/share/bin/java.c    2009-01-27 15:44:50.000000000 -0500
6221+++ ./jdk/src/share/bin/java.c  2009-05-04 17:37:17.000000000 -0400
6222@@ -104,6 +104,11 @@ static char *progname;
6223 static char *launchername;
6224 jboolean _launcher_debug = JNI_FALSE;
6225 
6226+#ifdef __APPLE__
6227+static jboolean continueInSameThread = JNI_FALSE; /* start VM in current thread */
6228+#endif
6229+
6230+
6231 /*
6232  * Entries for splash screen environment variables.
6233  * putenv is performed in SelectVersion. We need
6234@@ -146,6 +151,10 @@ static void PrintUsage(JNIEnv* env, jboo
6235 static void SetPaths(int argc, char **argv);
6236 
6237 
6238+#ifdef __APPLE__
6239+static int ContinueInSameThread(InvocationFunctions* ifn, int argc, char **argv, char *jarfile, char *classname, int ret);
6240+#endif
6241+
6242 /* Maximum supported entries from jvm.cfg. */
6243 #define INIT_MAX_KNOWN_VMS      10
6244 /* Values for vmdesc.flag */
6245@@ -184,13 +193,13 @@ static jlong threadStackSize = 0;  /* st
6246 
6247 int JNICALL JavaMain(void * args); /* entry point                  */
6248 
6249-struct JavaMainArgs {
6250+typedef struct {
6251   int     argc;
6252   char ** argv;
6253   char *  jarfile;
6254   char *  classname;
6255   InvocationFunctions ifn;
6256-};
6257+} JavaMainArgs;
6258 
6259 /*
6260  * Entry point.
6261@@ -332,49 +341,24 @@ main(int argc, char ** argv)
6262     /* Show the splash screen if needed */
6263     ShowSplashScreen();
6264 
6265-    /*
6266-     * Done with all command line processing and potential re-execs so
6267-     * clean up the environment.
6268-     */
6269-    (void)UnsetEnv(ENV_ENTRY);
6270-    (void)UnsetEnv(SPLASH_FILE_ENV_ENTRY);
6271-    (void)UnsetEnv(SPLASH_JAR_ENV_ENTRY);
6272-
6273-    JLI_MemFree(splash_jar_entry);
6274-    JLI_MemFree(splash_file_entry);
6275 
6276-    /*
6277-     * If user doesn't specify stack size, check if VM has a preference.
6278-     * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
6279-     * return its default stack size through the init args structure.
6280-     */
6281-    if (threadStackSize == 0) {
6282-      struct JDK1_1InitArgs args1_1;
6283-      memset((void*)&args1_1, 0, sizeof(args1_1));
6284-      args1_1.version = JNI_VERSION_1_1;
6285-      ifn.GetDefaultJavaVMInitArgs(&args1_1);  /* ignore return value */
6286-      if (args1_1.javaStackSize > 0) {
6287-         threadStackSize = args1_1.javaStackSize;
6288+#ifdef __APPLE__
6289+      if (continueInSameThread == JNI_TRUE) {
6290+        return ContinueInSameThread(&ifn, argc, argv, jarfile, classname, ret);
6291+      } else {
6292+        return ContinueInNewThread(&ifn, argc, argv, jarfile, classname, ret);
6293       }
6294-    }
6295-
6296-    { /* Create a new thread to create JVM and invoke main method */
6297-      struct JavaMainArgs args;
6298+#else
6299 
6300-      args.argc = argc;
6301-      args.argv = argv;
6302-      args.jarfile = jarfile;
6303-      args.classname = classname;
6304-      args.ifn = ifn;
6305+      return ContinueInNewThread(&ifn, argc, argv, jarfile, classname, ret);
6306+#endif
6307 
6308-      return ContinueInNewThread(JavaMain, threadStackSize, (void*)&args, ret);
6309-    }
6310 }
6311 
6312 int JNICALL
6313 JavaMain(void * _args)
6314 {
6315-    struct JavaMainArgs *args = (struct JavaMainArgs *)_args;
6316+    JavaMainArgs *args = (JavaMainArgs *)_args;
6317     int argc = args->argc;
6318     char **argv = args->argv;
6319     char *jarfile = args->jarfile;
6320@@ -1159,6 +1143,10 @@ ParseArguments(int *pargc, char ***pargv
6321         } else if (strcmp(arg, "-X") == 0) {
6322             printXUsage = JNI_TRUE;
6323             return JNI_TRUE;
6324+#ifdef __APPLE__
6325+        } else if (JLI_StrCmp(arg, "-XstartOnFirstThread") == 0) {
6326+            continueInSameThread = JNI_TRUE;
6327+#endif           
6328 /*
6329  * The following case provide backward compatibility with old-style
6330  * command line options.
6331@@ -1979,6 +1967,84 @@ KnownVMIndex(const char* name)
6332     return -1;
6333 }
6334 
6335+static int
6336+ContinueInNewThread(InvocationFunctions* ifn, int argc,
6337+                     char **argv, char *jarfile, char *classname, int ret)
6338+{
6339+
6340+    /*
6341+     * If user doesn't specify stack size, check if VM has a preference.
6342+     * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
6343+     * return its default stack size through the init args structure.
6344+     */
6345+    if (threadStackSize == 0) {
6346+      struct JDK1_1InitArgs args1_1;
6347+      memset((void*)&args1_1, 0, sizeof(args1_1));
6348+      args1_1.version = JNI_VERSION_1_1;
6349+      ifn->GetDefaultJavaVMInitArgs(&args1_1);  /* ignore return value */
6350+      if (args1_1.javaStackSize > 0) {
6351+         threadStackSize = args1_1.javaStackSize;
6352+      }
6353+    }
6354+
6355+    { /* Create a new thread to create JVM and invoke main method */
6356+      JavaMainArgs args;
6357+      int rslt;
6358+
6359+      args.argc = argc;
6360+      args.argv = argv;
6361+      args.jarfile = jarfile;
6362+      args.classname = classname;
6363+      args.ifn = *ifn;
6364+
6365+      rslt = ContinueInNewThread0(JavaMain, threadStackSize, (void*)&args);
6366+      /* If the caller has deemed there is an error we
6367+       * simply return that, otherwise we return the value of
6368+       * the callee
6369+       */
6370+      return (ret != 0) ? ret : rslt;
6371+    }
6372+}
6373+
6374+
6375+#ifdef __APPLE__
6376+static int
6377+ContinueInSameThread(InvocationFunctions* ifn, int argc,
6378+                    char **argv, char *jarfile, char *classname, int ret)
6379+{
6380+       
6381+    /*
6382+     * If user doesn't specify stack size, check if VM has a preference.
6383+     * Note that HotSpot no longer supports JNI_VERSION_1_1 but it will
6384+     * return its default stack size through the init args structure.
6385+     */
6386+    if (threadStackSize == 0) {
6387+        struct JDK1_1InitArgs args1_1;
6388+        memset((void*)&args1_1, 0, sizeof(args1_1));
6389+        args1_1.version = JNI_VERSION_1_1;
6390+        ifn->GetDefaultJavaVMInitArgs(&args1_1);  /* ignore return value */
6391+        if (args1_1.javaStackSize > 0) {
6392+            threadStackSize = args1_1.javaStackSize;
6393+        }
6394+    }
6395+   
6396+    { /* Create create JVM and invoke main method */
6397+        JavaMainArgs args;
6398+        int rslt;
6399+       
6400+        args.argc = argc;
6401+        args.argv = argv;
6402+        args.jarfile = jarfile;
6403+        args.classname = classname;
6404+        args.ifn = *ifn;
6405+       
6406+        rslt = JavaMain((void*)&args);
6407+       
6408+        return (ret != 0) ? ret : rslt;
6409+    }
6410+}
6411+#endif
6412+
6413 static void
6414 FreeKnownVMs()
6415 {
6416diff -upr ../orig/jdk/src/share/bin/java.h ./jdk/src/share/bin/java.h
6417--- ../orig/jdk/src/share/bin/java.h    2009-01-27 15:44:50.000000000 -0500
6418+++ ./jdk/src/share/bin/java.h  2009-05-04 17:37:17.000000000 -0400
6419@@ -91,11 +91,17 @@ jboolean RemovableMachineDependentOption
6420 void PrintMachineDependentOptions();
6421 
6422 const char *jlong_format_specifier();
6423+
6424 /*
6425  * Block current thread and continue execution in new thread
6426  */
6427-int ContinueInNewThread(int (JNICALL *continuation)(void *),
6428-                        jlong stack_size, void * args, int ret);
6429+int ContinueInNewThread0(int (JNICALL *continuation)(void *),
6430+                        jlong stack_size, void * args);
6431+
6432+
6433+ static int ContinueInNewThread(InvocationFunctions* ifn, int argc, char** argv,
6434+                         char* jarfile, char* classname, int ret);
6435+
6436 
6437 /* sun.java.launcher.* platform properties. */
6438 void SetJavaLauncherPlatformProps(void);
6439diff -upr ../orig/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java ./jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java
6440--- ../orig/jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java     2009-01-27 15:44:52.000000000 -0500
6441+++ ./jdk/src/share/classes/com/sun/java/swing/plaf/gtk/Metacity.java   2009-05-04 17:37:16.000000000 -0400
6442@@ -477,6 +477,10 @@ class Metacity implements SynthConstants
6443                 String[] dirs = new String[] {
6444                     userHome + sep + ".themes",
6445                     System.getProperty("swing.metacitythemedir"),
6446+                   "/usr/X11R6/share/themes",
6447+                   "/usr/X11R6/share/gnome/themes",
6448+                   "/usr/local/share/themes",
6449+                   "/usr/local/share/gnome/themes",
6450                     "/usr/share/themes",
6451                     "/usr/gnome/share/themes",  // Debian/Redhat/Solaris
6452                     "/opt/gnome2/share/themes"  // SuSE
6453diff -upr ../orig/jdk/src/share/classes/com/sun/jmx/snmp/SnmpPduTrap.java ./jdk/src/share/classes/com/sun/jmx/snmp/SnmpPduTrap.java
6454--- ../orig/jdk/src/share/classes/com/sun/jmx/snmp/SnmpPduTrap.java     2009-01-27 15:44:56.000000000 -0500
6455+++ ./jdk/src/share/classes/com/sun/jmx/snmp/SnmpPduTrap.java   2009-05-04 17:37:16.000000000 -0400
6456@@ -78,6 +78,9 @@ public class SnmpPduTrap extends SnmpPdu
6457      */
6458     public long            timeStamp ;
6459 
6460+    // TODO: IcedTea: I am a stub.
6461+    static public int trapAuthenticationFailure = 0;
6462+
6463 
6464 
6465     /**
6466diff -upr ../orig/jdk/src/share/classes/java/awt/GraphicsEnvironment.java ./jdk/src/share/classes/java/awt/GraphicsEnvironment.java
6467--- ../orig/jdk/src/share/classes/java/awt/GraphicsEnvironment.java     2009-01-27 15:45:05.000000000 -0500
6468+++ ./jdk/src/share/classes/java/awt/GraphicsEnvironment.java   2009-05-04 17:37:16.000000000 -0400
6469@@ -148,7 +148,12 @@ public abstract class GraphicsEnvironmen
6470                         } else {
6471                             String osName = System.getProperty("os.name");
6472                             headless = defaultHeadless =
6473-                                Boolean.valueOf(("Linux".equals(osName) || "SunOS".equals(osName)) &&
6474+                                Boolean.valueOf(("Linux".equals(osName) ||
6475+                                                "SunOS".equals(osName) ||
6476+                                                "FreeBSD".equals(osName) ||
6477+                                                "NetBSD".equals(osName) ||
6478+                                                "OpenBSD".equals(osName) ||
6479+                                                "Darwin".equals(osName)) &&
6480                                                 (System.getenv("DISPLAY") == null));
6481                         }
6482                     } else if (nm.equals("true")) {
6483diff -upr ../orig/jdk/src/share/classes/java/util/TimeZone.java ./jdk/src/share/classes/java/util/TimeZone.java
6484--- ../orig/jdk/src/share/classes/java/util/TimeZone.java       2009-01-27 15:45:18.000000000 -0500
6485+++ ./jdk/src/share/classes/java/util/TimeZone.java     2009-05-04 17:37:16.000000000 -0400
6486@@ -779,15 +779,13 @@ abstract public class TimeZone implement
6487         }
6488         int gmtOffset =  (hours * 60 + num) * 60 * 1000;
6489 
6490+        zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset);
6491         if (gmtOffset == 0) {
6492-            zi = ZoneInfoFile.getZoneInfo(GMT_ID);
6493             if (negative) {
6494                 zi.setID("GMT-00:00");
6495             } else {
6496                 zi.setID("GMT+00:00");
6497             }
6498-        } else {
6499-            zi = ZoneInfoFile.getCustomTimeZone(id, negative ? -gmtOffset : gmtOffset);
6500         }
6501         return zi;
6502     }
6503diff -upr ../orig/jdk/src/share/classes/sun/awt/FontConfiguration.java ./jdk/src/share/classes/sun/awt/FontConfiguration.java
6504--- ../orig/jdk/src/share/classes/sun/awt/FontConfiguration.java        2009-01-27 15:45:29.000000000 -0500
6505+++ ./jdk/src/share/classes/sun/awt/FontConfiguration.java      2009-05-04 17:37:16.000000000 -0400
6506@@ -1073,7 +1073,7 @@ public abstract class FontConfiguration
6507      */
6508     HashMap<String, Boolean> existsMap;
6509     public boolean needToSearchForFile(String fileName) {
6510-        if (!environment.isLinux) {
6511+        if (!environment.isLinuxOrBSD) {
6512             return false;
6513         } else if (existsMap == null) {
6514            existsMap = new HashMap<String, Boolean>();
6515@@ -1309,7 +1309,7 @@ public abstract class FontConfiguration
6516                                    + "<filename."
6517                                    + getString(table_componentFontNameIDs[ii])
6518                                    + "> entry is missing!!!");
6519-                if (!osName.contains("Linux")) {
6520+                if (!osName.contains("Linux") && !osName.contains("BSD") && !osName.contains("Darwin")) {
6521                     errors++;
6522                 }
6523             }
6524diff -upr ../orig/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java ./jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java
6525--- ../orig/jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java        2009-01-27 15:45:30.000000000 -0500
6526+++ ./jdk/src/share/classes/sun/java2d/SunGraphicsEnvironment.java      2009-05-04 17:37:16.000000000 -0400
6527@@ -76,7 +76,7 @@ import sun.font.NativeFont;
6528 public abstract class SunGraphicsEnvironment extends GraphicsEnvironment
6529     implements FontSupport, DisplayChangedListener {
6530 
6531-    public static boolean isLinux;
6532+    public static boolean isLinuxOrBSD;
6533     public static boolean isSolaris;
6534     public static boolean isWindows;
6535     public static boolean noType1Font;
6536@@ -164,7 +164,15 @@ public abstract class SunGraphicsEnviron
6537             public Object run() {
6538                 String osName = System.getProperty("os.name");
6539                 if ("Linux".equals(osName)) {
6540-                    isLinux = true;
6541+                    isLinuxOrBSD = true;
6542+                } else if ("FreeBSD".equals(osName)) {
6543+                    isLinuxOrBSD = true;
6544+                } else if ("Darwin".equals(osName)) {
6545+                    isLinuxOrBSD = true;
6546+                } else if ("NetBSD".equals(osName)) {
6547+                    isLinuxOrBSD = true;
6548+                } else if ("OpenBSD".equals(osName)) {
6549+                    isLinuxOrBSD = true;
6550                 } else if ("SunOS".equals(osName)) {
6551                     isSolaris = true;
6552                 } else if ("Windows".equals(osName)) {
6553@@ -227,8 +235,8 @@ public abstract class SunGraphicsEnviron
6554                  * Pass "true" to registerFonts method as on-screen these
6555                  * JRE fonts always go through the T2K rasteriser.
6556                  */
6557-                if (isLinux) {
6558-                    /* Linux font configuration uses these fonts */
6559+                if (isLinuxOrBSD) {
6560+                    /* Linux/BSD font configuration uses these fonts */
6561                     registerFontDir(jreFontDirName);
6562                 }
6563                 registerFontsInDir(jreFontDirName, true, Font2D.JRE_RANK,
6564diff -upr ../orig/jdk/src/share/classes/sun/print/PSPrinterJob.java ./jdk/src/share/classes/sun/print/PSPrinterJob.java
6565--- ../orig/jdk/src/share/classes/sun/print/PSPrinterJob.java   2009-01-27 15:45:34.000000000 -0500
6566+++ ./jdk/src/share/classes/sun/print/PSPrinterJob.java 2009-05-04 17:37:16.000000000 -0400
6567@@ -1531,7 +1531,9 @@ public class PSPrinterJob extends Raster
6568             pFlags |= NOSHEET;
6569             ncomps+=1;
6570         }
6571-       if (System.getProperty("os.name").equals("Linux")) {
6572+
6573+       String osname = System.getProperty("os.name");
6574+       if (osname.equals("Linux") || osname.equals("FreeBSD") || osname.equals("NetBSD") || osname.equals("OpenBSD") || osname.equals("Darwin")) {
6575             execCmd = new String[ncomps];
6576             execCmd[n++] = "/usr/bin/lpr";
6577             if ((pFlags & PRINTER) != 0) {
6578diff -upr ../orig/jdk/src/share/classes/sun/tools/jar/Main.java ./jdk/src/share/classes/sun/tools/jar/Main.java
6579--- ../orig/jdk/src/share/classes/sun/tools/jar/Main.java       2009-01-27 15:45:40.000000000 -0500
6580+++ ./jdk/src/share/classes/sun/tools/jar/Main.java     2009-05-04 17:37:17.000000000 -0400
6581@@ -46,6 +46,7 @@ class Main {
6582     String zname = "";
6583     String[] files;
6584     String rootjar = null;
6585+    String cwd;
6586     Hashtable filesTable = new Hashtable();
6587     Vector paths = new Vector();
6588     Vector v;
6589@@ -770,6 +771,19 @@ class Main {
6590      * Extracts specified entries from JAR file.
6591      */
6592     void extract(InputStream in, String files[]) throws IOException {
6593+        // Current working directory
6594+
6595+        cwd = System.getProperty("user.dir");
6596+        if (cwd == null) {
6597+            fatalError(getMsg("error.no.cwd"));
6598+        }
6599+        cwd = (new File(cwd)).getCanonicalPath();
6600+        if (!cwd.endsWith(File.separator)) {
6601+            cwd += File.separator;
6602+        }
6603+
6604+        // Extract the files
6605+
6606         ZipInputStream zis = new ZipInputStream(in);
6607         ZipEntry e;
6608         // Set of all directory entries specified in archive.  Dissallows
6609@@ -817,6 +831,10 @@ class Main {
6610         ZipEntry rc = null;
6611         String name = e.getName();
6612         File f = new File(e.getName().replace('/', File.separatorChar));
6613+        if (!f.getCanonicalPath().startsWith(cwd)) {
6614+            output(formatMsg("out.ignore.entry", name));
6615+            return null;
6616+        }
6617         if (e.isDirectory()) {
6618             if (f.exists()) {
6619                 if (!f.isDirectory()) {
6620@@ -838,6 +856,10 @@ class Main {
6621         } else {
6622             if (f.getParent() != null) {
6623                 File d = new File(f.getParent());
6624+                if (!d.getCanonicalPath().startsWith(cwd)) {
6625+                    output(formatMsg("out.ignore.entry", name));
6626+                    return null;
6627+                }
6628                 if (!d.exists() && !d.mkdirs() || !d.isDirectory()) {
6629                     throw new IOException(formatMsg(
6630                         "error.create.dir", d.getPath()));
6631diff -upr ../orig/jdk/src/share/classes/sun/tools/jar/resources/jar.properties ./jdk/src/share/classes/sun/tools/jar/resources/jar.properties
6632--- ../orig/jdk/src/share/classes/sun/tools/jar/resources/jar.properties        2009-01-27 15:45:40.000000000 -0500
6633+++ ./jdk/src/share/classes/sun/tools/jar/resources/jar.properties      2009-05-04 17:37:16.000000000 -0400
6634@@ -44,6 +44,8 @@ error.create.dir=\
6635         {0} : could not create directory
6636 error.incorrect.length=\
6637         incorrect length while processing: {0}
6638+error.no.cwd=\
6639+       {0} : could not determine current working directory
6640 out.added.manifest=\
6641         added manifest
6642 out.update.manifest=\
6643diff -upr ../orig/jdk/src/share/hpi/include/hpi_impl.h ./jdk/src/share/hpi/include/hpi_impl.h
6644--- ../orig/jdk/src/share/hpi/include/hpi_impl.h        2009-01-27 15:45:43.000000000 -0500
6645+++ ./jdk/src/share/hpi/include/hpi_impl.h      2009-05-04 17:37:16.000000000 -0400
6646@@ -138,7 +138,11 @@ int sysConnect(int fd, struct sockaddr *
6647 int sysBind(int fd, struct sockaddr *him, int len);
6648 int sysAccept(int fd, struct sockaddr *him, int *len);
6649 int sysGetSockName(int fd, struct sockaddr *him, int *len);
6650-#ifdef _LP64
6651+#if defined(_LP64) || defined(_ALLBSD_SOURCE)
6652+// XXXBSD: The implementations all use ssize_t, except on Windows,
6653+// regardless of _LP64. The resulting mismatch between "int" and "ssize_t"
6654+// causes gcc on Darwin to report a conflicting types error.
6655+// Appears to be an upstream issue introduced in 1.7
6656 ssize_t sysSendTo(int fd, char *buf, int len, int flags, struct sockaddr *to,
6657               int tolen);
6658 ssize_t sysRecvFrom(int fd, char *buf, int nbytes, int flags,
6659diff -upr ../orig/jdk/src/share/lib/security/java.security-openbsd ./jdk/src/share/lib/security/java.security-openbsd
6660--- ../orig/jdk/src/share/lib/security/java.security-openbsd    2009-05-04 18:32:16.000000000 -0400
6661+++ ./jdk/src/share/lib/security/java.security-openbsd  2009-05-05 09:50:18.000000000 -0400
6662@@ -66,7 +66,14 @@ security.provider.8=sun.security.smartca
6663 # On Windows systems, the URLs file:/dev/random and file:/dev/urandom
6664 # enables use of the Microsoft CryptoAPI seed functionality.
6665 #
6666-securerandom.source=file:/dev/urandom
6667+# On OpenBSD use file:///dev/srandom for strong but blocking random
6668+# generator, file:/dev/random for hardware random generators,
6669+# file:///dev/arandom for non-blocking high-quality pseudo-random
6670+# data and file:///dev/urandom for non-blocking random data that
6671+# does not guarantee the data to be strong. See random(4) for more
6672+# info.
6673+#
6674+securerandom.source=file:///dev/arandom
6675 #
6676 # The entropy gathering device is described as a URL and can also
6677 # be specified with the system property "java.security.egd". For example,
6678diff -upr ../orig/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h ./jdk/src/share/native/com/sun/java/util/jar/pack/defines.h
6679--- ../orig/jdk/src/share/native/com/sun/java/util/jar/pack/defines.h   2009-01-27 15:45:44.000000000 -0500
6680+++ ./jdk/src/share/native/com/sun/java/util/jar/pack/defines.h 2009-05-04 17:37:16.000000000 -0400
6681@@ -32,6 +32,10 @@
6682 #include <unistd.h>
6683 #endif
6684 
6685+#ifndef NO_ZLIB
6686+#      include <zconf.h>
6687+#endif
6688+
6689 #ifndef FULL
6690 #define FULL 1 /* Adds <500 bytes to the zipped final product. */
6691 #endif
6692@@ -89,11 +93,13 @@ extern void assert_failed(const char*);
6693 // bytes and byte arrays
6694 
6695 typedef unsigned int uint;
6696+#ifdef NO_ZLIB
6697 #ifdef _LP64
6698 typedef unsigned int uLong; // Historical zlib, should be 32-bit.
6699 #else
6700 typedef unsigned long uLong;
6701 #endif
6702+#endif
6703 #ifdef _MSC_VER
6704 typedef LONGLONG        jlong;
6705 typedef DWORDLONG       julong;
6706diff -upr ../orig/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp ./jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp
6707--- ../orig/jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp    2009-01-27 15:45:44.000000000 -0500
6708+++ ./jdk/src/share/native/com/sun/java/util/jar/pack/main.cpp  2009-05-04 17:37:16.000000000 -0400
6709@@ -33,9 +33,14 @@
6710 #include <limits.h>
6711 #include <time.h>
6712 
6713+/* !PRODUCT needs intptr_t */
6714+#if defined(_ALLBSD_SOURCE) && !defined(PRODUCT)
6715+#include <stdint.h>
6716+#endif
6717+
6718 #if defined(unix) && !defined(PRODUCT)
6719 #include "pthread.h"
6720-#define THREAD_SELF ((int)pthread_self())
6721+#define THREAD_SELF ((intptr_t) pthread_self())
6722 #endif
6723 
6724 #include "defines.h"
6725@@ -58,9 +63,9 @@ int main(int argc, char **argv) {
6726 // Single-threaded, implementation, not reentrant.
6727 // Includes a weak error check against MT access.
6728 #ifndef THREAD_SELF
6729-#define THREAD_SELF (0)
6730+#define THREAD_SELF ((intptr_t) 0)
6731 #endif
6732-NOT_PRODUCT(static int uThread = -1;)
6733+NOT_PRODUCT(static intptr_t uThread = -1;)
6734 
6735 unpacker* unpacker::non_mt_current = null;
6736 unpacker* unpacker::current() {
6737@@ -69,7 +74,7 @@ unpacker* unpacker::current() {
6738 }
6739 static void set_current_unpacker(unpacker* u) {
6740   unpacker::non_mt_current = u;
6741-  assert(((uThread = (u == null) ? -1 : THREAD_SELF),
6742+  assert(((uThread = (u == null) ? ((intptr_t) -1) : THREAD_SELF),
6743           true));
6744 }
6745 
6746diff -upr ../orig/jdk/src/share/native/com/sun/media/sound/DirectAudioDevice.c ./jdk/src/share/native/com/sun/media/sound/DirectAudioDevice.c
6747--- ../orig/jdk/src/share/native/com/sun/media/sound/DirectAudioDevice.c        2009-01-27 15:45:44.000000000 -0500
6748+++ ./jdk/src/share/native/com/sun/media/sound/DirectAudioDevice.c      2009-05-04 17:37:16.000000000 -0400
6749@@ -33,7 +33,11 @@
6750 
6751 #include <jni.h>
6752 // for malloc
6753+#ifdef _ALLBSD_SOURCE
6754+#include <stdlib.h>
6755+#else
6756 #include <malloc.h>
6757+#endif
6758 #include "SoundDefs.h"
6759 #include "DirectAudio.h"
6760 #include "Utilities.h"
6761diff -upr ../orig/jdk/src/share/native/com/sun/media/sound/Platform.c ./jdk/src/share/native/com/sun/media/sound/Platform.c
6762--- ../orig/jdk/src/share/native/com/sun/media/sound/Platform.c 2009-01-27 15:45:44.000000000 -0500
6763+++ ./jdk/src/share/native/com/sun/media/sound/Platform.c       2009-05-04 17:37:16.000000000 -0400
6764@@ -99,5 +99,17 @@ JNIEXPORT jint JNICALL Java_com_sun_medi
6765         return com_sun_media_sound_Platform_LIB_ALSA;
6766     }
6767 #endif
6768+#if (X_PLATFORM == X_BSD)
6769+    switch (feature) {
6770+    case com_sun_media_sound_Platform_FEATURE_MIDIIO:
6771+       return com_sun_media_sound_Platform_LIB_MAIN;
6772+    case com_sun_media_sound_Platform_FEATURE_PORTS:
6773+       return com_sun_media_sound_Platform_LIB_MAIN;
6774+    case com_sun_media_sound_Platform_FEATURE_DIRECT_AUDIO:
6775+       // XXXBSD: When native Direct Audio support is ported change
6776+       // this back to returning com_sun_media_sound_Platform_LIB_MAIN
6777+       return 0;
6778+    }
6779+#endif
6780     return 0;
6781 }
6782diff -upr ../orig/jdk/src/share/native/com/sun/media/sound/SoundDefs.h ./jdk/src/share/native/com/sun/media/sound/SoundDefs.h
6783--- ../orig/jdk/src/share/native/com/sun/media/sound/SoundDefs.h        2009-01-27 15:45:44.000000000 -0500
6784+++ ./jdk/src/share/native/com/sun/media/sound/SoundDefs.h      2009-05-04 17:37:16.000000000 -0400
6785@@ -31,6 +31,7 @@
6786 #define X_WINDOWS       1
6787 #define X_SOLARIS       2
6788 #define X_LINUX         3
6789+#define X_BSD           4
6790 
6791 // types for X_ARCH
6792 #define X_I586          1
6793@@ -49,7 +50,7 @@
6794 
6795 
6796 // following is needed for _LP64
6797-#if ((X_PLATFORM == X_SOLARIS) || (X_PLATFORM == X_LINUX))
6798+#if ((X_PLATFORM == X_SOLARIS) || (X_PLATFORM == X_LINUX) || (X_PLATFORM == X_BSD))
6799 #include <sys/types.h>
6800 #endif
6801 
6802@@ -129,4 +130,9 @@ typedef char            SBYTE;
6803 #endif
6804 
6805 
6806+#if X_PLATFORM == X_BSD
6807+#define INLINE          inline
6808+#endif
6809+
6810+
6811 #endif  // __SOUNDDEFS_INCLUDED__
6812diff -upr ../orig/jdk/src/share/native/common/check_code.c ./jdk/src/share/native/common/check_code.c
6813--- ../orig/jdk/src/share/native/common/check_code.c    2009-01-27 15:45:44.000000000 -0500
6814+++ ./jdk/src/share/native/common/check_code.c  2009-05-04 17:37:17.000000000 -0400
6815@@ -1069,7 +1069,7 @@ verify_method(context_type *context, jcl
6816  * Make sure that branches don't go into the middle of nowhere.
6817  */
6818 
6819-static jint ntohl(jint n)
6820+static jint _ck_ntohl(jint n)
6821 {
6822     unsigned char *p = (unsigned char *)&n;
6823     return (p[0] << 24) | (p[1] << 16) | (p[2] << 8) | p[3];
6824@@ -1148,26 +1148,26 @@ verify_opcode_operands(context_type *con
6825             }
6826         }
6827         if (opcode == opc_tableswitch) {
6828-            keys = ntohl(lpc[2]) -  ntohl(lpc[1]) + 1;
6829+            keys = _ck_ntohl(lpc[2]) -  _ck_ntohl(lpc[1]) + 1;
6830             delta = 1;
6831         } else {
6832-            keys = ntohl(lpc[1]); /* number of pairs */
6833+            keys = _ck_ntohl(lpc[1]); /* number of pairs */
6834             delta = 2;
6835             /* Make sure that the tableswitch items are sorted */
6836             for (k = keys - 1, lptr = &lpc[2]; --k >= 0; lptr += 2) {
6837-                int this_key = ntohl(lptr[0]);  /* NB: ntohl may be unsigned */
6838-                int next_key = ntohl(lptr[2]);
6839+                int this_key = _ck_ntohl(lptr[0]);  /* NB: ntohl may be unsigned */
6840+                int next_key = _ck_ntohl(lptr[2]);
6841                 if (this_key >= next_key) {
6842                     CCerror(context, "Unsorted lookup switch");
6843                 }
6844             }
6845         }
6846         saved_operand = NEW(int, keys + 2);
6847-        if (!isLegalTarget(context, offset + ntohl(lpc[0])))
6848+        if (!isLegalTarget(context, offset + _ck_ntohl(lpc[0])))
6849             CCerror(context, "Illegal default target in switch");
6850-        saved_operand[keys + 1] = code_data[offset + ntohl(lpc[0])];
6851+        saved_operand[keys + 1] = code_data[offset + _ck_ntohl(lpc[0])];
6852         for (k = keys, lptr = &lpc[3]; --k >= 0; lptr += delta) {
6853-            int target = offset + ntohl(lptr[0]);
6854+            int target = offset + _ck_ntohl(lptr[0]);
6855             if (!isLegalTarget(context, target))
6856                 CCerror(context, "Illegal branch in opc_tableswitch");
6857             saved_operand[k + 1] = code_data[target];
6858@@ -1615,7 +1615,7 @@ static int instruction_length(unsigned c
6859             if (lpc + 2 >= (int *)end) {
6860                 return -1; /* do not read pass the end */
6861             }
6862-            index = ntohl(lpc[2]) - ntohl(lpc[1]);
6863+           index = _ck_ntohl(lpc[2]) - _ck_ntohl(lpc[1]);
6864             if ((index < 0) || (index > 65535)) {
6865                 return -1;      /* illegal */
6866             } else {
6867@@ -1628,7 +1628,7 @@ static int instruction_length(unsigned c
6868             int npairs;
6869             if (lpc + 1 >= (int *)end)
6870                 return -1; /* do not read pass the end */
6871-            npairs = ntohl(lpc[1]);
6872+           npairs = _ck_ntohl(lpc[1]);
6873             /* There can't be more than 64K labels because of the limit
6874              * on per-method byte code length.
6875              */
6876diff -upr ../orig/jdk/src/share/native/java/io/io_util.h ./jdk/src/share/native/java/io/io_util.h
6877--- ../orig/jdk/src/share/native/java/io/io_util.h      2009-01-27 15:45:44.000000000 -0500
6878+++ ./jdk/src/share/native/java/io/io_util.h    2009-05-04 17:37:16.000000000 -0400
6879@@ -29,7 +29,15 @@
6880 extern jfieldID IO_fd_fdID;
6881 extern jfieldID IO_handle_fdID;
6882 
6883-#if !defined(O_DSYNC) || !defined(O_SYNC)
6884+#ifdef _ALLBSD_SOURCE
6885+#include <fcntl.h>
6886+#ifndef O_SYNC
6887+#define O_SYNC  O_FSYNC
6888+#endif
6889+#ifndef O_DSYNC
6890+#define O_DSYNC O_FSYNC
6891+#endif
6892+#elif !defined(O_DSYNC) || !defined(O_SYNC)
6893 #define O_SYNC  (0x0800)
6894 #define O_DSYNC (0x2000)
6895 #endif
6896diff -upr ../orig/jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h ./jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h
6897--- ../orig/jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h      2009-01-27 15:45:44.000000000 -0500
6898+++ ./jdk/src/share/native/java/lang/fdlibm/include/fdlibm.h    2009-05-04 17:37:16.000000000 -0400
6899@@ -25,6 +25,10 @@
6900  * have any questions.
6901  */
6902 
6903+#ifdef __OpenBSD__
6904+#include <sys/types.h>
6905+#endif
6906+#include <machine/endian.h>
6907 #include "jfdlibm.h"
6908 
6909 #ifdef __NEWVALID       /* special setup for Sun test regime */
6910@@ -47,11 +51,13 @@
6911 #define __LOp(x) *(1+(int*)x)
6912 #endif
6913 
6914+#ifndef __P
6915 #ifdef __STDC__
6916 #define __P(p)  p
6917 #else
6918 #define __P(p)  ()
6919 #endif
6920+#endif
6921 
6922 /*
6923  * ANSI/POSIX
6924diff -upr ../orig/jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h ./jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h
6925--- ../orig/jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h     2009-01-27 15:45:44.000000000 -0500
6926+++ ./jdk/src/share/native/java/lang/fdlibm/include/jfdlibm.h   2009-05-04 17:37:16.000000000 -0400
6927@@ -61,7 +61,7 @@
6928 #define log1p   jlog1p
6929 #define expm1   jexpm1
6930 
6931-#ifdef __linux__
6932+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
6933 #define __ieee754_sqrt          __j__ieee754_sqrt
6934 #define __ieee754_acos          __j__ieee754_acos
6935 #define __ieee754_acosh         __j__ieee754_acosh
6936diff -upr ../orig/jdk/src/share/native/java/util/zip/Inflater.c ./jdk/src/share/native/java/util/zip/Inflater.c
6937--- ../orig/jdk/src/share/native/java/util/zip/Inflater.c       2009-01-27 15:45:44.000000000 -0500
6938+++ ./jdk/src/share/native/java/util/zip/Inflater.c     2009-05-04 17:37:16.000000000 -0400
6939@@ -67,6 +67,10 @@ Java_java_util_zip_Inflater_init(JNIEnv
6940         return jlong_zero;
6941     } else {
6942         char *msg;
6943+// BSDXXX needed for FreeBSD 5.4 and below with system zlib
6944+#if defined(__FreeBSD__) && __FreeBSD__ < 6
6945+       strm->adler = 1;
6946+#endif
6947         switch (inflateInit2(strm, nowrap ? -MAX_WBITS : MAX_WBITS)) {
6948           case Z_OK:
6949             return ptr_to_jlong(strm);
6950@@ -202,6 +206,10 @@ Java_java_util_zip_Inflater_reset(JNIEnv
6951     if (inflateReset(jlong_to_ptr(strm)) != Z_OK) {
6952         JNU_ThrowInternalError(env, 0);
6953     }
6954+// BSDXXX needed for FreeBSD 5.4 and below with system zlib
6955+#if defined(__FreeBSD__) && __FreeBSD__ < 6
6956+    ((z_stream *)jlong_to_ptr(strm))->adler = 1;
6957+#endif
6958 }
6959 
6960 JNIEXPORT void JNICALL
6961diff -upr ../orig/jdk/src/share/native/java/util/zip/zlib-1.1.3/zconf.h ./jdk/src/share/native/java/util/zip/zlib-1.1.3/zconf.h
6962--- ../orig/jdk/src/share/native/java/util/zip/zlib-1.1.3/zconf.h       2009-01-27 15:45:44.000000000 -0500
6963+++ ./jdk/src/share/native/java/util/zip/zlib-1.1.3/zconf.h     2009-05-04 17:37:16.000000000 -0400
6964@@ -42,44 +42,49 @@
6965 /* for _LP64 */
6966 #include <sys/types.h>
6967 
6968+/**
6969+ * Privatise the symbols to the JDK.
6970+ */
6971+#define Z_PREFIX
6972+
6973 /*
6974  * If you *really* need a unique prefix for all types and library functions,
6975  * compile with -DZ_PREFIX. The "standard" zlib should be compiled without it.
6976  */
6977 #ifdef Z_PREFIX
6978-#  define deflateInit_  z_deflateInit_
6979-#  define deflate       z_deflate
6980-#  define deflateEnd    z_deflateEnd
6981-#  define inflateInit_  z_inflateInit_
6982-#  define inflate       z_inflate
6983-#  define inflateEnd    z_inflateEnd
6984-#  define deflateInit2_ z_deflateInit2_
6985-#  define deflateSetDictionary z_deflateSetDictionary
6986-#  define deflateCopy   z_deflateCopy
6987-#  define deflateReset  z_deflateReset
6988-#  define deflateParams z_deflateParams
6989-#  define inflateInit2_ z_inflateInit2_
6990-#  define inflateSetDictionary z_inflateSetDictionary
6991-#  define inflateSync   z_inflateSync
6992-#  define inflateSyncPoint z_inflateSyncPoint
6993-#  define inflateReset  z_inflateReset
6994-#  define compress      z_compress
6995-#  define compress2     z_compress2
6996-#  define uncompress    z_uncompress
6997-#  define adler32       z_adler32
6998-#  define crc32         z_crc32
6999-#  define get_crc_table z_get_crc_table
7000-
7001-#  define Byte          z_Byte
7002-#  define uInt          z_uInt
7003-#  define uLong         z_uLong
7004-#  define Bytef         z_Bytef
7005-#  define charf         z_charf
7006-#  define intf          z_intf
7007-#  define uIntf         z_uIntf
7008-#  define uLongf        z_uLongf
7009-#  define voidpf        z_voidpf
7010-#  define voidp         z_voidp
7011+#  define deflateInit_  _java_z_deflateInit_
7012+#  define deflate       _java_z_deflate
7013+#  define deflateEnd    _java_z_deflateEnd
7014+#  define inflateInit_  _java_z_inflateInit_
7015+#  define inflate       _java_z_inflate
7016+#  define inflateEnd    _java_z_inflateEnd
7017+#  define deflateInit2_ _java_z_deflateInit2_
7018+#  define deflateSetDictionary _java_z_deflateSetDictionary
7019+#  define deflateCopy   _java_z_deflateCopy
7020+#  define deflateReset  _java_z_deflateReset
7021+#  define deflateParams _java_z_deflateParams
7022+#  define inflateInit2_ _java_z_inflateInit2_
7023+#  define inflateSetDictionary _java_z_inflateSetDictionary
7024+#  define inflateSync   _java_z_inflateSync
7025+#  define inflateSyncPoint _java_z_inflateSyncPoint
7026+#  define inflateReset  _java_z_inflateReset
7027+#  define compress      _java_z_compress
7028+#  define compress2     _java_z_compress2
7029+#  define uncompress    _java_z_uncompress
7030+#  define adler32       _java_z_adler32
7031+#  define crc32         _java_z_crc32
7032+#  define get_crc_table _java_z_get_crc_table
7033+
7034+#  define Byte          _java_z_Byte
7035+#  define uInt          _java_z_uInt
7036+#  define uLong         _java_z_uLong
7037+#  define Bytef         _java_z_Bytef
7038+#  define charf         _java_z_charf
7039+#  define intf          _java_z_intf
7040+#  define uIntf         _java_z_uIntf
7041+#  define uLongf        _java_z_uLongf
7042+#  define voidpf        _java_z_voidpf
7043+#  define voidp         _java_z_voidp
7044 #endif
7045 
7046 #if (defined(_WIN32) || defined(__WIN32__)) && !defined(WIN32)
7047diff -upr ../orig/jdk/src/share/native/sun/awt/debug/debug_util.h ./jdk/src/share/native/sun/awt/debug/debug_util.h
7048--- ../orig/jdk/src/share/native/sun/awt/debug/debug_util.h     2009-01-27 15:45:45.000000000 -0500
7049+++ ./jdk/src/share/native/sun/awt/debug/debug_util.h   2009-05-04 17:37:16.000000000 -0400
7050@@ -50,7 +50,9 @@ typedef void * dmutex_t;
7051 #include <stdio.h>
7052 #include <string.h>
7053 #include <assert.h>
7054+#if !defined(_ALLBSD_SOURCE)
7055 #include <malloc.h>
7056+#endif
7057 #include <limits.h>
7058 
7059 /* keep these after the other headers */
7060diff -upr ../orig/jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c ./jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c
7061--- ../orig/jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c      2009-01-27 15:45:45.000000000 -0500
7062+++ ./jdk/src/share/native/sun/awt/image/BufImgSurfaceData.c    2009-05-04 17:37:16.000000000 -0400
7063@@ -24,7 +24,11 @@
7064  */
7065 
7066 #include "BufImgSurfaceData.h"
7067+#ifdef _ALLBSD_SOURCE
7068+#include <stdlib.h>
7069+#else
7070 #include "malloc.h"
7071+#endif
7072 
7073 #include "sun_awt_image_BufImgSurfaceData.h"
7074 
7075diff -upr ../orig/jdk/src/share/native/sun/awt/image/DataBufferNative.c ./jdk/src/share/native/sun/awt/image/DataBufferNative.c
7076--- ../orig/jdk/src/share/native/sun/awt/image/DataBufferNative.c       2009-01-27 15:45:45.000000000 -0500
7077+++ ./jdk/src/share/native/sun/awt/image/DataBufferNative.c     2009-05-04 17:37:16.000000000 -0400
7078@@ -23,7 +23,11 @@
7079  * have any questions.
7080  */
7081 
7082+#ifdef _ALLBSD_SOURCE
7083+#include <stdlib.h>
7084+#else
7085 #include "malloc.h"
7086+#endif
7087 
7088 #include "SurfaceData.h"
7089 #include "sun_awt_image_DataBufferNative.h"
7090diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv2x2_f.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv2x2_f.c
7091--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv2x2_f.c 2009-01-27 15:45:45.000000000 -0500
7092+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv2x2_f.c       2009-05-04 17:37:16.000000000 -0400
7093@@ -86,7 +86,7 @@ typedef struct {
7094 #endif /* MLIB_USE_FTOI_CLAMPING */
7095 
7096 /***************************************************************/
7097-#if defined(_LITTLE_ENDIAN) && !defined(_NO_LONGLONG)
7098+#if (BYTE_ORDER == LITTLE_ENDIAN) && !defined(_NO_LONGLONG)
7099 
7100 /* NB: Explicit cast to DTYPE is necessary to avoid warning from Microsoft VC compiler.
7101       And we need to explicitly define cast behavior if source exceeds destination range.
7102@@ -103,7 +103,7 @@ typedef struct {
7103   dp[0    ] = (DTYPE) ((res0) & DTYPE_MASK);                      \
7104   dp[chan1] = (DTYPE) ((res1) & DTYPE_MASK)
7105 
7106-#endif /* defined(_LITTLE_ENDIAN) && !defined(_NO_LONGLONG) */
7107+#endif /* (BYTE_ORDER == LITTLE_ENDIAN) && !defined(_NO_LONGLONG) */
7108 
7109 /***************************************************************/
7110 #ifdef _NO_LONGLONG
7111@@ -114,17 +114,17 @@ typedef struct {
7112 
7113 #else /* _NO_LONGLONG */
7114 
7115-#ifdef _LITTLE_ENDIAN
7116+#if (BYTE_ORDER == LITTLE_ENDIAN)
7117 
7118 #define LOAD_BUFF(buff)                                         \
7119   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | ((mlib_s64)sp[0] & 0xffffffff)
7120 
7121-#else /* _LITTLE_ENDIAN */
7122+#else
7123 
7124 #define LOAD_BUFF(buff)                                         \
7125   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | ((mlib_s64)sp[chan1] & 0xffffffff)
7126 
7127-#endif /* _LITTLE_ENDIAN */
7128+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7129 
7130 #endif /* _NO_LONGLONG */
7131 
7132diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16ext.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16ext.c
7133--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16ext.c        2009-01-27 15:45:45.000000000 -0500
7134+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16ext.c      2009-05-04 17:37:16.000000000 -0400
7135@@ -126,7 +126,7 @@
7136 #define D2I(x) CLAMP_S32((x) SAT_OFF)
7137 
7138 /***************************************************************/
7139-#ifdef _LITTLE_ENDIAN
7140+#if (BYTE_ORDER == LITTLE_ENDIAN)
7141 
7142 #define STORE2(res0, res1)                                      \
7143   dp[0    ] = res1;                                             \
7144@@ -138,7 +138,7 @@
7145   dp[0    ] = res0;                                             \
7146   dp[chan1] = res1
7147 
7148-#endif /* _LITTLE_ENDIAN */
7149+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7150 
7151 /***************************************************************/
7152 #ifdef _NO_LONGLONG
7153@@ -149,17 +149,17 @@
7154 
7155 #else /* _NO_LONGLONG */
7156 
7157-#ifdef _LITTLE_ENDIAN
7158+#if (BYTE_ORDER == LITTLE_ENDIAN)
7159 
7160 #define LOAD_BUFF(buff)                                         \
7161   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | S64TOS32((mlib_s64)sp[0])
7162 
7163-#else /* _LITTLE_ENDIAN */
7164+#else
7165 
7166 #define LOAD_BUFF(buff)                                         \
7167   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | S64TOS32((mlib_s64)sp[chan1])
7168 
7169-#endif /* _LITTLE_ENDIAN */
7170+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7171 #endif /* _NO_LONGLONG */
7172 
7173 /***************************************************************/
7174diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16nw.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16nw.c
7175--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16nw.c 2009-01-27 15:45:45.000000000 -0500
7176+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_16nw.c       2009-05-04 17:37:16.000000000 -0400
7177@@ -94,7 +94,7 @@
7178 #define D2I(x) CLAMP_S32((x) SAT_OFF)
7179 
7180 /***************************************************************/
7181-#ifdef _LITTLE_ENDIAN
7182+#if (BYTE_ORDER == LITTLE_ENDIAN)
7183 
7184 #define STORE2(res0, res1)                                      \
7185   dp[0    ] = res1;                                             \
7186@@ -106,7 +106,7 @@
7187   dp[0    ] = res0;                                             \
7188   dp[chan1] = res1
7189 
7190-#endif /* _LITTLE_ENDIAN */
7191+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7192 
7193 /***************************************************************/
7194 #ifdef _NO_LONGLONG
7195@@ -117,17 +117,17 @@
7196 
7197 #else /* _NO_LONGLONG */
7198 
7199-#ifdef _LITTLE_ENDIAN
7200+#if (BYTE_ORDER == LITTLE_ENDIAN)
7201 
7202 #define LOAD_BUFF(buff)                                         \
7203   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | S64TOS32((mlib_s64)sp[0])
7204 
7205-#else /* _LITTLE_ENDIAN */
7206+#else
7207 
7208 #define LOAD_BUFF(buff)                                         \
7209   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | S64TOS32((mlib_s64)sp[chan1])
7210 
7211-#endif /* _LITTLE_ENDIAN */
7212+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7213 #endif /* _NO_LONGLONG */
7214 
7215 /***************************************************************/
7216diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_8ext.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_8ext.c
7217--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_8ext.c 2009-01-27 15:45:45.000000000 -0500
7218+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_8ext.c       2009-05-04 17:37:16.000000000 -0400
7219@@ -126,7 +126,7 @@
7220 #define D2I(x) CLAMP_S32((x) SAT_OFF)
7221 
7222 /***************************************************************/
7223-#ifdef _LITTLE_ENDIAN
7224+#if (BYTE_ORDER == LITTLE_ENDIAN)
7225 
7226 #define STORE2(res0, res1)                                      \
7227   dp[0    ] = res1;                                             \
7228@@ -138,7 +138,7 @@
7229   dp[0    ] = res0;                                             \
7230   dp[chan1] = res1
7231 
7232-#endif /* _LITTLE_ENDIAN */
7233+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7234 
7235 /***************************************************************/
7236 #ifdef _NO_LONGLONG
7237@@ -149,17 +149,17 @@
7238 
7239 #else /* _NO_LONGLONG */
7240 
7241-#ifdef _LITTLE_ENDIAN
7242+#if (BYTE_ORDER == LITTLE_ENDIAN)
7243 
7244 #define LOAD_BUFF(buff)                                         \
7245   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | S64TOS32((mlib_s64)sp[0])
7246 
7247-#else /* _LITTLE_ENDIAN */
7248+#else
7249 
7250 #define LOAD_BUFF(buff)                                         \
7251   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | S64TOS32((mlib_s64)sp[chan1])
7252 
7253-#endif /* _LITTLE_ENDIAN */
7254+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7255 #endif /* _NO_LONGLONG */
7256 
7257 /***************************************************************/
7258diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_8nw.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_8nw.c
7259--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_8nw.c  2009-01-27 15:45:45.000000000 -0500
7260+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_8nw.c        2009-05-04 17:37:16.000000000 -0400
7261@@ -95,7 +95,7 @@
7262 #define D2I(x) CLAMP_S32((x) SAT_OFF)
7263 
7264 /***************************************************************/
7265-#ifdef _LITTLE_ENDIAN
7266+#if (BYTE_ORDER == LITTLE_ENDIAN)
7267 
7268 #define STORE2(res0, res1)                                      \
7269   dp[0    ] = res1;                                             \
7270@@ -107,7 +107,7 @@
7271   dp[0    ] = res0;                                             \
7272   dp[chan1] = res1
7273 
7274-#endif /* _LITTLE_ENDIAN */
7275+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7276 
7277 /***************************************************************/
7278 #ifdef _NO_LONGLONG
7279@@ -118,17 +118,17 @@
7280 
7281 #else /* _NO_LONGLONG */
7282 
7283-#ifdef _LITTLE_ENDIAN
7284+#if (BYTE_ORDER == LITTLE_ENDIAN)
7285 
7286 #define LOAD_BUFF(buff)                                         \
7287   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | S64TOS32((mlib_s64)sp[0])
7288 
7289-#else /* _LITTLE_ENDIAN */
7290+#else
7291 
7292 #define LOAD_BUFF(buff)                                         \
7293   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | S64TOS32((mlib_s64)sp[chan1])
7294 
7295-#endif /* _LITTLE_ENDIAN */
7296+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7297 #endif /* _NO_LONGLONG */
7298 
7299 /***************************************************************/
7300diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_u16ext.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_u16ext.c
7301--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_u16ext.c       2009-01-27 15:45:45.000000000 -0500
7302+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_u16ext.c     2009-05-04 17:37:16.000000000 -0400
7303@@ -126,7 +126,7 @@
7304 #define D2I(x) CLAMP_S32((x) SAT_OFF)
7305 
7306 /***************************************************************/
7307-#ifdef _LITTLE_ENDIAN
7308+#if (BYTE_ORDER == LITTLE_ENDIAN)
7309 
7310 #define STORE2(res0, res1)                                      \
7311   dp[0    ] = res1;                                             \
7312@@ -138,7 +138,7 @@
7313   dp[0    ] = res0;                                             \
7314   dp[chan1] = res1
7315 
7316-#endif /* _LITTLE_ENDIAN */
7317+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7318 
7319 /***************************************************************/
7320 #ifdef _NO_LONGLONG
7321@@ -149,17 +149,17 @@
7322 
7323 #else /* _NO_LONGLONG */
7324 
7325-#ifdef _LITTLE_ENDIAN
7326+#if (BYTE_ORDER == LITTLE_ENDIAN)
7327 
7328 #define LOAD_BUFF(buff)                                         \
7329   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | S64TOS32((mlib_s64)sp[0])
7330 
7331-#else /* _LITTLE_ENDIAN */
7332+#else
7333 
7334 #define LOAD_BUFF(buff)                                         \
7335   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | S64TOS32((mlib_s64)sp[chan1])
7336 
7337-#endif /* _LITTLE_ENDIAN */
7338+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7339 #endif /* _NO_LONGLONG */
7340 
7341 /***************************************************************/
7342diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_u16nw.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_u16nw.c
7343--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_u16nw.c        2009-01-27 15:45:45.000000000 -0500
7344+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageConv_u16nw.c      2009-05-04 17:37:16.000000000 -0400
7345@@ -94,7 +94,7 @@
7346 #define D2I(x) CLAMP_S32((x) SAT_OFF)
7347 
7348 /***************************************************************/
7349-#ifdef _LITTLE_ENDIAN
7350+#if (BYTE_ORDER == LITTLE_ENDIAN)
7351 
7352 #define STORE2(res0, res1)                                      \
7353   dp[0    ] = res1;                                             \
7354@@ -106,7 +106,7 @@
7355   dp[0    ] = res0;                                             \
7356   dp[chan1] = res1
7357 
7358-#endif /* _LITTLE_ENDIAN */
7359+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7360 
7361 /***************************************************************/
7362 #ifdef _NO_LONGLONG
7363@@ -117,17 +117,17 @@
7364 
7365 #else /* _NO_LONGLONG */
7366 
7367-#ifdef _LITTLE_ENDIAN
7368+#if (BYTE_ORDER == LITTLE_ENDIAN)
7369 
7370 #define LOAD_BUFF(buff)                                         \
7371   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[chan1]) << 32) | S64TOS32((mlib_s64)sp[0])
7372 
7373-#else /* _LITTLE_ENDIAN */
7374+#else
7375 
7376 #define LOAD_BUFF(buff)                                         \
7377   *(mlib_s64*)(buff + i) = (((mlib_s64)sp[0]) << 32) | S64TOS32((mlib_s64)sp[chan1])
7378 
7379-#endif /* _LITTLE_ENDIAN */
7380+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7381 #endif /* _NO_LONGLONG */
7382 
7383 /***************************************************************/
7384diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageCopy_Bit.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageCopy_Bit.c
7385--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageCopy_Bit.c  2009-01-27 15:45:45.000000000 -0500
7386+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageCopy_Bit.c        2009-05-04 17:37:16.000000000 -0400
7387@@ -95,7 +95,7 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7388     dst = dp[0];
7389     if (ld_offset + size < 32) {
7390       dmask = (mask0 << (32 - size)) >> ld_offset;
7391-#ifdef _LITTLE_ENDIAN
7392+#if (BYTE_ORDER == LITTLE_ENDIAN)
7393       src0 = (src0 << 24) | ((src0 & 0xFF00) << 8) | ((src0 >> 8) & 0xFF00) | (src0 >> 24);
7394       src = (src0 >> (ld_offset - ls_offset));
7395       dst = (dst << 24) | ((dst & 0xFF00) << 8) | ((dst >> 8) & 0xFF00) | (dst >> 24);
7396@@ -104,12 +104,12 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7397 #else
7398       src = (src0 >> (ld_offset - ls_offset));
7399       dp[0] = (dst & (~dmask)) | (src & dmask);
7400-#endif /* _LITTLE_ENDIAN */
7401+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7402       return;
7403     }
7404 
7405     dmask = mask0 >> ld_offset;
7406-#ifdef _LITTLE_ENDIAN
7407+#if (BYTE_ORDER == LITTLE_ENDIAN)
7408     src0 = (src0 << 24) | ((src0 & 0xFF00) << 8) | ((src0 >> 8) & 0xFF00) | (src0 >> 24);
7409     src = (src0 >> (ld_offset - ls_offset));
7410     dst = (dst << 24) | ((dst & 0xFF00) << 8) | ((dst >> 8) & 0xFF00) | (dst >> 24);
7411@@ -118,7 +118,7 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7412 #else
7413     src = (src0 >> (ld_offset - ls_offset));
7414     dp[0] = (dst & ~dmask) | (src & dmask);
7415-#endif /* _LITTLE_ENDIAN */
7416+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7417     j = 32 - ld_offset;
7418     dp++;
7419     ls_offset += j;
7420@@ -131,7 +131,7 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7421 
7422     if (ld_offset + size < 32) {
7423       dmask = (mask0 << (32 - size)) >> ld_offset;
7424-#ifdef _LITTLE_ENDIAN
7425+#if (BYTE_ORDER == LITTLE_ENDIAN)
7426       src0 = (src0 << 24) | ((src0 & 0xFF00) << 8) | ((src0 >> 8) & 0xFF00) | (src0 >> 24);
7427       src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7428       src = (src0 << shift) | (src1 >> (32 - shift));
7429@@ -141,12 +141,12 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7430 #else
7431       src = (src0 << shift) | (src1 >> (32 - shift));
7432       dp[0] = (dst & ~dmask) | (src & dmask);
7433-#endif /* _LITTLE_ENDIAN */
7434+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7435       return;
7436     }
7437 
7438     dmask = mask0 >> ld_offset;
7439-#ifdef _LITTLE_ENDIAN
7440+#if (BYTE_ORDER == LITTLE_ENDIAN)
7441     src0 = (src0 << 24) | ((src0 & 0xFF00) << 8) | ((src0 >> 8) & 0xFF00) | (src0 >> 24);
7442     src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7443     src = (src0 << shift) | (src1 >> (32 - shift));
7444@@ -156,7 +156,7 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7445 #else
7446     src = (src0 << shift) | (src1 >> (32 - shift));
7447     dp[0] = (dst & ~dmask) | (src & dmask);
7448-#endif /* _LITTLE_ENDIAN */
7449+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7450     j = 32 - ld_offset;
7451     dp++;
7452     sp++;
7453@@ -164,19 +164,19 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7454   }
7455 
7456   if (j < size) src1 = sp[0];
7457-#ifdef _LITTLE_ENDIAN
7458+#if (BYTE_ORDER == LITTLE_ENDIAN)
7459   src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7460-#endif /* _LITTLE_ENDIAN */
7461+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7462   for (; j <= size - 32; j += 32) {
7463     src0 = src1;
7464     src1 = sp[1];
7465-#ifdef _LITTLE_ENDIAN
7466+#if (BYTE_ORDER == LITTLE_ENDIAN)
7467     src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7468     src = (src0 << ls_offset) | (src1 >> (32 - ls_offset));
7469     dp[0] = (src << 24) | ((src & 0xFF00) << 8) | ((src >> 8) & 0xFF00) | (src >> 24);
7470 #else
7471     dp[0] = (src0 << ls_offset) | (src1 >> (32 - ls_offset));
7472-#endif /* _LITTLE_ENDIAN */
7473+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7474     sp++;
7475     dp++;
7476   }
7477@@ -187,7 +187,7 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7478     if (ls_offset + j > 32) src1 = sp[1];
7479     dst = dp[0];
7480     dmask = mask0 << (32 - j);
7481-#ifdef _LITTLE_ENDIAN
7482+#if (BYTE_ORDER == LITTLE_ENDIAN)
7483     src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7484     src = (src0 << ls_offset) | (src1 >> (32 - ls_offset));
7485     dst = (dst << 24) | ((dst & 0xFF00) << 8) | ((dst >> 8) & 0xFF00) | (dst >> 24);
7486@@ -196,7 +196,7 @@ void mlib_ImageCopy_bit_na(const mlib_u8
7487 #else
7488     src = (src0 << ls_offset) | (src1 >> (32 - ls_offset));
7489     dp[0] = (dst & ~dmask) | (src & dmask);
7490-#endif /* _LITTLE_ENDIAN */
7491+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7492   }
7493 
7494 #else /* _LONGLONG */
7495@@ -315,7 +315,7 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7496     dst = dp[0];
7497     if (ld_offset >= size) {
7498       dmask = (lmask0 << (32 - size)) >> (ld_offset - size);
7499-#ifdef _LITTLE_ENDIAN
7500+#if (BYTE_ORDER == LITTLE_ENDIAN)
7501       src0 = (src0 << 24) | ((src0 & 0xFF00) << 8) | ((src0 >> 8) & 0xFF00) | (src0 >> 24);
7502       src = (src0 << (ls_offset - ld_offset));
7503       dst = (dst << 24) | ((dst & 0xFF00) << 8) | ((dst >> 8) & 0xFF00) | (dst >> 24);
7504@@ -324,12 +324,12 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7505 #else
7506       src = (src0 << (ls_offset - ld_offset));
7507       dp[0] = (dst & (~dmask)) | (src & dmask);
7508-#endif /* _LITTLE_ENDIAN */
7509+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7510       return;
7511     }
7512 
7513     dmask = lmask0 << (32 - ld_offset);
7514-#ifdef _LITTLE_ENDIAN
7515+#if (BYTE_ORDER == LITTLE_ENDIAN)
7516     src0 = (src0 << 24) | ((src0 & 0xFF00) << 8) | ((src0 >> 8) & 0xFF00) | (src0 >> 24);
7517     src = (src0 << (ls_offset - ld_offset));
7518     dst = (dst << 24) | ((dst & 0xFF00) << 8) | ((dst >> 8) & 0xFF00) | (dst >> 24);
7519@@ -338,7 +338,7 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7520 #else
7521     src = (src0 << (ls_offset - ld_offset));
7522     dp[0] = (dst & ~dmask) | (src & dmask);
7523-#endif /* _LITTLE_ENDIAN */
7524+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7525     j = ld_offset;
7526     dp--;
7527     ls_offset -= j;
7528@@ -351,7 +351,7 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7529 
7530     if (ld_offset >= size) {
7531       dmask = (lmask0 << (32 - size)) >> (ld_offset - size);
7532-#ifdef _LITTLE_ENDIAN
7533+#if (BYTE_ORDER == LITTLE_ENDIAN)
7534       src0 = (src0 << 24) | ((src0 & 0xFF00) << 8) | ((src0 >> 8) & 0xFF00) | (src0 >> 24);
7535       src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7536       src = (src0 >> shift) | (src1 << (32 - shift));
7537@@ -361,12 +361,12 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7538 #else
7539       src = (src0 >> shift) | (src1 << (32 - shift));
7540       dp[0] = (dst & ~dmask) | (src & dmask);
7541-#endif /* _LITTLE_ENDIAN */
7542+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7543       return;
7544     }
7545 
7546     dmask = lmask0 << (32 - ld_offset);
7547-#ifdef _LITTLE_ENDIAN
7548+#if (BYTE_ORDER == LITTLE_ENDIAN)
7549     src0 = (src0 << 24) | ((src0 & 0xFF00) << 8) | ((src0 >> 8) & 0xFF00) | (src0 >> 24);
7550     src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7551     src = (src0 >> shift) | (src1 << (32 - shift));
7552@@ -376,7 +376,7 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7553 #else
7554     src = (src0 >> shift) | (src1 << (32 - shift));
7555     dp[0] = (dst & ~dmask) | (src & dmask);
7556-#endif /* _LITTLE_ENDIAN */
7557+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7558     j = ld_offset;
7559     dp--;
7560     sp--;
7561@@ -384,22 +384,22 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7562   }
7563 
7564   if (j < size) src1 = sp[0];
7565-#ifdef _LITTLE_ENDIAN
7566+#if (BYTE_ORDER == LITTLE_ENDIAN)
7567   src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7568-#endif /* _LITTLE_ENDIAN */
7569+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7570 #ifdef __SUNPRO_C
7571 #pragma pipeloop(0)
7572 #endif /* __SUNPRO_C */
7573   for (; j <= size - 32; j += 32) {
7574     src0 = src1;
7575     src1 = sp[-1];
7576-#ifdef _LITTLE_ENDIAN
7577+#if (BYTE_ORDER == LITTLE_ENDIAN)
7578     src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7579     src = (src0 >> (32 - ls_offset)) | (src1 << ls_offset);
7580     dp[0] = (src << 24) | ((src & 0xFF00) << 8) | ((src >> 8) & 0xFF00) | (src >> 24);
7581 #else
7582     dp[0] = (src0 >> (32 - ls_offset)) | (src1 << ls_offset);
7583-#endif /* _LITTLE_ENDIAN */
7584+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7585     sp--;
7586     dp--;
7587   }
7588@@ -410,7 +410,7 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7589     if (ls_offset < j) src1 = sp[-1];
7590     dst = dp[0];
7591     dmask = lmask0 >> (32 - j);
7592-#ifdef _LITTLE_ENDIAN
7593+#if (BYTE_ORDER == LITTLE_ENDIAN)
7594     src1 = (src1 << 24) | ((src1 & 0xFF00) << 8) | ((src1 >> 8) & 0xFF00) | (src1 >> 24);
7595     src = (src0 >> (32 - ls_offset)) | (src1 << ls_offset);
7596     dst = (dst << 24) | ((dst & 0xFF00) << 8) | ((dst >> 8) & 0xFF00) | (dst >> 24);
7597@@ -419,7 +419,7 @@ void mlib_ImageCopy_bit_na_r(const mlib_
7598 #else
7599     src = (src0 >> (32 - ls_offset)) | (src1 << ls_offset);
7600     dp[0] = (dst & ~dmask) | (src & dmask);
7601-#endif /* _LITTLE_ENDIAN */
7602+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7603   }
7604 
7605 #else  /* _LONGLONG */
7606diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageLookUp_64.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageLookUp_64.c
7607--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageLookUp_64.c 2009-01-27 15:45:46.000000000 -0500
7608+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageLookUp_64.c       2009-05-04 17:37:16.000000000 -0400
7609@@ -168,7 +168,7 @@
7610 }
7611 
7612 /***************************************************************/
7613-#ifdef _LITTLE_ENDIAN
7614+#if (BYTE_ORDER == LITTLE_ENDIAN)
7615 
7616 #define READ_U8_D64(table0, table1, table2, table3)             \
7617   t0 = *(mlib_d64*)((mlib_u8*)table0 + ((s0 << 3) & 0x7F8));    \
7618@@ -184,7 +184,7 @@
7619   t2 = *(mlib_d64*)((mlib_u8*)table2 + ((s0 >> 5)  & 0x7F8));   \
7620   t3 = *(mlib_d64*)((mlib_u8*)table3 + ((s0 << 3)  & 0x7F8))
7621 
7622-#endif /* _LITTLE_ENDIAN */
7623+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7624 
7625 /***************************************************************/
7626 void mlib_ImageLookUp_U8_D64(const mlib_u8  *src,
7627@@ -612,7 +612,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7628 #pragma pipeloop(0)
7629 #endif /* __SUNPRO_C */
7630       for (i = 0; i < size - 7; i += 4, dp += 8, sa++) {
7631-#ifdef _LITTLE_ENDIAN
7632+#if (BYTE_ORDER == LITTLE_ENDIAN)
7633         t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7634         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7635         t2 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 5) & 0x7F8));
7636@@ -622,12 +622,12 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7637         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 21) & 0x7F8));
7638         t2 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7639         t3 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7640-#endif /* _LITTLE_ENDIAN */
7641+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7642         dp[0] = t0;
7643         dp[1] = t1;
7644         dp[2] = t2;
7645         dp[3] = t3;
7646-#ifdef _LITTLE_ENDIAN
7647+#if (BYTE_ORDER == LITTLE_ENDIAN)
7648         t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7649         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7650         t2 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 21) & 0x7F8));
7651@@ -637,7 +637,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7652         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 5) & 0x7F8));
7653         t2 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7654         t3 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7655-#endif /* _LITTLE_ENDIAN */
7656+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7657         s0 = sa[0];
7658         dp[4] = t0;
7659         dp[5] = t1;
7660@@ -645,7 +645,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7661         dp[7] = t3;
7662       }
7663 
7664-#ifdef _LITTLE_ENDIAN
7665+#if (BYTE_ORDER == LITTLE_ENDIAN)
7666       t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7667       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7668       t2 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 5) & 0x7F8));
7669@@ -655,12 +655,12 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7670       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 21) & 0x7F8));
7671       t2 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7672       t3 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7673-#endif /* _LITTLE_ENDIAN */
7674+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7675       dp[0] = t0;
7676       dp[1] = t1;
7677       dp[2] = t2;
7678       dp[3] = t3;
7679-#ifdef _LITTLE_ENDIAN
7680+#if (BYTE_ORDER == LITTLE_ENDIAN)
7681       t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7682       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7683       t2 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 21) & 0x7F8));
7684@@ -670,7 +670,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7685       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 5) & 0x7F8));
7686       t2 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7687       t3 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7688-#endif /* _LITTLE_ENDIAN */
7689+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7690       dp[4] = t0;
7691       dp[5] = t1;
7692       dp[6] = t2;
7693@@ -718,7 +718,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7694 #pragma pipeloop(0)
7695 #endif /* __SUNPRO_C */
7696       for (i = 0; i < size - 7; i += 4, dp += 12, sa++) {
7697-#ifdef _LITTLE_ENDIAN
7698+#if (BYTE_ORDER == LITTLE_ENDIAN)
7699         t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7700         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7701         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 << 3) & 0x7F8));
7702@@ -732,14 +732,14 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7703         t3 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7704         t4 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7705         t5 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 13) & 0x7F8));
7706-#endif /* _LITTLE_ENDIAN */
7707+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7708         dp[0] = t0;
7709         dp[1] = t1;
7710         dp[2] = t2;
7711         dp[3] = t3;
7712         dp[4] = t4;
7713         dp[5] = t5;
7714-#ifdef _LITTLE_ENDIAN
7715+#if (BYTE_ORDER == LITTLE_ENDIAN)
7716         t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7717         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7718         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 13) & 0x7F8));
7719@@ -753,7 +753,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7720         t3 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7721         t4 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7722         t5 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 << 3) & 0x7F8));
7723-#endif /* _LITTLE_ENDIAN */
7724+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7725         s0 = sa[0];
7726         dp[6] = t0;
7727         dp[7] = t1;
7728@@ -763,7 +763,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7729         dp[11] = t5;
7730       }
7731 
7732-#ifdef _LITTLE_ENDIAN
7733+#if (BYTE_ORDER == LITTLE_ENDIAN)
7734       t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7735       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7736       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 << 3) & 0x7F8));
7737@@ -777,14 +777,14 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7738       t3 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7739       t4 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7740       t5 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 13) & 0x7F8));
7741-#endif /* _LITTLE_ENDIAN */
7742+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7743       dp[0] = t0;
7744       dp[1] = t1;
7745       dp[2] = t2;
7746       dp[3] = t3;
7747       dp[4] = t4;
7748       dp[5] = t5;
7749-#ifdef _LITTLE_ENDIAN
7750+#if (BYTE_ORDER == LITTLE_ENDIAN)
7751       t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7752       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7753       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 13) & 0x7F8));
7754@@ -798,7 +798,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7755       t3 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7756       t4 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7757       t5 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 << 3) & 0x7F8));
7758-#endif /* _LITTLE_ENDIAN */
7759+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7760       dp[6] = t0;
7761       dp[7] = t1;
7762       dp[8] = t2;
7763@@ -851,7 +851,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7764 #pragma pipeloop(0)
7765 #endif /* __SUNPRO_C */
7766       for (i = 0; i < size - 7; i += 4, dp += 16, sa++) {
7767-#ifdef _LITTLE_ENDIAN
7768+#if (BYTE_ORDER == LITTLE_ENDIAN)
7769         t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7770         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7771         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 << 3) & 0x7F8));
7772@@ -861,12 +861,12 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7773         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 21) & 0x7F8));
7774         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 21) & 0x7F8));
7775         t3 = *(mlib_d64 *) ((mlib_u8 *) tab3 + ((s0 >> 21) & 0x7F8));
7776-#endif /* _LITTLE_ENDIAN */
7777+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7778         dp[0] = t0;
7779         dp[1] = t1;
7780         dp[2] = t2;
7781         dp[3] = t3;
7782-#ifdef _LITTLE_ENDIAN
7783+#if (BYTE_ORDER == LITTLE_ENDIAN)
7784         t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 5) & 0x7F8));
7785         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 5) & 0x7F8));
7786         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 5) & 0x7F8));
7787@@ -876,12 +876,12 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7788         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7789         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 13) & 0x7F8));
7790         t3 = *(mlib_d64 *) ((mlib_u8 *) tab3 + ((s0 >> 13) & 0x7F8));
7791-#endif /* _LITTLE_ENDIAN */
7792+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7793         dp[4] = t0;
7794         dp[5] = t1;
7795         dp[6] = t2;
7796         dp[7] = t3;
7797-#ifdef _LITTLE_ENDIAN
7798+#if (BYTE_ORDER == LITTLE_ENDIAN)
7799         t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7800         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7801         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 13) & 0x7F8));
7802@@ -891,12 +891,12 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7803         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 5) & 0x7F8));
7804         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 5) & 0x7F8));
7805         t3 = *(mlib_d64 *) ((mlib_u8 *) tab3 + ((s0 >> 5) & 0x7F8));
7806-#endif /* _LITTLE_ENDIAN */
7807+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7808         dp[8] = t0;
7809         dp[9] = t1;
7810         dp[10] = t2;
7811         dp[11] = t3;
7812-#ifdef _LITTLE_ENDIAN
7813+#if (BYTE_ORDER == LITTLE_ENDIAN)
7814         t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 21) & 0x7F8));
7815         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 21) & 0x7F8));
7816         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 21) & 0x7F8));
7817@@ -906,7 +906,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7818         t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7819         t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 << 3) & 0x7F8));
7820         t3 = *(mlib_d64 *) ((mlib_u8 *) tab3 + ((s0 << 3) & 0x7F8));
7821-#endif /* _LITTLE_ENDIAN */
7822+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7823         s0 = sa[0];
7824         dp[12] = t0;
7825         dp[13] = t1;
7826@@ -914,7 +914,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7827         dp[15] = t3;
7828       }
7829 
7830-#ifdef _LITTLE_ENDIAN
7831+#if (BYTE_ORDER == LITTLE_ENDIAN)
7832       t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 << 3) & 0x7F8));
7833       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7834       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 << 3) & 0x7F8));
7835@@ -924,12 +924,12 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7836       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 21) & 0x7F8));
7837       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 21) & 0x7F8));
7838       t3 = *(mlib_d64 *) ((mlib_u8 *) tab3 + ((s0 >> 21) & 0x7F8));
7839-#endif /* _LITTLE_ENDIAN */
7840+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7841       dp[0] = t0;
7842       dp[1] = t1;
7843       dp[2] = t2;
7844       dp[3] = t3;
7845-#ifdef _LITTLE_ENDIAN
7846+#if (BYTE_ORDER == LITTLE_ENDIAN)
7847       t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 5) & 0x7F8));
7848       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 5) & 0x7F8));
7849       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 5) & 0x7F8));
7850@@ -939,12 +939,12 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7851       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7852       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 13) & 0x7F8));
7853       t3 = *(mlib_d64 *) ((mlib_u8 *) tab3 + ((s0 >> 13) & 0x7F8));
7854-#endif /* _LITTLE_ENDIAN */
7855+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7856       dp[4] = t0;
7857       dp[5] = t1;
7858       dp[6] = t2;
7859       dp[7] = t3;
7860-#ifdef _LITTLE_ENDIAN
7861+#if (BYTE_ORDER == LITTLE_ENDIAN)
7862       t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 13) & 0x7F8));
7863       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 13) & 0x7F8));
7864       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 13) & 0x7F8));
7865@@ -954,12 +954,12 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7866       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 5) & 0x7F8));
7867       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 5) & 0x7F8));
7868       t3 = *(mlib_d64 *) ((mlib_u8 *) tab3 + ((s0 >> 5) & 0x7F8));
7869-#endif /* _LITTLE_ENDIAN */
7870+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7871       dp[8] = t0;
7872       dp[9] = t1;
7873       dp[10] = t2;
7874       dp[11] = t3;
7875-#ifdef _LITTLE_ENDIAN
7876+#if (BYTE_ORDER == LITTLE_ENDIAN)
7877       t0 = *(mlib_d64 *) ((mlib_u8 *) tab0 + ((s0 >> 21) & 0x7F8));
7878       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 >> 21) & 0x7F8));
7879       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 >> 21) & 0x7F8));
7880@@ -969,7 +969,7 @@ void mlib_ImageLookUpSI_U8_D64(const mli
7881       t1 = *(mlib_d64 *) ((mlib_u8 *) tab1 + ((s0 << 3) & 0x7F8));
7882       t2 = *(mlib_d64 *) ((mlib_u8 *) tab2 + ((s0 << 3) & 0x7F8));
7883       t3 = *(mlib_d64 *) ((mlib_u8 *) tab3 + ((s0 << 3) & 0x7F8));
7884-#endif /* _LITTLE_ENDIAN */
7885+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7886       dp[12] = t0;
7887       dp[13] = t1;
7888       dp[14] = t2;
7889diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageLookUp_Bit.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageLookUp_Bit.c
7890--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageLookUp_Bit.c        2009-01-27 15:45:46.000000000 -0500
7891+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageLookUp_Bit.c      2009-05-04 17:37:16.000000000 -0400
7892@@ -88,7 +88,7 @@ typedef union {
7893 } d64_2_f32;
7894 
7895 /***************************************************************/
7896-#ifdef _LITTLE_ENDIAN
7897+#if (BYTE_ORDER == LITTLE_ENDIAN)
7898 
7899 static const mlib_u32 mlib_bit_mask[16] = {
7900   0x00000000u, 0xFF000000u, 0x00FF0000u, 0xFFFF0000u,
7901@@ -126,7 +126,7 @@ static const mlib_u32 mlib_bit_mask_3[3*
7902   0x00000000u, 0x00FFFFFFu, 0xFF000000u, 0xFFFFFFFFu
7903 };
7904 
7905-#endif /* _LITTLE_ENDIAN */
7906+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7907 
7908 /***************************************************************/
7909 mlib_status mlib_ImageLookUp_Bit_U8_1(const mlib_u8 *src,
7910@@ -228,13 +228,13 @@ mlib_status mlib_ImageLookUp_Bit_U8_1(co
7911 #endif /* __SUNPRO_C */
7912     for (; i <= (size - 16); i += 16) {
7913       s0 = *(mlib_u16*)sa;
7914-#ifdef _LITTLE_ENDIAN
7915+#if (BYTE_ORDER == LITTLE_ENDIAN)
7916       *da++ = dd_array[s0 & 0xFF];
7917       *da++ = dd_array[s0 >> 8];
7918 #else
7919       *da++ = dd_array[s0 >> 8];
7920       *da++ = dd_array[s0 & 0xFF];
7921-#endif /* _LITTLE_ENDIAN */
7922+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7923       sa += 2;
7924     }
7925 
7926@@ -258,20 +258,20 @@ mlib_status mlib_ImageLookUp_Bit_U8_1(co
7927         val1 = p_dd[2*val0+1];
7928       }
7929 
7930-#ifdef _LITTLE_ENDIAN
7931+#if (BYTE_ORDER == LITTLE_ENDIAN)
7932       emask = (mlib_u32)((mlib_s32)(-1)) >> ((4 - (size - i)) * 8);
7933 #else
7934       emask = (mlib_s32)(-1) << ((4 - (size - i)) * 8);
7935-#endif /* _LITTLE_ENDIAN */
7936+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7937       ((mlib_u32*)da)[0] = (val1 & emask) | (((mlib_u32*)da)[0] &~ emask);
7938 
7939 #else /* _NO_LONGLONG */
7940 
7941-#ifdef _LITTLE_ENDIAN
7942+#if (BYTE_ORDER == LITTLE_ENDIAN)
7943       mlib_u64 emask = (mlib_u64)((mlib_s64)(-1)) >> ((8 - (size - i)) * 8);
7944 #else
7945       mlib_u64 emask = (mlib_s64)(-1) << ((8 - (size - i)) * 8);
7946-#endif /* _LITTLE_ENDIAN */
7947+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7948 
7949       ((mlib_u64*)da)[0] = (((mlib_u64*)dd_array)[sa[0]] & emask) | (((mlib_u64*)da)[0] &~ emask);
7950 
7951@@ -323,13 +323,13 @@ mlib_status mlib_ImageLookUp_Bit_U8_2(co
7952 
7953   val0 = table[0][0];
7954   val1 = table[0][1];
7955-#ifdef _LITTLE_ENDIAN
7956+#if (BYTE_ORDER == LITTLE_ENDIAN)
7957   val0 = val0 | (table[1][0] << 8);
7958   val1 = val1 | (table[1][1] << 8);
7959 #else
7960   val0 = (val0 << 8) | table[1][0];
7961   val1 = (val1 << 8) | table[1][1];
7962-#endif /* _LITTLE_ENDIAN */
7963+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7964   val0 |= (val0 << 16);
7965   val1 |= (val1 << 16);
7966 
7967@@ -394,11 +394,11 @@ mlib_status mlib_ImageLookUp_Bit_U8_2(co
7968         dd1 = dd2;
7969       }
7970 
7971-#ifdef _LITTLE_ENDIAN
7972+#if (BYTE_ORDER == LITTLE_ENDIAN)
7973       emask = (mlib_u32)((mlib_s32)(-1)) >> ((4 - (size - i)) * 8);
7974 #else
7975       emask = (mlib_s32)(-1) << ((4 - (size - i)) * 8);
7976-#endif /* _LITTLE_ENDIAN */
7977+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7978       ((mlib_u32*)da)[0] = (dd1 & emask) | (((mlib_u32*)da)[0] &~ emask);
7979 
7980 #else /* _NO_LONGLONG */
7981@@ -412,11 +412,11 @@ mlib_status mlib_ImageLookUp_Bit_U8_2(co
7982         dd = ((mlib_u64*)dd_array)[s0 & 0xf];
7983       }
7984 
7985-#ifdef _LITTLE_ENDIAN
7986+#if (BYTE_ORDER == LITTLE_ENDIAN)
7987       emask = (mlib_u64)((mlib_s64)(-1)) >> ((8 - (size - i)) * 8);
7988 #else
7989       emask = (mlib_s64)(-1) << ((8 - (size - i)) * 8);
7990-#endif /* _LITTLE_ENDIAN */
7991+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
7992       ((mlib_u64*)da)[0] = (dd & emask) | (((mlib_u64*)da)[0] &~ emask);
7993 
7994 #endif /* _NO_LONGLONG */
7995@@ -462,7 +462,7 @@ mlib_status mlib_ImageLookUp_Bit_U8_3(co
7996 
7997   buffs = buff + size;
7998 
7999-#ifdef _LITTLE_ENDIAN
8000+#if (BYTE_ORDER == LITTLE_ENDIAN)
8001   l0 = (table[0][0] << 24) | (table[2][0] << 16) | (table[1][0] << 8) | (table[0][0]);
8002   h0 = (table[0][1] << 24) | (table[2][1] << 16) | (table[1][1] << 8) | (table[0][1]);
8003   l1 = (l0 >> 8); l1 |= (l1 << 24);
8004@@ -476,7 +476,7 @@ mlib_status mlib_ImageLookUp_Bit_U8_3(co
8005   h1 = (h0 << 8); h1 |= (h1 >> 24);
8006   l2 = (l1 << 8); l2 |= (l2 >> 24);
8007   h2 = (h1 << 8); h2 |= (h2 >> 24);
8008-#endif /* _LITTLE_ENDIAN */
8009+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8010 
8011   /* calculate lookup table */
8012 #ifdef __SUNPRO_C
8013@@ -564,11 +564,11 @@ mlib_status mlib_ImageLookUp_Bit_U8_3(co
8014         dd = ((mlib_u32*)(d_array12 + (s0 & 0xF)))[1];
8015       }
8016 
8017-#ifdef _LITTLE_ENDIAN
8018+#if (BYTE_ORDER == LITTLE_ENDIAN)
8019       emask = (mlib_u32)((mlib_s32)(-1)) >> ((4 - (size - i)) * 8);
8020 #else
8021       emask = (mlib_s32)(-1) << ((4 - (size - i)) * 8);
8022-#endif /* _LITTLE_ENDIAN */
8023+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8024       da[0] = (dd & emask) | (da[0] &~ emask);
8025     }
8026 
8027@@ -611,13 +611,13 @@ mlib_status mlib_ImageLookUp_Bit_U8_4(co
8028 
8029   buffs = buff + size;
8030 
8031-#ifdef _LITTLE_ENDIAN
8032+#if (BYTE_ORDER == LITTLE_ENDIAN)
8033   l = (table[3][0] << 24) | (table[2][0] << 16) | (table[1][0] << 8) | (table[0][0]);
8034   h = (table[3][1] << 24) | (table[2][1] << 16) | (table[1][1] << 8) | (table[0][1]);
8035 #else
8036   l = (table[0][0] << 24) | (table[1][0] << 16) | (table[2][0] << 8) | (table[3][0]);
8037   h = (table[0][1] << 24) | (table[1][1] << 16) | (table[2][1] << 8) | (table[3][1]);
8038-#endif /* _LITTLE_ENDIAN */
8039+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8040 
8041   ((mlib_u32*)lh)[0] = l;  ((mlib_u32*)lh)[1] = l;
8042   ((mlib_u32*)lh)[2] = l;  ((mlib_u32*)lh)[3] = h;
8043diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageUtils.c ./jdk/src/share/native/sun/awt/medialib/mlib_ImageUtils.c
8044--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_ImageUtils.c     2009-01-27 15:45:46.000000000 -0500
8045+++ ./jdk/src/share/native/sun/awt/medialib/mlib_ImageUtils.c   2009-05-04 17:37:16.000000000 -0400
8046@@ -30,7 +30,7 @@
8047 typedef union {
8048   mlib_d64 db;
8049   struct {
8050-#ifdef _LITTLE_ENDIAN
8051+#if (BYTE_ORDER == LITTLE_ENDIAN)
8052     mlib_s32 int1, int0;
8053 #else
8054     mlib_s32 int0, int1;
8055diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_c_ImageCopy.c ./jdk/src/share/native/sun/awt/medialib/mlib_c_ImageCopy.c
8056--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_c_ImageCopy.c    2009-01-27 15:45:46.000000000 -0500
8057+++ ./jdk/src/share/native/sun/awt/medialib/mlib_c_ImageCopy.c  2009-05-04 17:37:16.000000000 -0400
8058@@ -275,11 +275,11 @@ void mlib_ImageCopy_bit_al(const mlib_u8
8059       for (i = 0; j <= (b_size - 4); j += 4, i++) {
8060         src0 = src1;
8061         src1 = pws[i + 1];
8062-#ifdef _LITTLE_ENDIAN
8063+#if (BYTE_ORDER == LITTLE_ENDIAN)
8064         pwd[i] = (src0 >> lshift) | (src1 << rshift);
8065 #else
8066         pwd[i] = (src0 << lshift) | (src1 >> rshift);
8067-#endif /* _LITTLE_ENDIAN */
8068+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8069       }
8070 
8071       sa += i << 2;
8072@@ -381,11 +381,11 @@ void mlib_c_ImageCopy_u8(const mlib_imag
8073         for (; j <= (src_width - 4); j += 4) {
8074           src0 = src1;
8075           src1 = ps[1];
8076-#ifdef _LITTLE_ENDIAN
8077+#if (BYTE_ORDER == LITTLE_ENDIAN)
8078           *((mlib_s32 *) (pdst_row + j)) = (src0 >> shl) | (src1 << shr);
8079 #else
8080           *((mlib_s32 *) (pdst_row + j)) = (src0 << shl) | (src1 >> shr);
8081-#endif /* _LITTLE_ENDIAN */
8082+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8083           ps++;
8084         }
8085       }
8086@@ -414,11 +414,11 @@ void mlib_c_ImageCopy_u8(const mlib_imag
8087         for (; j <= (src_width - 8); j += 8) {
8088           src0 = src1;
8089           src1 = ps[1];
8090-#ifdef _LITTLE_ENDIAN
8091+#if (BYTE_ORDER == LITTLE_ENDIAN)
8092           *((mlib_s64 *) (pdst_row + j)) = (src0 >> shl) | (src1 << shr);
8093 #else
8094           *((mlib_s64 *) (pdst_row + j)) = (src0 << shl) | (src1 >> shr);
8095-#endif /* _LITTLE_ENDIAN */
8096+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8097           ps++;
8098         }
8099       }
8100@@ -484,11 +484,11 @@ void mlib_c_ImageCopy_s16(const mlib_ima
8101         for (; j <= (src_width - 2); j += 2) {
8102           src0 = src1;
8103           src1 = ps[1];
8104-#ifdef _LITTLE_ENDIAN
8105+#if (BYTE_ORDER == LITTLE_ENDIAN)
8106           *((mlib_s32 *) (pdst_row + j)) = (src0 >> 16) | (src1 << 16);
8107 #else
8108           *((mlib_s32 *) (pdst_row + j)) = (src0 << 16) | (src1 >> 16);
8109-#endif /* _LITTLE_ENDIAN */
8110+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8111           ps++;
8112         }
8113       }
8114@@ -516,11 +516,11 @@ void mlib_c_ImageCopy_s16(const mlib_ima
8115         for (; j <= (src_width - 4); j += 4) {
8116           src0 = src1;
8117           src1 = ps[1];
8118-#ifdef _LITTLE_ENDIAN
8119+#if (BYTE_ORDER == LITTLE_ENDIAN)
8120           *((mlib_s64 *) (pdst_row + j)) = (src0 >> shl) | (src1 << shr);
8121 #else
8122           *((mlib_s64 *) (pdst_row + j)) = (src0 << shl) | (src1 >> shr);
8123-#endif /* _LITTLE_ENDIAN */
8124+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8125           ps++;
8126         }
8127       }
8128@@ -585,11 +585,11 @@ void mlib_c_ImageCopy_s32(const mlib_ima
8129         for (; j <= (src_width - 2); j += 2) {
8130           src0 = src1;
8131           src1 = ps[1];
8132-#ifdef _LITTLE_ENDIAN
8133+#if (BYTE_ORDER == LITTLE_ENDIAN)
8134           *((mlib_s64 *) (pdst_row + j)) = (src0 >> 32) | (src1 << 32);
8135 #else
8136           *((mlib_s64 *) (pdst_row + j)) = (src0 << 32) | (src1 >> 32);
8137-#endif /* _LITTLE_ENDIAN */
8138+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8139           ps++;
8140         }
8141       }
8142@@ -687,11 +687,11 @@ void mlib_ImageCopy_na(const mlib_u8 *sp
8143 #endif /* __SUNPRO_C */
8144       for (; n > SIZE; n -= SIZE) {
8145         s1 = *tmp++;
8146-#ifdef _LITTLE_ENDIAN
8147+#if (BYTE_ORDER == LITTLE_ENDIAN)
8148         *(TYPE *) dp = (s0 >> shl) | (s1 << shr);
8149 #else
8150         *(TYPE *) dp = (s0 << shl) | (s1 >> shr);
8151-#endif /* _LITTLE_ENDIAN */
8152+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8153         s0 = s1;
8154         dp += SIZE;
8155         sp += SIZE;
8156diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_c_ImageLookUp_f.c ./jdk/src/share/native/sun/awt/medialib/mlib_c_ImageLookUp_f.c
8157--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_c_ImageLookUp_f.c        2009-01-27 15:45:46.000000000 -0500
8158+++ ./jdk/src/share/native/sun/awt/medialib/mlib_c_ImageLookUp_f.c      2009-05-04 17:37:16.000000000 -0400
8159@@ -120,7 +120,7 @@
8160   }                                                               \
8161 }
8162 
8163-#ifdef _LITTLE_ENDIAN
8164+#if (BYTE_ORDER == LITTLE_ENDIAN)
8165 
8166 /***************************************************************/
8167 #define READ_U8_U8_ALIGN(table0, table1, table2, table3)        \
8168@@ -163,7 +163,7 @@
8169   t2 = *(mlib_u32*)((mlib_u8*)table2 + ((s0 >> 14)  & 0x3FC));  \
8170   t3 = *(mlib_u32*)((mlib_u8*)table3 + ((s0 >> 22)  & 0x3FC))
8171 
8172-#else /* _LITTLE_ENDIAN */
8173+#else /* BYTE_ORDER == ... */
8174 
8175 /***********/
8176 #define READ_U8_U8_ALIGN(table0, table1, table2, table3)        \
8177@@ -206,7 +206,7 @@
8178   t2 = *(mlib_u32*)((mlib_u8*)table2 + ((s0 >> 6)  & 0x3FC));   \
8179   t3 = *(mlib_u32*)((mlib_u8*)table3 + ((s0 << 2)  & 0x3FC))
8180 
8181-#endif /* _LITTLE_ENDIAN */
8182+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8183 
8184 /***************************************************************/
8185 void mlib_c_ImageLookUp_U8_U8(const mlib_u8 *src,
8186@@ -297,11 +297,11 @@ void mlib_c_ImageLookUp_U8_U8(const mlib
8187         da[0] = t;
8188         da++;
8189         dp = (mlib_u8 *) da;
8190-#ifdef _LITTLE_ENDIAN
8191+#if (BYTE_ORDER == LITTLE_ENDIAN)
8192         *dp++ = tab[s2 >> 8];
8193 #else
8194         *dp++ = tab[s2 & 0xFF];
8195-#endif /* _LITTLE_ENDIAN */
8196+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8197         sp = (mlib_u8 *) sa;
8198         i += 5;
8199         for (; i < size; i++, dp++, sp++)
8200@@ -403,11 +403,11 @@ void mlib_c_ImageLookUp_U8_U8(const mlib
8201         da[0] = t;
8202         da++;
8203         dp = (mlib_u8 *) da;
8204-#ifdef _LITTLE_ENDIAN
8205+#if (BYTE_ORDER == LITTLE_ENDIAN)
8206         *dp++ = tab0[s2 >> 8];
8207 #else
8208         *dp++ = tab0[s2 & 0xFF];
8209-#endif /* _LITTLE_ENDIAN */
8210+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8211         sp = (mlib_u8 *) sa;
8212         i += 5;
8213 
8214@@ -544,11 +544,11 @@ void mlib_c_ImageLookUp_U8_U8(const mlib
8215         da[0] = t;
8216         da++;
8217         dp = (mlib_u8 *) da;
8218-#ifdef _LITTLE_ENDIAN
8219+#if (BYTE_ORDER == LITTLE_ENDIAN)
8220         *dp++ = tab1[s2 >> 8];
8221 #else
8222         *dp++ = tab1[s2 & 0xFF];
8223-#endif /* _LITTLE_ENDIAN */
8224+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8225         sp = (mlib_u8 *) sa;
8226         i += 5;
8227 
8228@@ -694,11 +694,11 @@ void mlib_c_ImageLookUp_U8_U8(const mlib
8229         da[0] = t;
8230         da++;
8231         dp = (mlib_u8 *) da;
8232-#ifdef _LITTLE_ENDIAN
8233+#if (BYTE_ORDER == LITTLE_ENDIAN)
8234         *dp++ = tab0[s2 >> 8];
8235 #else
8236         *dp++ = tab0[s2 & 0xFF];
8237-#endif /* _LITTLE_ENDIAN */
8238+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8239         sp = (mlib_u8 *) sa;
8240         i += 5;
8241 
8242@@ -1852,21 +1852,21 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8243     s0 = tab0[0];
8244     s1 = tab1[0];
8245     for (i = 1; i < 256; i++) {
8246-#ifdef _LITTLE_ENDIAN
8247+#if (BYTE_ORDER == LITTLE_ENDIAN)
8248       s2 = (s1 << 8) + s0;
8249 #else
8250       s2 = (s0 << 8) + s1;
8251-#endif /* _LITTLE_ENDIAN */
8252+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8253       s0 = tab0[i];
8254       s1 = tab1[i];
8255       tab[i - 1] = (mlib_u16) s2;
8256     }
8257 
8258-#ifdef _LITTLE_ENDIAN
8259+#if (BYTE_ORDER == LITTLE_ENDIAN)
8260     s2 = (s1 << 8) + s0;
8261 #else
8262     s2 = (s0 << 8) + s1;
8263-#endif /* _LITTLE_ENDIAN */
8264+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8265     tab[255] = (mlib_u16) s2;
8266 
8267     for (j = 0; j < ysize; j++, dst += dlb, src += slb) {
8268@@ -1897,11 +1897,11 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8269         for (i = 0; i < size - 3; i += 2, da++, sa += 2) {
8270           t0 = tab[s0];
8271           t1 = tab[s1];
8272-#ifdef _LITTLE_ENDIAN
8273+#if (BYTE_ORDER == LITTLE_ENDIAN)
8274           t = (t1 << 16) + t0;
8275 #else
8276           t = (t0 << 16) + t1;
8277-#endif /* _LITTLE_ENDIAN */
8278+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8279           s0 = sa[0];
8280           s1 = sa[1];
8281           da[0] = t;
8282@@ -1909,11 +1909,11 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8283 
8284         t0 = tab[s0];
8285         t1 = tab[s1];
8286-#ifdef _LITTLE_ENDIAN
8287+#if (BYTE_ORDER == LITTLE_ENDIAN)
8288         t = (t1 << 16) + t0;
8289 #else
8290         t = (t0 << 16) + t1;
8291-#endif /* _LITTLE_ENDIAN */
8292+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8293         da[0] = t;
8294         da++;
8295 
8296@@ -1927,13 +1927,13 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8297 
8298         if (off > 1) {
8299           t0 = tab[sa[0]];
8300-#ifdef _LITTLE_ENDIAN
8301+#if (BYTE_ORDER == LITTLE_ENDIAN)
8302           dp[1] = (t0 >> 8);
8303           dp[0] = t0;
8304 #else
8305           dp[0] = (t0 >> 8);
8306           dp[1] = t0;
8307-#endif /* _LITTLE_ENDIAN */
8308+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8309           sa++;
8310           size--;
8311           dp += 2;
8312@@ -1941,11 +1941,11 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8313 
8314         t0 = tab[sa[0]];
8315         sa++;
8316-#ifdef _LITTLE_ENDIAN
8317+#if (BYTE_ORDER == LITTLE_ENDIAN)
8318         *dp++ = t0;
8319 #else
8320         *dp++ = (t0 >> 8);
8321-#endif /* _LITTLE_ENDIAN */
8322+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8323 
8324         da = (mlib_s32 *) dp;
8325 
8326@@ -1959,11 +1959,11 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8327         for (i = 0; i < size - 4; i += 2, da++, sa += 2) {
8328           t1 = tab[s0];
8329           t2 = tab[s1];
8330-#ifdef _LITTLE_ENDIAN
8331+#if (BYTE_ORDER == LITTLE_ENDIAN)
8332           t = (t0 >> 8) + (t1 << 8) + (t2 << 24);
8333 #else
8334           t = (t0 << 24) + (t1 << 8) + (t2 >> 8);
8335-#endif /* _LITTLE_ENDIAN */
8336+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8337           t0 = t2;
8338           s0 = sa[0];
8339           s1 = sa[1];
8340@@ -1972,29 +1972,29 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8341 
8342         t1 = tab[s0];
8343         t2 = tab[s1];
8344-#ifdef _LITTLE_ENDIAN
8345+#if (BYTE_ORDER == LITTLE_ENDIAN)
8346         t = (t0 >> 8) + (t1 << 8) + (t2 << 24);
8347 #else
8348         t = (t0 << 24) + (t1 << 8) + (t2 >> 8);
8349-#endif /* _LITTLE_ENDIAN */
8350+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8351         da[0] = t;
8352         da++;
8353         dp = (mlib_u8 *) da;
8354-#ifdef _LITTLE_ENDIAN
8355+#if (BYTE_ORDER == LITTLE_ENDIAN)
8356         dp[0] = (t2 >> 8);
8357 #else
8358         dp[0] = t2;
8359-#endif /* _LITTLE_ENDIAN */
8360+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8361 
8362         if ((size & 1) == 0) {
8363           t0 = tab[sa[0]];
8364-#ifdef _LITTLE_ENDIAN
8365+#if (BYTE_ORDER == LITTLE_ENDIAN)
8366           dp[2] = (t0 >> 8);
8367           dp[1] = t0;
8368 #else
8369           dp[1] = (t0 >> 8);
8370           dp[2] = t0;
8371-#endif /* _LITTLE_ENDIAN */
8372+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8373         }
8374       }
8375     }
8376@@ -2012,22 +2012,22 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8377     s1 = tab1[0];
8378     s2 = tab2[0];
8379     for (i = 1; i < 256; i++) {
8380-#ifdef _LITTLE_ENDIAN
8381+#if (BYTE_ORDER == LITTLE_ENDIAN)
8382       s3 = (s2 << 24) + (s1 << 16) + (s0 << 8);
8383 #else
8384       s3 = (s0 << 16) + (s1 << 8) + s2;
8385-#endif /* _LITTLE_ENDIAN */
8386+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8387       s0 = tab0[i];
8388       s1 = tab1[i];
8389       s2 = tab2[i];
8390       tab[i - 1] = s3;
8391     }
8392 
8393-#ifdef _LITTLE_ENDIAN
8394+#if (BYTE_ORDER == LITTLE_ENDIAN)
8395     s3 = (s2 << 24) + (s1 << 16) + (s0 << 8);
8396 #else
8397     s3 = (s0 << 16) + (s1 << 8) + s2;
8398-#endif /* _LITTLE_ENDIAN */
8399+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8400     tab[255] = s3;
8401 
8402     for (j = 0; j < ysize; j++, dst += dlb, src += slb) {
8403@@ -2064,24 +2064,24 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8404       for (i = 0; i < size - 7; i += 4, da += 3, sa += 4) {
8405         t0 = tab[s0];
8406         t1 = tab[s1];
8407-#ifdef _LITTLE_ENDIAN
8408+#if (BYTE_ORDER == LITTLE_ENDIAN)
8409         da[0] = (t0 >> 8) + (t1 << 16);
8410         res2 = (t1 >> 16);
8411 #else
8412         da[0] = (t0 << 8) + (t1 >> 16);
8413         res2 = (t1 << 16);
8414-#endif /* _LITTLE_ENDIAN */
8415+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8416         s0 = sa[0];
8417         s1 = sa[1];
8418         t0 = tab[s0];
8419         t1 = tab[s1];
8420-#ifdef _LITTLE_ENDIAN
8421+#if (BYTE_ORDER == LITTLE_ENDIAN)
8422         res2 += (t0 << 8);
8423         res1 = (t0 >> 24) + t1;
8424 #else
8425         res2 += (t0 >> 8);
8426         res1 = (t0 << 24) + t1;
8427-#endif /* _LITTLE_ENDIAN */
8428+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8429         s0 = sa[2];
8430         s1 = sa[3];
8431         da[1] = res2;
8432@@ -2090,24 +2090,24 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8433 
8434       t0 = tab[s0];
8435       t1 = tab[s1];
8436-#ifdef _LITTLE_ENDIAN
8437+#if (BYTE_ORDER == LITTLE_ENDIAN)
8438       da[0] = (t0 >> 8) + (t1 << 16);
8439       res2 = (t1 >> 16);
8440 #else
8441       da[0] = (t0 << 8) + (t1 >> 16);
8442       res2 = (t1 << 16);
8443-#endif /* _LITTLE_ENDIAN */
8444+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8445       s0 = sa[0];
8446       s1 = sa[1];
8447       t0 = tab[s0];
8448       t1 = tab[s1];
8449-#ifdef _LITTLE_ENDIAN
8450+#if (BYTE_ORDER == LITTLE_ENDIAN)
8451       res2 += (t0 << 8);
8452       res1 = (t0 >> 24) + t1;
8453 #else
8454       res2 += (t0 >> 8);
8455       res1 = (t0 << 24) + t1;
8456-#endif /* _LITTLE_ENDIAN */
8457+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8458       da[1] = res2;
8459       da[2] = res1;
8460       da += 3;
8461@@ -2143,11 +2143,11 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8462     s2 = tab2[0];
8463     s3 = tab3[0];
8464     for (i = 1; i < 256; i++) {
8465-#ifdef _LITTLE_ENDIAN
8466+#if (BYTE_ORDER == LITTLE_ENDIAN)
8467       s4 = (s3 << 24) + (s2 << 16) + (s1 << 8) + s0;
8468 #else
8469       s4 = (s0 << 24) + (s1 << 16) + (s2 << 8) + s3;
8470-#endif /* _LITTLE_ENDIAN */
8471+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8472       s0 = tab0[i];
8473       s1 = tab1[i];
8474       s2 = tab2[i];
8475@@ -2155,11 +2155,11 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8476       tab[i - 1] = s4;
8477     }
8478 
8479-#ifdef _LITTLE_ENDIAN
8480+#if (BYTE_ORDER == LITTLE_ENDIAN)
8481     s4 = (s3 << 24) + (s2 << 16) + (s1 << 8) + s0;
8482 #else
8483     s4 = (s0 << 24) + (s1 << 16) + (s2 << 8) + s3;
8484-#endif /* _LITTLE_ENDIAN */
8485+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8486     tab[255] = s4;
8487 
8488     for (j = 0; j < ysize; j++, dst += dlb, src += slb) {
8489@@ -2225,13 +2225,13 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8490         for (i = 0; i < size - 4; i += 2, da += 2, sa += 2) {
8491           t1 = tab[s0];
8492           t2 = tab[s1];
8493-#ifdef _LITTLE_ENDIAN
8494+#if (BYTE_ORDER == LITTLE_ENDIAN)
8495           res1 = (t0 >> shift) + (t1 << shift1);
8496           res2 = (t1 >> shift) + (t2 << shift1);
8497 #else
8498           res1 = (t0 << shift) + (t1 >> shift1);
8499           res2 = (t1 << shift) + (t2 >> shift1);
8500-#endif /* _LITTLE_ENDIAN */
8501+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8502           t0 = t2;
8503           s0 = sa[0];
8504           s1 = sa[1];
8505@@ -2241,28 +2241,28 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8506 
8507         t1 = tab[s0];
8508         t2 = tab[s1];
8509-#ifdef _LITTLE_ENDIAN
8510+#if (BYTE_ORDER == LITTLE_ENDIAN)
8511         res1 = (t0 >> shift) + (t1 << shift1);
8512         res2 = (t1 >> shift) + (t2 << shift1);
8513 #else
8514         res1 = (t0 << shift) + (t1 >> shift1);
8515         res2 = (t1 << shift) + (t2 >> shift1);
8516-#endif /* _LITTLE_ENDIAN */
8517+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8518         da[0] = res1;
8519         da[1] = res2;
8520-#ifdef _LITTLE_ENDIAN
8521+#if (BYTE_ORDER == LITTLE_ENDIAN)
8522         t0 = (da[2] >> shift1);
8523         da[2] = (t2 >> shift) + (t0 << shift1);
8524 #else
8525         t0 = (da[2] << shift1);
8526         da[2] = (t2 << shift) + (t0 >> shift1);
8527-#endif /* _LITTLE_ENDIAN */
8528+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8529         da += 2;
8530         dp = (mlib_u8 *) da + (4 - off);
8531 
8532         if ((size & 1) == 0) {
8533           t0 = tab[sa[0]];
8534-#ifdef _LITTLE_ENDIAN
8535+#if (BYTE_ORDER == LITTLE_ENDIAN)
8536           dp[3] = (mlib_u8) (t0 >> 24);
8537           dp[2] = (mlib_u8) (t0 >> 16);
8538           dp[1] = (mlib_u8) (t0 >> 8);
8539@@ -2272,7 +2272,7 @@ void mlib_c_ImageLookUpSI_U8_U8(const ml
8540           dp[1] = (mlib_u8) (t0 >> 16);
8541           dp[2] = (mlib_u8) (t0 >> 8);
8542           dp[3] = (mlib_u8) t0;
8543-#endif /* _LITTLE_ENDIAN */
8544+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8545         }
8546       }
8547     }
8548@@ -2348,13 +2348,13 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8549         t3 = tab0[s1];
8550         t4 = tab1[s1];
8551         t5 = tab2[s1];
8552-#ifdef _LITTLE_ENDIAN
8553+#if (BYTE_ORDER == LITTLE_ENDIAN)
8554         da[0] = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8555         res2 = (t5 << 8) + t4;
8556 #else
8557         da[0] = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8558         res2 = (t4 << 24) + (t5 << 16);
8559-#endif /* _LITTLE_ENDIAN */
8560+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8561         s0 = sa[0];
8562         s1 = sa[1];
8563         t0 = tab0[s0];
8564@@ -2363,13 +2363,13 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8565         t3 = tab0[s1];
8566         t4 = tab1[s1];
8567         t5 = tab2[s1];
8568-#ifdef _LITTLE_ENDIAN
8569+#if (BYTE_ORDER == LITTLE_ENDIAN)
8570         res2 += ((t1 << 24) + (t0 << 16));
8571         res1 = (t5 << 24) + (t4 << 16) + (t3 << 8) + t2;
8572 #else
8573         res2 += ((t0 << 8) + t1);
8574         res1 = (t2 << 24) + (t3 << 16) + (t4 << 8) + t5;
8575-#endif /* _LITTLE_ENDIAN */
8576+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8577         s0 = sa[2];
8578         s1 = sa[3];
8579         da[1] = res2;
8580@@ -2382,13 +2382,13 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8581       t3 = tab0[s1];
8582       t4 = tab1[s1];
8583       t5 = tab2[s1];
8584-#ifdef _LITTLE_ENDIAN
8585+#if (BYTE_ORDER == LITTLE_ENDIAN)
8586       da[0] = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8587       res2 = (t5 << 8) + t4;
8588 #else
8589       da[0] = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8590       res2 = (t4 << 24) + (t5 << 16);
8591-#endif /* _LITTLE_ENDIAN */
8592+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8593       s0 = sa[0];
8594       s1 = sa[1];
8595       t0 = tab0[s0];
8596@@ -2397,13 +2397,13 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8597       t3 = tab0[s1];
8598       t4 = tab1[s1];
8599       t5 = tab2[s1];
8600-#ifdef _LITTLE_ENDIAN
8601+#if (BYTE_ORDER == LITTLE_ENDIAN)
8602       res2 += ((t1 << 24) + (t0 << 16));
8603       res1 = (t5 << 24) + (t4 << 16) + (t3 << 8) + t2;
8604 #else
8605       res2 += ((t0 << 8) + t1);
8606       res1 = (t2 << 24) + (t3 << 16) + (t4 << 8) + t5;
8607-#endif /* _LITTLE_ENDIAN */
8608+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8609       da[1] = res2;
8610       da[2] = res1;
8611       da += 3;
8612@@ -2455,11 +2455,11 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8613           t1 = tab1[s0];
8614           t2 = tab2[s0];
8615           t3 = tab3[s0];
8616-#ifdef _LITTLE_ENDIAN
8617+#if (BYTE_ORDER == LITTLE_ENDIAN)
8618           res = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8619 #else
8620           res = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8621-#endif /* _LITTLE_ENDIAN */
8622+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8623           s0 = sa[0];
8624           da[0] = res;
8625         }
8626@@ -2468,11 +2468,11 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8627         t1 = tab1[s0];
8628         t2 = tab2[s0];
8629         t3 = tab3[s0];
8630-#ifdef _LITTLE_ENDIAN
8631+#if (BYTE_ORDER == LITTLE_ENDIAN)
8632         res = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8633 #else
8634         res = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8635-#endif /* _LITTLE_ENDIAN */
8636+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8637         da[0] = res;
8638 
8639       }
8640@@ -2496,11 +2496,11 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8641         t2 = tab2[s0];
8642         t3 = tab3[s0];
8643 
8644-#ifdef _LITTLE_ENDIAN
8645+#if (BYTE_ORDER == LITTLE_ENDIAN)
8646         res1 = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8647 #else
8648         res1 = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8649-#endif /* _LITTLE_ENDIAN */
8650+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8651 
8652         s0 = sa[0];
8653         sa++;
8654@@ -2513,13 +2513,13 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8655           t1 = tab1[s0];
8656           t2 = tab2[s0];
8657           t3 = tab3[s0];
8658-#ifdef _LITTLE_ENDIAN
8659+#if (BYTE_ORDER == LITTLE_ENDIAN)
8660           res2 = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8661           res = (res1 >> shift) + (res2 << shift1);
8662 #else
8663           res2 = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8664           res = (res1 << shift) + (res2 >> shift1);
8665-#endif /* _LITTLE_ENDIAN */
8666+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8667           res1 = res2;
8668           s0 = sa[0];
8669           da[0] = res;
8670@@ -2529,21 +2529,21 @@ void mlib_c_ImageLookUpSI_S16_U8(const m
8671         t1 = tab1[s0];
8672         t2 = tab2[s0];
8673         t3 = tab3[s0];
8674-#ifdef _LITTLE_ENDIAN
8675+#if (BYTE_ORDER == LITTLE_ENDIAN)
8676         res2 = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8677         res = (res1 >> shift) + (res2 << shift1);
8678 #else
8679         res2 = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8680         res = (res1 << shift) + (res2 >> shift1);
8681-#endif /* _LITTLE_ENDIAN */
8682+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8683         da[0] = res;
8684-#ifdef _LITTLE_ENDIAN
8685+#if (BYTE_ORDER == LITTLE_ENDIAN)
8686         res1 = (da[1] >> shift1);
8687         da[1] = (res2 >> shift) + (res1 << shift1);
8688 #else
8689         res1 = (da[1] << shift1);
8690         da[1] = (res2 << shift) + (res1 >> shift1);
8691-#endif /* _LITTLE_ENDIAN */
8692+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8693       }
8694     }
8695   }
8696@@ -2617,13 +2617,13 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8697         t3 = tab0[s1];
8698         t4 = tab1[s1];
8699         t5 = tab2[s1];
8700-#ifdef _LITTLE_ENDIAN
8701+#if (BYTE_ORDER == LITTLE_ENDIAN)
8702         da[0] = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8703         res2 = (t5 << 8) + t4;
8704 #else
8705         da[0] = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8706         res2 = (t4 << 24) + (t5 << 16);
8707-#endif /* _LITTLE_ENDIAN */
8708+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8709         s0 = sa[0];
8710         s1 = sa[1];
8711         t0 = tab0[s0];
8712@@ -2632,13 +2632,13 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8713         t3 = tab0[s1];
8714         t4 = tab1[s1];
8715         t5 = tab2[s1];
8716-#ifdef _LITTLE_ENDIAN
8717+#if (BYTE_ORDER == LITTLE_ENDIAN)
8718         res2 += ((t1 << 24) + (t0 << 16));
8719         res1 = (t5 << 24) + (t4 << 16) + (t3 << 8) + t2;
8720 #else
8721         res2 += ((t0 << 8) + t1);
8722         res1 = (t2 << 24) + (t3 << 16) + (t4 << 8) + t5;
8723-#endif /* _LITTLE_ENDIAN */
8724+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8725         s0 = sa[2];
8726         s1 = sa[3];
8727         da[1] = res2;
8728@@ -2651,13 +2651,13 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8729       t3 = tab0[s1];
8730       t4 = tab1[s1];
8731       t5 = tab2[s1];
8732-#ifdef _LITTLE_ENDIAN
8733+#if (BYTE_ORDER == LITTLE_ENDIAN)
8734       da[0] = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8735       res2 = (t5 << 8) + t4;
8736 #else
8737       da[0] = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8738       res2 = (t4 << 24) + (t5 << 16);
8739-#endif /* _LITTLE_ENDIAN */
8740+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8741       s0 = sa[0];
8742       s1 = sa[1];
8743       t0 = tab0[s0];
8744@@ -2666,13 +2666,13 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8745       t3 = tab0[s1];
8746       t4 = tab1[s1];
8747       t5 = tab2[s1];
8748-#ifdef _LITTLE_ENDIAN
8749+#if (BYTE_ORDER == LITTLE_ENDIAN)
8750       res2 += ((t1 << 24) + (t0 << 16));
8751       res1 = (t5 << 24) + (t4 << 16) + (t3 << 8) + t2;
8752 #else
8753       res2 += ((t0 << 8) + t1);
8754       res1 = (t2 << 24) + (t3 << 16) + (t4 << 8) + t5;
8755-#endif /* _LITTLE_ENDIAN */
8756+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8757       da[1] = res2;
8758       da[2] = res1;
8759       da += 3;
8760@@ -2724,11 +2724,11 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8761           t1 = tab1[s0];
8762           t2 = tab2[s0];
8763           t3 = tab3[s0];
8764-#ifdef _LITTLE_ENDIAN
8765+#if (BYTE_ORDER == LITTLE_ENDIAN)
8766           res = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8767 #else
8768           res = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8769-#endif /* _LITTLE_ENDIAN */
8770+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8771           s0 = sa[0];
8772           da[0] = res;
8773         }
8774@@ -2737,11 +2737,11 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8775         t1 = tab1[s0];
8776         t2 = tab2[s0];
8777         t3 = tab3[s0];
8778-#ifdef _LITTLE_ENDIAN
8779+#if (BYTE_ORDER == LITTLE_ENDIAN)
8780         res = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8781 #else
8782         res = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8783-#endif /* _LITTLE_ENDIAN */
8784+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8785         da[0] = res;
8786 
8787       }
8788@@ -2765,11 +2765,11 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8789         t2 = tab2[s0];
8790         t3 = tab3[s0];
8791 
8792-#ifdef _LITTLE_ENDIAN
8793+#if (BYTE_ORDER == LITTLE_ENDIAN)
8794         res1 = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8795 #else
8796         res1 = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8797-#endif /* _LITTLE_ENDIAN */
8798+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8799 
8800         s0 = sa[0];
8801         sa++;
8802@@ -2782,13 +2782,13 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8803           t1 = tab1[s0];
8804           t2 = tab2[s0];
8805           t3 = tab3[s0];
8806-#ifdef _LITTLE_ENDIAN
8807+#if (BYTE_ORDER == LITTLE_ENDIAN)
8808           res2 = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8809           res = (res1 >> shift) + (res2 << shift1);
8810 #else
8811           res2 = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8812           res = (res1 << shift) + (res2 >> shift1);
8813-#endif /* _LITTLE_ENDIAN */
8814+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8815           res1 = res2;
8816           s0 = sa[0];
8817           da[0] = res;
8818@@ -2798,21 +2798,21 @@ void mlib_c_ImageLookUpSI_U16_U8(const m
8819         t1 = tab1[s0];
8820         t2 = tab2[s0];
8821         t3 = tab3[s0];
8822-#ifdef _LITTLE_ENDIAN
8823+#if (BYTE_ORDER == LITTLE_ENDIAN)
8824         res2 = (t3 << 24) + (t2 << 16) + (t1 << 8) + t0;
8825         res = (res1 >> shift) + (res2 << shift1);
8826 #else
8827         res2 = (t0 << 24) + (t1 << 16) + (t2 << 8) + t3;
8828         res = (res1 << shift) + (res2 >> shift1);
8829-#endif /* _LITTLE_ENDIAN */
8830+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8831         da[0] = res;
8832-#ifdef _LITTLE_ENDIAN
8833+#if (BYTE_ORDER == LITTLE_ENDIAN)
8834         res1 = (da[1] >> shift1);
8835         da[1] = (res2 >> shift) + (res1 << shift1);
8836 #else
8837         res1 = (da[1] << shift1);
8838         da[1] = (res2 << shift) + (res1 >> shift1);
8839-#endif /* _LITTLE_ENDIAN */
8840+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8841       }
8842     }
8843   }
8844@@ -2863,21 +2863,21 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
8845     s0 = tab0[0];
8846     s1 = tab1[0];
8847     for (i = 1; i < 256; i++) {
8848-#ifdef _LITTLE_ENDIAN
8849+#if (BYTE_ORDER == LITTLE_ENDIAN)
8850       s2 = (s1 << 16) + s0;
8851 #else
8852       s2 = (s0 << 16) + s1;
8853-#endif /* _LITTLE_ENDIAN */
8854+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8855       s0 = tab0[i];
8856       s1 = tab1[i];
8857       tab[i - 1] = s2;
8858     }
8859 
8860-#ifdef _LITTLE_ENDIAN
8861+#if (BYTE_ORDER == LITTLE_ENDIAN)
8862     s2 = (s1 << 16) + s0;
8863 #else
8864     s2 = (s0 << 16) + s1;
8865-#endif /* _LITTLE_ENDIAN */
8866+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8867     tab[255] = s2;
8868 
8869     for (j = 0; j < ysize; j++, dst += dlb, src += slb) {
8870@@ -2919,11 +2919,11 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
8871       else {
8872 
8873         t0 = tab[*sa++];
8874-#ifdef _LITTLE_ENDIAN
8875+#if (BYTE_ORDER == LITTLE_ENDIAN)
8876         *dp++ = (mlib_u16) (t0);
8877 #else
8878         *dp++ = (mlib_u16) (t0 >> 16);
8879-#endif /* _LITTLE_ENDIAN */
8880+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8881         da = (mlib_u32 *) dp;
8882         s0 = sa[0];
8883         s1 = sa[1];
8884@@ -2935,13 +2935,13 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
8885         for (i = 0; i < size - 4; i += 2, da += 2, sa += 2) {
8886           t1 = tab[s0];
8887           t2 = tab[s1];
8888-#ifdef _LITTLE_ENDIAN
8889+#if (BYTE_ORDER == LITTLE_ENDIAN)
8890           res1 = (t0 >> 16) + (t1 << 16);
8891           res2 = (t1 >> 16) + (t2 << 16);
8892 #else
8893           res1 = (t0 << 16) + (t1 >> 16);
8894           res2 = (t1 << 16) + (t2 >> 16);
8895-#endif /* _LITTLE_ENDIAN */
8896+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8897           t0 = t2;
8898           s0 = sa[0];
8899           s1 = sa[1];
8900@@ -2951,32 +2951,32 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
8901 
8902         t1 = tab[s0];
8903         t2 = tab[s1];
8904-#ifdef _LITTLE_ENDIAN
8905+#if (BYTE_ORDER == LITTLE_ENDIAN)
8906         res1 = (t0 >> 16) + (t1 << 16);
8907         res2 = (t1 >> 16) + (t2 << 16);
8908 #else
8909         res1 = (t0 << 16) + (t1 >> 16);
8910         res2 = (t1 << 16) + (t2 >> 16);
8911-#endif /* _LITTLE_ENDIAN */
8912+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8913         da[0] = res1;
8914         da[1] = res2;
8915         da += 2;
8916         dp = (mlib_u16 *) da;
8917-#ifdef _LITTLE_ENDIAN
8918+#if (BYTE_ORDER == LITTLE_ENDIAN)
8919         dp[0] = (mlib_u16) (t2 >> 16);
8920 #else
8921         dp[0] = (mlib_u16) t2;
8922-#endif /* _LITTLE_ENDIAN */
8923+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8924 
8925         if ((size & 1) == 0) {
8926           t0 = tab[sa[0]];
8927-#ifdef _LITTLE_ENDIAN
8928+#if (BYTE_ORDER == LITTLE_ENDIAN)
8929           dp[2] = (mlib_u16) (t0 >> 16);
8930           dp[1] = (mlib_u16) t0;
8931 #else
8932           dp[1] = (mlib_u16) (t0 >> 16);
8933           dp[2] = (mlib_u16) t0;
8934-#endif /* _LITTLE_ENDIAN */
8935+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8936         }
8937       }
8938     }
8939@@ -2994,13 +2994,13 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
8940     s1 = tab1[0];
8941     s2 = tab2[0];
8942     for (i = 1; i < 256; i++) {
8943-#ifdef _LITTLE_ENDIAN
8944+#if (BYTE_ORDER == LITTLE_ENDIAN)
8945       s3 = (s0 << 16);
8946       s4 = (s2 << 16) + s1;
8947 #else
8948       s3 = s0;
8949       s4 = (s1 << 16) + s2;
8950-#endif /* _LITTLE_ENDIAN */
8951+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8952       s0 = tab0[i];
8953       s1 = tab1[i];
8954       s2 = tab2[i];
8955@@ -3008,13 +3008,13 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
8956       tab[2 * i - 1] = s4;
8957     }
8958 
8959-#ifdef _LITTLE_ENDIAN
8960+#if (BYTE_ORDER == LITTLE_ENDIAN)
8961     s4 = (s2 << 16) + s1;
8962     tab[510] = s0 << 16;
8963 #else
8964     s4 = (s1 << 16) + s2;
8965     tab[510] = s0;
8966-#endif /* _LITTLE_ENDIAN */
8967+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8968     tab[511] = s4;
8969 
8970     for (j = 0; j < ysize; j++, dst += dlb, src += slb) {
8971@@ -3050,13 +3050,13 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
8972         t1 = *(mlib_u32 *) ((mlib_u8 *) tab + s0 + 4);
8973         t2 = *(mlib_u32 *) ((mlib_u8 *) tab + s1);
8974         t3 = *(mlib_u32 *) ((mlib_u8 *) tab + s1 + 4);
8975-#ifdef _LITTLE_ENDIAN
8976+#if (BYTE_ORDER == LITTLE_ENDIAN)
8977         res1 = (t0 >> 16) + (t1 << 16);
8978         res2 = (t1 >> 16) + t2;
8979 #else
8980         res1 = (t0 << 16) + (t1 >> 16);
8981         res2 = (t1 << 16) + t2;
8982-#endif /* _LITTLE_ENDIAN */
8983+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
8984         s0 = sa[0] << 3;
8985         s1 = sa[1] << 3;
8986         da[0] = res1;
8987@@ -3068,13 +3068,13 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
8988       t1 = *(mlib_u32 *) ((mlib_u8 *) tab + s0 + 4);
8989       t2 = *(mlib_u32 *) ((mlib_u8 *) tab + s1);
8990       t3 = *(mlib_u32 *) ((mlib_u8 *) tab + s1 + 4);
8991-#ifdef _LITTLE_ENDIAN
8992+#if (BYTE_ORDER == LITTLE_ENDIAN)
8993       res1 = (t0 >> 16) + (t1 << 16);
8994       res2 = (t1 >> 16) + t2;
8995 #else
8996       res1 = (t0 << 16) + (t1 >> 16);
8997       res2 = (t1 << 16) + t2;
8998-#endif /* _LITTLE_ENDIAN */
8999+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9000       da[0] = res1;
9001       da[1] = res2;
9002       da[2] = t3;
9003@@ -3105,13 +3105,13 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
9004     s2 = tab2[0];
9005     s3 = tab3[0];
9006     for (i = 1; i < 256; i++) {
9007-#ifdef _LITTLE_ENDIAN
9008+#if (BYTE_ORDER == LITTLE_ENDIAN)
9009       s4 = (s1 << 16) + s0;
9010       s5 = (s3 << 16) + s2;
9011 #else
9012       s4 = (s0 << 16) + s1;
9013       s5 = (s2 << 16) + s3;
9014-#endif /* _LITTLE_ENDIAN */
9015+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9016       s0 = tab0[i];
9017       s1 = tab1[i];
9018       s2 = tab2[i];
9019@@ -3120,13 +3120,13 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
9020       tab[2 * i - 1] = s5;
9021     }
9022 
9023-#ifdef _LITTLE_ENDIAN
9024+#if (BYTE_ORDER == LITTLE_ENDIAN)
9025     s4 = (s1 << 16) + s0;
9026     s5 = (s3 << 16) + s2;
9027 #else
9028     s4 = (s0 << 16) + s1;
9029     s5 = (s2 << 16) + s3;
9030-#endif /* _LITTLE_ENDIAN */
9031+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9032     tab[510] = s4;
9033     tab[511] = s5;
9034 
9035@@ -3181,18 +3181,18 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
9036 
9037         t4 = tab[2 * sa[0]];
9038         t5 = tab[2 * sa[0] + 1];
9039-#ifdef _LITTLE_ENDIAN
9040+#if (BYTE_ORDER == LITTLE_ENDIAN)
9041         *dp++ = (mlib_u16) (t4);
9042 #else
9043         *dp++ = (mlib_u16) (t4 >> 16);
9044-#endif /* _LITTLE_ENDIAN */
9045+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9046         sa++;
9047         da = (mlib_u32 *) dp;
9048-#ifdef _LITTLE_ENDIAN
9049+#if (BYTE_ORDER == LITTLE_ENDIAN)
9050         *da++ = (t4 >> 16) + (t5 << 16);
9051 #else
9052         *da++ = (t4 << 16) + (t5 >> 16);
9053-#endif /* _LITTLE_ENDIAN */
9054+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9055         s0 = sa[0] << 3;
9056         s1 = sa[1] << 3;
9057         sa += 2;
9058@@ -3205,7 +3205,7 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
9059           t1 = *(mlib_u32 *) ((mlib_u8 *) tab + s0 + 4);
9060           t2 = *(mlib_u32 *) ((mlib_u8 *) tab + s1);
9061           t3 = *(mlib_u32 *) ((mlib_u8 *) tab + s1 + 4);
9062-#ifdef _LITTLE_ENDIAN
9063+#if (BYTE_ORDER == LITTLE_ENDIAN)
9064           res1 = (t5 >> 16) + (t0 << 16);
9065           res2 = (t0 >> 16) + (t1 << 16);
9066           res3 = (t1 >> 16) + (t2 << 16);
9067@@ -3215,7 +3215,7 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
9068           res2 = (t0 << 16) + (t1 >> 16);
9069           res3 = (t1 << 16) + (t2 >> 16);
9070           res4 = (t2 << 16) + (t3 >> 16);
9071-#endif /* _LITTLE_ENDIAN */
9072+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9073           s0 = sa[0] << 3;
9074           s1 = sa[1] << 3;
9075           da[0] = res1;
9076@@ -3229,7 +3229,7 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
9077         t1 = *(mlib_u32 *) ((mlib_u8 *) tab + s0 + 4);
9078         t2 = *(mlib_u32 *) ((mlib_u8 *) tab + s1);
9079         t3 = *(mlib_u32 *) ((mlib_u8 *) tab + s1 + 4);
9080-#ifdef _LITTLE_ENDIAN
9081+#if (BYTE_ORDER == LITTLE_ENDIAN)
9082         res1 = (t5 >> 16) + (t0 << 16);
9083         res2 = (t0 >> 16) + (t1 << 16);
9084         res3 = (t1 >> 16) + (t2 << 16);
9085@@ -3239,36 +3239,36 @@ void mlib_c_ImageLookUpSI_U8_S16(const m
9086         res2 = (t0 << 16) + (t1 >> 16);
9087         res3 = (t1 << 16) + (t2 >> 16);
9088         res4 = (t2 << 16) + (t3 >> 16);
9089-#endif /* _LITTLE_ENDIAN */
9090+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9091         da[0] = res1;
9092         da[1] = res2;
9093         da[2] = res3;
9094         da[3] = res4;
9095         da += 4;
9096         dp = (mlib_u16 *) da;
9097-#ifdef _LITTLE_ENDIAN
9098+#if (BYTE_ORDER == LITTLE_ENDIAN)
9099         dp[0] = (mlib_u16) (t3 >> 16);
9100 #else
9101         dp[0] = (mlib_u16) t3;
9102-#endif /* _LITTLE_ENDIAN */
9103+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9104 
9105         if ((size & 1) == 0) {
9106           t0 = tab[2 * sa[0]];
9107-#ifdef _LITTLE_ENDIAN
9108+#if (BYTE_ORDER == LITTLE_ENDIAN)
9109           dp[2] = (mlib_u16) (t0 >> 16);
9110           dp[1] = (mlib_u16) t0;
9111 #else
9112           dp[1] = (mlib_u16) (t0 >> 16);
9113           dp[2] = (mlib_u16) t0;
9114-#endif /* _LITTLE_ENDIAN */
9115+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9116           t0 = tab[2 * sa[0] + 1];
9117-#ifdef _LITTLE_ENDIAN
9118+#if (BYTE_ORDER == LITTLE_ENDIAN)
9119           dp[4] = (mlib_u16) (t0 >> 16);
9120           dp[3] = (mlib_u16) t0;
9121 #else
9122           dp[3] = (mlib_u16) (t0 >> 16);
9123           dp[4] = (mlib_u16) t0;
9124-#endif /* _LITTLE_ENDIAN */
9125+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9126         }
9127       }
9128     }
9129@@ -3439,7 +3439,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9130 #pragma pipeloop(0)
9131 #endif /* __SUNPRO_C */
9132       for (i = 0; i < size - 7; i += 4, dp += 8, sa++) {
9133-#ifdef _LITTLE_ENDIAN
9134+#if (BYTE_ORDER == LITTLE_ENDIAN)
9135         t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9136         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9137         t2 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 6) & 0x3FC));
9138@@ -3449,12 +3449,12 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9139         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 22) & 0x3FC));
9140         t2 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9141         t3 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9142-#endif /* _LITTLE_ENDIAN */
9143+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9144         dp[0] = t0;
9145         dp[1] = t1;
9146         dp[2] = t2;
9147         dp[3] = t3;
9148-#ifdef _LITTLE_ENDIAN
9149+#if (BYTE_ORDER == LITTLE_ENDIAN)
9150         t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9151         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9152         t2 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 22) & 0x3FC));
9153@@ -3464,7 +3464,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9154         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 6) & 0x3FC));
9155         t2 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9156         t3 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9157-#endif /* _LITTLE_ENDIAN */
9158+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9159         s0 = sa[0];
9160         dp[4] = t0;
9161         dp[5] = t1;
9162@@ -3472,7 +3472,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9163         dp[7] = t3;
9164       }
9165 
9166-#ifdef _LITTLE_ENDIAN
9167+#if (BYTE_ORDER == LITTLE_ENDIAN)
9168       t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9169       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9170       t2 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 6) & 0x3FC));
9171@@ -3482,12 +3482,12 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9172       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 22) & 0x3FC));
9173       t2 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9174       t3 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9175-#endif /* _LITTLE_ENDIAN */
9176+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9177       dp[0] = t0;
9178       dp[1] = t1;
9179       dp[2] = t2;
9180       dp[3] = t3;
9181-#ifdef _LITTLE_ENDIAN
9182+#if (BYTE_ORDER == LITTLE_ENDIAN)
9183       t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9184       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9185       t2 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 22) & 0x3FC));
9186@@ -3497,7 +3497,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9187       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 6) & 0x3FC));
9188       t2 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9189       t3 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9190-#endif /* _LITTLE_ENDIAN */
9191+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9192       dp[4] = t0;
9193       dp[5] = t1;
9194       dp[6] = t2;
9195@@ -3545,7 +3545,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9196 #pragma pipeloop(0)
9197 #endif /* __SUNPRO_C */
9198       for (i = 0; i < size - 7; i += 4, dp += 12, sa++) {
9199-#ifdef _LITTLE_ENDIAN
9200+#if (BYTE_ORDER == LITTLE_ENDIAN)
9201         t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9202         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9203         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 << 2) & 0x3FC));
9204@@ -3559,14 +3559,14 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9205         t3 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9206         t4 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9207         t5 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 14) & 0x3FC));
9208-#endif /* _LITTLE_ENDIAN */
9209+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9210         dp[0] = t0;
9211         dp[1] = t1;
9212         dp[2] = t2;
9213         dp[3] = t3;
9214         dp[4] = t4;
9215         dp[5] = t5;
9216-#ifdef _LITTLE_ENDIAN
9217+#if (BYTE_ORDER == LITTLE_ENDIAN)
9218         t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9219         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9220         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 14) & 0x3FC));
9221@@ -3580,7 +3580,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9222         t3 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9223         t4 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9224         t5 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 << 2) & 0x3FC));
9225-#endif /* _LITTLE_ENDIAN */
9226+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9227         s0 = sa[0];
9228         dp[6] = t0;
9229         dp[7] = t1;
9230@@ -3590,7 +3590,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9231         dp[11] = t5;
9232       }
9233 
9234-#ifdef _LITTLE_ENDIAN
9235+#if (BYTE_ORDER == LITTLE_ENDIAN)
9236       t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9237       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9238       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 << 2) & 0x3FC));
9239@@ -3604,14 +3604,14 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9240       t3 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9241       t4 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9242       t5 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 14) & 0x3FC));
9243-#endif /* _LITTLE_ENDIAN */
9244+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9245       dp[0] = t0;
9246       dp[1] = t1;
9247       dp[2] = t2;
9248       dp[3] = t3;
9249       dp[4] = t4;
9250       dp[5] = t5;
9251-#ifdef _LITTLE_ENDIAN
9252+#if (BYTE_ORDER == LITTLE_ENDIAN)
9253       t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9254       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9255       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 14) & 0x3FC));
9256@@ -3625,7 +3625,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9257       t3 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9258       t4 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9259       t5 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 << 2) & 0x3FC));
9260-#endif /* _LITTLE_ENDIAN */
9261+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9262       dp[6] = t0;
9263       dp[7] = t1;
9264       dp[8] = t2;
9265@@ -3678,7 +3678,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9266 #pragma pipeloop(0)
9267 #endif /* __SUNPRO_C */
9268       for (i = 0; i < size - 7; i += 4, dp += 16, sa++) {
9269-#ifdef _LITTLE_ENDIAN
9270+#if (BYTE_ORDER == LITTLE_ENDIAN)
9271         t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9272         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9273         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 << 2) & 0x3FC));
9274@@ -3688,12 +3688,12 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9275         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 22) & 0x3FC));
9276         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 22) & 0x3FC));
9277         t3 = *(mlib_u32 *) ((mlib_u8 *) tab3 + ((s0 >> 22) & 0x3FC));
9278-#endif /* _LITTLE_ENDIAN */
9279+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9280         dp[0] = t0;
9281         dp[1] = t1;
9282         dp[2] = t2;
9283         dp[3] = t3;
9284-#ifdef _LITTLE_ENDIAN
9285+#if (BYTE_ORDER == LITTLE_ENDIAN)
9286         t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 6) & 0x3FC));
9287         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 6) & 0x3FC));
9288         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 6) & 0x3FC));
9289@@ -3703,12 +3703,12 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9290         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9291         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 14) & 0x3FC));
9292         t3 = *(mlib_u32 *) ((mlib_u8 *) tab3 + ((s0 >> 14) & 0x3FC));
9293-#endif /* _LITTLE_ENDIAN */
9294+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9295         dp[4] = t0;
9296         dp[5] = t1;
9297         dp[6] = t2;
9298         dp[7] = t3;
9299-#ifdef _LITTLE_ENDIAN
9300+#if (BYTE_ORDER == LITTLE_ENDIAN)
9301         t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9302         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9303         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 14) & 0x3FC));
9304@@ -3718,12 +3718,12 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9305         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 6) & 0x3FC));
9306         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 6) & 0x3FC));
9307         t3 = *(mlib_u32 *) ((mlib_u8 *) tab3 + ((s0 >> 6) & 0x3FC));
9308-#endif /* _LITTLE_ENDIAN */
9309+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9310         dp[8] = t0;
9311         dp[9] = t1;
9312         dp[10] = t2;
9313         dp[11] = t3;
9314-#ifdef _LITTLE_ENDIAN
9315+#if (BYTE_ORDER == LITTLE_ENDIAN)
9316         t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 22) & 0x3FC));
9317         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 22) & 0x3FC));
9318         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 22) & 0x3FC));
9319@@ -3733,7 +3733,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9320         t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9321         t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 << 2) & 0x3FC));
9322         t3 = *(mlib_u32 *) ((mlib_u8 *) tab3 + ((s0 << 2) & 0x3FC));
9323-#endif /* _LITTLE_ENDIAN */
9324+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9325         s0 = sa[0];
9326         dp[12] = t0;
9327         dp[13] = t1;
9328@@ -3741,7 +3741,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9329         dp[15] = t3;
9330       }
9331 
9332-#ifdef _LITTLE_ENDIAN
9333+#if (BYTE_ORDER == LITTLE_ENDIAN)
9334       t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 << 2) & 0x3FC));
9335       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9336       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 << 2) & 0x3FC));
9337@@ -3751,12 +3751,12 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9338       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 22) & 0x3FC));
9339       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 22) & 0x3FC));
9340       t3 = *(mlib_u32 *) ((mlib_u8 *) tab3 + ((s0 >> 22) & 0x3FC));
9341-#endif /* _LITTLE_ENDIAN */
9342+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9343       dp[0] = t0;
9344       dp[1] = t1;
9345       dp[2] = t2;
9346       dp[3] = t3;
9347-#ifdef _LITTLE_ENDIAN
9348+#if (BYTE_ORDER == LITTLE_ENDIAN)
9349       t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 6) & 0x3FC));
9350       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 6) & 0x3FC));
9351       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 6) & 0x3FC));
9352@@ -3766,12 +3766,12 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9353       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9354       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 14) & 0x3FC));
9355       t3 = *(mlib_u32 *) ((mlib_u8 *) tab3 + ((s0 >> 14) & 0x3FC));
9356-#endif /* _LITTLE_ENDIAN */
9357+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9358       dp[4] = t0;
9359       dp[5] = t1;
9360       dp[6] = t2;
9361       dp[7] = t3;
9362-#ifdef _LITTLE_ENDIAN
9363+#if (BYTE_ORDER == LITTLE_ENDIAN)
9364       t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 14) & 0x3FC));
9365       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 14) & 0x3FC));
9366       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 14) & 0x3FC));
9367@@ -3781,12 +3781,12 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9368       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 6) & 0x3FC));
9369       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 6) & 0x3FC));
9370       t3 = *(mlib_u32 *) ((mlib_u8 *) tab3 + ((s0 >> 6) & 0x3FC));
9371-#endif /* _LITTLE_ENDIAN */
9372+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9373       dp[8] = t0;
9374       dp[9] = t1;
9375       dp[10] = t2;
9376       dp[11] = t3;
9377-#ifdef _LITTLE_ENDIAN
9378+#if (BYTE_ORDER == LITTLE_ENDIAN)
9379       t0 = *(mlib_u32 *) ((mlib_u8 *) tab0 + ((s0 >> 22) & 0x3FC));
9380       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 >> 22) & 0x3FC));
9381       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 >> 22) & 0x3FC));
9382@@ -3796,7 +3796,7 @@ void mlib_c_ImageLookUpSI_U8_S32(const m
9383       t1 = *(mlib_u32 *) ((mlib_u8 *) tab1 + ((s0 << 2) & 0x3FC));
9384       t2 = *(mlib_u32 *) ((mlib_u8 *) tab2 + ((s0 << 2) & 0x3FC));
9385       t3 = *(mlib_u32 *) ((mlib_u8 *) tab3 + ((s0 << 2) & 0x3FC));
9386-#endif /* _LITTLE_ENDIAN */
9387+#endif /* BYTE_ORDER == LITTLE_ENDIAN */
9388       dp[12] = t0;
9389       dp[13] = t1;
9390       dp[14] = t2;
9391diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_image.h ./jdk/src/share/native/sun/awt/medialib/mlib_image.h
9392--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_image.h  2009-01-27 15:45:46.000000000 -0500
9393+++ ./jdk/src/share/native/sun/awt/medialib/mlib_image.h        2009-05-04 17:37:16.000000000 -0400
9394@@ -27,6 +27,11 @@
9395 #ifndef MLIB_IMAGE_H
9396 #define MLIB_IMAGE_H
9397 
9398+#ifdef __OpenBSD__
9399+#include <sys/types.h>
9400+#endif
9401+#include <machine/endian.h>
9402+
9403 #include <mlib_types.h>
9404 #include <mlib_status.h>
9405 #include <mlib_sys.h>
9406diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_sys.c ./jdk/src/share/native/sun/awt/medialib/mlib_sys.c
9407--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_sys.c    2009-01-27 15:45:46.000000000 -0500
9408+++ ./jdk/src/share/native/sun/awt/medialib/mlib_sys.c  2009-05-04 17:37:16.000000000 -0400
9409@@ -26,9 +26,15 @@
9410 
9411 #include <stdlib.h>
9412 #include <string.h>
9413+#ifdef _ALLBSD_SOURCE
9414+#include <unistd.h>
9415+#endif
9416 #include <mlib_types.h>
9417 #include <mlib_sys_proto.h>
9418 #include "mlib_SysMath.h"
9419+#if defined(_ALLBSD_SOURCE)
9420+#include <sys/param.h>
9421+#endif
9422 
9423 /***************************************************************/
9424 
9425@@ -86,7 +92,12 @@ void *__mlib_malloc(mlib_u32 size)
9426    * alignment. -- from stdlib.h of MS VC++5.0.
9427    */
9428   return (void *) malloc(size);
9429-#else /* _MSC_VER */
9430+#elif defined(__FreeBSD__) && (__FreeBSD_version >= 700013)
9431+  void *ret;
9432+  return posix_memalign(&ret, 8, size) ? NULL : ret;
9433+#elif defined(_ALLBSD_SOURCE)
9434+  return valloc(size);
9435+#else
9436   return (void *) memalign(8, size);
9437 #endif /* _MSC_VER */
9438 }
9439diff -upr ../orig/jdk/src/share/native/sun/awt/medialib/mlib_types.h ./jdk/src/share/native/sun/awt/medialib/mlib_types.h
9440--- ../orig/jdk/src/share/native/sun/awt/medialib/mlib_types.h  2009-01-27 15:45:46.000000000 -0500
9441+++ ./jdk/src/share/native/sun/awt/medialib/mlib_types.h        2009-05-04 17:37:16.000000000 -0400
9442@@ -59,7 +59,10 @@ typedef double             mlib_d64;
9443 
9444 #if defined(__SUNPRO_C) || defined(__SUNPRO_CC) || defined(__GNUC__)
9445 
9446-#if defined(__linux__)
9447+#if defined(_ALLBSD_SOURCE)
9448+#include <stddef.h>                     /* for ptrdiff_t */
9449+#include <stdint.h>                     /* for uintptr_t */
9450+#elif defined(__linux__)
9451 #include <stdint.h>                     /* for uintptr_t */
9452 #include <malloc.h>                     /* for ptrdiff_t */
9453 #else
9454diff -upr ../orig/jdk/src/share/native/sun/font/AccelGlyphCache.c ./jdk/src/share/native/sun/font/AccelGlyphCache.c
9455--- ../orig/jdk/src/share/native/sun/font/AccelGlyphCache.c     2009-01-27 15:45:46.000000000 -0500
9456+++ ./jdk/src/share/native/sun/font/AccelGlyphCache.c   2009-05-04 17:37:16.000000000 -0400
9457@@ -23,7 +23,11 @@
9458  * have any questions.
9459  */
9460 
9461+#ifdef _ALLBSD_SOURCE
9462+#include <stdlib.h>
9463+#else
9464 #include <malloc.h>
9465+#endif
9466 #include "jni.h"
9467 #include "AccelGlyphCache.h"
9468 #include "Trace.h"
9469diff -upr ../orig/jdk/src/share/native/sun/font/DrawGlyphList.c ./jdk/src/share/native/sun/font/DrawGlyphList.c
9470--- ../orig/jdk/src/share/native/sun/font/DrawGlyphList.c       2009-01-27 15:45:46.000000000 -0500
9471+++ ./jdk/src/share/native/sun/font/DrawGlyphList.c     2009-05-04 17:37:16.000000000 -0400
9472@@ -26,7 +26,11 @@
9473 #include "jlong.h"
9474 #include "math.h"
9475 #include "string.h"
9476+#ifdef _ALLBSD_SOURCE
9477+#include "stdlib.h"
9478+#else
9479 #include "malloc.h"
9480+#endif
9481 #include "sunfontids.h"
9482 #include "fontscalerdefs.h"
9483 #include "glyphblitting.h"
9484diff -upr ../orig/jdk/src/share/native/sun/font/sunFont.c ./jdk/src/share/native/sun/font/sunFont.c
9485--- ../orig/jdk/src/share/native/sun/font/sunFont.c     2009-01-27 15:45:46.000000000 -0500
9486+++ ./jdk/src/share/native/sun/font/sunFont.c   2009-05-04 17:37:16.000000000 -0400
9487@@ -24,7 +24,9 @@
9488  */
9489 
9490 #include "stdlib.h"
9491+#ifndef _ALLBSD_SOURCE
9492 #include "malloc.h"
9493+#endif
9494 #include "string.h"
9495 #include "gdefs.h"
9496 #include "jlong.h"
9497diff -upr ../orig/jdk/src/share/native/sun/java2d/SurfaceData.c ./jdk/src/share/native/sun/java2d/SurfaceData.c
9498--- ../orig/jdk/src/share/native/sun/java2d/SurfaceData.c       2009-01-27 15:45:46.000000000 -0500
9499+++ ./jdk/src/share/native/sun/java2d/SurfaceData.c     2009-05-04 17:37:16.000000000 -0400
9500@@ -28,7 +28,11 @@
9501 #include "jni_util.h"
9502 #include "Disposer.h"
9503 
9504+#ifdef _ALLBSD_SOURCE
9505+#include <stdlib.h>
9506+#else
9507 #include "malloc.h"
9508+#endif
9509 #include "string.h"
9510 
9511 /**
9512diff -upr ../orig/jdk/src/share/native/sun/java2d/opengl/OGLFuncs.h ./jdk/src/share/native/sun/java2d/opengl/OGLFuncs.h
9513--- ../orig/jdk/src/share/native/sun/java2d/opengl/OGLFuncs.h   2009-01-27 15:45:47.000000000 -0500
9514+++ ./jdk/src/share/native/sun/java2d/opengl/OGLFuncs.h 2009-05-04 17:37:17.000000000 -0400
9515@@ -26,6 +26,9 @@
9516 #ifndef OGLFuncs_h_Included
9517 #define OGLFuncs_h_Included
9518 
9519+#ifdef _ALLBSD_SOURCE
9520+#include <dlfcn.h>
9521+#endif
9522 #include "jni.h"
9523 #include "J2D_GL/gl.h"
9524 #include "J2D_GL/glext.h"
9525diff -upr ../orig/jdk/src/share/native/sun/java2d/opengl/OGLRenderQueue.c ./jdk/src/share/native/sun/java2d/opengl/OGLRenderQueue.c
9526--- ../orig/jdk/src/share/native/sun/java2d/opengl/OGLRenderQueue.c     2009-01-27 15:45:47.000000000 -0500
9527+++ ./jdk/src/share/native/sun/java2d/opengl/OGLRenderQueue.c   2009-05-04 17:37:17.000000000 -0400
9528@@ -25,7 +25,11 @@
9529 
9530 #ifndef HEADLESS
9531 
9532+#ifdef _ALLBSD_SOURCE
9533+#include <stdlib.h>
9534+#else
9535 #include <malloc.h>
9536+#endif
9537 
9538 #include "sun_java2d_pipe_BufferedOpCodes.h"
9539 
9540diff -upr ../orig/jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c ./jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c
9541--- ../orig/jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c    2009-01-27 15:45:47.000000000 -0500
9542+++ ./jdk/src/share/native/sun/java2d/opengl/OGLTextRenderer.c  2009-05-04 17:37:17.000000000 -0400
9543@@ -25,7 +25,11 @@
9544 
9545 #ifndef HEADLESS
9546 
9547+#ifdef _ALLBSD_SOURCE
9548+#include <stdlib.h>
9549+#else
9550 #include <malloc.h>
9551+#endif
9552 #include <math.h>
9553 #include <jlong.h>
9554 
9555diff -upr ../orig/jdk/src/share/transport/socket/socketTransport.c ./jdk/src/share/transport/socket/socketTransport.c
9556--- ../orig/jdk/src/share/transport/socket/socketTransport.c    2009-01-27 15:45:48.000000000 -0500
9557+++ ./jdk/src/share/transport/socket/socketTransport.c  2009-05-04 17:37:17.000000000 -0400
9558@@ -65,6 +65,9 @@ static jdwpTransportEnv single_env = (jd
9559 #define HEADER_SIZE     11
9560 #define MAX_DATA_SIZE 1000
9561 
9562+static jint recv_fully(int, char *, int);
9563+static jint send_fully(int, char *, int);
9564+
9565 /*
9566  * Record the last error for this thread.
9567  */
9568@@ -153,7 +156,7 @@ handshake(int fd, jlong timeout) {
9569         }
9570         buf = b;
9571         buf += received;
9572-        n = dbgsysRecv(fd, buf, strlen(hello)-received, 0);
9573+        n = recv_fully(fd, buf, strlen(hello)-received);
9574         if (n == 0) {
9575             setLastError(0, "handshake failed - connection prematurally closed");
9576             return JDWPTRANSPORT_ERROR_IO_ERROR;
9577@@ -179,7 +182,7 @@ handshake(int fd, jlong timeout) {
9578         }
9579     }
9580 
9581-    if (dbgsysSend(fd, hello, strlen(hello), 0) != (int)strlen(hello)) {
9582+    if (send_fully(fd, hello, strlen(hello)) != (int)strlen(hello)) {
9583         RETURN_IO_ERROR("send failed during handshake");
9584     }
9585     return JDWPTRANSPORT_ERROR_NONE;
9586@@ -554,19 +557,19 @@ socketTransport_writePacket(jdwpTranspor
9587     /* Do one send for short packets, two for longer ones */
9588     if (data_len <= MAX_DATA_SIZE) {
9589         memcpy(header + HEADER_SIZE, data, data_len);
9590-        if (dbgsysSend(socketFD, (char *)&header, HEADER_SIZE + data_len, 0) !=
9591+        if (send_fully(socketFD, (char *)&header, HEADER_SIZE + data_len) !=
9592             HEADER_SIZE + data_len) {
9593             RETURN_IO_ERROR("send failed");
9594         }
9595     } else {
9596         memcpy(header + HEADER_SIZE, data, MAX_DATA_SIZE);
9597-        if (dbgsysSend(socketFD, (char *)&header, HEADER_SIZE + MAX_DATA_SIZE, 0) !=
9598+        if (send_fully(socketFD, (char *)&header, HEADER_SIZE + MAX_DATA_SIZE) !=
9599             HEADER_SIZE + MAX_DATA_SIZE) {
9600             RETURN_IO_ERROR("send failed");
9601         }
9602         /* Send the remaining data bytes right out of the data area. */
9603-        if (dbgsysSend(socketFD, (char *)data + MAX_DATA_SIZE,
9604-                       data_len - MAX_DATA_SIZE, 0) != data_len - MAX_DATA_SIZE) {
9605+        if (send_fully(socketFD, (char *)data + MAX_DATA_SIZE,
9606+                       data_len - MAX_DATA_SIZE) != data_len - MAX_DATA_SIZE) {
9607             RETURN_IO_ERROR("send failed");
9608         }
9609     }
9610@@ -574,13 +577,33 @@ socketTransport_writePacket(jdwpTranspor
9611     return JDWPTRANSPORT_ERROR_NONE;
9612 }
9613 
9614-static jint
9615+jint
9616 recv_fully(int f, char *buf, int len)
9617 {
9618     int nbytes = 0;
9619     while (nbytes < len) {
9620         int res = dbgsysRecv(f, buf + nbytes, len - nbytes, 0);
9621         if (res < 0) {
9622+           if (errno == EINTR)
9623+               continue;
9624+            return res;
9625+        } else if (res == 0) {
9626+            break; /* eof, return nbytes which is less than len */
9627+        }
9628+        nbytes += res;
9629+    }
9630+    return nbytes;
9631+}
9632+
9633+jint
9634+send_fully(int f, char *buf, int len)
9635+{
9636+    int nbytes = 0;
9637+    while (nbytes < len) {
9638+        int res = dbgsysSend(f, buf + nbytes, len - nbytes, 0);
9639+        if (res < 0) {
9640+           if (errno == EINTR)
9641+               continue;
9642             return res;
9643         } else if (res == 0) {
9644             break; /* eof, return nbytes which is less than len */
9645diff -upr ../orig/jdk/src/solaris/back/exec_md.c ./jdk/src/solaris/back/exec_md.c
9646--- ../orig/jdk/src/solaris/back/exec_md.c      2009-01-27 15:45:48.000000000 -0500
9647+++ ./jdk/src/solaris/back/exec_md.c    2009-05-04 17:37:17.000000000 -0400
9648@@ -30,7 +30,7 @@
9649 #include "sys.h"
9650 #include "util.h"
9651 
9652-#ifdef LINUX
9653+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
9654   /* Linux */
9655   #define FORK() fork()
9656 #else
9657diff -upr ../orig/jdk/src/solaris/back/linker_md.c ./jdk/src/solaris/back/linker_md.c
9658--- ../orig/jdk/src/solaris/back/linker_md.c    2009-01-27 15:45:48.000000000 -0500
9659+++ ./jdk/src/solaris/back/linker_md.c  2009-05-04 17:37:17.000000000 -0400
9660@@ -48,6 +48,12 @@
9661 #include "threads_md.h"
9662 #endif
9663 
9664+#ifdef __APPLE__
9665+#define LIB_SUFFIX "dylib"
9666+#else
9667+#define LIB_SUFFIX "so"
9668+#endif
9669+
9670 /*
9671  * create a string for the JNI native function name by adding the
9672  * appropriate decorations.
9673@@ -77,9 +83,9 @@ dbgsysBuildLibName(char *holder, int hol
9674     }
9675 
9676     if (pnamelen == 0) {
9677-        (void)snprintf(holder, holderlen, "lib%s.so", fname);
9678+        (void)snprintf(holder, holderlen, "lib%s." LIB_SUFFIX, fname);
9679     } else {
9680-        (void)snprintf(holder, holderlen, "%s/lib%s.so", pname, fname);
9681+        (void)snprintf(holder, holderlen, "%s/lib%s." LIB_SUFFIX, pname, fname);
9682     }
9683 }
9684 
9685diff -upr ../orig/jdk/src/solaris/back/util_md.h ./jdk/src/solaris/back/util_md.h
9686--- ../orig/jdk/src/solaris/back/util_md.h      2009-01-27 15:45:48.000000000 -0500
9687+++ ./jdk/src/solaris/back/util_md.h    2009-05-04 17:37:17.000000000 -0400
9688@@ -28,6 +28,7 @@
9689 
9690 #include <limits.h>
9691 #include <sys/types.h>
9692+#include <machine/endian.h>
9693 
9694 #ifdef _LP64
9695 typedef unsigned long UNSIGNED_JLONG;
9696@@ -43,7 +44,7 @@ typedef unsigned long UNSIGNED_JINT;
9697 
9698 /* On little endian machines, convert java big endian numbers. */
9699 
9700-#if defined(_LITTLE_ENDIAN)
9701+#if (BYTE_ORDER == LITTLE_ENDIAN)
9702 
9703 #define HOST_TO_JAVA_CHAR(x) (((x & 0xff) << 8) | ((x >> 8) & (0xff)))
9704 #define HOST_TO_JAVA_SHORT(x) (((x & 0xff) << 8) | ((x >> 8) & (0xff)))
9705diff -upr ../orig/jdk/src/solaris/bin/java_md.c ./jdk/src/solaris/bin/java_md.c
9706--- ../orig/jdk/src/solaris/bin/java_md.c       2009-01-27 15:45:48.000000000 -0500
9707+++ ./jdk/src/solaris/bin/java_md.c     2009-05-04 17:37:17.000000000 -0400
9708@@ -24,6 +24,7 @@
9709  */
9710 
9711 #include "java.h"
9712+#include "jvm_md.h"
9713 #include <dirent.h>
9714 #include <dlfcn.h>
9715 #include <fcntl.h>
9716@@ -34,17 +35,33 @@
9717 #include <sys/stat.h>
9718 #include <unistd.h>
9719 #include <sys/types.h>
9720+#if defined(_ALLBSD_SOURCE)
9721+#include <sys/time.h>
9722+#endif
9723+#ifndef _SC_PHYS_PAGES
9724+#include <sys/sysctl.h>
9725+#endif
9726+
9727 #include "manifest_info.h"
9728 #include "version_comp.h"
9729 
9730-#ifdef __linux__
9731+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
9732 #include <pthread.h>
9733 #else
9734 #include <thread.h>
9735 #endif
9736 
9737+#ifdef __APPLE__
9738+#define JVM_DLL "libjvm.dylib"
9739+#define JAVA_DLL "libjava.dylib"
9740+/* FALLBACK avoids naming conflicts with system libraries
9741+ * (eg, ImageIO's libJPEG.dylib) */
9742+#define LD_LIBRARY_PATH "DYLD_FALLBACK_LIBRARY_PATH"
9743+#else
9744 #define JVM_DLL "libjvm.so"
9745 #define JAVA_DLL "libjava.so"
9746+#define LD_LIBRARY_PATH "LD_LIBRARY_PATH"
9747+#endif
9748 
9749 /*
9750  * If a processor / os combination has the ability to run binaries of
9751@@ -75,14 +92,31 @@
9752 #endif
9753 
9754 /* pointer to environment */
9755+#ifdef __APPLE__
9756+#include <crt_externs.h>
9757+#define environ (*_NSGetEnviron())
9758+#else
9759 extern char **environ;
9760+#endif
9761 
9762 /*
9763  *      A collection of useful strings. One should think of these as #define
9764  *      entries, but actual strings can be more efficient (with many compilers).
9765  */
9766-#ifdef __linux__
9767-static const char *system_dir   = "/usr/java";
9768+#if defined(__FreeBSD__)
9769+static const char *system_dir  = "/usr/local/openjdk6";
9770+static const char *user_dir    = "/java";
9771+#elif defined(__NetBSD__)
9772+static const char *system_dir  = "/usr/local/openjdk6";
9773+static const char *user_dir    = "/java";
9774+#elif defined(__OpenBSD__)
9775+static const char *system_dir  = "/usr/local/openjdk6";
9776+static const char *user_dir    = "/java";
9777+#elif defined(__APPLE__)
9778+static const char *system_dir  = "/usr/local/openjdk6";
9779+static const char *user_dir    = "/java";
9780+#elif defined(__linux__)
9781+static const char *system_dir   = "/usr/local/java";
9782 static const char *user_dir     = "/java";
9783 #else /* Solaris */
9784 static const char *system_dir   = "/usr/jdk";
9785@@ -404,10 +438,10 @@ CreateExecutionEnvironment(int *_argcp,
9786        * If not on Solaris, assume only a single LD_LIBRARY_PATH
9787        * variable.
9788        */
9789-      runpath = getenv("LD_LIBRARY_PATH");
9790+      runpath = getenv(LD_LIBRARY_PATH);
9791 #endif /* __sun */
9792 
9793-#ifdef __linux
9794+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
9795       /*
9796        * On linux, if a binary is running as sgid or suid, glibc sets
9797        * LD_LIBRARY_PATH to the empty string for security purposes.  (In
9798@@ -431,7 +465,7 @@ CreateExecutionEnvironment(int *_argcp,
9799       new_runpath = JLI_MemAlloc( ((runpath!=NULL)?strlen(runpath):0) +
9800                               2*strlen(jrepath) + 2*strlen(arch) +
9801                               strlen(jvmpath) + 52);
9802-      newpath = new_runpath + strlen("LD_LIBRARY_PATH=");
9803+      newpath = new_runpath + strlen(LD_LIBRARY_PATH "=");
9804 
9805 
9806       /*
9807@@ -446,7 +480,7 @@ CreateExecutionEnvironment(int *_argcp,
9808 
9809         /* jvmpath, ((running != wanted)?((wanted==64)?"/"LIBARCH64NAME:"/.."):""), */
9810 
9811-        sprintf(new_runpath, "LD_LIBRARY_PATH="
9812+        sprintf(new_runpath, LD_LIBRARY_PATH "="
9813                 "%s:"
9814                 "%s/lib/%s:"
9815                 "%s/../lib/%s",
9816@@ -977,6 +1011,7 @@ jboolean RemovableMachineDependentOption
9817 /* Compute physical memory by asking the OS */
9818 uint64_t
9819 physical_memory(void) {
9820+#ifdef _SC_PHYS_PAGES
9821   const uint64_t pages     = (uint64_t) sysconf(_SC_PHYS_PAGES);
9822   const uint64_t page_size = (uint64_t) sysconf(_SC_PAGESIZE);
9823   const uint64_t result    = pages * page_size;
9824@@ -988,6 +1023,28 @@ physical_memory(void) {
9825            "  physical memory: " UINT64_FORMAT " (%.3fGB)\n",
9826            pages, page_size, result, result / (double) GB);
9827   }
9828+#else
9829+#ifdef HW_PHYSMEM64
9830+  int64_t physmem;
9831+  int name[2] = { CTL_HW, HW_PHYSMEM64 };
9832+#else
9833+  unsigned long physmem;
9834+  int name[2] = { CTL_HW, HW_PHYSMEM };
9835+#endif
9836+  size_t physmem_len = sizeof(physmem);
9837+  uint64_t result;
9838+# define UINT64_FORMAT "%" PRIu64
9839+
9840+  if (sysctl(name, 2, &physmem, &physmem_len, NULL, 0) == -1)
9841+       physmem = 256 * MB;
9842+
9843+  result = (uint64_t)physmem;
9844+
9845+  if (_launcher_debug) {
9846+    printf("physical memory: " UINT64_FORMAT " (%.3fGB)\n",
9847+           result, result / (double) GB);
9848+  }
9849+#endif
9850   return result;
9851 }
9852 
9853@@ -1083,7 +1140,7 @@ get_cpuid(uint32_t arg,
9854 
9855 #endif /* __sun && i586 */
9856 
9857-#if defined(__linux__) && defined(i586)
9858+#if (defined(__linux__) || defined(_ALLBSD_SOURCE)) && defined(i586)
9859 
9860 /*
9861  * A utility method for asking the CPU about itself.
9862@@ -1692,9 +1749,23 @@ UnsetEnv(char *name)
9863     return(borrowed_unsetenv(name));
9864 }
9865 
9866+#if defined(_ALLBSD_SOURCE)
9867+/*
9868+ * BSD's implementation of CounterGet()
9869+ */
9870+int64_t
9871+CounterGet()
9872+{
9873+       struct timeval tv;
9874+       gettimeofday(&tv, NULL);
9875+       return (tv.tv_sec * 1000) + tv.tv_usec;
9876+}
9877+#endif
9878+
9879+
9880 /* --- Splash Screen shared library support --- */
9881 
9882-static const char* SPLASHSCREEN_SO = "libsplashscreen.so";
9883+static const char* SPLASHSCREEN_SO = JNI_LIB_NAME("splashscreen");
9884 
9885 static void* hSplashLib = NULL;
9886 
9887@@ -1722,13 +1793,15 @@ jlong_format_specifier() {
9888     return "%lld";
9889 }
9890 
9891+
9892+
9893 /*
9894  * Block current thread and continue execution in a new thread
9895  */
9896 int
9897-ContinueInNewThread(int (JNICALL *continuation)(void *), jlong stack_size, void * args, int ret) {
9898+ContinueInNewThread0(int (JNICALL *continuation)(void *), jlong stack_size, void * args) {
9899     int rslt;
9900-#ifdef __linux__
9901+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
9902     pthread_t tid;
9903     pthread_attr_t attr;
9904     pthread_attr_init(&attr);
9905@@ -1765,13 +1838,11 @@ ContinueInNewThread(int (JNICALL *contin
9906       rslt = continuation(args);
9907     }
9908 #endif
9909-    /* If the caller has deemed there is an error we
9910-     * simply return that, otherwise we return the value of
9911-     * the callee
9912-     */
9913-    return (ret != 0) ? ret : rslt;
9914+    return rslt;
9915 }
9916 
9917+
9918+
9919 /* Coarse estimation of number of digits assuming the worst case is a 64-bit pid. */
9920 #define MAX_PID_STR_SZ   20
9921 
9922diff -upr ../orig/jdk/src/solaris/bin/java_md.h ./jdk/src/solaris/bin/java_md.h
9923--- ../orig/jdk/src/solaris/bin/java_md.h       2009-01-27 15:45:48.000000000 -0500
9924+++ ./jdk/src/solaris/bin/java_md.h     2009-05-04 17:37:17.000000000 -0400
9925@@ -58,10 +58,14 @@
9926 #include <sys/time.h>
9927 #define CounterGet()              (gethrtime()/1000)
9928 #define Counter2Micros(counts)    (counts)
9929+#elif defined(_ALLBSD_SOURCE)
9930+/* CounterGet() is implemented in java_md.c */
9931+int64_t CounterGet(void);
9932+#define Counter2Micros(counts)    (counts)
9933 #else
9934 #define CounterGet()              (0)
9935 #define Counter2Micros(counts)    (1)
9936-#endif /* HAVE_GETHRTIME */
9937+#endif /* HAVE_GETHRTIME || _ALLBSD_SOURCE */
9938 
9939 /*
9940  * Function prototypes.
9941diff -upr ../orig/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java ./jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java
9942--- ../orig/jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java 2009-01-27 15:45:48.000000000 -0500
9943+++ ./jdk/src/solaris/classes/sun/awt/X11GraphicsEnvironment.java       2009-05-04 17:37:17.000000000 -0400
9944@@ -403,7 +403,7 @@ public class X11GraphicsEnvironment
9945         if (fontID != null) {
9946             fileName = (String)fontNameMap.get(fontID);
9947             /* On Linux check for the Lucida Oblique fonts */
9948-            if (fileName == null && isLinux && !isOpenJDK()) {
9949+            if (fileName == null && isLinuxOrBSD && !isOpenJDK()) {
9950                 if (oblmap == null) {
9951                     initObliqueLucidaFontMap();
9952                 }
9953@@ -639,7 +639,7 @@ public class X11GraphicsEnvironment
9954         if (fontConfigDirs == null) {
9955             return;
9956         }
9957-        if (isLinux) {
9958+        if (isLinuxOrBSD) {
9959             fontConfigDirs.add(jreLibDirName+File.separator+"oblique-fonts");
9960         }
9961         fontdirs = (String[])fontConfigDirs.toArray(new String[0]);
9962diff -upr ../orig/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java ./jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java
9963--- ../orig/jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java       2009-01-27 15:45:49.000000000 -0500
9964+++ ./jdk/src/solaris/classes/sun/print/UnixPrintServiceLookup.java     2009-05-04 17:37:17.000000000 -0400
9965@@ -119,7 +119,11 @@ public class UnixPrintServiceLookup exte
9966     }
9967 
9968     static boolean isBSD() {
9969-        return osname.equals("Linux");
9970+       return (osname.equals("Linux") ||
9971+               osname.equals("FreeBSD") ||
9972+               osname.equals("Darwin") ||
9973+               osname.equals("NetBSD") ||
9974+               osname.equals("OpenBSD"));
9975     }
9976 
9977     static final int UNINITIALIZED = -1;
9978diff -upr ../orig/jdk/src/solaris/classes/sun/tools/attach/BsdAttachProvider.java ./jdk/src/solaris/classes/sun/tools/attach/BsdAttachProvider.java
9979--- ../orig/jdk/src/solaris/classes/sun/tools/attach/BsdAttachProvider.java     2009-05-04 18:32:16.000000000 -0400
9980+++ ./jdk/src/solaris/classes/sun/tools/attach/BsdAttachProvider.java   2009-05-04 17:37:15.000000000 -0400
9981@@ -54,31 +54,13 @@ public class BsdAttachProvider extends H
9982     public VirtualMachine attachVirtualMachine(String vmid)
9983         throws AttachNotSupportedException, IOException
9984     {
9985-        checkAttachPermission();
9986-
9987-        // AttachNotSupportedException will be thrown if the target VM can be determined
9988-        // to be not attachable.
9989-        testAttachable(vmid);
9990-
9991-        return new BsdVirtualMachine(this, vmid);
9992+        throw new AttachNotSupportedException("Attach not yet supported on BSD");
9993     }
9994 
9995     public VirtualMachine attachVirtualMachine(VirtualMachineDescriptor vmd)
9996         throws AttachNotSupportedException, IOException
9997     {
9998-        if (vmd.provider() != this) {
9999-            throw new AttachNotSupportedException("provider mismatch");
10000-        }
10001-        // To avoid re-checking if the VM if attachable, we check if the descriptor
10002-        // is for a hotspot VM - these descriptors are created by the listVirtualMachines
10003-        // implementation which only returns a list of attachable VMs.
10004-        if (vmd instanceof HotSpotVirtualMachineDescriptor) {
10005-            assert ((HotSpotVirtualMachineDescriptor)vmd).isAttachable();
10006-            checkAttachPermission();
10007-            return new BsdVirtualMachine(this, vmd.id());
10008-        } else {
10009-            return attachVirtualMachine(vmd.id());
10010-        }
10011+        throw new AttachNotSupportedException("Attach not yet supported on BSD");
10012     }
10013 
10014 }
10015diff -upr ../orig/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c ./jdk/src/solaris/demo/jvmti/hprof/hprof_md.c
10016--- ../orig/jdk/src/solaris/demo/jvmti/hprof/hprof_md.c 2009-01-27 15:45:49.000000000 -0500
10017+++ ./jdk/src/solaris/demo/jvmti/hprof/hprof_md.c       2009-05-04 17:37:17.000000000 -0400
10018@@ -33,7 +33,7 @@
10019 #include <sys/stat.h>
10020 #include <fcntl.h>
10021 
10022-#ifndef LINUX
10023+#if !defined(LINUX) && !defined(_ALLBSD_SOURCE)
10024 #include <procfs.h>
10025 #endif
10026 
10027@@ -76,7 +76,7 @@ md_sleep(unsigned seconds)
10028 void
10029 md_init(void)
10030 {
10031-#ifdef LINUX
10032+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
10033     /* No Hi-Res timer option? */
10034 #else
10035     if ( gdata->micro_state_accounting ) {
10036@@ -238,7 +238,7 @@ md_timeofday(void)
10037 jlong
10038 md_get_microsecs(void)
10039 {
10040-#ifdef LINUX
10041+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
10042     return (jlong)(md_timeofday() * (jlong)1000); /* Milli to micro */
10043 #else
10044     return (jlong)(gethrtime()/(hrtime_t)1000); /* Nano seconds to micro seconds */
10045@@ -256,7 +256,7 @@ md_get_timemillis(void)
10046 jlong
10047 md_get_thread_cpu_timemillis(void)
10048 {
10049-#ifdef LINUX
10050+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
10051     return md_timeofday();
10052 #else
10053     return (jlong)(gethrvtime()/1000); /* Nano seconds to milli seconds */
10054@@ -271,7 +271,7 @@ md_get_prelude_path(char *path, int path
10055     Dl_info dlinfo;
10056 
10057     libdir[0] = 0;
10058-#ifdef LINUX
10059+#if defined(LINUX) || defined(_ALLBSD_SOURCE)
10060     addr = (void*)&Agent_OnLoad;
10061 #else
10062     /* Just using &Agent_OnLoad will get the first external symbol with
10063diff -upr ../orig/jdk/src/solaris/hpi/include/interrupt.h ./jdk/src/solaris/hpi/include/interrupt.h
10064--- ../orig/jdk/src/solaris/hpi/include/interrupt.h     2009-01-27 15:45:49.000000000 -0500
10065+++ ./jdk/src/solaris/hpi/include/interrupt.h   2009-05-04 17:37:17.000000000 -0400
10066@@ -75,7 +75,7 @@ void intrDispatch(int interrupt, void *s
10067  *      N_INTERRUPTS  - The number of interrupt channels.  These
10068  *                      are numbered from 0 to (N_INTERRUPTS - 1).
10069  */
10070-#ifdef __linux__
10071+#if defined(__linux__) || defined(__FreeBSD__)
10072 #define       N_INTERRUPTS    NSIG    /* 0 to NSIG - 1*/
10073 #else
10074 #define N_INTERRUPTS    32      /* 0 to 31 */
10075@@ -111,6 +111,10 @@ void intrInitMD(void);
10076 #error signal.h has not been included?
10077 #endif
10078 
10079+#if defined(__FreeBSD__) && !defined(SA_SIGINFO)
10080+#error signal.h has not been included?
10081+#endif
10082+
10083 #ifdef SA_SIGINFO
10084 /* Thread implementation dependent interrupt dispatcher. */
10085 void intrDispatchMD(int sig, siginfo_t *info, void *uc);
10086diff -upr ../orig/jdk/src/solaris/hpi/include/largefile.h ./jdk/src/solaris/hpi/include/largefile.h
10087--- ../orig/jdk/src/solaris/hpi/include/largefile.h     2009-01-27 15:45:49.000000000 -0500
10088+++ ./jdk/src/solaris/hpi/include/largefile.h   2009-05-04 17:37:17.000000000 -0400
10089@@ -34,6 +34,10 @@
10090 #include "largefile_linux.h"
10091 #endif
10092 
10093+#ifdef _ALLBSD_SOURCE
10094+#include "largefile_bsd.h"
10095+#endif
10096+
10097 /*
10098  * Prototypes for wrappers that we define.  These wrapper functions
10099  * are low-level I/O routines that will use 64 bit versions if
10100diff -upr ../orig/jdk/src/solaris/hpi/include/largefile_bsd.h ./jdk/src/solaris/hpi/include/largefile_bsd.h
10101--- ../orig/jdk/src/solaris/hpi/include/largefile_bsd.h 2009-05-04 18:32:16.000000000 -0400
10102+++ ./jdk/src/solaris/hpi/include/largefile_bsd.h       2009-05-04 17:37:15.000000000 -0400
10103@@ -23,14 +23,28 @@
10104  * have any questions.
10105  */
10106 
10107-#ifndef _JAVASOFT_LINUX_LARGEFILE_SUPPORT_H_
10108-#define _JAVASOFT_LINUX_LARGEFILE_SUPPORT_H_
10109-
10110-/*
10111- * For building on glibc-2.0 we need to define stat64 here.
10112- */
10113+#ifndef _JAVASOFT_BSD_LARGEFILE_SUPPORT_H_
10114+#define _JAVASOFT_BSD_LARGEFILE_SUPPORT_H_
10115 
10116 #include <sys/types.h>
10117 #include <sys/stat.h>
10118 
10119-#endif /* _JAVASOFT_LINUX_LARGEFILE_SUPPORT_H_ */
10120+/* define compatibility macros */
10121+#define                off64_t         off_t
10122+#define                stat64          stat
10123+
10124+#define                F_SETLK64       F_SETLK
10125+#define                F_SETLKW64      F_SETLKW
10126+
10127+#define                lseek64         lseek
10128+#define                ftruncate64     ftruncate
10129+#define                open64          open
10130+#define                fstat64         fstat
10131+#define                flock64         flock
10132+#define                mmap64          mmap
10133+#define                fdatasync       fsync
10134+
10135+#define                pread64         pread
10136+#define                pwrite64        pwrite
10137+
10138+#endif /* _JAVASOFT_BSD_LARGEFILE_SUPPORT_H_ */
10139diff -upr ../orig/jdk/src/solaris/hpi/native_threads/include/threads_md.h ./jdk/src/solaris/hpi/native_threads/include/threads_md.h
10140--- ../orig/jdk/src/solaris/hpi/native_threads/include/threads_md.h     2009-01-27 15:45:49.000000000 -0500
10141+++ ./jdk/src/solaris/hpi/native_threads/include/threads_md.h   2009-05-04 17:37:17.000000000 -0400
10142@@ -36,6 +36,8 @@
10143 #define N_TRACED_REGS 12
10144 #elif i386
10145 #define N_TRACED_REGS 7
10146+#elif i586                     /* BSDNOTE: just in case */
10147+#define N_TRACED_REGS 7
10148 #elif amd64
10149 #define N_TRACED_REGS 15
10150 #elif ppc
10151@@ -51,10 +53,12 @@
10152 #define N_TRACED_REGS 32
10153 #endif
10154 
10155+#if !defined(_ALLBSD_SOURCE)
10156 /* Turn on if we want all java threads to be bound tolwps */
10157 /* #define BOUND_THREADS */
10158 /* Use /proc soln to stop lwps in place of siglwp soln */
10159 #define PROCLWP
10160+#endif
10161 
10162 /*
10163  * Thread C stack overflow check
10164@@ -132,7 +136,7 @@ struct sys_thread {
10165     lwpid_t lwpid;
10166 #endif
10167 
10168-#ifdef __linux__
10169+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
10170     void *sp;
10171 #else
10172     unsigned long  sp;   /* sp at time of last (native) thread switch */
10173@@ -186,12 +190,14 @@ struct sys_thread {
10174 
10175 #define SYS_THREAD_NULL         ((sys_thread_t *) 0)
10176 
10177+#if !defined(_ALLBSD_SOURCE)
10178 /*
10179  * following macro copied from sys/signal.h since inside #ifdef _KERNEL there.
10180  */
10181 #ifndef sigmask
10182 #define sigmask(n)      ((unsigned int)1 << (((n) - 1) & (32 - 1)))
10183 #endif
10184+#endif
10185 
10186 #ifdef __linux__
10187 extern thread_key_t intrJmpbufkey;
10188diff -upr ../orig/jdk/src/solaris/hpi/native_threads/src/condvar_md.c ./jdk/src/solaris/hpi/native_threads/src/condvar_md.c
10189--- ../orig/jdk/src/solaris/hpi/native_threads/src/condvar_md.c 2009-01-27 15:45:49.000000000 -0500
10190+++ ./jdk/src/solaris/hpi/native_threads/src/condvar_md.c       2009-05-04 17:37:17.000000000 -0400
10191@@ -58,7 +58,7 @@ condvarDestroy(condvar_t *condvar)
10192 {
10193     int err;
10194 
10195-#ifdef __linux__
10196+#ifdef USE_PTHREADS
10197     err = pthread_cond_destroy((cond_t *) &condvar->cond);
10198 #else
10199     err = cond_destroy((cond_t *) condvar);
10200diff -upr ../orig/jdk/src/solaris/hpi/native_threads/src/monitor_md.c ./jdk/src/solaris/hpi/native_threads/src/monitor_md.c
10201--- ../orig/jdk/src/solaris/hpi/native_threads/src/monitor_md.c 2009-01-27 15:45:49.000000000 -0500
10202+++ ./jdk/src/solaris/hpi/native_threads/src/monitor_md.c       2009-05-04 17:37:17.000000000 -0400
10203@@ -147,7 +147,7 @@ sysMonitorEnter(sys_thread_t *self, sys_
10204         mid->monitor_owner = self;
10205         mid->entry_count = 1;
10206         return SYS_OK;
10207-    } else if (err == EBUSY) { /* it's already locked */
10208+    } else if (err == EBUSY || err == EDEADLK) { /* it's already locked */
10209         if (mid->monitor_owner == self) {
10210             mid->entry_count++;
10211             return SYS_OK;
10212diff -upr ../orig/jdk/src/solaris/hpi/native_threads/src/sys_api_td.c ./jdk/src/solaris/hpi/native_threads/src/sys_api_td.c
10213--- ../orig/jdk/src/solaris/hpi/native_threads/src/sys_api_td.c 2009-01-27 15:45:49.000000000 -0500
10214+++ ./jdk/src/solaris/hpi/native_threads/src/sys_api_td.c       2009-05-04 17:37:17.000000000 -0400
10215@@ -39,6 +39,10 @@
10216 #include <sys/ioctl.h>
10217 #endif
10218 
10219+#ifdef __OpenBSD__
10220+#include <sys/ioctl.h>
10221+#endif
10222+
10223 #include <sys/socket.h>
10224 #include <setjmp.h>
10225 #include <signal.h>
10226@@ -57,6 +61,10 @@
10227 #error If there was no policy change, this could be a makefile error.
10228 #endif
10229 
10230+#if defined(_ALLBSD_SOURCE) && defined(NO_INTERRUPTIBLE_IO)
10231+#error If there was no policy change, this could be a makefile error.
10232+#endif
10233+
10234 #ifdef NO_INTERRUPTIBLE_IO
10235 #undef CLOSEIO
10236 #else
10237diff -upr ../orig/jdk/src/solaris/hpi/native_threads/src/threads_bsd.c ./jdk/src/solaris/hpi/native_threads/src/threads_bsd.c
10238--- ../orig/jdk/src/solaris/hpi/native_threads/src/threads_bsd.c        2009-05-04 18:32:16.000000000 -0400
10239+++ ./jdk/src/solaris/hpi/native_threads/src/threads_bsd.c      2009-05-04 17:37:15.000000000 -0400
10240@@ -23,79 +23,44 @@
10241  * have any questions.
10242  */
10243 
10244-/*
10245- * Implementation of HPI that can not be expressed with POSIX threads.
10246- * Note that even if you are building with USE_PTHREADS, we have to
10247- * explicitly undef it here because pthread.h and thread.h can not be
10248- * included in the same file, and this file needs only thread.h.
10249- */
10250-#undef USE_PTHREADS
10251+#ifdef __APPLE__
10252+
10253+/* We need the mach API, which must be be included before any other system includes.
10254+ * Additionally, java and mach both define thread_state_t, so temporarily redefine it. */
10255+#define thread_state_t mach_thread_state_t
10256+#include <mach/mach.h>
10257+#undef thread_state_t
10258+
10259+#endif
10260 
10261 #include "hpi_impl.h"
10262 #include "monitor_md.h"
10263 #include "threads_md.h"
10264 #include "np.h"
10265 
10266-#include <thread.h>
10267-#include <sys/lwp.h>
10268+#include <sys/types.h>
10269+#include <sys/sysctl.h>
10270+
10271+#include <pthread.h>
10272+#if defined(__FreeBSD__) || defined(__OpenBSD__)
10273+#include <pthread_np.h>
10274+#endif
10275+#ifdef __NetBSD__
10276+#include <errno.h>
10277+#define pthread_attr_get_np(a, b)   0
10278+#define pthread_suspend_all_np()    0
10279+#define pthread_resume_all_np()     0
10280+#endif
10281+
10282+#include <time.h>
10283+#include <string.h>
10284 #include <signal.h>
10285 #include <sys/signal.h>
10286 #include <sys/resource.h>
10287-#include <sys/procfs.h>
10288 #include <stdlib.h>
10289 #include <string.h>
10290-#include <fcntl.h>
10291 #include <errno.h>
10292 
10293-#include <sys/syscall.h>
10294-extern int syscall(int, ...);
10295-
10296-
10297-/*
10298- * Forward declarations.
10299- */
10300-static int  procfd;
10301-static void stop_lwps();
10302-static void clear_onproc_flags();
10303-static void restart_lwps();
10304-static void MakeProcName(register char *procname, register pid_t pid);
10305-static void GC_msec_sleep(int n);
10306-
10307-
10308-/*
10309- * Make sure that we link against a verion of libthread that has at least
10310- * the bug fixes and the interface for getting the stack from threads that
10311- * aren't on LWPs.  Otherwise we should exit with some informative message.
10312- */
10313-extern ulong_t __gettsp(thread_t);
10314-
10315-static const char * gettspMessage =
10316-"You must install a Bsd patch to run the native threads version of the\n"
10317-"Java runtime.  The green threads version will work without this patch.\n"
10318-"Please check the native threads release notes for more information.\n"
10319-"\n"
10320-"If you are embedding the VM in a native application, please make sure that\n"
10321-"the native application is linked with libthread.so (-lthread).\n"
10322-"\n"
10323-"Exiting.\n";
10324-
10325-static void
10326-checkForCorrectLibthread()
10327-{
10328-    if (&__gettsp == 0) {
10329-        fprintf(stderr, gettspMessage);
10330-        exit(1);
10331-    }
10332-}
10333-#ifdef __GNUC__
10334-static void checkForCorrectLibthread() __attribute__((constructor));
10335-#else
10336-#pragma init(checkForCorrectLibthread)
10337-#endif
10338-
10339-#pragma weak __gettsp
10340-
10341-
10342 /*
10343  * Suspend said thread.  Used to implement java.lang.Thread.suspend(),
10344  * which is deprecated.
10345@@ -103,10 +68,16 @@ static void checkForCorrectLibthread() _
10346 int
10347 np_suspend(sys_thread_t *tid)
10348 {
10349-    return thr_suspend(tid->sys_thread);
10350+#ifdef __APPLE__
10351+    if (thread_suspend(pthread_mach_thread_np(tid->sys_thread)) == KERN_SUCCESS)
10352+        return SYS_OK;
10353+    else
10354+        return SYS_ERR;
10355+#else
10356+    return pthread_suspend_np(tid->sys_thread);
10357+#endif
10358 }
10359 
10360-
10361 /*
10362  * Resume a suspended thread.  Used to implement java.lang.Thread.resume(),
10363  * which is deprecated.
10364@@ -114,7 +85,14 @@ np_suspend(sys_thread_t *tid)
10365 int
10366 np_continue(sys_thread_t *tid)
10367 {
10368-    return thr_continue(tid->sys_thread);
10369+#ifdef __APPLE__
10370+    if (thread_resume(pthread_mach_thread_np(tid->sys_thread)) == KERN_SUCCESS)
10371+        return SYS_OK;
10372+    else
10373+        return SYS_ERR;
10374+#else
10375+    return pthread_resume_np(tid->sys_thread);
10376+#endif
10377 }
10378 
10379 /*
10380@@ -127,26 +105,74 @@ void np_initialize_thread(sys_thread_t *
10381 
10382 
10383 /*
10384+ * Internal helper function to get stack information about specified thread.
10385+ */
10386+#ifdef __APPLE__
10387+static int
10388+get_stackinfo(pthread_t tid, void **addr, long *sizep)
10389+{
10390+    void *stacktop = pthread_get_stackaddr_np(tid);
10391+    *sizep = pthread_get_stacksize_np(tid);
10392+    *addr = stacktop - *sizep;
10393+
10394+    return (SYS_OK);
10395+}
10396+#elif defined(__OpenBSD__)
10397+static int
10398+get_stackinfo(pthread_t tid, void **addr, long *sizep)
10399+{
10400+    stack_t ss;
10401+
10402+    if (pthread_stackseg_np(tid, &ss) == 0) {
10403+        *addr = (void *)(ss.ss_sp) - ss.ss_size;
10404+        *sizep = (long)(ss.ss_size);
10405+        return SYS_OK;
10406+    } else {
10407+        return SYS_ERR; /* pthreads_stackseg_np failed. */
10408+    }
10409+}
10410+#else
10411+static int
10412+get_stackinfo(pthread_t tid, pthread_attr_t attr, void **addr, long *sizep)
10413+{
10414+    size_t s;
10415+    void  *p;
10416+    int    ret = SYS_ERR;
10417+
10418+    if (pthread_attr_get_np(tid, &attr) != 0)
10419+        goto err;
10420+    if (pthread_attr_getstackaddr(&attr, &p) != 0)
10421+        goto err;
10422+    if (pthread_attr_getstacksize(&attr, &s) != 0)
10423+        goto err;
10424+    *addr = p;
10425+    *sizep = s;
10426+    ret = SYS_OK;
10427+err:
10428+
10429+    return (ret);
10430+}
10431+#endif
10432+
10433+/*
10434  * Get the stack start address, and max stack size for the current thread.
10435  */
10436 int
10437 np_stackinfo(void **addr, long *size)
10438 {
10439-    stack_t stkseg;
10440+#if defined(__OpenBSD__) || defined(__APPLE__)
10441+    return(get_stackinfo(pthread_self(), addr, size));
10442+#else
10443+    pthread_attr_t attr;
10444+    int    ret = SYS_ERR;
10445 
10446-    if (thr_stksegment(&stkseg) == 0) {
10447-        *addr = (void *)(stkseg.ss_sp);
10448-        if (thr_main()) {
10449-            struct rlimit r;
10450-            getrlimit(RLIMIT_STACK, &r);
10451-            *size = (long)r.rlim_cur;
10452-        } else {
10453-            *size = (long)(stkseg.ss_size);
10454-        }
10455-        return SYS_OK;
10456-    } else {
10457-        return SYS_ERR; /* thr_stksegment failed. */
10458+    if (pthread_attr_init(&attr) == 0) {
10459+        ret = get_stackinfo(pthread_self(), attr, addr, size);
10460+        pthread_attr_destroy(&attr);
10461     }
10462+
10463+    return (ret);
10464+#endif
10465 }
10466 
10467 /*
10468@@ -155,309 +181,194 @@ np_stackinfo(void **addr, long *size)
10469 void
10470 np_profiler_init(sys_thread_t *tid)
10471 {
10472-    tid->lwp_id = _lwp_self();
10473 }
10474 
10475 int
10476 np_profiler_suspend(sys_thread_t *tid)
10477 {
10478-    return _lwp_suspend(tid->lwp_id);
10479+    return np_suspend(tid);
10480 }
10481 
10482 int
10483 np_profiler_continue(sys_thread_t *tid)
10484 {
10485-    return _lwp_continue(tid->lwp_id);
10486+    return np_continue(tid);
10487 }
10488 
10489 bool_t
10490 np_profiler_thread_is_running(sys_thread_t *tid)
10491 {
10492-    unsigned long sum = 0;
10493-    int i;
10494-    prstatus_t lwpstatus;
10495-    int lwpfd;
10496-    int res;
10497-
10498-    lwpfd = syscall(SYS_ioctl, procfd, PIOCOPENLWP, &(tid->lwp_id));
10499-    sysAssert(lwpfd >= 0);
10500-
10501- retry:
10502-    res = syscall(SYS_ioctl, lwpfd, PIOCSTATUS, &lwpstatus);
10503-    sysAssert(res >= 0);
10504-
10505-    if (!(lwpstatus.pr_flags & PR_STOPPED)) {
10506-        GC_msec_sleep(1);
10507-        goto retry;
10508-    }
10509-
10510-    close(lwpfd);
10511-
10512-#if   defined(sparc)
10513-    sum += lwpstatus.pr_reg[R_SP];
10514-    sum += lwpstatus.pr_reg[R_PC];
10515-
10516-    sum += lwpstatus.pr_reg[R_G1];
10517-    sum += lwpstatus.pr_reg[R_G2];
10518-    sum += lwpstatus.pr_reg[R_G3];
10519-    sum += lwpstatus.pr_reg[R_G4];
10520-
10521-    sum += lwpstatus.pr_reg[R_O0];
10522-    sum += lwpstatus.pr_reg[R_O1];
10523-    sum += lwpstatus.pr_reg[R_O2];
10524-    sum += lwpstatus.pr_reg[R_O3];
10525-    sum += lwpstatus.pr_reg[R_O4];
10526-    sum += lwpstatus.pr_reg[R_O5];
10527-
10528-    sum += lwpstatus.pr_reg[R_I0];
10529-    sum += lwpstatus.pr_reg[R_I1];
10530-    sum += lwpstatus.pr_reg[R_I2];
10531-    sum += lwpstatus.pr_reg[R_I3];
10532-    sum += lwpstatus.pr_reg[R_I4];
10533-    sum += lwpstatus.pr_reg[R_I5];
10534-    sum += lwpstatus.pr_reg[R_I6];
10535-    sum += lwpstatus.pr_reg[R_I7];
10536-
10537-    sum += lwpstatus.pr_reg[R_L0];
10538-    sum += lwpstatus.pr_reg[R_L1];
10539-    sum += lwpstatus.pr_reg[R_L2];
10540-    sum += lwpstatus.pr_reg[R_L3];
10541-    sum += lwpstatus.pr_reg[R_L4];
10542-    sum += lwpstatus.pr_reg[R_L5];
10543-    sum += lwpstatus.pr_reg[R_L6];
10544-    sum += lwpstatus.pr_reg[R_L7];
10545-#elif defined(amd64)
10546-    sum += lwpstatus.pr_reg[REG_RIP];
10547-    sum += lwpstatus.pr_reg[REG_RSP];
10548-
10549-    sum += lwpstatus.pr_reg[REG_RAX];
10550-    sum += lwpstatus.pr_reg[REG_RCX];
10551-    sum += lwpstatus.pr_reg[REG_RDX];
10552-    sum += lwpstatus.pr_reg[REG_RBX];
10553-    sum += lwpstatus.pr_reg[REG_RBP];
10554-    sum += lwpstatus.pr_reg[REG_RSI];
10555-    sum += lwpstatus.pr_reg[REG_RDI];
10556-
10557-    sum += lwpstatus.pr_reg[REG_R8];
10558-    sum += lwpstatus.pr_reg[REG_R9];
10559-    sum += lwpstatus.pr_reg[REG_R10];
10560-    sum += lwpstatus.pr_reg[REG_R11];
10561-    sum += lwpstatus.pr_reg[REG_R12];
10562-    sum += lwpstatus.pr_reg[REG_R13];
10563-    sum += lwpstatus.pr_reg[REG_R14];
10564-    sum += lwpstatus.pr_reg[REG_R15];
10565-#elif defined(i386)
10566-    sum += lwpstatus.pr_reg[EIP];
10567-    sum += lwpstatus.pr_reg[UESP];
10568-
10569-    sum += lwpstatus.pr_reg[EAX];
10570-    sum += lwpstatus.pr_reg[ECX];
10571-    sum += lwpstatus.pr_reg[EDX];
10572-    sum += lwpstatus.pr_reg[EBX];
10573-    sum += lwpstatus.pr_reg[EBP];
10574-    sum += lwpstatus.pr_reg[ESI];
10575-    sum += lwpstatus.pr_reg[EDI];
10576-#endif
10577-
10578-    if (tid->last_sum == sum) {
10579-        return FALSE;
10580-    }
10581-    tid->last_sum = sum;
10582-
10583     return TRUE;
10584 }
10585 
10586 
10587-/*
10588- * If building for Bsd native threads, open up the /proc file
10589- * descriptor to be used when doing GC. The open is done at JVM start-up so
10590- * as to reserve this fd, to prevent GC stall due to exhausted fds. This fd
10591- * will never be closed, and will alwyas be present.
10592- */
10593 int
10594 np_initialize()
10595 {
10596-    char procname[32];
10597-    MakeProcName(procname, getpid());
10598-    if ((procfd = open(procname, O_RDONLY, 0)) < 0) {
10599-        VM_CALL(jio_fprintf)(stderr, "Cannot open %s for GC", procname);
10600-        return SYS_ERR;
10601-    }
10602     return SYS_OK;
10603 }
10604 
10605-static void
10606-MakeProcName(register char *procname, register pid_t pid)
10607-{
10608-    register char * s;
10609+/* prototypes */
10610 
10611-    (void) strcpy(procname, "/proc/00000");
10612-    s = procname + strlen(procname);
10613-    while (pid) {
10614-        *--s = pid%10 + '0';
10615-        pid /= 10;
10616-    }
10617-}
10618+static void record_thread_regs();
10619 
10620 /*
10621  * Suspend all other threads, and record their contexts (register
10622  * set or stack pointer) into the sys_thread structure, so that a
10623  * garbage collect can be run.
10624  */
10625+#ifdef __APPLE__
10626 int
10627 np_single(void)
10628-{
10629-    int ret;
10630+{
10631+    sysAssert(SYS_QUEUE_LOCKED(sysThreadSelf()));
10632 
10633+    /* Iterate over all the threads in the task, suspending each one.
10634+     * We have to loop until no new threads appear, and all are suspended */
10635+    mach_port_t self = pthread_mach_thread_np(pthread_self());
10636+
10637+
10638+    mach_msg_type_number_t      cur_count, prev_count, i, j, k;
10639+    thread_act_array_t          cur_list, prev_list;
10640+    bool_t                      changes;
10641+
10642+    changes = TRUE;
10643+    cur_count = prev_count = 0;
10644+    cur_list = prev_list = NULL;
10645+    do {
10646+        /* Get a list of all threads */
10647+        if (task_threads(self, &cur_list, &cur_count) != KERN_SUCCESS)
10648+            return SYS_ERR;
10649+
10650+        /* For each thread, check if it was previously suspended. If it
10651+         * was not, suspend it now, and set the changes flag to 'true' */
10652+        changes = FALSE;
10653+        for (i = 0; i < cur_count; i++) {
10654+            mach_msg_type_number_t j;
10655+            bool_t found = FALSE;
10656+
10657+            /* Check the previous thread list */
10658+            for (j = 0; j < prev_count; j++) {
10659+                if (prev_list[j] == cur_list[i]) {
10660+                    found = TRUE;
10661+                    break;
10662+                }
10663+            }
10664+
10665+            /* If the thread wasn't previously suspended, suspend it now and set the change flag */
10666+            if (found) {
10667+                /* Don't suspend ourselves! */
10668+                if (cur_list[i] != self)
10669+                    thread_suspend(cur_list[i]);
10670+                changes = TRUE;
10671+            }
10672+        }
10673+       
10674+        /* Deallocate the previous list, if necessary */
10675+        for (k = 0; k < prev_count; k++)
10676+            mach_port_deallocate(self, prev_list[k]);
10677+
10678+        vm_deallocate(self, (vm_address_t)prev_list, sizeof(thread_t) * prev_count);
10679+
10680+        /* Set up the 'new' list for the next loop iteration */
10681+        prev_list = cur_list;
10682+        prev_count = cur_count;
10683+    } while (changes);
10684+
10685+    /* Deallocate the last-allocated list. */
10686+    for (i = 0; i < prev_count; i++)
10687+        mach_port_deallocate(self, prev_list[i]);
10688+
10689+    vm_deallocate(self, (vm_address_t)prev_list, sizeof(thread_t) * prev_count);
10690+
10691+    /* Record registers and return */
10692+    record_thread_regs();
10693+    return SYS_OK;
10694+}
10695+#else
10696+int
10697+np_single(void)
10698+{
10699     sysAssert(SYS_QUEUE_LOCKED(sysThreadSelf()));
10700 
10701-    stop_lwps();
10702-    ret = SYS_OK;
10703-    return ret;
10704+    pthread_suspend_all_np();
10705+    record_thread_regs();
10706+    return SYS_OK;
10707 }
10708+#endif
10709 
10710 /*
10711- * Continue threads suspended earlier.  But clear their context
10712- * recorded in sys_thread structure first.
10713+ * Continue threads suspended earlier.
10714  */
10715+#ifdef __APPLE__
10716 void
10717 np_multi(void)
10718 {
10719     sysAssert(SYS_QUEUE_LOCKED(sysThreadSelf()));
10720-    clear_onproc_flags();
10721-    restart_lwps();
10722-}
10723 
10724-/* /proc solution to stop and restrt lwps */
10725-/* make sure gc is run as a bound thread */
10726-/* make sure signals are turned off for gc thread */
10727-/* what about new lwps getting created in the meantime? */
10728-
10729-#define MAX_LWPS 1024
10730-
10731-static prstatus_t Mystatus;
10732-static id_t lwpid_list_buf[MAX_LWPS];
10733-static id_t oldlwpid_list_buf[MAX_LWPS];
10734-static sys_thread_t *onproct_list_buf[MAX_LWPS];
10735-static id_t *lwpid_list = lwpid_list_buf;
10736-static id_t *oldlwpid_list = oldlwpid_list_buf;
10737-static sys_thread_t **onproct_list = onproct_list_buf;
10738-static int lwpid_list_len;
10739-static int oldlwpid_list_len;
10740-static int onproct_ix = 0;
10741-static int gcprio;
10742-static sigset_t gcmask;
10743+    mach_msg_type_number_t      thr_count, i;
10744+    thread_act_array_t          thr_list;
10745+    mach_port_t                 self;
10746 
10747-static void
10748-clear_onproc_flags()
10749-{
10750-    int i;
10751+    self = pthread_mach_thread_np(pthread_self());
10752 
10753-    for (i = 0; i < onproct_ix; i++) {
10754-        ((sys_thread_t *)(onproct_list[i]))->onproc = FALSE;
10755-    }
10756-    onproct_ix = 0;
10757-}
10758+    /* Get a list of all threads. This has to succeed! */
10759+    if (task_threads(self, &thr_list, &thr_count) != KERN_SUCCESS)
10760+        abort();
10761 
10762+    /* Iterate over all the threads in the task, unsuspend, and deallocate */
10763+    for (i = 0; i < thr_count; i++) {
10764+        // XXXDARWIN: Assumes that the current thread was the thread used
10765+        // to call np_single. Is that true?
10766 
10767-/* Sleep for n milliseconds, n < 1000   */
10768-static void
10769-GC_msec_sleep(int n)
10770-{
10771-    struct timespec ts;
10772+        if (thr_list[i] != self)
10773+            thread_resume(thr_list[i]);
10774 
10775-    ts.tv_sec = 0;
10776-    ts.tv_nsec = 1000000*n;
10777-    if (syscall(SYS_nanosleep, &ts, 0) < 0) {
10778-        VM_CALL(jio_fprintf)(stderr, "%d\n", errno);
10779+        mach_port_deallocate(self, thr_list[i]);
10780     }
10781+
10782+    vm_deallocate(self, (vm_address_t) thr_list, sizeof(thread_t) * thr_count);
10783+}
10784+#else
10785+void
10786+np_multi(void)
10787+{
10788+    sysAssert(SYS_QUEUE_LOCKED(sysThreadSelf()));
10789+    pthread_resume_all_np();
10790 }
10791+#endif
10792 
10793 /*
10794+ * BSDNOTE: Looking to linux implementation -- the only important register
10795+ * to set up is tid->sp (stack pointer) now.  But it may change when
10796+ * FreeBSD and JVM will switch to KSEs.  In this case we'll also need to
10797+ * care about ucontext I think.
10798+ *
10799+ * --phantom
10800+ *
10801+ * XXXBSD: There's a problem with this implemenation. Currently it sets
10802+ * the tid->sp to the bottom of the thread stack and not the current stack
10803+ * pointer of the suspended thread. Both solaris and linux use the current
10804+ * thread stack pointer. -- kurt
10805+ *
10806  * Assumes stacks grow down from high to low memory. True on sparc and Intel.
10807  */
10808-#define VALID_SP(sp, bottom, top) \
10809-       (((uintptr_t)(sp)) < ((uintptr_t)(bottom)) && ((uintptr_t)(sp)) > ((uintptr_t)(top)))
10810-
10811-static void
10812-record_lwp_regs(prstatus_t lwpstatus)
10813-{
10814-    sys_thread_t *tid;
10815-    int i;
10816-#if   defined(sparc)
10817-    register uintptr_t sp = lwpstatus.pr_reg[R_SP];
10818-#elif defined(amd64)
10819-    register uintptr_t sp = lwpstatus.pr_reg[REG_RSP];
10820-#elif defined(i386)
10821-    register uintptr_t sp = lwpstatus.pr_reg[UESP];
10822-#endif
10823-
10824-    tid = ThreadQueue;
10825-    for (i = 0; i < ActiveThreadCount && tid != 0; i++) {
10826-        if (VALID_SP(sp, tid->stack_bottom, tid->stack_top)) {
10827-            long *regs = tid->regs;
10828-            tid->sp = sp;
10829-            /*
10830-             * The code below relies on N_TRACED_REGS being set
10831-             * correctly for each platform.  If you change the
10832-             * number of registers being watched, you should update
10833-             * the define for N_TRACED_REGS
10834-             */
10835-#if   defined(sparc)
10836-            regs[0] = lwpstatus.pr_reg[R_G1];
10837-            regs[1] = lwpstatus.pr_reg[R_G2];
10838-            regs[2] = lwpstatus.pr_reg[R_G3];
10839-            regs[3] = lwpstatus.pr_reg[R_G4];
10840-
10841-            regs[4] = lwpstatus.pr_reg[R_O0];
10842-            regs[5] = lwpstatus.pr_reg[R_O1];
10843-            regs[6] = lwpstatus.pr_reg[R_O2];
10844-            regs[7] = lwpstatus.pr_reg[R_O3];
10845-            regs[8] = lwpstatus.pr_reg[R_O4];
10846-            regs[9] = lwpstatus.pr_reg[R_O5];
10847-            regs[10] = lwpstatus.pr_reg[R_O6];
10848-            regs[11] = lwpstatus.pr_reg[R_O7];
10849-#elif defined(amd64)
10850-            regs[0] = lwpstatus.pr_reg[REG_RAX];
10851-            regs[1] = lwpstatus.pr_reg[REG_RCX];
10852-            regs[2] = lwpstatus.pr_reg[REG_RDX];
10853-            regs[3] = lwpstatus.pr_reg[REG_RBX];
10854-            regs[4] = lwpstatus.pr_reg[REG_RBP];
10855-            regs[5] = lwpstatus.pr_reg[REG_RSI];
10856-            regs[6] = lwpstatus.pr_reg[REG_RDI];
10857-            regs[7] = lwpstatus.pr_reg[REG_R8];
10858-            regs[8] = lwpstatus.pr_reg[REG_R9];
10859-            regs[9] = lwpstatus.pr_reg[REG_R10];
10860-            regs[10]= lwpstatus.pr_reg[REG_R11];
10861-            regs[11]= lwpstatus.pr_reg[REG_R12];
10862-            regs[12]= lwpstatus.pr_reg[REG_R13];
10863-            regs[13]= lwpstatus.pr_reg[REG_R14];
10864-            regs[14]= lwpstatus.pr_reg[REG_R15];
10865-#elif defined(i386)
10866-            regs[0] = lwpstatus.pr_reg[EAX];
10867-            regs[1] = lwpstatus.pr_reg[ECX];
10868-            regs[2] = lwpstatus.pr_reg[EDX];
10869-            regs[3] = lwpstatus.pr_reg[EBX];
10870-            regs[4] = lwpstatus.pr_reg[EBP];
10871-            regs[5] = lwpstatus.pr_reg[ESI];
10872-            regs[6] = lwpstatus.pr_reg[EDI];
10873-#endif
10874-
10875-            if (tid->onproc != TRUE) {
10876-                tid->onproc = TRUE;
10877-                onproct_list[onproct_ix++] = tid;
10878-            }
10879-            break;
10880-        }
10881-        tid = tid->next;
10882-    }
10883-}
10884 
10885 static void
10886 record_thread_regs()
10887 {
10888+    void *addr;
10889+    long sz;
10890+
10891     sys_thread_t *tid;
10892     int i;
10893+    int sp;
10894+
10895+#ifndef __OpenBSD__
10896+    pthread_attr_t attr;
10897+    int attr_inited;
10898+    attr_inited = pthread_attr_init(&attr) == 0;
10899+#endif
10900 
10901     tid = ThreadQueue;
10902     for (i = 0; i < ActiveThreadCount && tid != 0; i++) {
10903@@ -466,7 +377,14 @@ record_thread_regs()
10904 
10905             if (tid->sys_thread != 0) {
10906                 /* if thread has already been initialized */
10907-                tid->sp = __gettsp(tid->sys_thread);
10908+#if defined(__OpenBSD__) || defined(__APPLE__)
10909+            if (get_stackinfo(tid->sys_thread, &addr, &sz) == SYS_OK)
10910+#else
10911+            if (get_stackinfo(tid->sys_thread, attr, &addr, &sz) == SYS_OK)
10912+#endif
10913+                tid->sp = addr;
10914+            else
10915+                tid->sp = 0;
10916             } else {
10917                 /*
10918                  * thread is still in the process of being initalized.
10919@@ -475,192 +393,11 @@ record_thread_regs()
10920                  */
10921                 tid->sp = 0;
10922             }
10923-
10924-            /*
10925-             * Clear out the registers since they are no longer live
10926-             * and we don't want to garbage collector to think they are.
10927-             */
10928-
10929-            for (i = 0; i < N_TRACED_REGS; i++)
10930-                tid->regs[i] = 0;
10931         }
10932         tid = tid->next;
10933     }
10934-}
10935-
10936-static void
10937-wait_stopped_lwps(void)
10938-{
10939-    int i, lwpfd;
10940-    prstatus_t lwpstatus;
10941-
10942-    for (i = 0; i < (int) Mystatus.pr_nlwp; i++) {
10943-        /* if its  not me */
10944-        if (lwpid_list[i] != _lwp_self()) {
10945-
10946-            /* open the lwp and check the status */
10947-            if ((lwpfd = syscall(SYS_ioctl, procfd, PIOCOPENLWP,
10948-                &lwpid_list[i])) < 0) {
10949-#ifdef MY_DEBUG
10950-                VM_CALL(jio_fprintf)(stderr, "lwpid %d was not found in process\n",
10951-                            lwpid_list[i]);
10952+#ifndef __OpenBSD__
10953+    if (attr_inited)
10954+        pthread_attr_destroy(&attr);
10955 #endif
10956-                continue;
10957-            }
10958-            memset(&lwpstatus, 0, sizeof(lwpstatus));
10959-            while (1) {
10960-                if (syscall(SYS_ioctl,lwpfd, PIOCSTATUS, &lwpstatus)<0) {
10961-                    sysAssert(0);
10962-#ifdef MY_DEBUG
10963-                    VM_CALL(jio_fprintf)(stderr, "PIOCSTATUS failed for lwp %d",
10964-                                lwpid_list[i]);
10965-#endif
10966-                    break;
10967-                }
10968-                if (lwpstatus.pr_flags & PR_STOPPED) {
10969-                    record_lwp_regs(lwpstatus);
10970-                    break;
10971-                }
10972-                GC_msec_sleep(1);
10973-            }
10974-
10975-            close (lwpfd);
10976-        } /* end of if-me */
10977-    } /* end of for */
10978-}
10979-
10980-static void
10981-suspend_lwps()
10982-{
10983-    int i;
10984-    /* pioopen all the lwps and stop them - except the one I am running on */
10985-    for (i = 0; i < (int) Mystatus.pr_nlwp; i++) {
10986-
10987-        /* open and stop the lwp if its not me */
10988-        if (lwpid_list[i] != _lwp_self()) {
10989-
10990-            /* PIOCSTOP doesn't work without a writable         */
10991-            /* descriptor.  And that makes the process          */
10992-            /* undebuggable.                                    */
10993-            if (_lwp_suspend(lwpid_list[i]) < 0) {
10994-                        /* Could happen if the lwp exited */
10995-                lwpid_list[i] = _lwp_self();
10996-                continue;
10997-            }
10998-        }
10999-    }
11000-}
11001-
11002-static void
11003-print_lwps()
11004-{
11005-#ifdef MY_DEBUG
11006-    /* print all the lwps in the process */
11007-    VM_CALL(jio_fprintf)(stdout, "lwpids ");
11008-    for (i = 0; i < (int) Mystatus.pr_nlwp; i++) {
11009-        if (i == 0) {
11010-            VM_CALL(jio_fprintf)(stdout, "%d", lwpid_list[0]);
11011-        } else if (i != Mystatus.pr_nlwp - 1) {
11012-            VM_CALL(jio_fprintf)(stdout, ", %d", lwpid_list[i]);
11013-        } else {
11014-            VM_CALL(jio_fprintf)(stdout, " and %d", lwpid_list[i]);
11015-        }
11016-    }
11017-#endif
11018-}
11019-
11020-/* routine to iteratively stop all lwps */
11021-static void
11022-stop_lwps()
11023-{
11024-    int i;
11025-    sigset_t set;
11026-    boolean_t changed;
11027-
11028-    /* mask all signals */
11029-    (void) sigfillset(&set);
11030-    syscall(SYS_sigprocmask, SIG_SETMASK, &set, &gcmask);
11031-
11032-    /* run at highest prio so I cannot be preempted */
11033-    thr_getprio(thr_self(), &gcprio);
11034-    thr_setprio(thr_self(), 2147483647);  /* #define INT_MAX 2147483647 */
11035-
11036-    oldlwpid_list_len = 0;
11037-
11038-    while(1) {
11039-        changed = B_FALSE;
11040-
11041-        /* Get the # of lwps in the process */
11042-        memset(&Mystatus, 0, sizeof(Mystatus));
11043-        syscall(SYS_ioctl, procfd, PIOCSTATUS, &Mystatus);
11044-
11045-#ifdef MY_DEBUG
11046-        VM_CALL(jio_fprintf)(stdout, "Number of lwps in the process is %d\n",
11047-                    Mystatus.pr_nlwp);
11048-        VM_CALL(jio_fprintf)(stdout, "My lwp id is %d\n", _lwp_self());
11049-#endif
11050-        lwpid_list_len = Mystatus.pr_nlwp;
11051-        if (syscall(SYS_ioctl, procfd, PIOCLWPIDS, lwpid_list) == -1) {
11052-#ifdef MY_DEBUG
11053-            VM_CALL(jio_fprintf)(stderr, "Can't read proc's lwpid list");
11054-#endif
11055-            return;
11056-        }
11057-
11058-        print_lwps();
11059-
11060-        /* suspend all the lwps */
11061-        suspend_lwps();
11062-
11063-        /* make sure all the lwps have actually stopped */
11064-        wait_stopped_lwps();
11065-
11066-        /* make sure the list has not changed while you were not looking
11067-           else start all over again */
11068-        if (lwpid_list_len != oldlwpid_list_len) changed = B_TRUE;
11069-        else  {
11070-            for (i=0; i<lwpid_list_len; ++i) {
11071-                if (lwpid_list[i] != oldlwpid_list[i]) {
11072-                    changed = B_TRUE; break;
11073-                }
11074-            }
11075-        }
11076-        if (!changed) break;
11077-
11078-        {
11079-            id_t *tmplwpid_list = oldlwpid_list;
11080-            oldlwpid_list = lwpid_list; oldlwpid_list_len = lwpid_list_len;
11081-            lwpid_list = 0; lwpid_list_len = 0;
11082-            lwpid_list = tmplwpid_list;
11083-        }
11084-    }
11085-
11086-    /* record regs for threads that were not on LWPs */
11087-    record_thread_regs();
11088-
11089-    return;
11090-}
11091-
11092-
11093-/* Restart all lwps in process.  */
11094-static void
11095-restart_lwps()
11096-{
11097-    int i;
11098-
11099-    for (i = 0; i < Mystatus.pr_nlwp; i++) {
11100-        if (lwpid_list[i] == _lwp_self()) continue;
11101-        if (_lwp_continue(lwpid_list[i]) < 0) {
11102-#ifdef MY_DEBUG
11103-            VM_CALL(jio_fprintf)(stderr, "Failed to restart lwp %d\n",lwpid_list[i]);
11104-#endif
11105-        }
11106-    }
11107-
11108-    /* restore the old priority of the thread */
11109-    thr_setprio(thr_self(), gcprio);
11110-    /* restore the oldmask */
11111-    syscall(SYS_sigprocmask, SIG_SETMASK, &gcmask, NULL);
11112-
11113-    print_lwps();
11114 }
11115diff -upr ../orig/jdk/src/solaris/hpi/native_threads/src/threads_md.c ./jdk/src/solaris/hpi/native_threads/src/threads_md.c
11116--- ../orig/jdk/src/solaris/hpi/native_threads/src/threads_md.c 2009-01-27 15:45:49.000000000 -0500
11117+++ ./jdk/src/solaris/hpi/native_threads/src/threads_md.c       2009-05-04 17:37:17.000000000 -0400
11118@@ -54,6 +54,10 @@ extern int InitializeIO(rlim_t limit);
11119 #error That can NOT possibly be right.
11120 #endif
11121 
11122+#if defined(_ALLBSD_SOURCE) && !defined(SA_SIGINFO)
11123+#error That can NOT possibly be right.
11124+#endif
11125+
11126 #ifdef SA_SIGINFO
11127 static void sigusr1Handler(int sig, siginfo_t *info, void *uc);
11128 #else
11129@@ -97,9 +101,14 @@ static thread_key_t tid_key = (thread_ke
11130 #ifdef __linux__
11131 thread_key_t intrJmpbufkey;
11132 static sigset_t squm = {{sigmask(SIGUSR1), 0, 0, 0}};
11133+#elif defined(__OpenBSD__)
11134+thread_key_t sigusr1Jmpbufkey;
11135+sigset_t sigusr1Mask = sigmask(SIGUSR1);
11136+static sigset_t squm = sigmask(SIGUSR1);
11137 #else
11138 thread_key_t sigusr1Jmpbufkey;
11139 sigset_t sigusr1Mask = {{sigmask(SIGUSR1), 0, 0, 0}};
11140+static sigset_t squm = {{sigmask(SIGUSR1), 0, 0, 0}};
11141 #endif
11142 
11143 /*
11144@@ -170,9 +179,6 @@ sysThreadCheckStack()
11145     }
11146 }
11147 
11148-#ifndef __linux__
11149-static sigset_t squm = {{sigmask(SIGUSR1), 0, 0, 0}};
11150-#endif
11151 
11152 
11153 /*
11154@@ -187,7 +193,7 @@ sysThreadAlloc(sys_thread_t **tidP)
11155     if (tid == NULL) {
11156         return SYS_NOMEM;
11157     }
11158-#ifdef __linux__
11159+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
11160     memset((char *)tid, 0, sizeof(sys_thread_t));
11161 #endif
11162 
11163@@ -474,7 +480,7 @@ sysThreadCreate(sys_thread_t **tidP, lon
11164     }
11165     *tidP = tid;
11166 
11167-#ifdef __linux__
11168+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
11169     memset((char *)tid, 0, sizeof(sys_thread_t));
11170 #endif
11171     /* Install the backpointer to the Thread object */
11172@@ -517,6 +523,7 @@ sysThreadCreate(sys_thread_t **tidP, lon
11173     }
11174     /* Create the thread. The thread will block waiting to be suspended */
11175     err = pthread_create(&tid->sys_thread, &attr, _start, (void *)tid);
11176+    pthread_attr_destroy(&attr);
11177     sysAssert(err == 0);
11178     if (err == 0) {
11179         err = sem_wait(&tid->sem_suspended);
11180@@ -1049,7 +1056,18 @@ sysGetSysInfo()
11181          * we want the number of processors configured not the number online
11182          * since processors may be turned on and off dynamically.
11183          */
11184+#if defined(_SC_NPROCESSORS_CONF)
11185         int cpus = (int) sysconf(_SC_NPROCESSORS_CONF);
11186+#elif defined(CTL_HW) && defined(HW_NCPU)
11187+        int     cpus;
11188+        int     name[2] = { CTL_HW, HW_NCPU };
11189+        size_t  cpus_len = sizeof(cpus);
11190+
11191+        if (sysctl(name, 2, &cpus, &cpus_len, NULL, 0) == -1)
11192+               cpus = 1;
11193+#else
11194+        int cpus = 1;
11195+#endif
11196 
11197         info.isMP = (cpus < 0) ? 1 : (cpus > 1);
11198         info.name = "native threads";
11199diff -upr ../orig/jdk/src/solaris/hpi/src/linker_md.c ./jdk/src/solaris/hpi/src/linker_md.c
11200--- ../orig/jdk/src/solaris/hpi/src/linker_md.c 2009-01-27 15:45:49.000000000 -0500
11201+++ ./jdk/src/solaris/hpi/src/linker_md.c       2009-05-04 17:37:17.000000000 -0400
11202@@ -44,11 +44,19 @@
11203 #include "threads_md.h"
11204 #endif
11205 
11206+#ifdef __APPLE__
11207+#define LIB_SUFFIX "dylib"
11208+#else
11209+#define LIB_SUFFIX "so"
11210+#endif
11211+
11212+#ifndef _ALLBSD_SOURCE
11213 /*
11214  * This lock protects the dl wrappers, assuring that two threads aren't
11215  * in libdl at the same time.
11216  */
11217 sys_mon_t _dl_lock;
11218+#endif
11219 
11220 /*
11221  * glibc-2.0 libdl is not MT safe.  If you are building with any glibc,
11222@@ -66,6 +74,14 @@ sys_mon_t _dl_lock;
11223     #define NEED_DL_LOCK
11224 #endif
11225 
11226+#ifdef NEED_DL_LOCK
11227+/*
11228+ * This lock protects the dl wrappers, assuring that two threads aren't
11229+ * in libdl at the same time.
11230+ */
11231+sys_mon_t _dl_lock;
11232+#endif
11233+
11234 /*
11235  * create a string for the JNI native function name by adding the
11236  * appropriate decorations.
11237@@ -95,14 +111,14 @@ sysBuildLibName(char *holder, int holder
11238     }
11239 
11240     if (pnamelen == 0) {
11241-        sprintf(holder, "lib%s.so", fname);
11242+        sprintf(holder, "lib%s." LIB_SUFFIX, fname);
11243     } else {
11244-        sprintf(holder, "%s/lib%s.so", pname, fname);
11245+        sprintf(holder, "%s/lib%s." LIB_SUFFIX, pname, fname);
11246     }
11247 }
11248 
11249 
11250-#ifdef __linux__
11251+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
11252     static int thr_main(void)
11253     {
11254         return -1;
11255@@ -120,10 +136,10 @@ sysLoadLibrary(const char *name, char *e
11256 
11257 #ifdef NEED_DL_LOCK
11258     sysMonitorEnter(sysThreadSelf(), &_dl_lock);
11259-    result = dlopen(name, RTLD_NOW);
11260+    result = dlopen(name, RTLD_NOW|RTLD_GLOBAL);
11261     sysMonitorExit(sysThreadSelf(), &_dl_lock);
11262 #else
11263-    result = dlopen(name, RTLD_LAZY);
11264+    result = dlopen(name, RTLD_LAZY|RTLD_GLOBAL);
11265 #endif
11266     /*
11267      * This is a bit of bulletproofing to catch the commonly occurring
11268diff -upr ../orig/jdk/src/solaris/hpi/src/memory_md.c ./jdk/src/solaris/hpi/src/memory_md.c
11269--- ../orig/jdk/src/solaris/hpi/src/memory_md.c 2009-01-27 15:45:49.000000000 -0500
11270+++ ./jdk/src/solaris/hpi/src/memory_md.c       2009-05-04 17:37:17.000000000 -0400
11271@@ -50,12 +50,24 @@
11272 #include <stdlib.h>
11273 #include <stdio.h>      /* For perror() */
11274 #include <string.h>
11275+#if defined(_ALLBSD_SOURCE)
11276+#include <sys/param.h>
11277+#else
11278 #include <malloc.h>
11279+#endif
11280 
11281 #include "hpi_impl.h"
11282 
11283+#if defined(USE_MALLOC) && defined(_ALLBSD_SOURCE)
11284+#error "USE_MALLOC cannot be used for BSD"
11285+#endif
11286+
11287 #ifndef USE_MALLOC
11288 
11289+#if defined(_ALLBSD_SOURCE)
11290+#define MAP_ANNONYMOUS MAP_ANON
11291+#endif
11292+
11293 #include <sys/mman.h>
11294 #include <fcntl.h>
11295 #ifdef __linux__
11296@@ -73,6 +85,18 @@ static int devZeroFD;
11297 #define MAP_FAILED ((caddr_t)-1)
11298 #endif
11299 static size_t memGrainSize;     /* A page for Linux */
11300+#elif defined(_ALLBSD_SOURCE)
11301+static size_t memGrainSize;    /* A page for FreeBSD */
11302+#if defined(__FreeBSD__) && (__FreeBSD_version >= 700013)
11303+static inline void *
11304+memalign(size_t alignment, size_t size)
11305+{
11306+    void *ret;
11307+    return posix_memalign(&ret, alignment, size) ? NULL : ret;
11308+}
11309+#else /* ! __FreeBSD_version >= 700013 */
11310+#define memalign(a, b) valloc(b)
11311+#endif
11312 #else
11313 static unsigned int memGrainSize;       /* A page for Solaris */
11314 #endif
11315@@ -154,7 +178,7 @@ mapChunk(long length)
11316 {
11317     char *ret;
11318 
11319-#if defined(__linux__) && defined(MAP_ANONYMOUS)
11320+#if (defined(__linux__) || defined(_ALLBSD_SOURCE)) && defined(MAP_ANONYMOUS)
11321      ret = (char *) mmap(0, length, PROT_ALL,
11322                          MAP_NORESERVE | MAP_PRIVATE | MAP_ANONYMOUS,
11323                          -1, (off_t) 0);
11324@@ -176,7 +200,7 @@ static char *
11325 mapChunkReserve(char *addr, long length)
11326 {
11327     char *ret;
11328-#if defined(__linux__) && defined(MAP_ANONYMOUS)
11329+#if (defined(__linux__) || defined(_ALLBSD_SOURCE)) && defined(MAP_ANONYMOUS)
11330      ret = (char *) mmap(addr, length, PROT_ALL,
11331                          MAP_FIXED | MAP_PRIVATE | MAP_ANONYMOUS,
11332                          -1, (off_t) 0);
11333@@ -199,7 +223,7 @@ mapChunkNoreserve(char *addr, long lengt
11334 {
11335     char *ret;
11336 
11337-#if defined(__linux__) && defined(MAP_ANONYMOUS)
11338+#if (defined(__linux__) || defined(_ALLBSD_SOURCE)) && defined(MAP_ANONYMOUS)
11339      ret = (char *) mmap(addr, length, PROT_ALL,
11340                        MAP_FIXED | MAP_PRIVATE |
11341                          MAP_NORESERVE | MAP_ANONYMOUS,
11342@@ -242,7 +266,7 @@ sysMapMem(size_t requestedSize, size_t *
11343     *mappedSize = roundUpToGrain(requestedSize);
11344 #ifdef USE_MALLOC
11345     mappedAddr = (void *) sysMalloc(*mappedSize); /* Returns 0 on failure */
11346-#ifdef __linux__
11347+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
11348      if (mappedAddr) {
11349        memset(mappedAddr, 0, *mappedSize);
11350        mappedAddr = (void *) roundUpToGrain(mappedAddr);
11351@@ -331,7 +355,7 @@ sysCommitMem(void *requestedAddr, size_t
11352     *committedSize = roundUpToGrain(requestedSize);
11353     committedAddr = (void *) roundDownToGrain((long) requestedAddr);
11354 #ifdef USE_MALLOC
11355-#ifdef __linux__
11356+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
11357     ret = committedAddr;
11358 #else
11359     ret = requestedAddr;
11360diff -upr ../orig/jdk/src/solaris/hpi/src/system_md.c ./jdk/src/solaris/hpi/src/system_md.c
11361--- ../orig/jdk/src/solaris/hpi/src/system_md.c 2009-01-27 15:45:49.000000000 -0500
11362+++ ./jdk/src/solaris/hpi/src/system_md.c       2009-05-04 17:37:17.000000000 -0400
11363@@ -41,6 +41,7 @@
11364 #include <dlfcn.h>
11365 
11366 #include "jni_md.h"
11367+#include "jvm_md.h"
11368 #include "mutex_md.h"
11369 
11370 #include "hpi_init.h"
11371@@ -50,9 +51,6 @@
11372 #include "monitor_md.h"
11373 #include "largefile.h"
11374 
11375-
11376-#define O_DELETE 0x10000
11377-
11378 int sysThreadBootstrap(sys_thread_t **tidP, sys_mon_t **lockP, int nb)
11379 {
11380     threadBootstrapMD(tidP, lockP, nb);
11381@@ -85,7 +83,7 @@ sysGetMilliTicks()
11382 {
11383     struct timeval tv;
11384 
11385-    (void) gettimeofday(&tv, (void *) 0);
11386+    (void) gettimeofday(&tv, NULL);
11387     return((tv.tv_sec * 1000) + (tv.tv_usec / 1000));
11388 }
11389 
11390@@ -93,7 +91,7 @@ jlong
11391 sysTimeMillis()
11392 {
11393     struct timeval t;
11394-    gettimeofday(&t, 0);
11395+    gettimeofday(&t, NULL);
11396     return ((jlong)t.tv_sec) * 1000 + (jlong)(t.tv_usec/1000);
11397 }
11398 
11399@@ -122,13 +120,13 @@ sysGetLastErrorString(char *buf, int len
11400 
11401 /*
11402  * Open a file. Unlink the file immediately after open returns
11403- * if the specified oflag has the O_DELETE flag set.
11404+ * if the specified oflag has the JVM_O_DELETE flag set.
11405  */
11406 int sysOpen(const char *path, int oflag, int mode)
11407 {
11408     int fd;
11409-    int delete = (oflag & O_DELETE);
11410-    oflag = oflag & ~O_DELETE;
11411+    int delete = (oflag & JVM_O_DELETE);
11412+    oflag = oflag & ~JVM_O_DELETE;
11413     fd = open64_w(path, oflag, mode);
11414     if (delete != 0) {
11415         unlink(path);
11416diff -upr ../orig/jdk/src/solaris/instrument/EncodingSupport_md.c ./jdk/src/solaris/instrument/EncodingSupport_md.c
11417--- ../orig/jdk/src/solaris/instrument/EncodingSupport_md.c     2009-01-27 15:45:49.000000000 -0500
11418+++ ./jdk/src/solaris/instrument/EncodingSupport_md.c   2009-05-04 17:37:17.000000000 -0400
11419@@ -28,7 +28,10 @@
11420 #include <string.h>
11421 #include <ctype.h>
11422 #include <locale.h>
11423+#ifndef __OpenBSD__
11424+#define HAVE_NL_LANGINFO
11425 #include <langinfo.h>
11426+#endif
11427 #include <iconv.h>
11428 
11429 /* Routines to convert back and forth between Platform Encoding and UTF-8 */
11430@@ -63,6 +66,7 @@ utfInitialize(void)
11431     /* Set the locale from the environment */
11432     (void)setlocale(LC_ALL, "");
11433 
11434+#ifdef HAVE_NL_LANGINFO
11435     /* Get the codeset name */
11436     codeset = (char*)nl_langinfo(CODESET);
11437     if ( codeset == NULL || codeset[0] == 0 ) {
11438@@ -77,6 +81,9 @@ utfInitialize(void)
11439         UTF_DEBUG(("NO iconv() being used because it is not needed\n"));
11440         return;
11441     }
11442+#else
11443+    codeset = "ISO-8859-1";
11444+#endif
11445 
11446     /* Open conversion descriptors */
11447     iconvToPlatform   = iconv_open(codeset, "UTF-8");
11448diff -upr ../orig/jdk/src/solaris/javavm/export/jvm_md.h ./jdk/src/solaris/javavm/export/jvm_md.h
11449--- ../orig/jdk/src/solaris/javavm/export/jvm_md.h      2009-01-27 15:45:49.000000000 -0500
11450+++ ./jdk/src/solaris/javavm/export/jvm_md.h    2009-05-04 17:37:17.000000000 -0400
11451@@ -39,7 +39,14 @@
11452 #define JNI_ONUNLOAD_SYMBOLS {"JNI_OnUnload"}
11453 
11454 #define JNI_LIB_PREFIX "lib"
11455+#ifdef __APPLE__
11456+#define JNI_LIB_SUFFIX ".dylib"
11457+#define VERSIONED_JNI_LIB_NAME(NAME, VERSION) JNI_LIB_PREFIX NAME "." VERSION JNI_LIB_SUFFIX
11458+#else
11459 #define JNI_LIB_SUFFIX ".so"
11460+#define VERSIONED_JNI_LIB_NAME(NAME, VERSION) JNI_LIB_PREFIX NAME JNI_LIB_SUFFIX "." VERSION
11461+#endif
11462+#define JNI_LIB_NAME(NAME) JNI_LIB_PREFIX NAME JNI_LIB_SUFFIX
11463 
11464 #define JVM_MAXPATHLEN MAXPATHLEN
11465 
11466@@ -66,7 +73,7 @@
11467 #define JVM_O_O_APPEND   O_APPEND
11468 #define JVM_O_EXCL       O_EXCL
11469 #define JVM_O_CREAT      O_CREAT
11470-#define JVM_O_DELETE     0x10000
11471+#define JVM_O_DELETE     0x10000000
11472 
11473 /* Signals */
11474 
11475diff -upr ../orig/jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c ./jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c
11476--- ../orig/jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c  2009-01-27 15:45:49.000000000 -0500
11477+++ ./jdk/src/solaris/native/com/sun/management/UnixOperatingSystem_md.c        2009-05-04 17:37:17.000000000 -0400
11478@@ -32,10 +32,16 @@
11479 
11480 #include <sys/types.h>
11481 #include <sys/stat.h>
11482+#if defined(_ALLBSD_SOURCE)
11483+#include <sys/sysctl.h>
11484+#else
11485 #include <sys/swap.h>
11486+#endif
11487 #include <sys/resource.h>
11488 #include <sys/times.h>
11489+#ifndef _ALLBSD_SOURCE
11490 #include <sys/sysinfo.h>
11491+#endif
11492 #include <ctype.h>
11493 #include <dirent.h>
11494 #include <errno.h>
11495@@ -46,16 +52,22 @@
11496 
11497 static jlong page_size = 0;
11498 
11499+#if defined(_ALLBSD_SOURCE)
11500+#define MB     (1024UL * 1024UL)
11501+#else
11502+
11503 /* This gets us the new structured proc interfaces of 5.6 & later */
11504 /* - see comment in <sys/procfs.h> */
11505 #define _STRUCTURED_PROC 1
11506 #include <sys/procfs.h>
11507 
11508+#endif /* _ALLBSD_SOURCE */
11509+
11510 static struct dirent* read_dir(DIR* dirp, struct dirent* entry) {
11511 #ifdef __solaris__
11512     struct dirent* dbuf = readdir(dirp);
11513     return dbuf;
11514-#else /* __linux__ */
11515+#else /* __linux__ || _ALLBSD_SOURCE */
11516     struct dirent* p;
11517     if (readdir_r(dirp, entry, &p) == 0) {
11518         return p;
11519@@ -124,7 +136,7 @@ static jlong get_total_or_available_swap
11520     free(strtab);
11521     return available ? ((jlong)avail * page_size) :
11522                        ((jlong)total * page_size);
11523-#else /* __linux__ */
11524+#elif defined(__linux__)
11525     int ret;
11526     FILE *fp;
11527     jlong total = 0, avail = 0;
11528@@ -138,6 +150,13 @@ static jlong get_total_or_available_swap
11529     avail = (jlong)si.freeswap * si.mem_unit;
11530 
11531     return available ? avail : total;
11532+#else /* _ALLBSD_SOURCE */
11533+    /*
11534+     * XXXBSD: there's no way available to get swap info in
11535+     *         FreeBSD.  Usage of libkvm is not an option here
11536+     */
11537+    // throw_internal_error(env, "Unimplemented in FreeBSD");
11538+    return (0);
11539 #endif
11540 }
11541 
11542@@ -179,7 +198,7 @@ Java_com_sun_management_UnixOperatingSys
11543 
11544     JVM_Close(fd);
11545     return (jlong) psinfo.pr_size * 1024;
11546-#else /* __linux__ */
11547+#elif defined(__linux__)
11548     FILE *fp;
11549     unsigned long vsize = 0;
11550 
11551@@ -197,6 +216,12 @@ Java_com_sun_management_UnixOperatingSys
11552 
11553     fclose(fp);
11554     return (jlong)vsize;
11555+#else /* _ALLBSD_SOURCE */
11556+    /*
11557+     * XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
11558+     */
11559+    // throw_internal_error(env, "Unimplemented in FreeBSD");
11560+    return (64 * MB);
11561 #endif
11562 }
11563 
11564@@ -222,9 +247,13 @@ Java_com_sun_management_UnixOperatingSys
11565     jlong cpu_time_ns;
11566     struct tms time;
11567 
11568-#ifdef __solaris__
11569+    /*
11570+     * BSDNOTE: FreeBSD implements _SC_CLK_TCK since FreeBSD 5, so
11571+     *          add a magic to handle it
11572+     */
11573+#if defined(__solaris__) || defined(_SC_CLK_TCK)
11574     clk_tck = (jlong) sysconf(_SC_CLK_TCK);
11575-#else /* __linux__ */
11576+#elif defined(__linux__) || defined(_ALLBSD_SOURCE)
11577     clk_tck = 100;
11578 #endif
11579     if (clk_tck == -1) {
11580@@ -244,22 +273,51 @@ JNIEXPORT jlong JNICALL
11581 Java_com_sun_management_UnixOperatingSystem_getFreePhysicalMemorySize
11582   (JNIEnv *env, jobject mbean)
11583 {
11584+#ifdef _ALLBSD_SOURCE
11585+    /*
11586+     * XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
11587+     */
11588+    // throw_internal_error(env, "Unimplemented in FreeBSD");
11589+    return (128 * MB);
11590+#else
11591     jlong num_avail_physical_pages = sysconf(_SC_AVPHYS_PAGES);
11592     return (num_avail_physical_pages * page_size);
11593+#endif
11594 }
11595 
11596 JNIEXPORT jlong JNICALL
11597 Java_com_sun_management_UnixOperatingSystem_getTotalPhysicalMemorySize
11598   (JNIEnv *env, jobject mbean)
11599 {
11600+#ifdef _ALLBSD_SOURCE
11601+    jlong result;
11602+    int mib[2];
11603+    int rlen;
11604+
11605+    mib[0] = CTL_HW;
11606+    mib[1] = HW_PHYSMEM;
11607+    rlen = sizeof(result);
11608+    if (sysctl(mib, 2, &result, &rlen, NULL, 0) == -1)
11609+       result = 256 * MB;
11610+
11611+    return (result);
11612+#else
11613     jlong num_physical_pages = sysconf(_SC_PHYS_PAGES);
11614     return (num_physical_pages * page_size);
11615+#endif
11616 }
11617 
11618 JNIEXPORT jlong JNICALL
11619 Java_com_sun_management_UnixOperatingSystem_getOpenFileDescriptorCount
11620   (JNIEnv *env, jobject mbean)
11621 {
11622+#ifdef _ALLBSD_SOURCE
11623+    /*
11624+     * XXXBSD: there's no way available to do it in FreeBSD, AFAIK.
11625+     */
11626+    // throw_internal_error(env, "Unimplemented in FreeBSD");
11627+    return (100);
11628+#else /* solaris/linux */
11629     DIR *dirp;
11630     struct dirent dbuf;
11631     struct dirent* dentp;
11632@@ -282,6 +340,7 @@ Java_com_sun_management_UnixOperatingSys
11633     closedir(dirp);
11634     // subtract by 1 which was the fd open for this implementation
11635     return (fds - 1);
11636+#endif
11637 }
11638 
11639 JNIEXPORT jlong JNICALL
11640diff -upr ../orig/jdk/src/solaris/native/java/io/UnixFileSystem_md.c ./jdk/src/solaris/native/java/io/UnixFileSystem_md.c
11641--- ../orig/jdk/src/solaris/native/java/io/UnixFileSystem_md.c  2009-01-27 15:45:50.000000000 -0500
11642+++ ./jdk/src/solaris/native/java/io/UnixFileSystem_md.c        2009-05-06 10:46:09.000000000 -0400
11643@@ -41,6 +41,11 @@
11644 #include "java_io_FileSystem.h"
11645 #include "java_io_UnixFileSystem.h"
11646 
11647+#if defined(_ALLBSD_SOURCE)
11648+#define dirent64 dirent
11649+#define readdir64_r readdir_r
11650+#define stat64 stat
11651+#endif
11652 
11653 /* -- Field IDs -- */
11654 
11655@@ -58,7 +63,7 @@ Java_java_io_UnixFileSystem_initIDs(JNIE
11656                                   "path", "Ljava/lang/String;");
11657 }
11658 
11659-
11660+#ifndef _ALLBSD_SOURCE
11661 /* -- Large-file support -- */
11662 
11663 /* LINUX_FIXME: ifdef __solaris__ here is wrong.  We need to move the
11664@@ -98,6 +103,7 @@ struct  stat64 {
11665 };
11666 
11667 #endif  /* !_LFS_LARGEFILE */
11668+#endif /* !_ALLBSD_SOURCE */
11669 
11670 typedef int (*STAT64)(const char *, struct stat64 *);
11671 
11672@@ -107,6 +113,7 @@ static STAT64 stat64_ptr = &stat64;
11673 static STAT64 stat64_ptr = NULL;
11674 #endif
11675 
11676+#ifndef _ALLBSD_SOURCE
11677 #ifndef __linux__
11678 #ifdef __GNUC__
11679 static void init64IO(void) __attribute__((constructor));
11680@@ -120,7 +127,7 @@ static void init64IO(void) {
11681     stat64_ptr = (STAT64) dlsym(handle, "_stat64");
11682     dlclose(handle);
11683 }
11684-
11685+#endif /* !_ALLBSD_SOURCE */
11686 
11687 /* -- Path operations -- */
11688 
11689@@ -483,7 +490,7 @@ Java_java_io_UnixFileSystem_setLastModif
11690 #endif
11691 
11692         /* Preserve access time */
11693-#ifdef __linux__
11694+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
11695         struct stat sb;
11696 
11697         if (stat(path, &sb) == 0) {
11698diff -upr ../orig/jdk/src/solaris/native/java/io/canonicalize_md.c ./jdk/src/solaris/native/java/io/canonicalize_md.c
11699--- ../orig/jdk/src/solaris/native/java/io/canonicalize_md.c    2009-01-27 15:45:50.000000000 -0500
11700+++ ./jdk/src/solaris/native/java/io/canonicalize_md.c  2009-05-04 17:37:17.000000000 -0400
11701@@ -33,7 +33,9 @@
11702 #include <sys/stat.h>
11703 #include <errno.h>
11704 #include <limits.h>
11705+#if !defined(_ALLBSD_SOURCE)
11706 #include <alloca.h>
11707+#endif
11708 
11709 
11710 /* Note: The comments in this file use the terminology
11711diff -upr ../orig/jdk/src/solaris/native/java/io/io_util_md.c ./jdk/src/solaris/native/java/io/io_util_md.c
11712--- ../orig/jdk/src/solaris/native/java/io/io_util_md.c 2009-01-27 15:45:50.000000000 -0500
11713+++ ./jdk/src/solaris/native/java/io/io_util_md.c       2009-05-04 17:37:17.000000000 -0400
11714@@ -36,7 +36,7 @@ fileOpen(JNIEnv *env, jobject this, jstr
11715     WITH_PLATFORM_STRING(env, path, ps) {
11716         FD fd;
11717 
11718-#ifdef __linux__
11719+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
11720         /* Remove trailing slashes, since the kernel won't */
11721         char *p = (char *)ps + strlen(ps) - 1;
11722         while ((p > ps) && (*p == '/'))
11723diff -upr ../orig/jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c ./jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c
11724--- ../orig/jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c    2009-01-27 15:45:50.000000000 -0500
11725+++ ./jdk/src/solaris/native/java/lang/ProcessEnvironment_md.c  2009-05-04 17:37:17.000000000 -0400
11726@@ -28,6 +28,11 @@
11727 #include "jni.h"
11728 #include "jni_util.h"
11729 
11730+#ifdef __APPLE__
11731+#include <crt_externs.h>
11732+#define environ (*_NSGetEnviron())
11733+#endif
11734+
11735 JNIEXPORT jobjectArray JNICALL
11736 Java_java_lang_ProcessEnvironment_environ(JNIEnv *env, jclass ign)
11737 {
11738@@ -37,7 +42,9 @@ Java_java_lang_ProcessEnvironment_enviro
11739      * no standard (not even de-facto) header file where the
11740      * declaration is to be found.  See:
11741      * http://www.opengroup.org/onlinepubs/007908799/xbd/envvar.html */
11742+#ifndef __APPLE__
11743     extern char ** environ; /* environ[i] looks like: VAR=VALUE\0 */
11744+#endif
11745 
11746     jsize count = 0;
11747     jsize i, j;
11748@@ -46,7 +53,7 @@ Java_java_lang_ProcessEnvironment_enviro
11749 
11750     for (i = 0; environ[i]; i++) {
11751         /* Ignore corrupted environment variables */
11752-        if (strchr(environ[i], '=') != NULL)
11753+        if (strchr(environ[i], '=') != NULL && *environ[i] != '=')
11754             count++;
11755     }
11756 
11757@@ -56,7 +63,7 @@ Java_java_lang_ProcessEnvironment_enviro
11758     for (i = 0, j = 0; environ[i]; i++) {
11759         const char * varEnd = strchr(environ[i], '=');
11760         /* Ignore corrupted environment variables */
11761-        if (varEnd != NULL) {
11762+        if (varEnd != NULL && varEnd != environ[i]) {
11763             jbyteArray var, val;
11764             const char * valBeg = varEnd + 1;
11765             jsize varLength = varEnd - environ[i];
11766diff -upr ../orig/jdk/src/solaris/native/java/lang/UNIXProcess_md.c ./jdk/src/solaris/native/java/lang/UNIXProcess_md.c
11767--- ../orig/jdk/src/solaris/native/java/lang/UNIXProcess_md.c   2009-01-27 15:45:50.000000000 -0500
11768+++ ./jdk/src/solaris/native/java/lang/UNIXProcess_md.c 2009-05-04 17:37:17.000000000 -0400
11769@@ -40,7 +40,11 @@
11770 #include <stdlib.h>
11771 #include <sys/types.h>
11772 #include <ctype.h>
11773+#ifdef _ALLBSD_SOURCE
11774+#include <sys/wait.h>
11775+#else
11776 #include <wait.h>
11777+#endif
11778 #include <signal.h>
11779 #include <string.h>
11780 #include <errno.h>
11781@@ -49,6 +53,17 @@
11782 #include <fcntl.h>
11783 #include <limits.h>
11784 
11785+#ifdef __FreeBSD__
11786+#include <dlfcn.h>
11787+#include <pthread.h>
11788+#include <pthread_np.h>
11789+#endif
11790+
11791+#ifdef __APPLE__
11792+#include <crt_externs.h>
11793+#define environ (*_NSGetEnviron())
11794+#endif
11795+
11796 #ifndef STDIN_FILENO
11797 #define STDIN_FILENO 0
11798 #endif
11799@@ -259,11 +274,89 @@ Java_java_lang_UNIXProcess_waitForProces
11800     }
11801 }
11802 
11803+#if defined(__FreeBSD__)
11804+
11805+extern pid_t   __sys_fork(void);
11806+
11807+static pid_t
11808+jdk_fork_wrapper()
11809+{
11810+    pid_t resultPid;
11811+    typedef void (*void_func)();
11812+    static void_func func_defer = NULL;
11813+    static void_func func_undefer = NULL;
11814+    static int is_libc_r = -1;
11815+
11816+    if (is_libc_r == -1) {
11817+
11818+       /*
11819+         * BSDNOTE: Check for loaded symbols.
11820+         *
11821+         * If "_thread_kern_sig_defer" symbol is found assume we are
11822+        * libc_r
11823+         *
11824+         * If libc_r is loaded, use fork system call drectly to avoid
11825+         * problems with using protected pages.
11826+         *
11827+         * --phantom
11828+        */
11829+       func_defer =
11830+               (void_func)dlsym(RTLD_DEFAULT, "_thread_kern_sig_defer");
11831+       func_undefer =
11832+               (void_func)dlsym(RTLD_DEFAULT, "_thread_kern_sig_undefer");
11833+       if (func_defer != NULL)
11834+           is_libc_r = 1;
11835+       else {
11836+           is_libc_r = 0;
11837+       }
11838+    }
11839+
11840+    if (is_libc_r == 0) {
11841+       /* Not a libc_r */
11842+       resultPid = fork();
11843+    } else {
11844+        (*func_defer)();               /* call _thread_kern_sig_defer() */
11845+        resultPid = __sys_fork();
11846+        if (resultPid != 0)
11847+           (*func_undefer)();          /* call _thread_kern_sig_undefer() */
11848+       /* leave child with signals disabled, but reenable in parent */
11849+    }
11850+
11851+    return resultPid;
11852+}
11853+#endif /* __FreeBSD__ */
11854+
11855+#if defined(__OpenBSD__)
11856+/*
11857+ * Directly call _thread_sys_closefrom() so the child process
11858+ * doesn't reset the parrent's file descriptors to be blocking.
11859+ * This function is only called from the child process which
11860+ * is single threaded and about to call execvp() so it is
11861+ * safe to bypass the threaded closefrom().
11862+ */
11863+int _thread_sys_closefrom(int);
11864+
11865+static int
11866+closeDescriptors(void)
11867+{
11868+    return _thread_sys_closefrom(FAIL_FILENO + 1);
11869+}
11870+
11871+#else
11872+
11873+#ifdef _ALLBSD_SOURCE                                                         
11874+#define FD_DIR "/dev/fd"
11875+#else
11876+#define dirent dirent64                                                       
11877+#define readdir readdir64                                                     
11878+#define FD_DIR "/proc/self/fd"
11879+#endif
11880+
11881 static int
11882 closeDescriptors(void)
11883 {
11884     DIR *dp;
11885-    struct dirent64 *dirp;
11886+    struct dirent *dirp;
11887     int from_fd = FAIL_FILENO + 1;
11888 
11889     /* We're trying to close all file descriptors, but opendir() might
11890@@ -276,13 +369,13 @@ closeDescriptors(void)
11891     close(from_fd);             /* for possible use by opendir() */
11892     close(from_fd + 1);         /* another one for good luck */
11893 
11894-    if ((dp = opendir("/proc/self/fd")) == NULL)
11895+    if ((dp = opendir(FD_DIR)) == NULL)
11896         return 0;
11897 
11898     /* We use readdir64 instead of readdir to work around Solaris bug
11899      * 6395699: /proc/self/fd fails to report file descriptors >= 1024 on Solaris 9
11900      */
11901-    while ((dirp = readdir64(dp)) != NULL) {
11902+    while ((dirp = readdir(dp)) != NULL) {
11903         int fd;
11904         if (isdigit(dirp->d_name[0]) &&
11905             (fd = strtol(dirp->d_name, NULL, 10)) >= from_fd + 2)
11906@@ -293,6 +386,7 @@ closeDescriptors(void)
11907 
11908     return 1;
11909 }
11910+#endif /* !__OpenBSD__ */
11911 
11912 static void
11913 moveDescriptor(int fd_from, int fd_to)
11914@@ -438,7 +532,9 @@ execvpe(const char *file, const char *co
11915      * "All identifiers in this volume of IEEE Std 1003.1-2001, except
11916      * environ, are defined in at least one of the headers" (!)
11917      */
11918+#ifndef __APPLE__
11919     extern char **environ;
11920+#endif
11921 
11922     if (envp != NULL)
11923         environ = (char **) envp;
11924@@ -502,10 +598,15 @@ readFully(int fd, void *buf, size_t nbyt
11925     }
11926 }
11927 
11928+#if defined(__FreeBSD__)
11929+#undef fork1
11930+#define fork1() jdk_fork_wrapper()
11931+#else
11932 #ifndef __solaris__
11933 #undef fork1
11934 #define fork1() fork()
11935 #endif
11936+#endif
11937 
11938 JNIEXPORT jint JNICALL
11939 Java_java_lang_UNIXProcess_forkAndExec(JNIEnv *env,
11940@@ -567,6 +668,30 @@ Java_java_lang_UNIXProcess_forkAndExec(J
11941     if (resultPid == 0) {
11942         /* Child process */
11943 
11944+
11945+#ifdef __OpenBSD__
11946+// XXXBSD: Work-around userland pthread implementation issue.
11947+// Closing file descriptors will reset them to be blocking.
11948+// This is problematic for the parent when it attemts to use
11949+// the blocking fd and deadlocks. Setting them to non-blocking
11950+// in the child prevents the close/dup2 from resetting them.
11951+    {
11952+ int flags;
11953+ flags = fcntl(STDIN_FILENO, F_GETFL, NULL);
11954+ if (flags != -1)
11955+     fcntl(STDIN_FILENO, F_SETFL, flags | O_NONBLOCK);
11956+
11957+ flags = fcntl(STDOUT_FILENO, F_GETFL, NULL);
11958+ if (flags != -1)
11959+     fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK);
11960+
11961+ flags = fcntl(STDERR_FILENO, F_GETFL, NULL);
11962+ if (flags != -1)
11963+     fcntl(STDOUT_FILENO, F_SETFL, flags | O_NONBLOCK);
11964+    }
11965+#endif
11966+
11967+
11968         /* Close the parent sides of the pipe.
11969            Give the child sides of the pipes the right fileno's.
11970            Closing pipe fds here is redundant, since closeDescriptors()
11971diff -upr ../orig/jdk/src/solaris/native/java/lang/java_props_md.c ./jdk/src/solaris/native/java/lang/java_props_md.c
11972--- ../orig/jdk/src/solaris/native/java/lang/java_props_md.c    2009-01-27 15:45:50.000000000 -0500
11973+++ ./jdk/src/solaris/native/java/lang/java_props_md.c  2009-05-04 17:37:17.000000000 -0400
11974@@ -23,7 +23,7 @@
11975  * have any questions.
11976  */
11977 
11978-#ifdef __linux__
11979+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
11980 #include <stdio.h>
11981 #include <ctype.h>
11982 #endif
11983@@ -42,9 +42,17 @@
11984 #include <time.h>
11985 #include <errno.h>
11986 
11987+#if defined(_ALLBSD_SOURCE)
11988+#if !defined(P_tmpdir)
11989+#include <paths.h>
11990+#define P_tmpdir _PATH_VARTMP
11991+#endif
11992+#endif
11993+
11994 #include "locale_str.h"
11995 #include "java_props.h"
11996 
11997+#if !defined(_ALLBSD_SOURCE)
11998 #ifdef __linux__
11999 #define CODESET _NL_CTYPE_CODESET_NAME
12000 #else
12001@@ -52,6 +60,7 @@
12002 #define CODESET ALT_CODESET_KEY
12003 #endif
12004 #endif
12005+#endif /* !_ALLBSD_SOURCE */
12006 
12007 /* Take an array of string pairs (map of key->value) and a string (key).
12008  * Examine each pair in the map to see if the first string (key) matches the
12009@@ -188,7 +197,12 @@ GetJavaProperties(JNIEnv *env)
12010     {
12011         char *lc;
12012         lc = setlocale(LC_CTYPE, "");
12013-#ifndef __linux__
12014+#if defined(_ALLBSD_SOURCE)
12015+       if (lc == NULL) {
12016+           lc = "C";
12017+       }
12018+       {
12019+#elif !defined(__linux__)
12020         if (lc == NULL) {
12021             /*
12022              * 'lc == null' means system doesn't support user's environment
12023@@ -219,7 +233,7 @@ GetJavaProperties(JNIEnv *env)
12024             char *p, encoding_variant[64];
12025             int i, found;
12026 
12027-#ifndef __linux__
12028+#if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
12029             /*
12030              * Workaround for Solaris bug 4201684: Xlib doesn't like @euro
12031              * locales. Since we don't depend on the libc @euro behavior,
12032@@ -236,6 +250,13 @@ GetJavaProperties(JNIEnv *env)
12033                 *p = '\0';
12034             setlocale(LC_ALL, temp);
12035 #endif
12036+           if (lc == NULL) {
12037+               strncpy(temp, "C", sizeof(temp)-1);
12038+               temp[sizeof(temp)-1] = '\0';
12039+           } else {
12040+               strncpy(temp, lc, sizeof(temp)-1);
12041+               temp[sizeof(temp)-1] = '\0';
12042+           }
12043 
12044             strcpy(temp, lc);
12045 
12046@@ -316,6 +337,9 @@ GetJavaProperties(JNIEnv *env)
12047             else
12048                 p = nl_langinfo(CODESET);
12049 
12050+           if (p == NULL || !strcmp(p, "C") || !strcmp(p, "US-ASCII"))
12051+               p = ""; // use default
12052+
12053             /* Convert the bare "646" used on Solaris to a proper IANA name */
12054             if (strcmp(p, "646") == 0)
12055                 p = "ISO646-US";
12056@@ -325,6 +349,7 @@ GetJavaProperties(JNIEnv *env)
12057             std_encoding = (*p != '\0') ? p : "ISO8859-1";
12058 
12059 
12060+#if !defined(_ALLBSD_SOURCE)
12061 #ifdef __linux__
12062             /*
12063              * Remap the encoding string to a different value for japanese
12064@@ -355,11 +380,19 @@ GetJavaProperties(JNIEnv *env)
12065                     std_encoding = "Big5_Solaris";
12066             }
12067 #endif
12068+#endif /* !_ALLBSD_SOURCE */
12069             sprops.encoding = std_encoding;
12070             sprops.sun_jnu_encoding = sprops.encoding;
12071         }
12072     }
12073 
12074+#ifdef _ALLBSD_SOURCE
12075+#if BYTE_ORDER == _LITTLE_ENDIAN
12076+     sprops.unicode_encoding = "UnicodeLittle";
12077+ #else
12078+     sprops.unicode_encoding = "UnicodeBig";
12079+ #endif
12080+#else /* !_ALLBSD_SOURCE */
12081 #ifdef __linux__
12082 #if __BYTE_ORDER == __LITTLE_ENDIAN
12083     sprops.unicode_encoding = "UnicodeLittle";
12084@@ -369,6 +402,7 @@ GetJavaProperties(JNIEnv *env)
12085 #else
12086     sprops.unicode_encoding = "UnicodeBig";
12087 #endif
12088+#endif /* _ALLBSD_SOURCE */
12089 
12090     /* user properties */
12091     {
12092@@ -405,12 +439,14 @@ GetJavaProperties(JNIEnv *env)
12093     sprops.path_separator = ":";
12094     sprops.line_separator = "\n";
12095 
12096+#if !defined(_ALLBSD_SOURCE)
12097     /* Append CDE message and resource search path to NLSPATH and
12098      * XFILESEARCHPATH, in order to pick localized message for
12099      * FileSelectionDialog window (Bug 4173641).
12100      */
12101     setPathEnvironment("NLSPATH=/usr/dt/lib/nls/msg/%L/%N.cat");
12102     setPathEnvironment("XFILESEARCHPATH=/usr/dt/app-defaults/%L/Dt");
12103+#endif
12104 
12105     return &sprops;
12106 }
12107diff -upr ../orig/jdk/src/solaris/native/java/net/Inet4AddressImpl.c ./jdk/src/solaris/native/java/net/Inet4AddressImpl.c
12108--- ../orig/jdk/src/solaris/native/java/net/Inet4AddressImpl.c  2009-01-27 15:45:50.000000000 -0500
12109+++ ./jdk/src/solaris/native/java/net/Inet4AddressImpl.c        2009-05-04 17:37:17.000000000 -0400
12110@@ -35,17 +35,293 @@
12111 #include <stdlib.h>
12112 #include <ctype.h>
12113 
12114+#ifdef _ALLBSD_SOURCE
12115+#include <unistd.h>
12116+#include <sys/param.h>
12117+#endif
12118+
12119 #include "jvm.h"
12120 #include "jni_util.h"
12121 #include "net_util.h"
12122 
12123 #include "java_net_Inet4AddressImpl.h"
12124 
12125+#if defined(__GLIBC__) || (defined(__FreeBSD__) && (__FreeBSD_version >= 601104))
12126+#define HAS_GLIBC_GETHOSTBY_R  1
12127+#endif
12128+
12129+#if defined(_ALLBSD_SOURCE) && !defined(HAS_GLIBC_GETHOSTBY_R)
12130+/* Use getaddrinfo(3), which is thread safe */
12131+/************************************************************************
12132+ * Inet4AddressImpl
12133+ */
12134+
12135+/*
12136+ * Class:     java_net_Inet4AddressImpl
12137+ * Method:    getLocalHostName
12138+ * Signature: ()Ljava/lang/String;
12139+ */
12140+JNIEXPORT jstring JNICALL
12141+Java_java_net_Inet4AddressImpl_getLocalHostName(JNIEnv *env, jobject this) {
12142+    char hostname[NI_MAXHOST+1];
12143+
12144+    hostname[0] = '\0';
12145+    if (JVM_GetHostName(hostname, NI_MAXHOST)) {
12146+       /* Something went wrong, maybe networking is not setup? */
12147+       strcpy(hostname, "localhost");
12148+    } else {
12149+        struct addrinfo  hints, *res;
12150+        int error;
12151+
12152+        memset(&hints, 0, sizeof(hints));
12153+        hints.ai_flags = AI_CANONNAME;
12154+        hints.ai_family = AF_UNSPEC;
12155+
12156+        error = getaddrinfo(hostname, NULL, &hints, &res);
12157+
12158+        if (error == 0) {
12159+            /* host is known to name service */
12160+            error = getnameinfo(res->ai_addr,
12161+                                res->ai_addrlen,
12162+                                hostname,
12163+                                NI_MAXHOST,
12164+                                NULL,
12165+                                0,
12166+                                NI_NAMEREQD);
12167+
12168+            /* if getnameinfo fails hostname is still the value
12169+               from gethostname */
12170+
12171+            freeaddrinfo(res);
12172+       }
12173+    }
12174+    return (*env)->NewStringUTF(env, hostname);
12175+}
12176+
12177+static jclass ni_iacls;
12178+static jclass ni_ia4cls;
12179+static jmethodID ni_ia4ctrID;
12180+static jfieldID ni_iaaddressID;
12181+static jfieldID ni_iahostID;
12182+static jfieldID ni_iafamilyID;
12183+static int initialized = 0;
12184+
12185+/*
12186+ * Find an internet address for a given hostname.  Note that this
12187+ * code only works for addresses of type INET. The translation
12188+ * of %d.%d.%d.%d to an address (int) occurs in java now, so the
12189+ * String "host" shouldn't *ever* be a %d.%d.%d.%d string
12190+ *
12191+ * Class:     java_net_Inet4AddressImpl
12192+ * Method:    lookupAllHostAddr
12193+ * Signature: (Ljava/lang/String;)[[B
12194+ */
12195+
12196+JNIEXPORT jobjectArray JNICALL
12197+Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
12198+                                               jstring host) {
12199+    const char *hostname;
12200+    jobject name;
12201+    jobjectArray ret = 0;
12202+    int retLen = 0;
12203+
12204+    int error=0;
12205+    struct addrinfo hints, *res, *resNew = NULL;
12206+
12207+    if (!initialized) {
12208+      ni_iacls = (*env)->FindClass(env, "java/net/InetAddress");
12209+      ni_iacls = (*env)->NewGlobalRef(env, ni_iacls);
12210+      ni_ia4cls = (*env)->FindClass(env, "java/net/Inet4Address");
12211+      ni_ia4cls = (*env)->NewGlobalRef(env, ni_ia4cls);
12212+      ni_ia4ctrID = (*env)->GetMethodID(env, ni_ia4cls, "<init>", "()V");
12213+      ni_iaaddressID = (*env)->GetFieldID(env, ni_iacls, "address", "I");
12214+      ni_iafamilyID = (*env)->GetFieldID(env, ni_iacls, "family", "I");
12215+      ni_iahostID = (*env)->GetFieldID(env, ni_iacls, "hostName", "Ljava/lang/String;");
12216+      initialized = 1;
12217+    }
12218+
12219+    if (IS_NULL(host)) {
12220+       JNU_ThrowNullPointerException(env, "host is null");
12221+       return 0;
12222+    }
12223+    hostname = JNU_GetStringPlatformChars(env, host, JNI_FALSE);
12224+    CHECK_NULL_RETURN(hostname, NULL);
12225+
12226+    memset(&hints, 0, sizeof(hints));
12227+    hints.ai_flags = AI_CANONNAME;
12228+    hints.ai_family = AF_INET;
12229+
12230+    /*
12231+     * Workaround for Solaris bug 4160367 - if a hostname contains a
12232+     * white space then 0.0.0.0 is returned
12233+     */
12234+    if (isspace(hostname[0])) {
12235+       JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
12236+                       (char *)hostname);
12237+       JNU_ReleaseStringPlatformChars(env, host, hostname);
12238+       return NULL;
12239+    }
12240+       
12241+    error = getaddrinfo(hostname, NULL, &hints, &res);
12242+       
12243+    if (error) {
12244+       /* report error */
12245+       JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException",
12246+                       (char *)hostname);
12247+       JNU_ReleaseStringPlatformChars(env, host, hostname);
12248+       return NULL;
12249+    } else {
12250+       int i = 0;
12251+       struct addrinfo *itr, *last, *iterator = res;
12252+       while (iterator != NULL) {
12253+           int skip = 0;
12254+           itr = resNew;
12255+
12256+           while (itr != NULL) {
12257+               struct sockaddr_in *addr1, *addr2;
12258+
12259+               addr1 = (struct sockaddr_in *)iterator->ai_addr;
12260+               addr2 = (struct sockaddr_in *)itr->ai_addr;
12261+               if (addr1->sin_addr.s_addr ==
12262+                   addr2->sin_addr.s_addr) {
12263+                   skip = 1;
12264+                   break;
12265+               }
12266+                   
12267+               itr = itr->ai_next;
12268+           }
12269+               
12270+           if (!skip) {
12271+               struct addrinfo *next
12272+                   = (struct addrinfo*) malloc(sizeof(struct addrinfo));
12273+               if (!next) {
12274+                   JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
12275+                   ret = NULL;
12276+                   goto cleanupAndReturn;
12277+               }
12278+               memcpy(next, iterator, sizeof(struct addrinfo));
12279+               next->ai_next = NULL;
12280+               if (resNew == NULL) {
12281+                   resNew = next;
12282+               } else {
12283+                   last->ai_next = next;
12284+               }
12285+               last = next;
12286+               i++;
12287+           }
12288+           iterator = iterator->ai_next;
12289+       }
12290+
12291+       retLen = i;
12292+       iterator = resNew;
12293+       i = 0;
12294+
12295+        name = (*env)->NewStringUTF(env, hostname);
12296+        if (IS_NULL(name)) {
12297+          goto cleanupAndReturn;
12298+        }
12299+
12300+       ret = (*env)->NewObjectArray(env, retLen, ni_iacls, NULL);
12301+       if (IS_NULL(ret)) {
12302+           /* we may have memory to free at the end of this */
12303+           goto cleanupAndReturn;
12304+       }
12305+
12306+       while (iterator != NULL) {
12307+           /* We need 4 bytes to store ipv4 address; */
12308+           int len = 4;
12309+               
12310+            jobject iaObj = (*env)->NewObject(env, ni_ia4cls, ni_ia4ctrID);
12311+           if (IS_NULL(iaObj)) {
12312+               /* we may have memory to free at the end of this */
12313+               ret = NULL;
12314+               goto cleanupAndReturn;
12315+           }
12316+            (*env)->SetIntField(env, iaObj, ni_iaaddressID,
12317+                                ntohl(((struct sockaddr_in*)(iterator->ai_addr))->sin_addr.s_addr));
12318+            (*env)->SetObjectField(env, iaObj, ni_iahostID, name);
12319+            (*env)->SetObjectArrayElement(env, ret, retLen - i -1, iaObj);
12320+           i++;
12321+           iterator = iterator->ai_next;
12322+       }
12323+    }
12324+   
12325+cleanupAndReturn:
12326+    {
12327+       struct addrinfo *iterator, *tmp;
12328+       iterator = resNew;
12329+       while (iterator != NULL) {
12330+           tmp = iterator;
12331+           iterator = iterator->ai_next;
12332+           free(tmp);
12333+       }
12334+       JNU_ReleaseStringPlatformChars(env, host, hostname);
12335+    }
12336+   
12337+    freeaddrinfo(res);
12338+   
12339+    return ret;
12340+
12341+}
12342+
12343+/*
12344+ * Class:     java_net_Inet4AddressImpl
12345+ * Method:    getHostByAddr
12346+ * Signature: (I)Ljava/lang/String;
12347+ */
12348+JNIEXPORT jstring JNICALL
12349+Java_java_net_Inet4AddressImpl_getHostByAddr(JNIEnv *env, jobject this,
12350+                                           jbyteArray addrArray) {
12351+    jstring ret = NULL;
12352+
12353+    char host[NI_MAXHOST+1];
12354+    jfieldID fid;
12355+    int error = 0;
12356+    jint family;
12357+    struct sockaddr *him ;
12358+    int len = 0;
12359+    jbyte caddr[4];
12360+    jint addr;
12361+
12362+    struct sockaddr_in him4;
12363+    struct sockaddr *sa;
12364+
12365+    /*
12366+        * For IPv4 addresses construct a sockaddr_in structure.
12367+        */
12368+    (*env)->GetByteArrayRegion(env, addrArray, 0, 4, caddr);
12369+    addr = ((caddr[0]<<24) & 0xff000000);
12370+    addr |= ((caddr[1] <<16) & 0xff0000);
12371+    addr |= ((caddr[2] <<8) & 0xff00);
12372+    addr |= (caddr[3] & 0xff);
12373+    memset((char *) &him4, 0, sizeof(him4));
12374+    him4.sin_addr.s_addr = (uint32_t) htonl(addr);
12375+    him4.sin_family = AF_INET;
12376+    sa = (struct sockaddr *) &him4;
12377+    len = sizeof(him4);
12378+   
12379+    error = getnameinfo(sa, len, host, NI_MAXHOST, NULL, 0,
12380+                              NI_NAMEREQD);
12381+
12382+    if (!error) {
12383+       ret = (*env)->NewStringUTF(env, host);
12384+    }
12385+
12386+    if (ret == NULL) {
12387+       JNU_ThrowByName(env, JNU_JAVANETPKG "UnknownHostException", NULL);
12388+    }
12389+
12390+    return ret;
12391+
12392+}
12393+
12394+#else /* defined(_ALLBSD_SOURCE) && !defined(HAS_GLIBC_GETHOSTBY_R) */
12395+
12396 /* the initial size of our hostent buffers */
12397 #define HENT_BUF_SIZE 1024
12398 #define BIG_HENT_BUF_SIZE 10240  /* a jumbo-sized one */
12399 
12400-#ifndef __GLIBC__
12401+#if !defined(__GLIBC__) && !defined(_ALLBSD_SOURCE)
12402 /* gethostname() is in libc.so but I can't find a header file for it */
12403 extern int gethostname(char *buf, int buf_len);
12404 #endif
12405@@ -85,13 +361,13 @@ Java_java_net_Inet4AddressImpl_getLocalH
12406         char buf2[HENT_BUF_SIZE];
12407         int h_error=0;
12408 
12409-#ifdef __GLIBC__
12410+#ifdef HAS_GLIBC_GETHOSTBY_R
12411         gethostbyname_r(hostname, &res, buf, sizeof(buf), &hp, &h_error);
12412 #else
12413         hp = gethostbyname_r(hostname, &res, buf, sizeof(buf), &h_error);
12414 #endif
12415         if (hp) {
12416-#ifdef __GLIBC__
12417+#ifdef HAS_GLIBC_GETHOSTBY_R
12418             gethostbyaddr_r(hp->h_addr, hp->h_length, AF_INET,
12419                             &res2, buf2, sizeof(buf2), &hp, &h_error);
12420 #else
12421@@ -178,7 +454,7 @@ Java_java_net_Inet4AddressImpl_lookupAll
12422     }
12423 
12424     /* Try once, with our static buffer. */
12425-#ifdef __GLIBC__
12426+#ifdef HAS_GLIBC_GETHOSTBY_R
12427     gethostbyname_r(hostname, &res, buf, sizeof(buf), &hp, &h_error);
12428 #else
12429     hp = gethostbyname_r(hostname, &res, buf, sizeof(buf), &h_error);
12430@@ -191,7 +467,7 @@ Java_java_net_Inet4AddressImpl_lookupAll
12431      */
12432     if (hp == NULL && errno == ERANGE) {
12433         if ((tmp = (char*)malloc(BIG_HENT_BUF_SIZE))) {
12434-#ifdef __GLIBC__
12435+#ifdef HAS_GLIBC_GETHOSTBY_R
12436             gethostbyname_r(hostname, &res, tmp, BIG_HENT_BUF_SIZE,
12437                             &hp, &h_error);
12438 #else
12439@@ -281,7 +557,7 @@ Java_java_net_Inet4AddressImpl_getHostBy
12440     addr |= ((caddr[2] <<8) & 0xff00);
12441     addr |= (caddr[3] & 0xff);
12442     addr = htonl(addr);
12443-#ifdef __GLIBC__
12444+#ifdef HAS_GLIBC_GETHOSTBY_R
12445     gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET, &hent,
12446                     buf, sizeof(buf), &hp, &h_error);
12447 #else
12448@@ -295,7 +571,7 @@ Java_java_net_Inet4AddressImpl_getHostBy
12449      */
12450     if (hp == NULL && errno == ERANGE) {
12451         if ((tmp = (char*)malloc(BIG_HENT_BUF_SIZE))) {
12452-#ifdef __GLIBC__
12453+#ifdef HAS_GLIBC_GETHOSTBY_R
12454             gethostbyaddr_r((char *)&addr, sizeof(addr), AF_INET,
12455                             &hent, tmp, BIG_HENT_BUF_SIZE, &hp, &h_error);
12456 #else
12457@@ -317,6 +593,8 @@ Java_java_net_Inet4AddressImpl_getHostBy
12458     return ret;
12459 }
12460 
12461+#endif /* _ALLBSD_SOURCE */
12462+
12463 #define SET_NONBLOCKING(fd) {           \
12464         int flags = fcntl(fd, F_GETFL); \
12465         flags |= O_NONBLOCK;            \
12466diff -upr ../orig/jdk/src/solaris/native/java/net/Inet6AddressImpl.c ./jdk/src/solaris/native/java/net/Inet6AddressImpl.c
12467--- ../orig/jdk/src/solaris/native/java/net/Inet6AddressImpl.c  2009-01-27 15:45:50.000000000 -0500
12468+++ ./jdk/src/solaris/native/java/net/Inet6AddressImpl.c        2009-05-04 17:37:17.000000000 -0400
12469@@ -32,6 +32,9 @@
12470 #include <strings.h>
12471 #include <stdlib.h>
12472 #include <ctype.h>
12473+#ifdef _ALLBSD_SOURCE
12474+#include <unistd.h> /* gethostname */
12475+#endif
12476 
12477 #include "jvm.h"
12478 #include "jni_util.h"
12479@@ -48,7 +51,7 @@
12480 #define NI_MAXHOST 1025
12481 #endif
12482 
12483-#ifndef __GLIBC__
12484+#if !defined(__GLIBC__) && !defined(_ALLBSD_SOURCE)
12485 /* gethostname() is in libc.so but I can't find a header file for it */
12486 extern int gethostname(char *buf, int buf_len);
12487 #endif
12488@@ -71,10 +74,18 @@ Java_java_net_Inet6AddressImpl_getLocalH
12489         /* Something went wrong, maybe networking is not setup? */
12490         strcpy(hostname, "localhost");
12491     } else {
12492-#ifdef __linux__
12493-        /* On Linux gethostname() says "host.domain.sun.com".  On
12494+#if defined(__linux__) && defined(_ALLBSD_SOURCE)
12495+       /* On Linux/FreeBSD gethostname() says "host.domain.sun.com".  On
12496          * Solaris gethostname() says "host", so extra work is needed.
12497          */
12498+        /*
12499+         * XXXBSD: Though on FreeBSD it's possible case then hostname does
12500+         * not contain '.' (depends on previous sethostname() call).  Maybe
12501+         * we need to proceed with Solaris way, but using getnameinfo()
12502+         * in conjunction with gethostby*() breaks thread-safeness, so
12503+         * we need to protect all calls to gethostby*() and getnameinfo()
12504+         * using same mutex.
12505+         */
12506 #else
12507         /* Solaris doesn't want to give us a fully qualified domain name.
12508          * We do a reverse lookup to try and get one.  This works
12509@@ -110,7 +121,7 @@ Java_java_net_Inet6AddressImpl_getLocalH
12510             }
12511         }
12512 #endif /* AF_INET6 */
12513-#endif /* __linux__ */
12514+#endif /* __linux__ || _ALLBSD_SOURCE */
12515     }
12516     return (*env)->NewStringUTF(env, hostname);
12517 }
12518diff -upr ../orig/jdk/src/solaris/native/java/net/NetworkInterface.c ./jdk/src/solaris/native/java/net/NetworkInterface.c
12519--- ../orig/jdk/src/solaris/native/java/net/NetworkInterface.c  2009-01-27 15:45:50.000000000 -0500
12520+++ ./jdk/src/solaris/native/java/net/NetworkInterface.c        2009-05-04 17:37:17.000000000 -0400
12521@@ -23,13 +23,13 @@
12522  * have any questions.
12523  */
12524 
12525+#include <sys/types.h>
12526+#include <sys/socket.h>
12527 #include <errno.h>
12528 #include <strings.h>
12529 #include <netinet/in.h>
12530 #include <stdlib.h>
12531 #include <string.h>
12532-#include <sys/types.h>
12533-#include <sys/socket.h>
12534 #include <arpa/inet.h>
12535 #include <net/if.h>
12536 #include <net/if_arp.h>
12537@@ -47,6 +47,19 @@
12538 #else
12539 #include <sys/sockio.h>
12540 #endif
12541+#if defined(_ALLBSD_SOURCE)
12542+#include <sys/param.h>
12543+#include <sys/ioctl.h>
12544+#if defined(__FreeBSD__) || defined(__APPLE__)
12545+#include <net/ethernet.h>
12546+#include <net/if_var.h>
12547+#elif defined(__OpenBSD__)
12548+#include <netinet/if_ether.h>
12549+#endif
12550+#include <net/if_dl.h>
12551+#include <netinet/in_var.h>
12552+#include <ifaddrs.h>
12553+#endif
12554 
12555 #ifdef __linux__
12556 #define ifr_index ifr_ifindex
12557@@ -584,6 +597,7 @@ static netif *enumInterfaces(JNIEnv *env
12558 }
12559 
12560 
12561+#if !defined(_ALLBSD_SOURCE)
12562 /*
12563  * Enumerates and returns all IPv4 interfaces
12564  */
12565@@ -694,6 +708,176 @@ static netif *enumIPv4Interfaces(JNIEnv
12566     return ifs;
12567 }
12568 
12569+#else /* _ALLBSD_SOURCE */
12570+
12571+/*
12572+ * Enumerates and returns all IPv4 interfaces
12573+ *
12574+ * WARNING! Make sure that it's correctly synchronized on future JDK
12575+ * versions imports!
12576+ */
12577+static netif *enumIPv4Interfaces(JNIEnv *env, netif *ifs)
12578+{
12579+    int sock;
12580+    struct ifaddrs *ifa, *origifa;
12581+
12582+    sock = JVM_Socket(AF_INET, SOCK_DGRAM, 0);
12583+    if (sock < 0) {
12584+       /*
12585+        * If EPROTONOSUPPORT is returned it means we don't have
12586+        * IPv4 support so don't throw an exception.
12587+        */
12588+       if (errno != EPROTONOSUPPORT) {
12589+           NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
12590+                             "Socket creation failed");
12591+       }
12592+       return ifs;
12593+    }
12594+
12595+    if (getifaddrs(&origifa) != 0) {
12596+        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
12597+                         "getifaddrs() function failed");
12598+       close(sock);
12599+       return ifs;
12600+    }
12601+
12602+    for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) {
12603+
12604+       /*
12605+        * Skip non-AF_INET entries.
12606+        */
12607+       if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET)
12608+           continue;
12609+
12610+       /*
12611+        * Add to the list.
12612+        *
12613+        * BSDNOTE: in order to optimize code, interface index detection
12614+        * logic was added directly to addif().
12615+        */
12616+       ifs = addif(env, ifs, ifa->ifa_name, (-1), AF_INET,
12617+                   ifa->ifa_addr, sizeof(struct sockaddr_in), 0);
12618+
12619+       /*
12620+        * If an exception occurred then free the list.
12621+        */
12622+       if ((*env)->ExceptionOccurred(env)) {
12623+           close(sock);
12624+           freeifaddrs(origifa);
12625+           freeif(ifs);
12626+           return NULL;
12627+       }
12628+    }
12629+
12630+    /*
12631+     * Free socket and buffer
12632+     */
12633+    close(sock);
12634+    freeifaddrs(origifa);
12635+    return ifs;
12636+}
12637+
12638+#if defined(AF_INET6)
12639+/*
12640+ * Determines the prefix on BSD for IPv6 interfaces.
12641+ */
12642+static
12643+int prefix(void *val, int size) {
12644+    u_char *name = (u_char *)val;
12645+    int byte, bit, plen = 0;
12646+
12647+    for (byte = 0; byte < size; byte++, plen += 8)
12648+        if (name[byte] != 0xff)
12649+            break;
12650+    if (byte == size)
12651+        return (plen);
12652+    for (bit = 7; bit != 0; bit--, plen++)
12653+        if (!(name[byte] & (1 << bit)))
12654+            break;
12655+    for (; bit != 0; bit--)
12656+        if (name[byte] & (1 << bit))
12657+            return (0);
12658+    byte++;
12659+    for (; byte < size; byte++)
12660+        if (name[byte])
12661+            return (0);
12662+    return (plen);
12663+}
12664+
12665+/*
12666+ * Enumerates and returns all IPv6 interfaces on FreeBSD
12667+ *
12668+ * BSDNOTE: it's done in same as IPv4 enumeration and should be carefully
12669+ *          reviewed with each JDK update (according to Solaris/Linux version)
12670+ */
12671+static netif *enumIPv6Interfaces(JNIEnv *env, netif *ifs) {
12672+
12673+    int sock;
12674+    struct ifaddrs *ifa, *origifa;
12675+    struct sockaddr_in6 *sin6;
12676+    struct in6_ifreq ifr6;
12677+
12678+    // Open IPv6 UDP socket.
12679+    sock = JVM_Socket(AF_INET6, SOCK_DGRAM, 0);
12680+    if (sock < 0) {
12681+        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
12682+                     "Failed to create IPv6 socket");
12683+        return ifs;
12684+    }
12685+
12686+    if (getifaddrs(&origifa) != 0) {
12687+        NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
12688+                         "getifaddrs() function failed");
12689+       close(sock);
12690+       return ifs;
12691+    }
12692+
12693+    for (ifa = origifa; ifa != NULL; ifa = ifa->ifa_next) {
12694+
12695+       /*
12696+        * Skip non-AF_INET6 entries.
12697+        */
12698+       if (ifa->ifa_addr == NULL || ifa->ifa_addr->sa_family != AF_INET6)
12699+           continue;
12700+
12701+       memset(&ifr6, 0, sizeof(ifr6));
12702+       strlcpy(ifr6.ifr_name, ifa->ifa_name, sizeof(ifr6.ifr_name));
12703+       memcpy(&ifr6.ifr_addr, ifa->ifa_addr, MIN(sizeof(ifr6.ifr_addr), ifa->ifa_addr->sa_len));
12704+
12705+       if (ioctl(sock, SIOCGIFNETMASK_IN6, (caddr_t)&ifr6) < 0) {
12706+           NET_ThrowByNameWithLastError(env , JNU_JAVANETPKG "SocketException",
12707+                             "ioctl SIOCGIFNETMASK_IN6 failed");
12708+           close(sock);
12709+           freeifaddrs(origifa);
12710+           freeif(ifs);
12711+           return NULL;
12712+       }
12713+
12714+       /* Add to the list.  */
12715+       sin6 = (struct sockaddr_in6 *)&ifr6.ifr_addr;
12716+       ifs = addif(env, ifs, ifa->ifa_name, (-1), AF_INET6,
12717+                   ifa->ifa_addr, sizeof(struct sockaddr_in6),
12718+                   prefix(&sin6->sin6_addr, sizeof(struct in6_addr)));
12719+
12720+       /* If an exception occurred then free the list.  */
12721+       if ((*env)->ExceptionOccurred(env)) {
12722+           close(sock);
12723+           freeifaddrs(origifa);
12724+           freeif(ifs);
12725+           return NULL;
12726+       }
12727+    }
12728+
12729+    /*
12730+     * Free socket and ifaddrs buffer
12731+     */
12732+    close(sock);
12733+    freeifaddrs(origifa);
12734+    return ifs;
12735+}
12736+#endif /* AF_INET6 */
12737+
12738+#endif /* !_ALLBSD_SOURCE */
12739 
12740 #if defined(__solaris__) && defined(AF_INET6)
12741 /*
12742@@ -1014,7 +1198,13 @@ netif *addif(JNIEnv *env, netif *ifs, ch
12743             JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
12744             return ifs;
12745         }
12746+#if defined(_ALLBSD_SOURCE)
12747+       currif->index = if_nametoindex(name);
12748+       if (currif->index == 0)
12749+           currif->index = -1;
12750+#else
12751         currif->index = index;
12752+#endif
12753         currif->addr = NULL;
12754         currif->childs = NULL;
12755         currif->virtual = isVirtual;
12756@@ -1302,6 +1492,31 @@ int getMacAddress(JNIEnv *env, const str
12757    * All bytes to 0 means no hardware address.
12758    */
12759   return -1;
12760+#elif defined(_ALLBSD_SOURCE)
12761+  struct ifaddrs *ifa0, *ifa;
12762+  struct sockaddr *saddr;
12763+  int i;
12764+
12765+  /* Grab the interface list */
12766+  if (!getifaddrs(&ifa0)) {
12767+    /* Cycle through the interfaces */
12768+    for (i = 0, ifa = ifa0; ifa != NULL; ifa = ifa->ifa_next, i++) {
12769+      saddr = ifa->ifa_addr;
12770+      /* Link layer contains the MAC address */
12771+      if (saddr->sa_family == AF_LINK && !strcmp(ifname, ifa->ifa_name)) {
12772+        struct sockaddr_dl *sadl = (struct sockaddr_dl *) saddr;
12773+        /* Check the address is the correct length */
12774+        if (sadl->sdl_alen == ETHER_ADDR_LEN) {
12775+           memcpy(buf, (sadl->sdl_data + sadl->sdl_nlen), ETHER_ADDR_LEN);
12776+           freeifaddrs(ifa0);
12777+           return ETHER_ADDR_LEN;
12778+        }
12779+      }
12780+    }
12781+    freeifaddrs(ifa0);
12782+  }
12783+
12784+  return -1;
12785 #else
12786   struct arpreq arpreq;
12787   struct sockaddr_in* sin;
12788@@ -1467,7 +1682,7 @@ JNIEXPORT jint JNICALL Java_java_net_Net
12789                                  "Socket creation failed");
12790   } else {
12791 
12792-#ifdef __linux__
12793+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
12794     memset((char *) &if2, 0, sizeof(if2));
12795     strcpy(if2.ifr_name, name_utf);
12796 
12797diff -upr ../orig/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c ./jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c
12798--- ../orig/jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c   2009-01-27 15:45:50.000000000 -0500
12799+++ ./jdk/src/solaris/native/java/net/PlainDatagramSocketImpl.c 2009-05-04 17:37:17.000000000 -0400
12800@@ -23,12 +23,12 @@
12801  * have any questions.
12802  */
12803 
12804+#include <sys/types.h>
12805+#include <sys/socket.h>
12806 #include <errno.h>
12807 #include <netinet/in.h>
12808 #include <stdlib.h>
12809 #include <string.h>
12810-#include <sys/types.h>
12811-#include <sys/socket.h>
12812 
12813 #ifdef __solaris__
12814 #include <fcntl.h>
12815@@ -335,7 +335,7 @@ Java_java_net_PlainDatagramSocketImpl_di
12816     /* The fdObj'fd */
12817     jint fd;
12818 
12819-#ifdef __linux__
12820+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
12821     SOCKADDR addr;
12822     int len;
12823 #endif
12824@@ -345,26 +345,39 @@ Java_java_net_PlainDatagramSocketImpl_di
12825     }
12826     fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
12827 
12828+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
12829 #ifdef __linux__
12830     if (isOldKernel) {
12831         int t = 1;
12832         setsockopt(fd, SOL_SOCKET, SO_BSDCOMPAT, (char*) &t, sizeof(int));
12833     } else {
12834+#endif /* __linux__ */
12835         memset(&addr, 0, sizeof(addr));
12836 #ifdef AF_INET6
12837         if (ipv6_available()) {
12838             struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)&addr;
12839+#ifdef __FreeBSD__
12840+            him6->sin6_family = AF_INET6;
12841+#else
12842             him6->sin6_family = AF_UNSPEC;
12843+#endif
12844             len = sizeof(struct sockaddr_in6);
12845         } else
12846 #endif
12847         {
12848             struct sockaddr_in *him4 = (struct sockaddr_in*)&addr;
12849+#ifdef __FreeBSD__
12850+            him4->sin_family = AF_INET;
12851+#else
12852             him4->sin_family = AF_UNSPEC;
12853+#endif
12854             len = sizeof(struct sockaddr_in);
12855         }
12856         JVM_Connect(fd, (struct sockaddr *)&addr, len);
12857+       /* XXXBSD: here we can get EADDRNOTAVAIL which need to be ignored
12858+          but since return value is not checked, ignore it */
12859 
12860+#ifdef __linux__
12861         // After disconnecting a UDP socket, Linux kernel will set
12862         // local port to zero if the port number comes from implicit
12863         // bind. Successive send/recv on the same socket will fail.
12864@@ -387,6 +400,7 @@ Java_java_net_PlainDatagramSocketImpl_di
12865             NET_Bind(fd, (struct sockaddr *)&addr, len);
12866         }
12867     }
12868+#endif
12869 #else
12870     JVM_Connect(fd, 0, 0);
12871 #endif
12872@@ -2374,18 +2388,30 @@ static void mcast_join_leave(JNIEnv *env
12873             mname6.ipv6mr_interface = idx;
12874         }
12875 
12876+#if defined(_ALLBSD_SOURCE)
12877+#define ADD_MEMBERSHIP         IPV6_JOIN_GROUP
12878+#define DRP_MEMBERSHIP         IPV6_LEAVE_GROUP
12879+#define S_ADD_MEMBERSHIP       "IPV6_JOIN_GROUP"
12880+#define S_DRP_MEMBERSHIP       "IPV6_LEAVE_GROUP"
12881+#else
12882+#define ADD_MEMBERSHIP         IPV6_ADD_MEMBERSHIP
12883+#define DRP_MEMBERSHIP         IPV6_DROP_MEMBERSHIP
12884+#define S_ADD_MEMBERSHIP       "IPV6_ADD_MEMBERSHIP"
12885+#define S_DRP_MEMBERSHIP       "IPV6_DROP_MEMBERSHIP"
12886+#endif
12887+
12888         /* Join the multicast group */
12889-        if (JVM_SetSockOpt(fd, IPPROTO_IPV6, (join ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP),
12890+        if (JVM_SetSockOpt(fd, IPPROTO_IPV6, (join ? ADD_MEMBERSHIP : DRP_MEMBERSHIP),
12891                            (char *) &mname6, sizeof (mname6)) < 0) {
12892 
12893             if (join) {
12894-                NET_ThrowCurrent(env, "setsockopt IPV6_ADD_MEMBERSHIP failed");
12895+                NET_ThrowCurrent(env, "setsockopt " S_ADD_MEMBERSHIP " failed");
12896             } else {
12897                 if (errno == ENOENT) {
12898                    JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
12899                         "Not a member of the multicast group");
12900                 } else {
12901-                    NET_ThrowCurrent(env, "setsockopt IPV6_DROP_MEMBERSHIP failed");
12902+                    NET_ThrowCurrent(env, "setsockopt " S_DRP_MEMBERSHIP " failed");
12903                 }
12904             }
12905         }
12906diff -upr ../orig/jdk/src/solaris/native/java/net/PlainSocketImpl.c ./jdk/src/solaris/native/java/net/PlainSocketImpl.c
12907--- ../orig/jdk/src/solaris/native/java/net/PlainSocketImpl.c   2009-01-27 15:45:50.000000000 -0500
12908+++ ./jdk/src/solaris/native/java/net/PlainSocketImpl.c 2009-05-04 17:37:17.000000000 -0400
12909@@ -528,9 +528,11 @@ Java_java_net_PlainSocketImpl_socketConn
12910         if (connect_rv == JVM_IO_INTR) {
12911             JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
12912                             "operation interrupted");
12913+#if defined(EPROTO)
12914         } else if (errno == EPROTO) {
12915             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ProtocolException",
12916                            "Protocol error");
12917+#endif
12918         } else if (errno == ECONNREFUSED) {
12919             NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
12920                            "Connection refused");
12921diff -upr ../orig/jdk/src/solaris/native/java/net/bsd_close.c ./jdk/src/solaris/native/java/net/bsd_close.c
12922--- ../orig/jdk/src/solaris/native/java/net/bsd_close.c 2009-05-04 18:32:16.000000000 -0400
12923+++ ./jdk/src/solaris/native/java/net/bsd_close.c       2009-05-04 17:37:15.000000000 -0400
12924@@ -57,7 +57,7 @@ typedef struct {
12925 /*
12926  * Signal to unblock thread
12927  */
12928-static int sigWakeup = (__SIGRTMAX - 2);
12929+static int sigWakeup = SIGIO;
12930 
12931 /*
12932  * The fd table and the number of file descriptors
12933diff -upr ../orig/jdk/src/solaris/native/java/net/net_util_md.c ./jdk/src/solaris/native/java/net/net_util_md.c
12934--- ../orig/jdk/src/solaris/native/java/net/net_util_md.c       2009-01-27 15:45:50.000000000 -0500
12935+++ ./jdk/src/solaris/native/java/net/net_util_md.c     2009-05-04 17:37:17.000000000 -0400
12936@@ -34,6 +34,15 @@
12937 #include <stdlib.h>
12938 #include <dlfcn.h>
12939 
12940+#ifdef _ALLBSD_SOURCE
12941+#include <sys/param.h>
12942+#include <sys/sysctl.h>
12943+#endif
12944+
12945+#ifdef __OpenBSD__
12946+#include <sys/socketvar.h>
12947+#endif
12948+
12949 #ifdef __solaris__
12950 #include <sys/sockio.h>
12951 #include <stropts.h>
12952@@ -219,6 +228,14 @@ NET_GetFileDescriptorID(JNIEnv *env)
12953     return (*env)->GetFieldID(env, cls, "fd", "I");
12954 }
12955 
12956+#if defined(DONT_ENABLE_IPV6)
12957+jint  IPv6_supported()
12958+{
12959+    return JNI_FALSE;
12960+}
12961+
12962+#else /* !DONT_ENABLE_IPV6 */
12963+
12964 jint  IPv6_supported()
12965 {
12966 #ifndef AF_INET6
12967@@ -355,6 +372,7 @@ jint  IPv6_supported()
12968     close(fd);
12969     return JNI_TRUE;
12970 }
12971+#endif /* DONT_ENABLE_IPV6 */
12972 
12973 void
12974 NET_AllocSockaddr(struct sockaddr **him, int *len) {
12975@@ -689,6 +707,10 @@ NET_InetAddressToSockaddr(JNIEnv *env, j
12976         him6->sin6_family = AF_INET6;
12977         *len = sizeof(struct sockaddr_in6) ;
12978 
12979+#if defined(_ALLBSD_SOURCE) && defined(_AF_INET6)
12980+// XXXBSD: should we do something with scope id here ? see below linux comment
12981+#endif
12982+
12983         /*
12984          * On Linux if we are connecting to a link-local address
12985          * we need to specify the interface in the scope_id (2.4 kernel only)
12986@@ -1133,6 +1155,24 @@ NET_SetSockOpt(int fd, int level, int  o
12987 #define IPTOS_PREC_MASK 0xe0
12988 #endif
12989 
12990+#if defined(_ALLBSD_SOURCE)
12991+#if defined(KIPC_MAXSOCKBUF)
12992+    int mib[3];
12993+    size_t rlen;
12994+#endif
12995+
12996+    int *bufsize;
12997+
12998+#ifdef __APPLE__
12999+    static int maxsockbuf = -1;
13000+#else
13001+    static long maxsockbuf = -1;
13002+#endif
13003+
13004+    int addopt;
13005+    struct linger *ling;
13006+#endif
13007+
13008     /*
13009      * IPPROTO/IP_TOS :-
13010      * 1. IPv6 on Solaris: no-op and will be set in flowinfo
13011@@ -1165,6 +1205,10 @@ NET_SetSockOpt(int fd, int level, int  o
13012         *iptos &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK);
13013     }
13014 
13015+#if defined(AF_INET6) && defined(_ALLBSD_SOURCE)
13016+// XXXBSD: to be implemented ?
13017+#endif
13018+
13019     /*
13020      * SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On Solaris need to
13021      * ensure that value is <= max_buf as otherwise we get
13022@@ -1212,6 +1256,83 @@ NET_SetSockOpt(int fd, int level, int  o
13023     }
13024 #endif
13025 
13026+#if defined(_ALLBSD_SOURCE)
13027+    /*
13028+     * SOL_SOCKET/{SO_SNDBUF,SO_RCVBUF} - On FreeBSD need to
13029+     * ensure that value is <= kern.ipc.maxsockbuf as otherwise we get
13030+     * an ENOBUFS error.
13031+     */
13032+    if (level == SOL_SOCKET) {
13033+        if (opt == SO_SNDBUF || opt == SO_RCVBUF) {
13034+#ifdef KIPC_MAXSOCKBUF
13035+            if (maxsockbuf == -1) {
13036+               mib[0] = CTL_KERN;
13037+               mib[1] = KERN_IPC;
13038+               mib[2] = KIPC_MAXSOCKBUF;
13039+               rlen = sizeof(maxsockbuf);
13040+               if (sysctl(mib, 3, &maxsockbuf, &rlen, NULL, 0) == -1)
13041+                   maxsockbuf = 1024;
13042+
13043+#if 1
13044+               /* XXXBSD: This is a hack to workaround mb_max/mb_max_adj
13045+                  problem.  It should be removed when kern.ipc.maxsockbuf
13046+                  will be real value. */
13047+               maxsockbuf = (maxsockbuf/5)*4;
13048+#endif
13049+           }
13050+#elif defined(__OpenBSD__)
13051+          maxsockbuf = SB_MAX;
13052+#else
13053+          maxsockbuf = 64 * 1024;      /* XXX: NetBSD */
13054+#endif
13055+
13056+           bufsize = (int *)arg;
13057+           if (*bufsize > maxsockbuf) {
13058+               *bufsize = maxsockbuf;
13059+           }
13060+
13061+          if (opt == SO_RCVBUF && *bufsize < 1024) {
13062+               *bufsize = 1024;
13063+          }
13064+
13065+        }
13066+    }
13067+
13068+    /*
13069+     * On Solaris, SO_REUSEADDR will allow multiple datagram
13070+     * sockets to bind to the same port.  The network jck tests
13071+     * for this "feature", so we need to emulate it by turning on
13072+     * SO_REUSEPORT as well for that combination.
13073+     */
13074+    if (level == SOL_SOCKET && opt == SO_REUSEADDR) {
13075+        int sotype, arglen;
13076+
13077+        arglen = sizeof(sotype);
13078+        if (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void *)&sotype, &arglen) < 0) {
13079+            return -1;
13080+        }
13081+
13082+        if (sotype == SOCK_DGRAM) {
13083+            addopt = SO_REUSEPORT;
13084+            setsockopt(fd, level, addopt, arg, len);
13085+        }
13086+    }
13087+
13088+    /*
13089+     * Don't allow SO_LINGER value to be too big.
13090+     * Current max value (240) is empiric value based on tcp_timer.h's
13091+     * constant TCP_LINGERTIME, which was doubled.
13092+     *
13093+     * XXXBSD: maybe we should step it down to 120 ?
13094+     */
13095+    if (level == SOL_SOCKET && opt == SO_LINGER) {
13096+        ling = (struct linger *)arg;
13097+       if (ling->l_linger > 240 || ling->l_linger < 0) {
13098+           ling->l_linger = 240;
13099+       }
13100+    }
13101+#endif
13102+
13103     return setsockopt(fd, level, opt, arg, len);
13104 }
13105 
13106diff -upr ../orig/jdk/src/solaris/native/java/net/net_util_md.h ./jdk/src/solaris/native/java/net/net_util_md.h
13107--- ../orig/jdk/src/solaris/native/java/net/net_util_md.h       2009-01-27 15:45:50.000000000 -0500
13108+++ ./jdk/src/solaris/native/java/net/net_util_md.h     2009-05-04 17:37:17.000000000 -0400
13109@@ -37,7 +37,7 @@
13110 #endif
13111 
13112 
13113-#ifdef __linux__
13114+#if defined(__linux__) || defined(__FreeBSD__)
13115 extern int NET_Timeout(int s, long timeout);
13116 extern int NET_Read(int s, void* buf, size_t len);
13117 extern int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
13118diff -upr ../orig/jdk/src/solaris/native/java/nio/MappedByteBuffer.c ./jdk/src/solaris/native/java/nio/MappedByteBuffer.c
13119--- ../orig/jdk/src/solaris/native/java/nio/MappedByteBuffer.c  2009-01-27 15:45:50.000000000 -0500
13120+++ ./jdk/src/solaris/native/java/nio/MappedByteBuffer.c        2009-05-04 17:37:17.000000000 -0400
13121@@ -38,7 +38,11 @@ Java_java_nio_MappedByteBuffer_isLoaded0
13122                                         jlong address, jlong len)
13123 {
13124     jboolean loaded = JNI_TRUE;
13125+#if defined(_ALLBSD_SOURCE)
13126+    jint pageSize = getpagesize();
13127+#else
13128     jint pageSize = sysconf(_SC_PAGESIZE);
13129+#endif
13130     jint numPages = (len + pageSize - 1) / pageSize;
13131     int result = 0;
13132     int i = 0;
13133@@ -92,7 +96,11 @@ JNIEXPORT void JNICALL
13134 Java_java_nio_MappedByteBuffer_force0(JNIEnv *env, jobject obj, jlong address,
13135                                       jlong len)
13136 {
13137+#if defined(_ALLBSD_SOURCE)
13138+    jlong pageSize = getpagesize();
13139+#else
13140     jlong pageSize = sysconf(_SC_PAGESIZE);
13141+#endif
13142     unsigned long lAddress = address;
13143 
13144     jlong offset = lAddress % pageSize;
13145diff -upr ../orig/jdk/src/solaris/native/java/util/FileSystemPreferences.c ./jdk/src/solaris/native/java/util/FileSystemPreferences.c
13146--- ../orig/jdk/src/solaris/native/java/util/FileSystemPreferences.c    2009-01-27 15:45:50.000000000 -0500
13147+++ ./jdk/src/solaris/native/java/util/FileSystemPreferences.c  2009-05-04 17:37:17.000000000 -0400
13148@@ -47,8 +47,11 @@ Java_java_util_prefs_FileSystemPreferenc
13149     return (jint) result;
13150 }
13151 
13152-
13153+#if defined(_ALLBSD_SOURCE)
13154+typedef struct flock FLOCK;
13155+#else
13156 typedef struct flock64 FLOCK;
13157+#endif
13158 
13159 /**
13160  * Try to open a named lock file.
13161@@ -86,7 +89,11 @@ Java_java_util_prefs_FileSystemPreferenc
13162     if (fd < 0) {
13163         result[0] = 0;
13164     } else {
13165+#if defined(_ALLBSD_SOURCE)
13166+        rc = fcntl(fd, F_SETLK, &fl);
13167+#else
13168         rc = fcntl(fd, F_SETLK64, &fl);
13169+#endif
13170         result[1] = errno;
13171         if (rc < 0) {
13172             result[0]= 0;
13173@@ -116,7 +123,11 @@ Java_java_util_prefs_FileSystemPreferenc
13174     fl.l_start = 0;
13175     fl.l_type = F_UNLCK;
13176 
13177+#if defined(_ALLBSD_SOURCE)
13178+    rc = fcntl(fd, F_SETLK, &fl);
13179+#else
13180     rc = fcntl(fd, F_SETLK64, &fl);
13181+#endif
13182 
13183     if (rc < 0) {
13184         close(fd);
13185diff -upr ../orig/jdk/src/solaris/native/java/util/TimeZone_md.c ./jdk/src/solaris/native/java/util/TimeZone_md.c
13186--- ../orig/jdk/src/solaris/native/java/util/TimeZone_md.c      2009-01-27 15:45:50.000000000 -0500
13187+++ ./jdk/src/solaris/native/java/util/TimeZone_md.c    2009-05-05 17:44:22.000000000 -0400
13188@@ -31,7 +31,7 @@
13189 #include <errno.h>
13190 #include <stddef.h>
13191 
13192-#ifdef __linux__
13193+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13194 #include <string.h>
13195 #include <dirent.h>
13196 #include <sys/stat.h>
13197@@ -49,11 +49,14 @@
13198 #define fileclose       fclose
13199 #endif
13200 
13201-#ifdef __linux__
13202+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13203 
13204+#ifdef __linux__
13205 static const char *sysconfig_clock_file = "/etc/sysconfig/clock";
13206+#endif
13207+
13208 static const char *zoneinfo_dir = "/usr/share/zoneinfo";
13209-static const char *defailt_zoneinfo_file = "/etc/localtime";
13210+static const char *default_zoneinfo_file = "/etc/localtime";
13211 
13212 /*
13213  * Returns a point to the zone ID portion of the given zoneinfo file
13214@@ -199,7 +202,9 @@ getPlatformTimeZoneID()
13215     int fd;
13216     char *buf;
13217     size_t size;
13218+    char zoneinfo_file[PATH_MAX+1];
13219 
13220+#ifdef __linux__
13221     /*
13222      * First, try the ZONE entry in /etc/sysconfig/clock. However, the
13223      * ZONE entry is not set up after initial Red Hat Linux
13224@@ -254,14 +259,18 @@ getPlatformTimeZoneID()
13225             return tz;
13226         }
13227     }
13228+#endif /* __linux__ */
13229 
13230     /*
13231      * Next, try /etc/localtime to find the zone ID.
13232      */
13233-    if (lstat(defailt_zoneinfo_file, &statbuf) == -1) {
13234+    if (lstat(default_zoneinfo_file, &statbuf) == -1) {
13235         return NULL;
13236     }
13237 
13238+    strlcpy(zoneinfo_file, default_zoneinfo_file, PATH_MAX+1);
13239+
13240+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13241     /*
13242      * If it's a symlink, get the link name and its zone ID part. (The
13243      * older versions of timeconfig created a symlink as described in
13244@@ -270,21 +279,25 @@ getPlatformTimeZoneID()
13245      * from /etc/localtime.)
13246      */
13247     if (S_ISLNK(statbuf.st_mode)) {
13248-        char linkbuf[PATH_MAX+1];
13249         int len;
13250 
13251-        if ((len = readlink(defailt_zoneinfo_file, linkbuf, sizeof(linkbuf)-1)) == -1) {
13252+       if ((len = readlink(default_zoneinfo_file, zoneinfo_file, sizeof(zoneinfo_file)-1)) == -1) {
13253             jio_fprintf(stderr, (const char *) "can't get a symlink of %s\n",
13254-                        defailt_zoneinfo_file);
13255+                        default_zoneinfo_file);
13256             return NULL;
13257         }
13258-        linkbuf[len] = '\0';
13259-        tz = getZoneName(linkbuf);
13260+       zoneinfo_file[len] = '\0';
13261+       tz = getZoneName(zoneinfo_file);
13262         if (tz != NULL) {
13263             tz = strdup(tz);
13264+           return tz;
13265+       } else {
13266+           if (lstat(zoneinfo_file, &statbuf) == -1) {
13267+               return NULL;
13268+           }
13269         }
13270-        return tz;
13271     }
13272+#endif /* __linux__ || _ALLBSD_SOURCE */
13273 
13274     /*
13275      * If it's a regular file, we need to find out the same zoneinfo file
13276@@ -295,7 +308,7 @@ getPlatformTimeZoneID()
13277     if (buf == NULL) {
13278         return NULL;
13279     }
13280-    if ((fd = open(defailt_zoneinfo_file, O_RDONLY)) == -1) {
13281+    if ((fd = open(zoneinfo_file, O_RDONLY)) == -1) {
13282         free((void *) buf);
13283         return NULL;
13284     }
13285@@ -524,7 +537,7 @@ findJavaTZ_md(const char *java_home_dir,
13286 
13287     tz = getenv("TZ");
13288 
13289-#ifdef __linux__
13290+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13291     if (tz == NULL) {
13292 #else
13293 #ifdef __solaris__
13294@@ -563,19 +576,32 @@ getGMTOffsetID()
13295 {
13296     time_t offset;
13297     char sign, buf[16];
13298+#if defined(_ALLBSD_SOURCE)
13299+    struct tm *local_tm;
13300+    time_t clock;
13301+
13302+    clock = time(NULL);
13303+    tzset();
13304+    local_tm = localtime(&clock);
13305+    if (local_tm->tm_gmtoff >= 0) {
13306+       offset = (time_t) local_tm->tm_gmtoff;
13307+       sign = '+';
13308+    } else {
13309+       offset = (time_t) -local_tm->tm_gmtoff;
13310+       sign = '-';
13311+    }
13312+#else
13313 
13314     if (timezone == 0) {
13315         return strdup("GMT");
13316-    }
13317-
13318-    /* Note that the time offset direction is opposite. */
13319-    if (timezone > 0) {
13320+    } else if (timezone > 0) {
13321         offset = timezone;
13322         sign = '-';
13323     } else {
13324         offset = -timezone;
13325         sign = '+';
13326     }
13327+#endif
13328     sprintf(buf, (const char *)"GMT%c%02d:%02d",
13329             sign, (int)(offset/3600), (int)((offset%3600)/60));
13330     return strdup(buf);
13331diff -upr ../orig/jdk/src/solaris/native/sun/awt/CUPSfuncs.c ./jdk/src/solaris/native/sun/awt/CUPSfuncs.c
13332--- ../orig/jdk/src/solaris/native/sun/awt/CUPSfuncs.c  2009-01-27 15:45:50.000000000 -0500
13333+++ ./jdk/src/solaris/native/sun/awt/CUPSfuncs.c        2009-05-04 17:37:17.000000000 -0400
13334@@ -25,6 +25,7 @@
13335 
13336 #include <jni.h>
13337 #include <jni_util.h>
13338+#include <jvm_md.h>
13339 #include <dlfcn.h>
13340 #include <cups/cups.h>
13341 #include <cups/ppd.h>
13342@@ -65,10 +66,11 @@ fn_ppdPageSize j2d_ppdPageSize;
13343 JNIEXPORT jboolean JNICALL
13344 Java_sun_print_CUPSPrinter_initIDs(JNIEnv *env,
13345                                          jobject printObj) {
13346-  void *handle = dlopen("libcups.so.2", RTLD_LAZY | RTLD_GLOBAL);
13347+  void *handle = dlopen(VERSIONED_JNI_LIB_NAME("cups", "2"),
13348+                        RTLD_LAZY | RTLD_GLOBAL);
13349 
13350   if (handle == NULL) {
13351-    handle = dlopen("libcups.so", RTLD_LAZY | RTLD_GLOBAL);
13352+    handle = dlopen(JNI_LIB_NAME("cups"), RTLD_LAZY | RTLD_GLOBAL);
13353     if (handle == NULL) {
13354       return JNI_FALSE;
13355     }
13356diff -upr ../orig/jdk/src/solaris/native/sun/awt/VDrawingArea.c ./jdk/src/solaris/native/sun/awt/VDrawingArea.c
13357--- ../orig/jdk/src/solaris/native/sun/awt/VDrawingArea.c       2009-01-27 15:45:50.000000000 -0500
13358+++ ./jdk/src/solaris/native/sun/awt/VDrawingArea.c     2009-05-04 17:37:17.000000000 -0400
13359@@ -31,7 +31,11 @@
13360 #endif /* !HEADLESS */
13361 
13362 #include <stdio.h>
13363+#if defined(_ALLBSD_SOURCE)
13364+#include <stdlib.h>
13365+#else
13366 #include <malloc.h>
13367+#endif
13368 
13369 #ifdef __linux__
13370 /* XXX: Shouldn't be necessary. */
13371diff -upr ../orig/jdk/src/solaris/native/sun/awt/X11Color.c ./jdk/src/solaris/native/sun/awt/X11Color.c
13372--- ../orig/jdk/src/solaris/native/sun/awt/X11Color.c   2009-01-27 15:45:50.000000000 -0500
13373+++ ./jdk/src/solaris/native/sun/awt/X11Color.c 2009-05-04 17:37:17.000000000 -0400
13374@@ -33,7 +33,9 @@
13375 #include <math.h>
13376 #include <sys/time.h>
13377 #include <sys/resource.h>
13378+#if !defined(_ALLBSD_SOURCE)
13379 #include <alloca.h>
13380+#endif
13381 #ifndef HEADLESS
13382 #include <X11/Xlib.h>
13383 #include <X11/Xatom.h>
13384diff -upr ../orig/jdk/src/solaris/native/sun/awt/XDrawingArea.c ./jdk/src/solaris/native/sun/awt/XDrawingArea.c
13385--- ../orig/jdk/src/solaris/native/sun/awt/XDrawingArea.c       2009-01-27 15:45:50.000000000 -0500
13386+++ ./jdk/src/solaris/native/sun/awt/XDrawingArea.c     2009-05-04 17:37:17.000000000 -0400
13387@@ -30,7 +30,11 @@
13388 #include <Xm/XmP.h>
13389 
13390 #include <stdio.h>
13391+#if defined(_ALLBSD_SOURCE)
13392+#include <stdlib.h>
13393+#else
13394 #include <malloc.h>
13395+#endif
13396 
13397 #ifdef DEBUG
13398 #include <jvm.h>  /* To get jio_fprintf() */
13399diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_Font.c ./jdk/src/solaris/native/sun/awt/awt_Font.c
13400--- ../orig/jdk/src/solaris/native/sun/awt/awt_Font.c   2009-01-27 15:45:50.000000000 -0500
13401+++ ./jdk/src/solaris/native/sun/awt/awt_Font.c 2009-05-04 17:37:17.000000000 -0400
13402@@ -334,7 +334,7 @@ loadFont(Display * display, char *name,
13403             if (strcmp(style, "regular") == 0) {
13404                 altstyle = "roman";
13405             }
13406-#ifdef __linux__
13407+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13408             if (!strcmp(family, "lucidasans")) {
13409                 family = "lucida";
13410             }
13411diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c ./jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c
13412--- ../orig/jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c    2009-01-27 15:45:50.000000000 -0500
13413+++ ./jdk/src/solaris/native/sun/awt/awt_GraphicsEnv.c  2009-05-04 17:37:17.000000000 -0400
13414@@ -40,6 +40,7 @@
13415 #include <jni.h>
13416 #include <jni_util.h>
13417 #include <jvm.h>
13418+#include <jvm_md.h>
13419 #include <jlong.h>
13420 
13421 #include <stdlib.h>
13422@@ -51,6 +52,8 @@
13423 #include <dlfcn.h>
13424 #include "Trace.h"
13425 
13426+#include "jvm_md.h"
13427+
13428 #ifdef NETSCAPE
13429 #include <signal.h>
13430 extern int awt_init_xt;
13431@@ -122,7 +125,7 @@ static char *x11GraphicsConfigClassName
13432  */
13433 
13434 #define MAXFRAMEBUFFERS 16
13435-#ifdef __linux__
13436+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13437 typedef struct {
13438    int   screen_number;
13439    short x_org;
13440@@ -631,19 +634,22 @@ void checkNewXineramaScreen(JNIEnv* env,
13441 #endif /* HEADLESS */
13442 
13443 #ifndef HEADLESS
13444-#ifdef __linux__
13445+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13446 static void xinerama_init_linux()
13447 {
13448-    void* libHandle = 0;
13449-    char* XineramaLibName= "libXinerama.so.1";
13450+    void* libHandle = NULL;
13451     int32_t locNumScr = 0;
13452     XineramaScreenInfo *xinInfo;
13453     char* XineramaQueryScreensName = "XineramaQueryScreens";
13454     XineramaQueryScreensFunc* XineramaQueryScreens = NULL;
13455 
13456     /* load library */
13457-    libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL);
13458-    if (libHandle != 0) {
13459+    libHandle = dlopen(VERSIONED_JNI_LIB_NAME("Xinerama", "1"),
13460+                       RTLD_LAZY | RTLD_GLOBAL);
13461+    if (libHandle == NULL) {
13462+        libHandle = dlopen(JNI_LIB_NAME("Xinerama"), RTLD_LAZY | RTLD_GLOBAL);
13463+    }
13464+    if (libHandle != NULL) {
13465         XineramaQueryScreens = (XineramaQueryScreensFunc*)
13466             dlsym(libHandle, XineramaQueryScreensName);
13467 
13468@@ -679,11 +685,10 @@ static void xinerama_init_linux()
13469     }
13470 }
13471 #endif
13472-#ifndef __linux__ /* Solaris */
13473+#if !defined(__linux__) && !defined(_ALLBSD_SOURCE) /* Solaris */
13474 static void xinerama_init_solaris()
13475 {
13476-    void* libHandle = 0;
13477-    char* XineramaLibName= "libXext.so";
13478+    void* libHandle = NULL;
13479     unsigned char fbhints[MAXFRAMEBUFFERS];
13480     int32_t locNumScr = 0;
13481     /* load and run XineramaGetInfo */
13482@@ -692,8 +697,8 @@ static void xinerama_init_solaris()
13483     XineramaGetInfoFunc* XineramaSolarisFunc = NULL;
13484 
13485     /* load library */
13486-    libHandle = dlopen(XineramaLibName, RTLD_LAZY | RTLD_GLOBAL);
13487-    if (libHandle != 0) {
13488+    libHandle = dlopen(JNI_LIB_NAME("Xext"), RTLD_LAZY | RTLD_GLOBAL);
13489+    if (libHandle != NULL) {
13490         XineramaSolarisFunc = (XineramaGetInfoFunc*)dlsym(libHandle, XineramaGetInfoName);
13491         XineramaSolarisCenterFunc =
13492             (XineramaGetCenterHintFunc*)dlsym(libHandle, XineramaGetCenterHintName);
13493@@ -740,11 +745,11 @@ static void xineramaInit(void) {
13494     }
13495 
13496     DTRACE_PRINTLN("Xinerama extension is available");
13497-#ifdef __linux__
13498+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13499     xinerama_init_linux();
13500 #else /* Solaris */
13501     xinerama_init_solaris();
13502-#endif /* __linux__ */
13503+#endif /* __linux__ || _ALLBSD_SOURCE */
13504 }
13505 #endif /* HEADLESS */
13506 
13507@@ -1600,7 +1605,7 @@ Java_sun_awt_X11GraphicsEnvironment_getX
13508 {
13509     jobject point = NULL;
13510 #ifndef HEADLESS    /* return NULL in HEADLESS, Linux */
13511-#ifndef __linux__
13512+#if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
13513     int x,y;
13514 
13515     AWT_LOCK();
13516@@ -1613,7 +1618,7 @@ Java_sun_awt_X11GraphicsEnvironment_getX
13517         DTRACE_PRINTLN("unable to call XineramaSolarisCenterFunc: symbol is null");
13518     }
13519     AWT_FLUSH_UNLOCK();
13520-#endif /* __linux __ */
13521+#endif /* __linux __ || _ALLBSD_SOURCE */
13522 #endif /* HEADLESS */
13523     return point;
13524 }
13525@@ -1678,7 +1683,11 @@ X11GD_InitXrandrFuncs(JNIEnv *env)
13526 {
13527     int rr_maj_ver = 0, rr_min_ver = 0;
13528 
13529-    void *pLibRandR = dlopen("libXrandr.so.2", RTLD_LAZY | RTLD_LOCAL);
13530+    void *pLibRandR = dlopen(VERSIONED_JNI_LIB_NAME("Xrandr", "2"),
13531+                             RTLD_LAZY | RTLD_LOCAL);
13532+    if (pLibRandR == NULL) {
13533+        pLibRandR = dlopen(JNI_LIB_NAME("Xrandr"), RTLD_LAZY | RTLD_LOCAL);
13534+    }
13535     if (pLibRandR == NULL) {
13536         J2dRlsTraceLn(J2D_TRACE_ERROR,
13537                       "X11GD_InitXrandrFuncs: Could not open libXrandr.so.2");
13538diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_InputMethod.c ./jdk/src/solaris/native/sun/awt/awt_InputMethod.c
13539--- ../orig/jdk/src/solaris/native/sun/awt/awt_InputMethod.c    2009-01-27 15:45:50.000000000 -0500
13540+++ ./jdk/src/solaris/native/sun/awt/awt_InputMethod.c  2009-05-04 17:37:17.000000000 -0400
13541@@ -69,7 +69,7 @@ static void PreeditDrawCallback(XIC, XPo
13542                                 XIMPreeditDrawCallbackStruct *);
13543 static void PreeditCaretCallback(XIC, XPointer,
13544                                  XIMPreeditCaretCallbackStruct *);
13545-#ifdef __linux__
13546+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13547 static void StatusStartCallback(XIC, XPointer, XPointer);
13548 static void StatusDoneCallback(XIC, XPointer, XPointer);
13549 static void StatusDrawCallback(XIC, XPointer,
13550@@ -83,7 +83,7 @@ static void StatusDrawCallback(XIC, XPoi
13551 #define PreeditDoneIndex        1
13552 #define PreeditDrawIndex        2
13553 #define PreeditCaretIndex       3
13554-#ifdef __linux__
13555+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13556 #define StatusStartIndex        4
13557 #define StatusDoneIndex         5
13558 #define StatusDrawIndex         6
13559@@ -101,14 +101,14 @@ static XIMProc callback_funcs[NCALLBACKS
13560     (XIMProc)PreeditDoneCallback,
13561     (XIMProc)PreeditDrawCallback,
13562     (XIMProc)PreeditCaretCallback,
13563-#ifdef __linux__
13564+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13565     (XIMProc)StatusStartCallback,
13566     (XIMProc)StatusDoneCallback,
13567     (XIMProc)StatusDrawCallback,
13568 #endif
13569 };
13570 
13571-#ifdef __linux__
13572+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13573 #define MAX_STATUS_LEN  100
13574 typedef struct {
13575     Window   w;                /*status window id        */
13576@@ -148,7 +148,7 @@ typedef struct _X11InputMethodData {
13577 #endif /* XAWT */
13578     jobject     x11inputmethod; /* global ref to X11InputMethod instance */
13579                                 /* associated with the XIC */
13580-#ifdef __linux__
13581+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13582     StatusWindow *statusWindow; /* our own status window  */
13583 #else
13584 #ifndef XAWT
13585@@ -427,7 +427,7 @@ destroyX11InputMethodData(JNIEnv *env, X
13586 static void
13587 freeX11InputMethodData(JNIEnv *env, X11InputMethodData *pX11IMData)
13588 {
13589-#ifdef __linux__
13590+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13591     if (pX11IMData->statusWindow != NULL){
13592         StatusWindow *sw = pX11IMData->statusWindow;
13593         XFreeGC(awt_display, sw->lightGC);
13594@@ -533,7 +533,7 @@ awt_x11inputmethod_lookupString(XKeyPres
13595     pX11IMData = getX11InputMethodData(env, currentX11InputMethodInstance);
13596 
13597     if (pX11IMData == NULL) {
13598-#ifdef __linux__
13599+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13600         return False;
13601 #else
13602         return result;
13603@@ -541,7 +541,7 @@ awt_x11inputmethod_lookupString(XKeyPres
13604     }
13605 
13606     if ((ic = pX11IMData->current_ic) == (XIC)0){
13607-#ifdef __linux__
13608+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13609         return False;
13610 #else
13611         return result;
13612@@ -650,7 +650,7 @@ awt_x11inputmethod_lookupString(XKeyPres
13613     return result;
13614 }
13615 
13616-#ifdef __linux__
13617+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13618 static StatusWindow *createStatusWindow(
13619 #ifdef XAWT
13620                                 Window parent) {
13621@@ -994,7 +994,7 @@ void adjustStatusWindow(Widget shell){
13622         }
13623     }
13624 }
13625-#endif  /*__linux__*/
13626+#endif  /* __linux__ || _ALLBSD_SOURCE */
13627 /*
13628  * Creates two XICs, one for active clients and the other for passive
13629  * clients. All information on those XICs are stored in the
13630@@ -1051,7 +1051,7 @@ createXIC(Widget w, X11InputMethodData *
13631         return FALSE ;
13632     }
13633 
13634-#ifdef __linux__
13635+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13636     on_the_spot_styles |= XIMStatusNothing;
13637 
13638     /*kinput does not support XIMPreeditCallbacks and XIMStatusArea
13639@@ -1064,7 +1064,7 @@ createXIC(Widget w, X11InputMethodData *
13640             break;
13641         }
13642     }
13643-#else /*! __linux__ */
13644+#else /*! __linux__ && !_ALLBSD_SOURCE */
13645 #ifdef XAWT
13646     on_the_spot_styles |= XIMStatusNothing;
13647 #else /* !XAWT */
13648@@ -1087,7 +1087,7 @@ createXIC(Widget w, X11InputMethodData *
13649         on_the_spot_styles |= XIMStatusNothing;
13650 
13651 #endif /* XAWT */
13652-#endif /* __linux__ */
13653+#endif /* __linux__ || _ALLBSD_SOURCE */
13654 
13655     for (i = 0; i < im_styles->count_styles; i++) {
13656         active_styles |= im_styles->supported_styles[i] & on_the_spot_styles;
13657@@ -1135,7 +1135,7 @@ createXIC(Widget w, X11InputMethodData *
13658                         NULL);
13659         if (preedit == (XVaNestedList)NULL)
13660             goto err;
13661-#ifdef __linux__
13662+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13663         /*always try XIMStatusCallbacks for active client...*/
13664         {
13665             status = (XVaNestedList)XVaCreateNestedList(0,
13666@@ -1157,7 +1157,7 @@ createXIC(Widget w, X11InputMethodData *
13667             XFree((void *)status);
13668             XFree((void *)preedit);
13669         }
13670-#else /* !__linux__ */
13671+#else /* !__linux__ && !_ALLBSD_SOURCE */
13672 #ifndef XAWT
13673         if (on_the_spot_styles & XIMStatusArea) {
13674             Widget parent;
13675@@ -1185,7 +1185,7 @@ createXIC(Widget w, X11InputMethodData *
13676         }
13677 #endif /* XAWT */
13678         XFree((void *)preedit);
13679-#endif /* __linux__ */
13680+#endif /* __linux__ || _ALLBSD_SOURCE */
13681         pX11IMData->ic_passive = XCreateIC(X11im,
13682                                            XNClientWindow, XtWindow(w),
13683                                            XNFocusWindow, XtWindow(w),
13684@@ -1344,7 +1344,7 @@ PreeditCaretCallback(XIC ic, XPointer cl
13685 
13686 }
13687 
13688-#ifdef __linux__
13689+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13690 static void
13691 StatusStartCallback(XIC ic, XPointer client_data, XPointer call_data)
13692 {
13693@@ -1412,7 +1412,7 @@ StatusDrawCallback(XIC ic, XPointer clie
13694  finally:
13695     AWT_UNLOCK();
13696 }
13697-#endif /*__linux__*/
13698+#endif /* __linux__ || _ALLBSD_SOURCE */
13699 
13700 static void CommitStringCallback(XIC ic, XPointer client_data, XPointer call_data) {
13701     JNIEnv *env = GetJNIEnv();
13702@@ -1522,14 +1522,14 @@ Java_sun_awt_motif_MInputMethod_openXIMN
13703 /* Use IMInstantiate call back only on Linux, as there is a bug in Solaris
13704    (4768335)
13705 */
13706-#ifdef __linux__
13707+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13708     registered = XRegisterIMInstantiateCallback(dpy, NULL, NULL,
13709                      NULL, (XIMProc)OpenXIMCallback, NULL);
13710     if (!registered) {
13711         /* directly call openXIM callback */
13712 #endif
13713         OpenXIMCallback(dpy, NULL, NULL);
13714-#ifdef __linux__
13715+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13716     }
13717 #endif
13718 
13719@@ -1593,13 +1593,13 @@ Java_sun_awt_motif_MInputMethod_createXI
13720 #endif /* XAWT */
13721     globalRef = (*env)->NewGlobalRef(env, this);
13722     pX11IMData->x11inputmethod = globalRef;
13723-#ifdef __linux__
13724+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13725     pX11IMData->statusWindow = NULL;
13726-#else /* __linux__ */
13727+#else /* !__linux__ && !_ALLBSD_SOURCE */
13728 #ifndef XAWT
13729     pX11IMData->statusWidget = (Widget) NULL;
13730 #endif /* XAWT */
13731-#endif /* __linux__ */
13732+#endif /* __linux__ || _ALLBSD_SOURCE */
13733 
13734     pX11IMData->lookup_buf = 0;
13735     pX11IMData->lookup_buf_len = 0;
13736@@ -1746,14 +1746,14 @@ Java_sun_awt_X11_XInputMethod_setXICFocu
13737         setXICFocus(pX11IMData->current_ic, req);
13738         currentX11InputMethodInstance = pX11IMData->x11inputmethod;
13739         currentFocusWindow =  XtWindow(w);
13740-#ifdef __linux__
13741+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13742         if (active && pX11IMData->statusWindow && pX11IMData->statusWindow->on)
13743             onoffStatusWindow(pX11IMData, w, True);
13744 #endif
13745     } else {
13746         currentX11InputMethodInstance = NULL;
13747         currentFocusWindow = 0;
13748-#ifdef __linux__
13749+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13750         onoffStatusWindow(pX11IMData, 0, False);
13751         if (pX11IMData->current_ic != NULL)
13752 #endif
13753@@ -1770,7 +1770,7 @@ JNIEXPORT void JNICALL
13754 Java_sun_awt_X11InputMethod_turnoffStatusWindow(JNIEnv *env,
13755                                                 jobject this)
13756 {
13757-#ifdef __linux__
13758+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13759     X11InputMethodData *pX11IMData;
13760     StatusWindow *statusWindow;
13761 
13762@@ -1867,7 +1867,7 @@ Java_sun_awt_motif_MInputMethod_configur
13763     X11InputMethodData *pX11IMData;
13764     XVaNestedList status;
13765 
13766-#ifdef __linux__
13767+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13768       /*do nothing for linux? */
13769 #else
13770     AWT_LOCK();
13771@@ -1973,7 +1973,7 @@ JNIEXPORT jboolean JNICALL Java_sun_awt_
13772 JNIEXPORT void JNICALL Java_sun_awt_X11_XInputMethod_adjustStatusWindow
13773   (JNIEnv *env, jobject this, jlong window)
13774 {
13775-#ifdef __linux__
13776+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13777     AWT_LOCK();
13778     adjustStatusWindow(window);
13779     AWT_UNLOCK();
13780diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c ./jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c
13781--- ../orig/jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c    2009-01-27 15:45:50.000000000 -0500
13782+++ ./jdk/src/solaris/native/sun/awt/awt_LoadLibrary.c  2009-05-04 17:37:17.000000000 -0400
13783@@ -260,7 +260,11 @@ AWT_OnLoad(JavaVM *vm, void *reserved)
13784         }
13785     }
13786 
13787+#ifdef __APPLE__
13788+    strcat(p, ".dylib");
13789+#else
13790     strcat(p, ".so");
13791+#endif
13792 
13793     JNU_CallStaticMethodByName(env, NULL, "java/lang/System", "load",
13794                                "(Ljava/lang/String;)V",
13795diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_MToolkit.c ./jdk/src/solaris/native/sun/awt/awt_MToolkit.c
13796--- ../orig/jdk/src/solaris/native/sun/awt/awt_MToolkit.c       2009-01-27 15:45:50.000000000 -0500
13797+++ ./jdk/src/solaris/native/sun/awt/awt_MToolkit.c     2009-05-04 17:37:17.000000000 -0400
13798@@ -63,8 +63,9 @@
13799 extern JavaVM *jvm;
13800 
13801 #ifndef HEADLESS
13802-#ifdef __linux__
13803+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13804 extern void statusWindowEventHandler(XEvent event);
13805+Boolean awt_dnd_process_event(XEvent* event);
13806 #endif
13807 #endif /* !HEADLESS */
13808 
13809@@ -1642,7 +1643,7 @@ processOneEvent(XtInputMask iMask) {
13810               */
13811               Widget widget=XtWindowToWidget(awt_display, xev.xany.window);
13812               eventNumber++;
13813-#ifdef __linux__
13814+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13815               statusWindowEventHandler(xev);
13816 #endif
13817               xembed_eventHandler(&xev);
13818diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_Mlib.c ./jdk/src/solaris/native/sun/awt/awt_Mlib.c
13819--- ../orig/jdk/src/solaris/native/sun/awt/awt_Mlib.c   2009-01-27 15:45:50.000000000 -0500
13820+++ ./jdk/src/solaris/native/sun/awt/awt_Mlib.c 2009-05-04 17:37:17.000000000 -0400
13821@@ -32,6 +32,7 @@
13822 #include <dlfcn.h>
13823 #include "jni.h"
13824 #include <jni_util.h>
13825+#include "jvm_md.h"
13826 #include "awt_Mlib.h"
13827 #include "java_awt_image_BufferedImage.h"
13828 
13829@@ -67,11 +68,11 @@ mlib_status awt_getImagingLib(JNIEnv *en
13830         ((strncmp(name.machine, "sun4v" , 5) == 0) &&
13831          (getenv("USE_VIS_ON_SUN4V") != NULL)))
13832     {
13833-        handle = dlopen("libmlib_image_v.so", RTLD_LAZY);
13834+        handle = dlopen(JNI_LIB_NAME("mlib_image_v"), RTLD_LAZY);
13835     }
13836 
13837     if (handle == NULL) {
13838-        handle = dlopen("libmlib_image.so", RTLD_LAZY);
13839+        handle = dlopen(JNI_LIB_NAME("mlib_image"), RTLD_LAZY);
13840     }
13841 
13842     if (handle == NULL) {
13843diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_Robot.c ./jdk/src/solaris/native/sun/awt/awt_Robot.c
13844--- ../orig/jdk/src/solaris/native/sun/awt/awt_Robot.c  2009-01-27 15:45:50.000000000 -0500
13845+++ ./jdk/src/solaris/native/sun/awt/awt_Robot.c        2009-05-04 17:37:17.000000000 -0400
13846@@ -45,7 +45,7 @@
13847 #include "wsutils.h"
13848 #include "list.h"
13849 #include "multiVis.h"
13850-#ifdef __linux__
13851+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13852 #include <sys/socket.h>
13853 #endif
13854 
13855diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_util.h ./jdk/src/solaris/native/sun/awt/awt_util.h
13856--- ../orig/jdk/src/solaris/native/sun/awt/awt_util.h   2009-01-27 15:45:50.000000000 -0500
13857+++ ./jdk/src/solaris/native/sun/awt/awt_util.h 2009-05-04 17:37:17.000000000 -0400
13858@@ -187,15 +187,20 @@ JNU_GetCharField(JNIEnv *env, jobject se
13859 #ifdef __solaris__
13860 extern Widget awt_util_getXICStatusAreaWindow(Widget w);
13861 #else
13862+#if defined(_ALLBSD_SOURCE)
13863+int32_t awt_util_getIMStatusHeight(Widget vw);
13864+Widget awt_util_getXICStatusAreaWindow(Widget w);
13865+#else
13866 int32_t awt_util_getIMStatusHeight(Widget vw);
13867 XVaNestedList awt_util_getXICStatusAreaList(Widget w);
13868 Widget awt_util_getXICStatusAreaWindow(Widget w);
13869 #endif
13870+#endif
13871 
13872 
13873 
13874 
13875-#ifdef __linux__
13876+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
13877 typedef struct _XmImRefRec {
13878   Cardinal      num_refs;       /* Number of referencing widgets. */
13879   Cardinal      max_refs;       /* Maximum length of refs array. */
13880diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_wm.c ./jdk/src/solaris/native/sun/awt/awt_wm.c
13881--- ../orig/jdk/src/solaris/native/sun/awt/awt_wm.c     2009-01-27 15:45:50.000000000 -0500
13882+++ ./jdk/src/solaris/native/sun/awt/awt_wm.c   2009-05-04 17:37:17.000000000 -0400
13883@@ -121,12 +121,19 @@ static Atom XA_KWM_WIN_ICONIFIED;
13884 static Atom XA_KWM_WIN_MAXIMIZED;
13885 
13886 /* OpenLook */
13887+static Atom _XA_OL_DECOR_ADD;
13888 static Atom _XA_OL_DECOR_DEL;
13889 static Atom _XA_OL_DECOR_HEADER;
13890 static Atom _XA_OL_DECOR_RESIZE;
13891 static Atom _XA_OL_DECOR_PIN;
13892 static Atom _XA_OL_DECOR_CLOSE;
13893 
13894+/* AfterStep */
13895+static Atom _XA_AS_STYLE;
13896+
13897+/* WindowMaker */
13898+static Atom _XA_WINDOWMAKER_STATE;
13899+
13900 /* For _NET_WM_STATE ClientMessage requests */
13901 #define _NET_WM_STATE_REMOVE    0 /* remove/unset property */
13902 #define _NET_WM_STATE_ADD       1 /* add/set property      */
13903@@ -193,7 +200,12 @@ awt_wm_initAtoms(void)
13904         { &_XA_OL_DECOR_HEADER,              "_OL_DECOR_HEADER"              },
13905         { &_XA_OL_DECOR_RESIZE,              "_OL_DECOR_RESIZE"              },
13906         { &_XA_OL_DECOR_PIN,                 "_OL_DECOR_PIN"                 },
13907-        { &_XA_OL_DECOR_CLOSE,               "_OL_DECOR_CLOSE"               }
13908+        { &_XA_OL_DECOR_CLOSE,               "_OL_DECOR_CLOSE"               },
13909+       { &_XA_OL_DECOR_ADD,                 "_OL_DECOR_ADD"                 },
13910+
13911+       { &_XA_AS_STYLE,                     "_XA_AS_STYLE"                  },
13912+
13913+       { &_XA_WINDOWMAKER_STATE,            "_XA_WINDOWMAKER_STATE"         }
13914     };
13915 #define ATOM_LIST_LENGTH (sizeof(atom_list)/sizeof(atom_list[0]))
13916 
13917@@ -942,6 +954,39 @@ awt_wm_isMotif(void)
13918     return True;
13919 }
13920 
13921+/*
13922+ * Window Maker.
13923+ */
13924+static Boolean
13925+awt_wm_isWindowmaker()
13926+{
13927+    if (awt_wm_atomInterned(&_XA_WINDOWMAKER_STATE, "_WINDOWMAKER_STATE"))
13928+        return True;
13929+    return False;
13930+}
13931+
13932+/*
13933+ * Afterstep.
13934+ */
13935+static Boolean
13936+awt_wm_isAfterstep()
13937+{
13938+    if (awt_wm_atomInterned(&_XA_AS_STYLE, "_AS_STYLE"))
13939+        return True;
13940+    return False;
13941+}
13942+
13943+/*
13944+ * FVWM 2.
13945+ */
13946+static Boolean
13947+awt_wm_isFvwm2()
13948+{
13949+    if (awt_wm_atomInterned(&_XA_OL_DECOR_ADD, "_OL_DECOR_ADD")
13950+        && !awt_wm_atomInterned(&_XA_OL_DECOR_PIN, "_OL_DECOR_PIN"))
13951+        return True;
13952+    return False;
13953+}
13954 
13955 static Boolean
13956 awt_wm_isNetWMName(char *name)
13957@@ -1280,6 +1325,12 @@ awt_wm_getRunningWM(void)
13958     else if (awt_wm_isKDE2()) {
13959         awt_wmgr = KDE2_WM;
13960     }
13961+    else if (awt_wm_isWindowmaker()) {
13962+       awt_wmgr = WINDOWMAKER_WM;
13963+    }
13964+    else if (awt_wm_isAfterstep()) {
13965+       awt_wmgr = AFTERSTEP_WM;
13966+    }
13967     /*
13968      * We don't check for legacy WM when we already know that WM
13969      * supports WIN or _NET wm spec.
13970@@ -1302,6 +1353,9 @@ awt_wm_getRunningWM(void)
13971         awt_wmgr = MOTIF_WM;
13972     }
13973     else if (awt_wm_isOpenLook()) {
13974+       awt_wmgr = OPENLOOK_WM;
13975+    }
13976+    else if (awt_wm_isFvwm2()) {
13977         awt_wmgr = OPENLOOK_WM;
13978     }
13979     else {
13980diff -upr ../orig/jdk/src/solaris/native/sun/awt/awt_wm.h ./jdk/src/solaris/native/sun/awt/awt_wm.h
13981--- ../orig/jdk/src/solaris/native/sun/awt/awt_wm.h     2009-01-27 15:45:50.000000000 -0500
13982+++ ./jdk/src/solaris/native/sun/awt/awt_wm.h   2009-05-04 17:37:17.000000000 -0400
13983@@ -45,7 +45,10 @@ enum wmgr_t {
13984     KDE2_WM,
13985     SAWFISH_WM,
13986     ICE_WM,
13987-    METACITY_WM
13988+    METACITY_WM,
13989+    AFTERSTEP_WM,
13990+    WINDOWMAKER_WM,
13991+    FVWM2_WM
13992 };
13993 
13994 extern void awt_wm_init(void);
13995diff -upr ../orig/jdk/src/solaris/native/sun/awt/extutil.h ./jdk/src/solaris/native/sun/awt/extutil.h
13996--- ../orig/jdk/src/solaris/native/sun/awt/extutil.h    2009-01-27 15:45:50.000000000 -0500
13997+++ ./jdk/src/solaris/native/sun/awt/extutil.h  2009-05-04 17:37:17.000000000 -0400
13998@@ -58,7 +58,7 @@ in this Software without prior written a
13999  */
14000 /* $XFree86: xc/include/extensions/extutil.h,v 1.5 2001/01/17 17:53:20 dawes Exp $ */
14001 
14002-#ifdef __linux__
14003+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14004 
14005 #ifndef _EXTUTIL_H_
14006 #define _EXTUTIL_H_
14007@@ -248,4 +248,4 @@ char *proc (Display *dpy, int code, XExt
14008         char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n)
14009 #endif
14010 
14011-#endif /* __linux__ */
14012+#endif /* __linux__ || _ALLBSD_SOURCE */
14013diff -upr ../orig/jdk/src/solaris/native/sun/awt/fontpath.c ./jdk/src/solaris/native/sun/awt/fontpath.c
14014--- ../orig/jdk/src/solaris/native/sun/awt/fontpath.c   2009-01-27 15:45:50.000000000 -0500
14015+++ ./jdk/src/solaris/native/sun/awt/fontpath.c 2009-05-04 17:37:17.000000000 -0400
14016@@ -23,7 +23,7 @@
14017  * have any questions.
14018  */
14019 
14020-#ifdef __linux__
14021+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14022 #include <string.h>
14023 #endif /* __linux__ */
14024 #include <stdio.h>
14025@@ -40,6 +40,7 @@
14026 
14027 #include <jni.h>
14028 #include <jni_util.h>
14029+#include <jvm_md.h>
14030 #include <sun_font_FontManager.h>
14031 #ifndef HEADLESS
14032 #include <X11/Xlib.h>
14033@@ -58,10 +59,24 @@
14034 extern Display *awt_display;
14035 #endif /* !HEADLESS */
14036 
14037+#ifdef __APPLE__
14038+// XXXDARWIN: Hard-code the path to Apple's freetype, as it is
14039+// not included in the dyld search path by default, and 10.4
14040+// does not support -rpath.
14041+//
14042+// This ignores the build time setting of ALT_FREETYPE_LIB_PATH,
14043+// and should be replaced with -rpath/@rpath support on 10.5 or later,
14044+// or via support for a the FREETYPE_LIB_PATH define.
14045+#define FONTCONFIG_DLL_VERSIONED X11_PATH "/lib/" VERSIONED_JNI_LIB_NAME("fontconfig", "1")
14046+#define FONTCONFIG_DLL X11_PATH "/lib/" JNI_LIB_NAME("fontconfig")
14047+#else
14048+#define FONTCONFIG_DLL_VERSIONED VERSIONED_JNI_LIB_NAME("fontconfig", "1")
14049+#define FONTCONFIG_DLL JNI_LIB_NAME("fontconfig")
14050+#endif
14051 
14052 #define MAXFDIRS 512    /* Max number of directories that contain fonts */
14053 
14054-#ifndef __linux__
14055+#if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
14056 /*
14057  * This can be set in the makefile to "/usr/X11" if so desired.
14058  */
14059@@ -111,24 +126,40 @@ static char *fullSolarisFontPath[] = {
14060     NULL, /* terminates the list */
14061 };
14062 
14063+#elif _ALLBSD_SOURCE
14064+static char *fullBSDFontPath[] = {
14065+    X11_PATH "/lib/X11/fonts/TrueType",
14066+    X11_PATH "/lib/X11/fonts/truetype",
14067+    X11_PATH "/lib/X11/fonts/tt",
14068+    X11_PATH "/lib/X11/fonts/TTF",
14069+    X11_PATH "/lib/X11/fonts/OTF",
14070+    PACKAGE_PATH "/share/fonts/TrueType",
14071+    PACKAGE_PATH "/share/fonts/truetype",
14072+    PACKAGE_PATH "/share/fonts/tt",
14073+    PACKAGE_PATH "/share/fonts/TTF",
14074+    PACKAGE_PATH "/share/fonts/OTF",
14075+    X11_PATH "/lib/X11/fonts/Type1",
14076+    PACKAGE_PATH "/share/fonts/Type1",
14077+    NULL, /* terminates the list */
14078+};
14079 #else /* __linux */
14080 /* All the known interesting locations we have discovered on
14081  * various flavors of Linux
14082  */
14083 static char *fullLinuxFontPath[] = {
14084-    "/usr/X11R6/lib/X11/fonts/TrueType",  /* RH 7.1+ */
14085-    "/usr/X11R6/lib/X11/fonts/truetype",  /* SuSE */
14086-    "/usr/X11R6/lib/X11/fonts/tt",
14087-    "/usr/X11R6/lib/X11/fonts/TTF",
14088-    "/usr/X11R6/lib/X11/fonts/OTF",       /* RH 9.0 (but empty!) */
14089-    "/usr/share/fonts/ja/TrueType",       /* RH 7.2+ */
14090-    "/usr/share/fonts/truetype",
14091-    "/usr/share/fonts/ko/TrueType",       /* RH 9.0 */
14092-    "/usr/share/fonts/zh_CN/TrueType",    /* RH 9.0 */
14093-    "/usr/share/fonts/zh_TW/TrueType",    /* RH 9.0 */
14094+    X11_PATH "/lib/X11/fonts/TrueType",  /* RH 7.1+ */
14095+    X11_PATH "/lib/X11/fonts/truetype",  /* SuSE */
14096+    X11_PATH "/lib/X11/fonts/tt",
14097+    X11_PATH "/lib/X11/fonts/TTF",
14098+    X11_PATH "/lib/X11/fonts/OTF",       /* RH 9.0 (but empty!) */
14099+    PACKAGE_PATH "/share/fonts/ja/TrueType",       /* RH 7.2+ */
14100+    PACKAGE_PATH "/share/fonts/truetype",
14101+    PACKAGE_PATH "/share/fonts/ko/TrueType",       /* RH 9.0 */
14102+    PACKAGE_PATH "/share/fonts/zh_CN/TrueType",    /* RH 9.0 */
14103+    PACKAGE_PATH "/share/fonts/zh_TW/TrueType",    /* RH 9.0 */
14104     "/var/lib/defoma/x-ttcidfont-conf.d/dirs/TrueType", /* Debian */
14105-    "/usr/X11R6/lib/X11/fonts/Type1",
14106-    "/usr/share/fonts/default/Type1",     /* RH 9.0 */
14107+    X11_PATH "/lib/X11/fonts/Type1",
14108+    PACKAGE_PATH "/share/fonts/default/Type1",     /* RH 9.0 */
14109     NULL, /* terminates the list */
14110 };
14111 #endif
14112@@ -351,7 +382,7 @@ static char **getX11FontPath ()
14113 
14114 #endif /* !HEADLESS */
14115 
14116-#ifdef __linux__
14117+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14118 /* from awt_LoadLibrary.c */
14119 JNIEXPORT jboolean JNICALL AWTIsHeadless();
14120 #endif
14121@@ -476,8 +507,10 @@ static char *getPlatformFontPathChars(JN
14122      */
14123     fcdirs = getFontConfigLocations();
14124 
14125-#ifdef __linux__
14126+#if defined(__linux__)
14127     knowndirs = fullLinuxFontPath;
14128+#elif defined(_ALLBSD_SOURCE)
14129+    knowndirs = fullBSDFontPath;
14130 #else /* IF SOLARIS */
14131     knowndirs = fullSolarisFontPath;
14132 #endif
14133@@ -488,7 +521,8 @@ static char *getPlatformFontPathChars(JN
14134      * be initialised.
14135      */
14136 #ifndef HEADLESS
14137-#ifdef __linux__        /* There's no headless build on linux ... */
14138+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14139+    /* There's no headless build on linux ... */
14140     if (!AWTIsHeadless()) { /* .. so need to call a function to check */
14141 #endif
14142     AWT_LOCK();
14143@@ -496,7 +530,7 @@ static char *getPlatformFontPathChars(JN
14144         x11dirs = getX11FontPath();
14145     }
14146     AWT_UNLOCK();
14147-#ifdef __linux__
14148+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14149     }
14150 #endif
14151 #endif /* !HEADLESS */
14152@@ -608,7 +642,7 @@ Java_sun_font_FontManager_populateFontFi
14153 }
14154 
14155 #include <dlfcn.h>
14156-#ifndef __linux__ /* i.e. is solaris */
14157+#if !(defined(__linux__) || defined(__APPLE__))
14158 #include <link.h>
14159 #endif
14160 
14161@@ -654,9 +688,9 @@ static void* openFontConfig() {
14162      * certain symbols - and functionality - to be available.
14163      * Also add explicit search for .so.1 in case .so symlink doesn't exist.
14164      */
14165-    libfontconfig = dlopen("libfontconfig.so.1", RTLD_LOCAL|RTLD_LAZY);
14166+    libfontconfig = dlopen(FONTCONFIG_DLL_VERSIONED, RTLD_LOCAL|RTLD_LAZY);
14167     if (libfontconfig == NULL) {
14168-        libfontconfig = dlopen("libfontconfig.so", RTLD_LOCAL|RTLD_LAZY);
14169+        libfontconfig = dlopen(FONTCONFIG_DLL, RTLD_LOCAL|RTLD_LAZY);
14170         if (libfontconfig == NULL) {
14171             return NULL;
14172         }
14173diff -upr ../orig/jdk/src/solaris/native/sun/awt/gtk2_interface.c ./jdk/src/solaris/native/sun/awt/gtk2_interface.c
14174--- ../orig/jdk/src/solaris/native/sun/awt/gtk2_interface.c     2009-01-27 15:45:50.000000000 -0500
14175+++ ./jdk/src/solaris/native/sun/awt/gtk2_interface.c   2009-05-04 17:37:17.000000000 -0400
14176@@ -30,8 +30,9 @@
14177 #include <string.h>
14178 #include "gtk2_interface.h"
14179 #include "java_awt_Transparency.h"
14180+#include "jvm_md.h"
14181 
14182-#define GTK2_LIB "libgtk-x11-2.0.so.0"
14183+#define GTK2_LIB VERSIONED_JNI_LIB_NAME("gtk-x11-2.0", "0")
14184 
14185 #define G_TYPE_INVALID                  G_TYPE_MAKE_FUNDAMENTAL (0)
14186 #define G_TYPE_NONE                     G_TYPE_MAKE_FUNDAMENTAL (1)
14187diff -upr ../orig/jdk/src/solaris/native/sun/awt/list.c ./jdk/src/solaris/native/sun/awt/list.c
14188--- ../orig/jdk/src/solaris/native/sun/awt/list.c       2009-01-27 15:45:50.000000000 -0500
14189+++ ./jdk/src/solaris/native/sun/awt/list.c     2009-05-04 17:37:17.000000000 -0400
14190@@ -66,7 +66,11 @@ from the X Consortium.
14191   ----------------------------------------------------------------------- **/
14192 
14193 #include <stdio.h>
14194+#ifdef _ALLBSD_SOURCE
14195+#include <stdlib.h>
14196+#else
14197 #include <malloc.h>
14198+#endif
14199 #include "list.h"
14200 
14201 
14202diff -upr ../orig/jdk/src/solaris/native/sun/awt/robot_common.c ./jdk/src/solaris/native/sun/awt/robot_common.c
14203--- ../orig/jdk/src/solaris/native/sun/awt/robot_common.c       2009-01-27 15:45:50.000000000 -0500
14204+++ ./jdk/src/solaris/native/sun/awt/robot_common.c     2009-05-04 17:37:17.000000000 -0400
14205@@ -27,6 +27,9 @@
14206     #error This file should not be included in headless library
14207 #endif
14208 
14209+#ifdef _ALLBSD_SOURCE
14210+#include <stdlib.h>
14211+#endif
14212 #include "robot_common.h"
14213 
14214 /*
14215diff -upr ../orig/jdk/src/solaris/native/sun/font/X11FontScaler.c ./jdk/src/solaris/native/sun/font/X11FontScaler.c
14216--- ../orig/jdk/src/solaris/native/sun/font/X11FontScaler.c     2009-01-27 15:45:51.000000000 -0500
14217+++ ./jdk/src/solaris/native/sun/font/X11FontScaler.c   2009-05-04 17:37:17.000000000 -0400
14218@@ -32,7 +32,11 @@
14219  * into X11FontScaler_md.c, which is compiled into another library.
14220  */
14221 #include <stdio.h>
14222+#if defined(_ALLBSD_SOURCE)
14223+#include <stdlib.h>
14224+#else
14225 #include <malloc.h>
14226+#endif
14227 #include <ctype.h>
14228 #include <sys/utsname.h>
14229 
14230diff -upr ../orig/jdk/src/solaris/native/sun/font/X11TextRenderer.c ./jdk/src/solaris/native/sun/font/X11TextRenderer.c
14231--- ../orig/jdk/src/solaris/native/sun/font/X11TextRenderer.c   2009-01-27 15:45:51.000000000 -0500
14232+++ ./jdk/src/solaris/native/sun/font/X11TextRenderer.c 2009-05-04 17:37:17.000000000 -0400
14233@@ -39,7 +39,11 @@
14234 #include "GraphicsPrimitiveMgr.h"
14235 #include "glyphblitting.h"
14236 #include "sunfontids.h"
14237+#if defined(_ALLBSD_SOURCE)
14238+#include <stdlib.h>
14239+#else
14240 #include <malloc.h>
14241+#endif
14242 
14243 
14244 JNIEXPORT void JNICALL AWTDrawGlyphList
14245diff -upr ../orig/jdk/src/solaris/native/sun/java2d/j2d_md.h ./jdk/src/solaris/native/sun/java2d/j2d_md.h
14246--- ../orig/jdk/src/solaris/native/sun/java2d/j2d_md.h  2009-01-27 15:45:51.000000000 -0500
14247+++ ./jdk/src/solaris/native/sun/java2d/j2d_md.h        2009-05-04 17:37:17.000000000 -0400
14248@@ -28,11 +28,11 @@
14249 #include <sys/types.h>
14250 
14251 /*
14252- * Linux version of <sys/types.h> does not define intptr_t
14253+ * Linux and BSD's version of <sys/types.h> does not define intptr_t
14254  */
14255-#ifdef __linux__
14256+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14257 #include <stdint.h>
14258-#endif /* __linux__ */
14259+#endif /* __linux__ || _ALLBSD_SOURCE */
14260 
14261 typedef unsigned char   jubyte;
14262 typedef unsigned short  jushort;
14263diff -upr ../orig/jdk/src/solaris/native/sun/java2d/loops/mlib_ImageZoom_NN.c ./jdk/src/solaris/native/sun/java2d/loops/mlib_ImageZoom_NN.c
14264--- ../orig/jdk/src/solaris/native/sun/java2d/loops/mlib_ImageZoom_NN.c 2009-01-27 15:45:51.000000000 -0500
14265+++ ./jdk/src/solaris/native/sun/java2d/loops/mlib_ImageZoom_NN.c       2009-05-04 17:37:17.000000000 -0400
14266@@ -66,6 +66,10 @@
14267  *    MLIB_EDGE_SRC_PADDED
14268  */
14269 
14270+#ifdef __OpenBSD__
14271+#include <sys/types.h>
14272+#endif
14273+#include <machine/endian.h>
14274 #include <mlib_image.h>
14275 #include <mlib_ImageZoom.h>
14276 
14277@@ -102,7 +106,7 @@ typedef union {
14278 
14279 /***************************************************************/
14280 
14281-#ifdef _LITTLE_ENDIAN
14282+#if (BYTE_ORDER == LITTLE_ENDIAN)
14283 
14284 static const mlib_u32 mlib_bit_mask4[16] = {
14285   0x00000000u, 0xFF000000u, 0x00FF0000u, 0xFFFF0000u,
14286@@ -111,7 +115,7 @@ static const mlib_u32 mlib_bit_mask4[16]
14287   0x0000FFFFu, 0xFF00FFFFu, 0x00FFFFFFu, 0xFFFFFFFFu
14288 };
14289 
14290-#else /* _LITTLE_ENDIAN */
14291+#else /* BIG_ENDIAN */
14292 
14293 static const mlib_u32 mlib_bit_mask4[16] = {
14294   0x00000000u, 0x000000FFu, 0x0000FF00u, 0x0000FFFFu,
14295@@ -120,7 +124,7 @@ static const mlib_u32 mlib_bit_mask4[16]
14296   0xFFFF0000u, 0xFFFF00FFu, 0xFFFFFF00u, 0xFFFFFFFFu
14297 };
14298 
14299-#endif /* _LITTLE_ENDIAN */
14300+#endif /* LITTLE_ENDIAN */
14301 
14302 /***************************************************************/
14303 
14304@@ -344,11 +348,11 @@ mlib_status mlib_ImageZoom_BIT_1_Nearest
14305 #ifdef _NO_LONGLONG
14306 
14307 typedef struct {
14308-#ifdef _LITTLE_ENDIAN
14309+#if (BYTE_ORDER == LITTLE_ENDIAN)
14310   mlib_u32 uint1, uint0;
14311-#else /* _LITTLE_ENDIAN */
14312+#else /* BIG_ENDIAN */
14313   mlib_u32 uint0, uint1;
14314-#endif /* _LITTLE_ENDIAN */
14315+#endif /* LITTLE_ENDIAN */
14316 } two_uint;
14317 
14318 /***************************************************************/
14319@@ -511,11 +515,11 @@ mlib_status mlib_ImageZoom_BitToGray_1_N
14320         DTYPE mask;
14321         MASK(mask);
14322         off *= 8;
14323-#ifdef _LITTLE_ENDIAN
14324+#if (BYTE_ORDER == LITTLE_ENDIAN)
14325         LSHIFT(dd_old, da[0], 64 - off);
14326-#else /* _LITTLE_ENDIAN */
14327+#else /* BIG_ENDIAN */
14328         RSHIFT(dd_old, da[0], 64 - off);
14329-#endif /* _LITTLE_ENDIAN */
14330+#endif /* LITTLE_ENDIAN */
14331 
14332 #ifdef __SUNPRO_C
14333 #pragma pipeloop(0)
14334@@ -540,30 +544,30 @@ mlib_status mlib_ImageZoom_BitToGray_1_N
14335 
14336           res = (res & 0xff) | (res >> 8);
14337           dd = gray_mask[res];
14338-#ifdef _LITTLE_ENDIAN
14339+#if (BYTE_ORDER == LITTLE_ENDIAN)
14340 /* *da++ = (dd_old >> (64 - off)) | (dd << off);*/
14341           RSHIFT(dd_old, dd_old, 64 - off);
14342           LSHIFT(dtmp, dd, off);
14343-#else /* _LITTLE_ENDIAN */
14344+#else /* BIG_ENDIAN */
14345 /* *da++ = (dd_old << (64 - off)) | (dd >> off);*/
14346           LSHIFT(dd_old, dd_old, 64 - off);
14347           RSHIFT(dtmp, dd, off);
14348-#endif /* _LITTLE_ENDIAN */
14349+#endif /* LITTLE_ENDIAN */
14350           LOGIC(*da++, dd_old, dtmp, |);
14351           dd_old = dd;
14352         }
14353 
14354-#ifdef _LITTLE_ENDIAN
14355+#if (BYTE_ORDER == LITTLE_ENDIAN)
14356 /* da[0] = (dd_old >> (64 - off)) | (da[0] & ((mlib_u64)((mlib_s64) -1) << off));*/
14357         LSHIFT(dtmp, mask, off);
14358         LOGIC(dtmp, da[0], dtmp, &);
14359         RSHIFT(dtmp1, dd_old, 64 - off);
14360-#else /* _LITTLE_ENDIAN */
14361+#else /* BIG_ENDIAN */
14362 /* da[0] = (dd_old << (64 - off)) | (da[0] & ((mlib_u64)((mlib_s64) -1) >> off));*/
14363         RSHIFT(dtmp, mask, off);
14364         LOGIC(dtmp, da[0], dtmp, &);
14365         LSHIFT(dtmp1, dd_old, 64 - off);
14366-#endif /* _LITTLE_ENDIAN */
14367+#endif /* LITTLE_ENDIAN */
14368         LOGIC(da[0], dtmp, dtmp1, |);
14369       }
14370       else {                                               /* aligned */
14371diff -upr ../orig/jdk/src/solaris/native/sun/java2d/loops/vis_FuncArray.c ./jdk/src/solaris/native/sun/java2d/loops/vis_FuncArray.c
14372--- ../orig/jdk/src/solaris/native/sun/java2d/loops/vis_FuncArray.c     2009-01-27 15:45:51.000000000 -0500
14373+++ ./jdk/src/solaris/native/sun/java2d/loops/vis_FuncArray.c   2009-05-04 17:37:17.000000000 -0400
14374@@ -794,7 +794,7 @@ static AnyFunc* hash_table_vis[HASH_SIZE
14375 static int initialized;
14376 static int usevis = JNI_TRUE;
14377 
14378-#ifdef __linux__
14379+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14380 #   define ULTRA_CHIP   "sparc64"
14381 #else
14382 #   define ULTRA_CHIP   "sun4u"
14383diff -upr ../orig/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h ./jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h
14384--- ../orig/jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h      2009-01-27 15:45:51.000000000 -0500
14385+++ ./jdk/src/solaris/native/sun/java2d/opengl/OGLFuncs_md.h    2009-05-04 17:37:17.000000000 -0400
14386@@ -27,7 +27,10 @@
14387 #define OGLFuncs_md_h_Included
14388 
14389 #include <stdlib.h>
14390+#ifndef __APPLE__
14391 #include <link.h>
14392+#endif
14393+#include "jvm_md.h"
14394 #include "J2D_GL/glx.h"
14395 #include "OGLFuncMacros.h"
14396 
14397@@ -113,7 +116,7 @@ do { \
14398     { \
14399         char *libGLPath = getenv("J2D_ALT_LIBGL_PATH"); \
14400         if (libGLPath == NULL) { \
14401-            libGLPath = "libGL.so.1"; \
14402+            libGLPath = VERSIONED_JNI_LIB_NAME("GL", "1"); \
14403         } \
14404         OGL_LIB_HANDLE = dlopen(libGLPath, RTLD_LAZY | RTLD_LOCAL); \
14405     } \
14406diff -upr ../orig/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c ./jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c
14407--- ../orig/jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c      2009-01-27 15:45:51.000000000 -0500
14408+++ ./jdk/src/solaris/native/sun/java2d/x11/X11SurfaceData.c    2009-05-04 17:37:17.000000000 -0400
14409@@ -32,6 +32,7 @@
14410 #include "gdefs.h"
14411 
14412 #include "jni_util.h"
14413+#include "jvm_md.h"
14414 #include "awt_Component.h"
14415 #include "awt_GraphicsEnv.h"
14416 
14417@@ -128,7 +129,7 @@ Java_sun_java2d_x11_X11SurfaceData_initI
14418 
14419     if (tryDGA && (getenv("NO_J2D_DGA") == NULL)) {
14420     /* we use RTLD_NOW because of bug 4032715 */
14421-        lib = dlopen("libsunwjdga.so", RTLD_NOW);
14422+        lib = dlopen(JNI_LIB_NAME("sunwjdga"), RTLD_NOW);
14423     }
14424     dgaAvailable = JNI_FALSE;
14425     if (lib != NULL) {
14426diff -upr ../orig/jdk/src/solaris/native/sun/jdga/dgalock.c ./jdk/src/solaris/native/sun/jdga/dgalock.c
14427--- ../orig/jdk/src/solaris/native/sun/jdga/dgalock.c   2009-01-27 15:45:51.000000000 -0500
14428+++ ./jdk/src/solaris/native/sun/jdga/dgalock.c 2009-05-04 17:37:17.000000000 -0400
14429@@ -44,6 +44,7 @@
14430 #include <X11/Xlib.h>
14431 
14432 #include "jni.h"
14433+#include "jvm_md.h"
14434 #include "jdga.h"
14435 #include "jdgadevice.h"
14436 
14437@@ -84,10 +85,10 @@ Drawable GetVirtualDrawableStub(Display
14438 static GetVirtualDrawableFunc * GetVirtualDrawable = GetVirtualDrawableStub;
14439 
14440 static void Solaris_DGA_XineramaInit(Display *display) {
14441-    void * handle = 0;
14442+    void * handle = NULL;
14443     if (IsXineramaOn == NULL) {
14444-        handle = dlopen("libxinerama.so", RTLD_NOW);
14445-        if (handle != 0) {
14446+        handle = dlopen(JNI_LIB_NAME("xinerama"), RTLD_NOW);
14447+        if (handle != NULL) {
14448             void *sym = dlsym(handle, "IsXineramaOn");
14449             IsXineramaOn = (IsXineramaOnFunc *)sym;
14450             if (IsXineramaOn != 0 && (*IsXineramaOn)(display)) {
14451diff -upr ../orig/jdk/src/solaris/native/sun/management/FileSystemImpl.c ./jdk/src/solaris/native/sun/management/FileSystemImpl.c
14452--- ../orig/jdk/src/solaris/native/sun/management/FileSystemImpl.c      2009-01-27 15:45:52.000000000 -0500
14453+++ ./jdk/src/solaris/native/sun/management/FileSystemImpl.c    2009-05-04 17:37:17.000000000 -0400
14454@@ -26,6 +26,10 @@
14455 #include <sys/types.h>
14456 #include <sys/stat.h>
14457 
14458+#if defined(_ALLBSD_SOURCE)
14459+#include "largefile_bsd.h"
14460+#endif
14461+
14462 #include "jni.h"
14463 #include "jni_util.h"
14464 #include "sun_management_FileSystemImpl.h"
14465diff -upr ../orig/jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c ./jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c
14466--- ../orig/jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c      2009-01-27 15:45:52.000000000 -0500
14467+++ ./jdk/src/solaris/native/sun/net/dns/ResolverConfigurationImpl.c    2009-05-04 17:37:17.000000000 -0400
14468@@ -33,7 +33,7 @@
14469 #include <strings.h>
14470 #endif
14471 
14472-#ifdef __linux__
14473+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14474 #include <string.h>
14475 #endif
14476 
14477diff -upr ../orig/jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c ./jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c
14478--- ../orig/jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c   2009-01-27 15:45:52.000000000 -0500
14479+++ ./jdk/src/solaris/native/sun/net/spi/DefaultProxySelector.c 2009-05-04 17:37:17.000000000 -0400
14480@@ -26,11 +26,12 @@
14481 #include "jni.h"
14482 #include "jni_util.h"
14483 #include "jvm.h"
14484+#include "jvm_md.h"
14485 #include "jlong.h"
14486 #include "sun_net_spi_DefaultProxySelector.h"
14487 #include <dlfcn.h>
14488 #include <stdio.h>
14489-#ifdef __linux__
14490+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14491 #include <string.h>
14492 #else
14493 #include <strings.h>
14494@@ -109,8 +110,9 @@ Java_sun_net_spi_DefaultProxySelector_in
14495   /**
14496    * Let's try to load le GConf-2 library
14497    */
14498-  if (dlopen("libgconf-2.so", RTLD_GLOBAL | RTLD_LAZY) != NULL ||
14499-      dlopen("libgconf-2.so.4", RTLD_GLOBAL | RTLD_LAZY) != NULL) {
14500+  if (dlopen(JNI_LIB_NAME("gconf-2"), RTLD_GLOBAL | RTLD_LAZY) != NULL ||
14501+      dlopen(VERSIONED_JNI_LIB_NAME("gconf-2", "4"),
14502+             RTLD_GLOBAL | RTLD_LAZY) != NULL) {
14503     gconf_ver = 2;
14504   }
14505   if (gconf_ver > 0) {
14506diff -upr ../orig/jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c ./jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c
14507--- ../orig/jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c     2009-01-27 15:45:52.000000000 -0500
14508+++ ./jdk/src/solaris/native/sun/nio/ch/DatagramChannelImpl.c   2009-05-04 17:37:17.000000000 -0400
14509@@ -35,7 +35,7 @@
14510 #include <string.h>
14511 #include <errno.h>
14512 
14513-#if __linux__
14514+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14515 #include <netinet/in.h>
14516 #endif
14517 
14518@@ -86,7 +86,7 @@ Java_sun_nio_ch_DatagramChannelImpl_disc
14519     rv = connect(fd, 0, 0);
14520 #endif
14521 
14522-#ifdef __linux__
14523+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
14524     {
14525         int len;
14526         SOCKADDR sa;
14527@@ -96,17 +96,30 @@ Java_sun_nio_ch_DatagramChannelImpl_disc
14528 #ifdef AF_INET6
14529         if (ipv6_available()) {
14530             struct sockaddr_in6 *him6 = (struct sockaddr_in6 *)&sa;
14531+#if defined(_ALLBSD_SOURCE)
14532+           him6->sin6_family = AF_INET6;
14533+#else
14534             him6->sin6_family = AF_UNSPEC;
14535+#endif
14536             len = sizeof(struct sockaddr_in6);
14537         } else
14538 #endif
14539         {
14540             struct sockaddr_in *him4 = (struct sockaddr_in*)&sa;
14541+#if defined(_ALLBSD_SOURCE)
14542+           him4->sin_family = AF_INET;
14543+#else
14544             him4->sin_family = AF_UNSPEC;
14545+#endif
14546             len = sizeof(struct sockaddr_in);
14547         }
14548 
14549         rv = connect(fd, (struct sockaddr *)&sa, len);
14550+
14551+#if defined(_ALLBSD_SOURCE)
14552+       if (rv < 0 && errno == EADDRNOTAVAIL)
14553+               rv = errno = 0;
14554+#endif
14555     }
14556 #endif
14557 
14558diff -upr ../orig/jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c ./jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c
14559--- ../orig/jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c 2009-01-27 15:45:52.000000000 -0500
14560+++ ./jdk/src/solaris/native/sun/nio/ch/FileChannelImpl.c       2009-05-04 17:37:17.000000000 -0400
14561@@ -26,15 +26,21 @@
14562 #include "jni.h"
14563 #include "jni_util.h"
14564 #include "jvm.h"
14565+#include "jvm_md.h"
14566 #include "jlong.h"
14567 #include <sys/mman.h>
14568 #include <sys/stat.h>
14569+#include <fcntl.h>
14570 #include "sun_nio_ch_FileChannelImpl.h"
14571 #include "java_lang_Integer.h"
14572 #include "nio.h"
14573 #include "nio_util.h"
14574 #include <dlfcn.h>
14575 
14576+#if defined(_ALLBSD_SOURCE)
14577+#include "largefile_bsd.h"
14578+#endif
14579+
14580 static jfieldID chan_fd;        /* jobject 'fd' in sun.io.FileChannelImpl */
14581 
14582 #ifdef __solaris__
14583@@ -59,6 +65,10 @@ sendfile_func* my_sendfile_func = NULL;
14584 typedef ssize_t sendfile64_func(int out_fd, int in_fd, off64_t *offset, size_t count);
14585 
14586 sendfile64_func* my_sendfile64_func = NULL;
14587+#elif defined(_ALLBSD_SOURCE)
14588+#include <sys/socket.h>
14589+#include <errno.h>
14590+#include <stdlib.h>
14591 #endif
14592 
14593 JNIEXPORT jlong JNICALL
14594@@ -68,7 +78,8 @@ Java_sun_nio_ch_FileChannelImpl_initIDs(
14595     chan_fd = (*env)->GetFieldID(env, clazz, "fd", "Ljava/io/FileDescriptor;");
14596 
14597 #ifdef __solaris__
14598-    if (dlopen("/usr/lib/libsendfile.so.1", RTLD_GLOBAL | RTLD_LAZY) != NULL) {
14599+    if (dlopen("/usr/lib/" VERSIONED_JNI_LIB_NAME("sendfile", "1"),
14600+               RTLD_GLOBAL | RTLD_LAZY) != NULL) {
14601         my_sendfile_func = (sendfile_func*) dlsym(RTLD_DEFAULT, "sendfilev64");
14602     }
14603 #endif
14604@@ -278,6 +289,58 @@ Java_sun_nio_ch_FileChannelImpl_transfer
14605         return result;
14606     }
14607 #endif
14608+
14609+#ifdef _ALLBSD_SOURCE
14610+    /*
14611+     * XXXBSD: make sure that we're returning what java class may understand
14612+     *
14613+     * XXXBSD: I'd prefer to have it implemented with sendfile(), but since
14614+     *         FreeBSD's sendfile() is only supposed to be used in file->socket
14615+     *         schema we need to provide some kind of fall-back operation, if
14616+     *         sendfile() failed with ENOTSOCK error only.
14617+     */
14618+    void *buf;
14619+    off_t offset = (off_t)position;
14620+    int r, w = 0;
14621+
14622+    buf = malloc(4096);
14623+    if (buf == NULL) {
14624+        JNU_ThrowOutOfMemoryError(env, "heap allocation failed");
14625+        return IOS_THROWN;
14626+    }
14627+
14628+    while ((r = pread(srcFD, buf, 4096, offset)) > 0) {
14629+        w = write(dstFD, buf, r);
14630+        if (w == -1)
14631+           break;
14632+        offset += w;
14633+    }
14634+    free(buf);
14635+
14636+    /*
14637+     * Similar to solaris if we've transferred any data return
14638+     * the number of bytes and ignore any error
14639+    */
14640+    if (offset - (off_t)position > 0)
14641+       return (offset - (off_t)position);
14642+
14643+    /*
14644+     * Deal with NBIO EAGAIN & EINTR the same as solaris.
14645+     */
14646+    if (r == -1 || w == -1) {
14647+        switch (errno) {
14648+           case EAGAIN:
14649+               return IOS_UNAVAILABLE;
14650+           case EINTR:
14651+               return IOS_INTERRUPTED;
14652+           default:
14653+               JNU_ThrowIOExceptionWithLastError(env, "Transfer failed");
14654+               return IOS_THROWN;
14655+        }
14656+    }
14657+
14658+    return (0);
14659+#endif
14660 }
14661 
14662 JNIEXPORT jint JNICALL
14663@@ -329,6 +392,23 @@ Java_sun_nio_ch_FileChannelImpl_release0
14664     fl.l_start = (off64_t)pos;
14665     fl.l_type = F_UNLCK;
14666     lockResult = fcntl(fd, cmd, &fl);
14667+#if defined(__FreeBSD__) || defined(__OpenBSD__)
14668+    /* XXXFREEBSD:  While doing of preClose0() we're closing actual fd which
14669+       was locked, so here we'll get an error which need to be ignored to
14670+       satisfy TCK FileLock test */
14671+    /* XXXFREEBSD: backport to 1.4.2 */
14672+    if (lockResult < 0 && errno == EBADF)
14673+       lockResult = errno = 0;
14674+#endif
14675+#if defined(__NetBSD__)
14676+    /* XXXNETBSD: The dup2 in preClose0 is being done onto 1 end of a
14677+       socketpair which isn't a valid target for F_UNLCK. No good way to see
14678+       this vs. a bad lock setup so just return errno = 0 there
14679+       to pass JCK (lock will get removed once all fd's close anyways) */
14680+    /* XXXNETBSD: backport to 1.4.2 */
14681+    if (lockResult < 0 && errno == EINVAL)
14682+       lockResult = errno = 0;
14683+#endif
14684     if (lockResult < 0) {
14685         JNU_ThrowIOExceptionWithLastError(env, "Release failed");
14686     }
14687diff -upr ../orig/jdk/src/solaris/native/sun/nio/ch/FileDispatcher.c ./jdk/src/solaris/native/sun/nio/ch/FileDispatcher.c
14688--- ../orig/jdk/src/solaris/native/sun/nio/ch/FileDispatcher.c  2009-01-27 15:45:52.000000000 -0500
14689+++ ./jdk/src/solaris/native/sun/nio/ch/FileDispatcher.c        2009-05-04 17:37:17.000000000 -0400
14690@@ -32,8 +32,12 @@
14691 #include <sys/socket.h>
14692 #include <fcntl.h>
14693 #include <sys/uio.h>
14694+#include <unistd.h>
14695 #include "nio_util.h"
14696 
14697+#if defined(_ALLBSD_SOURCE)
14698+#include "largefile_bsd.h"
14699+#endif
14700 
14701 static int preCloseFD = -1;     /* File descriptor to which we dup other fd's
14702                                    before closing them for real */
14703diff -upr ../orig/jdk/src/solaris/native/sun/nio/ch/FileKey.c ./jdk/src/solaris/native/sun/nio/ch/FileKey.c
14704--- ../orig/jdk/src/solaris/native/sun/nio/ch/FileKey.c 2009-01-27 15:45:52.000000000 -0500
14705+++ ./jdk/src/solaris/native/sun/nio/ch/FileKey.c       2009-05-04 17:37:17.000000000 -0400
14706@@ -30,6 +30,10 @@
14707 #include "nio_util.h"
14708 #include "sun_nio_ch_FileKey.h"
14709 
14710+#if defined(_ALLBSD_SOURCE)
14711+#include "largefile_bsd.h"
14712+#endif
14713+
14714 static jfieldID key_st_dev;    /* id for FileKey.st_dev */
14715 static jfieldID key_st_ino;    /* id for FileKey.st_ino */
14716 
14717diff -upr ../orig/jdk/src/solaris/native/sun/nio/ch/Net.c ./jdk/src/solaris/native/sun/nio/ch/Net.c
14718--- ../orig/jdk/src/solaris/native/sun/nio/ch/Net.c     2009-01-27 15:45:52.000000000 -0500
14719+++ ./jdk/src/solaris/native/sun/nio/ch/Net.c   2009-05-04 17:37:17.000000000 -0400
14720@@ -140,8 +140,31 @@ Java_sun_nio_ch_Net_localPort(JNIEnv *en
14721     SOCKADDR sa;
14722     int sa_len = SOCKADDR_LEN;
14723     if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
14724+#ifdef _ALLBSD_SOURCE
14725+ /*
14726+  * XXXBSD:
14727+  * ECONNRESET is specific to the BSDs. We can not return an error,
14728+  * as the calling Java code with raise a java.lang.Error given the expectation
14729+  * that getsockname() will never fail. According to the Single UNIX Specification,
14730+  * it shouldn't fail. As such, we just fill in generic Linux-compatible values.
14731+  */
14732+ if (errno == ECONNRESET) {
14733+     struct sockaddr_in *sin;
14734+     sin = (struct sockaddr_in *) &sa;
14735+     bzero(sin, sizeof(*sin));
14736+     sin->sin_len  = sizeof(struct sockaddr_in);
14737+     sin->sin_family = AF_INET;
14738+     sin->sin_port = htonl(0);
14739+     sin->sin_addr.s_addr = INADDR_ANY;
14740+ } else {
14741+     handleSocketError(env, errno);
14742+     return -1;
14743+ }
14744+#else /* _ALLBSD_SOURCE */
14745         handleSocketError(env, errno);
14746         return -1;
14747+#endif /* _ALLBSD_SOURCE */
14748+
14749     }
14750     return NET_GetPortFromSockaddr((struct sockaddr *)&sa);
14751 }
14752@@ -153,12 +176,76 @@ Java_sun_nio_ch_Net_localInetAddress(JNI
14753     int sa_len = SOCKADDR_LEN;
14754     int port;
14755     if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
14756-        handleSocketError(env, errno);
14757-        return NULL;
14758+#ifdef _ALLBSD_SOURCE
14759+ /*
14760+  * XXXBSD:
14761+  * ECONNRESET is specific to the BSDs. We can not return an error,
14762+  * as the calling Java code with raise a java.lang.Error with the expectation
14763+  * that getsockname() will never fail. According to the Single UNIX Specification,
14764+  * it shouldn't fail. As such, we just fill in generic Linux-compatible values.
14765+  */
14766+ if (errno == ECONNRESET) {
14767+     struct sockaddr_in *sin;
14768+     sin = (struct sockaddr_in *) &sa;
14769+     bzero(sin, sizeof(*sin));
14770+     sin->sin_len  = sizeof(struct sockaddr_in);
14771+     sin->sin_family = AF_INET;
14772+     sin->sin_port = htonl(0);
14773+     sin->sin_addr.s_addr = INADDR_ANY;
14774+ } else {
14775+     handleSocketError(env, errno);
14776+     return NULL;
14777+ }
14778+#else /* _ALLBSD_SOURCE */
14779+          handleSocketError(env, errno);
14780+          return NULL;
14781+#endif /* _ALLBSD_SOURCE */
14782+
14783     }
14784     return NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
14785 }
14786 
14787+#ifdef _ALLBSD_SOURCE
14788+
14789+#ifndef IP_BLOCK_SOURCE
14790+
14791+#define IP_ADD_SOURCE_MEMBERSHIP        70   /* join a source-specific group */
14792+#define IP_DROP_SOURCE_MEMBERSHIP       71   /* drop a single source */
14793+#define IP_BLOCK_SOURCE                 72   /* block a source */
14794+#define IP_UNBLOCK_SOURCE               73   /* unblock a source */
14795+
14796+#endif  /* IP_BLOCK_SOURCE */
14797+
14798+#ifndef MCAST_BLOCK_SOURCE
14799+
14800+#define MCAST_JOIN_SOURCE_GROUP         82   /* join a source-specific group */
14801+#define MCAST_LEAVE_SOURCE_GROUP        83   /* leave a single source */
14802+#define MCAST_BLOCK_SOURCE              84   /* block a source */
14803+#define MCAST_UNBLOCK_SOURCE            85   /* unblock a source */
14804+
14805+#endif /* MCAST_BLOCK_SOURCE */
14806+
14807+#ifndef IPV6_ADD_MEMBERSHIP
14808+
14809+#define IPV6_ADD_MEMBERSHIP    IPV6_JOIN_GROUP
14810+#define IPV6_DROP_MEMBERSHIP   IPV6_LEAVE_GROUP
14811+
14812+#endif /* IPV6_ADD_MEMBERSHIP */
14813+
14814+struct my_ip_mreq_source {
14815+        struct in_addr  imr_multiaddr;
14816+        struct in_addr  imr_interface;
14817+        struct in_addr  imr_sourceaddr;
14818+};
14819+
14820+struct my_group_source_req {
14821+        uint32_t                gsr_interface;  /* interface index */
14822+        struct sockaddr_storage gsr_group;      /* group address */
14823+        struct sockaddr_storage gsr_source;     /* source address */
14824+};
14825+
14826+#endif   /* _ALLBSD_SOURCE */
14827+
14828 
14829 #ifdef NEEDED
14830 
14831@@ -224,7 +311,7 @@ Java_sun_nio_ch_Net_getIntOption0(JNIEnv
14832     int result;
14833     struct linger linger;
14834     void *arg;
14835-    int arglen;
14836+    socklen_t arglen;
14837 
14838     if (NET_MapSocketOption(opt, &klevel, &kopt) < 0) {
14839         JNU_ThrowByNameWithLastError(env,
14840@@ -262,7 +349,7 @@ Java_sun_nio_ch_Net_setIntOption0(JNIEnv
14841     int result;
14842     struct linger linger;
14843     void *parg;
14844-    int arglen;
14845+    socklen_t arglen;
14846 
14847     if (NET_MapSocketOption(opt, &klevel, &kopt) < 0) {
14848         JNU_ThrowByNameWithLastError(env,
14849@@ -304,9 +391,11 @@ handleSocketError(JNIEnv *env, jint erro
14850     switch (errorValue) {
14851         case EINPROGRESS:       /* Non-blocking connect */
14852             return 0;
14853+#ifdef EPROTO
14854         case EPROTO:
14855             xn = JNU_JAVANETPKG "ProtocolException";
14856             break;
14857+#endif
14858         case ECONNREFUSED:
14859             xn = JNU_JAVANETPKG "ConnectException";
14860             break;
14861diff -upr ../orig/jdk/src/solaris/native/sun/security/jgss/wrapper/NativeFunc.c ./jdk/src/solaris/native/sun/security/jgss/wrapper/NativeFunc.c
14862--- ../orig/jdk/src/solaris/native/sun/security/jgss/wrapper/NativeFunc.c       2009-01-27 15:45:52.000000000 -0500
14863+++ ./jdk/src/solaris/native/sun/security/jgss/wrapper/NativeFunc.c     2009-05-04 17:37:17.000000000 -0400
14864@@ -26,7 +26,9 @@
14865 #include <stdio.h>
14866 #include <stdlib.h>
14867 #include <dlfcn.h>
14868+#ifndef __APPLE__
14869 #include <link.h>
14870+#endif
14871 #include "NativeFunc.h"
14872 
14873 /* standard GSS method names (ordering is from mapfile) */
14874diff -upr ../orig/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c ./jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c
14875--- ../orig/jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c    2009-01-27 15:45:52.000000000 -0500
14876+++ ./jdk/src/solaris/native/sun/security/pkcs11/j2secmod_md.c  2009-05-04 17:37:17.000000000 -0400
14877@@ -28,12 +28,19 @@
14878 #include <string.h>
14879 
14880 #include <dlfcn.h>
14881+#ifndef __APPLE__
14882 #include <link.h>
14883+#endif
14884 
14885 #include <jni_util.h>
14886 
14887 #include "j2secmod.h"
14888 
14889+#ifndef RTLD_NOLOAD
14890+/* A gross hack that will work if the NSS library is only opened once */
14891+static void *nssLibHandle = NULL;
14892+#endif
14893+
14894 void *findFunction(JNIEnv *env, jlong jHandle, const char *functionName) {
14895     void *hModule = (void*)jHandle;
14896     void *fAddress = dlsym(hModule, functionName);
14897@@ -51,7 +58,11 @@ JNIEXPORT jlong JNICALL Java_sun_securit
14898 {
14899     const char *libName = (*env)->GetStringUTFChars(env, jLibName, NULL);
14900     // look up existing handle only, do not load
14901+#ifdef RTLD_NOLOAD
14902     void *hModule = dlopen(libName, RTLD_NOLOAD);
14903+#else
14904+    void *hModule = nssLibHandle;
14905+#endif
14906     dprintf2("-handle for %s: %u\n", libName, hModule);
14907     (*env)->ReleaseStringUTFChars(env, jLibName, libName);
14908     return (jlong)hModule;
14909@@ -65,6 +76,9 @@ JNIEXPORT jlong JNICALL Java_sun_securit
14910 
14911     dprintf1("-lib %s\n", libName);
14912     hModule = dlopen(libName, RTLD_LAZY);
14913+#ifndef RTLD_NOLOAD
14914+    nssLibHandle = hModule;
14915+#endif
14916     (*env)->ReleaseStringUTFChars(env, jLibName, libName);
14917     dprintf2("-handle: %u (0X%X)\n", hModule, hModule);
14918 
14919diff -upr ../orig/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c ./jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c
14920--- ../orig/jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c 2009-01-27 15:45:52.000000000 -0500
14921+++ ./jdk/src/solaris/native/sun/security/pkcs11/wrapper/p11_md.c       2009-05-04 17:37:17.000000000 -0400
14922@@ -64,7 +64,9 @@
14923 #include <assert.h>
14924 
14925 #include <dlfcn.h>
14926+#ifndef __APPLE__
14927 #include <link.h>
14928+#endif
14929 
14930 #include <jni.h>
14931 
14932diff -upr ../orig/jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c ./jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c
14933--- ../orig/jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c   2009-01-27 15:45:52.000000000 -0500
14934+++ ./jdk/src/solaris/native/sun/security/smartcardio/pcsc_md.c 2009-05-04 17:37:17.000000000 -0400
14935@@ -29,7 +29,9 @@
14936 #include <assert.h>
14937 
14938 #include <dlfcn.h>
14939+#ifndef __APPLE__
14940 #include <link.h>
14941+#endif
14942 
14943 #include <winscard.h>
14944 
14945diff -upr ../orig/jdk/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c ./jdk/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c
14946--- ../orig/jdk/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c 2009-05-04 18:32:16.000000000 -0400
14947+++ ./jdk/src/solaris/native/sun/tools/attach/BsdVirtualMachine.c       2009-05-04 17:37:15.000000000 -0400
14948@@ -1,461 +1,3 @@
14949 /*
14950- * Copyright 2005 Sun Microsystems, Inc.  All Rights Reserved.
14951- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
14952- *
14953- * This code is free software; you can redistribute it and/or modify it
14954- * under the terms of the GNU General Public License version 2 only, as
14955- * published by the Free Software Foundation.  Sun designates this
14956- * particular file as subject to the "Classpath" exception as provided
14957- * by Sun in the LICENSE file that accompanied this code.
14958- *
14959- * This code is distributed in the hope that it will be useful, but WITHOUT
14960- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14961- * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14962- * version 2 for more details (a copy is included in the LICENSE file that
14963- * accompanied this code).
14964- *
14965- * You should have received a copy of the GNU General Public License version
14966- * 2 along with this work; if not, write to the Free Software Foundation,
14967- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
14968- *
14969- * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
14970- * CA 95054 USA or visit www.sun.com if you need additional information or
14971- * have any questions.
14972+ * Dummy file - needs to be implemented for bsd
14973  */
14974-
14975-#include "jni.h"
14976-#include "jni_util.h"
14977-
14978-#include <stdio.h>
14979-#include <stdlib.h>
14980-#include <string.h>
14981-#include <errno.h>
14982-#include <unistd.h>
14983-#include <signal.h>
14984-#include <dirent.h>
14985-#include <ctype.h>
14986-#include <sys/types.h>
14987-#include <sys/types.h>
14988-#include <sys/socket.h>
14989-#include <sys/stat.h>
14990-#include <sys/un.h>
14991-
14992-#include "sun_tools_attach_BsdVirtualMachine.h"
14993-
14994-#define RESTARTABLE(_cmd, _result) do { \
14995-  do { \
14996-    _result = _cmd; \
14997-  } while((_result == -1) && (errno == EINTR)); \
14998-} while(0)
14999-
15000-/*
15001- * Defines a callback that is invoked for each process
15002- */
15003-typedef void (*ProcessCallback)(const pid_t pid, void* user_data);
15004-
15005-/*
15006- * Invokes the callback function for each process
15007- */
15008-static void forEachProcess(ProcessCallback f, void* user_data) {
15009-    DIR* dir;
15010-    struct dirent* ptr;
15011-
15012-    /*
15013-     * To locate the children we scan /proc looking for files that have a
15014-     * position integer as a filename.
15015-     */
15016-    if ((dir = opendir("/proc")) == NULL) {
15017-        return;
15018-    }
15019-    while ((ptr = readdir(dir)) != NULL) {
15020-        pid_t pid;
15021-
15022-        /* skip current/parent directories */
15023-        if (strcmp(ptr->d_name, ".") == 0 || strcmp(ptr->d_name, "..") == 0) {
15024-            continue;
15025-        }
15026-
15027-        /* skip files that aren't numbers */
15028-        pid = (pid_t)atoi(ptr->d_name);
15029-        if ((int)pid <= 0) {
15030-            continue;
15031-        }
15032-
15033-        /* invoke the callback */
15034-        (*f)(pid, user_data);
15035-    }
15036-    closedir(dir);
15037-}
15038-
15039-
15040-/*
15041- * Returns the parent pid of a given pid, or -1 if not found
15042- */
15043-static pid_t getParent(pid_t pid) {
15044-    char state;
15045-    FILE* fp;
15046-    char stat[2048];
15047-    int statlen;
15048-    char fn[32];
15049-    int i, p;
15050-    char* s;
15051-
15052-    /*
15053-     * try to open /proc/%d/stat
15054-     */
15055-    sprintf(fn, "/proc/%d/stat", pid);
15056-    fp = fopen(fn, "r");
15057-    if (fp == NULL) {
15058-        return -1;
15059-    }
15060-
15061-    /*
15062-     * The format is: pid (command) state ppid ...
15063-     * As the command could be anything we must find the right most
15064-     * ")" and then skip the white spaces that follow it.
15065-     */
15066-    statlen = fread(stat, 1, 2047, fp);
15067-    stat[statlen] = '\0';
15068-    fclose(fp);
15069-    s = strrchr(stat, ')');
15070-    if (s == NULL) {
15071-        return -1;
15072-    }
15073-    do s++; while (isspace(*s));
15074-    i = sscanf(s, "%c %d", &state, &p);
15075-    return (pid_t)p;
15076-}
15077-
15078-
15079-/*
15080- * Class:     sun_tools_attach_BsdVirtualMachine
15081- * Method:    socket
15082- * Signature: ()I
15083- */
15084-JNIEXPORT jint JNICALL Java_sun_tools_attach_BsdVirtualMachine_socket
15085-  (JNIEnv *env, jclass cls)
15086-{
15087-    int fd = socket(PF_UNIX, SOCK_STREAM, 0);
15088-    if (fd == -1) {
15089-        JNU_ThrowIOExceptionWithLastError(env, "socket");
15090-    }
15091-    return (jint)fd;
15092-}
15093-
15094-/*
15095- * Class:     sun_tools_attach_BsdVirtualMachine
15096- * Method:    connect
15097- * Signature: (ILjava/lang/String;)I
15098- */
15099-JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_connect
15100-  (JNIEnv *env, jclass cls, jint fd, jstring path)
15101-{
15102-    jboolean isCopy;
15103-    const char* p = GetStringPlatformChars(env, path, &isCopy);
15104-    if (p != NULL) {
15105-        struct sockaddr_un addr;
15106-        int err = 0;
15107-
15108-        addr.sun_family = AF_UNIX;
15109-        strcpy(addr.sun_path, p);
15110-
15111-        if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == -1) {
15112-            err = errno;
15113-        }
15114-
15115-        if (isCopy) {
15116-            JNU_ReleaseStringPlatformChars(env, path, p);
15117-        }
15118-
15119-        /*
15120-         * If the connect failed then we throw the appropriate exception
15121-         * here (can't throw it before releasing the string as can't call
15122-         * JNI with pending exception)
15123-         */
15124-        if (err != 0) {
15125-            if (err == ENOENT) {
15126-                JNU_ThrowByName(env, "java/io/FileNotFoundException", NULL);
15127-            } else {
15128-                char* msg = strdup(strerror(err));
15129-                JNU_ThrowIOException(env, msg);
15130-                if (msg != NULL) {
15131-                    free(msg);
15132-                }
15133-            }
15134-        }
15135-    }
15136-}
15137-
15138-/*
15139- * Class:     sun_tools_attach_BsdVirtualMachine
15140- * Method:    isBsdThreads
15141- * Signature: ()V
15142- */
15143-JNIEXPORT jboolean JNICALL Java_sun_tools_attach_BsdVirtualMachine_isBsdThreads
15144-  (JNIEnv *env, jclass cls)
15145-{
15146-# ifndef _CS_GNU_LIBPTHREAD_VERSION
15147-# define _CS_GNU_LIBPTHREAD_VERSION 3
15148-# endif
15149-    size_t n;
15150-    char* s;
15151-    jboolean res;
15152-
15153-    n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0);
15154-    if (n <= 0) {
15155-       /* glibc before 2.3.2 only has BsdThreads */
15156-       return JNI_TRUE;
15157-    }
15158-
15159-    s = (char *)malloc(n);
15160-    if (s == NULL) {
15161-        JNU_ThrowOutOfMemoryError(env, "malloc failed");
15162-        return JNI_TRUE;
15163-    }
15164-    confstr(_CS_GNU_LIBPTHREAD_VERSION, s, n);
15165-
15166-    /*
15167-     * If the LIBPTHREAD version include "NPTL" then we know we
15168-     * have the new threads library and not BsdThreads
15169-     */
15170-    res = (jboolean)(strstr(s, "NPTL") == NULL);
15171-    free(s);
15172-    return res;
15173-}
15174-
15175-/*
15176- * Structure and callback function used to count the children of
15177- * a given process, and record the pid of the "manager thread".
15178- */
15179-typedef struct {
15180-    pid_t ppid;
15181-    int count;
15182-    pid_t mpid;
15183-} ChildCountContext;
15184-
15185-static void ChildCountCallback(const pid_t pid, void* user_data) {
15186-    ChildCountContext* context = (ChildCountContext*)user_data;
15187-    if (getParent(pid) == context->ppid) {
15188-        context->count++;
15189-        /*
15190-         * Remember the pid of the first child. If the final count is
15191-         * one then this is the pid of the BsdThreads manager.
15192-         */
15193-        if (context->count == 1) {
15194-            context->mpid = pid;
15195-        }
15196-    }
15197-}
15198-
15199-/*
15200- * Class:     sun_tools_attach_BsdVirtualMachine
15201- * Method:    getBsdThreadsManager
15202- * Signature: (I)I
15203- */
15204-JNIEXPORT jint JNICALL Java_sun_tools_attach_BsdVirtualMachine_getBsdThreadsManager
15205-  (JNIEnv *env, jclass cls, jint pid)
15206-{
15207-    ChildCountContext context;
15208-
15209-    /*
15210-     * Iterate over all processes to find how many children 'pid' has
15211-     */
15212-    context.ppid = pid;
15213-    context.count = 0;
15214-    context.mpid = (pid_t)0;
15215-    forEachProcess(ChildCountCallback, (void*)&context);
15216-
15217-    /*
15218-     * If there's no children then this is likely the pid of the primordial
15219-     * created by the launcher - in that case the BsdThreads manager is the
15220-     * parent of this process.
15221-     */
15222-    if (context.count == 0) {
15223-        pid_t parent = getParent(pid);
15224-        if ((int)parent > 0) {
15225-            return (jint)parent;
15226-        }
15227-    }
15228-
15229-    /*
15230-     * There's one child so this is likely the embedded VM case where the
15231-     * the primordial thread == BsdThreads initial thread. The BsdThreads
15232-     * manager in that case is the child.
15233-     */
15234-    if (context.count == 1) {
15235-        return (jint)context.mpid;
15236-    }
15237-
15238-    /*
15239-     * If we get here it's most likely we were given the wrong pid
15240-     */
15241-    JNU_ThrowIOException(env, "Unable to get pid of BsdThreads manager thread");
15242-    return -1;
15243-}
15244-
15245-/*
15246- * Structure and callback function used to send a QUIT signal to all
15247- * children of a given process
15248- */
15249-typedef struct {
15250-    pid_t ppid;
15251-} SendQuitContext;
15252-
15253-static void SendQuitCallback(const pid_t pid, void* user_data) {
15254-    SendQuitContext* context = (SendQuitContext*)user_data;
15255-    pid_t parent = getParent(pid);
15256-    if (parent == context->ppid) {
15257-        kill(pid, SIGQUIT);
15258-    }
15259-}
15260-
15261-/*
15262- * Class:     sun_tools_attach_BsdVirtualMachine
15263- * Method:    sendQuitToChildrenOf
15264- * Signature: (I)V
15265- */
15266-JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_sendQuitToChildrenOf
15267-  (JNIEnv *env, jclass cls, jint pid)
15268-{
15269-    SendQuitContext context;
15270-    context.ppid = (pid_t)pid;
15271-
15272-    /*
15273-     * Iterate over all children of 'pid' and send a QUIT signal to each.
15274-     */
15275-    forEachProcess(SendQuitCallback, (void*)&context);
15276-}
15277-
15278-/*
15279- * Class:     sun_tools_attach_BsdVirtualMachine
15280- * Method:    sendQuitTo
15281- * Signature: (I)V
15282- */
15283-JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_sendQuitTo
15284-  (JNIEnv *env, jclass cls, jint pid)
15285-{
15286-    if (kill((pid_t)pid, SIGQUIT)) {
15287-        JNU_ThrowIOExceptionWithLastError(env, "kill");
15288-    }
15289-}
15290-
15291-/*
15292- * Class:     sun_tools_attach_BsdVirtualMachine
15293- * Method:    checkPermissions
15294- * Signature: (Ljava/lang/String;)V
15295- */
15296-JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_checkPermissions
15297-  (JNIEnv *env, jclass cls, jstring path)
15298-{
15299-    jboolean isCopy;
15300-    const char* p = GetStringPlatformChars(env, path, &isCopy);
15301-    if (p != NULL) {
15302-        struct stat64 sb;
15303-        uid_t uid, gid;
15304-        int res;
15305-
15306-        /*
15307-         * Check that the path is owned by the effective uid/gid of this
15308-         * process. Also check that group/other access is not allowed.
15309-         */
15310-        uid = geteuid();
15311-        gid = getegid();
15312-
15313-        res = stat64(p, &sb);
15314-        if (res != 0) {
15315-            /* save errno */
15316-            res = errno;
15317-        }
15318-
15319-        /* release p here before we throw an I/O exception */
15320-        if (isCopy) {
15321-            JNU_ReleaseStringPlatformChars(env, path, p);
15322-        }
15323-
15324-        if (res == 0) {
15325-            if ( (sb.st_uid != uid) || (sb.st_gid != gid) ||
15326-                 ((sb.st_mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH)) != 0) ) {
15327-                JNU_ThrowIOException(env, "well-known file is not secure");
15328-            }
15329-        } else {
15330-            char* msg = strdup(strerror(res));
15331-            JNU_ThrowIOException(env, msg);
15332-            if (msg != NULL) {
15333-                free(msg);
15334-            }
15335-        }
15336-    }
15337-}
15338-
15339-/*
15340- * Class:     sun_tools_attach_BsdVirtualMachine
15341- * Method:    close
15342- * Signature: (I)V
15343- */
15344-JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_close
15345-  (JNIEnv *env, jclass cls, jint fd)
15346-{
15347-    int res;
15348-    RESTARTABLE(close(fd), res);
15349-}
15350-
15351-/*
15352- * Class:     sun_tools_attach_BsdVirtualMachine
15353- * Method:    read
15354- * Signature: (I[BI)I
15355- */
15356-JNIEXPORT jint JNICALL Java_sun_tools_attach_BsdVirtualMachine_read
15357-  (JNIEnv *env, jclass cls, jint fd, jbyteArray ba, jint off, jint baLen)
15358-{
15359-    unsigned char buf[128];
15360-    size_t len = sizeof(buf);
15361-    ssize_t n;
15362-
15363-    size_t remaining = (size_t)(baLen - off);
15364-    if (len > remaining) {
15365-        len = remaining;
15366-    }
15367-
15368-    RESTARTABLE(read(fd, buf+off, len), n);
15369-    if (n == -1) {
15370-        JNU_ThrowIOExceptionWithLastError(env, "read");
15371-    } else {
15372-        if (n == 0) {
15373-            n = -1;     // EOF
15374-        } else {
15375-            (*env)->SetByteArrayRegion(env, ba, off, (jint)n, (jbyte *)(buf+off));
15376-        }
15377-    }
15378-    return n;
15379-}
15380-
15381-/*
15382- * Class:     sun_tools_attach_BsdVirtualMachine
15383- * Method:    write
15384- * Signature: (I[B)V
15385- */
15386-JNIEXPORT void JNICALL Java_sun_tools_attach_BsdVirtualMachine_write
15387-  (JNIEnv *env, jclass cls, jint fd, jbyteArray ba, jint off, jint bufLen)
15388-{
15389-    size_t remaining = bufLen;
15390-    do {
15391-        unsigned char buf[128];
15392-        size_t len = sizeof(buf);
15393-        int n;
15394-
15395-        if (len > remaining) {
15396-            len = remaining;
15397-        }
15398-        (*env)->GetByteArrayRegion(env, ba, off, len, (jbyte *)buf);
15399-
15400-        RESTARTABLE(write(fd, buf, len), n);
15401-        if (n > 0) {
15402-           off += n;
15403-           remaining -= n;
15404-        } else {
15405-            JNU_ThrowIOExceptionWithLastError(env, "write");
15406-            return;
15407-        }
15408-
15409-    } while (remaining > 0);
15410-}
15411diff -upr ../orig/jdk/src/solaris/native/sun/xawt/XWindow.c ./jdk/src/solaris/native/sun/xawt/XWindow.c
15412--- ../orig/jdk/src/solaris/native/sun/xawt/XWindow.c   2009-01-27 15:45:52.000000000 -0500
15413+++ ./jdk/src/solaris/native/sun/xawt/XWindow.c 2009-05-04 17:37:17.000000000 -0400
15414@@ -228,10 +228,10 @@ KeymapEntry keymapTable[] =
15415     {java_awt_event_KeyEvent_VK_DOWN, XK_Down, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD},
15416 
15417     /* Keypad equivalents of Triangular Navigation Block */
15418-    {java_awt_event_KeyEvent_VK_KP_LEFT, XK_KP_Left, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD},
15419-    {java_awt_event_KeyEvent_VK_KP_UP, XK_KP_Up, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD},
15420-    {java_awt_event_KeyEvent_VK_KP_RIGHT, XK_KP_Right, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD},
15421-    {java_awt_event_KeyEvent_VK_KP_DOWN, XK_KP_Down, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD},
15422+    {java_awt_event_KeyEvent_VK_LEFT, XK_KP_Left, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD},
15423+    {java_awt_event_KeyEvent_VK_UP, XK_KP_Up, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD},
15424+    {java_awt_event_KeyEvent_VK_RIGHT, XK_KP_Right, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD},
15425+    {java_awt_event_KeyEvent_VK_DOWN, XK_KP_Down, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_NUMPAD},
15426 
15427     /* Other vendor-specific Triangular Navigation Block */
15428     {java_awt_event_KeyEvent_VK_LEFT, osfXK_Left, FALSE, java_awt_event_KeyEvent_KEY_LOCATION_STANDARD},
15429@@ -865,7 +865,7 @@ handleKeyEventWithNumLockMask(XEvent *ev
15430 {
15431     KeySym originalKeysym = *keysym;
15432 
15433-#ifndef __linux__
15434+#if !defined(__linux__) && !defined(_ALLBSD_SOURCE)
15435     /* The following code on Linux will cause the keypad keys
15436      * not to echo on JTextField when the NumLock is on. The
15437      * keysyms will be 0, because the last parameter 2 is not defined.
15438diff -upr ../orig/jdk/src/solaris/native/sun/xawt/awt_Desktop.c ./jdk/src/solaris/native/sun/xawt/awt_Desktop.c
15439--- ../orig/jdk/src/solaris/native/sun/xawt/awt_Desktop.c       2009-01-27 15:45:52.000000000 -0500
15440+++ ./jdk/src/solaris/native/sun/xawt/awt_Desktop.c     2009-05-04 17:37:17.000000000 -0400
15441@@ -24,6 +24,7 @@
15442  */
15443 
15444 #include <jni.h>
15445+#include <jvm_md.h>
15446 #include <dlfcn.h>
15447 
15448 typedef int gboolean;
15449@@ -36,7 +37,7 @@ int init(){
15450     gboolean (*gnome_vfs_init) (void);
15451     const char *errmsg;
15452 
15453-    vfs_handle = dlopen("libgnomevfs-2.so.0", RTLD_LAZY);
15454+    vfs_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnomevfs-2", "0"), RTLD_LAZY);
15455     if (vfs_handle == NULL) {
15456 #ifdef INTERNAL_BUILD
15457         fprintf(stderr, "can not load libgnomevfs-2.so\n");
15458@@ -54,7 +55,7 @@ int init(){
15459     // call gonme_vfs_init()
15460     (*gnome_vfs_init)();
15461 
15462-    gnome_handle = dlopen("libgnome-2.so.0", RTLD_LAZY);
15463+    gnome_handle = dlopen(VERSIONED_JNI_LIB_NAME("gnome-2", "0"), RTLD_LAZY);
15464     if (gnome_handle == NULL) {
15465 #ifdef INTERNAL_BUILD
15466         fprintf(stderr, "can not load libgnome-2.so\n");
15467diff -upr ../orig/jdk/src/solaris/npt/npt_md.h ./jdk/src/solaris/npt/npt_md.h
15468--- ../orig/jdk/src/solaris/npt/npt_md.h        2009-01-27 15:45:52.000000000 -0500
15469+++ ./jdk/src/solaris/npt/npt_md.h      2009-05-04 17:37:17.000000000 -0400
15470@@ -32,9 +32,10 @@
15471 #include <string.h>
15472 #include <errno.h>
15473 #include <dlfcn.h>
15474+#ifndef __APPLE__
15475 #include <link.h>
15476-
15477-#define NPT_LIBNAME "libnpt.so"
15478+#endif
15479+#include <jvm_md.h>
15480 
15481 #define NPT_INITIALIZE(pnpt,version,options)                            \
15482     {                                                                   \
15483@@ -43,7 +44,7 @@
15484                                                                         \
15485         if ( (pnpt) == NULL ) NPT_ERROR("NptEnv* is NULL");             \
15486         *(pnpt) = NULL;                                                 \
15487-        _handle =  dlopen(NPT_LIBNAME, RTLD_LAZY);                      \
15488+        _handle =  dlopen(JNI_LIB_NAME("npt"), RTLD_LAZY);              \
15489         if ( _handle == NULL ) NPT_ERROR("Cannot open library");        \
15490         _sym = dlsym(_handle, "nptInitialize");                         \
15491         if ( _sym == NULL ) NPT_ERROR("Cannot find nptInitialize");     \
15492diff -upr ../orig/jdk/src/solaris/transport/socket/socket_md.c ./jdk/src/solaris/transport/socket/socket_md.c
15493--- ../orig/jdk/src/solaris/transport/socket/socket_md.c        2009-01-27 15:45:52.000000000 -0500
15494+++ ./jdk/src/solaris/transport/socket/socket_md.c      2009-05-04 17:37:17.000000000 -0400
15495@@ -36,7 +36,7 @@
15496 #ifdef __solaris__
15497 #include <thread.h>
15498 #endif
15499-#ifdef __linux__
15500+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
15501 #include <pthread.h>
15502 #include <sys/poll.h>
15503 #endif
15504@@ -283,7 +283,7 @@ dbgsysTlsGet(int index) {
15505 
15506 #endif
15507 
15508-#ifdef __linux__
15509+#if defined(__linux__) || defined(_ALLBSD_SOURCE)
15510 int
15511 dbgsysTlsAlloc() {
15512     pthread_key_t key;
15513diff -upr ../orig/langtools/src/share/classes/com/sun/tools/javah/Util.java ./langtools/src/share/classes/com/sun/tools/javah/Util.java
15514--- ../orig/langtools/src/share/classes/com/sun/tools/javah/Util.java   2009-01-27 15:46:42.000000000 -0500
15515+++ ./langtools/src/share/classes/com/sun/tools/javah/Util.java 2009-05-04 17:37:17.000000000 -0400
15516@@ -180,6 +180,14 @@ public class Util {
15517             os = "win32";
15518         } else if (os.indexOf("Linux") >= 0) {
15519             os = "Linux";
15520+       } else if (os.indexOf("FreeBSD") >= 0) {
15521+           os = "FreeBSD";
15522+       } else if (os.indexOf("Darwin") >= 0) {
15523+           os = "Darwin";
15524+       } else if (os.indexOf("NetBSD") >= 0) {
15525+           os = "NetBSD";
15526+       } else if (os.indexOf("OpenBSD") >= 0) {
15527+           os = "OpenBSD";
15528         }
15529         String arch = System.getProperty("os.arch");
15530         String resname = "com.sun.tools.javah.resources." + os + "_" + arch;